Skip to content

Commit

Permalink
Format source code and add prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
christophetd committed Mar 21, 2023
1 parent e53aefe commit c5232e2
Show file tree
Hide file tree
Showing 15 changed files with 423 additions and 307 deletions.
5 changes: 5 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"useTabs": false,
"tabWidth": 4,
"singleQuote": true
}
37 changes: 15 additions & 22 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,21 @@
require('dotenv').config()

require('dotenv').config();

const figlet = require('figlet');
const chalk = require('chalk');
console.log('-----------------------------------')
console.log(
figlet.textSync('HASH', { horizontalLayout: 'full' })
);
console.log('-----------------------------------');
console.log(figlet.textSync('HASH', { horizontalLayout: 'full' }));
console.log(' HTTP Agnostic Software Honeypot ');
console.log('-----------------------------------');
const logger = require('./libs/log');


logger.info('App -> Starting HASH ');

let appName = 'default'; //default app
//overwrite by environment variable or the cli
appName = process.env.HONEYPOT_PROFILE || process.argv.slice(2)[0];

let appName = 'default'; //default app
//overwrite by environment variable or the cli
appName = process.env.HONEYPOT_PROFILE || process.argv.slice(2)[0];

logger.info('App -> Loading Application: ' + appName)
const app = require('./libs/app')(__dirname, appName)
logger.info('App -> Loading Application: ' + appName);
const app = require('./libs/app')(__dirname, appName);
app.logger = logger;

const config = require('./libs/config')(app);
Expand All @@ -31,35 +26,33 @@ const http = require('./libs/init')(app);
const { Cache } = require('./libs/randomizer');
Cache.reset();

//reset cache every 10 min (1000 * 60 * 10)
//reset cache every 10 min (1000 * 60 * 10)
setInterval(() => {
Cache.reset();
}, 600000);


//loading templates
const Template = require('./libs/template');

const template = new Template(app);
const { templates, dynamicTemplates } = template.load();

//simulate
//simulate
const Simulator = require('./libs/simulator');
const simulator = new Simulator(app, http, templates, dynamicTemplates);
simulator.apply()
simulator.apply();

//overwrite express error handler
http.use((err, req, res, next) => {
logger.error('HTTP -> 500 error: ' + err.message, {stack: err.stack});
logger.error('HTTP -> 500 error: ' + err.message, { stack: err.stack });
res.status(200).send('!!');
});

//default endpoint
http.get('/', (req,res) => {
http.get('/', (req, res) => {
res.send('Hello, World');
})

});

http.listen(config.port, () => {
logger.info(`App -> ${app.name} listening on port ${config.port}`);
})
});
5 changes: 2 additions & 3 deletions libs/actor.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// const mark
// const mark


module.exports = {}
module.exports = {};
36 changes: 24 additions & 12 deletions libs/app.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,34 @@
const fs = require('fs')
const fs = require('fs');
module.exports = (basedir, name) => {
const appDir = basedir + '/profiles/' + name;
const initFile = appDir + '/init.yaml';
const templatesDir = appDir + '/templates';
const resourcesDir = templatesDir + '/resources';

//check if the directory is available
if (!fs.existsSync(appDir)) { console.log("Error: Directory: `"+appDir+"` not exists"); process.exit(1); }
if (!fs.existsSync(initFile)) { console.log("Error: Init file: `"+initFile+"` not exists"); process.exit(1); }
if (!fs.existsSync(templatesDir)) { console.log("Error: Template directory: `"+appDir+"` not exists"); process.exit(1); }
if (!fs.existsSync(resourcesDir)) { console.log("Error: Template Resources directory: `"+appDir+"` not exists"); process.exit(1); }

//check if the directory is available
if (!fs.existsSync(appDir)) {
console.log('Error: Directory: `' + appDir + '` not exists');
process.exit(1);
}
if (!fs.existsSync(initFile)) {
console.log('Error: Init file: `' + initFile + '` not exists');
process.exit(1);
}
if (!fs.existsSync(templatesDir)) {
console.log('Error: Template directory: `' + appDir + '` not exists');
process.exit(1);
}
if (!fs.existsSync(resourcesDir)) {
console.log(
'Error: Template Resources directory: `' + appDir + '` not exists'
);
process.exit(1);
}

return {
name,
initFile,
templatesDir,
resourcesDir
}
}


resourcesDir,
};
};
18 changes: 10 additions & 8 deletions libs/config.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
const fs = require('fs')
const fs = require('fs');
const yaml = require('js-yaml');

const defaultConfig = {
port:3000,
headers: {}
}
port: 3000,
headers: {},
};

module.exports = (app) => {
try {
let config = yaml.load(fs.readFileSync(app.initFile, 'utf8'));
app.logger.info('Config -> loading main config')
app.logger.info('Config -> loading main config');
return config;
} catch (e) {
app.logger.error('Config -> loading main config failed, make sure init.yaml is exists and have correct values')
app.logger.error('Config -> Falling back to default config')
app.logger.error(
'Config -> loading main config failed, make sure init.yaml is exists and have correct values'
);
app.logger.error('Config -> Falling back to default config');
return defaultConfig;
}
}
};
29 changes: 14 additions & 15 deletions libs/honeytraps/cookie.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,29 @@
const randomizer = require('../randomizer')

const randomizer = require('../randomizer');

module.exports = (http) => {
//add couple of fake cookies
//list of cookies to implement
//list of cookies to implement
let cookie_set = {
key: randomizer.faker.internet.domainWord(),
value: randomizer.faker.git.commitSha()
}
value: randomizer.faker.git.commitSha(),
};

http.use(function(req, res, next) {
http.use(function (req, res, next) {
//if not exists create it
if(!req.cookies || !req.cookies[cookie_set.key]){
if (!req.cookies || !req.cookies[cookie_set.key]) {
res.cookie(cookie_set.key, cookie_set.value, {
httpOnly: true
})
next()
return
httpOnly: true,
});
next();
return;
}

if(req.cookies && req.cookies[cookie_set.key] != cookie_set.value){
if (req.cookies && req.cookies[cookie_set.key] != cookie_set.value) {
//cookie manipulated
req.session.isMalicious = true
req.session.isMalicious = true;
}

//all good
next()
next();
});
}
};
39 changes: 23 additions & 16 deletions libs/honeytraps/exposed-files.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,31 @@
const fs = require('fs')
const randomizer = require('../randomizer')
const fs = require('fs');
const randomizer = require('../randomizer');

module.exports = (http) => {

let files = {
".env": randomizer.fakeIt(fs.readFileSync(__dirname + '/files/dotenv', {encoding: 'utf-8'})),
"readme.txt": randomizer.fakeIt(fs.readFileSync(__dirname + '/files/readme.txt', {encoding: 'utf-8'})),
"changelog.txt": randomizer.fakeIt(fs.readFileSync(__dirname + '/files/changelog.txt', {encoding: 'utf-8'}))
'.env': randomizer.fakeIt(
fs.readFileSync(__dirname + '/files/dotenv', {
encoding: 'utf-8',
})
),
'readme.txt': randomizer.fakeIt(
fs.readFileSync(__dirname + '/files/readme.txt', {
encoding: 'utf-8',
})
),
'changelog.txt': randomizer.fakeIt(
fs.readFileSync(__dirname + '/files/changelog.txt', {
encoding: 'utf-8',
})
),
};



for (const route in files) {
const content = files[route];
http.get("/"+route, (req,res) => {
req.session.isMalicious = true
res.set('Content-Type', 'text/plain')
res.status(500).send(content)
const content = files[route];
http.get('/' + route, (req, res) => {
req.session.isMalicious = true;
res.set('Content-Type', 'text/plain');
res.status(500).send(content);
});
}


}
};
27 changes: 14 additions & 13 deletions libs/honeytraps/robots-txt.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
const fs = require('fs')
const randomizer = require('../randomizer')
const fs = require('fs');
const randomizer = require('../randomizer');

module.exports = (http) => {
let robotsTxt = fs.readFileSync(__dirname + '/files/robots.txt', {
encoding: 'utf-8',
});
robotsTxt = randomizer.fakeIt(robotsTxt);

let robotsTxt = fs.readFileSync(__dirname + '/files/robots.txt', {encoding: 'utf-8'});
robotsTxt = randomizer.fakeIt(robotsTxt)

http.get('/robots.txt', (req,res) => {
http.get('/robots.txt', (req, res) => {
let content = robotsTxt;
res.set('Content-Type', 'text/plain')
res.set('Content-Type', 'text/plain');
res.send(content);
})
});

http.get('/[cd]/*', (req,res) => {
http.get('/[cd]/*', (req, res) => {
//if accessed, this request is malicious
req.session.isMalicious = true
res.status(500).send("Internal Server Error")
})
}
req.session.isMalicious = true;
res.status(500).send('Internal Server Error');
});
};
Loading

0 comments on commit c5232e2

Please sign in to comment.