Exploiting Misconfigured IAM assume-role in AWS
In the realm of AWS, the keys to the kingdom often lie in the hands of IAM roles. With the right permissions, a role can do anything from spinning up EC2 instances to exfiltrating data.
Last updated
In the realm of AWS, the keys to the kingdom often lie in the hands of IAM roles. With the right permissions, a role can do anything from spinning up EC2 instances to exfiltrating data.
Last updated
At its core, an IAM role is a set of permissions that grant access to specific AWS resources. When an entity assumes a role, it inherits these permissions, often temporarily, making it a powerful tool for security and flexibility. The assume-role
action is what allows one entity (a user, an application, or another service) to take on the role of another, often with elevated permissions.
But here’s the kicker: if the assume-role permissions are misconfigured, it opens up a whole new attack vector.
Misconfigured assume-role policies are like an unlocked backdoor to your AWS environment. Here's how an attacker can exploit them:
Role Enumeration: First, the attacker identifies potential roles they can assume. This could be done through API calls or by gaining access to an already compromised environment where roles are listed.
Exploiting Trust Policies: Trust policies define who can assume a role. If these are too permissive—allowing any account or broad groups of users—an attacker can easily slip through. For instance, a trust policy that allows all AWS accounts to assume a role (Principal: "*"
in the policy) is a big red flag.
Privilege Escalation: Once an attacker assumes a role, they can escalate their privileges. For example, if the assumed role has s3:*
permissions, the attacker can access all S3 buckets and data. If it has EC2 permissions, the attacker could spin up instances, inject malicious code, or pivot to other services.
Persistence and Data Exfiltration: With elevated access, attackers can create persistence mechanisms, such as creating backdoor users or roles, and then proceed to exfiltrate sensitive data, deploy crypto miners, or cause other havoc.
Consider a scenario where a developer accidentally allows a wide range of entities to assume a role meant for internal use only. An attacker who discovers this could gain access to production databases, exfiltrate sensitive data, or use the environment for cryptojacking.
Another common mistake is when roles are set up for cross-account access without proper restrictions. An attacker with access to one account could jump into another, broadening their attack surface.
Let's see if we have any inline user policies attached to our IAM user.
This reveals the policy named test-temp-user
. Let's check it out.
This reveals that the user is allowed to assume the role named AdminRole
!
Having identified the role, the attacker attempted to assume it. We can do this with the command below.
To assume the role, we need to issue the aws configure
command to utilize the AccessKeyId
and SecretAccessKey
provided from the above step. Then issue the command aws configure set aws_session_token "<SessionToken>"
to set the token. With that done we can call the command aws sts get-caller-identity
and verify our new context!
To prevent your IAM roles from becoming attack vectors, follow these best practices:
Least Privilege: Always follow the principle of least privilege. Grant only the permissions necessary for the role's function and regularly audit these permissions.
Restrictive Trust Policies: Define narrow trust policies. Only allow specific accounts or services to assume roles, and avoid wildcard entries like "Principal": "*"
.
Role Monitoring: Implement logging and monitoring for role assumption activities. AWS CloudTrail can track assume-role events, helping you detect suspicious activity.
Regular Audits: Conduct regular IAM policy audits. Use tools like AWS IAM Access Analyzer to identify overly permissive roles and trust policies.
Automation: Automate the enforcement of security policies using AWS Config or custom scripts to detect and remediate misconfigurations in real-time.
In the game of cloud security, misconfigured IAM assume-roles are low-hanging fruit for attackers. By understanding the mechanics of these exploits and tightening your IAM policies, you can turn the tables on potential attackers and secure your AWS environment against unauthorized access. Remember, in the cloud, your best defense is a well-configured offense. Stay vigilant, and keep those roles locked down tight.