Skip to content

Instantly share code, notes, and snippets.

@majek
Created February 9, 2012 15:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save majek/1780761 to your computer and use it in GitHub Desktop.
Save majek/1780761 to your computer and use it in GitHub Desktop.
Misultin haproxy websocket hixie76 bug
var net = require('net');
console.log(" [.] Connecting to localhost:8000");
var conn = net.createConnection(8000, '127.0.0.1');
var data = [
"GET /echo/1/1/websocket HTTP/1.1",
"Upgrade: WebSocket",
"Connection: Upgrade",
"Host: localhost:8000",
"Origin: http://localhost:8000",
"Cookie: x=x",
"Sec-WebSocket-Key1: 232J 4jm9 w6!4^ 9<05@ h# do",
"Sec-WebSocket-Key2: ; 6KW91 %3 ` u7 59 -:c'58",
"",
"01234567"]
conn.on('connect', function() {
conn.write(data.join('\r\n'));
setTimeout(function(){conn.end()}, 200);
});
conn.on('data', function(d) {
console.log(d.toString());
});
var net = require('net');
console.log(" [.] Connecting to localhost:8000");
var conn = net.createConnection(8000, '127.0.0.1');
var data = [
"GET /echo/1/1/websocket HTTP/1.1",
"Upgrade: WebSocket",
"Connection: Upgrade",
"Host: localhost:8000",
"Origin: http://localhost:8000",
"Cookie: x=x",
"Sec-WebSocket-Key1: 232J 4jm9 w6!4^ 9<05@ h# do",
"Sec-WebSocket-Key2: ; 6KW91 %3 ` u7 59 -:c'58",
"",
""]
conn.on('connect', function() {
conn.write(data.join('\r\n'));
setTimeout(function(){conn.end()}, 200);
});
conn.once('data', function(d) {
conn.write('01234567');
console.log(d.toString());
conn.on('data', function(d) {
console.log(d.toString());
});
});
#!/usr/bin/env escript
%%! -smp disable +A1 +K true -pz ./ebin -pa deps/misultin/ebin -input
-module(misultin_haproxy_bug).
-mode(compile).
-export([main/1]).
main(_) ->
Port = 8000,
io:format(" [*] Running at http://localhost:~p~n", [Port]),
misultin:start_link(
[{port, Port},
{autoexit, false},
{ws_autoexit, false},
{loop, fun (Req) -> handle_http(Req) end},
{ws_loop, fun (Req) -> handle_ws(Req) end}]),
receive
_ -> ok
end.
handle_http(Req) ->
Req:respond(404,
<<"404 - Nothing here\n">>).
handle_ws(Req) ->
Req:send(<<"deadbabe">>),
closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment