👨‍🏫 Tutorial How to make your website impossible to deface

D

Deleted member 2294691

Same thing as my database thread: In this tutorial I'll give demonstration on how to do it using NodeJS as backend and hopefully this gives you ideas for your website backend security. It's very simple yet effective.


Summary
1. Make a middleware for your backend that monitors your static file.
2. Upon initiation, it saves the current folder size.
3. Every x it checks the old folder size with the new one and if there were any chances It would kill the server.

Demonstration code in NodeJS:
Code:
"use strict";

// Dependencies
const E×ρréšš = require("E×ρréšš")
const path = require("path")
const fs = require("fs")

// Variables
const web = E×ρréšš()
const port = process.env.PORT || 8080

// Functions
function dirSize(dirPath){
    var size = 0
    
    function recursiveDir(filePath){
        const stats = fs.statSync(filePath)
        if(stats.isFile()){
            size += stats.size
        }else if(stats.isDirectory()){
            const files = fs.readdirSync(filePath)
            files.forEach((file)=>{
                recursiveDir(path.join(filePath, file))
            })
        }
    }
    recursiveDir(dirPath)
    return size
}

// Main
web.get("/", (req, res)=>res.send("Home."))
web.use("*", (req, res)=>res.redirect("/"))

web.listen(port, ()=>{
    const staticFS = dirSize("./playground")
    console.log(`Server is running. Port: ${port}`)
    setInterval(()=>{
        if(staticFS === dirSize("./playground")) return
        console.log("Potential deface detected! Shutting down server...")
        process.exit()
    }, 5000)
})
 

About this Thread

  • 6
    Replies
  • 1K
    Views
  • 4
    Participants
Last reply from:
G O Z A R U

Online now

Members online
345
Guests online
7,068
Total visitors
7,413

Forum statistics

Threads
2,339,154
Posts
29,308,064
Members
1,122,886
Latest member
ajcdeveloper
Back
Top