f10@t's blog

Metasploit渗透测试魔鬼训练营-信息收集

字数统计: 3.5k阅读时长: 16 min
2019/02/04

外围信息收集技术 OSINT(OpenSource INTelligence)

通过DNS和IP地址挖掘信息

whois 域名注册信息查询

可以在msfconsole终端中进行查询,如:

msfconsole

nslookup和dig域名查询

区别:后者可以从该域名的官方DNS服务器上查到精确的权威解答,而前者只能得到DNS接媳妇而起保存在Cache中的非权威解答

  • nslookup结果:

  • dig结果:

  • IP2Location地理位置查询。一些网站提供了IP到地理位置的查询服务

  • GeoIP服务。可通过这个网站上的经纬度,使用google地图进行定位

  • QQc纯真数据库。这个常使用在国内IP查询

netcraft网站提供的信息查询服务

该网站中可以枚举出网站的子节点,如图为testfire.net结果:

该网站亦可查询关于网站和服务器更为详细的信息,如地理位置、域名服务器地址、服务器操作系统类型、服务器运行状况等。网址:https://toolbar.netcraft.com/site_report?url=xxx.com

IP2Domain反查域名

加入你的对象是多个虚拟主机,由于他们都是运行在一台机器上的,所以通常共用一个IP地址。我们可以通过IP反查到的机器的域名信息,网址:http://www.ip-address.com/reverse_ip/

国内也有提供反查询的网站,其结果针对国内更加精确:http://www.7c.com/

搜索引擎信息收集

Google Hacking技术

工具:SiteDigger: http://www.mcafee.com/us/downloads/free-tools/sitedigger.aspx

search Diggty: http://www.stachliu.com

获取网站的目录结构

  1. 方法一:Google搜索

使用一些google hacking的关键字如:parent directory site:testfire.net。留意一下关键字:

1
2
3
.inc: 包含一些网站的配置信息
.bak: 通常是一些文本编辑器在编辑源代码后留下的备份文件
.txt或.sql: 一般是包含网站运行的SQL脚本,可能会透露类似数据库结构等信息

  1. 方法二:使用msf

msf中的brute_dirs、dir_listing、dir_scanner等辅助模块,主要使用暴力猜解的方式。如我扫描OWASP虚拟机的结果: dir_scanner

检索特定类型文件

同样使用Google Hacking技术,使用关键字搭配,基本语法是operator:search_term ,下面是几个常用操作词:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
intitle操作符: 
将会返回title中含有关键字的页面
例如intitle:Google将会返回标题中含有Google的页面
intitle:"Index of"将会返回标题中含有Index of的页面

site操作符:
把结果范围缩小到指定的网站,域名或子域中
例如news site:yahoo.com将会显示在yahoo网站或子域中的news

inurl操作符:
将会返回url中含有关键字的页面
例如inurl:contactus site:www.MySite.com将会返回Mysite中url里面含有contactus的页面

filetype操作符:
搜索特定文件扩展名的页面。
例如filetype:pdf site:yahoo.com返回yahoo.com中指向pdf文件的url

搜索网站中的E-mail地址

msf的辅助模块中search_email_collecter,只需要提供一个邮箱后缀(域名),他就可以通过多个搜索引擎的查询结果分析使用还后缀的邮件地址,使用改模块可以很方便的获取某个机构的大量邮件地址。

搜索易存在SQL注入点的页面

仍使用Google Hacking技术,搭配关键字。如:site:testfire.net inurl:login,就可搜索到其后台登录页面:

IP路由侦查

很多网站的IP查询结果不够准确,如总部在北京,IP查完在广东,此时我们需要使用traceroute工具来进行路由侦查,获取其真实IP。

主机探测与端口扫描

以下实验均在上篇搭建的环境中进。这里再贴上拓扑图:

活跃主机扫描

  1. ICMP Ping命令

Ping全称(Packet Internet Grope)因特网包探索器。我们已知了对方的域名是www.dvssc.com(实验用),我们通过Ping来获得它的IP地址:

  1. Metasploit活跃主机扫描

在msf辅助模块中提供了一些扫描活跃主机的模块,位于/modules/auxiliary/scanner/discovery/目录:       

常用的两个模块:

1
2
arp_sweep: 使用ARP请求枚举本地局域网络中所有活跃主机。
udp_sweep: 发送UDP数据包来侦查指定主机是否活跃,并发现上面的UDP服务。
arp_sweep实质就是ARP扫描器,下面是使用方法和结果:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
msf5 > search arp_sweep

Matching Modules
================

Name Disclosure Date Rank Check Description
---- --------------- ---- ----- -----------
auxiliary/scanner/discovery/arp_sweep normal Yes ARP Sweep Local Network Discovery


msf5 > use auxiliary/scanner/discovery/arp_sweep
msf5 auxiliary(scanner/discovery/arp_sweep) > options

Module options (auxiliary/scanner/discovery/arp_sweep):

Name Current Setting Required Description
---- --------------- -------- -----------
INTERFACE no The name of the interface
RHOSTS yes The target address range or CIDR identifier
SHOST no Source IP Address
SMAC no Source MAC Address
THREADS 1 yes The number of concurrent threads
TIMEOUT 5 yes The number of seconds to wait for new data

msf5 auxiliary(scanner/discovery/arp_sweep) > set THREADS 50
THREADS => 50
msf5 auxiliary(scanner/discovery/arp_sweep) > set RHOSTS 10.10.10.0/24
RHOSTS => 10.10.10.0/24
msf5 auxiliary(scanner/discovery/arp_sweep) > run

[+] 10.10.10.1 appears to be up (VMware, Inc.). # 宿主主机上的网卡
[+] 10.10.10.2 appears to be up (VMware, Inc.). # 宿主主机上的网卡
[+] 10.10.10.129 appears to be up (VMware, Inc.).
[+] 10.10.10.130 appears to be up (VMware, Inc.).
[+] 10.10.10.254 appears to be up (VMware, Inc.).
[*] Scanned 256 of 256 hosts (100% complete)
[*] Auxiliary module execution completed
算上我的攻击机10.10.10.128,在该DMZ区活动的共有四台机器。

  1. 用nmap进行主机探测

Nmap(Network mapper)是目前最流行的网络扫描器。在msf中也提供了nmap的接口。如果只是要发现DMZ区的存活主机,使用-sn参数即可:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
msf5 > nmap -sn 10.10.10.0/24
[*] exec: nmap -sn 10.10.10.0/24

Starting Nmap 7.70 ( https://nmap.org ) at 2019-02-05 21:57 CST
Nmap scan report for 10.10.10.1
Host is up (0.00037s latency).
MAC Address: 00:50:56:C0:00:08 (VMware)
Nmap scan report for 10.10.10.2
Host is up (0.00020s latency).
MAC Address: 00:50:56:F6:FD:F5 (VMware)
Nmap scan report for www.dvssc.com (10.10.10.129) # 门户网页
Host is up (0.00036s latency).
MAC Address: 00:0C:29:C5:A6:2B (VMware)
Nmap scan report for service.dvssc.com (10.10.10.130) # 后台服务器
Host is up (0.00050s latency).
MAC Address: 00:0C:29:09:18:C6 (VMware)
Nmap scan report for gate.dvssc.com (10.10.10.254) # 定V公司网关
Host is up (0.00077s latency).
MAC Address: 00:0C:29:F0:1F:EF (VMware)
Nmap scan report for attacker.dvssc.com (10.10.10.128) # 我的攻击机
Host is up.
Nmap done: 256 IP addresses (6 hosts up) scanned in 1.68 seconds

同理也可以得到相同的结果。如果是在Internet环境中推荐使用-Pn选项,此时Nmap则会不使用ping扫描,因为ICMP数据包通常无法穿透Internet上的网络边界。 可以使用-PU 通过对开放的UDP端口进行探测来确定存活的主机,其功能类似msf的udp_sweep。进行UDP主机扫描时,默认会列出开放的TCP端口,如果想加快扫描速度,可以使用-sn来仅探测存活主机,而不进行TCP端口的扫描。如:使用UDP Ping扫描存活主机:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
msf5 > nmap -PU -sn 10.10.10.0/24
[*] exec: nmap -PU -sn 10.10.10.0/24

Starting Nmap 7.70 ( https://nmap.org ) at 2019-02-05 22:05 CST
Nmap scan report for 10.10.10.1
Host is up (0.00051s latency).
MAC Address: 00:50:56:C0:00:08 (VMware)
Nmap scan report for 10.10.10.2
Host is up (0.00039s latency).
MAC Address: 00:50:56:F6:FD:F5 (VMware)
Nmap scan report for www.dvssc.com (10.10.10.129)
Host is up (0.00027s latency).
MAC Address: 00:0C:29:C5:A6:2B (VMware)
Nmap scan report for service.dvssc.com (10.10.10.130)
Host is up (0.00023s latency).
MAC Address: 00:0C:29:09:18:C6 (VMware)
Nmap scan report for gate.dvssc.com (10.10.10.254)
Host is up (0.00030s latency).
MAC Address: 00:0C:29:F0:1F:EF (VMware)
Nmap scan report for attacker.dvssc.com (10.10.10.128)
Host is up.
Nmap done: 256 IP addresses (6 hosts up) scanned in 2.04 seconds

结果相同。 ### 操作系统辨识 准确区别出主机设备使用的操作系统对后期的后渗透很有帮助。使用Nmap的-O选项可进行主机操作系统的辨识:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# 对OWASP 10.10.10.129的扫描:
msf5 > nmap -O 10.10.10.129
[*] exec: nmap -O 10.10.10.129

Starting Nmap 7.70 ( https://nmap.org ) at 2019-02-05 22:09 CST
Nmap scan report for www.dvssc.com (10.10.10.129)
Host is up (0.0019s latency).
Not shown: 992 closed ports
PORT STATE SERVICE
21/tcp open ftp
22/tcp open ssh
80/tcp open http
139/tcp open netbios-ssn
143/tcp open imap
445/tcp open microsoft-ds
5001/tcp open commplex-link
8080/tcp open http-proxy
MAC Address: 00:0C:29:C5:A6:2B (VMware)
Device type: general purpose
Running: Linux 2.6.X
OS CPE: cpe:/o:linux:linux_kernel:2.6 # linux主机
OS details: Linux 2.6.17 - 2.6.36
Network Distance: 1 hop

OS detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 2.25 seconds

# 对10.10.10.130的扫描:
msf5 > nmap -O 10.10.10.130
[*] exec: nmap -O 10.10.10.130

Starting Nmap 7.70 ( https://nmap.org ) at 2019-02-05 22:09 CST
Nmap scan report for service.dvssc.com (10.10.10.130)
Host is up (0.00038s latency).
Not shown: 985 closed ports
PORT STATE SERVICE
21/tcp open ftp
80/tcp open http
135/tcp open msrpc
139/tcp open netbios-ssn
445/tcp open microsoft-ds
777/tcp open multiling-http
1025/tcp open NFS-or-IIS
1026/tcp open LSA-or-nterm
1027/tcp open IIS
1031/tcp open iad2
1521/tcp open oracle
6002/tcp open X11:2
7001/tcp open afs3-callback
7002/tcp open afs3-prserver
8099/tcp open unknown
MAC Address: 00:0C:29:09:18:C6 (VMware)
Device type: general purpose
Running: Microsoft Windows XP|2003
OS CPE: cpe:/o:microsoft:windows_xp::sp2:professional cpe:/o:microsoft:windows_server_2003
OS details: Microsoft Windows XP Professional SP2 or Windows Server 2003
# windows的2k3
Network Distance: 1 hop

OS detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 1.65 seconds

# ~~对10.10.10.254(Metasploit Linux2)的扫描(这个不知道为什么扫不出来。。。)~~:
# 这是VMware网管问题。。解决办法,调整DHCP分配10.10.10.244为10.10.10.255
msf5 > nmap -O 10.10.10.254
[*] exec: nmap -O 10.10.10.254

Starting Nmap 7.70 ( https://nmap.org ) at 2019-02-05 23:47 CST
Nmap scan report for gate.dvssc.com (10.10.10.254)
Host is up (0.00080s latency).
Not shown: 977 closed ports
PORT STATE SERVICE
21/tcp open ftp
22/tcp open ssh
23/tcp open telnet
25/tcp open smtp
53/tcp open domain
80/tcp open http
111/tcp open rpcbind
139/tcp open netbios-ssn
445/tcp open microsoft-ds
512/tcp open exec
513/tcp open login
514/tcp open shell
1099/tcp open rmiregistry
1524/tcp open ingreslock
2049/tcp open nfs
2121/tcp open ccproxy-ftp
3306/tcp open mysql
5432/tcp open postgresql
5900/tcp open vnc
6000/tcp open X11
6667/tcp open irc
8009/tcp open ajp13
8180/tcp open unknown
MAC Address: 00:0C:29:F0:1F:EF (VMware)
Device type: general purpose
Running: Linux 2.6.X
OS CPE: cpe:/o:linux:linux_kernel:2.6
OS details: Linux 2.6.9 - 2.6.33
Network Distance: 1 hop

OS detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 1.91 seconds

端口扫描与服务类型探测

通过扫描主机开发的端口对后期的渗透很有帮助。常见的扫描技术如下所示:

1
2
3
4
TCP Connect, TCP SYN, TCP ACK, TCP FIN, TCP IDLE(高级扫描技术)

其中Connect是建立完整TCP连接来证明端口的开放,所以速度较为缓慢。
SYN, ACK, FIN等则是利用了TCP协议栈的一些特性,如包含特殊标志位的数据包,这类扫描更加隐蔽和快速。
1. Metasploit中的端口扫描
1
2
3
4
5
* ack:通过ACK扫描对防火墙未被屏蔽的端口进行探测。
* ftpbounce:通过FTP bounce攻击的原理对TCP服务进行枚举,一些新的FTP服务其软件能够很好的防范FTP bounce攻击,但在一些旧的Solaris以及FreeBSD系统的FTP服务中此攻击仍可以生效
* syn: 通过发送Tcp SYN标志的方式来探测开放的端口。
* tcp: 通过一次完整的TCP连接来完成端口扫描,这种方式最精确,但速度最慢。
* xmas: 一种更为隐秘的扫描方式,通过发送FIN, PSH和URG标志,能够躲避一些高级TCP标记探测器的过滤。
  一般情况下推荐使用syn扫描的方式,因为扫描速度够快,结果精确且不易被察觉。
1
2
# 对网关10.10.10.129的扫描

2. Nmap的端口扫描 常用Nmap扫描类型参数和选项主要有:
1
2
3
4
5
6
7
8
9
10
11
12
13
# 参数
-sT: TCP Connect扫描
-sS: TCP SYN扫描
-sF/-sX/-sN: 发送特殊标志位来避开设备或软件的监测
-sP: 通过发送ICMP echo请求探测存活主机,原理类似Ping
-sU: UDP Ping扫描,探测开放了哪些UDP端口
-sA: ACK扫描

# 选项
-Pn: 在扫描之前不发送ICMP echo请求测试目标是否活跃
-O: 启用TCP/IP协议栈的职位特征来获取远程主机的操作系统类型等信息
-F: 快扫描模式,只扫描在nmap-services中列出的端口
-p<端口范围>:指定希望扫描的端口号范围
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# 对10.10.10.129
msf5 > nmap -sS -Pn 10.10.10.129 #使用syn扫描,无需确定主机是否存活
[*] exec: nmap -sS -Pn 10.10.10.129

Starting Nmap 7.70 ( https://nmap.org ) at 2019-02-05 22:46 CST
Nmap scan report for www.dvssc.com (10.10.10.129)
Host is up (0.0024s latency).
Not shown: 992 closed ports
PORT STATE SERVICE
21/tcp open ftp
22/tcp open ssh
80/tcp open http
139/tcp open netbios-ssn
143/tcp open imap
445/tcp open microsoft-ds
5001/tcp open commplex-link
8080/tcp open http-proxy
MAC Address: 00:0C:29:C5:A6:2B (VMware)

Nmap done: 1 IP address (1 host up) scanned in 1.69 seconds
3. 使用Nmap获得更详细的信息   想要对上面的结果做一个更详细的拓展如:服务版本号等可以使用-sV参数。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# 对10.10.10.129
msf5 > nmap -sV -Pn 10.10.10.129
[*] exec: nmap -sV -Pn 10.10.10.129

Starting Nmap 7.70 ( https://nmap.org ) at 2019-02-05 22:50 CST
Nmap scan report for www.dvssc.com (10.10.10.129)
Host is up (0.010s latency).
Not shown: 992 closed ports
PORT STATE SERVICE VERSION
21/tcp open ftp vsftpd 2.2.2
22/tcp open ssh OpenSSH 5.3p1 Debian 3ubuntu4 (Ubuntu Linux; protocol 2.0)
80/tcp open http Apache httpd 2.2.14 ((Ubuntu) mod_mono/2.4.3 PHP/5.3.2-1ubuntu4.5 with Suhosin-Patch mod_python/3.3.1 Python/2.6.5 mod_perl/2.0.4 Perl/v5.10.1)
139/tcp open netbios-ssn Samba smbd 3.X - 4.X (workgroup: WORKGROUP)
143/tcp open imap Courier Imapd (released 2008)
445/tcp open netbios-ssn Samba smbd 3.X - 4.X (workgroup: WORKGROUP)
5001/tcp open java-rmi Java RMI
8080/tcp open http Apache Tomcat/Coyote JSP engine 1.1
1 service unrecognized despite returning data. If you know the service/version, please submit the following fingerprint at https://nmap.org/cgi-bin/submit.cgi?new-service :
SF-Port5001-TCP:V=7.70%I=7%D=2/5%Time=5C59A2A2%P=x86_64-pc-linux-gnu%r(NUL
SF:L,4,"\xac\xed\0\x05"); # 提示5001端口上未识别的服务
MAC Address: 00:0C:29:C5:A6:2B (VMware)
Service Info: OSs: Unix, Linux; CPE: cpe:/o:linux:linux_kernel

Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 13.91 seconds

实验环境扫描结果小结

CATALOG
  1. 1. 通过DNS和IP地址挖掘信息
    1. 1.1. whois 域名注册信息查询
    2. 1.2. nslookup和dig域名查询
    3. 1.3. netcraft网站提供的信息查询服务
    4. 1.4. IP2Domain反查域名
  2. 2. 搜索引擎信息收集
    1. 2.1. Google Hacking技术
    2. 2.2. 获取网站的目录结构
    3. 2.3. 检索特定类型文件
    4. 2.4. 搜索网站中的E-mail地址
    5. 2.5. 搜索易存在SQL注入点的页面
    6. 2.6. IP路由侦查
  3. 3. 主机探测与端口扫描
    1. 3.1. 活跃主机扫描
    2. 3.2. 端口扫描与服务类型探测
  4. 4. 实验环境扫描结果小结