29 local connlistener = { default_port = proxy_port, default_interface = proxy_interface, default_mode = "*a" }; |
29 local connlistener = { default_port = proxy_port, default_interface = proxy_interface, default_mode = "*a" }; |
30 |
30 |
31 function connlistener.onincoming(conn, data) |
31 function connlistener.onincoming(conn, data) |
32 local session = sessions[conn] or {}; |
32 local session = sessions[conn] or {}; |
33 |
33 |
34 if session.setup == nil and data ~= nil and data:sub(1):byte() == 0x05 and data:len() > 2 then |
34 if session.setup == nil and data ~= nil and data:byte(1) == 0x05 and data:len() > 2 then |
35 local nmethods = data:sub(2):byte(); |
35 local nmethods = data:byte(2); |
36 local methods = data:sub(3); |
36 local methods = data:sub(3); |
37 local supported = false; |
37 local supported = false; |
38 for i=1, nmethods, 1 do |
38 for i=1, nmethods, 1 do |
39 if(methods:sub(i):byte() == 0x00) then -- 0x00 == method: NO AUTH |
39 if(methods:byte(i) == 0x00) then -- 0x00 == method: NO AUTH |
40 supported = true; |
40 supported = true; |
41 break; |
41 break; |
42 end |
42 end |
43 end |
43 end |
44 if(supported) then |
44 if(supported) then |
60 end |
60 end |
61 return; |
61 return; |
62 end |
62 end |
63 end |
63 end |
64 if data ~= nil and data:len() == 0x2F and -- 40 == length of SHA1 HASH, and 7 other bytes => 47 => 0x2F |
64 if data ~= nil and data:len() == 0x2F and -- 40 == length of SHA1 HASH, and 7 other bytes => 47 => 0x2F |
65 data:sub(1):byte() == 0x05 and -- SOCKS5 has 5 in first byte |
65 data:byte(1) == 0x05 and -- SOCKS5 has 5 in first byte |
66 data:sub(2):byte() == 0x01 and -- CMD must be 1 |
66 data:byte(2) == 0x01 and -- CMD must be 1 |
67 data:sub(3):byte() == 0x00 and -- RSV must be 0 |
67 data:byte(3) == 0x00 and -- RSV must be 0 |
68 data:sub(4):byte() == 0x03 and -- ATYP must be 3 |
68 data:byte(4) == 0x03 and -- ATYP must be 3 |
69 data:sub(5):byte() == 40 and -- SHA1 HASH length must be 40 (0x28) |
69 data:byte(5) == 40 and -- SHA1 HASH length must be 40 (0x28) |
70 data:sub(-2):byte() == 0x00 and -- PORT must be 0, size 2 byte |
70 data:byte(-2) == 0x00 and -- PORT must be 0, size 2 byte |
71 data:sub(-1):byte() == 0x00 |
71 data:byte(-1) == 0x00 |
72 then |
72 then |
73 local sha = data:sub(6, 45); -- second param is not count! it's the ending index (included!) |
73 local sha = data:sub(6, 45); -- second param is not count! it's the ending index (included!) |
74 if transfers[sha] == nil then |
74 if transfers[sha] == nil then |
75 transfers[sha] = {}; |
75 transfers[sha] = {}; |
76 transfers[sha].activated = false; |
76 transfers[sha].activated = false; |