Ping并使用三个八位字节ipv4地址.为什么它有效



意外地,我有一个拼写错误,发现我可以ping和ssh到IP地址10.8.290。。。右边缺少一个八位字节。有人能给我解释一下吗?这是协议的一部分还是linux的一些黑魔法(我使用的是Debian)?

user@ws:~$ ping -c3 10.8.290
PING 10.8.290 (10.8.1.34) 56(84) bytes of data.
64 bytes from 10.8.1.34: icmp_req=1 ttl=62 time=0.910 ms
64 bytes from 10.8.1.34: icmp_req=2 ttl=62 time=0.686 ms
64 bytes from 10.8.1.34: icmp_req=3 ttl=62 time=0.708 ms
--- 10.8.290 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 1998ms
rtt min/avg/max/mdev = 0.686/0.768/0.910/0.100 ms
user@ws:~$ ssh root@10.8.290
The authenticity of host '10.8.290 (10.8.1.34)' can't be established.
ECDSA key fingerprint is 21:bd:7e:fb:1e:6d:1e:c1:e9:11:c0:a9:73:a8:cf:85.
Are you sure you want to continue connecting (yes/no)? no
Host key verification failed.

它之所以有效,是因为您正在为ip地址的第三个字节使用值290。一个字节可以存储从0255的值,从而给出256的值。由于IPv4地址是一个4字节的值,将290传递到第三个字节会导致整数溢出到第四个字节->290-256=>34

它与协议"功能"无关。ping只是不验证target命令行参数的各个八位字节的值,而是简单地将其传递给较低级别的C函数inet_aton()(aton表示数字的ascii)。这将导致ping 10.8.1.34

我不确定,但我预计其他版本的ping(在Windows、BSD上)也会有同样的表现。

最新更新