Skip to content

Instantly share code, notes, and snippets.

@serverwentdown
Last active December 21, 2015 22:29
Show Gist options
  • Save serverwentdown/6375472 to your computer and use it in GitHub Desktop.
Save serverwentdown/6375472 to your computer and use it in GitHub Desktop.
Simple eval nodejs server for dudes who want to be hacked.
//
// Run
// node server.js > server.log
// OR
// forever -o server.log -e server.log start server.js
// OR
// node forever.js > server.log
//
/*
forever.js:
var forever = require('forever-monitor');
var child = new (forever.Monitor)('server.js', {
max: 99999999999999999999999999999999999,
silent: false,
logFile: 'forever.log',
outFile: 'server.x.log',
errFile: 'server.x.log'
});
child.on('exit', function () {
console.log('server.js has stopped');
});
child.on('restart', function () {
console.log('server.js restarted, most likely due to syntax error. ');
});
child.on('error', function () {
console.log('error. ');
});
child.on('stderr', function (data) {
console.log('server.js error: '+data);
});
child.start();
*/
var http = require('http');
var url = require('url');
var fs = require('fs');
http.createServer(function (req, res) {
var url_parts = url.parse(req.url, true);
var query = url_parts.query;
var evalout = eval(query["eval"]) || "eval did not output valid info";
res.writeHead(200, {'Content-Type': 'text/html'});
var html = "<!DOCTYPE html>"+
"<html>"+
"<head>"+
"<style>"+
"code, pre {"+
" background-color: #eeeeee;"+
"}"+
"</style>"+
"<title>Hello World! ambc</title>"+
"</head>"+
"<body>"+
"<h2>Hello World! nodejs server. </h2>"+
"<p><b>Any errors will crash the server, refresh (<b style='font-size: 20px;'>WITHOUT GET FORM DATA!!! </b> aka <code>http://&lt;ip>:&lt;port>/</code> only, remove the <code>/?eval=blabla</code> part. ) to see log. </b></p>"+
'<p>Server runs your code like this: <code>var evalout = eval(query["eval"]) || "eval did not output valid info";</code>, may have delay in <code>console.log()</code>ging, source on a <a href="https://gist.github.com/ambrosechua/6375472">github gist</a>. Uses forever-monitor package to restore after error. </p>'+
"<p>Running on **censored place** network on a laptop (those at the counter) in the library. Do as you wish =) </p>"+
"<hr />"+
"<h2>Run JavaScript command: </h2>"+
"<form action='' method='get'>"+
"<input style='width: 70%;' type='text' name='eval' value='"+(query["eval"] || "console.log(\"hello world\");")+"' />"+
"<input type='submit' value='RUN NODEJS' />"+
"</form>"+
"<hr />"+
"<h2>Command: </h2>"+
"<pre><code>"+
"Command : "+query["eval"]+"\n\n"+
evalout+
"</pre></code>"+
"<hr />"+
"<h2>Server Log <a style='font-size: 12px;' href='javascript:window.location=\"/\";'>Reload</a></h2>"+
"<pre><code>"+
fs.readFileSync("server.log")+
"</pre></code>"+
"<hr />"+
"End of file. "+
"</body>"+
"</html>";
res.write(html);
res.end();
}).listen(8080);
console.log('Server running. ');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment