performing-aws-privilege-escalation-assessment について
AWS の IAM 権限昇格を評価する、許可を得たセキュリティテスト担当者向けの手順です。権限の列挙、経路分析、クロスアカウント信頼の確認、結果の記録を扱います。
主な機能
- 01IAM 主体の権限列挙
- 02Pacu による昇格経路のスキャン
- 03PMapper による権限関係のマッピング
- 04クロスアカウントロール信頼の確認
- 05CloudFox による攻撃経路の列挙
- 06所見と修正策の記録
活用シーン
- 01最小権限に沿った IAM 設定の検証
- 02認証情報侵害時の影響範囲の評価
- 03ロールやポリシー変更のレビュー
- 04クロスアカウント信頼リスクの確認
インストール
コマンドをコピーしてターミナルで実行します。
npx skills add https:/ / github.com/ mukul975/ anthropic-cybersecurity-skills --skill performing-aws-privilege-escalation-assessmentインストール後、Claude Code で/performing-aws-privilege-escalation-assessmentを入力して読み込まれたか確認します。
同梱ファイル
SKILL.md と一緒にインストールされる参考資料やスクリプト。
LICENSEreferences/api-reference.mdscripts/agent.py詳細
AWS の権限昇格評価を実施する
使用する場面
- AWS IAM 設定の許可されたペネトレーションテストを実施する場合
- IAM ポリシーが最小権限の原則に従っていることを検証する場合
- AWS 認証情報が侵害された場合の影響範囲を評価する場合
- CI/CD パイプラインで IAM ロールとポリシーの変更に関するセキュリティレビューを構築する場合
- 権限昇格のリスクについて、アカウント間の信頼関係を評価する場合
使用しないでください。AWS アカウントに対する許可のないテスト、IAM 以外の攻撃ベクトル(SSRF、アプリケーションの脆弱性)の評価、または包括的なクラウドペネトレーションテストの代替としての使用には適していません。テストを実施する前に、必ず書面による許可を取得してください。
前提条件
- 対象の AWS アカウントで権限昇格テストを実施するための書面による許可
- 開始時点の権限が制限されたテスト用 IAM ユーザーまたはロール
- Pacu のインストール(
pip install pacu) - CloudFox のインストール(
go install github.com/BishopFox/cloudfox@latest) - PMapper(Principal Mapper)のインストール(
pip install principalmapper) - 監査証跡用の CloudTrail ログ記録を有効にした、テスト用認証情報での AWS CLI の設定
ワークフロー
ステップ 1:開始時点の権限を列挙する
権限昇格を試みる前に、テスト対象のプリンシパルが持つベースライン権限を確認します。
# Get current identity
aws sts get-caller-identity
# Enumerate inline and attached policies for the current user
aws iam list-user-policies --user-name test-user
aws iam list-attached-user-policies --user-name test-user
# Get group memberships and group policies
aws iam list-groups-for-user --user-name test-user
for group in $(aws iam list-groups-for-user --user-name test-user --query 'Groups[*].GroupName' --output text); do
echo "=== Group: $group ==="
aws iam list-group-policies --group-name "$group"
aws iam list-attached-group-policies --group-name "$group"
done
# Simulate specific API calls to map effective permissions
aws iam simulate-principal-policy \
--policy-source-arn arn:aws:iam::ACCOUNT:user/test-user \
--action-names iam:CreateUser iam:AttachUserPolicy iam:PassRole \
lambda:CreateFunction ec2:RunInstances sts:AssumeRole \
--query 'EvaluationResults[*].[EvalActionName,EvalDecision]' --output table
ステップ 2:Pacu で権限昇格経路をスキャンする
Pacu の権限昇格スキャナーを使用して、既知の IAM 権限昇格手法を特定します。
# Start Pacu session
pacu
# Create session and set credentials
Pacu (new:session) > set_keys --key-alias privesc-test
# Enumerate IAM configuration
Pacu > run iam__enum_users_roles_policies_groups
Pacu > run iam__enum_permissions
# Run privilege escalation scanner
Pacu > run iam__privesc_scan
# The scanner checks for 21+ known escalation methods including:
# - iam:CreatePolicyVersion (create admin policy version)
# - iam:SetDefaultPolicyVersion (revert to permissive older version)
# - iam:AttachUserPolicy / iam:AttachRolePolicy (attach admin policy)
# - iam:PutUserPolicy / iam:PutRolePolicy (create inline admin policy)
# - iam:PassRole + lambda:CreateFunction (Lambda with admin role)
# - iam:PassRole + ec2:RunInstances (EC2 with admin instance profile)
# - iam:CreateLoginProfile / iam:UpdateLoginProfile (set console password)
# - iam:CreateAccessKey (create keys for other users)
# - sts:AssumeRole (assume more privileged roles)
# - glue:CreateDevEndpoint + iam:PassRole (Glue with admin role)
ステップ 3:PMapper で権限昇格グラフをマッピングする
Principal Mapper を使用して、すべての IAM プリンシパルのグラフを作成し、権限昇格につながるエッジを特定します。
# Collect IAM data for graph construction
pmapper graph create --account ACCOUNT_ID
# Query for paths to admin
pmapper query 'who can do iam:AttachUserPolicy with * on *'
pmapper query 'who can do sts:AssumeRole with arn:aws:iam::ACCOUNT:role/AdminRole'
# Find all principals that can escalate to admin
pmapper analysis
# Visualize the privilege escalation graph
pmapper visualize --filetype png
# Check specific escalation paths
pmapper query 'can arn:aws:iam::ACCOUNT:user/test-user do iam:CreatePolicyVersion with *'
pmapper query 'can arn:aws:iam::ACCOUNT:user/test-user do sts:AssumeRole with arn:aws:iam::ACCOUNT:role/*'
ステップ 4:アカウント間のロール引き受けをテストする
不正な権限昇格を許す、設定ミスのあるロール引き受けがないか、アカウント間の信頼ポリシーを評価します。
# List all roles and their trust policies
aws iam list-roles --query 'Roles[*].[RoleName,Arn]' --output text | while read name arn; do
trust=$(aws iam get-role --role-name "$name" --query 'Role.AssumeRolePolicyDocument' --output json 2>/dev/null)
# Check for wildcards or broad trust
echo "$trust" | python3 -c "
import json, sys
doc = json.load(sys.stdin)
for stmt in doc.get('Statement', []):
principal = stmt.get('Principal', {})
condition = stmt.get('Condition', {})
if isinstance(principal, dict):
aws_princ = principal.get('AWS', '')
else:
aws_princ = principal
if '*' in str(aws_princ) or 'root' in str(aws_princ):
has_external_id = 'sts:ExternalId' in str(condition)
has_mfa = 'aws:MultiFactorAuthPresent' in str(condition)
print(f'ROLE: $name')
print(f' Principal: {aws_princ}')
print(f' ExternalId required: {has_external_id}')
print(f' MFA required: {has_mfa}')
if not has_external_id and not has_mfa:
print(f' WARNING: No ExternalId or MFA condition - confused deputy risk')
" 2>/dev/null
done
# Test role assumption
aws sts assume-role \
--role-arn arn:aws:iam::TARGET_ACCOUNT:role/CrossAccountRole \
--role-session-name privesc-test \
--duration-seconds 900
ステップ 5:CloudFox で攻撃経路を列挙する
CloudFox を使用して、リソースベースのポリシーやサービス固有の権限昇格経路など、追加の攻撃対象領域を特定します。
# Run all CloudFox checks
cloudfox aws --profile target-account all-checks -o ./cloudfox-output/
# Specific privilege escalation checks
cloudfox aws --profile target-account permissions
cloudfox aws --profile target-account role-trusts
cloudfox aws --profile target-account access-keys
cloudfox aws --profile target-account env-vars # Lambda environment variables with secrets
cloudfox aws --profile target-account instances # EC2 with instance profiles
cloudfox aws --profile target-account endpoints # Exposed services
ステップ 6:調査結果と修正策を文書化する
発見したすべての権限昇格経路を、概念実証の手順および修正の推奨事項とともにまとめます。
# Generate a consolidated report
cat > privesc-report.md << 'EOF'
# AWS Privilege Escalation Assessment Report
## Tested Escalation Vectors
| Vector | Status | Starting Principal | Escalated To | Risk |
|--------|--------|--------------------|--------------|------|
| iam:CreatePolicyVersion | EXPLOITABLE | test-user | AdministratorAccess | Critical |
| iam:PassRole + lambda:CreateFunction | EXPLOITABLE | dev-role | LambdaAdminRole | Critical |
| sts:AssumeRole (cross-account) | EXPLOITABLE | test-user | ProdAdminRole | High |
| iam:AttachUserPolicy | BLOCKED | test-user | N/A | N/A |
| ec2:RunInstances + iam:PassRole | BLOCKED | test-user | N/A | N/A |
## Remediation
1. Apply permission boundaries to all IAM users and roles
2. Remove iam:CreatePolicyVersion from non-admin principals
3. Add sts:ExternalId condition to all cross-account role trust policies
4. Implement SCP guardrails preventing privilege escalation actions
EOF
主な概念
| 用語 | 定義 |
|---|---|
| IAM 権限昇格 | 過度に許容的な IAM ポリシーを悪用し、プリンシパルに当初付与された権限よりも高いアクセス権を取得すること |
| アクセス許可境界 | プリンシパルに付与されたアイデンティティベースのポリシーにかかわらず、そのプリンシパルが持てる最大権限を定める IAM ポリシー |
| iam:PassRole | プリンシパルが IAM ロールを AWS サービスに渡し、そのサービスがロールの権限で動作できるようにする IAM アクション |
| 混乱した代理人 | 外部 ID による検証を行わず、アカウント間のロール引き受けを利用して、攻撃者が信頼されたサービスに自分の代わりにアクションを実行させる攻撃 |
| サービスコントロールポリシー | メンバーアカウントの最大権限を定め、権限昇格に対するガードレールを提供する AWS Organizations のポリシー |
| Principal Mapper | IAM プリンシパルとその権限昇格経路を有向グラフとしてモデル化し、分析するオープンソースツール |
ツールとシステム
- Pacu:自動検出と悪用に対応した、21 以上の権限昇格モジュールを備える AWS 悪用フレームワーク
- Principal Mapper:プリンシパル間の権限昇格経路をマッピングする、グラフベースの IAM 分析ツール
- CloudFox:攻撃者の視点から攻撃経路を特定することに重点を置いた AWS 列挙ツール
- IAM Policy Simulator:特定の API アクションに対する実効権限をテストする、AWS ネイティブのツール
- AWS Access Analyzer:外部アクセスを許可するリソースポリシーを特定し、IAM ポリシーの変更を検証するサービス
よくあるシナリオ
シナリオ:iam:CreatePolicyVersion 権限を持つ開発者ロールによる管理者アクセス
コンテキスト:承認済みの評価中に、テスターは開発者ロールに iam:CreatePolicyVersion 権限があり、任意の権限を付与した新しいバージョンのカスタマー管理ポリシーを作成できることを発見しました。
アプローチ:
- Pacu の
iam__enum_permissionsを使って、開発者ロールにアタッチされたポリシーを列挙します - ロールが自身にアタッチされたポリシーに対して
iam:CreatePolicyVersionを呼び出せることを特定します "Action": "*", "Resource": "*", "Effect": "Allow"を指定して新しいポリシーバージョンを作成します- 新しいバージョンをデフォルトのポリシーバージョンに設定します
iam:ListUsers、s3:ListBucketsなどを呼び出して、管理者アクセスを検証します- 権限昇格の経路を記録し、
iam:CreatePolicyVersionの削除とアクセス許可境界の実装を推奨します
注意点:AWS の管理ポリシーでは、バージョンは最大 5 つまでです。5 つすべて存在する場合、新しいバージョンを作成する前に 1 つ削除する必要があります。クリーンアップ時に元に戻せるよう、必ず元のデフォルトバージョンを記録してください。アクセス許可境界が適切に設定されていれば、この権限昇格を防げるため、問題を報告する前に境界ポリシーを確認してください。
出力形式
AWS Privilege Escalation Assessment Report
=============================================
Account: 123456789012 (Production)
Assessment Date: 2026-02-23
Starting Principal: arn:aws:iam::123456789012:user/test-user
Starting Permissions: S3 read-only, Lambda invoke, EC2 describe
Authorization: Signed by CISO, engagement #PT-2026-014
ESCALATION PATHS DISCOVERED: 4
[PRIVESC-001] iam:CreatePolicyVersion -> Admin
Severity: CRITICAL
Starting Permission: iam:CreatePolicyVersion on policy/dev-policy
Escalation: Created policy version 6 with Action:* Resource:*
Time to Exploit: < 2 minutes
Remediation: Remove iam:CreatePolicyVersion, apply permission boundary
[PRIVESC-002] iam:PassRole + lambda:CreateFunction -> LambdaAdminRole
Severity: CRITICAL
Starting Permission: iam:PassRole, lambda:CreateFunction
Escalation: Created Lambda function with AdminRole, invoked to get admin credentials
Time to Exploit: < 5 minutes
Remediation: Restrict iam:PassRole to specific role ARNs with condition key
[PRIVESC-003] sts:AssumeRole -> Cross-Account Admin
Severity: HIGH
Starting Permission: sts:AssumeRole on arn:aws:iam::987654321098:role/SharedRole
Escalation: Role trust policy allows any principal in source account
Remediation: Add sts:ExternalId condition and restrict Principal to specific roles
TOTAL ESCALATION PATHS: 4 (2 Critical, 1 High, 1 Medium)
PERMISSION BOUNDARIES IN PLACE: 0 / 47 IAM principals
SCP GUARDRAILS BLOCKING ESCALATION: 0 / 3 tested vectors