Created
July 7, 2012 03:07
-
-
Save chjj/3064156 to your computer and use it in GitHub Desktop.
curl node repl (possibly dangerous?)
This file contains 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
var http = require('http'); | |
var pty = require('pty.js'); | |
var server = http.createServer(function(req, res) { | |
var ua = req.headers['user-agent'] || ''; | |
if (!~ua.indexOf('curl/')) { | |
res.setHeader('Content-Type', 'text/plain'); | |
return res.end('curl -sSNT. localhost:8000'); | |
} | |
var ps = pty.fork('irssi', [], { | |
name: 'xterm', | |
cols: 80, | |
rows: 24 | |
}); | |
res.setHeader('Content-Type', 'multipart/octet-stream'); | |
var iv = setInterval(function () { | |
res.write('\0'); | |
}, 100); | |
req.on('end', function () { | |
clearInterval(iv); | |
ps.destroy(); | |
}); | |
ps.pipe(res); | |
req.pipe(ps); | |
}); | |
server.listen(8000, 'localhost', function() { | |
console.log('curl -sSNT. localhost:8000'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment