2018-04-15 14:15:58 -04:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
2018-09-20 20:42:37 +02:00
|
|
|
printf "=== PIA CONTAINER ==="
|
|
|
|
|
|
2018-09-21 11:28:23 +02:00
|
|
|
############################################
|
|
|
|
|
# SETTING DNS OVER TLS TO 1.1.1.1 / 1.0.0.1
|
|
|
|
|
############################################
|
|
|
|
|
printf "\nChanging DNS to localhost..."
|
|
|
|
|
echo "nameserver 127.0.0.1" > /etc/resolv.conf
|
|
|
|
|
echo "options ndots:0" >> /etc/resolv.conf
|
|
|
|
|
printf "DONE"
|
|
|
|
|
printf "\nLaunching Unbound daemon to connect to Cloudflare DNS 1.1.1.1 at its TLS endpoint..."
|
|
|
|
|
unbound
|
|
|
|
|
printf "DONE"
|
|
|
|
|
|
|
|
|
|
############################################
|
|
|
|
|
# ORIGINAL IP FOR HEALTHCHECK
|
|
|
|
|
############################################
|
2018-06-07 18:33:03 -04:00
|
|
|
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"
|
|
|
|
|
|
2018-09-21 11:28:23 +02:00
|
|
|
############################################
|
|
|
|
|
# FIREWALL
|
|
|
|
|
############################################
|
2018-06-07 18:33:03 -04:00
|
|
|
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"
|
2018-09-21 11:28:23 +02:00
|
|
|
printf "\n * Reading parameters to be used for region $REGION, protocol $PROTOCOL and encryption $ENCRYPTION..."
|
2018-06-07 18:33:03 -04:00
|
|
|
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
|
2018-09-21 09:33:37 +02:00
|
|
|
ip6tables --flush
|
|
|
|
|
ip6tables --delete-chain
|
2018-06-07 18:33:03 -04:00
|
|
|
printf "DONE"
|
2018-09-21 09:33:37 +02:00
|
|
|
iptables -F OUTPUT
|
|
|
|
|
iptables -P OUTPUT DROP
|
|
|
|
|
ip6tables -F OUTPUT 2>/dev/null
|
|
|
|
|
ip6tables -P OUTPUT DROP 2>/dev/null
|
2018-06-07 18:33:03 -04:00
|
|
|
printf "\n * Adding rules to accept local loopback traffic..."
|
2018-09-21 09:33:37 +02:00
|
|
|
iptables -A OUTPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
|
|
|
|
|
iptables -A OUTPUT -o lo -j ACCEPT
|
2018-09-21 11:28:23 +02:00
|
|
|
iptables -A INPUT -i lo -j ACCEPT
|
2018-09-21 09:33:37 +02:00
|
|
|
ip6tables -A OUTPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT 2>/dev/null
|
|
|
|
|
ip6tables -A OUTPUT -o lo -j ACCEPT 2>/dev/null
|
2018-09-21 11:28:23 +02:00
|
|
|
ip6tables -A INPUT -i lo -j ACCEPT 2>/dev/null
|
2018-06-07 18:33:03 -04:00
|
|
|
printf "DONE"
|
|
|
|
|
printf "\n * Adding rules to accept traffic of subnet $SUBNET..."
|
2018-09-21 09:33:37 +02:00
|
|
|
iptables -A OUTPUT -d $SUBNET -j ACCEPT
|
|
|
|
|
ip6tables -A OUTPUT -d $SUBNET -j ACCEPT 2>/dev/null
|
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
|
2018-09-21 11:28:23 +02:00
|
|
|
iptables -A INPUT -j ACCEPT -s $ip -i eth0 -p $PROTOCOL -m $PROTOCOL --sport $PORT
|
2018-09-21 09:33:37 +02:00
|
|
|
ip6tables -A OUTPUT -j ACCEPT -d $ip -o eth0 -p $PROTOCOL -m $PROTOCOL --dport $PORT 2>/dev/null
|
2018-09-21 11:28:23 +02:00
|
|
|
ip6tables -A INPUT -j ACCEPT -s $ip -i eth0 -p $PROTOCOL -m $PROTOCOL --sport $PORT 2>/dev/null
|
2018-09-20 20:42:37 +02:00
|
|
|
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-09-21 09:33:37 +02:00
|
|
|
iptables -A OUTPUT -o tun0 -j ACCEPT
|
2018-09-21 11:28:23 +02:00
|
|
|
iptables -A INPUT -i tun0 -j ACCEPT
|
2018-09-21 09:33:37 +02:00
|
|
|
ip6tables -A OUTPUT -o tun0 -j ACCEPT 2>/dev/null
|
2018-09-21 11:28:23 +02:00
|
|
|
ip6tables -A INPUT -i tun0 -j ACCEPT 2>/dev/null
|
2018-09-21 09:33:37 +02:00
|
|
|
printf "DONE"
|
|
|
|
|
printf "\n * Allowing outgoing DNS queries on port 53 UDP..."
|
|
|
|
|
iptables -A OUTPUT -p udp -m udp --dport 53 -j ACCEPT
|
|
|
|
|
ip6tables -A OUTPUT -p udp -m udp --dport 53 -j ACCEPT 2>/dev/null
|
2018-06-07 18:33:03 -04:00
|
|
|
printf "DONE"
|
2018-09-21 11:28:23 +02:00
|
|
|
|
|
|
|
|
############################################
|
|
|
|
|
# SUMMARY
|
|
|
|
|
############################################
|
2018-09-21 11:39:00 +02:00
|
|
|
printf "\nStarting OpenVPN using the following parameters:"
|
|
|
|
|
printf "\n * Domain: $PIADOMAIN"
|
|
|
|
|
printf "\n * Port: $PORT"
|
|
|
|
|
printf "\n * Protocol: $PROTOCOL"
|
|
|
|
|
printf "\n * Encryption: $ENCRYPTION"
|
2018-09-21 11:28:23 +02:00
|
|
|
|
|
|
|
|
############################################
|
|
|
|
|
# OPENVPN LAUNCH
|
|
|
|
|
############################################
|
2018-04-16 14:50:24 -04:00
|
|
|
cd /openvpn-$PROTOCOL-$ENCRYPTION
|
2018-09-21 11:39:00 +02:00
|
|
|
printf "\nSwitching from root to nonrootuser..."
|
|
|
|
|
su -l nonrootuser
|
|
|
|
|
printf "DONE\n"
|
2018-04-18 18:02:36 -04:00
|
|
|
openvpn --config "$REGION.ovpn" --auth-user-pass /auth.conf
|
2018-09-21 11:28:23 +02:00
|
|
|
|
|
|
|
|
############################################
|
|
|
|
|
# CLEANUP
|
|
|
|
|
############################################
|
2018-06-07 18:33:03 -04:00
|
|
|
printf "\nExiting...\n\n"
|