erebe / wstunnel

Tunnel all your traffic over Websocket or HTTP2 - Bypass firewalls/DPI - Static binary available
BSD 3-Clause "New" or "Revised" License
3.72k stars 328 forks source link

get 400 when using cloudflare #288

Open sajjadnasiribrn opened 4 weeks ago

sajjadnasiribrn commented 4 weeks ago

hi. im using wstunnel with cloudflare. but i get this error:

2024-06-07T13:37:46.875975Z INFO wstunnel::tcp: Opening TCP connection to cdn.example.com:8443 Jun 07 14:37:46 sajjad wstunnel[3912]: 2024-06-07T13:37:46.890491Z ERROR tunnel{id="018ff2eb-6e81-73ed-90e7-a333b0bcaaf3" remote="localhost:2083"}: wstunnel::tunnel::client: failed to do websocket handshake wit> Jun 07 14:37:46 sajjad wstunnel[3912]: Caused by: Jun 07 14:37:46 sajjad wstunnel[3912]: Invalid status code: 400

my server and client commands are:

server: wstunnel server wss://0.0.0.0:8443

client: wstunnel client -L tcp://0.0.0.0:443:localhost:443 -L tcp://0.0.0.0:2083:localhost:2083 wss://cdn.example.com:8443

i have a nginx on server side. Please help me solve this issue.

erebe commented 3 weeks ago

Try with the port 443 first, not sure port 8443 is allowed everywhere.

sajjadnasiribrn commented 3 weeks ago

i cant. 443 is used by nginx. 8443 is allowed from cloudflare. one of the best benefit of wstunnel is that we can point client to the server with a domain behind cloudflare cdn. this feature work in v5 but not in v9. please help me solve this issue.

erebe commented 3 weeks ago

Can you provide the logs of the client and server, and both started with --log-lvl=debug ?

sajjadnasiribrn commented 3 weeks ago

client: Jun 14 08:34:39 sajjad wstunnel[17544]: Invalid status code: 400 Jun 14 08:34:39 sajjad wstunnel[17544]: 2024-06-14T07:34:39.660500Z DEBUG rustls::common_state: Sending warning alert CloseNotify Jun 14 08:34:39 sajjad wstunnel[17544]: 2024-06-14T07:34:39.664319Z ERROR tunnel{id="019015ab-8009-7862-93f2-a75b4207d9fe" remote="localhost:2083"}: wstunnel::tunnel::clie> Jun 14 08:34:39 sajjad wstunnel[17544]: Caused by: Jun 14 08:34:39 sajjad wstunnel[17544]: Invalid status code: 400 Jun 14 08:34:39 sajjad wstunnel[17544]: 2024-06-14T07:34:39.664408Z DEBUG rustls::common_state: Sending warning alert CloseNotify Jun 14 08:34:39 sajjad wstunnel[17544]: 2024-06-14T07:34:39.691875Z INFO wstunnel::tls: Doing TLS handshake using SNI DnsName("p2cdn.ninjav.com") with the server(wss://cdn.example.com:8443) Jun 14 08:34:39 sajjad wstunnel[17544]: 2024-06-14T07:34:39.692072Z DEBUG rustls::client::hs: Resuming session Jun 14 08:34:39 sajjad wstunnel[17544]: 2024-06-14T07:34:39.693402Z INFO wstunnel::tls: Doing TLS handshake using SNI DnsName("p2cdn.ninjav.com") with the server (wss://cdn.example.com:8443) Jun 14 08:34:39 sajjad wstunnel[17544]: 2024-06-14T07:34:39.693544Z DEBUG rustls::client::hs: Resuming session

server: Jun 14 07:33:20 sajjad wstunnel[63451]: Rejecting connection Jun 14 07:33:20 sajjad wstunnel[63451]: CLOSE connection to localhost:443 Jun 14 07:33:21 sajjad wstunnel[63451]: NEW incoming connection from 172.69.151.209:63072 [("X-Forwarded-For","2a0f:2b8:2a:2:1:1:7> Jun 14 07:33:21 sajjad wstunnel[63451]: CONNECTING to localhost:443 Jun 14 07:33:21 sajjad wstunnel[63451]: NEW incoming connection from 162.158.86.114:31240 [("X-Forwarded-For","2a0f:2b84:2a:2:1:1:7> Jun 14 07:33:21 sajjad wstunnel[63451]: CONNECTING to localhost:443 Jun 14 07:33:21 sajjad wstunnel[63451]: NEW incoming connection from 162.158.95.43:64584 [("X-Forwarded-For","95.38.24...")] Jun 14 07:33:21 sajjad wstunnel[63451]: Rejecting connection Jun 14 07:33:21 sajjad wstunnel[63451]: NEW incoming connection from 172.70.243.75:52902 [("X-Forwarded-For","2a0f:2b84:2a:2:1:1:75> Jun 14 07:33:21 sajjad wstunnel[63451]: CONNECTING to localhost:443