mirror of
https://github.com/HackTricks-wiki/hacktricks-cloud.git
synced 2026-03-12 21:22:57 -07:00
Translated ['src/pentesting-cloud/aws-security/aws-privilege-escalation/
This commit is contained in:
@@ -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**는 코드 인터프리터가 AWS 서비스를 액세스할 수 있도록 권한을 제공하는 **`executionRoleArn`**으로 구성할 수 있습니다.
|
||||
|
||||
만약 **lower-privileged IAM principal**가 **start + invoke** 가능한, 더 높은 권한의 execution role로 구성된 Code Interpreter 세션을 사용할 수 있다면, 호출자는 사실상 **pivot into the execution role’s permissions**할 수 있습니다 (role 범위에 따라 lateral movement / privilege escalation).
|
||||
|
||||
> [!NOTE]
|
||||
> 이것은 일반적으로 **misconfiguration / excessive permissions** 문제입니다 (interpreter execution role에 광범위한 권한을 부여하거나 invoke 권한을 넓게 허용하는 경우).
|
||||
> AWS는 invoke를 허용한 identity보다 execution roles가 **equal or fewer** 권한을 갖도록 하여 privilege escalation을 방지할 것을 명시적으로 경고합니다.
|
||||
|
||||
#### Preconditions (common misconfiguration)
|
||||
|
||||
- 과도한 권한을 가진 **execution role**이 연결된 **custom code interpreter**가 존재합니다 (ex: 민감한 S3/Secrets/SSM 접근 또는 IAM-admin-like 권한).
|
||||
- 사용자(developer/auditor/CI identity)가 다음 권한을 가지고 있습니다:
|
||||
- start sessions: `bedrock-agentcore:StartCodeInterpreterSession`
|
||||
- invoke tools: `bedrock-agentcore:InvokeCodeInterpreter`
|
||||
- (Optional) 사용자는 `bedrock-agentcore:CreateCodeInterpreter`로 인터프리터를 생성할 수도 있습니다 (org guardrails에 따라 execution role로 구성된 새 인터프리터를 생성할 수 있게 됨).
|
||||
|
||||
#### Recon (custom interpreters 및 execution role 사용 식별)
|
||||
|
||||
인터프리터를 나열(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`을 지원하며, 이는 인터프리터가 갖게 될 AWS 권한을 정의합니다.
|
||||
|
||||
#### Step 1 - 세션 시작 (이것은 `sessionId`를 반환하며 인터랙티브 셸이 아닙니다)
|
||||
```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 또는 signed HTTPS)
|
||||
|
||||
`start-code-interpreter-session`에서는 **대화형 python shell이 제공되지 않습니다**. 실행은 **InvokeCodeInterpreter**를 통해 이루어집니다.
|
||||
|
||||
**옵션 A - Boto3 예시 (Python 실행 + 신원 확인):**
|
||||
```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)
|
||||
```
|
||||
인터프리터가 execution role로 구성되어 있다면, `sts:GetCallerIdentity()` 출력은 해당 역할의 신원(즉 not the low-priv caller)을 반영해야 하며, 이는 pivot을 보여줍니다.
|
||||
|
||||
**Option 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**: interpreter 실행 역할이 보유한 AWS 접근 권한으로 이동할 수 있음.
|
||||
* **Privilege escalation**: interpreter 실행 역할이 호출자보다 더 많은 권한을 가진 경우 권한 상승이 발생할 수 있음.
|
||||
* 탐지가 더 어려움 — interpreter 호출에 대한 **CloudTrail data events**가 활성화되어 있지 않으면(구성에 따라 호출이 기본적으로 기록되지 않을 수 있음).
|
||||
|
||||
#### 완화 / 보안 강화
|
||||
|
||||
* **Least privilege** 원칙을 interpreter `executionRoleArn`에 적용 (Lambda execution roles / CI roles처럼 취급).
|
||||
* **Restrict who can invoke** (`bedrock-agentcore:InvokeCodeInterpreter`) 및 누가 세션을 시작할 수 있는지를 제한.
|
||||
* 승인된 agent runtime roles를 제외하고 InvokeCodeInterpreter를 거부하도록 **SCPs** 사용(조직 수준의 강제 적용이 필요할 수 있음).
|
||||
* 적용 가능한 경우 AgentCore에 대해 적절한 **CloudTrail data events**를 활성화하고, 예기치 않은 호출 및 세션 생성에 대해 알림을 설정.
|
||||
|
||||
## 참고자료
|
||||
|
||||
- [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}}
|
||||
Reference in New Issue
Block a user