candyapplecorn

nist vulnerability extractor 2 - server

Jan 1st, 2016
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var http = require('http'),
  2.     fs = require('fs'),
  3.     path = require('path'),
  4.     url = require('url'),
  5.     auth = require('basic-auth'),
  6.     time = require('time'),
  7.     child_process = require('child_process');
  8. var lastAccessed = Date.now() / 1000;
  9.  
  10. http.createServer(function(request, response) {
  11.     console.log("Received a request");
  12.  
  13.     var credentials = auth(request);
  14.     if (!credentials || credentials.name !== 'guest' || credentials.pass !== 'pass') {
  15.         response.statusCode = 401;
  16.         response.setHeader('WWW-Authenticate', 'Basic realm="example"');
  17.         response.end('Access denied');
  18.         return;
  19.     }
  20.    
  21.     var url_parts = url.parse(request.url, true);
  22.     var query = url_parts.query;
  23.     console.log(query); //{Object}
  24.     // If get has a var in it
  25.     if (query["download"] == "true") {
  26.         var filePath = path.join(__dirname, 'payload.txt');
  27.         var stat = fs.statSync(filePath);
  28.  
  29.         response.writeHead(200, {
  30.             'Content-Type': 'text/plain',
  31.             'Content-Length': stat.size
  32.         });
  33.         fs.readFile(filePath, 'utf8', function (err,data) {
  34.             if (err) {
  35.                 return console.log(err);
  36.             }
  37.             response.write(data);
  38.             console.log("Wrote file");
  39.         });
  40.         console.log("Writing file");
  41.     }
  42.     else {
  43.         response.writeHead(200, {
  44.             'Content-Type': 'text/plain'
  45.         });
  46.         var now = Date.now() / 1000;
  47.         response.write("Executing server script; please check back in five minutes. \n\nDo not refresh this page.\n\nTo receive the file, append this to the URL: /?download=true\n\nSo if the url was YOURURL:PORT, it would become:\n\nYOURURL:PORT/?download=true\n\nWhen you check back, make sure it's at the download=true url");
  48.             response.write("\n\nIt has been " + Math.floor(now - lastAccessed) + " seconds since the script was last run.");
  49.         console.log(now);
  50.         if (now - lastAccessed > 60 * 5) {
  51.             response.end();
  52.             lastAccessed = Date.now() / 1000;
  53.             console.log("Executing Perl Script");
  54.             child_process.exec("rm " + __dirname + "/lastaccessed.txt; /usr/bin/perl getVulns.pl");
  55.             console.log("Finished Executing Perl Script");
  56.         }
  57.         else {
  58.             response.write("\n\nWait " + Math.floor(60 * 5 - (now - lastAccessed)) + " more seconds.");
  59.             response.end();
  60.         }
  61.     }
  62. })
  63. .listen(6666);
Advertisement
Add Comment
Please, Sign In to add comment