• Stars
    star
    457
  • Rank 95,146 (Top 2 %)
  • Language HCL
  • License
    MIT License
  • Created over 3 years ago
  • Updated 8 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Use Terraform to create your own vulnerable by design AWS IAM privilege escalation playground.

IAM Vulnerable

Use Terraform to create your own vulnerable by design AWS IAM privilege escalation playground.

IAM Vulnerable uses the Terraform binary and your AWS credentials to deploy over 250 IAM resources into your selected AWS account. Within minutes, you can start learning how to identify and exploit vulnerable IAM configurations that allow for privilege escalation.

🦊 Currently supported privilege escalation paths: 31

Table of Contents

Recommended Approach

  1. Select or create an AWS account - Do NOT use an account that has any production resources or sensitive data.
  2. Create your vulnerable playground - Use this repo to create the IAM principals and policies that support 31 unique AWS IAM privesc paths.
  3. Do your homework - Learn about the 21 original privesc paths pioneered by Spencer Gietzen.
  4. Hacky, hack - Practice exploitation in your new playground using Gerben Kleijn's guide.
  5. Level up - Run your tools against your new IAM privesc playground account (i.e., Cloudsplaining, AWSPX, Principal Mapper, Pacu).

Detailed Usage Instructions

Blog Post: IAM Vulnerable - An AWS IAM Privilege Escalation Playground

Quick Start

This quick start outlines an opinionated approach to getting IAM Vulnerable up and running in your AWS account as quickly as possible. You might have many of these steps already completed, or you might want to tweak things to work with your current configuration. Check out the Other Use Cases section in this repository for some additional configuration options.

  1. Select or create an AWS account. (Do NOT use an account that has any production resources or sensitive data!)
  2. Create a non-root user with administrative access that you will use when running Terraform.
  3. Create an access key for that user.
  4. Install the AWS CLI.
  5. Configure your AWS CLI with your newly created admin user as the default profile.
  6. Confirm your CLI is working as expected by executing aws sts get-caller-identity.
  7. Install the Terraform binary and add the binary location to your path.
  8. git clone https://github.com/BishopFox/iam-vulnerable
  9. cd iam-vulnerable/
  10. terraform init
  11. (Optional) export TF_VAR_aws_local_profile=PROFILE_IN_AWS_CREDENTIALS_FILE_IF_OTHER_THAN_DEFAULT
  12. (Optional) export TF_VAR_aws_local_creds_file=FILE_LOCATION_IF_NON_DEFAULT
  13. (Optional) terraform plan
  14. terraform apply
  15. (Optional) Add the IAM vulnerable profiles to your AWS credentials file, and change the account number.
    • The following commands make a backup of your current AWS credentials file, then takes the example credentials file from the repo and replaces the placeholder account with your target account number, and finally adds all of the IAM Vulnerable privesc profiles to your credentials file so you can use them:
    • cp ~/.aws/credentials ~/.aws/credentials.backup
    • tail -n +7 aws_credentials_file_example | sed s/111111111111/$(aws sts get-caller-identity | grep Account | awk -F\" '{print $4}')/g >> ~/.aws/credentials

Cleanup

Whenever you want to remove all of the IAM Vulnerable-created resources, you can run these commands:

  1. cd iam-vulnerable/
  2. terraform destroy

What resources were just created?

The Terraform binary just used your default AWS account profile credentials to create:

  • 31 users, roles, and policies each with a unique exploit path to administrative access of the playground account
  • Some additional users, groups, roles, and policies that are required to fully realize certain exploit paths
  • Some additional users, roles, and policies that test the detection capabilities of other tools

By default, every role created by this Terraform module is assumable by the user or role you used to run Terraform.

  • If you'd like Terraform to use a profile other than the default profile, or you'd like to hard-code the assume_role_policy ARN, see Other Use Cases.

How much is this going to cost?

Deploying IAM vulnerable in its default configuration will cost nothing. See the next section to learn how to enable non-default modules that do incur cost, and how much each module will cost per month if you deploy it.

A Modular Approach

IAM Vulnerable groups certain resources together in modules. Some of the modules are enabled by default (the ones that don't have any cost implications), and others are disabled by default (the ones that incur cost if deployed). This way, you can enable specific modules as needed.

For example, when you are ready to play with the exploit paths like ssm:StartSession that involve resources outside of IAM, you can deploy and tear down these resources on demand by uncommenting the module in the iam-vulnerable/main.tf file, and re-running terraform apply:

# Uncomment the next four lines to create an ec2 instance and related resources
#module "ec2" {
#  source = "./modules/non-free-resources/ec2"
#  aws_assume_role_arn = (var.aws_assume_role_arn != "" ? var.aws_assume_role_arn : data.aws_caller_identity.current.arn)
#}

After you uncomment the ec2 module, run:

terraform init
terraform apply

You have now deployed the required components to try the SSM privesc paths.

Free Resource Modules

There is no cost to anything deployed within free-resources:

Name Default Status Estimated Cost Description
privesc-paths Enabled None Contains all of the IAM privesc paths
tool-testing Enabled None Contains test cases that evaluate the capabilities of the different IAM privesc tools

Non-free Resource Modules

Deploying these additional modules can result in cost:

Name Default Status Estimated Cost Description Required for
EC2 Disabled πŸ’²
$4.50/month
Creates an EC2 instance and a security group that allows SSH from anywhere ssm-SendCommand
ssm-StartSession
ec2InstanceConnect-SendSSHPublicKey
Lambda Disabled πŸ™‚
Monthly cost depends on usage (cost should be zero)
Creates a Lambda function Lambda-EditExistingLambdaFunctionWithRole
Glue Disabled πŸ’²πŸ’²πŸ’²πŸ’²
$4/hour
Creates a Glue dev endpoint Glue-UpdateExistingGlueDevEndpoint
SageMaker Disabled Not sure yet Creates a SageMaker notebook sageMakerCreatePresignedNotebookURL
CloudFormation Disabled πŸ™‚
$0.40/month for the secret created via CloudFormation. Nothing or barely nothing for the stack itself
Creates a CloudFormation stack that creates a secret in secret manager privesc-cloudFormationUpdateStack

Supported Privilege Escalation Paths

Path Name IAM Vulnerable Profile Name Non-Default Modules Required Exploitation References
Category: IAM Permissions on Other Users
IAM-CreateAccessKey privesc4 None 🦊 Well, That Escalated Quickly - Privesc 04
πŸ”’ s3cur3.it IAMVulnerable - Part 3
IAM-CreateLoginProfile privesc5 None 🦊 Well, That Escalated Quickly - Privesc 05
πŸ”’ s3cur3.it IAMVulnerable - Part 3
IAM-UpdateLoginProfile privesc6 None 🦊 Well, That Escalated Quickly - Privesc 06
πŸ”’ s3cur3.it IAMVulnerable - Part 3
Category: PassRole to Service
CloudFormation-PassExistingRoleToCloudFormation privesc20 None 🦊 Well, That Escalated Quickly - Privesc 20
CodeBuild-CreateProjectPassRole privesc-codeBuildProject None
DataPipeline-PassExistingRoleToNewDataPipeline privesc21 None 🦊 Well, That Escalated Quickly - Privesc 21
EC2-CreateInstanceWithExistingProfile privesc3 None 🦊 Well, That Escalated Quickly - Privesc 03
πŸ”’ s3cur3.it IAMVulnerable - Part 2
Glue-PassExistingRoleToNewGlueDevEndpoint privesc18 None 🦊 Well, That Escalated Quickly - Privesc 18
Lambda-PassExistingRoleToNewLambdaThenInvoke privesc15 None 🦊 Well, That Escalated Quickly - Privesc 15
Lambda-PassRoleToNewLambdaThenTrigger privesc16 None 🦊 Well, That Escalated Quickly - Privesc 16
SageMaker-CreateNotebookPassRole privesc-sageNotebook None 🦏 AWS IAM Privilege Escalation - Method 2
SageMaker-CreateTrainingJobPassRole privesc-sageTraining None
SageMaker-CreateProcessingJobPassRole privesc-sageProcessing None
Category: Permissions on Policies
IAM-AddUserToGroup privesc13 None 🦊 Well, That Escalated Quickly - Privesc 13
IAM-AttachGroupPolicy privesc8 None 🦊 Well, That Escalated Quickly - Privesc 08
IAM-AttachRolePolicy privesc9 None 🦊 Well, That Escalated Quickly - Privesc 09
IAM-AttachUserPolicy privesc7 None 🦊 Well, That Escalated Quickly - Privesc 07
IAM-CreateNewPolicyVersion privesc1 None 🦊 Well, That Escalated Quickly - Privesc 01
πŸ”’ s3cur3.it IAMVulnerable - Part 1
IAM-PutGroupPolicy privesc11 None 🦊 Well, That Escalated Quickly - Privesc 11
IAM-PutRolePolicy privesc12 None 🦊 Well, That Escalated Quickly - Privesc 12
IAM-PutUserPolicy privesc10 None 🦊 Well, That Escalated Quickly - Privesc 10
IAM-SetExistingDefaultPolicyVersion privesc2 None 🦊 Well, That Escalated Quickly - Privesc 02
πŸ”’ s3cur3.it IAMVulnerable - Part 2
Category: Privilege Escalation using AWS Services
EC2InstanceConnect-SendSSHPublicKey privesc-instanceConnect EC2 πŸ”‘ AWS IAM privilege escalation paths
CloudFormation-UpdateStack privesc-cfUpdateStack CloudFormation πŸ”‘ AWS IAM privilege escalation paths
Glue-UpdateExistingGlueDevEndpoint privesc19 Glue 🦊 Well, That Escalated Quickly - Privesc 19
Lambda-EditExistingLambdaFunctionWithRole privesc17 Lambda 🦊 Well, That Escalated Quickly - Privesc 17
πŸ”’ s3cur3.it IAMVulnerable - Part 4
SageMakerCreatePresignedNotebookURL privesc-sageUpdateURL Sagemaker 🦏 AWS IAM Privilege Escalation - Method 3
SSM-SendCommand privesc-ssm-command EC2 πŸ”‘ AWS IAM privilege escalation paths
SSM-StartSession privesc-ssm-session EC2 πŸ”‘ AWS IAM privilege escalation paths
STS-AssumeRole privesc-assumerole None πŸ”‘ AWS IAM privilege escalation paths
Category: Updating an AssumeRole Policy
IAM-UpdatingAssumeRolePolicy privesc14 None 🦊 Well, That Escalated Quickly - Privesc 14

Other Use Cases

Default - No terraform.tfvars configured

  • Deploy using your default AWS profile (Default)
  • All created roles are assumable by the principal used to run Terraform (specified in your default profile)

Use a profile other than the default to run Terraform

  • Copy terraform.tfvars.example to terraform.tvvars
  • Uncomment the line #aws_local_profile = "profile_name" and enter the profile name you'd like to use
  • If you are using a non-default profile, and still want to use the aws_credentails_file_example file, you can use this command to generate an AWS credentials file that works with your non-default profile name (Thanks @scriptingislife)
    • Remember to replace nondefaultuser with the profile name you are using):
    • tail -n +7 aws_credentials_file_example | sed -e "s/111111111111/$(aws sts get-caller-identity | grep Account | awk -F\" '{print $4}')/g;s/default/nondefaultuser/g" >> ~/.aws/credentials

Use an ARN other than the caller as the principal that can assume the newly created roles

  • Copy terraform.tfvars.example to terraform.tvvars
  • Uncomment the line #aws_assume_role_arn = "arn:aws:iam::112233445566:user/you" and enter the ARN you'd like to use

Once created, each of the privesc roles will be assumable by the principal (ARN) you specified.

Create the resource in account X, but use an ARN from account Y as the principal that can assume the newly created roles

If you have configured AWS CLI profiles that assume roles into other accounts, you will want to specify the profile name AND manually specify the ARN you'd like to use to assume into the different roles.

In the example below, the resources will be created in the account that is tied to "prod-cross-org-access-role", but each role that Terraform creates can be accessed by "arn:aws:iam::112233445566:user/you", which belongs to another account.

aws_local_profile = "prod-cross-org-access-role"
aws_assume_role_arn = "arn:aws:iam::112233445566:user/you"

FAQ

How does IAM Vulnerable compare to CloudGoat, Terragoat, and SadCloud?

All of these tools use Terraform to deploy intentionally vulnerable infrastructure to AWS. However, IAM Vulnerable's focus is IAM privilege escalation, whereas the other tools either don't cover IAM privesc or only cover some scenarios.

  • CloudGoat deploys eight unique scenarios, some of which cover IAM privesc paths, while others focus on other areas like secrets in EC2 metadata.
  • Terragoat and SadCloud both focus on the many ways you can misconfigure your cloud accounts, but do not cover IAM privesc paths. In fact, you can almost think of IAM vulnerable as a missing puzzle piece when applied along side Terragoat or SadCloud. The intentionally vulnerable configurations complement each other.

How does IAM Vulnerable compare to Cloudsplaining, AWSPX, Principal Mapper, Pacu, Cloudmapper, or ScouteSuite?

All of these tools help identify existing misconfigurations in your AWS environment. Some, like Pacu, also help you exploit misconfigurations. In contrast, IAM Vulnerable creates intentionally vulnerable infrastructure. If you really want to learn how to use tools like Principal Mapper (PMapper), AWSPX, Pacu, and Cloudsplaining, IAM Vulnerable is for you.

I've never used Terraform and I'm afraid of it. Help!?

I was also afraid of Terraform and projects that would create resources in my account before I knew how Terraform worked. Here are some things that might ease your anxiety:

  • By using an AWS account for this single purpose, you can rest assured that this repository won't negatively impact anything else you care about. Even if you deploy IAM Vulnerable to a separate account in an AWS organization, you can rest assured that the other accounts in the org will be outside the blast radius of this playground account.
  • The terraform plan command is a dry run. It shows you exactly what will be deployed if you run terraform apply before you actually run it.
  • Rest assured knowing that you can terraform destroy anything you terraform apply for a clean slate.
  • If your concern is cost, check out Infracost. You download this binary, register for a free API key, and execute it within a Terraform directory like iam-vulnerable. This tool runs terraform plan and calculates the monthly cost associated with the plan as it is currently configured. This is the tool I used to populate the module cost estimates table above.

Can I run this tool and another tool like CloudGoat, Terragoat, or SadCloud in the same AWS account?

Yes. Each tool will keep its Terraform state separately, but all resources will be created, updated, and deleted in the same account, and they can coexist.

Prior work and good references

More Repositories

1

sliver

Adversary Emulation Framework
Go
8,155
star
2

unredacter

Never ever ever use pixelation as a redaction technique
TypeScript
7,687
star
3

cloudfox

Automating situational awareness for cloud penetration tests.
Go
1,867
star
4

GitGot

Semi-automated, feedback-driven tool to rapidly search through troves of public data on GitHub for sensitive secrets.
Python
1,412
star
5

jsluice

Extract URLs, paths, secrets, and other interesting bits from JavaScript
Go
1,311
star
6

eyeballer

Convolutional neural network for analyzing pentest screenshots
Python
1,017
star
7

spoofcheck

Simple script that checks a domain for email protections
Python
776
star
8

h2csmuggler

HTTP Request Smuggling over HTTP/2 Cleartext (h2c)
Python
632
star
9

bfinject

Dylib injection for iOS 11.0 - 11.1.2 with LiberiOS and Electra jailbreaks
Objective-C++
619
star
10

GadgetProbe

Probe endpoints consuming Java serialized objects to identify classes, libraries, and library versions on remote Java classpaths.
Java
578
star
11

badPods

A collection of manifests that will create pods with elevated privileges.
Shell
574
star
12

bfdecrypt

Utility to decrypt App Store apps on jailbroken iOS 11.x
C
439
star
13

iSpy

A reverse engineering framework for iOS
Logos
438
star
14

rmiscout

RMIScout uses wordlist and bruteforce strategies to enumerate Java RMI functions and exploit RMI parameter unmarshalling vulnerabilities
Java
422
star
15

sj

A tool for auditing endpoints defined in exposed (Swagger/OpenAPI) definition files.
Go
354
star
16

smogcloud

Find cloud assets that no one wants exposed πŸ”Ž ☁️
Go
329
star
17

cloudfoxable

Create your own vulnerable by design AWS penetration testing playground
Python
311
star
18

sliver-gui

A Sliver GUI Client
TypeScript
288
star
19

dufflebag

Search exposed EBS volumes for secrets
Go
274
star
20

zigdiggity

A ZigBee hacking toolkit by Bishop Fox
Python
258
star
21

deephack

PoC code from DEF CON 25 presentation
Python
240
star
22

rickmote

The Rickmote Controller: Hijack TVs using Google Chromecast
Python
220
star
23

CVE-2023-3519

RCE exploit for CVE-2023-3519
Python
216
star
24

json-interop-vuln-labs

Companion labs to "An Exploration of JSON Interoperability Vulnerabilities"
Python
193
star
25

Imperva_gzip_WAF_Bypass

Python
154
star
26

pwn-pulse

Exploit for Pulse Connect Secure SSL VPN arbitrary file read vulnerability (CVE-2019-11510)
Shell
136
star
27

firecat

Firecat is a penetration testing tool that allows you to punch reverse TCP tunnels out of a compromised network.
C
126
star
28

CVE-2023-27997-check

Safely detect whether a FortiGate SSL VPN instance is vulnerable to CVE-2023-27997 based on response timing
Python
124
star
29

asminject

Heavily-modified fork of David Buchanan's dlinject project. Injects arbitrary assembly (or precompiled binary) payloads directly into x86-64, x86, and ARM32 Linux processes without the use of ptrace by accessing /proc/<pid>/mem. Useful for certain post-exploitation scenarios, recovering content from process memory, etc..
Python
112
star
30

cve-2024-21762-check

Safely detect whether a FortiGate SSL VPN is vulnerable to CVE-2024-21762
Python
93
star
31

anti-anti-automation

Anti-Anti-Automation Framework
Python
92
star
32

mellon

OSDP attack tool (and the Elvish word for friend)
HTML
87
star
33

forticrack

Decrypt encrypted Fortienet FortiOS firmware images
Python
83
star
34

cyberdic

An auxiliary spellcheck dictionary that corresponds with the Bishop Fox Cybersecurity Style Guide
83
star
35

llm-testing-findings

LLM Testing Findings Templates
HTML
65
star
36

bigip-scanner

Determine the running software version of a remote F5 BIG-IP management interface.
Python
61
star
37

IDontSpeakSSL-deprecated

Simple tool based on sslyze to scan large scope and provide SSL/TLS vulnerabilities
Python
51
star
38

spfmap

A program to map out SPF and DKIM records for a large number of domains
Go
37
star
39

CVE-2021-35211

Python
36
star
40

SpoofcheckSelfTest

Web application that lets you test if your domain is vulnerable to email spoofing
Python
33
star
41

ca-clone

Scripts to clone CA certificates for use in HTTPS client attacks.
Shell
33
star
42

ProxyListReliabilityCheck

Perl script to test the reliability of a list of open web proxies.
Perl
27
star
43

ispy-shell

C
24
star
44

coldfusion-10-11-xss

Proof of Concept code for CVE-2015-0345 (APSB15-07)
22
star
45

CVE-2022-22274_CVE-2023-0656

Python
18
star
46

awsservicemap

Go module that returns supported regions for a service or supported services for a region
Go
14
star
47

wordlist-sanitizer

Remove Offensive and Profane Words from Wordlists
Go
12
star
48

sliver-overlord

Go
9
star
49

burpcage

Kotlin
7
star
50

guardian-ci

Shell
4
star
51

You-re-Doing-IoT-RNG

Results and device code from the DEF CON 29 presentation "You're Doing IoT RNG"
C
4
star
52

VulnerableGWTApp

An intentionally-vulnerable GWT-based web application to test tooling and techniques
Java
3
star
53

.github

Bishop Fox Engineering
2
star
54

knownawsaccountslookup

Go module that provides two lookup functions for the data in https://github.com/fwdcloudsec/known_aws_accounts
Go
1
star