-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathfirewall.sh
More file actions
executable file
·169 lines (124 loc) · 4.15 KB
/
Copy pathfirewall.sh
File metadata and controls
executable file
·169 lines (124 loc) · 4.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#!/bin/bash
# Fredz firewall
# Stealth and OpenVPN-aware firewall.
# eth0 is connected to the internet.
# tun0 is connected to a private subnet.
# Kernel configuration.
#-------------------------
# Enable IP forwarding.
# On => Off = (reset)
echo 1 > /proc/sys/net/ipv4/ip_forward
# Enable IP spoofing protection
for i in /proc/sys/net/ipv4/conf/*/rp_filter; do echo 1 > $i; done
# Protect against SYN flood attacks
echo 1 > /proc/sys/net/ipv4/tcp_syncookies
# VPN1
PRIVATE=10.8.0.0/16
echo "Private Address (trusted): ${PRIVATE}"
# VPN2
PRIVATE2=10.9.0.0/16
echo "Private Address (trusted): ${PRIVATE2}"
# Loopback address
LOOP=127.0.0.1
echo "Loop Address: ${LOOP}"
# FULLY Trusted networks.
TRUSTED="168.120.0.0/16 55.55.55.55 66.66.66.66"
TRUSTED=""
# Eternal Ports
TCP_PORTS="22 80 110 143 443 587 993 995 2222 22022 55455 8080 55455"
# Set to True if you have TOR running
TOR_ENABLED=true
# Delete old iptables rules
# and temporarily block all traffic.
iptables -P OUTPUT DROP
iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -F
# Set default policies
iptables -P OUTPUT ACCEPT
iptables -P INPUT DROP
iptables -P FORWARD DROP
echo "Prevent external packets from using loopback addr"
iptables -A INPUT -i eth0 -s $LOOP -j DROP
iptables -A FORWARD -i eth0 -s $LOOP -j DROP
iptables -A INPUT -i eth0 -d $LOOP -j DROP
iptables -A FORWARD -i eth0 -d $LOOP -j DROP
# Always allow loop
echo "Allow local loopback ${LOOP}"
iptables -A INPUT -s $LOOP -j ACCEPT
iptables -A INPUT -d $LOOP -j ACCEPT
echo "Keep state of connections from local machine and private subnets"
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
echo "Allow all outgoing connections"
iptables -A OUTPUT -m state --state NEW -j ACCEPT
iptables -A FORWARD -m state --state NEW -j ACCEPT
# Allow incoming pings (can be disabled)
echo "Allow only Pings (icmp-type: echo-request)"
iptables -A INPUT -p icmp --icmp-type echo-request -j ACCEPT
if [ $TOR_ENABLED ]
then
echo "Allowing TOR ports"
iptables -A INPUT -i eth+ -p tcp -m multiport --ports 9001,9050,9051,9090,9091 -j ACCEPT
iptables -A INPUT -i eth+ -p udp -m multiport --ports 9001,9050,9051,9090,9091 -j ACCEPT
fi
##############################
# Trusted
##############################
for IP in $TRUSTED
do
echo "Allow Fully Trusted only from: ${IP}"
iptables -A INPUT -i eth+ -s $IP -j ACCEPT
done
#########################
# External Services
#########################
for PORT in $TCP_PORTS
do
echo "Allow TCP PORT: ${PORT}"
iptables -A INPUT -p tcp --dport $PORT -j ACCEPT
done
#################
### ALLOW UDP ###
#################
echo "Allowing ALL UDP"
iptables -A INPUT -p udp -j ACCEPT
###########
### VPN ###
###########
# Allow incoming OpenVPN packets
# Duplicate the line below for each
# OpenVPN tunnel, changing --dport n
# to match the OpenVPN UDP port.
echo "Allow port UDP 1194 for OpenVPN"
iptables -A INPUT -p udp --dport 1194 -j ACCEPT
iptables -A INPUT -p tcp --dport 1194 -j ACCEPT
echo "Allow Everything from local VPN, WARNING !!!"
iptables -A INPUT -s $PRIVATE -j ACCEPT
iptables -A INPUT -d $PRIVATE -j ACCEPT
iptables -A INPUT -s $PRIVATE2 -j ACCEPT
iptables -A INPUT -d $PRIVATE2 -j ACCEPT
# Allow packets from TUN/TAP devices.
# When OpenVPN is run in a secure mode,
# it will authenticate packets prior
# to their arriving on a tun or tap
# interface. Therefore, it is not
# necessary to add any filters here,
# unless you want to restrict the
# type of packets which can flow over
# the tunnel.
echo "Allow all in and outgoing OpenVPN packets"
iptables -A INPUT -i tun+ -j ACCEPT
iptables -A FORWARD -i tun+ -j ACCEPT
iptables -A INPUT -i tap+ -j ACCEPT
iptables -A FORWARD -i tap+ -j ACCEPT
echo "Masquerade local VPN subnet on eth0"
iptables -t nat -A POSTROUTING -s $PRIVATE -o eth0 -j MASQUERADE
iptables -t nat -A POSTROUTING -s $PRIVATE2 -o eth0 -j MASQUERADE
# Log Dropped Packets
echo "Logging dropped packages at the mos 90/min"
iptables -A INPUT -m limit --limit 90/min -j LOG --log-prefix "iptables denied: " --log-level 7
# Drop all other traffic
echo "Drop everything else"
iptables -A INPUT -j DROP
### END ###