Kuboid
Open Luck·Kuboid.in
Black Hat2024
Open in YouTube ↗

Breaching AWS Accounts Through Shadow Resources

Black Hat1,723 views32:16about 1 year ago

This talk demonstrates a novel attack vector called 'Shadow Resources' where attackers exploit predictable AWS resource naming conventions to hijack cloud services. By pre-emptively creating S3 buckets that AWS services expect to exist, attackers can intercept sensitive data, perform resource injection, and achieve remote code execution in victim accounts. The researchers provide a practical demonstration of this technique across multiple AWS services including CloudFormation, Glue, EMR, and SageMaker. The talk concludes with actionable mitigation strategies, such as using resource-based policies with the 'aws:ResourceAccount' condition and verifying bucket ownership.

Exploiting Predictable AWS Resource Naming to Hijack Cloud Services

TLDR: Researchers at Black Hat 2024 unveiled a technique called Shadow Resources, which exploits predictable naming conventions in AWS services like CloudFormation, Glue, and EMR. By pre-emptively creating S3 buckets that these services expect to use, attackers can intercept sensitive data, perform resource injection, and achieve remote code execution. Security teams should implement resource-based policies using the aws:ResourceAccount condition and verify bucket ownership to prevent these unauthorized interceptions.

Cloud security often feels like a game of cat and mouse, but sometimes the mouse is just waiting for the cat to walk into a trap it set months ago. The research presented at Black Hat 2024 on Shadow Resources highlights a fundamental flaw in how many AWS services handle resource creation. When a service like CloudFormation or Glue needs an S3 bucket to store temporary files or scripts, it often follows a predictable naming pattern. If an attacker can guess or calculate that name, they can create the bucket first, effectively squatting on the resource before the victim ever triggers the service.

This is not a theoretical vulnerability. It is a race condition where the attacker wins by default because they are not constrained by the victim's internal deployment timelines. Once the attacker owns the bucket, they control the data flow. They can intercept sensitive deployment templates, inject malicious code into Glue scripts, or redirect traffic to fake login pages in EMR Studio.

The Mechanics of Shadow Resources

The core of this attack vector lies in the predictability of AWS resource names. Many services generate bucket names using a combination of a static prefix, a hash, and a region. While the hash might seem like a barrier, the researchers found that it is often derived from account-specific metadata or predictable inputs. When a user initiates a service like CloudFormation, the service attempts to create a bucket. If that bucket already exists and the attacker has configured it with a permissive policy, the service will happily use the attacker's bucket instead of creating a new one.

Consider the CloudFormation attack flow. When a user uploads a template via the management console, the service creates an S3 bucket to store the template file. If an attacker has already created a bucket with the expected name in the target region, the service will upload the template to the attacker's bucket. The attacker then has immediate access to the victim's infrastructure-as-code, which often contains sensitive configuration details or hardcoded credentials.

To automate the discovery of these buckets, the researchers developed TrailShark, a tool that allows security researchers to debug AWS API calls similarly to how one would inspect network traffic with Wireshark. By monitoring the API calls made during service initialization, they identified the specific, often undocumented, calls that trigger these bucket creations.

From Data Leakage to Remote Code Execution

The impact of Shadow Resources scales with the service being targeted. In AWS Glue, the attack is particularly devastating. Glue jobs often pull Python scripts from S3. If an attacker controls the bucket where these scripts are stored, they can replace the legitimate script with a malicious one. When the victim runs the Glue job, they are executing the attacker's code with the permissions of the Glue service role.

The following command demonstrates how an attacker might verify bucket ownership during a penetration test, ensuring they are interacting with the correct resource:

aws s3api list-objects-v2 --bucket <BUCKET_NAME> --expected-bucket-owner <OWNER_ACCOUNT_ID>

This command is a critical check for any pentester. If the expected-bucket-owner does not match the account you are testing, you have likely stumbled upon a misconfigured or hijacked resource.

In EMR Studio, the researchers demonstrated a post-exploitation technique where they injected JavaScript into a Jupyter notebook. Because the notebook is parsed by the victim's browser, this leads to a classic cross-site scripting scenario, allowing the attacker to steal session tokens or perform actions on behalf of the authenticated user. This falls squarely under OWASP A01:2021-Broken Access Control, as the service fails to verify that the bucket it is using actually belongs to the account initiating the request.

Defensive Strategies for the Cloud

Defending against Shadow Resources requires a shift in how we think about resource-based policies. You cannot rely on the assumption that a bucket name is private. Instead, you must explicitly define who is allowed to interact with your resources.

The most effective mitigation is to use the aws:ResourceAccount condition in your S3 bucket policies. This ensures that even if an attacker manages to create a bucket with a name that your service expects, the service will be denied access because the bucket does not belong to your account.

"Condition": {
    "StringEquals": {
        "aws:ResourceAccount": "YOUR_ACCOUNT_ID"
    }
}

Additionally, always verify the bucket owner when performing operations on S3. If you are writing automation scripts, include the --expected-bucket-owner flag in your AWS CLI commands. This simple addition prevents your scripts from accidentally interacting with a bucket that has been hijacked or misconfigured.

Shadow Resources serve as a stark reminder that in the cloud, predictability is a vulnerability. As we continue to build more complex architectures, we must account for the fact that our services are not operating in a vacuum. They are interacting with a shared global namespace, and if we do not lock down our resources, we are leaving the door open for anyone who can guess the name on the lock. Stop treating your account ID as a secret, and start treating your resource policies as the primary line of defense.

Talk Type
research presentation
Difficulty
advanced
Has Demo Has Code Tool Released


Black Hat USA 2024

121 talks · 2024
Browse conference →
Premium Security Audit

We break your app before they do.

Professional penetration testing and vulnerability assessments by the Kuboid Secure Layer team. Securing your infrastructure at every layer.

Get in Touch
Official Security Partner
kuboid.in