2018-04-15 14:15:58 -04:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
2018-09-20 20:42:37 +02:00
|
|
|
printf "=== PIA CONTAINER ==="
|
|
|
|
|
|
2018-06-07 18:33:03 -04:00
|
|
|
# Obtaining your original IP address to use for the healthcheck
|
|
|
|
|
printf "\nGetting non VPN public IP address..."
|
2018-05-27 20:38:43 -04:00
|
|
|
export INITIAL_IP=$(wget -qqO- 'https://duckduckgo.com/?q=what+is+my+ip' | grep -ow 'Your IP address is [0-9.]*[0-9]' | grep -ow '[0-9][0-9.]*')
|
2018-06-07 18:33:03 -04:00
|
|
|
printf "$INITIAL_IP"
|
|
|
|
|
|
|
|
|
|
printf "\nSetting firewall for killswitch purposes..."
|
|
|
|
|
printf "\n * Detecting local subnet..."
|
2018-06-06 22:44:11 -04:00
|
|
|
SUBNET=$(ip route show default | tail -n 1 | awk '// {print $1}')
|
2018-06-07 18:33:03 -04:00
|
|
|
printf "$SUBNET"
|
|
|
|
|
printf "\n * Detecting parameters to be used for region $REGION, protocol $PROTOCOL and encryption $ENCRYPTION..."
|
|
|
|
|
CONNECTIONSTRING=$(grep -i "/openvpn-$PROTOCOL-$ENCRYPTION/$REGION.ovpn" -e 'privateinternetaccess.com')
|
|
|
|
|
PORT=$(echo $CONNECTIONSTRING | cut -d' ' -f3)
|
|
|
|
|
PIADOMAIN=$(echo $CONNECTIONSTRING | cut -d' ' -f2)
|
|
|
|
|
printf "\n * Port: $PORT"
|
|
|
|
|
printf "\n * Domain: $PIADOMAIN"
|
|
|
|
|
printf "\n * Detecting IP addresses corresponding to $PIADOMAIN..."
|
|
|
|
|
VPNIPS=$(nslookup $PIADOMAIN localhost | tail -n +5 | grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}')
|
2018-06-06 22:44:11 -04:00
|
|
|
for ip in $VPNIPS
|
|
|
|
|
do
|
2018-09-20 20:42:37 +02:00
|
|
|
printf "\n $ip"
|
2018-06-06 22:44:11 -04:00
|
|
|
done
|
2018-06-07 18:33:03 -04:00
|
|
|
printf "\n * Deleting all iptables rules..."
|
2018-06-06 22:44:11 -04:00
|
|
|
iptables --flush
|
|
|
|
|
iptables --delete-chain
|
|
|
|
|
iptables -t nat --flush
|
|
|
|
|
iptables -t nat --delete-chain
|
|
|
|
|
iptables -P OUTPUT DROP
|
2018-06-07 18:33:03 -04:00
|
|
|
printf "DONE"
|
|
|
|
|
printf "\n * Adding rules to accept local loopback traffic..."
|
2018-06-06 22:44:11 -04:00
|
|
|
iptables -A INPUT -j ACCEPT -i lo
|
|
|
|
|
iptables -A OUTPUT -j ACCEPT -o lo
|
2018-06-07 18:33:03 -04:00
|
|
|
printf "DONE"
|
|
|
|
|
printf "\n * Adding rules to accept traffic of subnet $SUBNET..."
|
2018-06-06 22:44:11 -04:00
|
|
|
#iptables -A INPUT --src $SUBNET -j ACCEPT -i eth0
|
|
|
|
|
iptables -A OUTPUT -d $SUBNET -j ACCEPT -o eth0
|
2018-06-07 18:33:03 -04:00
|
|
|
printf "DONE"
|
2018-06-06 22:44:11 -04:00
|
|
|
for ip in $VPNIPS
|
|
|
|
|
do
|
2018-09-20 20:42:37 +02:00
|
|
|
printf "\n * Adding rules to accept traffic with $ip on port $PROTOCOL $PORT..."
|
|
|
|
|
iptables -A OUTPUT -j ACCEPT -d $ip -o eth0 -p $PROTOCOL -m $PROTOCOL --dport $PORT
|
|
|
|
|
iptables -A INPUT -j ACCEPT -s $ip -i eth0 -p $PROTOCOL -m $PROTOCOL --sport $PORT
|
|
|
|
|
printf "DONE"
|
2018-06-06 22:44:11 -04:00
|
|
|
done
|
2018-06-07 18:33:03 -04:00
|
|
|
printf "\n * Adding rules to accept traffic going through the tun device..."
|
2018-06-06 22:44:11 -04:00
|
|
|
iptables -A INPUT -j ACCEPT -i tun0
|
|
|
|
|
iptables -A OUTPUT -j ACCEPT -o tun0
|
2018-06-07 18:33:03 -04:00
|
|
|
printf "DONE"
|
|
|
|
|
printf "\n * Starting OpenVPN using the following parameters:"
|
|
|
|
|
printf "\n * Domain: $PIADOMAIN"
|
|
|
|
|
printf "\n * Port: $PORT"
|
|
|
|
|
printf "\n * Protocol: $PROTOCOL"
|
2018-09-12 19:23:02 +02:00
|
|
|
printf "\n * Encryption: $ENCRYPTION\n"
|
2018-04-16 14:50:24 -04:00
|
|
|
cd /openvpn-$PROTOCOL-$ENCRYPTION
|
2018-04-18 18:02:36 -04:00
|
|
|
openvpn --config "$REGION.ovpn" --auth-user-pass /auth.conf
|
2018-06-07 18:33:03 -04:00
|
|
|
printf "\nExiting...\n\n"
|