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

This commit is contained in:
Translator
2026-02-12 19:50:29 +00:00
parent dc4243d531
commit af1bdcbbf3

View File

@@ -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, yönetilen bir yürütme ortamıdır. **Custom Code Interpreters** bir **`executionRoleArn`** ile yapılandırılabilir; bu, “code interpreter'ın AWS services'e erişmesi için izin sağlar”.
Eğer bir **lower-privileged IAM principal**, **start + invoke** yetkisine sahip olarak, daha ayrıcalıklı bir **execution role** ile yapılandırılmış bir Code Interpreter oturumu başlatıp çalıştırabilirse, çağıran kimlik fiilen **pivot into the execution roles permissions** yapabilir (lateral movement / privilege escalation; rol kapsamına bağlı olarak).
> [!NOTE]
> Bu tipik olarak bir **misconfiguration / excessive permissions** sorunudur (interpreter execution role'e geniş izinler verilmesi ve/veya geniş invoke erişimi tanınması).
> AWS, execution role'lerin invoke etmeye izin verilen kimliklerden **equal or fewer** ayrıcalıklara sahip olmasını sağlayarak privilege escalation'dan kaçınılmasınııkça uyarır.
#### Ön Koşullar (yaygın yanlış yapılandırma)
- Bir **custom code interpreter** vardır ve aşırı ayrıcalıklı bir **execution role** ile yapılandırılmıştır (örn: hassas S3/Secrets/SSM erişimi veya IAM-admin benzeri yetenekler).
- Bir kullanıcı (developer/auditor/CI identity) şu izinlere sahiptir:
- start sessions: `bedrock-agentcore:StartCodeInterpreterSession`
- invoke tools: `bedrock-agentcore:InvokeCodeInterpreter`
- (Optional) Kullanıcı ayrıca interpreter oluşturabilir: `bedrock-agentcore:CreateCodeInterpreter` (organizasyon kısıtlamalarına bağlı olarak execution role ile yapılandırılmış yeni bir interpreter oluşturmasına izin verir).
#### Recon (custom interpreters ve execution role kullanımının belirlenmesi)
Interpreter'ları listeleyin (control-plane) ve yapılandırmalarını inceleyin:
```bash
aws bedrock-agentcore-control list-code-interpreters
aws bedrock-agentcore-control get-code-interpreter --code-interpreter-id <CODE_INTERPRETER_ID>
````
> create-code-interpreter komutu `--execution-role-arn` parametresini destekler; bu, yorumlayıcının sahip olacağı AWS izinlerini tanımlar.
#### Adım 1 - Bir oturum başlatın (bu bir `sessionId` döndürür, etkileşimli bir shell değildir)
```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"
```
#### Step 2 - Invoke code execution (Boto3 or signed HTTPS)
`start-code-interpreter-session`'den **etkileşimli python shell** yok. Yürütme **InvokeCodeInterpreter** aracılığıyla gerçekleşir.
**Seçenek A - Boto3 örneği (Python çalıştır + kimliği doğrula):**
```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)
```
Eğer yorumlayıcı bir execution role ile yapılandırıldıysa, `sts:GetCallerIdentity()` çıktısı o role ait kimliği (düşük ayrıcalıklı çağıranı değil) göstermelidir; bu pivot'u kanıtlar.
**Seçenek B - İmzalı HTTPS çağrısı (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\")"
}
}'
```
#### Etkiler
* **Lateral movement** — interpreter execution role'ın sahip olduğu AWS erişimine yayılma.
* **Privilege escalation** — interpreter execution role, çağırandan daha ayrıcalıklıysa yetki yükseltme.
* CloudTrail data events for interpreter invocations etkin değilse tespiti zorlaşır (çağrılar yapılandırmaya bağlı olarak varsayılan olarak kaydedilmeyebilir).
#### Önlemler / Sertleştirme
* Interpreter `executionRoleArn` üzerinde **Least privilege** uygulayın (Lambda execution roles / CI roles gibi değerlendirin).
* Kimlerin `bedrock-agentcore:InvokeCodeInterpreter` ile invoke edebileceğini ve kimlerin oturum başlatabileceğini kısıtlayın.
* Onaylanmış agent runtime rolleri hariç InvokeCodeInterpreter'ı reddetmek için **SCPs** kullanın (org-seviyesi zorlayıcı önlem gerekebilir).
* Uygun yerlerde AgentCore için **CloudTrail data events**'i etkinleştirin; beklenmeyen çağrılar ve oturum oluşturma için uyarı oluşturun.
## Referanslar
- [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}}