Skip to content

Commit 2e66838

Browse files
committed
arte-veue
1 parent 979375b commit 2e66838

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

src/pentesting-cloud/aws-security/aws-services/aws-ecs-enum.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,43 @@ aws ecs describe-tasks --cluster <cluster> --tasks <tasks>
5353
aws ecs describe-task-definition --task-definition <TASK_NAME>:<VERSION>
5454
```
5555

56+
### On-Host Enumeration via the ECS Agent State DB (`agent.db`)
57+
58+
When you have **shell access on an ECS container instance** , or you have **escaped a container with a host bind-mount of `/var/lib/ecs`** (a common misconfiguration when tasks run privileged or with `volumesFrom` exposing the host data dir), the ECS agent leaves `agent.db` on disk that can be read **without any AWS API call**, **without any IAM permission**, and **without triggering CloudTrail**.
59+
60+
```
61+
/var/lib/ecs/data/agent.db
62+
```
63+
64+
(or, when reading from a container that has the host mounted at `/host`, `/host/var/lib/ecs/data/agent.db`).
65+
66+
```bash
67+
# Most useful one-liner — dumps everything readable
68+
strings /var/lib/ecs/data/agent.db
69+
70+
# From inside a container with the host mounted at /host
71+
strings /host/var/lib/ecs/data/agent.db
72+
73+
# Filter for the highest-value artefacts
74+
strings /var/lib/ecs/data/agent.db | grep -aE 'arn:aws:|AKIA|ASIA|"secret|password|TOKEN|credentials|taskRoleArn|executionRoleArn'
75+
76+
# Save the outcome from strings for offline analysis
77+
strings /host/var/lib/ecs/data/agent.db >> /tmp/agent.txt
78+
tr -s '{}[],:"\\' '\n' < /tmp/agent.txt | sed 's/^[[:space:]]*//; s/[[:space:]]*$//' | awk 'NF && length($0)>2 && !/^[0-9.]+$/' | sort -u
79+
```
80+
81+
#### What you can recover
82+
83+
Depending on the cluster's age and workload churn, `strings` against `agent.db` typically yields:
84+
85+
- **Task and execution IAM role ARNs** (`taskRoleArn`, `executionRoleArn`) for every task the agent has run — useful targets for [credential retrieval via the task metadata endpoint](https://cloud.hacktricks.wiki/en/pentesting-cloud/aws-security/aws-services/aws-ecs-enum.html) (`169.254.170.2`).
86+
- **Full task definitions** — image URIs (often private ECR repos), command, entrypoint, port mappings, mount points, log configuration, and **plaintext environment variables** that frequently include database URLs, API tokens, and third-party secrets.
87+
- **Secrets references**`secretOptions` and `secrets` blocks pointing at SSM Parameter Store paths and Secrets Manager ARNs (great pivot list).
88+
- **Container instance ARN, cluster ARN, and registration token** — confirms the cluster name and account/region context with no API call.
89+
- **ENI metadata** — private IPs, MAC addresses, subnet IDs, and security group IDs assigned in `awsvpc` mode (useful for lateral movement planning).
90+
- **Image pull credentials** — when the task definition uses `repositoryCredentials`, the referenced Secrets Manager ARN is here; on older agents private-registry auth blobs (`ECS_ENGINE_AUTH_DATA`) may also be cached.
91+
- **Recently-stopped task containers** — including names, IDs, exit codes and labels, sometimes long after the corresponding `aws ecs describe-tasks` call has aged them out of the API response.
92+
5693
### Unauthenticated Access
5794

5895
{{#ref}}

0 commit comments

Comments
 (0)