Attackers Exploit Public .env Files to Breach Cloud and Social Media Accounts

Summary:
Unit 42 researchers uncovered a highly sophisticated extortion campaign that specifically targeted cloud environments by exploiting exposed environment variable files, commonly referred to as .env files. These files, which are often used to store sensitive information such as cloud service keys, API tokens, and database credentials, were inadvertently exposed due to misconfigurations in web servers and applications. The attackers took advantage of this widespread misconfiguration to gain unauthorized access to numerous organizations' cloud infrastructures.


The attackers scanned over 230 million potential targets and successfully compromised more than 110,000 domains. From these exposed .env files, they extracted approximately 90,000 unique variables. Notably, 7,000 of these variables were associated with cloud services, providing the attackers with direct access to cloud environments, while 1,500 were linked to social media accounts, which included not just authentication keys but often account names as well. The attackers demonstrated a high level of sophistication and automation. After gaining initial access through compromised AWS Identity and Access Management (IAM) credentials found in .env files, they performed a series of automated operations to escalate privileges within the cloud environments. One of the key tools in their arsenal was the use of AWS Lambda functions. The attackers created and deployed these serverless functions across multiple regions, using them to perform large-scale internet scans for more exposed .env files. This automated approach allowed them to efficiently harvest sensitive information and expand their reach within compromised environments.


Once inside the cloud environments, the attackers executed a variety of tactics to deepen their control. They escalated privileges by creating new IAM roles with administrative access, which gave them full control over the affected environments. They also exfiltrated data from Amazon S3 buckets using the S3 Browser tool, meticulously searching for valuable data to steal. After exfiltrating and deleting the data from the victim's S3 buckets, they left ransom notes demanding payment in Bitcoin to prevent the sale of the stolen data on the dark web.


Security Officer Comments:


The campaign’s success was not due to vulnerabilities in the cloud providers’ infrastructure, but rather due to the exploitation of common misconfigurations and security oversights within the victim organizations.

Suggested Corrections:
Given the sophisticated nature of this attack, it’s crucial to implement robust security measures to protect our cloud environments. Here are key strategies we should focus on:

  1. Secure Environment Files: .env files and similar configuration files should never be publicly accessible. Implement security controls such as network access restrictions, and ensure that these files are stored securely, away from public directories.
  2. Use Temporary Credentials: Where possible, replace long-lived access keys with IAM roles that provide temporary, short-lived credentials. These roles should be configured to provide just-in-time access, minimizing the window of opportunity for attackers.
  3. Principle of Least Privilege: Review and tighten IAM policies regularly. Ensure that IAM roles and users have only the permissions they need to perform their tasks—nothing more. Also, consider implementing service control policies (SCPs) at the organizational level to enforce these restrictions.
  4. Disable Unused Regions: Threat actors often deploy resources in regions that are not actively monitored. By disabling regions that are not in use, we can reduce the attack surface and make it harder for attackers to hide their activities.
  5. Enable Comprehensive Logging and Monitoring: Enable logging services such as AWS CloudTrail, VPC flow logs, and GuardDuty across all regions. This will provide visibility into API calls and network traffic, enabling us to detect and respond to suspicious activities more effectively.
  6. Automate Security Posture Management: Use tools like AWS Config, Prisma Cloud, or similar services to automatically assess and enforce security best practices across your cloud environment. Automation can help detect and remediate misconfigurations before they can be exploited."

Link(s):
https://thehackernews.com/2024/08/attackers-exploit-public-env-files-to.html