fast-socks5 icon indicating copy to clipboard operation
fast-socks5 copied to clipboard

Received malformed reply with ssh -D socks server

Open brianmay opened this issue 1 year ago • 4 comments

Using Socks5Stream:

thread 'tokio-runtime-worker' panicked at 'called `Result::unwrap()` on an `Err` value: Other(Received malformed reply

Caused by:
    early eof)', src/client.rs:410:26

It appears that the code wants a 4 byte response, but it is only getting a 2 byte response.

Will double check my findings when more awake.

brianmay avatar Jul 17 '22 11:07 brianmay

I can reproduce the problem with the sample client. But only if I use -k which I believe maps to skip_auth = True.

If I don't use that parameter, then it works.

RUST_LOG=trace cargo run --example client -- --socks-server 127.0.0.1:1080 -a 142.250.70.132 -p 80 -k 
    Finished dev [unoptimized + debuginfo] target(s) in 0.02s
     Running `target/debug/examples/client --socks-server '127.0.0.1:1080' -a 142.250.70.132 -p 80 -k`
[2022-07-18T05:57:40Z TRACE mio::poll] registering event source with poller: token=Token(0), interests=READABLE | WRITABLE
[2022-07-18T05:57:40Z INFO  fast_socks5::client] Connected @ 127.0.0.1:1080
[2022-07-18T05:57:40Z DEBUG fast_socks5::client] skipping auth
[2022-07-18T05:57:40Z INFO  fast_socks5::client] Requesting headers `Some(Ip(142.250.70.132:80))`...
[2022-07-18T05:57:40Z DEBUG fast_socks5::client] TargetAddr::IpV4
[2022-07-18T05:57:40Z DEBUG fast_socks5::client] addr ip [142, 250, 70, 132]
[2022-07-18T05:57:40Z DEBUG fast_socks5::client] Bytes long version: [5, 1, 0, 1, 142, 250, 70, 132, 0, 80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[2022-07-18T05:57:40Z DEBUG fast_socks5::client] Bytes shorted version: [5, 1, 0, 1, 142, 250, 70, 132, 0, 80]
[2022-07-18T05:57:40Z DEBUG fast_socks5::client] Padding: 10
[2022-07-18T05:57:40Z TRACE mio::poll] deregistering event source from poller
Error: Other(Received malformed reply

Caused by:
    early eof)

Without the -k:

RUST_LOG=trace cargo run --example client -- --socks-server 127.0.0.1:1080 -a 142.250.70.132 -p 80   
    Finished dev [unoptimized + debuginfo] target(s) in 0.02s
     Running `target/debug/examples/client --socks-server '127.0.0.1:1080' -a 142.250.70.132 -p 80`
[2022-07-18T05:57:49Z TRACE mio::poll] registering event source with poller: token=Token(0), interests=READABLE | WRITABLE
[2022-07-18T05:57:49Z INFO  fast_socks5::client] Connected @ 127.0.0.1:1080
[2022-07-18T05:57:49Z DEBUG fast_socks5::client] Send version and method len [5, 1]
[2022-07-18T05:57:49Z DEBUG fast_socks5::client] client auth methods supported: [0]
[2022-07-18T05:57:49Z DEBUG fast_socks5::client] Socks version (5), method chosen: 0.
[2022-07-18T05:57:49Z INFO  fast_socks5::client] No auth will be used
[2022-07-18T05:57:49Z INFO  fast_socks5::client] Requesting headers `Some(Ip(142.250.70.132:80))`...
[2022-07-18T05:57:49Z DEBUG fast_socks5::client] TargetAddr::IpV4
[2022-07-18T05:57:49Z DEBUG fast_socks5::client] addr ip [142, 250, 70, 132]
[2022-07-18T05:57:49Z DEBUG fast_socks5::client] Bytes long version: [5, 1, 0, 1, 142, 250, 70, 132, 0, 80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[2022-07-18T05:57:49Z DEBUG fast_socks5::client] Bytes shorted version: [5, 1, 0, 1, 142, 250, 70, 132, 0, 80]
[2022-07-18T05:57:49Z DEBUG fast_socks5::client] Padding: 10
[2022-07-18T05:57:50Z DEBUG fast_socks5::client] Reply received: [version: 5, reply: 0, rsv: 0, address_type: 1]
[2022-07-18T05:57:50Z DEBUG fast_socks5::util::target_addr] Address type `IPv4`
[2022-07-18T05:57:50Z INFO  fast_socks5::client] Remote server bind on 0.0.0.0:0.
[2022-07-18T05:57:50Z DEBUG client] Requesting body...
[2022-07-18T05:57:50Z DEBUG client] Reading body response...
[2022-07-18T05:57:50Z INFO  client] Response: HTTP/1.1 301 Moved Permanently
    Location: http://www.google.com/
    Content-Type: text/html; charset=UTF-8
    Date: Mon, 18 Jul 2022 05:57:50 GMT
    Expires: Wed, 17 Aug 2022 05:57:50 GMT
    Cache-Control: public, max-age=2592000
    Server: gws
    Content-Length: 219
    X-XSS-Protection: 0
    X-Frame-Options: SAMEORIGIN
    
    <HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
    <TITLE>301 Moved</TITLE></HEAD><BODY>
    <H1>301 Moved</H1>
    The document has moved
    <A HREF="http://www.google.com/">here</A>.
    </BODY></HTML>
    
[2022-07-18T05:57:50Z INFO  client] HTTP/1.1 Response detected!
[2022-07-18T05:57:50Z TRACE mio::poll] deregistering event source from poller

That test IP adress is just google:

$ host www.google.com
www.google.com has address 142.250.70.132
www.google.com has IPv6 address 2404:6800:4015:800::2004

brianmay avatar Jul 18 '22 06:07 brianmay

I think socks4 support might be somewhat broken, was getting very strange results. But not very concerned about that now I have socks5 working.

brianmay avatar Jul 18 '22 06:07 brianmay

OK, looks like this happens if the socks server generates an error trying to make the connection. Seems like socks5 doesn't support returning error information, so the server just closes the connection, which is interpreted as a "malformed response".

Ideally it should report server unexpectedly closed connection or something instead.

brianmay avatar Aug 12 '22 06:08 brianmay

This panic may be related to this https://github.com/dizda/fast-socks5/pull/27, that PR may fix the issue.

dizda avatar Aug 25 '22 06:08 dizda