plugins/mod_proxy65.lua

changeset 3815
95069c67df6c
parent 3814
f74f2c49b939
child 3693
519f5eadf4b9
equal deleted inserted replaced
3814:f74f2c49b939 3815:95069c67df6c
31 local connlistener = { default_port = proxy_port, default_interface = proxy_interface, default_mode = "*a" }; 31 local connlistener = { default_port = proxy_port, default_interface = proxy_interface, default_mode = "*a" };
32 32
33 function connlistener.onincoming(conn, data) 33 function connlistener.onincoming(conn, data)
34 local session = sessions[conn] or {}; 34 local session = sessions[conn] or {};
35 35
36 if session.setup == nil and data ~= nil and data:byte(1) == 0x05 and data:len() > 2 then 36 if session.setup == nil and data ~= nil and data:byte(1) == 0x05 and #data > 2 then
37 local nmethods = data:byte(2); 37 local nmethods = data:byte(2);
38 local methods = data:sub(3); 38 local methods = data:sub(3);
39 local supported = false; 39 local supported = false;
40 for i=1, nmethods, 1 do 40 for i=1, nmethods, 1 do
41 if(methods:byte(i) == 0x00) then -- 0x00 == method: NO AUTH 41 if(methods:byte(i) == 0x00) then -- 0x00 == method: NO AUTH
61 transfers[sha].initiator:write(data); 61 transfers[sha].initiator:write(data);
62 end 62 end
63 return; 63 return;
64 end 64 end
65 end 65 end
66 if data ~= nil and data:len() == 0x2F and -- 40 == length of SHA1 HASH, and 7 other bytes => 47 => 0x2F 66 if data ~= nil and #data == 0x2F and -- 40 == length of SHA1 HASH, and 7 other bytes => 47 => 0x2F
67 data:byte(1) == 0x05 and -- SOCKS5 has 5 in first byte 67 data:byte(1) == 0x05 and -- SOCKS5 has 5 in first byte
68 data:byte(2) == 0x01 and -- CMD must be 1 68 data:byte(2) == 0x01 and -- CMD must be 1
69 data:byte(3) == 0x00 and -- RSV must be 0 69 data:byte(3) == 0x00 and -- RSV must be 0
70 data:byte(4) == 0x03 and -- ATYP must be 3 70 data:byte(4) == 0x03 and -- ATYP must be 3
71 data:byte(5) == 40 and -- SHA1 HASH length must be 40 (0x28) 71 data:byte(5) == 40 and -- SHA1 HASH length must be 40 (0x28)
84 session.sha = sha; 84 session.sha = sha;
85 module:log("debug", "initiator connected ... "); 85 module:log("debug", "initiator connected ... ");
86 server.link(conn, transfers[sha].target, max_buffer_size); 86 server.link(conn, transfers[sha].target, max_buffer_size);
87 server.link(transfers[sha].target, conn, max_buffer_size); 87 server.link(transfers[sha].target, conn, max_buffer_size);
88 end 88 end
89 conn:write(string.char(5, 0, 0, 3, sha:len()) .. sha .. string.char(0, 0)); -- VER, REP, RSV, ATYP, BND.ADDR (sha), BND.PORT (2 Byte) 89 conn:write(string.char(5, 0, 0, 3, #sha) .. sha .. string.char(0, 0)); -- VER, REP, RSV, ATYP, BND.ADDR (sha), BND.PORT (2 Byte)
90 conn:lock_read(true) 90 conn:lock_read(true)
91 else 91 else
92 module:log("warn", "Neither data transfer nor initial connect of a participator of a transfer.") 92 module:log("warn", "Neither data transfer nor initial connect of a participator of a transfer.")
93 conn:close(); 93 conn:close();
94 end 94 end

mercurial