Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Firewall rule update #20

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
2c9069a
Get default interface instead of defaulting to eth0
xfrjared Nov 30, 2018
4b90659
use the AWS metadata service to determin subnetid
xfrjared Nov 30, 2018
69b305d
moved before directory change
xfrjared Nov 30, 2018
4bd314c
collects vpn client files to ~/proxycannon-vpn-client for easy download
xfrjared Nov 30, 2018
2dd83d6
fixed folder name
xfrjared Nov 30, 2018
f97fe14
fixed message and filepath
xfrjared Nov 30, 2018
6ee7ed4
fixed chown cmd
xfrjared Nov 30, 2018
37a504f
moved size and ami values to variables.tf
xfrjared Nov 30, 2018
eaa61e9
moved node size and ami to variables.tf
xfrjared Nov 30, 2018
e0b96e3
Merge pull request #1 from jaredhaight/move-node-size-to-variables.tf
jaredhaight Nov 30, 2018
ddcae74
Merge pull request #2 from jaredhaight/create-vpn-config-dir
jaredhaight Nov 30, 2018
db658fc
Merge branch 'master' into get-aws-subnet-id
jaredhaight Nov 30, 2018
dcd66ea
Merge pull request #3 from jaredhaight/get-aws-subnet-id
jaredhaight Nov 30, 2018
50ee1fc
Merge pull request #4 from jaredhaight/determine-default-eth
jaredhaight Nov 30, 2018
2caecad
updated readme instructions on downloading vpn client info
xfrjared Nov 30, 2018
e0e727f
Merge pull request #5 from jaredhaight/create-vpn-config-dir
jaredhaight Nov 30, 2018
79ea7f4
create aws creds file and set permissions
xfrjared Nov 30, 2018
5a5cfff
Merge pull request #6 from jaredhaight/create-aws-creds-file
jaredhaight Nov 30, 2018
ab7973f
locking firewall for nodes down to control server
xfrjared Nov 30, 2018
1da9396
fixing the dumb typo here too
xfrjared Nov 30, 2018
13c645d
more sed swaps
xfrjared Nov 30, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,10 @@ Perform the following on the control-server:
2. Run `terraform init` to download the AWS modules. (you only need to do this once)

#### 5. Copy OpenVPN files to your workstation
Copy the following files from the control-server to the `/etc/openvpn` directory on your workstation:
- ~/proxycannon-client.conf
- /etc/openvpn/easy-rsa/keys/ta.key
- /etc/openvpn/easy-rsa/keys/ca.crt
- /etc/openvpn/easy-rsa/keys/client01.crt
- /etc/openvpn/easy-rsa/keys/client01.key
Copy the contents of the ~/proxycannon-vpn-client folder on your workstation:
```
scp -i proxycannon.pem ubuntu@<external_ip>:/home/ubuntu/proxycannon-vpn-client/* .
```

Test OpenVPN connectivity from your workstation by running:
```
Expand Down
3 changes: 2 additions & 1 deletion nodes/aws/configs/node_setup.bash
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#! /bin/bash
sudo sysctl -w net.ipv4.ip_forward=1
sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
DEFAULTETH=`ip route | grep default | sed -e "s/^.*dev.//" -e "s/.proto.*//"`
sudo iptables -t nat -A POSTROUTING -o $DEFAULTETH -j MASQUERADE
6 changes: 3 additions & 3 deletions nodes/aws/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ provider "aws" {
}

resource "aws_instance" "exit-node" {
ami = "ami-0f65671a86f061fcd"
instance_type = "t2.micro"
ami = "${var.ami}"
instance_type = "${var.size}"
key_name = "proxycannon"
vpc_security_group_ids = ["${aws_security_group.exit-node-sec-group.id}"]
subnet_id = "${var.subnet_id}"
Expand Down Expand Up @@ -67,7 +67,7 @@ resource "aws_security_group" "exit-node-sec-group" {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
cidr_blocks = "${var.allowedips}"
}
}

Expand Down
17 changes: 17 additions & 0 deletions nodes/aws/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,23 @@ variable "count" {
default = 2
}

# AMI image to use for exit nodes
variable "ami" {
default = "ami-0f65671a86f061fcd"
}

# Size of EC2 VM to spin up for exit nodes
variable "size" {
default = "t2.micro"
}

variable "allowedips" {
default = [
"CONTROLSERVERPUBLICIP/32",
"CONTROLSERVERPRIVATEIP/32"
]
}

# launch all exit nodes in the same subnet id
# this should be the same subnet id that your control server is in
# you can get this value from the AWS console when viewing the details of the control-server instance
Expand Down
46 changes: 39 additions & 7 deletions setup/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# update and install deps
apt update
apt -y upgrade
apt -y install unzip git openvpn easy-rsa
apt -y install zip unzip git openvpn easy-rsa

# install terraform
wget https://releases.hashicorp.com/terraform/0.11.10/terraform_0.11.10_linux_amd64.zip
Expand All @@ -20,6 +20,24 @@ rm -rf terraform
# create directory for our aws credentials
mkdir ~/.aws
touch ~/.aws/credentials
cat << EOF >> ~/.aws/credentials
[default]
aws_access_key_id = REPLACE_WITH_YOUR_OWN
aws_secret_access_key = REPLACE_WITH_YOUR_OWN
region = us-east-2
EOF
chown -R $SUDO_USER:$SUDO_USER ~/.aws

####################################################
# update subnet id and firewall rule in variables.tf
####################################################
MAC=`curl http://169.254.169.254/latest/meta-data/network/interfaces/macs/`
SUBNETID=`curl http://169.254.169.254/latest/meta-data/network/interfaces/macs/$MAC/subnet-id`
sed -i "s/subnet-XXXXXXXX/$SUBNETID/" ../nodes/aws/variables.tf
PRIVATEIP=`curl http://169.254.169.254/latest/meta-data/network/interfaces/macs/$MAC/local-ipv4s`
sed -i "s/CONTROLSERVERPRIVATEIP/$PRIVATEIP/" ../nodes/aws/variables.tf
EIP=`curl -s http://169.254.169.254/latest/meta-data/public-ipv4`
sed -i "s/CONTROLSERVERPUBLICIP/$EIP/" ../nodes/aws/variables.tf

################
# setup openvpn
Expand Down Expand Up @@ -51,7 +69,6 @@ systemctl start [email protected]
systemctl start [email protected]

# modify client config with remote IP of this server
EIP=`curl -s http://169.254.169.254/latest/meta-data/public-ipv4`
sed -i "s/REMOTE_PUB_IP/$EIP/" ~/proxycannon-client.conf

###################
Expand All @@ -70,17 +87,32 @@ echo "50 loadb" >> /etc/iproute2/rt_tables
# set rule for openvpn client source network to use the second routing table
ip rule add from 10.10.10.0/24 table loadb

# always snat from eth0
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
# always snat from default ethernet
DEFAULTETH=`ip route | grep default | sed -e "s/^.*dev.//" -e "s/.proto.*//"`
iptables -t nat -A POSTROUTING -o $DEFAULTETH -j MASQUERADE

#######################################
# collect vpn config files to one place
#######################################
mkdir ~/proxycannon-vpn-client
cp /etc/openvpn/easy-rsa/keys/ta.key ~/proxycannon-vpn-client/
cp /etc/openvpn/easy-rsa/keys/ca.crt ~/proxycannon-vpn-client/
cp /etc/openvpn/easy-rsa/keys/client01.crt ~/proxycannon-vpn-client/
cp /etc/openvpn/easy-rsa/keys/client01.key ~/proxycannon-vpn-client/
mv ~/proxycannon-client.conf ~/proxycannon-vpn-client/
chown -R $SUDO_USER:$SUDO_USER ~/proxycannon-vpn-client

############################
# post install instructions
############################

echo "Copy /etc/openvpn/easy-rsa/keys/ta.key, /etc/openvpn/easy-rsa/keys/ca.crt, /etc/openvpn/easy-rsa/keys/client01.crt, /etc/openvpn/easy-rsa/keys/client01.key, and ~/proxycannon-client.conf to your workstation."

echo "A folder containing the OpenVPN client config has been created at /home/$SUDO_USER/proxycannon-vpn-client."
echo "Download these files by running the following from your workstation (including the trailing period): "
echo
echo "scp -i proxycannon.pem $SUDO_USER@$EIP:/home/$SUDO_USER/proxycannon-vpn-client/* ."
echo
echo "####################### OpenVPN client config [proxycannon-client.conf] ################################"
cat ~/proxycannon-client.conf
cat ~/proxycannon-vpn-client/proxycannon-client.conf

echo "####################### Be sure to add your AWS API keys and SSH keys to the following locations ###################"
echo "copy your aws ssh private key to ~/.ssh/proxycannon.pem and chmod 600"
Expand Down