之前在Linux和window通信。除了自己寫代碼之外,利用好的工具也是個不錯的方法。
作為小白,研究了一個比較的好工具,雖然了解不是很深,寫下記錄:
首先我們安裝現在netcat:
轉發大神:
https://www.aliyun.com/jiaocheng/123561.html
安裝後我們就可以利用netcat來作為伺服器,在Linux 上監聽你想的端口。
nc -l 12345 > httpRequset
其中 -l,應該是HostAddress::Any ,12345 為port号。httpRequset為收到資訊寫入的檔案。
如果想用回複,那麼我們還寫一些東西,這裡是簡單HTTP例子:
( echo -ne "HTTP/1.1 200 Ok\r\nContent-Length: 11\r\n"; echo -ne "\r\nHello World" ) | nc -l 12345 > httpRequset
echo 即輸入輸出,輸出傳回值。
這樣進行循環監視,sh腳本是個好東西 ./test.sh
#/bin/sh
while true
do
( echo -ne "HTTP/1.1 200 Ok\r\nContent-Length: 11\r\n"; echo -ne "\r\nHello World" ) | nc -l 12345 > httpRequset
done
我們來分部解析最簡單來的HTTP請求:
nc -l 12345 > httpRequset.txt
收到資訊寫入httpRequset.txt
cat httpRequset.txt | grep "head" > 1.txt
找到收到資訊中的head字段,由于我發的是http,Http頭中有 字段 head: ifno, info中資訊是用base64編碼的。
解析之後寫入1.txt
cat 1.txt | awk -F'[:]' '{print $2}' > 2.txt
讀取1.txt 按照冒号截斷,并且取第二位,也是其中info,寫入2.txt
cat 2.txt | base64 -di > 3.txt
讀取 2.txt資料, base64來解讀, -d 代表把base64字元轉換原資料,-i表示去除無用的除字母以外字元,檔案裡包含的空格字元,比較有用。 然後把翻譯資料寫道3.txt中。
當然有用資料可以寫到管道裡
mkfifo /tmp/my_fifo
cat 2.txt | base64 -di > /tmp/my_fifo
test.sh
#/bin/sh
while true
do
( echo -ne "HTTP/1.1 200 Ok\r\nContent-Length: 11\r\n"; echo -ne "\r\nHello World" ) | nc -l 12345 > httpRequset
cat httpRequset | grep "target" | awk -F'[:]' '{print $2}' | base64 -di > /tmp/okism_fifo
done
netcat 作為開源的,号稱黑客必備,網絡界的瑞士軍刀,作用還有好多,以後還得學習