Answers:
nmap
轻松做到这一点:
sudo nmap --script broadcast-dhcp-discover -e eth0
将会呈现:
Starting Nmap 6.40 ( http://nmap.org ) at 2016-08-16 09:25 UTC
Pre-scan script results:
| broadcast-dhcp-discover:
| IP Offered: 192.168.14.67
| DHCP Message Type: DHCPOFFER
| Server Identifier: 192.168.14.1
| IP Address Lease Time: 0 days, 0:05:00
| Subnet Mask: 255.255.255.0
| Router: 192.168.14.1
| Domain Name Server: 193.190.127.150
| Domain Name: maas
| Broadcast Address: 192.168.14.255
|_ NTP Servers: 91.189.91.157, 91.189.89.199, 91.189.94.4, 91.189.89.198
WARNING: No targets were specified, so 0 hosts scanned.
Nmap done: 0 IP addresses (0 hosts up) scanned in 0.27 seconds
如果在存储库中可用,则有dhcpdump
从手册页:
SYNOPSIS
dhcpdump [-h regular-expression] -i interface
DESCRIPTION
This command parses the output of tcpdump to display the dhcp-packets for easier checking and debugging.
USAGE
dhcpdump -i /dev/fxp0
If you want to filter a specific Client Hardware Address (CHADDR), then you can specifiy it as a regular expressions:
dhcpdump -i /dev/fxp0 -h ^00:c0:4f
This will display only the packets with Client Hardware Addresses which start with 00:c0:4f.
如果您tcpdump
有空,请使用以下参数以root用户身份调用程序,以帮助您查找服务器:
tcpdump -i [接口ID] -nev udp端口68
不幸的是,由于网络的布局,我无法立即捕获到完整的DHCP握手。但是,我确实从我的iPad上看到了DHCP请求:
22:16:44.767371 30:10:e4:8f:02:14 > ff:ff:ff:ff:ff:ff, ethertype IPv4 (0x0800), length 342: (tos 0x0, ttl 255, id 15652, offset 0, flags [none], proto UDP (17), length 328)
0.0.0.0.68 > 255.255.255.255.67: BOOTP/DHCP, Request from 30:10:e4:8f:02:14, length 300, xid 0x42448eb6, Flags [none]
Client-Ethernet-Address 30:10:e4:8f:02:14
Vendor-rfc1048 Extensions
Magic Cookie 0x63825363
DHCP-Message Option 53, length 1: Request
Parameter-Request Option 55, length 6:
Subnet-Mask, Default-Gateway, Domain-Name-Server, Domain-Name
Option 119, Option 252
MSZ Option 57, length 2: 1500
Client-ID Option 61, length 7: ether 30:10:e4:8f:02:14
Requested-IP Option 50, length 4: 192.168.2.222
Lease-Time Option 51, length 4: 7776000
Hostname Option 12, length 15: "NevinWiamssiPad"
在让“ tcpdump”运行了一整夜之后,我确实看到了这个ACK:
07:46:40.049423 a8:39:44:96:fa:b8 > 68:a8:6d:58:5b:f3, ethertype IPv4 (0x0800), length 320: (tos 0x0, ttl 64, id 0, offset 0, flags [none], proto UDP (17), length 306)
192.168.2.1.67 > 192.168.2.22.68: BOOTP/DHCP, Reply, length 278, xid 0x5e7944f, Flags [none]
Client-IP 192.168.2.22
Your-IP 192.168.2.22
Client-Ethernet-Address 68:a8:6d:58:5b:f3
Vendor-rfc1048 Extensions
Magic Cookie 0x63825363
DHCP-Message Option 53, length 1: ACK
Server-ID Option 54, length 4: 192.168.2.1
Lease-Time Option 51, length 4: 86400
Subnet-Mask Option 1, length 4: 255.255.255.0
Default-Gateway Option 3, length 4: 192.168.2.1
Domain-Name-Server Option 6, length 8: 192.168.2.1,142.166.166.166
如果在运行该tcpdump
命令时看到BOOTP / DHCP Offer或Ack(Nack),它将来自DHCP服务器,并且服务器的MAC地址将在第一行的时间戳之后。
因此,这里的(有效)DHCP服务器具有MAC地址a8:39:44:96:fa:b8`。
使用Web上许多MAC地址查找工具之一,我看到此MAC属于A8:39:44 Actiontec Electronics, Inc
我的路由器。
为了及时捕获流氓DHCP服务器数据包,我必须让此tcpdump
过程在终端窗口中运行:
tcpdump -i en0 -nev udp src port 67 and not ether host a8:39:44:96:fa:b8
只要进程在其自己的窗口中运行,这只会向我显示来自除我的有效DHCP服务器之外的主机的DHCP服务器响应。
以下命令将在后台运行,直到捕获到100个数据包,并将所有恶意DHCP服务器消息附加到该文件/tmp/rogue
。同样,必须在适当的位置使用有效的DHCP服务器的MAC地址以及系统上的接口描述符。
tcpdump -U -i en0 -c 100 -nev udp src port 67 and not ether host a8:39:44:96:fa:b8 >> /tmp/rogue 2>&1 &
`
tcpdump
命令保持运行状态,它将显示通过与您的DHCP服务器不同的MAC地址发送的DHCP服务器数据包。当然,您需要在指定的位置提供地址...为了得到更好的格式,我现在将其放在我的答案中。
如果有足够的时间,则可以被动进行检测:回想一下,初始化客户端发出DHCPDISCOVER广播。如果dhcpserver可用,它将获得一个报价,然后发出(再次广播!)DHCPREQUEST。从而
前两点的成功揭露了新连接/启动到网络的其他主机的数量以及租用时间。
您可以尝试创建别名设备,并在测试模式下使用dhcp客户端,在该模式下,它会打印出任何响应,而无需实际重新配置接口:
ifconfig eth0:1 up
dhclient -w -n eth0:1
我只能访问一个debian机器,因此,如果您有另一个dhcp实现,则dry-run选项可能会有所不同,例如dhcpcd:
dhcpcd -T eth0:1
我曾经用这样的程序运行过cron脚本,它将使管理员(me!)警惕流氓dhcp服务器。
ifconfig eth0:1 up
输出时SIOCSIFFLAGS: Cannot assign requested address