Tech with Tyler
LinkedInGitHubYouTube
  • 👋Welcome!
    • whoami
    • !!! Disclaimer !!!
  • 🎓Academy
    • AWS Security Cookbook by Tyler
      • AWS Control Tower
        • Lab: Deploying AWS Control Tower via Terraform
      • AWS CloudTrail
      • AWS GuardDuty
        • Lab: Deploying AWS GuardDuty via Terraform
        • Lab: Logging GuardDuty Findings to S3
        • Lab: Adversary Simulation Detection with Stratus Red Team and GuardDuty
      • AWS Organizations
        • Lab: Deploying AWS Organizations via Terraform
      • AWS Root Account Management
        • Lab: Deploying AWS Root Account Management via Terraform
      • AWS Service Control Policies (SCPs)
        • Lab: Deploying AWS Service Control Policies (SCPs) via Terraform
      • TBD - Coming Soon!
        • [TBD] AWS Account Factory
        • [TBD] AWS Identity Center
    • My content on Cybr
      • Course - Terraform on AWS: From Zero to Cloud Infrastructure
      • Lab - Create Static AWS S3 Website with Terraform
      • Lab - Secure EC2 Access with SSM Session Manager and KMS
      • Lab - Encrypt and Decrypt Data with KMS and Data Encryption Keys
    • My content on PwnedLabs
      • Cyber Range - Electra
      • Lab - Abusing Identity Providers in AWS
      • Lab - Prowler and AWS Security Hub
      • Blog - Abusing Identity Providers in AWS
      • Blog - Building Security Guardrails with AWS Resource Control Policies
      • Blog - Defending Against the whoAMI Attack with AWS Declarative Policies
    • My content on YouTube
      • AWS Security Engineering
      • Linux in 60 Seconds!
  • ☁️Cloud Security
    • AWS Attacks and Techniques
      • Enumerate AWS Account IDs
      • Enumerate AWS IAM Users
      • Enumerate (Unauthenticated) IAM Users and Roles
      • Enumerate AWS Public Resources
      • Enumerate Secrets in AWS
      • Generate AWS Console Session
      • Generate IAM Access Keys from CloudShell
      • Password Spraying AWS IAM Users
      • Subdomain Takeovers
    • AWS Privilege Escalation
      • Identity Access Management (IAM)
      • IAM Trust Policies
      • Key Management Service (KMS)
      • Lightsail
      • OpenID Connect (OIDC)
      • S3
      • Secrets Manager
      • Security Token Service (STS)
    • AWS General Info
      • Amazon Bedrock
      • EC2
      • KMS
      • S3
      • SNS Topic
    • AWS CLI Cheat Sheet
    • Capture the Flags (CTFs)
      • Flaws.Cloud
        • Level 1
        • Level 2
        • Level 3
        • Level 4
        • Level 5
        • Level 6
      • PwnedLabs
        • Escalate Privileges by IAM Policy Rollback
        • Exploiting Weak S3 Bucket Policies
        • Leveraging S3 Bucket Versioning
        • S3 Enumeration Basics
        • Pillage Exposed RDS Instances
        • EC2 SSRF Attack
        • Hunt for Secrets in Git Repos
      • Cybr
        • Challenge - Secrets Unleashed
    • Tools
      • Tooling Index
      • dsnap
      • Pacu
      • s3-account-search
      • GoAWSConsoleSpray
      • aws_consoler
      • cloudenum
  • 📦Containers & Orchestration
    • Kubernetes
  • 👨‍💻Coding & CLI Tooling
    • CLI Tools
      • AWS CLI
      • Git
      • GitHub Copilot (CLI)
      • Homebrew
      • jq
      • ngrok
      • ssh
    • Coding and Scripting
      • Bash
      • Python
    • Terminal Customization
  • ⚙️DevSecOps
    • CI/CD
      • GitLab
    • Hashicorp Terraform
    • Hashicorp Vault
    • IAC Scanning
      • tfsec
    • Secrets Scanning
      • Trufflehog
  • 🎁Miscellaneous
    • Jenkins
  • 💻Operating Systems
    • Linux
      • APT Package Manager
      • CLI Tools Cheat Sheet
      • Man Pages
      • Services
      • Users and Groups
  • 🏗️Projects
    • Active Directory Homelab Automation
    • AWS Cloud Resume Challenge
    • Proxmox Homelab as Code
  • 📌Other
    • Useful Resources
Powered by GitBook
On this page
  • Setup
  • IAM Commands
  • Users/Roles/Groups
  • Policies
  • Identity Center Commands
  • S3
  • SSM
  • Secrets Manager
  • DynamoDB

Was this helpful?

  1. Cloud Security

AWS CLI Cheat Sheet

Quick reference for commonly used commands

PreviousSNS TopicNextCapture the Flags (CTFs)

Last updated 11 months ago

Was this helpful?

Setup

# Cli command structure
aws <service> <action> --region <region> --profile <profileName>

# Configure aws cli
aws configure
aws configure --profile <nameOfProfile>
aws configure set aws_session_token <sessionToken> --profile <nameOfProfile>

# Whoami
aws sts get-caller-identity

IAM Commands

Users/Roles/Groups

# list iam users
aws iam list-users

# list iam roles
aws iam list-roles

# list iam groups
aws iam list-groups

# list all iam access keys for a user
aws iam list-access-keys --user-name <iamUserName> --profile <awsProfile>

# create iam access keys
aws iam create-access-key --user-name <iamUserName> --profile <awsProfile>

# assume an iam role
aws sts assume-role --role-arn <arnIamRole> --role-session-name <whatever> --profile <awsProfile>

Policies

User Enumeration

# list iam Inline policies attached to user
aws iam list-user-policies --user-name <user>

# list iam Managed policies attached to user
aws iam list-attached-user-policies --user-name <user>

Role Enumeration

# list iam trust policy attached to role
aws iam get-role --role-name <roleName> --query 'Role.AssumeRolePolicyDocument'

# list Inline policies attached to role
aws iam list-role-policies --role-name <roleName>

# list Managed policies attached to role
aws iam list-attached-role-policies --role-name <roleName>

Policy Enumeration

# view Managed policy info
aws iam get-policy --policy-arn <policyARN>

# view Managed policy version and actions
aws iam get-policy-version --policy-arn <policyARN> --version-id <policyVersionId>

# view Inline policy 
aws iam get-user-policy --user-name <user> --policy-name <policy-name>

# view available versions of a policy
aws iam list-policy-versions --policy-arn <policyArn>

# view the policy for a particular version
aws iam get-policy-version --policy-arn <policyArn> --version-id <versionId>

# attach a specific version of a policy
aws iam set-default-policy-version --policy-arn <policyArn> --version-id <versionId>

Identity Center Commands

# list Identity Center instance, returns ARN
aws sso-admin list-instances --region <region>

# view permission sets
aws sso-admin list-permission-sets --instance-arn <instanceARN> --region <region>

# view permission set details
aws sso-admin describe-permission-set --instance-arn <instanceARN> --permission-set-arn <permissionSetARN>

# view Inline policy for permission set
aws sso-admin get-inline-policy-for-permission-set --instance-arn <instanceARN> --permission-set-arn <permissionSetARN>

S3

# list bucket contents
aws s3 ls s3://<bucketName> --recursive --no-sign-request

# copy files
aws s3 cp s3://<bucketName> /local/path/download --recursive --no-sign-request
aws s3 cp s3://<bucketName>/object /local/path/download --no-sign-request

# get bucket versioning
aws s3api list-object-versions --bucket <bucketName>

# get particular version of an object
aws s3api get-object --bucket <bucketName> --key "object/object" --version-id <versionID> <objectName>

SSM

# remote code execution
aws ssm send-command \
    --document-name "AWS-RunShellScript" \
    --parameters 'commands=["echo HelloWorld"]' \
    --targets "Key=instanceids,Values=i-1234567890abcdef0,<instanceId2>,<instanceId3>" \
    --comment "echo HelloWorld"
    
# view command log, useful if command failed
aws ssm list-command-invocations \
    --instance-id "<instanceId>"
    --command-id "<commandId>"
    --details 
    
# base64 encode commands
aws ssm send-command \
    --instance-id "<instanceId>"
    --document-name "<name>"
    --comment "<comment>"
    --parameters '{"commands":["echo <base64EncodedCommand> | base64 -d | bash"]}'

Secrets Manager

# list stored secrets
aws secretsmanager list-secrets

# read a secret
aws secretsmanager get-secret-value --secret-id <name>

# read a secret (version, when available)
aws secretsmanager get-secret-value --secret-id <name> --version-id <versionId>

DynamoDB

# list tables
aws dynamodb list-tables

# read tables
aws dynamodb scan --table-name <name>

Multiple ways to run commands, see

☁️
AWS CLI Reference Documentation
Docs