Git Product home page Git Product logo

vpc-vpn-pivot's Introduction

Pivoting into VPC networks

This tool automates the creation of a VPN between the attacker's workstation and an AWS resource in the target VPC with the objective of connecting to other AWS services, such as EC2 instances, which are not accessible from the Internet.

vpn-vpc-pivot-demo

Or watch this demo on asciinema.

Use case

You are performing a cloud penetration test and gained access to a set of AWS credentials. The target infrastructure uses VPCs and most of the interesting services are private (can only be accessed by other hosts connected to the same VPC or subnet).

This tool completely automates the process of creating a VPN between your workstation and the target VPC so you can connect to those private services.

Depending on the permissions associated with the compromised credentials the tool will use different techniques to create and maintain the VPN service running. For example, if the credentials have permissions for EC2 and ACM then an AWS Client VPN is created and the openvpn client is used to connect to it.

Supported services

This tool will try to create the VPN connection using different techniques, based on the permissions associated with the compromised credentials. The supported services for creating the VPN are:

The following will be implemented in the future:

  • EC2
  • Lambda
  • LightSail
  • Fargate

Noise

The tool will generate a lot of CloudTrail logs and if anyone is paying attention you will get detected and blocked.

Installation

The vpc-vpn-pivot tool uses Python 3.6. The full installation steps are:

git clone https://github.com/andresriancho/vpc-vpn-pivot.git
cd vpc-vpn-pivot

pip3 install requirements.txt
sudo apt-get install openvpn

Usage

This command will setup the SSL certificates, routes and other resources required for the AWS Client VPN to work:

./vpc-vpn-pivot create --profile={profile-name} --subnet-id={subnet-id}

The profile needs to contain compromised credentials for the target AWS account and be stored in ~/.aws/credentials/, the VPC ID can be obtained using aws ec2 describe-vpcs.

Everything is ready! Just connect your workstation to the VPC using openvpn:

sudo ./vpc-vpn-pivot connect

./vpc-vpn-pivot status
route -n
nmap -sS ...

The script needs to be run using sudo because openvpn requires root privileges to create the tun interface.

Once connected to the VPC you should be able to inspect the IP address range with ifconfig and run any tool, such as nmap to find open services on the VPC.

Use the following commands to disconnect from the VPN and remove all remote resources created for the VPN to work:

./vpc-vpn-pivot disconnect
./vpc-vpn-pivot purge

Troubleshooting

vpc-vpn-pivot keeps current state and the names of all the created resources in the state file (~/.vpc-vpn-pivot/state). This file is useful if you need to manually kill the openvpn process or remove the AWS resources.

Warning

In order to create an AWS Client VPN we import two certificates into the target's AWS account. There is a hard-limit of 20 imported certificates per year, by using this tool you are reducing the number of available ACM certificates.

vpc-vpn-pivot's People

Contributors

andresriancho avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

vpc-vpn-pivot's Issues

EC2 instance ID as parameter

As a user I might have a lot of privileges and only care about the target instance I want to attack. The tool should be able to figure out the subnet-id, vpc-id, and any other required parameters for the connection.

Instead of calling vpc-vpn-pivot using:

./vpc-vpn-pivot create --subnet-id subnet-...

I would like to call it using:

./vpc-vpn-pivot create --instance-id ...

The tool should use the AWS APIs to find the subnet-id where the EC2 instance lives, and create a VPN connection for me to be able to attack it.

VPN client from EC2, Lambda, etc.

The initial implementation of vpc-vpn-pivot is starting a VPN server in AWS Client VPN. In order to do that, the compromised AWS credentials require rather uncommon privileges (unless you have *:*).

A great improvement for this tool would be to:

  • Start https://ngrok.com/ on the attacker workstation (this allows the attacker server to be behind a NAT and doesn't require port forwarding at the edge router)
  • Start VPN server in attacker workstation
  • Run VPN client in EC2, Lambda, Fargate, LightSail, etc.
  • Pivot into the target VPC

If the attacker has privileges to create the AWS Client VPN, then the initial method should be used, else:

  • Try to start an EC2 instance in the target VPC with a specific user-data to connect to the VPN
  • Try to run a lambda function that connects to the VPN. This implementation will have the challenge of handling lambda function timeouts.
  • Use Fargate

Lambda implementation

Intro

A few days ago I saw a tool that allows you to convert docker images to lambda layers. Read about it on twitter... failed to find it now... but it would be a really good way to implement the lambda support for vpc-vpn-pivot.

Steps

  • Install docker VPN client in docker
  • Setup VPN server in a way that we can route traffic via VPN client
  • Test using ECS (and I have support for that too as a side effect)
  • Deploy to Lambda using vpc-vpn-pivot

Multiple region support

The tool must support multiple regions: When the user specifies a subnet-id , we should query the AWS API to identify which region that subnet is in, and then create all the required resources in the same region.

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.