Skip to content
This repository has been archived by the owner on Mar 16, 2024. It is now read-only.

Prevent leakage while killswitch setup is performed #80

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
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
21 changes: 18 additions & 3 deletions data/scripts/entry.sh
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,26 @@ sed -i 's/\r$//g' "$modified_config_file"


default_gateway=$(ip -4 route | grep 'default via' | awk '{print $3}')
resolvers=$(grep -E '^nameserver' /etc/resolv.conf | awk '{print $2}')

case "$KILL_SWITCH" in
'iptables')
echo "info: kill switch is using iptables"

iptables -P INPUT DROP
iptables -P OUTPUT DROP
iptables -P FORWARD DROP

iptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -i lo -j ACCEPT
iptables -A OUTPUT -o lo -j ACCEPT

# temporarily allow access to dns resolvers to look up vpn endpoint fqdns
for resolver in $resolvers; do
iptables -A OUTPUT -d "$resolver" -p udp --dport 53 -j ACCEPT
iptables -A OUTPUT -d "$resolver" -p tcp --dport 53 -j ACCEPT
done

local_subnet=$(ip -4 route | grep 'scope link' | awk '{print $1}')
iptables -A INPUT -s "$local_subnet" -j ACCEPT
iptables -A OUTPUT -d "$local_subnet" -j ACCEPT
Expand Down Expand Up @@ -127,9 +138,13 @@ case "$KILL_SWITCH" in
done <<< "$remotes"
iptables -A INPUT -i tun0 -j ACCEPT
iptables -A OUTPUT -o tun0 -j ACCEPT
iptables -P INPUT DROP
iptables -P OUTPUT DROP
iptables -P FORWARD DROP

# revoke access to dns resolvers
for resolver in $resolvers; do
iptables -D OUTPUT -d "$resolver" -p udp --dport 53 -j ACCEPT
iptables -D OUTPUT -d "$resolver" -p tcp --dport 53 -j ACCEPT
done

iptables-save > config/iptables.conf
;;

Expand Down