我正在使用socat. 開始簡單,我script.sh在下面使用,但它也適用于客戶端bash(用于反向 shell)、python、vim、irssi等。
我想監控客戶端的活動,所以我嘗試-v了服務器端的詳細選項。
程式script.sh:
#!/bin/bash
while read -p 'Tell me something: ' MSG;
do
echo "I got $MSG";
done
服務器:
socat -v tcp-listen:9099,reuseaddr exec:script.sh,pty,stderr,setsid,sane
客戶:
socat tcp-connect:IP:9099 file:$(tty),rawer
socat它可以作業,但是由于生成詳細輸出的方式,結果是不可讀的。
客戶看到的:
Tell me something: hello
I got hello
socat服務器端的詳細輸出:
< 2022/06/06 00:17:59.920945 length=19 from=0 to=18
Tell me something: > 2022/06/06 00:18:01.716074 length=1 from=0 to=0
h< 2022/06/06 00:18:01.716317 length=1 from=19 to=19
h> 2022/06/06 00:18:01.935165 length=1 from=1 to=1
e< 2022/06/06 00:18:01.935401 length=1 from=20 to=20
e> 2022/06/06 00:18:02.176460 length=1 from=2 to=2
l< 2022/06/06 00:18:02.176874 length=1 from=21 to=21
l> 2022/06/06 00:18:02.303743 length=1 from=3 to=3
l< 2022/06/06 00:18:02.304001 length=1 from=22 to=22
l> 2022/06/06 00:18:02.454156 length=1 from=4 to=4
o< 2022/06/06 00:18:02.454555 length=1 from=23 to=23
o> 2022/06/06 00:18:03.693822 length=1 from=5 to=5
\r< 2022/06/06 00:18:03.694050 length=2 from=24 to=25
\r
< 2022/06/06 00:18:03.694373 length=32 from=26 to=57
I got hello\r
當與帶有顏色和 UI 的程式一起使用時——比如vim——由于顏色和互動性,事情變得非常不可用:
這是服務器端的 vim 歡迎訊息:
.[21;1H~
.[22;1H~
.[m.[38;5;253m.[48;5;234m.[23;1H.[38;5;247m.[48;5;235m[No Name]
0,0-1 All.[m.[38;5;253m.[48;5;234m.[6;32HVIM - Vi IMproved.[8;33Hversion 8.1.3741.[9;29Hby Bram Moolenaar et al..[10;21HModified by team [email protected].[11;19HVim is open source and freely distributable.[13;26HBecome a registered Vim user!.[14;18Htype :help register.[38;5;238m<Enter>.[m.[38;5;253m.[48;5;234m for information .[16;18Htype :q.[38;5;238m<Enter>.[m.[38;5;253m.[48;5;234m to exit .[17;18Htype :help.[38;5;238m<Enter>.[m.[38;5;253m.[48;5;234m or .[38;5;238m<F1>.[m.[38;5;253m.[48;5;234m for on-line help.[18;18Htype :help version8.[38;5;238m<Enter>.[m.[38;5;253m.[48;5;234m for version info.[1;5H.[?25h> 2022/06/06 01:59:24.565253 length=6 from=0 to=5
.[2;2R> 2022/06/06 01:59:24.565700 length=10 from=6 to=15
.[>0;10;1c
我怎樣才能在服務器端看到盡可能接近客戶端看到的東西?我更喜歡使用socat,因為下一步將使用 SSL 對其進行加密。
我試圖通過管道將它傳遞給
grep -v "<",弄亂icanon作為socat引數和做stty -icanon && socat -v tcp-l...,使用cut -c 1和sed 's/\(.\).*/\1/'提取第一個字符,但仍然無法找到解決方案。
uj5u.com熱心網友回復:
從 Socat 版本 1.7.4.2 開始,有一些合理的作業選項可以獲取資料流的 1:1 副本:
-r /path/to/file1 # copy of left-to-right
-R /path/to/file2 # copy of right-to-left
顯然他們沒有找到進入手冊頁的方式,但顯示為 socat -h
您仍然可能需要剝離終端控制序列,或嘗試將資料通過管道傳輸到 less -R 或 less -r
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/489129.html
