Last active
October 21, 2017 04:54
-
-
Save wfjsw/dac68b16a56a3823267bcc6e1204d2c7 to your computer and use it in GitHub Desktop.
Websocket to CONNECT middleware. Obsolete. Please check out https://github.com/wfjsw/madproxy
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
const http = require('http'); | |
const net = require('net'); | |
const url = require('url'); | |
var proxy = http.createServer( (req, res) => { | |
res.writeHead(400, {'Content-Type': 'text/plain'}); | |
res.end('400 Bad Request'); | |
}); | |
var processsocket = (req, cltSocket, head) => { | |
try{ | |
console.log(`http://${req.headers['x-connect-to']}`); | |
var srvUrl = url.parse(`http://${req.headers['x-connect-to']}`); | |
var srvSocket = net.connect(srvUrl.port, srvUrl.hostname, () => { | |
cltSocket.write('HTTP/1.1 200 OK\r\n' + '\r\n'); | |
srvSocket.write(head); | |
srvSocket.pipe(cltSocket); | |
cltSocket.pipe(srvSocket); | |
}); | |
srvSocket.on('error', (e) => {console.error(e);}); | |
cltSocket.on('error', (e) => {console.error(e);}); | |
} catch (e) { | |
console.error('bad request'); | |
cltSocket.end('HTTP/1.1 404 Not Found\r\n' + '\r\n'); | |
} | |
}; | |
proxy.on('upgrade', processsocket); | |
proxy.on('connect', processsocket); | |
proxy.on('error', (e) => {console.error(e);}); | |
proxy.listen(443, '0.0.0.0', () => { | |
console.log('running on port 443, change this on line 28 if you prefer(only 80,443,8080 allowed)') | |
console.log('Point Your HTTP Injector Remote Proxy to This-IP:8080'); | |
console.log('Vaild Payload: GET http://wap.cmvideo.cn/ HTTP/1.1[crlf]Host: wap.cmvideo.cn[crlf]Connection: Upgrade[crlf]Upgrade: websocket[crlf]X-Connect-To: [host_port][crlf][crlf]') | |
console.log('No Warranty Provided - Use it at your OWN risk!') | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@codexss
ES6 支持需要安装不小于Node.js 5的版本
还有这东西重构了 看 https://github.com/wfjsw/madproxy