AWS - ECS Enum
Tip
AWS 해킹 학습 및 실습:
HackTricks Training AWS Red Team Expert (ARTE)
GCP 해킹 학습 및 실습:HackTricks Training GCP Red Team Expert (GRTE)
Az 해킹 학습 및 실습:HackTricks Training Azure Red Team Expert (AzRTE)
HackTricks 지원하기
- 구독 플랜을 확인하세요!
- 참여하세요 💬 Discord group 또는 telegram group에 참여하거나 Twitter 🐦 @hacktricks_live를 팔로우하세요.
- PR을 제출하여 해킹 트릭을 공유하세요: HackTricks 및 HackTricks Cloud github repos.
ECS
Basic Information
Amazon Elastic Container Services 또는 ECS는 클라우드에서 containerized applications를 호스팅하는 플랫폼을 제공합니다. ECS에는 deployment 방식이 두 가지 있는데, EC2 instance type과 serverless 옵션인 Fargate입니다. 이 서비스는 클라우드에서 containers를 실행하는 것을 매우 쉽고 거의 고통 없이 만들어줍니다.
ECS는 다음 세 가지 building blocks로 동작합니다: Clusters, Services, 그리고 Task Definitions.
- Clusters는 클라우드에서 실행 중인 containers의 그룹입니다. 앞서 언급했듯이 containers에는 두 가지 launch type이 있는데, EC2와 Fargate입니다. AWS는 EC2 launch type을 고객이 “Amazon EC2 instances의 cluster에서 [자신의] containerized applications를 manage하도록 허용하는 것”으로 정의합니다. Fargate도 유사하며 “backend infrastructure를 provision하고 manage할 필요 없이 [자신의] containerized applications를 실행할 수 있게 해주는 것”으로 정의됩니다.
- Services는 cluster 내부에 생성되며 tasks를 실행하는 역할을 합니다. service definition 안에서 실행할 tasks의 수, auto scaling, capacity provider (Fargate/EC2/External), 그리고 VPC, subnets, security groups 같은 networking 정보를 정의합니다.
- 애플리케이션에는 2가지 유형이 있습니다:
- Service: 장시간 실행되는 computing work를 처리하는 task들의 그룹으로, 중지되었다가 다시 시작될 수 있습니다. 예를 들어 web application.
- Task: 실행되고 종료되는 독립적인 task입니다. 예를 들어 batch job.
- service applications에는 2가지 service scheduler 유형이 있습니다:
- REPLICA: replica scheduling strategy는 cluster 전반에 걸쳐 task의 원하는 수를 배치하고 유지합니다. 어떤 이유로 task가 종료되면 같은 node 또는 다른 node에서 새 task가 시작됩니다.
- DAEMON: 필요한 요구 사항을 가진 모든 active container instance에 정확히 하나의 task를 배포합니다. 원하는 task 수, task placement strategy, Service Auto Scaling policies를 지정할 필요가 없습니다.
- Task Definitions는 어떤 containers가 실행될지 정의하고, host와의 port mappings, env variables, Docker entrypoint 등 containers에 대해 설정될 다양한 파라미터를 담당합니다.
- 민감한 정보가 있는 env variables를 확인하세요!
Sensitive Data In Task Definitions
Task definitions는 ECS에서 실제로 실행될 containers를 구성하는 역할을 합니다. task definitions가 containers의 실행 방식을 정의하므로, 그 안에서 많은 정보를 찾을 수 있습니다.
Pacu can enumerate ECS (list-clusters, list-container-instances, list-services, list-task-definitions), it can also dump task definitions.
Enumeration
# Clusters info
aws ecs list-clusters
aws ecs describe-clusters --clusters <cluster>
# Container instances
## An Amazon ECS container instance is an Amazon EC2 instance that is running the Amazon ECS container agent and has been registered into an Amazon ECS cluster.
aws ecs list-container-instances --cluster <cluster>
aws ecs describe-container-instances --cluster <cluster> --container-instances <container_instance_arn>
# Services info
aws ecs list-services --cluster <cluster>
aws ecs describe-services --cluster <cluster> --services <services>
aws ecs describe-task-sets --cluster <cluster> --service <service>
# Task definitions
aws ecs list-task-definition-families
aws ecs list-task-definitions
aws ecs list-tasks --cluster <cluster>
aws ecs describe-tasks --cluster <cluster> --tasks <tasks>
## Look for env vars and secrets used from the task definition
aws ecs describe-task-definition --task-definition <TASK_NAME>:<VERSION>
ECS Agent State DB (agent.db)를 통한 On-Host Enumeration
shell access on an ECS container instance가 있거나, /var/lib/ecs의 host bind-mount로 container에서 escaped한 경우(작업이 privileged로 실행되거나 volumesFrom이 host data dir를 노출할 때 흔한 misconfiguration), ECS agent는 디스크에 agent.db를 남기며, 이는 어떤 AWS API call도 없이, 어떤 IAM permission도 없이, CloudTrail을 트리거하지 않고 읽을 수 있습니다.
/var/lib/ecs/data/agent.db
(또는, host가 /host에 마운트된 container에서 읽을 때는 /host/var/lib/ecs/data/agent.db).
# Most useful one-liner — dumps everything readable
strings /var/lib/ecs/data/agent.db
# From inside a container with the host mounted at /host
strings /host/var/lib/ecs/data/agent.db
# Filter for the highest-value artefacts
strings /var/lib/ecs/data/agent.db | grep -aE 'arn:aws:|AKIA|ASIA|"secret|password|TOKEN|credentials|taskRoleArn|executionRoleArn'
# Save the outcome from strings for offline analysis
strings /host/var/lib/ecs/data/agent.db >> /tmp/agent.txt
tr -s '{}[],:"\\' '\n' < /tmp/agent.txt | sed 's/^[[:space:]]*//; s/[[:space:]]*$//' | awk 'NF && length($0)>2 && !/^[0-9.]+$/' | sort -u
복구할 수 있는 것
클러스터의 연식과 workload churn에 따라, agent.db에 대해 strings를 실행하면 일반적으로 다음을 얻을 수 있습니다:
- Task 및 execution IAM role ARNs (
taskRoleArn,executionRoleArn) - agent가 실행한 모든 task에 대해 존재하며, task metadata endpoint (169.254.170.2)를 통한 credential retrieval의 유용한 대상입니다. - 전체 task definition - image URI(대개 private ECR repos), command, entrypoint, port mappings, mount points, log configuration, 그리고 종종 database URLs, API tokens, third-party secrets를 포함하는 plaintext environment variables.
- Secrets references - SSM Parameter Store path와 Secrets Manager ARNs를 가리키는
secretOptions및secretsblock(훌륭한 pivot list). - Container instance ARN, cluster ARN, 및 registration token - API call 없이 cluster name과 account/region context를 확인합니다.
- ENI metadata -
awsvpcmode에서 할당된 private IP, MAC address, subnet ID, security group ID( lateral movement 계획에 유용). - Image pull credentials - task definition이
repositoryCredentials를 사용할 때, 참조된 Secrets Manager ARN이 여기에 있습니다; older agents에서는 private-registry auth blob(ECS_ENGINE_AUTH_DATA)도 캐시될 수 있습니다. - 최근에 중지된 task containers - 이름, ID, exit code, label을 포함하며, 경우에 따라 해당
aws ecs describe-taskscall이 API response에서 더 이상 나타나지 않는 한참 뒤에도 남아 있습니다.
Unauthenticated Access
AWS - ECS Unauthenticated Enum
Privesc
In the following page you can check how to abuse ECS permissions to escalate privileges:
Post Exploitation
Persistence
Tip
AWS 해킹 학습 및 실습:
HackTricks Training AWS Red Team Expert (ARTE)
GCP 해킹 학습 및 실습:HackTricks Training GCP Red Team Expert (GRTE)
Az 해킹 학습 및 실습:HackTricks Training Azure Red Team Expert (AzRTE)
HackTricks 지원하기
- 구독 플랜을 확인하세요!
- 참여하세요 💬 Discord group 또는 telegram group에 참여하거나 Twitter 🐦 @hacktricks_live를 팔로우하세요.
- PR을 제출하여 해킹 트릭을 공유하세요: HackTricks 및 HackTricks Cloud github repos.
HackTricks Cloud

