一、基础知识
Traceroute应用了IP协议TTL字段,每经过一次转发会TTL减一,减少到0的时候,结点会回送超时的ICMP报文,这样就可以探测到经过了哪些结点。在Windows下指令tracert用ICMP协议,而Linux下指令是traceroute用高端口的UDP协议(更容易被防火墙过滤),基本原理就是这样,但是由于有些结点会设置为不回复此类型ICMP或者防火墙过滤了,会导致traceroute失效。所以一些工具又加入了TCP traceroute,用80端口SYN追踪。
二、虚拟机NAT下traceroute
环境:虚拟机NAT模式,虚拟机Kali,实体机win7.
1.traceroute www.baidu.com
图1、虚拟机抓包traceroute
图2、实体机抓包traceroute
分析:转发出去只是源端口改变了,会得到超时的回应,但是主机不给虚拟机回复。所以traceroute失败。
2.tcptraceroute baidu.com
图3、虚拟机tcptraceroute
图4、实体机tcptraceroute
分析:虚拟机是源端口5位数,TTL依次加1,主机抓到的是TTL固定为64,源端口改为了4位数。由于NAT改变了TCP协议下层的TTL,所以直接tcptraceroute出了最后的结果。另外校验和也置为了0,发的时候自动计算。(为什么wireshark这次抓到的校验和没有算呢?本机发送的TCP计算过了。)
3.ping
图5、虚拟机ping
图6、实体机ping
分析:虚拟机中的ping可以正常工作,主机抓包显示转发只改变了IP。
通过以上现象,可以观察到NAT不转发ICMP出错报文给内部主机,并且会修改上层协议是TCP协议的TTL,从而导致traceroute无法使用。NAT是通过这样的依据端口的映射转发的,如下图:
图7、NAT地址转换
但是为什么UDP的traceroute也会失败呢?一切根源应该还是在于无法接转发ICMP错误报文;所以在虚拟机NAT下使用Kali等还是受限的。
RFC5508
7.2. Time Exceeded Message
A NAT device MUST generate a "TimeExceeded" ICMP Error message when
it discards a packet due to an expired Timeto Live (TTL) field. A
NAT device MAY have a per-interface optionto disable origination of
these messages on that interface, but thatoption MUST default to
allowing the messages to be originated.
When a NAT device conforms to the aboverequirement, it ensures that
legacy applications such as Traceroute[RFC1470], [MS-TRCRT], which
depend upon the "Time Exceeded"ICMP Error message, will continue to
operate even as NAT devices are en route.