Resource Hijacking: Compute Hijacking - ECS
AWS Specific Sub-Technique
Other sub-techniques of Resource Hijacking (9)
AWS Specific Content
A prerequisite for this technique is that a threat actor has already gained control of an AWS identity with the permissions to access or create Amazon ECS resources.
Using this technique, a threat actor can use Amazon ECS resources for their computation requirements with the cost of the resources being attributed to the compromised account. Threat actors can either hijack an existing ECS container or create ECS containers or clusters for this purpose.
This technique is related to the Modify Cloud Compute Infrastructure > Create Cloud Instance technique and is used to additionally identify what type of cloud instance was created.
In addition to creating new ECS containers or clusters, threat actors may exploit application-layer vulnerabilities in existing containerized workloads running on Amazon ECS to deploy malware or run unauthorized application workloads. Threat actors may attempt to exploit running ECS tasks to deploy malware within the container environment and, in separate cases, deployed or modified ECS tasks to run fraudulent application workloads such as unauthorized payment dashboards. Threat actors may also register malicious task definitions or modify existing ECS services to replace legitimate containers with threat actor-controlled images.
Detection
AWS Specific Content
Configure, review, and monitor VPC Flow logs traffic egress from the ECS container to capture records of unauthorized all traffic originating or transiting through the ECS container.
Amazon GuardDuty has detections and finding types for when potential threats based on operating system-level behavior on ECS workloads is found.
When this technique is used by the threat actor, actions taken by the threat actor using the credentials obtained will be logged in CloudTrail. You can use the Event History page in the AWS CloudTrail console to view the last 90 days of management events in an AWS Region for the events listed in the AWS CloudTrail Event Name(s) section, such as
ecs:CreateCluster.A separate CloudTrail trail will give you an ongoing record of events in your AWS account past 90 days and can be configured to log events in multiple regions. You can also review events using the console as well as the AWS CLI.
It is also possible to create a CloudWatch metric filter to watch for when specific AWS API calls are used and perform notification actions if logged, and additionally configure CloudWatch to automatically perform an action in response to an alarm.
In AWS CloudTrail, monitor for
ecs:RegisterTaskDefinition and ecs:UpdateService calls from unexpected principals or at unusual times. Monitor for ecs:ExecuteCommand calls which indicate interactive access to running containers. Key indicators of compromise include task definitions referencing container images from unexpected registries, tasks running with elevated privileges or host networking mode, and ECS services modified to use different task definitions than originally configured.If Amazon GuardDuty is configured with ECS Runtime Monitoring, findings related to malware execution, cryptocurrency mining, or connections to known malicious IP addresses within ECS tasks may be generated.
Mitigation
AWS Specific Content
You can make sure that principals are scoped with the least-privileged permissions necessary to perform duties, limiting the ability to perform unauthorized actions in an AWS account when not required. One possible method of applying the principle of least-privileged permissions is to use Service Control Policies to restrict the maximum available permissions for the IAM users and IAM roles within your AWS Organizations accounts (note - you should test SCPs in a development environment before deploying them in production).
You can also use IAM Access Analyzer to regularly review and verify access and manage permissions across your AWS environment, which will highlight AWS identities with excessive permissions and the actions performed by those identities.
It is also possible to block the use of IAM user and IAM role credentials outside of trusted IP networks using Service Control Policies. Examples of these policies are available in the aws-samples repository for data perimeters, and include a sample policy for IAM users and a sample policy for IAM roles.
Apply least-privilege task execution roles and task roles for ECS tasks. Use
awsvpc networking mode with security groups to restrict network access for each task. Enable ECS Exec audit logging to monitor interactive access to containers. Enable Amazon GuardDuty ECS Runtime Monitoring for runtime threat detection. Use Amazon ECR image scanning to detect vulnerabilities in container images before deployment. Restrict ecs:RegisterTaskDefinition and ecs:UpdateService permissions to authorized deployment pipelines only.