Skip to main content
Back
IntrusionAWS ยท Kubernetes
5 min read

TeamTNT takes AWS role credentials from the instance metadata service

Victim
Over 4,000 compromised Linux machines, containers and cloud instances, and a Kubernetes cluster observed by Sysdig; no organization is named
When
Feb 10, 2021, assumed from upload file namesDisclosed Mar 9, 2021
Entry
Remote code execution on Linux machines and containers, through misconfigurations or unpatched flaws (Trend Micro) or a brute-forced dashboard of a WordPress pod (Sysdig), then a shell script that collects AWS credentials.

Trend Micro published research on March 9, 2021 about a TeamTNT campaign in which a shell script, dropped on Linux machines, containers and cloud instances the actor had already compromised, searched for AWS credentials and uploaded them; it counted over 4,000 infected instances, about 200 of them with AWS customer data. In December 2021 Sysdig described the same script family in a WordPress pod of a Kubernetes cluster, entered through its brute-forced dashboard, where it asked the instance metadata service for the attached role's temporary credentials with requests that carried no session token. No source reports that any stolen credential was used.

What happened

Attacker side
Upload Server
Internet
EC2 Instance Metadatano session token sent
Compromised Linux Workloads
+ instance IAM role
+ role permissions
+ no reported use
AWS Account of the Role
WordPress Pod
Credential Script
Stored AWS Keys

Replaying the TeamTNT intrusion / from February 2021 by Trend Micro's reading

  1. 1

    Code execution on the workload

    Not reported

    A WordPress pod exposed outside the network is entered through its misconfigured dashboard, which is brute-forced and gives command execution in the container.

  2. 2

    Credential harvest

    From February 10, 2021 by Trend Micro's reading; not reported for the Sysdig attack

    A shell script searches environment variables, the host's containers and home-directory credential files for AWS keys, then asks the metadata service for the role's temporary credentials with requests that carry no session token.

  3. 3

    Upload to the attacker

    From February 10, 2021 by Trend Micro's reading; not reported for the Sysdig attack

    The script writes what it finds to a file, uploads it over HTTP to an attacker-controlled server and deletes the local copy; Trend Micro finds that server open as a browsable directory.

Impact

Over 4,000 machines ran the script and about 200 uploads held AWS customer data; Sysdig saw the script take a role's temporary credentials from a WordPress pod. No source reports that any stolen credential was used, and Trend Micro notes that a role with no permissions grants nothing.

Outcome

A plain metadata request handed out the role

No cloud control reaches a guessed password on your site's own dashboard, or the keys you leave in a machine's files and environment. What a cloud setting does reach is the metadata request: requiring IMDSv2 with a hop limit of 1 refuses the tokenless requests the script made, and a service control policy keeps the instances your member accounts launch or change on that setting. Security groups with no outbound rule to the internet refuse the upload where your workload needs no open web access. A Kubernetes NetworkPolicy only narrows the reach: it can keep pods that are not on the host network away from the metadata address and the upload server, and no source says whether the WordPress pod ran on the host network. No source reports that a stolen credential was used, and a role with no permissions grants nothing.

Could this have been prevented?

In hindsight, not as a whole. 2 controls would have refused a step outright, and 3 controls would have limited one. 2 steps have no cloud-provider control. The counts below are control assessments, not attack stages: several can address the same step. The same replay with the controls in place before the incident shows where each phase would have been refused or bounded.

2
Prevented
3
Contained
2
Not covered

How it could have been prevented

The same replay with the controls in place. Green marks where a step is refused, blue where it is bounded, and red where no control reaches it. Open a row to read the control, why it acts, and its caveat.

Attacker side
Upload Server
Internet
EC2 Instance Metadatano session token sent
Compromised Linux Workloads
+ instance IAM role
+ role permissions
+ no reported use
AWS Account of the Role
WordPress Pod
Credential Script
Stored AWS Keys

Replaying the TeamTNT intrusion / from February 2021 by Trend Micro's reading

1 ยท Code execution on the workload

1 Not covered

2 ยท Credential harvest

1 Prevented2 Contained1 Not covered3 on other clouds

3 ยท Upload to the attacker

1 Prevented1 Contained3 on other clouds

Key facts

  • Trend Micro published its research on March 9, 2021 and assumed, from the timestamps in the uploaded file names, that the campaign started on February 10, 2021; no end date was reported
  • Trend Micro saw over 4,000 infected instances; around 5%, or approximately 200, held sensitive information on AWS customers
  • Sysdig observed the script in a WordPress pod of a Kubernetes cluster that was entered through its misconfigured dashboard, which was brute-forced; it gave no date for that attack
  • The script asked the instance metadata service for the attached IAM role's name, then for its temporary access key, secret key and session token; the requests Sysdig showed carried no session token
  • The results were uploaded over HTTP to an attacker-controlled web server, which Trend Micro found open as a browsable directory
  • No source reported use of any stolen credential; Trend Micro noted that an instance has no permissions unless an administrator assigns them

Sources

Every fact in this breakdown comes from the public reporting below. The replay is a model of that reporting, not a reconstruction of the environment it describes.

  1. 1.
    TeamTNT Continues Attack on the Cloud, Targets AWS CredentialsTrend Micro Research ยท Mar 9, 2021 ยท ResearchCampaign start, dropper, metadata credential search, upload to an open directory, infection counts, no stated use of the credentials, recommendations
  2. 2.
    Threat news: TeamTNT stealing credentials using EC2 Instance MetadataSysdig Threat Research Team ยท Dec 7, 2021 ยท ResearchEntry through the WordPress pod, credential searches, metadata role-credential request, upload, no observed use of the credentials, recommendations including IMDSv2
  3. 3.
    TeamTNT targeting AWS, AlibabaCisco Talos ยท Apr 21, 2022 ยท ResearchStealer credential sources, upload and deletion, no cloud API calls, no CloudTrail or GuardDuty events in a test run

The estate in the replay is illustrative and drawn at the level of attack stages; the victim's real environment is not public. Verdicts describe what a control does when it is in place before the incident. They are not an assessment of the victim's security program.

More cloud attack breakdowns

All breakdowns