update caw
[firewall-squeep] / firewall.sh
1 #!/bin/sh
2
3 set -e
4
5 . ./common.sh
6
7 debug=0
8
9 if [ ${debug} -ne 0 ]
10 then
11 IPTABLES="echo ${IPTABLES}"
12 IP6TABLES="echo ${IP6TABLES}"
13 IPSET="echo ${IPSET}"
14 fi
15
16 if [ $# -lt 1 ]
17 then
18 echo "Usage: $(basename "$0") external_interface" 1>&2
19 exit 64
20 fi
21
22 EXT_IF="$1"
23 if ! ip link show "${EXT_IF}" >/dev/null 2>&1
24 then
25 echo "'${EXT_IF}' does not seem to be a valid interface"
26 exit 1
27 fi
28
29 $IPTABLES -F
30 $IPTABLES -F INPUT
31 $IPTABLES -X
32
33 $IP6TABLES -F
34 $IP6TABLES -F INPUT
35 $IP6TABLES -X
36
37 # default policies
38 $IPTABLES -P INPUT DROP
39 $IPTABLES -P OUTPUT ACCEPT
40
41 $IP6TABLES -P INPUT DROP
42 $IP6TABLES -P OUTPUT ACCEPT
43
44 # accept local traffic
45 $IPTABLES -A INPUT -i lo -j ACCEPT
46 $IP6TABLES -A INPUT -i lo -j ACCEPT
47
48 # accept ICMP
49 $IPTABLES -A INPUT -p icmp -j ACCEPT
50 $IP6TABLES -A INPUT -p ipv6-icmp -j ACCEPT
51
52 # drop source-route rh0 headery things
53 $IP6TABLES -A INPUT -m rt --rt-type 0 -j DROP || echo "MISSING RT MATCH" 1>&2
54
55 # accept things we set up
56 $IPTABLES -A INPUT -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
57 $IP6TABLES -A INPUT -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
58
59 # accept ipv6 link-local traffic
60 $IP6TABLES -A INPUT -s fe80::/10 -j ACCEPT
61
62 # accept ipv6 multicast
63 $IP6TABLES -A INPUT -s ff00::/8 -j ACCEPT
64
65 # log and drop invalid flag combinations
66 for flags in 'ALL FIN,URG,PSH' 'ALL ALL' 'ALL SYN,RST,ACK,FIN,URG' 'ALL NONE' 'SYN,RST SYN,RST' 'SYN,FIN SYN,FIN'
67 do
68 $IPTABLES -A INPUT -p tcp --tcp-flags ${flags} -j DROP
69 done
70
71 # accept ESP for IPSec
72 $IPTABLES -A INPUT -p esp -j ACCEPT
73 $IP6TABLES -A INPUT -p esp -j ACCEPT
74
75 # accept all IPSec traffic
76 $IPTABLES -A INPUT -m policy --dir in --pol ipsec -j ACCEPT
77 $IP6TABLES -A INPUT -m policy --dir in --pol ipsec -j ACCEPT
78
79 ./services.sh ${EXT_IF}
80
81 create_drop_chain xenophobe
82
83 # insert asia blocker
84 ./sinokorea.sh
85
86 # insert persistent-pest-blocker
87 ./xenophobe.sh
88
89 # insert trusted passes
90 ./trusted.sh
91