主机发现

发现主机 Host Discovery

最有效的主机发现方法是使用ICMP echo requests

1
2
3
4
5
6
7
KillMen1@htb[/htb]$ sudo nmap 10.129.2.0/24 -sn -oA tnet | grep for | cut -d" " -f510.129.2.4
10.129.2.10
10.129.2.11
10.129.2.18
10.129.2.19
10.129.2.20
10.129.2.28

此扫描方法仅在主机防火墙允许的情况下才有效。否则,我们可以使用其他扫描技术来查明主机是否处于活动状态。我们将在Firewall and IDS Evasion中仔细研究这些技术。

扫描IP列表 Scan IP List

Nmap为我们提供了使用列表并从此列表中读取主机的选项,而不是手动定义或键入它们(内部渗透直接给了我们主机目标IP List)。

1
2
3
4
5
6
7
KillMen1@htb[/htb]$ cat hosts.lst10.129.2.4
10.129.2.10
10.129.2.11
10.129.2.18
10.129.2.19
10.129.2.20
10.129.2.28

可以把扫描IP和发现主机写进同一行命令中:

1
2
3
KillMen1@htb[/htb]$ sudo nmap -sn -oA tnet -iL hosts.lst | grep for | cut -d" " -f510.129.2.18
10.129.2.19
10.129.2.20

在此示例中,我们看到 7 个主机中只有 3 个处于活动状态。请记住,这可能意味着其他主机由于其防火墙配置而忽略默认的ICMP 回显请求。由于Nmap没有收到响应,它将这些主机标记为不活动。

扫描多个IP

1
2
3
KillMen1@htb[/htb]$ sudo nmap -sn -oA tnet 10.129.2.18-20| grep for | cut -d" " -f510.129.2.18
10.129.2.19
10.129.2.20

扫描单个IP

在扫描单个主机的开放端口及其服务之前,我们首先必须确定它是否处于活动状态。为此,我们可以使用与之前相同的方法。

1
2
3
4
5
KillMen1@htb[/htb]$ sudo nmap 10.129.2.18 -sn -oA hostStarting Nmap 7.80 ( https://nmap.org ) at 2020-06-14 23:59 CEST
Nmap scan report for 10.129.2.18
Host is up (0.087s latency).
MAC Address: DE:AD:00:00:BE:EF
Nmap done: 1 IP address (1 host up) scanned in 0.11 seconds

如果我们禁用端口扫描(-sn),Nmap会使用ICMP回显请求(-PE)自动ping扫描。一旦发送了这样的请求,如果ping主机处于活动状态,我们通常会收到ICMP回复。更有趣的事实是,我们之前的扫描并没有做到这一点,因为在Nmap发送ICMP回显请求之前,它会发送ARP ping,从而得到ARP回复。我们可以通过“--packet trace”选项来确认这一点。为了确保发送ICMP回显请求,我们还为此定义了选项(-PE)。

1
2
3
4
5
6
7
KillMen1@htb[/htb]$ sudo nmap 10.129.2.18 -sn -oA host -PE --packet-trace Starting Nmap 7.80 ( https://nmap.org ) at 2020-06-15 00:08 CEST
SENT (0.0074s) ARP who-has 10.129.2.18 tell 10.10.14.2
RCVD (0.0309s) ARP reply 10.129.2.18 is-at DE:AD:00:00:BE:EF
Nmap scan report for 10.129.2.18
Host is up (0.023s latency).
MAC Address: DE:AD:00:00:BE:EF
Nmap done: 1 IP address (1 host up) scanned in 0.05 seconds

确定 Nmap 为什么将我们的目标标记为“alive”的另一种方法是使用“--reason”选项。

1
2
3
4
5
6
7
KillMen1@htb[/htb]$ sudo nmap 10.129.2.18 -sn -oA host -PE --reason Starting Nmap 7.80 ( https://nmap.org ) at 2020-06-15 00:10 CEST
SENT (0.0074s) ARP who-has 10.129.2.18 tell 10.10.14.2
RCVD (0.0309s) ARP reply 10.129.2.18 is-at DE:AD:00:00:BE:EF
Nmap scan report for 10.129.2.18
Host is up, received arp-response (0.028s latency).
MAC Address: DE:AD:00:00:BE:EF
Nmap done: 1 IP address (1 host up) scanned in 0.03 seconds

我们在这里看到,Nmap确实仅通过ARP请求和ARP回复来检测主机是否存活。 要禁用 ARP 请求并使用所需的 ICMP 回显请求扫描我们的目标,我们可以通过设置“--disable-arp-ping”选项来禁用 ARP ping。 然后我们可以再次扫描目标并查看发送和接收的数据包。

1
2
3
4
5
6
7
KillMen1@htb[/htb]$ sudo nmap 10.129.2.18 -sn -oA host -PE --packet-trace --disable-arp-ping Starting Nmap 7.80 ( https://nmap.org ) at 2020-06-15 00:12 CEST
SENT (0.0107s) ICMP [10.10.14.2 > 10.129.2.18 Echo request (type=8/code=0) id=13607 seq=0] IP [ttl=255 id=23541 iplen=28 ]
RCVD (0.0152s) ICMP [10.129.2.18 > 10.10.14.2 Echo reply (type=0/code=0) id=13607 seq=0] IP [ttl=128 id=40622 iplen=28 ]
Nmap scan report for 10.129.2.18
Host is up (0.086s latency).
MAC Address: DE:AD:00:00:BE:EF
Nmap done: 1 IP address (1 host up) scanned in 0.11 seconds

更多主机发现策略:https://nmap.org/book/host-discovery-strategies.html