wstunnel icon indicating copy to clipboard operation
wstunnel copied to clipboard

Error while upgrading cnx to http

Open verbal666 opened this issue 10 months ago β€’ 13 comments

Describe the goal

ws server is the same on both env. Connect wstunnel thru a proxy chains

  • in a TEST environment, it works [wstunnel client]-> local http proxy -> remote http proxy -> remote socks5 proxy -> remote http proxy -> wstunnel server
  • in a PROD environment, quite same chaining, got an error πŸ€”πŸ€”πŸ€”

Testing with a simple curl -kL https://url -x socks5h://wstunnel_ip:socks5_ip ,

  • in TEST works perfect
  • in PROD i got errors Error while upgrading cnx to http πŸ₯²

Describe what does not work

Client side i have no errors, apparently, wstunnel starts and starts listening at its socks5. Server side i got a strange error,

ERROR cnx{peer="1.2.3.4:31734"}: wstunnel::tunnel::server::server: Error while upgrading cnx to http: hyper::Error(Io, Custom { kind: UnexpectedEof, error: "connection closed before reading preface" })

Maybe production http proxy filter and alter https/ws packets? πŸ₯²

Describe your wstunnel setup

server wss://local_ip:443 --tls-certificate \path_to\fullchain.pem --tls-private-key \path_to\privkey.pem --restrict-http-upgrade-path-prefix my_private_prefix --remote-to-local-server-idle-timeout 30m --websocket-ping-frequency-sec 600 --log-lvl DEBUG

 INFO cnx{peer="1.2.3.4:31734"}: wstunnel::tunnel::server::server: Accepting connection
 INFO cnx{peer="1.2.3.4:31734"}: wstunnel::tunnel::server::server: Doing TLS handshake
DEBUG cnx{peer="1.2.3.4:31734"}: rustls::server::hs: decided upon suite TLS13_AES_256_GCM_SHA384
DEBUG cnx{peer="1.2.3.4:31734"}: rustls::server::hs: Chosen ALPN protocol [104, 50]
ERROR cnx{peer="1.2.3.4:31734"}: wstunnel::tunnel::server::server: Error while upgrading cnx to http: hyper::Error(Io, Custom { kind: UnexpectedEof, error: "connection closed before reading preface" })

Desktop (please complete the following information):

Chaining many OS ==> Linux (Ubuntu / Debian / Alma) and also Windows

verbal666 avatar Feb 12 '25 19:02 verbal666

Are you starting your wstunnel client to use http2 ?

Because the server see an incoming TLS connection with Chosen ALPN protocol [104, 50] which means h2 (http2). While for websocket the ALPN should be http/1.1

You can use TRACE log level on the server to get more info.

erebe avatar Feb 13 '25 08:02 erebe

I'll try tracing πŸ‘

But i think it's the production proxy (it has also a firewall onboard!) which filters or alters the TLS communication with the ws server, and so the connection is for some networking reason not going well.

Considering the test proxy has no filters/firewall and it's full open, and ws client connects well πŸ€·β€β™€οΈ

PS. how can i force not using HTTP2? Can't see parameters client side πŸ€”πŸ€”πŸ€”

Attached a clean session with a single curl get. (hoping have removed all sensible data πŸ™πŸ™πŸ™)

[cut]

verbal666 avatar Feb 13 '25 08:02 verbal666

Ha it seems you start your client with http2 as transport protocol

wstunnel client -L socks5://127.0.0.1:1080 --connection-min-idle 0 --tls-sni-override my.domain.com --http-upgrade-path-prefix my_path https://my.domain.com:443 --tls-certificate /etc/certs/fullchain.pem --tls-private-key /etc/certs/privkey.pem --tls-verify-certificate -p proxy:port --log-lvl TRACE
 https://my.domain.com:443

to use websocket as transport, you need to change it to

 wss://my.domain.com:443

It should work better after that

erebe avatar Feb 13 '25 12:02 erebe

Gosh! You're perfect right. Didn't noticed i started remote to https πŸ€¦β€β™‚οΈforce of habit πŸ˜‰ I'll try again soon with remote wss:// . But i really think the proxy/firewall has something which changes headers/packets πŸ₯² Thanks πŸ‘πŸ‘πŸ‘

verbal666 avatar Feb 13 '25 16:02 verbal666

Surely production proxy/fw is filtering πŸ‘ŽπŸ‘ŽπŸ‘Ž

TEST PROXY == OK == tunnel & next curl went ok PROD PROXY == KO == alpn: None / DEBUG cnx{peer="my_remote_ip:32094"}: rustls::common_state: Sending warning alert CloseNotify

[cut]

I'll find another way to connect the tunnel πŸ€·β€β™€οΈ

verbal666 avatar Feb 14 '25 06:02 verbal666

Indeed that's strange, it seems you never receive data server side. To investigate more, I would need a network capture.

export SSLKEYLOGFILE=/tmp/tls_keys.txt
wstunnel server ... wss://local_ip:443

# in another terminal 
sudo tcpdump -i any port 443 -w capture.pcap -s 65535

and you can send me the /tmp/tls_keys.txt and capture.pcap files for a ko request

erebe avatar Feb 14 '25 15:02 erebe

Not so strange. Prod Proxy (HTTPS) and its firewall has many professional filters and tls inspectors. Surely it changes the packets flow so ws can't understand what's going on πŸ€·β€β™€οΈπŸ€·β€β™€οΈπŸ€·β€β™€οΈ

wstunnel works perfect, it's proxy who alters its flow πŸ₯²

Don't mind about it. Eventually i'll send the tcpdump, in other case ok so πŸ€·β€β™€οΈ

verbal666 avatar Feb 14 '25 17:02 verbal666

@verbal666 @erebe You can try use a public CA like letsencrypt. Some firewall block selfsigned cert or some specific SNI. If public CA is not work, you can try selfsigned a cert that SNI is localhost. Good luck

bytejedi avatar Feb 17 '25 03:02 bytejedi

Hi. Still have my certs signed with Let'sEncrypt πŸ‘ I manage 3 domains, all with L/E signed certs. My HTTPS proxy blocks all not signed certs by years. I can with no problems navigate all my webservers thru HTTPS proxy, so it does not blocks HTTPS/TLS negotiate.

HTTPS proxy has many many professional filters and also provides its certs for authentication, so it changes original certs with its own... so, something in the middle [proxy] (also seeing what i'm doing 😀) broke the connection.

Thanks.

verbal666 avatar Feb 17 '25 05:02 verbal666

I also tried a session with stunnel, which works more less like yours, perfect on any of my clients, both Linux and Windows, and thru that proxy it does not work. The proxy/firewall filters all data and breaks any not HTTP traffic. Probably a very deep DPI interrupts all traffic! πŸ€·β€β™€οΈLe roi est mort, vive le roi!!! πŸ€·β€β™€οΈπŸ€·β€β™€οΈ PS. can't use redsocks or shadowsocks or similar, since connection to public ip:port is denied πŸ‘Ž

verbal666 avatar Feb 17 '25 14:02 verbal666

That's sad, maybe your proxy forbid completely websocket. You can give a try by visiting this website https://websocketstest.com/

Out of curiosity, in which kind of environment are you working in to have such strong firewall ?

erebe avatar Feb 18 '25 21:02 erebe

Yes, not properly sad πŸ˜‰but frustrating. Can't talk much 🀭but it's a very strong fw/av, our Company migrated the previous proxy to an external service provider, and they invest much on security (correctly!!! πŸ‘), but censorship policy is very very frustrating!!! We -developers- can't neither download apache/tomcat/tools or others bins/sources from the inet, since 1) or target is denied (access is blocked) 2) or target starts downloading and then proxy cuts and truncate the final download file to 10%, responding 200, giving a corrupted file πŸ₯²πŸ₯²πŸ₯²πŸ‘Ž 3) any "strange" CONNECT is monitored and a notification runs on every event of such type πŸ€¦β€β™‚οΈπŸ€¦β€β™‚οΈπŸ€¦β€β™‚οΈ

Just to understand,

On the TCP Listener (Port 443), a Client (IP address 1.2.3.4, Host name "1.2.3.4", Port number 47078) has connected.
For the client (IP address: 1.2.3.4, host name: "1.2.3.4", port number: 47078), connection "CID-1-9EDE0C5552" has been created.
SSL communication for connection "CID-1-9EDE0C5552" has been started. The encryption algorithm name is "TLS_AES_256_GCM_SHA384".
Connection "CID-1-9EDE0C5552" terminated by the cause "A client which is non-SoftEther VPN software has connected to the port." (code 5).
Connection "CID-1-9EDE0C5552" has been terminated.
The connection with the client (IP address 1.2.3.4, Port number 47078) has been disconnected.

With same identical config i can connect both to wstunnel and to my vpn outside that proxy/fw/av πŸ€·β€β™€οΈ

So, HAIL TO THE KING πŸ€·β€β™€οΈπŸ€·β€β™€οΈπŸ€·β€β™€οΈπŸ˜€

πŸ€·β€β™€οΈ

verbal666 avatar Feb 19 '25 02:02 verbal666

Anyway, just to let you know πŸ₯²πŸ₯²πŸ₯²

WebSockets seem to
Not Work for you :(

Environment
WebSockets supported YES
HTTP Proxy NO

WebSockets (Port 443, SSL)
Connected No ❌

πŸ€·β€β™€οΈπŸ€·β€β™€οΈπŸ€·β€β™€οΈ

verbal666 avatar Feb 19 '25 08:02 verbal666