Mercurial > prosody-hg
comparison plugins/mod_proxy65.lua @ 11012:027af78d8125
mod_proxy65: Limit dump of invalid data to 300 bytes (like mod_c2s)
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Fri, 17 Jul 2020 08:29:03 +0200 |
| parents | c079103c9172 |
| children | 3bbb1af92514 |
comparison
equal
deleted
inserted
replaced
| 11011:c079103c9172 | 11012:027af78d8125 |
|---|---|
| 42 return; | 42 return; |
| 43 end | 43 end |
| 44 end -- else error, unexpected input | 44 end -- else error, unexpected input |
| 45 conn:write("\5\255"); -- send (SOCKS version 5, no acceptable method) | 45 conn:write("\5\255"); -- send (SOCKS version 5, no acceptable method) |
| 46 conn:close(); | 46 conn:close(); |
| 47 module:log("debug", "Invalid SOCKS5 greeting received: %q", data); | 47 module:log("debug", "Invalid SOCKS5 greeting received: %q", data:sub(1, 300)); |
| 48 else -- connection request | 48 else -- connection request |
| 49 --local head = string.char( 0x05, 0x01, 0x00, 0x03, 40 ); -- ( VER=5=SOCKS5, CMD=1=CONNECT, RSV=0=RESERVED, ATYP=3=DOMAIMNAME, SHA-1 size ) | 49 --local head = string.char( 0x05, 0x01, 0x00, 0x03, 40 ); -- ( VER=5=SOCKS5, CMD=1=CONNECT, RSV=0=RESERVED, ATYP=3=DOMAIMNAME, SHA-1 size ) |
| 50 if #data == 47 and data:sub(1,5) == "\5\1\0\3\40" and data:sub(-2) == "\0\0" then | 50 if #data == 47 and data:sub(1,5) == "\5\1\0\3\40" and data:sub(-2) == "\0\0" then |
| 51 local sha = data:sub(6, 45); | 51 local sha = data:sub(6, 45); |
| 52 conn:pause(); | 52 conn:pause(); |
| 64 server.link(transfers[sha].target, conn, max_buffer_size); | 64 server.link(transfers[sha].target, conn, max_buffer_size); |
| 65 end | 65 end |
| 66 else -- error, unexpected input | 66 else -- error, unexpected input |
| 67 conn:write("\5\1\0\3\0\0\0"); -- VER, REP, RSV, ATYP, BND.ADDR (sha), BND.PORT (2 Byte) | 67 conn:write("\5\1\0\3\0\0\0"); -- VER, REP, RSV, ATYP, BND.ADDR (sha), BND.PORT (2 Byte) |
| 68 conn:close(); | 68 conn:close(); |
| 69 module:log("debug", "Invalid SOCKS5 negotiation received: %q", data); | 69 module:log("debug", "Invalid SOCKS5 negotiation received: %q", data:sub(1, 300)); |
| 70 end | 70 end |
| 71 end | 71 end |
| 72 end | 72 end |
| 73 | 73 |
| 74 function listener.ondisconnect(conn) | 74 function listener.ondisconnect(conn) |
