目录
主动信息收集简介
主动信息收集通过直接扫描目标主机或者网站,主动方式能获取更多的信息,目标系统可能会记录操作信息。
主动信息收集发现过程
1.识别存活的目标系统或者主机(潜在的攻击目标)。
2.根据osi的分层,主要在2(数据链路层)/3(网络层)/4(传输层)层进行主机发现。
3.输出发现结果。
主动信息收集方式
一、二层发现
原理:使用ARP协议,在网段内进行广播,看是否有回包,或者直接抓包查看
优点:扫描速度快
缺点:只能扫描同一网段
1、ARPING
(1)ARP 协议概述:ARP 协议是“Address Resolution Protocol”(地址解析协议)的缩写。计算机通过 ARP 协议将 IP 地址转换成 MAC 地址。

例 1:对 arping 命令的结果进行筛选,只取 ip 地址的次数,我们只需要 1 次即可
┌──(root💀kali)-[~]
└─# arping -c 1 192.168.1.1 | grep "bytes from" | cut -d" " -f 5 | cut -d "(" -f 2 | cut -d")" -f 1
192.168.1.1
#!/bin/bash
if [ "$#" -ne 1 ];then #判断用户是否输入了至少一个参数如果没有输入参数,输出提示信息并退出
echo "Usage - ./arping.sh [interface]"
echo "Excample - ./arping.sh eth0"
echo "Example will perform an ARP scan of the local subnet to which eth0 is assigned"
exit
fi
interface=$1 #将用户输入的参数传递给interface变量
prefix=$(ifconfig $interface | grep "inet " | cut -d 't' -f 2 | cut -d '.' -f 1-3) #获取本机IP地址网段192.168.1
#对整个网段进行arping
for addr in $(seq 1 254);do
arping -c 1 $prefix.$addr | grep "bytes from" | cut -d" " -f 5 | cut -d "(" -f 2 | cut -d")" -f 1
done
2、netdiscover
二、三层发现
原理:使用ip/icmp协议
优点:相对于二层可以路由
缺点:速度慢(相对于二层),经常被过滤掉
1、Ping
┌──(root💀kali)-[~]
└─# ping www.baidu.com -c 1
PING www.a.shifen.com (36.152.44.96) 56(84) bytes of data.
64 bytes from 36.152.44.96 (36.152.44.96): icmp_seq=1 ttl=54 time=10.2 ms
--- www.a.shifen.com ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 10.221/10.221/10.221/0.000 ms
2、Traceroute
┌──(root💀kali)-[~]
└─# traceroute www.taobao.com
traceroute to www.taobao.com (111.6.93.166), 30 hops max, 60 byte packets
1 192.168.1.1 (192.168.1.1) 1.140 ms 0.991 ms 0.930 ms
2 * * *
3 * 172.206.1.22 (172.206.1.22) 3.061 ms *
4 211.141.219.41 (211.141.219.41) 4.035 ms 3.957 ms 3.914 ms
5 111.38.161.201 (111.38.161.201) 3.851 ms 111.38.161.225 (111.38.161.225) 7.632 ms 111.38.160.101 (111.38.160.101) 3.769 ms
6 221.183.115.117 (221.183.115.117) 3.595 ms 221.183.115.113 (221.183.115.113) 3.170 ms 3.092 ms
7 221.183.113.25 (221.183.113.25) 6.861 ms 221.183.113.21 (221.183.113.21) 6.007 ms 6.152 ms
8 221.183.44.177 (221.183.44.177) 16.049 ms 16.009 ms 17.043 ms
3、Fping
┌──(root💀kali)-[~]
└─# fping -ag 192.168.1.0/24 > fping.txt
4、Hping
Hping能够发送几乎任意的TCP/IP包;
功能强大但是每次只能扫描一个目标。
Hping3发送ICMP包:
命令:hping3 ip地址 --icmp -c 2
,--icmp
指的是发送的包类型,-c
指次数
┌──(root💀kali)-[~]
└─# hping3 192.168.1.103 --icmp -c 2
HPING 192.168.1.103 (eth0 192.168.1.103): icmp mode set, 28 headers + 0 data bytes
len=46 ip=192.168.1.103 ttl=128 id=4528 icmp_seq=0 rtt=4.8 ms
len=46 ip=192.168.1.103 ttl=128 id=4529 icmp_seq=1 rtt=4.1 ms
--- 192.168.1.103 hping statistic ---
2 packets transmitted, 2 packets received, 0% packet loss
round-trip min/avg/max = 4.1/4.5/4.8 ms
三、四层发现
原理:使用TCP/UDP协议
优点:可路由并且可靠、不太可能被防火墙过滤掉
缺点:基于状态过滤的防火墙可能过滤扫描、全端口扫描速度慢
1、NMAP使用及技巧
┌──(root💀kali)-[~]
└─# nmap 192.168.1.109
Starting Nmap 7.91 ( https://nmap.org ) at 2023-03-21 23:08 CST
Nmap scan report for 192.168.1.109
Host is up (0.000079s latency).
Not shown: 996 closed ports
PORT STATE SERVICE
22/tcp open ssh
111/tcp open rpcbind
5003/tcp open filemaker
5555/tcp open freeciv
MAC Address: 00:0C:29:AF:59:19 (VMware)
Nmap done: 1 IP address (1 host up) scanned in 0.08 seconds
┌──(root💀kali)-[~]
└─# nmap -v 192.168.1.109
Starting Nmap 7.91 ( https://nmap.org ) at 2023-03-21 23:10 CST
Initiating ARP Ping Scan at 23:10
Scanning 192.168.1.109 [1 port]
Completed ARP Ping Scan at 23:10, 0.04s elapsed (1 total hosts)
Initiating Parallel DNS resolution of 1 host. at 23:10
Completed Parallel DNS resolution of 1 host. at 23:10, 0.01s elapsed
Initiating SYN Stealth Scan at 23:10
Scanning 192.168.1.109 [1000 ports]
Discovered open port 111/tcp on 192.168.1.109
Discovered open port 22/tcp on 192.168.1.109
Discovered open port 5555/tcp on 192.168.1.109
Discovered open port 5003/tcp on 192.168.1.109
Completed SYN Stealth Scan at 23:10, 0.05s elapsed (1000 total ports)
Nmap scan report for 192.168.1.109
Host is up (0.000071s latency).
Not shown: 996 closed ports
PORT STATE SERVICE
22/tcp open ssh
111/tcp open rpcbind
5003/tcp open filemaker
5555/tcp open freeciv
MAC Address: 00:0C:29:AF:59:19 (VMware)
Read data files from: /usr/bin/../share/nmap
Nmap done: 1 IP address (1 host up) scanned in 0.15 seconds
Raw packets sent: 1001 (44.028KB) | Rcvd: 1001 (40.044KB)
注:生产环境下,我们只需要开启正在提供服务的端口,其他端口都关闭。
┌──(root💀kali)-[~]
└─# nmap -sS -O www.taobao.com
Starting Nmap 7.91 ( https://nmap.org ) at 2023-03-21 23:19 CST
Nmap scan report for www.taobao.com (111.6.93.167)
Host is up (0.021s latency).
Other addresses for www.taobao.com (not scanned): 111.6.93.166 2409:8c44:6100:1000:3::3cd 2409:8c44:6100:1000:3::3ce
Not shown: 998 filtered ports
PORT STATE SERVICE
80/tcp open http
443/tcp open https
Warning: OSScan results may be unreliable because we could not find at least 1 open and 1 closed port
OS fingerprint not ideal because: Missing a closed TCP port so results incomplete
No OS matches for host
OS detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 8.87 seconds

┌──(root💀kali)-[~]
└─# nmap -v --randomize-hosts -p 80 192.168.1.62-69 130 ⨯
Starting Nmap 7.91 ( https://nmap.org ) at 2023-03-21 23:26 CST
Initiating ARP Ping Scan at 23:26
Scanning 8 hosts [1 port/host]
Completed ARP Ping Scan at 23:26, 1.41s elapsed (8 total hosts)
Nmap scan report for 192.168.1.66 [host down]
Nmap scan report for 192.168.1.68 [host down]
Nmap scan report for 192.168.1.62 [host down]
Nmap scan report for 192.168.1.63 [host down]
Nmap scan report for 192.168.1.65 [host down]
Nmap scan report for 192.168.1.64 [host down]
Nmap scan report for 192.168.1.69 [host down]
Nmap scan report for 192.168.1.67 [host down]
Read data files from: /usr/bin/../share/nmap
Nmap done: 8 IP addresses (0 hosts up) scanned in 1.45 seconds
Raw packets sent: 16 (448B) | Rcvd: 0 (0B)
2、Hping3发送TCP/UDP包
Hping3发送udp包:
命令:hing3 ip地址 --udp -c 2
Hping3默认发送TCP包:
命令:hping3 ip地址 -c 2