Hunting Shadow Admins in AWS
AWS privilege escalation techniques modelled by PMapper and awspx, where they fall short, and how I rebuilt the shadow admin check in Snotra to cover everything they do and more.
When conducting AWS Configuration Reviews, something I keep coming back to is shadow administrators. These are principals that look harmless, a deploy role or a service account for example, but have some combination of permissions that allows them to elevate their privileges to full administrator. Attackers love these as they are easy to miss, and they are also great for persistence. An attacker can set up a shadow admin somewhere that won't draw attention and use it to get back into the account long after the initial foothold has been burned.
The two tools most people use for this are NCC Group's PMapper and WithSecure's awspx. Both build a graph of the IAM principals in an account and work out who can reach administrator. They are both great tools and I have used them for years, but they haven't been updated in years either and are starting to show their age. I have also been using and developing Snotra for many years and it is the base of all my cloud configuration reviews. The old shadow admin check in Snotra was pretty basic, it scanned individual policy documents for a fixed list of dangerous actions and flagged them, completely ignoring resource scoping. This meant it was noisy and missed a lot of the more interesting paths. So I rebuilt it as a proper graph engine and used PMapper and awspx as the benchmark. This post goes through what each of those tools model, where they stop, and how Snotra now goes beyond both of them.
How the graph tools work
Both tools work in the same way. Every IAM user and role is a node, and an edge is drawn
from A to B whenever A can obtain the privileges of B. This could be by
assuming it, passing it to a service that will run attacker controlled code, resetting its
credentials and so on. Any nodes that are already administrator are marked, and if there is
a path from a principal to an admin node then that principal is a shadow admin.
PMapper works out this reachability directly and reports the path. awspx loads a similar graph into Neo4j and lets you query attack paths with Cypher. The main difference between them is which techniques each one knows how to draw an edge for.
What PMapper models
PMapper covers a wide range of services. It draws edges for:
sts:AssumeRole, taking into account the target's trust policy and checking the path both with and without MFA. It also handles cross-account role assumption.iam:UpdateAssumeRolePolicy- update a role's trust policy to trust yourself, then assume it.iam:CreateAccessKey,iam:CreateLoginProfileandiam:UpdateLoginProfileagainst another user.iam:PassRoleto a service that will run your code as the role: EC2 (with an instance profile), Auto Scaling, Lambda (creating a new function or editing an existing one), CloudFormation (creating or updating a stack, or a change set), CodeBuild and SageMaker.ssm:SendCommandandssm:StartSessionagainst an instance that already has a role attached.
As well as the paths it also reports on instance profiles, Lambda roles and CloudFormation roles with administrator access, roles with unsafe SSM permissions, principals in a circular access relationship, and administrators without MFA.
What it does not model is in-place self escalation. Every edge in PMapper points from
one principal to another principal, so a role that can just attach AdministratorAccess
to itself, or create a new default version of a policy it is already using, has nowhere to
point. It becomes administrator without ever leaving its own identity and the graph never
draws an edge. This is a real and common path, and it's exactly what awspx and Snotra pick up.
What awspx models
awspx takes the opposite approach. Rather than hard coding combinations it composes primitive IAM actions. It models:
- All of the in-place escalation actions:
iam:CreatePolicyVersion,iam:CreatePolicy,iam:Put{User,Role,Group}Policy,iam:Attach{User,Role,Group}Policy,iam:AddUserToGroup. - Creating new principals to pivot through:
iam:Create{User,Role,Group,InstanceProfile},iam:AddRoleToInstanceProfile,ec2:AssociateIamInstanceProfile. iam:CreateAccessKey,iam:CreateLoginProfileandiam:UpdateLoginProfile. awspx also knows thatCreateAccessKeyonly works if the target has less than two keys (or you can delete one), andCreateLoginProfileonly works if a profile doesn't already exist.iam:UpdateAssumeRolePolicy,sts:AssumeRole,ec2:RunInstances.
It takes conditions and resources into account and also models resource based policies.
However, it doesn't cover the rest of the services. awspx does not draw iam:PassRole
edges for Lambda, CloudFormation, Glue, SageMaker, CodeBuild or SSM like PMapper does, and it
doesn't do cross-account at all. It is also quite heavy to run, it needs Docker, a Neo4j
container and a full ingest before you can query anything.
Where they each fall short
To summarise:
- PMapper misses in-place self escalation (attaching or writing an admin policy to yourself, or creating a new policy version), because its edges only ever point to another principal.
- awspx misses
iam:PassRoleto services other than IAM and EC2, as well as cross-account paths, and is a pain to get up and running. - Both only cover the techniques in the published lists. Neither of them model the control plane and trust based techniques that have been published over the last couple of years, which is where most of the interesting modern privilege escalation paths are.
Whichever one you use, it's another tool to run alongside whatever you already use for configuration reviews, and you then have two sets of output to reconcile. I wanted this to be part of Snotra, reported as normal findings, written in pure Python with no extra dependencies.
What Snotra does now
Snotra builds the graph in memory from a single iam:GetAccountAuthorizationDetails
call, which returns every principal with its inline, attached and group policies as well as
role trust policies in one go. It also does a few regional sweeps for instance profiles,
running instances and existing resources that have a role attached. Permissions are evaluated
locally, with proper wildcard expansion, explicit Deny taking precedence and resource ARN
matching. This means an iam:PutRolePolicy scoped to arn:aws:iam::*:role/build-* is no
longer reported as a path to administrator. Statements with conditions are reported as
conditional rather than just being treated as wide open.
This covers everything PMapper and awspx model - sts:AssumeRole,
iam:UpdateAssumeRolePolicy, all of the in-place self escalation actions, credential
creation, SSM, and iam:PassRole to EC2, Lambda, CloudFormation, CodeBuild, SageMaker,
Glue and Auto Scaling. These are all reported as a single finding (iam_37) which lists
each non-administrative principal and the path it can take to administrator.
Going Further
The more interesting part is the techniques that neither PMapper nor awspx draw an edge for. These aren't about a single permission on a single principal, they are about manipulating the configuration that decides who is allowed to assume what. Snotra now models all of them:
- Identity provider manipulation. A principal with
iam:UpdateSAMLProvider,iam:UpdateOpenIDConnectProviderThumbprintoriam:AddClientIDToOpenIDConnectProviderover a SAML or OIDC provider can swap in an identity provider they control and federate in as any role that trusts that provider. This is basically the identity provider version ofiam:UpdateAssumeRolePolicy, and is how a lot of real world persistence is set up. There are some great write-ups on RogueOIDC, Silver SAML and persistence via a SAML identity provider. - IAM Roles Anywhere.
rolesanywhere:CreateProfilealong withiam:PassRoleallows an attacker to add any role to a profile and assume it with a certificate from a trust anchor they control. This is both a privilege escalation and a persistent backdoor, and is covered well in this post. - EKS access entries.
eks:CreateAccessEntryandeks:AssociateAccessPolicycan be used to associate the cluster admin access policy with yourself, giving you Kubernetes cluster administrator directly from IAM without any RBAC changes. Both Wiz and Datadog have looked into this. Snotra reports this as a separate finding, as cluster admin is a Kubernetes privilege rather than AWS account administrator, and it works well alongside Snotra Kubernetes. - AWS Identity Center. In an Identity Center management or delegated admin account, a principal that can edit and provision a permission set, create an account assignment, or add itself to a group can grant itself an administrative permission set across the whole organisation. None of this shows up in a normal IAM analysis. CloudQuery has a good breakdown of this.
As well as these, Snotra also covers a lot of the less common paths that the older tools
never included: EC2 Instance Connect (ec2-instance-connect:SendSSHPublicKey to a running
instance with a role attached), editing existing Glue jobs and dev endpoints,
lambda:UpdateFunctionConfiguration, and iam:PassRole to ECS, AWS Batch, DataPipeline,
Bedrock AgentCore, Step Functions, EMR, MWAA, App Runner, EKS node groups and CodePipeline.
There is also a check for a case that PMapper's reliance on Deny would otherwise miss,
where a principal is restricted by an explicit Deny but can delete or detach the policy
containing it (iam:DeleteRolePolicy, iam:DetachRolePolicy etc). Remove the
restriction first and then escalate.
Where the techniques came from
None of these techniques are new. The baseline comes from research that the community has been producing for years, including:
- Rhino Security Labs' AWS IAM Privilege Escalation methods and the companion repository - the original twenty-one methods and everything added since.
- Hacking the Cloud's IAM privilege escalation techniques, which is the most complete list, now over thirty-five techniques.
- Bishop Fox's iam-vulnerable and the playground write-up that goes with it, which is a great way to properly test a tool's coverage.
The newer identity provider and trust based techniques came from the posts linked above, as well as Elastic's post on sts:AssumeRoot.
What Snotra doesn't do
There are some limitations to be aware of:
- Cross-account paths are out of scope. PMapper will join graphs across an organisation, but Snotra only looks at one account at a time. A role that trusts an external account is still reported as a starting point, but Snotra won't tell you which principal in the other account can actually use it.
- Service Control Policies and permission boundaries are not evaluated, only identity policies are. This means it may report a path that an SCP or permission boundary would actually block, but it won't miss one. For a configuration review tool I would much rather it be that way round.
sts:AssumeRootis noted but not modelled, because it is really a management account to member account technique and belongs with the cross-account work which I have put on hold for now.
Scanning for it
All of this is available in Snotra now. Shadow
admin paths are reported in iam_37, and the separate categories - instance profile admin,
service role admin, circular access, administrators without MFA, EKS cluster admin, Identity
Center escalation and removable restrictions - are iam_41 to iam_47.
You can run the IAM checks on their own with:
snotra --results-dir ./results/ --service iam
iam:GetAccountAuthorizationDetails is required, which is included in both the
ReadOnlyAccess and SecurityAudit managed policies. ViewOnlyAccess does not
include it, so use one of the other two for full coverage.
Links
- Snotra - https://gitlab.com/snotra.cloud/aws
- PMapper - https://github.com/nccgroup/PMapper
- awspx - https://github.com/WithSecureLabs/awspx
- Rhino Security Labs - AWS IAM Privilege Escalation - https://rhinosecuritylabs.com/aws/aws-privilege-escalation-methods-mitigation/
- Hacking the Cloud - IAM Privilege Escalation - https://hackingthe.cloud/aws/exploitation/iam_privilege_escalation/
- Bishop Fox - iam-vulnerable - https://github.com/BishopFox/iam-vulnerable
- RogueOIDC - https://www.offensai.com/blog/rogueoidc-aws-persistence-and-evasion-through-attacker-controlled-oidc-identity-provider
- Wiz - EKS access entry attack vectors - https://www.wiz.io/blog/new-attack-vectors-emerge-via-recent-eks-access-entries
- CloudQuery - AWS Identity Center privilege escalation - https://www.cloudquery.io/blog/aws-priv-esc-identity-center
- Elastic Security Labs - Exploring AWS STS AssumeRoot - https://www.elastic.co/security-labs/exploring-aws-sts-assumeroot
About the author
Shaun is a Penetration Tester and Bitcoiner, with over a decade in the Security Industry, specialising in Cloud and Infrastructure Security and regularly completing assessments for all manner of companies from global corporations to small charities and non profits.