Hi! Vielen Dank für die Anleitung! Diese funktioniert toll und ist echt gut!Moin,
@nonono
So, du kannst gerne erneut testen.
Nun wird automatisch erkannt, ob iptables oder nftables installiert ist und welcher der beiden aktiv ist.
Dementsprechend gibt das Script dies auch aus.
Sag Bescheid, wenn wieder was sein sollte.
Bash:#!/bin/bash # function fw_rules_iptables { # loeschen der vorhandenen Regeln iptables -F # Freigabe der openVPN-Ports der Standardkonfiguration von Perfect-Privacy iptables -t filter -A OUTPUT -o "$1" -p udp -m multiport --dports 1148,148,1149,149,1150,150,1151,151,44,443,4433 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT iptables -t filter -A OUTPUT -o "$1" -p tcp -m multiport --dports 300,301,1142,142,1152,152,22 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT iptables -t filter -A INPUT -i "$1" -p udp -m multiport --sports 1148,148,1149,149,1150,150,1151,151,44,443,4433 -m state --state ESTABLISHED,RELATED -j ACCEPT iptables -t filter -A INPUT -i "$1" -p tcp -m multiport --sports 300,301,1142,142,1152,152,22 -m state --state ESTABLISHED,RELATED -j ACCEPT # Freigabe der Standard-IP-Ranges fuer lokale Netzwerke iptables -t filter -A OUTPUT --dst 192.168.0.0/16 -j ACCEPT iptables -t filter -A INPUT --src 192.168.0.0/16 -j ACCEPT iptables -t filter -A OUTPUT --dst 10.0.0.0/8 -j ACCEPT iptables -t filter -A INPUT --src 10.0.0.0/8 -j ACCEPT iptables -t filter -A OUTPUT --dst 172.16.0.0/12 -j ACCEPT iptables -t filter -A INPUT --src 172.16.0.0/12 -j ACCEPT # Blockieren saemtlicher, nicht zuvor definierter, Netzwerkanfragen iptables -t filter -A OUTPUT -o "$1" -j DROP iptables -t filter -A INPUT -i "$1" -j DROP } function fw_rules_nftables { # Hinzufuegen einer neuen Table nft add table block_without_tun # loeschen der vorhandenen Regeln nft flush table block_without_tun # Chains anlegen nft add chain block_without_tun input { type filter hook input priority 0 \; } nft add chain block_without_tun output { type filter hook input priority 0 \; } # Freigabe der openVPN-Ports der Standardkonfiguration von Perfect-Privacy nft add rule block_without_tun output oifname '"'"$1"'"' ip protocol udp udp dport { 1148,148,1149,149,1150,150,1151,151,44,443,4433} ct state new,related,established counter accept nft add rule block_without_tun output oifname '"'"$1"'"' ip protocol tcp tcp dport { 300,301,1142,142,1152,152,22} ct state new,related,established counter accept nft add rule block_without_tun input iifname '"'"$1"'"' ip protocol udp udp sport { 1148,148,1149,149,1150,150,1151,151,44,443,4433} ct state related,established counter accept nft add rule block_without_tun input iifname '"'"$1"'"' ip protocol tcp tcp sport { 300,301,1142,142,1152,152,22} ct state related,established counter accept # Freigabe der Standard-IP-Ranges fuer lokale Netzwerke nft add rule block_without_tun output ip daddr 192.168.0.0/16 counter accept nft add rule block_without_tun input ip saddr 192.168.0.0/16 counter accept nft add rule block_without_tun output ip daddr 10.0.0.0/8 counter accept nft add rule block_without_tun input ip saddr 10.0.0.0/8 counter accept nft add rule block_without_tun output ip daddr 172.16.0.0/12 counter accept nft add rule block_without_tun input ip saddr 172.16.0.0/12 counter accept # Blockieren saemtlicher -nicht zuvor definierter- Netzwerkanfragen nft add rule block_without_tun output oifname '"'"$1"'"' counter drop nft add rule block_without_tun input iifname '"'"$1"'"' counter drop } echo -e "\n\nKillswitch-Script zum Abriegeln der physischen Netzwerkadapter" echo -e "--------------------------------------------------------------\n" # ermitteln der genutzten Firewall dpkg -l | grep ^ii | awk '{print $2}' | grep -w "iptables" >> /dev/null inst_ipt="$?" dpkg -l | grep ^ii | awk '{print $2}' | grep -w "nftables" >> /dev/null inst_nft="$?" if [ "$inst_ipt" -eq "1" ] && [ "$inst_nft" -eq "1" ]; then echo -e "'iptables' oder 'nftables' nicht installiert!" echo -e "Bitte erst die gewuenschte Firewall mit folgendem Befehl installieren und anschliessend das Script erneut ausfuehren:" echo -e "\niptables:\tsudo apt-get install iptables\n" echo -e "\nnftables:\tsudo apt-get install nftables\n" exit elif [ "$inst_ipt" -eq "$inst_nft" ]; then if systemctl status nftables | grep -w "inactive" >> /dev/null then use_fw=iptables else use_fw=nftables fi elif [ "$inst_ipt" -eq "0" ] && [ "$inst_nft" -eq "1" ]; then use_fw=iptables elif [ "$inst_ipt" -eq "1" ] && [ "$inst_nft" -eq "0" ]; then use_fw=nftables else echo -e "\n--------------------------------" echo -e "unbekannter Status - beenden!" echo -e "--------------------------------\n\n" exit fi # ermitteln vorhandener physischer Netzwerkadapter mapfile -t phy_net < <(grep -E -v 'tun|lo' /proc/net/dev | cut -d ':' -f 1 | tr -d '[:blank:]' | grep -E '*[0-9]') # ermitteln vorhandener VPN-TUN mapfile -t tun_net < <(grep 'tun' /proc/net/dev | cut -d ':' -f 1 | tr -d '[:blank:]') if [ "${#tun_net[*]}" -gt "0" ]; then START=0 count="$((${#phy_net[*]}-"1"))" echo -e "Es wurden folgende physischen Apdater erkannt" echo -e "---------------------------------------------" for (( i=START; i<=count; i++ )) do echo -e "==> ${phy_net[i]}" done echo -e "\n\nErkannte, aktive Firewall" echo -e "-------------------------" if [ "$use_fw" == "iptables" ]; then echo -e "==> 'iptables' scheint aktiv zu sein!\n" elif [ "$use_fw" == "nftables" ]; then echo -e "==> 'nftables' scheint aktiv zu sein!\n" fi echo -e "Firewall-Konfiguration von $use_fw wird somit angepasst!" echo -e "\nHINWEIS: Nach einem Neustart werden die Anpassungen automatisch zurueckgesetzt!" echo -e "Welche Aktion soll ausgefuehrt werden?\n" echo -e "(i)mport der Regeln\n(l)oeschen saemtlicher Regeln\n(a)bbruch des Scripts" read -r answer case "$answer" in i) START=0 count="$((${#phy_net[*]}-"1"))" echo -e "\nAntwort: 'import'\n" for (( i=START; i<=count; i++ )) do if [ "$use_fw" == "iptables" ]; then fw_rules_iptables "${phy_net[i]}" elif [ "$use_fw" == "nftables" ]; then fw_rules_nftables "${phy_net[i]}" fi done echo -e "\n-------------------------------------------" echo -e "Hinzufuegen der Firewall-Regeln erfolgreich" echo -e "-------------------------------------------\n\n" ;; l) echo -e "\nAntwort: 'loeschen'\n" if [ "$use_fw" == "iptables" ]; then iptables -F elif [ "$use_fw" == "nftables" ]; then nft flush table block_without_tun fi echo -e "\n----------------------------------------" echo -e "Loeschen der Firewall-Regeln erfolgreich" echo -e "----------------------------------------\n\n" ;; a) echo -e "\nAntwort: 'abbruch'\n" echo -e "\n-------------" echo -e "Scriptabbruch" echo -e "-------------\n\n" ;; *) echo -e "\nAntwort: 'undefiniert'\n" echo -e "\n-------------" echo -e "Scriptabbruch" echo -e "-------------\n\n" ;; esac else echo -e "Es konnten KEINE TUN-Adapter ermittelt werden" echo -e "Bitte die VPN-Verbindungen aufbauen und das Script im Anschluss erneut starten!\n" echo -e "Soll versucht werden, saemtliche temporaere 'iptables' und 'nftables' Regeln zu entfernen?\n" echo -e "(j)a / (n)ein" read -r answer case "$answer" in j) echo -e "\nAntwort: 'ja'\n" iptables -F nft flush table block_without_tun echo -e "\n---------------" echo -e "Regeln entfernt" echo -e "---------------\n\n" ;; n) echo -e "\nAntwort: 'nein'\n" echo -e "\n-------------" echo -e "Scriptabbruch" echo -e "-------------\n\n" ;; *) echo -e "\nAntwort: 'undefiniert'\n" echo -e "\n-------------" echo -e "Scriptabbruch" echo -e "-------------\n\n" ;; esac fi
hi, Linux Mint in einer virtual Box und Netzwerkbrücke scheint Probleme zu machen .. sobald ich das script starte Fragt er Import oder Löschen. Nach Import sagt er alles erfolgreich, jedoch lässt sich einfach keine Verbindung aufbauen ..Dann Feuer frei!
Bash:#!/bin/bash # function fw_rules_iptables { # loeschen der vorhandenen Regeln iptables -F # Freigabe der openVPN-Ports der Standardkonfiguration von Perfect-Privacy iptables -t filter -A OUTPUT -o "$1" -p udp -m multiport --dports 1148,148,1149,149,1150,150,1151,151,44,443,4433 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT iptables -t filter -A OUTPUT -o "$1" -p tcp -m multiport --dports 300,301,1142,142,1152,152,22,44,443,4433 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT iptables -t filter -A INPUT -i "$1" -p udp -m multiport --sports 1148,148,1149,149,1150,150,1151,151,44,443,4433 -m state --state ESTABLISHED,RELATED -j ACCEPT iptables -t filter -A INPUT -i "$1" -p tcp -m multiport --sports 300,301,1142,142,1152,152,22,44,443,4433 -m state --state ESTABLISHED,RELATED -j ACCEPT # Freigabe der Standard-IP-Ranges fuer lokale Netzwerke iptables -t filter -A OUTPUT --dst 192.168.0.0/16 -j ACCEPT iptables -t filter -A INPUT --src 192.168.0.0/16 -j ACCEPT iptables -t filter -A OUTPUT --dst 10.0.0.0/8 -j ACCEPT iptables -t filter -A INPUT --src 10.0.0.0/8 -j ACCEPT iptables -t filter -A OUTPUT --dst 172.16.0.0/12 -j ACCEPT iptables -t filter -A INPUT --src 172.16.0.0/12 -j ACCEPT # Blockieren saemtlicher, nicht zuvor definierter, Netzwerkanfragen iptables -t filter -A OUTPUT -o "$1" -j DROP iptables -t filter -A INPUT -i "$1" -j DROP } function fw_rules_nftables { # Hinzufuegen einer neuen Table nft add table block_without_tun # loeschen der vorhandenen Regeln nft flush table block_without_tun # Chains anlegen nft add chain block_without_tun input { type filter hook input priority 0 \; } nft add chain block_without_tun output { type filter hook input priority 0 \; } # Freigabe der openVPN-Ports der Standardkonfiguration von Perfect-Privacy nft add rule block_without_tun output oifname '"'"$1"'"' ip protocol udp udp dport { 1148,148,1149,149,1150,150,1151,151,44,443,4433} ct state new,related,established counter accept nft add rule block_without_tun output oifname '"'"$1"'"' ip protocol tcp tcp dport { 300,301,1142,142,1152,152,22,44,443,4433} ct state new,related,established counter accept nft add rule block_without_tun input iifname '"'"$1"'"' ip protocol udp udp sport { 1148,148,1149,149,1150,150,1151,151,44,443,4433} ct state related,established counter accept nft add rule block_without_tun input iifname '"'"$1"'"' ip protocol tcp tcp sport { 300,301,1142,142,1152,152,22,44,443,4433} ct state related,established counter accept # Freigabe der Standard-IP-Ranges fuer lokale Netzwerke nft add rule block_without_tun output ip daddr 192.168.0.0/16 counter accept nft add rule block_without_tun input ip saddr 192.168.0.0/16 counter accept nft add rule block_without_tun output ip daddr 10.0.0.0/8 counter accept nft add rule block_without_tun input ip saddr 10.0.0.0/8 counter accept nft add rule block_without_tun output ip daddr 172.16.0.0/12 counter accept nft add rule block_without_tun input ip saddr 172.16.0.0/12 counter accept # Blockieren saemtlicher -nicht zuvor definierter- Netzwerkanfragen nft add rule block_without_tun output oifname '"'"$1"'"' counter drop nft add rule block_without_tun input iifname '"'"$1"'"' counter drop } echo -e "\n\nKillswitch-Script zum Abriegeln der physischen Netzwerkadapter" echo -e "--------------------------------------------------------------\n" # ermitteln der genutzten Firewall dpkg -l | grep ^ii | awk '{print $2}' | grep -w "iptables" >> /dev/null inst_ipt="$?" dpkg -l | grep ^ii | awk '{print $2}' | grep -w "nftables" >> /dev/null inst_nft="$?" if [ "$inst_ipt" -eq "1" ] && [ "$inst_nft" -eq "1" ]; then echo -e "'iptables' oder 'nftables' nicht installiert!" echo -e "Bitte erst die gewuenschte Firewall mit folgendem Befehl installieren und anschliessend das Script erneut ausfuehren:" echo -e "\niptables:\tsudo apt-get install iptables\n" echo -e "\nnftables:\tsudo apt-get install nftables\n" exit elif [ "$inst_ipt" -eq "$inst_nft" ]; then if systemctl status nftables | grep -w "inactive" >> /dev/null then use_fw=iptables else use_fw=nftables fi elif [ "$inst_ipt" -eq "0" ] && [ "$inst_nft" -eq "1" ]; then use_fw=iptables elif [ "$inst_ipt" -eq "1" ] && [ "$inst_nft" -eq "0" ]; then use_fw=nftables else echo -e "\n--------------------------------" echo -e "unbekannter Status - beenden!" echo -e "--------------------------------\n\n" exit fi # ermitteln vorhandener physischer Netzwerkadapter mapfile -t phy_net < <(grep -E -v 'tun|lo' /proc/net/dev | cut -d ':' -f 1 | tr -d '[:blank:]' | grep -E '*[0-9]') # ermitteln vorhandener VPN-TUN mapfile -t tun_net < <(grep 'tun' /proc/net/dev | cut -d ':' -f 1 | tr -d '[:blank:]') if [ "${#tun_net[*]}" -gt "0" ]; then START=0 count="$((${#phy_net[*]}-"1"))" echo -e "Es wurden folgende physischen Apdater erkannt" echo -e "---------------------------------------------" for (( i=START; i<=count; i++ )) do echo -e "==> ${phy_net[i]}" done echo -e "\n\nErkannte, aktive Firewall" echo -e "-------------------------" if [ "$use_fw" == "iptables" ]; then echo -e "==> 'iptables' scheint aktiv zu sein!\n" elif [ "$use_fw" == "nftables" ]; then echo -e "==> 'nftables' scheint aktiv zu sein!\n" fi echo -e "Firewall-Konfiguration von $use_fw wird somit angepasst!" echo -e "\nHINWEIS: Nach einem Neustart werden die Anpassungen automatisch zurueckgesetzt!" echo -e "Welche Aktion soll ausgefuehrt werden?\n" echo -e "(i)mport der Regeln\n(l)oeschen saemtlicher Regeln\n(a)bbruch des Scripts" read -r answer case "$answer" in i) START=0 count="$((${#phy_net[*]}-"1"))" echo -e "\nAntwort: 'import'\n" for (( i=START; i<=count; i++ )) do if [ "$use_fw" == "iptables" ]; then fw_rules_iptables "${phy_net[i]}" elif [ "$use_fw" == "nftables" ]; then fw_rules_nftables "${phy_net[i]}" fi done echo -e "\n-------------------------------------------" echo -e "Hinzufuegen der Firewall-Regeln erfolgreich" echo -e "-------------------------------------------\n\n" ;; l) echo -e "\nAntwort: 'loeschen'\n" if [ "$use_fw" == "iptables" ]; then iptables -F elif [ "$use_fw" == "nftables" ]; then nft flush table block_without_tun fi echo -e "\n----------------------------------------" echo -e "Loeschen der Firewall-Regeln erfolgreich" echo -e "----------------------------------------\n\n" ;; a) echo -e "\nAntwort: 'abbruch'\n" echo -e "\n-------------" echo -e "Scriptabbruch" echo -e "-------------\n\n" ;; *) echo -e "\nAntwort: 'undefiniert'\n" echo -e "\n-------------" echo -e "Scriptabbruch" echo -e "-------------\n\n" ;; esac else echo -e "Es konnten KEINE TUN-Adapter ermittelt werden" echo -e "Bitte die VPN-Verbindungen aufbauen und das Script im Anschluss erneut starten!\n" echo -e "Soll versucht werden, saemtliche temporaere 'iptables' und 'nftables' Regeln zu entfernen?\n" echo -e "(j)a / (n)ein" read -r answer case "$answer" in j) echo -e "\nAntwort: 'ja'\n" iptables -F nft flush table block_without_tun echo -e "\n---------------" echo -e "Regeln entfernt" echo -e "---------------\n\n" ;; n) echo -e "\nAntwort: 'nein'\n" echo -e "\n-------------" echo -e "Scriptabbruch" echo -e "-------------\n\n" ;; *) echo -e "\nAntwort: 'undefiniert'\n" echo -e "\n-------------" echo -e "Scriptabbruch" echo -e "-------------\n\n" ;; esac fi
Aber ACHTUNG!
TCP 443 ist Standard HTTPS -> das wird somit trotzdem funktionieren, wenn der Tunnel weg sein sollte!
Fri Sep 25 16:04:08 2020 us=540400 PID_ERR replay-window backtrack occurred [4] [SSL-0] [0_0__00000000000000000000000000000000000000000000000000000000000] 0:41448 0:41444 t=1601042648[0] r=[-2,64,15,4,1] sl=[24,64,64,528]