vi / websocat

Command-line client for WebSockets, like netcat (or curl) for ws:// with advanced socat-like functions
MIT License
6.71k stars 257 forks source link

Please add support for specifying a proxy server #15

Open NoahAndrews opened 5 years ago

NoahAndrews commented 5 years ago

I wanted to use websocat to help me file a bug report in OWASP ZAP, but I can't do that unless I can point it at the ZAP proxy endpoint. This would be useful for other things as well, of course.

vi commented 5 years ago

Such option is a good idea.

For now you can use websocat with HTTP CONNECT proxy by combining it with socat:

websocat -t --ws-c-uri=ws://lol/ - ws-c:cmd:'socat - proxy:127.0.0.1:lol:80,proxyport=1234'

For SOCKS proxy you can analogously combine it with corkscrew or connect-proxy.

vi commented 5 years ago

Implemented --socks5 (and also some low-level) option. Without auth yet, and no HTTP connect proxy yet although.

$ target/debug/websocat -v  ws://echo.websocket.org --socks5=127.0.0.1:1080 
 INFO 2018-08-28T23:09:09Z: websocat::lints: Auto-inserting the line mode
 INFO 2018-08-28T23:09:09Z: websocat::sessionserve: Serving Line2Message(Stdio) to Message2Line(WsConnect(SocksProxy(TcpConnect(V4(127.0.0.1:1080))))) with Options { ..., ws_c_uri: "ws://echo.websocket.org", socks_destination: Some(SocksSocketAddr { host: Name("echo.websocket.org"), port: 80 }), auto_socks5: Some(V4(127.0.0.1:1080)) }
 INFO 2018-08-28T23:09:09Z: websocat::stdio_peer: get_stdio_peer (async)
 INFO 2018-08-28T23:09:09Z: websocat::stdio_peer: Setting stdin to nonblocking mode
 INFO 2018-08-28T23:09:09Z: websocat::stdio_peer: Installing signal handler
 INFO 2018-08-28T23:09:09Z: websocat::net_peer: Connected to TCP
 INFO 2018-08-28T23:09:09Z: websocat::proxy_peer: Connected though the SOCKS5 proxy from SocksSocketAddr { host: Ip(V4(0.0.0.0)), port: 0 }
 INFO 2018-08-28T23:09:09Z: websocat::ws_client_peer: get_ws_client_peer_wrapped
 INFO 2018-08-28T23:09:09Z: websocat::ws_client_peer: Connected to ws
qwer
qwer
as  
as
 INFO 2018-08-28T23:09:14Z: websocat::sessionserve: Forward finished
 INFO 2018-08-28T23:09:14Z: websocat::sessionserve: Forward shutdown finished
 INFO 2018-08-28T23:09:14Z: websocat::sessionserve: Reverse finished
 INFO 2018-08-28T23:09:14Z: websocat::sessionserve: Reverse shutdown finished
 INFO 2018-08-28T23:09:14Z: websocat::sessionserve: Finished
 INFO 2018-08-28T23:09:14Z: websocat::stdio_peer: Restoring blocking status for stdin
 INFO 2018-08-28T23:09:14Z: websocat::stdio_peer: Restoring blocking status for stdin
NoahAndrews commented 5 years ago

wow, that was fast! Very cool :)

vi commented 5 years ago

Added an advanced feature to open ports remotely at SOCKS5 server side to accept websocket connections.

anfuse commented 5 years ago

For SOCKS proxy you can analogously combine it with corkscrew or connect-proxy.

I am afraid, corkscrew only works with HTTP proxies.

vi commented 5 years ago

connect-proxy works with both.

toonetown commented 5 years ago

The given command:

websocat -t --ws-c-uri=ws://echo.websocket.org/ - ws-c:cmd:'socat - proxy:127.0.0.1:echo.websocket.org:80,proxyport=1234'

works for proxying ws:// over an HTTP proxy - however, is there a way to tunnel wss:// over the same proxy? I tried this command:

websocat -t --ws-c-uri=wss://echo.websocket.org/ - ws-c:cmd:'socat - proxy:127.0.0.1:echo.websocket.org:443,proxyport=1234'

but it appears to just be connecting the non-secure ws:// protocol anyway.

vi commented 5 years ago

@toonetown

websocat -t --ws-c-uri=wss://echo.websocket.org/ - ws-c:ssl-connect:cmd:'socat - proxy:127.0.0.1:echo.websocket.org:443,proxyport=1234'

?

toonetown commented 5 years ago

Yes - that does work!

toonetown commented 5 years ago

I'd like to suggest the (possible) option of specifying --proxy on the command line for http and https proxies as well (the option exists for socks proxy). However, the ws-c:... command options are a great workaround.

vi commented 5 years ago

Usage of HTTP CONNECT proxies is not yet implemented inside websocat. I'll consider your comment as a vote to implement this feature.