erebe / wstunnel

Tunnel all your traffic over Websocket or HTTP2 - Bypass firewalls/DPI - Static binary available
Other
3.17k stars 287 forks source link

Difference in headers when using headers in file and --http-headers + can't use space in headers --http-headers when used with ssh #230

Closed AnorBanantje closed 2 months ago

AnorBanantje commented 2 months ago

Describe the bug when i use --http-headers www.example.com it is in request as :authority: www.example.com but when i save "Host:www.example.com" in headers.txt and use --http-headers-file headers.txt this header is added to request as new header no update for :authority:

Wireshark request with --http-headers www.example.com :method: POST :scheme: http :authority: www.example.com :path: /v1/events cookie: XXX... content-type: application/json

:status: 200 content-type: application/json date: Wed, 14 Feb 2024 21:21:55 GMT

Wireshark request with --http-headers-file headers.txt :method: POST :scheme: http :authority: 127.0.0.1:8080 :path: /v1/events cookie: XXX... content-type: application/json host: www.example.com

:status: 200 content-type: application/json date: Wed, 14 Feb 2024 21:27:50 GMT

To Reproduce .\wstunnel.exe server http://0.0.0.0:8080

Start Wireshark -> Execute client commands: ssh -o ProxyCommand=".\wstunnel.exe client --http-headers Host:www.example.com -L stdio://%h:%p http://127.0.0.1:8080" user@192.168.0.2 -p 22

ssh -o ProxyCommand=".\wstunnel.exe client --http-headers-file headers.txt -L stdio://%h:%p http://127.0.0.1:8080" user@192.168.0.2 -p 22

Expected behavior both options must give same result.

Screenshots

Desktop (please complete the following information): Windows wstunnel.exe

Additional context When using ProxyCommand for ssh can't add headers which have spaces like user-agent from browser. I found that best is mixing both options: --http-headers Host:www.example.com --http-headers-file headers.txt

In headers.txt e.q.: user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x86; rv:100.0) Gecko/20100101 Firefox/122.0 accept: text/html,application/xhtml+xml,application/xml accept-language: en-US,en;q=0.5 accept-encoding: gzip upgrade-insecure-requests: 1 sec-fetch-dest: document sec-fetch-mode: navigate sec-fetch-site: none sec-fetch-user: ?1 te: trailers

Example command: ssh -o ProxyCommand=".\wstunnel.exe client --http-headers Host:www.example.com --http-headers-file headers.txt --tls-sni-override www.example.com --http-upgrade-path-prefix SuperSecret --websocket-mask-frame -L stdio://%h:%p https://example.com" user@server -p 22

Now is need only auto count content-length to make this traffic close to real http2 which i sniffed from browser over content-length i made another feature request here.

erebe commented 2 months ago

Hello,

Thanks for reporting, would you mind trying this pre-release and let me know if it is ok. It will use Host header as authority also https://github.com/erebe/wstunnel/releases/tag/v9.2.3

Regarding the whitespace, I suppose it is when you try to pass headers from the command line ? I think you need to use quote and escape them from as you are inside the proxyCommand

AnorBanantje commented 2 months ago

got error no connection was made with v9.2.3 Starting STDIO server thread 'tokio-runtime-worker' panicked at C:\Users\runneradmin.cargo\registry\src\index.crates.io-6f17d22bba15001f\http-1.0.0\src\header\name.rs:1270:13: index out of bounds: the len is 0 but the index is 0 note: run with RUST_BACKTRACE=1 environment variable to display a backtrace kex_exchange_identification: Connection closed by remote host

with v9.2.3 with same command everything was fine.

Yes i tried to pass headers from command line, tried to escape with ` and \ didn't help so workaroud work fine.

erebe commented 2 months ago

Alright it should be fixed, would you mind retrying ? https://github.com/erebe/wstunnel/releases/tag/v9.2.3 (I have updated the binaries)

AnorBanantje commented 2 months ago

Is beter but not perfect. it works but it makestwo headers now host: example.com and :authority: example.com

--http-headers Host:example.com makes only :authority: example.com

erebe commented 2 months ago

Should be fixed in the latest 9.2.3 release