You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/pentesting-cloud/aws-security/aws-post-exploitation/aws-bedrock-post-exploitation/README.md
+109Lines changed: 109 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -130,11 +130,118 @@ The core issue is that the backend lets the model decide **who may do what** by
130
130
- 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.
131
131
- 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.
132
132
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.
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
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**.
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:
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
+
133
239
134
240
## References
135
241
136
242
-[When AI Remembers Too Much – Persistent Behaviors in Agents’ Memory (Unit 42)](https://unit42.paloaltonetworks.com/indirect-prompt-injection-poisons-ai-longterm-memory/)
137
243
-[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/)
138
245
-[Retain conversational context across multiple sessions using memory – Amazon Bedrock](https://docs.aws.amazon.com/bedrock/latest/userguide/agents-memory.html)
@@ -143,5 +250,7 @@ The core issue is that the backend lets the model decide **who may do what** by
143
250
-[Monitor model invocation using CloudWatch Logs and Amazon S3 – Amazon Bedrock](https://docs.aws.amazon.com/bedrock/latest/userguide/model-invocation-logging.html)
144
251
-[Track agent’s step-by-step reasoning process using trace – Amazon Bedrock](https://docs.aws.amazon.com/bedrock/latest/userguide/trace-events.html)
0 commit comments