From 7a023603fe2c8ddbffcc47414b341bcfb54c8d37 Mon Sep 17 00:00:00 2001 From: Translator Date: Thu, 12 Feb 2026 19:55:23 +0000 Subject: [PATCH] Translated ['src/pentesting-cloud/aws-security/aws-privilege-escalation/ --- .../aws-bedrock-privesc/README.md | 113 ++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 src/pentesting-cloud/aws-security/aws-privilege-escalation/aws-bedrock-privesc/README.md diff --git a/src/pentesting-cloud/aws-security/aws-privilege-escalation/aws-bedrock-privesc/README.md b/src/pentesting-cloud/aws-security/aws-privilege-escalation/aws-bedrock-privesc/README.md new file mode 100644 index 000000000..755a7144a --- /dev/null +++ b/src/pentesting-cloud/aws-security/aws-privilege-escalation/aws-bedrock-privesc/README.md @@ -0,0 +1,113 @@ +# 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 — це кероване середовище виконання. **Custom Code Interpreters** можна налаштувати з **`executionRoleArn`**, який «надає дозволи інтерпретатору коду для доступу до AWS services». + +Якщо **lower-privileged IAM principal** може **start + invoke** сесію Code Interpreter, налаштовану з **more privileged execution role**, викликач фактично може **pivot into the execution role’s permissions** (lateral movement / privilege escalation залежно від обсягу ролі). + +> [!NOTE] +> Зазвичай це питання **misconfiguration / excessive permissions** (надання широких дозволів виконуючій ролі інтерпретатора і/або широкого доступу до invoke). +> AWS явно попереджає, щоб уникнути privilege escalation, переконуючись, що execution roles мають **equal or fewer** privileges, ніж identities, яким дозволено invoke. + +#### Передумови (common misconfiguration) + +- Існує **custom code interpreter** з надмірно привілейованою **execution role** (ex: доступ до чутливих S3/Secrets/SSM або можливості на кшталт IAM-admin). +- Користувач (developer/auditor/CI identity) має дозволи на: +- start sessions: `bedrock-agentcore:StartCodeInterpreterSession` +- invoke tools: `bedrock-agentcore:InvokeCodeInterpreter` +- (Optional) Користувач також може створювати інтерпретатори: `bedrock-agentcore:CreateCodeInterpreter` (дозволяє створити нового інтерпретатора, налаштованого з execution role, залежно від org guardrails). + +#### Recon (identify custom interpreters and execution role usage) + +Перелічіть interpreters (control-plane) та перевірте їх конфігурацію: +```bash +aws bedrock-agentcore-control list-code-interpreters +aws bedrock-agentcore-control get-code-interpreter --code-interpreter-id +```` +> Команда create-code-interpreter підтримує `--execution-role-arn`, який визначає, які дозволи AWS матиме інтерпретатор. + +#### Крок 1 - Розпочати сесію (це повертає `sessionId`, а не interactive shell) +```bash +SESSION_ID=$( +aws bedrock-agentcore start-code-interpreter-session \ +--code-interpreter-identifier \ +--name "arte-oussama" \ +--query sessionId \ +--output text +) + +echo "SessionId: $SESSION_ID" +``` +#### Крок 2 - Виклик виконання коду (Boto3 або підписаний HTTPS) + +Немає **інтерактивної оболонки python** від `start-code-interpreter-session`. Виконання відбувається через **InvokeCodeInterpreter**. + +**Варіант A - приклад Boto3 (запуск Python + перевірка ідентичності):** +```python +import boto3 + +client = boto3.client("bedrock-agentcore", region_name="") + +# Execute python inside the Code Interpreter session +resp = client.invoke_code_interpreter( +codeInterpreterIdentifier="", +sessionId="", +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) +``` +Якщо інтерпретатор налаштовано з execution role, вивід `sts:GetCallerIdentity()` має відображати ідентичність цієї ролі (а не low-priv caller), що демонструє pivot. + +**Варіант B - Підписаний HTTPS виклик (awscurl):** +```bash +awscurl -X POST \ +"https://bedrock-agentcore..amazonaws.com/code-interpreters//tools/invoke" \ +-H "Content-Type: application/json" \ +-H "Accept: application/json" \ +-H "x-amzn-code-interpreter-session-id: " \ +--service bedrock-agentcore \ +--region \ +-d '{ +"name": "executeCode", +"arguments": { +"language": "python", +"code": "print(\"Hello from AgentCore\")" +} +}' +``` +#### Наслідки + +* **Lateral movement** до будь-якого доступу AWS, який має роль виконання інтерпретатора. +* **Privilege escalation** якщо роль виконання інтерпретатора має більше привілеїв, ніж викликач. +* Ускладнене виявлення, якщо CloudTrail data events для викликів інтерпретатора не ввімкнено (виклики можуть не логуватися за замовчуванням, залежно від конфігурації). + +#### Пом'якшення ризиків / Посилення безпеки + +* **Least privilege** для інтерпретатора `executionRoleArn` (ставтеся до нього так само, як до Lambda execution roles / CI roles). +* **Обмежте, хто може викликати** (`bedrock-agentcore:InvokeCodeInterpreter`) та хто може починати сесії. +* Використовуйте **SCPs** для заборони InvokeCodeInterpreter, за винятком затверджених agent runtime roles (може знадобитися застосування на рівні org). +* Увімкніть відповідні **CloudTrail data events** для AgentCore там, де це доречно; сповіщайте про несподівані виклики та створення сесій. + +## 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}}