-
Notifications
You must be signed in to change notification settings - Fork 1
/
dvna.js
82 lines (74 loc) · 2.85 KB
/
dvna.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// Dependencies
var ws = require('ws');
var filesystem = require('fs');
var path = require('path');
var express = require('express');
var md = require('marked');
var morgan = require('morgan');
var bodyparser = require('body-parser');
// Express setup
var dvna = express();
var port = process.env.PORT || 3000;
// Setup the vulnerability file path
var vulnerabilities = [], vulnerabilities_path = './vulnerabilities/';
filesystem.readdir(vulnerabilities_path, function (error, folders) {
if (error) {
throw error;
}
dvna.set('vulnerabilities', vulnerabilities);
folders.map(function (folder) {
return path.join(vulnerabilities_path, folder);
}).filter(function (folder) {
return !filesystem.statSync(folder).isFile();
}).forEach(function (folder) {
console.log("[+] Loaded challenge '%s'...", folder);
var vulnerability_id = path.basename(folder);
var vulnerability_path = path.join(folder, 'vulnerability.js');
var challenge_path = path.join(folder, 'challenge.md');
var hint_path = path.join(folder, 'hint.md');
var vulnerability = require('./' + vulnerability_path);
var challenge = filesystem.readFileSync(challenge_path, 'utf8');
var hint = filesystem.readFileSync(hint_path, 'utf8');
vulnerability.id = vulnerability_id;
vulnerability.path = vulnerability_id;
vulnerability.challenge = challenge;
vulnerability.hint = hint;
vulnerabilities.push(vulnerability);
});
console.log('\nPress ctrl+c to shutdown the server');
});
// Setup the templating engine
dvna.set('view engine', 'jade');
dvna.use('/assets', express.static('public'));
// Setup loggers
dvna.use(bodyparser.urlencoded({ extended: true }));
dvna.use(morgan('combined'));
dvna.get('/', function (req, res) {
var data = {
vulnerabilities: vulnerabilities
};
res.render('dvna', data);
});
dvna.locals.md = md;
// Display the challenges
dvna.get('/:vulnerability/challenge', function (req, res) {
var vulnerability = req.app.set('vulnerabilities').filter(function (vulnerability) {
return vulnerability.path === req.params.vulnerability;
})[0];
res.render('vulnerability', { challenge: vulnerability.challenge });
});
// Console interface
dvna.set('port', port);
dvna.listen(port, function welcome () {
console.log(" ______ _ _______ ");
console.log(" ( __ \\ |\\ /|( ( /|( ___ )");
console.log(" | ( \\ )| ) ( || \\ ( || ( ) |");
console.log(" | | ) || | | || \\ | || (___) |");
console.log(" | | | |( ( ) )| (\\ \\) || ___ |");
console.log(" | | ) | \\ \\_/ / | | \\ || ( ) |");
console.log(" | (__/ ) \\ / | ) \\ || ) ( |");
console.log(" (______/ \\_/ |/ )_)|/ \\|");
console.log("\r\n Damn Vulnerable Node Application ");
console.log(" https://github.com/quantumfoam/dvna \r\n");
console.log("dvna listening at: http://127.0.0.1:" + port + "/\n");
});