vi / websocat

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

SUPPORT / REQUEST #51

Closed yarglah closed 5 years ago

yarglah commented 5 years ago

Hi,

First thanks for this tool ! I use it in many context (client / serveur / windows / Linux) for tests or POC purpose.

Is there a way for a program run by websocat (--exec) to get HTTP headers (I wish to get cookies) ? Websocket server display headers with -v -v option, but I can't found a way to get them in my bash script:

websocat -v -v -e --exit-on-eof --text l-ws:0.0.0.0:3009 exec:/WS_user.sh --exec-args websocket [INFO websocat::lints] Auto-inserting the line mode ... [INFO websocat::net_peer] Incoming TCP connection from Some(V4(172.17.0.1:43036)) [DEBUG websocat::sessionserve] Underlying connection established [INFO websocat::sessionserve] Serving 1 ongoing connections [INFO websocat::ws_server_peer] Incoming connection to websocket: /wsock [DEBUG websocat::ws_server_peer] Incoming { version: Http11, subject: (Get, AbsolutePath("/wsock")), headers: Headers { Upgrade: websocket , Connection: upgrade , Host: wtb_admin:3009 , Cookie: AUTH_TOKEN=80d02638a3cec601e7fbe0cdf6ecc5f4ccb3cce5 , Sec-WebSocket-Version: 13 , Sec-WebSocket-Key: PhjBHwNbV5p4+1dg5agWjA== , } } [DEBUG websocat::ws_server_peer] Headers { } [DEBUG websocat::ws_server_peer] Headers { Sec-WebSocket-Accept: m+ZXqcHuSXeSb3tre38wz+oW1pQ= , Connection: Upgrade , Upgrade: websocket , } [INFO websocat::ws_server_peer] Upgraded

From client

websocat -H "Cookie: AUTH_TOKEN=80d02638a3cec601e7fbe0cdf6ecc5f4ccb3cce5" -k wss://endpoint/wsock CONNECT from 172.17.0.1:43036 WEBSOCAT_URI=/wsock WEBSOCAT_CLIENT=172.17.0.1:43036 SHLVL=2

Script:

echo CONNECT from ${WEBSOCAT_CLIENT} env

vi commented 5 years ago

I'm cooking Websocat 2.0.0 now, and maybe I'll add an option to selectively forward headers to environment variables when executing scripts. Note that it may be not very secure do you things like shellshock.

Maybe I can also try making a special build for you that just forwards all headers. Which platform do you need?

yarglah commented 5 years ago

Hi,

I'm aware that bash must be robustified, but it's only for POC devlopments. I use Debian x64 (websocat_1.4.0_ssl1.1_amd64.deb).

Thanks !

vi commented 5 years ago

Prepared a special build: https://vi-server.org/pub/websocat_headers_1.4.0_amd64.deb

The source code is in all_headers_forward branch.

% websocat -Eeb ws-l:0.0.0.0:1234 sh-c:env

$ websocat -H 'Qqq: Www' -Eb ws://127.0.0.1:1234/ | grep H_
H_Upgrade=websocket
H_Host=127.0.0.1:1234
H_Connection=Upgrade
H_Qqq=Www

It is not certain that this feature will be implemented in Websocat 2.0 as is. Probably explicit header list will be required and values may be base64-encoded.

yarglah commented 5 years ago

What a reactivity. Very impressive.

I will test it tomorrow.

Thanks !

yarglah commented 5 years ago

It works perfectly.

vi commented 4 years ago

@yarglah, Released v1.5.0 with --header-to-env option.

It is less flexible than "headers" version, as you need to explicitly specify which headers to forward.

yarglah commented 4 years ago

Thank you very much Vitaly.

Have a nice day.