mcpField
S
source-leak-hunt

source-leak-hunt

github.com/uphiagoセキュリティ1.3k41 回インストール8 週間前に更新
リポジトリ

source-leak-hunt について

source-leak-hunt は、稼働中のサイトで機密ファイルの露出をスキャンし、内容に基づいて結果を検証するセキュリティテスト用スキルです。漏えいファイルからの認証情報抽出や、よくある誤検知の除外方法も扱います。

主な機能

  1. 01露出した機密ファイルのスキャン
  2. 02ファイル内容による結果の絞り込み
  3. 03漏えいファイルからの認証情報抽出
  4. 04複数の漏えいがあるドメインの特定
  5. 05よくある誤検知への対処

活用シーン

  1. 01稼働中ドメインのファイル露出監査
  2. 02複数サイトの認証情報漏えい確認
  3. 03検証済みの漏えいが複数ある対象の優先調査

インストール

コマンドをコピーしてターミナルで実行します。

$npx skills add https://github.com/uphiago/recon-skills --skill source-leak-hunt

インストール後、Claude Code で/source-leak-huntを入力して読み込まれたか確認します。

詳細

ソース漏えい調査スキル

コンテンツベースの誤検知フィルタリングを使用して、公開された機密ファイル(.env、.git/config、wp-config.php.bak、debug.log、backup.sql、phpinfo.php、Dockerfile など)を一括スキャンします。ソース漏えいは、WordPress ユーザー列挙に次いで多く見つかる項目で、対象の約 7% で確認されます。

使用するタイミング

  • skill_view(name='wp-mass-recon') で対象が稼働中であることを確認した後。
  • 複数のドメインを一括でスキャンする場合。
  • より深いアクセスにつながる認証情報の漏えいを調査する場合。
  • クライアント側のシークレットを調べるために skill_view(name='js-secrets-extraction') を補完する場合。

前提条件

  • curl を使用できる terminal。
  • 稼働中の URL のリスト(httpx または wp-mass-recon Phase 1 の出力)。
  • データの保持先:$OUTDIR/leaks/ の出力ディレクトリ。

実行方法

# Quick scan single target (20 paths)
TARGET="https://example.com"
for path in .env .git/config wp-config.php.bak debug.log backup.sql info.php phpinfo.php \
  .env.backup .env.local .env.production wp-config.php~ .git/HEAD .backup.sql \
  docker-compose.yml Dockerfile .DS_Store robots.txt sitemap.xml; do
  code=$(curl -sk -o /dev/null -w "%{http_code}" --max-time 5 --connect-timeout 5 "$TARGET/$path")
  [[ "$code" == "200" ]] && echo "HTTP 200: $TARGET/$path"
  sleep 0.2
done

クイックリファレンス

パス公開される情報深刻度
.envDB 認証情報、API キー、アプリのシークレットCritical
wp-config.php.bakMySQL の root パスワード、ソルトCritical
.git/configリポジトリ URL、認証情報High
debug.logPHP エラー、サーバーパス、SQL クエリHigh
backup.sqlデータベース全体のダンプCritical
info.php / phpinfo.phpPHP 設定、disable_functions、サーバー環境High
docker-compose.ymlサービス構成、環境変数Medium
Dockerfileビルド設定、公開ポートLow
.env.backup / .env.local.env と同じ情報、別のファイル名Critical
wp-config.php~wp-config の Vim スワップファイルCritical
.DS_Storeディレクトリ一覧(macOS)Low
error_logPHP エラーログ(数 MB に及び、パスやクエリが大量に含まれる場合があります)High

手順

ステップ 1 — 並列一括スキャン
#!/bin/bash
URLS_FILE="$1"   # One URL per line
OUTDIR="$OUTDIR/leaks"
mkdir -p "$OUTDIR"

PATHS=(
  ".env"
  ".git/config"
  "wp-config.php.bak"
  "debug.log"
  "backup.sql"
  "info.php"
  "phpinfo.php"
  ".env.backup"
  ".env.local"
  ".env.production"
  "wp-config.php~"
  ".git/HEAD"
  "docker-compose.yml"
  "Dockerfile"
  ".DS_Store"
  "robots.txt"
  "sitemap.xml"
  "error_log"
  "wp-content/debug.log"
  ".backup.sql"
)

# Content verification patterns (avoids SPA catch-all false positives)
declare -A PATTERNS
PATTERNS[".env"]='DB_|APP_|_KEY|_SECRET|DATABASE|PASSWORD|TOKEN'
PATTERNS["wp-config.php.bak"]='DB_NAME|DB_PASSWORD|AUTH_KEY'
PATTERNS[".git/config"]='\[core\]'
PATTERNS["debug.log"]='PHP|ERROR|WARNING|Stack trace'
PATTERNS["backup.sql"]='CREATE TABLE|INSERT INTO|DROP TABLE'
PATTERNS["info.php"]='PHP Version|phpinfo'
PATTERNS["phpinfo.php"]='PHP Version|phpinfo'
PATTERNS[".env.backup"]='DB_|APP_|_KEY|_SECRET'
PATTERNS[".env.local"]='DB_|APP_|_KEY|_SECRET'
PATTERNS[".env.production"]='DB_|APP_|_KEY|_SECRET'
PATTERNS["wp-config.php~"]='DB_NAME|DB_PASSWORD'
PATTERNS["error_log"]='PHP|ERROR|Stack trace'

scan_target() {
  local url="$1"
  local domain
  domain=$(echo "$url" | sed 's|https\?://||' | sed 's|/.*||')

  for path in "${PATHS[@]}"; do
    local full_url="${url}/${path}"
    local code
    code=$(curl -sk -o /tmp/leak_check_$$.tmp -w "%{http_code}" --max-time 5 --connect-timeout 5 "$full_url" 2>/dev/null)

    if [[ "$code" == "200" ]]; then
      local content
      content=$(head -c 2000 /tmp/leak_check_$$.tmp 2>/dev/null)
      local pattern="${PATTERNS[$path]}"

      if [[ -n "$pattern" ]] && echo "$content" | grep -qiE "$pattern"; then
        echo "[LEAK] $full_url (VERIFIED: $path)"
        echo "$full_url" >> "$OUTDIR/${domain}_leaks.txt"
        cp /tmp/leak_check_$$.tmp "$OUTDIR/${domain}_${path//\//_}.content" 2>/dev/null
      elif [[ -z "$pattern" ]]; then
        # No pattern check — just log HTTP 200 (e.g., robots.txt)
        local size=$(wc -c < /tmp/leak_check_$$.tmp)
        if [[ "$size" -gt 50 ]]; then
          echo "[INFO] $full_url (HTTP 200, ${size} bytes)"
          echo "$full_url" >> "$OUTDIR/${domain}_leaks.txt"
        fi
      fi
    fi
    sleep 0.3
  done
  rm -f /tmp/leak_check_$$.tmp
}

export -f scan_target
export OUTDIR
export PATHS

# Run 30 parallel workers
cat "$URLS_FILE" | xargs -P 30 -I {} bash -c 'scan_target "{}"'

echo "[+] Done. Results in $OUTDIR/"
ステップ 2 — 漏えいファイルから認証情報を抽出
# From .env files
grep -rhE '(DB_|APP_|_KEY|_SECRET|DATABASE|PASSWORD|TOKEN|SECRET)=' $OUTDIR/leaks/*.env*.content 2>/dev/null | sort -u

# From wp-config backups
grep -rhE 'DB_NAME|DB_USER|DB_PASSWORD|DB_HOST|AUTH_KEY' $OUTDIR/leaks/*wp-config* 2>/dev/null

# From .git/config
grep -rh 'url = ' $OUTDIR/leaks/*.git_config.content 2>/dev/null

# From SQL dumps
grep -rhE 'CREATE TABLE|INSERT INTO' $OUTDIR/leaks/*backup* $OUTDIR/leaks/*.sql* 2>/dev/null | head -20
ステップ 3 — 複数の漏えいがある対象を特定(詳細調査候補)
for f in $OUTDIR/leaks/*_leaks.txt; do
  count=$(wc -l < "$f")
  [[ "$count" -ge 3 ]] && echo "$(basename "$f" _leaks.txt): $count leaks"
done | sort -t: -k2 -rn

注意点

  • フィルタリングしない場合、結果の 70% 以上が SPA のキャッチオールによる誤検知です。 シングルページアプリは、どのパスに対しても index.html を HTTP 200 で返します。コンテンツの検証は必須です。
  • CloudFront/S3 のエラーページ。 ファイルが見つからないときに、一部の CDN は XML のエラー本文を HTTP 200 で返します。コンテンツタイプと本文を確認してください。
  • 大きなファイルのコンテンツが切り詰められる場合。 error_log ファイルは 1.7MB 以上になることがあります。分割して取得するか、curl -r 0-5000 で一部をサンプリングしてください。
  • git/HEAD の誤検知。 一部のテーマや構成では、.git/HEAD が正規の git ハッシュを含む HTTP 200 を返します。先に .git/config を確認してください。
  • パーキング中または売り出し中のドメインは、すべてのパスに HTTP 200 を返します。 汎用のパーキングページは、エラー処理なしで /.env、/.git/config、/info.php などにコンテンツを返します。どのパスでも同じランディングページが返されます。無関係な複数のパスで同じコンテンツ(同一の本文ハッシュ、同じ <title>、または「for sale」や「parked」などの同じキーワード)が返されるかを確認して検出してください。早期終了の判定を追加してください。/robots.txt と /.env の両方が、ほぼ同一の HTML を含む HTTP 200 を返す場合は、ドメインをパーキング中と判定し、それ以降のソース漏えいチェックをスキップします。

検証

  • .env の漏えいには、必ず DB_、APP_、_KEY、_SECRET、PASSWORD、TOKEN のいずれかが含まれている必要があります。
  • wp-config.php.bak の漏えいには、必ず DB_NAME と DB_PASSWORD が含まれている必要があります。
  • .git/config の漏えいには、必ず [core] セクションヘッダーが含まれている必要があります。
  • SQL バックアップには、必ず DDL(CREATE TABLE)または DML(INSERT INTO)ステートメントが含まれている必要があります。
  • 検証済みの漏えいはすべて、タイムスタンプと HTTP レスポンスサイズを記録してください。
フェーズ 6 — バックアップファイルの探索
# bfac — multi-level backup file detection
bfac --url https://target.com \
  --detection-technique all \
  --level 3 \
  --exclude-status-codes 404,500

# Wayback Machine — historical sensitive files
waybackurls https://target.com | grep -iE \
  "\.(xls|xlsx|csv|sql|db|bak|backup|old|tar\.gz|tgz|zip|7z|rar|pdf|pem|key|crt|env|json|yml|yaml|conf|config|git|htpasswd|log|dump|DS_Store)" \
  | sort -u > sensitive_wayback.txt

# Check which are still accessible
cat sensitive_wayback.txt | httpx -silent -mc 200 -o accessible_sensitive.txt

# Common backup patterns to probe
for ext in bak old backup zip tar.gz tgz sql dump; do
  curl --max-time 30 --connect-timeout 10 -skI "https://target.com/backup.$ext" | head -1
  curl --max-time 30 --connect-timeout 10 -skI "https://target.com/site.$ext" | head -1
  curl --max-time 30 --connect-timeout 10 -skI "https://target.com/target.$ext" | head -1
  sleep 0.3
done
フェーズ 7 — Google サービスの漏えいを検索するための Google 検索演算子の使用
# Google Sheets — internal spreadsheets often left public
# Manual search:
# site:docs.google.com/spreadsheets "target.com"
# site:docs.google.com/spreadsheets "@target.com"
# site:docs.google.com/spreadsheets "password" "target.com"

# Google Drive files
# site:drive.google.com "target.com" "confidential"

# Firebase/Firestore URLs in public search results
# site:firebaseio.com "target.com"
# site:firestore.googleapis.com "target-app"

# GCP buckets
# site:storage.googleapis.com "target"
# site:storage.cloud.google.com "target"

コメント