Subversion Repositories ALCASAR

Rev

Rev 1291 | Rev 1299 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log

Rev Author Line No. Line
872 richard 1
#!/bin/bash
64 franck 2
# $Id: alcasar-iptables.sh 1294 2014-01-12 23:03:00Z richard $
675 richard 3
# Script de mise en place des regles du parefeu d'Alcasar (mode normal)
568 richard 4
# This script write the netfilter rules for ALCASAR
675 richard 5
# Rexy - 3abtux - CPN
6
#
7
# Reminders
1221 richard 8
# There are four channels for log :
1294 richard 9
#	1 tracability of the consultation equipment with The 'Netflow' kernel module (iptables target = NETFLOW);
1221 richard 10
#	2 protection of ALCASAR with the Ulog group 1 (default group) 
1294 richard 11
#	3 SSH on ALCASAR with the Ulog group 2;
12
#	4 extern access attempts on ALCASAR with the Ulog group 3.
675 richard 13
# The bootps/dhcp (67) port is always open on tun0/eth1 by coova 
612 richard 14
conf_file="/usr/local/etc/alcasar.conf"
766 richard 15
private_ip_mask=`grep PRIVATE_IP= $conf_file|cut -d"=" -f2`
615 richard 16
private_ip_mask=${private_ip_mask:=192.168.182.1/24}
783 richard 17
PRIVATE_IP=`echo $private_ip_mask | cut -d"/" -f1`			# ALCASAR LAN IP address
604 richard 18
private_network=`/bin/ipcalc -n $private_ip_mask|cut -d"=" -f2`		# LAN IP address (ie.: 192.168.182.0)
19
private_prefix=`/bin/ipcalc -p $private_ip_mask|cut -d"=" -f2`		# LAN prefix (ie. 24)
783 richard 20
PRIVATE_NETWORK_MASK=$private_network/$private_prefix			# Lan IP address + prefix (192.168.182.0/24)
21
public_ip_mask=`grep PUBLIC_IP= $conf_file|cut -d"=" -f2`		# ALCASAR WAN IP address
22
PUBLIC_IP=`echo $public_ip_mask | cut -d"/" -f1`
766 richard 23
dns1=`grep DNS1= $conf_file|cut -d"=" -f2`				# first public DNS server
615 richard 24
dns1=${dns1:=208.67.220.220}
766 richard 25
dns2=`grep DNS2= $conf_file|cut -d"=" -f2`				# second public DNS server
615 richard 26
dns2=${dns2:=208.67.222.222}
783 richard 27
DNSSERVERS="$dns1,$dns2"						# first and second DNS IP servers addresses
766 richard 28
PROTOCOLS_FILTERING=`grep PROTOCOLS_FILTERING= $conf_file|cut -d"=" -f2`	# Network protocols filter (on/off)
615 richard 29
PROTOCOLS_FILTERING=${PROTOCOLS_FILTERING:=off}
766 richard 30
DNS_FILTERING=`grep DNS_FILTERING= $conf_file|cut -d"=" -f2`		# DNS and URLs filter (on/off)
615 richard 31
DNS_FILTERING=${DNS_FILTERING:=off}
1294 richard 32
BL_IP_CAT="/usr/local/share/iptables-bl"				# categories files of the BlackListed IP
783 richard 33
QOS=`grep QOS= $conf_file|cut -d"=" -f2`				# QOS (on/off)
615 richard 34
QOS=${QOS:=off}
783 richard 35
SSH=`grep SSH= $conf_file|cut -d"=" -f2`				# sshd active (on/off)
615 richard 36
SSH=${SSH:=off}
1063 richard 37
SSH_ADMIN_FROM=`grep SSH_ADMIN_FROM= $conf_file|cut -d"=" -f2`
38
SSH_ADMIN_FROM=${SSH_ADMIN_FROM:="0.0.0.0/0.0.0.0"}			# WAN IP address to reduce ssh access (all ip allowed on LAN side)
783 richard 39
LDAP=`grep LDAP= $conf_file|cut -d"=" -f2`				# LDAP external server active (on/off)
615 richard 40
LDAP=${LDAP:=off}
783 richard 41
LDAP_IP=`grep LDAP_IP= $conf_file|cut -d"=" -f2`			# WAN IP address to reduce LDAP WAN access (all ip allowed on LAN side)
768 richard 42
LDAP_IP=${LDAP_IP:="0.0.0.0/0.0.0.0"}
675 richard 43
EXTIF="eth0"
1 root 44
INTIF="eth1"
783 richard 45
TUNIF="tun0"								# listen device for chilli daemon
612 richard 46
IPTABLES="/sbin/iptables"
1 root 47
 
1291 richard 48
 
49
# loading of NetFlow probe (ipt_NETFLOW kernel module)
1159 crox53 50
modprobe ipt_NETFLOW destination=127.0.0.1:2055
51
 
498 richard 52
# Effacement des règles existantes
476 richard 53
# Flush all existing rules
1 root 54
$IPTABLES -F
55
$IPTABLES -t nat -F
56
$IPTABLES -t mangle -F
57
$IPTABLES -F INPUT
58
$IPTABLES -F FORWARD
59
$IPTABLES -F OUTPUT
60
 
498 richard 61
# Suppression des chaines utilisateurs sur les tables filter et nat
62
# Flush non default rules on filter and nat tables
63
$IPTABLES -X
64
$IPTABLES -t nat -X
65
 
66
# Stratégies par défaut
476 richard 67
# Default policies
1 root 68
$IPTABLES -P INPUT DROP
69
$IPTABLES -P FORWARD DROP
498 richard 70
$IPTABLES -P OUTPUT DROP
1 root 71
$IPTABLES -t nat -P PREROUTING ACCEPT
72
$IPTABLES -t nat -P POSTROUTING ACCEPT
73
$IPTABLES -t nat -P OUTPUT ACCEPT
74
 
1291 richard 75
# destruction de tous les SET
76
# destroy all the SET
77
ipset destroy
78
 
1294 richard 79
# Création et peuplement du SET alcasar_ip_blocked
80
# creation and first populating of alcasar_ip_blocked SET
1291 richard 81
ipset create alcasar_ip_blocked hash:net hashsize 1024
82
if [ -s /usr/local/etc/alcasar-ip-blocked ]; then 
83
	while read ip_line
84
	do
85
		ip_on=`echo $ip_line|cut -b1`
86
		if [ $ip_on != "#" ]
87
		then	
88
			ip_blocked=`echo $ip_line|cut -d" " -f1`
89
			ipset add alcasar_ip_blocked $ip_blocked
90
		fi
91
	done < /usr/local/etc/alcasar-ip-blocked
92
fi
93
 
1294 richard 94
# Création et initialisation du SET authenticated_ip (dynamiquement peuplé par les scripts conup/condown)
95
# creation and initialization of authenticated_ip_ SET (populated dynamicly by conup/condown scripts)
96
ipset create authenticated_ip hash:net hashsize 1024
97
OLDIFS=$IFS
98
IFS=$'\n'
99
for equipment in `/usr/sbin/chilli_query list |grep -v "\.0\.0\.0"`
100
do
101
	active_ip=`echo $equipment |cut -d" " -f2`
102
	active_session=`echo $equipment |cut -d" " -f5`
103
	if [[ $(expr $active_session) -eq 1 ]]
104
	then
105
		ipset add authenticated_ip $active_ip
106
	fi
107
done
108
IFS=$OLDIFS
109
 
110
# Création et peuplement du SET blacklist_ip_blocked
111
# creation and first populating of blacklist_ip_blocked SET
112
# wait for a better blacklist adapt process 
113
#ipset create blacklist_ip_blocked hash:net hashsize 1024
114
#cd $BL_IP_CAT
115
#for category in `ls -1 | cut -d"@" -f1`
116
#do
117
#	while read ip_blocked
118
#	do
119
#		ipset add blacklist_ip_blocked $ip_blocked
120
#	done < $BL_IP_CAT/$category
121
#done
122
 
472 richard 123
#############################
783 richard 124
#       PREROUTING          #
472 richard 125
#############################
783 richard 126
# Marquage (et journalisation) des paquets qui tentent d'accéder directement à DansGuardian pour pouvoir les rejeter en INPUT
127
# mark (and log) the dansguardian bypass attempts in order to DROP them in INPUT rules
1221 richard 128
$IPTABLES -A PREROUTING -t nat -i $TUNIF -p tcp -d $PRIVATE_IP -m tcp --dport 8080 -j ULOG --ulog-prefix "RULE direct-proxy -- DENY "
783 richard 129
$IPTABLES -A PREROUTING -t mangle -i $TUNIF -d $PRIVATE_IP -p tcp -m tcp --dport 8080 -j MARK --set-mark 1
1 root 130
 
783 richard 131
# Marquage (et journalisation) des paquets qui tentent d'accéder directement au port udp 54 pour pouvoir les rejeter en INPUT
132
# Mark (and log) the udp 54 direct attempts to REJECT them in INPUT rules
133
# Remarque : Ce port n'est ouvert que lorsque le filtrage est activé
134
# Remark : this port is only open when filtering is on
135
# $IPTABLES -A PREROUTING -t nat -i $TUNIF -p udp -d $PRIVATE_IP -m udp --dport 54 -j ULOG --ulog-prefix "RULE DNS-proxy -- DENY "
136
$IPTABLES -A PREROUTING -t mangle -i $TUNIF -d $PRIVATE_IP -p tcp --dport 54 -j MARK --set-mark 2
137
 
1072 richard 138
# Si le filtrage DNS est activé, redirection des flux DNS vers le port 54 (dns+blackhole) sauf pour les IP en exceptions 
783 richard 139
# If DNS filter is on, redirect DNS request to udp 54 (dns+blackhole) except for exception IP addresses
140
if [ $DNS_FILTERING = on ]; then
141
	# Compute exception IP
142
	nb_exceptions=`wc -l /usr/local/etc/alcasar-filter-exceptions | cut -d" " -f1`
143
	if [ $nb_exceptions != "0" ]
144
	then
145
		while read ip_exception 
146
		do
147
			$IPTABLES -A PREROUTING -t nat -i $TUNIF -p udp -s $ip_exception -d $PRIVATE_IP --dport domain -j ACCEPT
148
		done < /usr/local/etc/alcasar-filter-exceptions
149
	fi
150
		$IPTABLES -A PREROUTING -t nat -i $TUNIF -s $PRIVATE_NETWORK_MASK -d $PRIVATE_IP -p udp --dport domain -j REDIRECT --to-port 54
151
fi
1294 richard 152
# Redirection des requêtes HTTP des IP admin bannies vers ALCASAR (page 'accès interdit')
153
# Redirect HTTP requests of admin banned ip to ALCASAR (access deny window)
154
$IPTABLES -A PREROUTING -t nat -i $TUNIF -s $PRIVATE_NETWORK_MASK -m set --match-set alcasar_ip_blocked dst -p tcp --dport http -j REDIRECT --to-port http
783 richard 155
 
1294 richard 156
# Redirection des requêtes HTTP des IP de la blacklist vers ALCASAR (page 'accès interdit')
157
# Redirect HTTP requests of blacklist ip to ALCASAR (access deny window)
158
#if [ $DNS_FILTERING = on ]; then
159
#$IPTABLES -A PREROUTING -t nat -i $TUNIF -s $PRIVATE_NETWORK_MASK -m set --match-set blacklist_ip_blocked dst -p tcp --dport http -j REDIRECT --to-port 80
160
#fi
161
 
162
# Redirection des requêtes HTTPS des IP sans utilisateurs authentifiés vers ALCASAR (page d'interception)
163
# Redirect HTTPS requests of IP that don't have authenticate user to ALCASAR (intercept page)
164
$IPTABLES -A PREROUTING -t nat -i $TUNIF -s $PRIVATE_NETWORK_MASK -m set ! --match-set authenticated_ip src ! -d $PRIVATE_IP -p tcp --dport https -j REDIRECT --to-port https
165
 
1291 richard 166
# Journalisation des requètes HTTP vers Internet (seulement les paquets SYN) - Les autres protocoles sont journalisés en FORWARD par netflow
167
## Log HTTP requests to Internet (only syn packets) - Other protocols are log in FORWARD by netflow
1230 crox53 168
$IPTABLES -A PREROUTING -t nat -i $TUNIF -s $PRIVATE_NETWORK_MASK ! -d $PRIVATE_IP -p tcp --dport http -m state --state NEW -j ULOG --ulog-prefix "RULE F_http -- ACCEPT "
1221 richard 169
 
1291 richard 170
# Redirection des requêtes HTTP sortantes vers DansGuardian (proxy transparent)
171
# Redirect outbound HTTP requests to DansGuardian (transparent proxy)
783 richard 172
$IPTABLES -A PREROUTING -t nat -i $TUNIF -s $PRIVATE_NETWORK_MASK ! -d $PRIVATE_IP -p tcp --dport http -j REDIRECT --to-port 8080
173
 
174
# Redirection des requêtes NTP vers le serveur NTP local
175
# Redirect NTP request in local NTP server
176
$IPTABLES -A PREROUTING -t nat -i $TUNIF -s $PRIVATE_NETWORK_MASK ! -d $PRIVATE_IP -p udp --dport ntp -j REDIRECT --to-port 123
177
 
472 richard 178
#############################
783 richard 179
#         INPUT             #
472 richard 180
#############################
871 richard 181
 
783 richard 182
# Tout passe sur loopback
183
# accept all on loopback
184
$IPTABLES -A INPUT -i lo -j ACCEPT
990 franck 185
$IPTABLES -A OUTPUT -o lo -j ACCEPT
783 richard 186
 
187
# Rejet des demandes de connexions non conformes (FIN-URG-PUSH, XMAS, NullScan, SYN-RST et NEW not SYN)
188
# Drop non standard connexions (FIN-URG-PUSH, XMAS, NullScan, SYN-RST et NEW not SYN)
472 richard 189
$IPTABLES -A INPUT -p tcp --tcp-flags FIN,URG,PSH FIN,URG,PSH -j DROP
190
$IPTABLES -A INPUT -p tcp --tcp-flags ALL ALL -j DROP
191
$IPTABLES -A INPUT -p tcp --tcp-flags ALL NONE -j DROP
192
$IPTABLES -A INPUT -p tcp --tcp-flags SYN,RST SYN,RST -j DROP
675 richard 193
$IPTABLES -A INPUT -p tcp -m tcp ! --syn -m state --state NEW -j DROP
498 richard 194
 
871 richard 195
# On rejette les trame en broadcast et en multicast sur EXTIF (évite leur journalisation)
196
# Drop broadcast & multicast on EXTIF to avoid log 
783 richard 197
$IPTABLES -A INPUT -i $EXTIF -m addrtype --dst-type BROADCAST,MULTICAST -j DROP
498 richard 198
 
783 richard 199
# On autorise les retours de connexions légitimes par INPUT
200
# Conntrack on INPUT
201
$IPTABLES -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
373 richard 202
 
1221 richard 203
# On interdit les connexions directes au port utilisé par DansGuardian (8080). Les packets concernés ont été marqués et loggués dans la table mangle (PREROUTING)
204
# Deny direct connections on DansGuardian port (8080). The concerned paquets are marked and logged in mangle table (PREROUTING)
783 richard 205
$IPTABLES -A INPUT -i $TUNIF -p tcp --dport 8080 -m mark --mark 1 -j REJECT --reject-with tcp-reset
791 richard 206
 
783 richard 207
# Autorisation des connexions légitimes à DansGuardian 
208
# Allow connections for DansGuardian
209
$IPTABLES -A INPUT -i $TUNIF -s $PRIVATE_NETWORK_MASK -p tcp --dport 8080 -m state --state NEW --syn -j ACCEPT
373 richard 210
 
783 richard 211
# On interdit les connexions directes au port UDP 54. Les packets concernés ont été marqués dans la table mangle (PREROUTING)
212
# Deny direct connections on UDP 54. The concerned paquets are marked in mangle table (PREROUTING)
213
$IPTABLES -A INPUT -i $TUNIF -p udp --dport 54 -m mark --mark 2 -j REJECT --reject-with icmp-port-unreachable
791 richard 214
 
783 richard 215
# autorisation des connexion légitime à DNSMASQ (avec blackhole)
216
# Allow connections for DNSMASQ (with blackhole)
217
$IPTABLES -A INPUT -i $TUNIF -s $PRIVATE_NETWORK_MASK -d $PRIVATE_IP -p udp --dport 54 -j ACCEPT
218
 
219
# Accès direct aux services internes
220
# Internal services access
786 richard 221
$IPTABLES -A INPUT -i $TUNIF -s $PRIVATE_NETWORK_MASK -d $PRIVATE_IP -p udp --dport domain -j ACCEPT	# DNS non filtré # DNS without blackhole
222
$IPTABLES -A INPUT -i $TUNIF -s $PRIVATE_NETWORK_MASK -d $PRIVATE_IP -p icmp --icmp-type 8 -j ACCEPT	# Réponse ping # ping responce
223
$IPTABLES -A INPUT -i $TUNIF -s $PRIVATE_NETWORK_MASK -d $PRIVATE_IP -p icmp --icmp-type 0 -j ACCEPT	# Requête  ping # ping request
224
$IPTABLES -A INPUT -i $TUNIF -s $PRIVATE_NETWORK_MASK -d $PRIVATE_IP -p tcp --dport https -j ACCEPT	# Pages d'authentification et MCC # authentication pages and MCC
225
$IPTABLES -A INPUT -i $TUNIF -s $PRIVATE_NETWORK_MASK -d $PRIVATE_IP -p tcp --dport http -j ACCEPT	# Page d'avertissement filtrage # Filtering warning pages
226
$IPTABLES -A INPUT -i $TUNIF -s $PRIVATE_NETWORK_MASK -d $PRIVATE_IP -p tcp --dport 3990 -j ACCEPT	# Requêtes de deconnexion usagers # Users logout requests
227
$IPTABLES -A INPUT -i $TUNIF -s $PRIVATE_NETWORK_MASK -d $PRIVATE_IP -p udp --dport ntp -j ACCEPT	# Serveur local de temps # local time server
783 richard 228
 
229
# SSHD rules if activate 
230
if [ $SSH = on ]
520 richard 231
	then
783 richard 232
	$IPTABLES -A INPUT -i $TUNIF -s $PRIVATE_NETWORK_MASK -d $PRIVATE_IP -p tcp --dport ssh -m state --state NEW -j ULOG --ulog-nlgroup 2 --ulog-prefix "RULE ssh-from-LAN -- ACCEPT"
233
	$IPTABLES -A INPUT -i $TUNIF -s $PRIVATE_NETWORK_MASK -d $PRIVATE_IP -p tcp --dport ssh -j ACCEPT
1063 richard 234
	$IPTABLES -A INPUT -i $EXTIF -s $SSH_ADMIN_FROM -d $PUBLIC_IP -p tcp --dport ssh -m state --state NEW --syn -j ULOG --ulog-nlgroup 2 --ulog-prefix "RULE ssh-from-WAN -- ACCEPT"
1161 richard 235
	$IPTABLES -A INPUT -i $EXTIF -s $SSH_ADMIN_FROM -d $PUBLIC_IP -p tcp --dport ssh -m state --state NEW -j ACCEPT
520 richard 236
fi
783 richard 237
 
238
# Insertion de règles locales
239
# Here, we add local rules (i.e. VPN from Internet)
240
if [ -f /usr/local/etc/alcasar-iptables-local.sh ]; then
241
        . /usr/local/etc/alcasar-iptables-local.sh
242
fi
243
 
244
# Journalisation et rejet des connexions (autres que celles autorisées) effectuées depuis le LAN
245
# Deny and log on INPUT from the LAN
246
$IPTABLES -A INPUT -i $TUNIF -m state --state NEW -j ULOG --ulog-prefix "RULE rej-int -- REJECT "
247
$IPTABLES -A INPUT -i $TUNIF -p tcp -j REJECT --reject-with tcp-reset
248
$IPTABLES -A INPUT -i $TUNIF -p udp -j REJECT --reject-with icmp-port-unreachable
249
 
250
# interdiction d'accès à INTIF (n'est utile que lorsque chilli est arrêté).
251
# Reject INTIF access (only when chilli is down)
252
$IPTABLES -A INPUT -i $INTIF -j ULOG --ulog-prefix "RULE Protect1 -- REJECT "
253
$IPTABLES -A INPUT -i $INTIF -j REJECT
254
 
255
# Journalisation et rejet des connexions initiées depuis le réseau extérieur (test des effets du paramètre --limit en cours)
256
# On EXTIF, the access attempts are log in channel 2 (we should test --limit option to avoid deny of service)
257
$IPTABLES -A INPUT -i $EXTIF -m state --state NEW -j ULOG --ulog-nlgroup 3 --ulog-qthreshold 10 --ulog-prefix "RULE rej-ext -- DROP"
258
 
871 richard 259
 
783 richard 260
#############################
261
#        FORWARD            #
262
#############################
263
 
264
# Rejet des requêtes DNS vers Internet
265
# Deny forward DNS
266
$IPTABLES -A FORWARD -i $TUNIF -p udp --dport domain -j REJECT --reject-with icmp-port-unreachable
267
$IPTABLES -A FORWARD -i $TUNIF -p tcp --dport domain -j REJECT --reject-with tcp-reset
268
 
1291 richard 269
# Blocage des IPs du SET alcasar_ip_blocked
270
# Deny IPs of the SET alcasar_ip_blocked 
1294 richard 271
$IPTABLES -A FORWARD -i $TUNIF -m set --match-set alcasar_ip_blocked dst -p icmp -j REJECT --reject-with icmp-port-unreachable
1291 richard 272
$IPTABLES -A FORWARD -i $TUNIF -m set --match-set alcasar_ip_blocked dst -p udp -j REJECT --reject-with icmp-port-unreachable
273
$IPTABLES -A FORWARD -i $TUNIF -m set --match-set alcasar_ip_blocked dst -p tcp -j REJECT --reject-with tcp-reset
859 richard 274
 
1294 richard 275
# Blocage des IPs du SET blacklist_ip_blocked
276
# Deny IPs of the SET blacklist_ip_blocked 
1072 richard 277
#if [ $DNS_FILTERING = on ]; then
1294 richard 278
#	$IPTABLES -A FORWARD -i $TUNIF -m set --match-set blacklist_ip_blocked -p icmp -j REJECT --reject-with icmp-port-unreachable
279
#	$IPTABLES -A FORWARD -i $TUNIF -m set --match-set blacklist_ip_blocked dst -p udp -j REJECT --reject-with icmp-port-unreachable
280
#	$IPTABLES -A FORWARD -i $TUNIF -m set --match-set blacklist_ip_blocked -p tcp -j REJECT --reject-with tcp-reset
1072 richard 281
#fi
282
 
815 richard 283
# Autorisation des retours de connexions légitimes
284
$IPTABLES -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
790 richard 285
 
783 richard 286
#  If protocols filter is activate 
612 richard 287
if [ $PROTOCOLS_FILTERING = on ]; then
688 richard 288
	# Compute exception IP (IP addresses that shouldn't be filtered)
289
	nb_exceptions=`wc -l /usr/local/etc/alcasar-filter-exceptions | cut -d" " -f1`
373 richard 290
	if [ $nb_exceptions != "0" ]
291
	then
292
		while read ip_exception 
293
		do
1221 richard 294
#			$IPTABLES -A FORWARD -i $TUNIF -s $ip_exception -m state --state NEW -j ULOG --ulog-prefix "RULE IP-exception -- ACCEPT "
1159 crox53 295
			$IPTABLES -A FORWARD -i $TUNIF -s $ip_exception -m state --state NEW -j NETFLOW
373 richard 296
			$IPTABLES -A FORWARD -i $TUNIF -s $ip_exception -m state --state NEW -j ACCEPT
297
		done < /usr/local/etc/alcasar-filter-exceptions
298
	fi
871 richard 299
	# Compute uamallowed IP (IP address of equipments connected between ALCASAR and Internet (DMZ, own servers, ...) 
300
	nb_uamallowed=`wc -l /usr/local/etc/alcasar-uamallowed | cut -d" "  -f1`
301
	if [ $nb_uamallowed != "0" ]
688 richard 302
	then
303
		while read ip_allowed_line 
304
		do
305
			ip_allowed=`echo $ip_allowed_line|cut -d"\"" -f2`
1221 richard 306
#			$IPTABLES -A FORWARD -i $TUNIF -d $ip_allowed -m state --state NEW -j ULOG --ulog-prefix "RULE IP-allowed -- ACCEPT "
1159 crox53 307
			$IPTABLES -A FORWARD -i $TUNIF -d $ip_allowed -m state --state NEW -j NETFLOW
688 richard 308
			$IPTABLES -A FORWARD -i $TUNIF -d $ip_allowed -m state --state NEW -j ACCEPT
309
		done < /usr/local/etc/alcasar-uamallowed
310
	fi
520 richard 311
	# Autorisation des protocoles non commentés
476 richard 312
	# Allow non comment protocols
373 richard 313
	while read svc_line
314
	do
315
		svc_on=`echo $svc_line|cut -b1`
316
		if [ $svc_on != "#" ]
317
		then	
318
			svc_name=`echo $svc_line|cut -d" " -f1`
319
			svc_port=`echo $svc_line|cut -d" " -f2`
320
			if [ $svc_name = "icmp" ]
321
			then
1159 crox53 322
				$IPTABLES -A FORWARD -i $TUNIF -s $PRIVATE_NETWORK_MASK -p icmp -j NETFLOW
859 richard 323
				$IPTABLES -A FORWARD -i $TUNIF -s $PRIVATE_NETWORK_MASK -p icmp -j ACCEPT 
373 richard 324
			else
1159 crox53 325
 
1221 richard 326
#				$IPTABLES -A FORWARD -i $TUNIF -s $PRIVATE_NETWORK_MASK -p tcp --dport $svc_port -m state --state NEW -j ULOG --ulog-prefix "RULE F_TCP-$svc_name -- ACCEPT "
1159 crox53 327
				$IPTABLES -A FORWARD -i $TUNIF -s $PRIVATE_NETWORK_MASK -p tcp --dport $svc_port -m state --state NEW -j NETFLOW
859 richard 328
				$IPTABLES -A FORWARD -i $TUNIF -s $PRIVATE_NETWORK_MASK -p tcp --dport $svc_port -m state --state NEW -j ACCEPT
1221 richard 329
#				$IPTABLES -A FORWARD -i $TUNIF -s $PRIVATE_NETWORK_MASK -p udp --dport $svc_port -m state --state NEW -j ULOG --ulog-prefix "RULE F_UDP-$svc_name -- ACCEPT "
1159 crox53 330
				$IPTABLES -A FORWARD -i $TUNIF -s $PRIVATE_NETWORK_MASK -p udp --dport $svc_port -m state --state NEW -j NETFLOW
859 richard 331
				$IPTABLES -A FORWARD -i $TUNIF -s $PRIVATE_NETWORK_MASK -p udp --dport $svc_port -m state --state NEW -j ACCEPT
373 richard 332
			fi
333
		fi
334
	done < /usr/local/etc/alcasar-services
783 richard 335
	# Rejet explicite des autres protocoles
336
	# reject the others protocols
1221 richard 337
#	$IPTABLES -A FORWARD -i $TUNIF -j ULOG --ulog-prefix "RULE F_filter -- REJECT "
373 richard 338
	$IPTABLES -A FORWARD -i $TUNIF -p tcp -j REJECT --reject-with tcp-reset
339
	$IPTABLES -A FORWARD -i $TUNIF -p udp -j REJECT --reject-with icmp-port-unreachable
340
	$IPTABLES -A FORWARD -i $TUNIF -p icmp -j REJECT 
1 root 341
fi
492 franck 342
 
343
#  If QOS is activate  #
612 richard 344
if [ $QOS = on ] && [ -e /usr/local/etc/alcasar-iptables-qos.sh ]; then
492 franck 345
	. /usr/local/etc/alcasar-iptables-qos.sh 	
346
fi
347
 
498 richard 348
# Autorisation des connections sortant du LAN  
476 richard 349
# Allow forward connections with log
1221 richard 350
#$IPTABLES -A FORWARD -i $TUNIF -s $PRIVATE_NETWORK_MASK -m state --state NEW -j ULOG --ulog-prefix "RULE F_all -- ACCEPT "
1159 crox53 351
$IPTABLES -A FORWARD -i $TUNIF -s $PRIVATE_NETWORK_MASK -m state --state NEW -j NETFLOW
859 richard 352
$IPTABLES -A FORWARD -i $TUNIF -s $PRIVATE_NETWORK_MASK -m state --state NEW -j ACCEPT
1 root 353
 
783 richard 354
#############################
355
#         OUTPUT            #
356
#############################
1159 crox53 357
# On laisse tout sortir sur toutes les cartes sauf celle qui est connectée sur l'extérieur
358
# Everything is allowed but traffic through outside network interface
498 richard 359
$IPTABLES -A OUTPUT ! -o $EXTIF -j ACCEPT
520 richard 360
 
503 richard 361
# On autorise les requêtes DNS vers les serveurs DNS identifiés 
498 richard 362
# Allow DNS requests to identified DNS servers
363
$IPTABLES -A OUTPUT -o $EXTIF -d $DNSSERVERS -p udp --dport domain -m state --state NEW -j ACCEPT
783 richard 364
 
615 richard 365
# On autorise les requêtes HTTP sortantes
498 richard 366
# HTTP requests are allowed
1159 crox53 367
$IPTABLES -A OUTPUT -o $EXTIF -p tcp --dport http -j NETFLOW
498 richard 368
$IPTABLES -A OUTPUT -o $EXTIF -p tcp --dport http -j ACCEPT
783 richard 369
 
784 richard 370
# On autorise les requêtes FTP 
371
# FTP requests are allowed
372
modprobe ip_conntrack_ftp
373
$IPTABLES -A OUTPUT -o $EXTIF -p tcp --dport ftp -j ACCEPT
1159 crox53 374
$IPTABLES -A OUTPUT -o $EXTIF -m state --state ESTABLISHED,RELATED -j ACCEPT
784 richard 375
 
615 richard 376
# On autorise les requêtes NTP 
498 richard 377
# NTP requests are allowed
378
$IPTABLES -A OUTPUT -o $EXTIF -p udp --dport ntp -j ACCEPT
783 richard 379
 
503 richard 380
# On autorise les requêtes ICMP (ping) 
381
# ICMP (ping) requests are allowed
382
$IPTABLES -A OUTPUT -o $EXTIF -p icmp --icmp-type 8 -j ACCEPT
783 richard 383
 
615 richard 384
# On autorise les requêtes LDAP si un serveur externe est configué
385
# LDAP requests are allowed if an external server is declared
386
if [ $LDAP = on ]
387
	then
694 franck 388
	$IPTABLES -A OUTPUT -p tcp -d $LDAP_IP -m multiport --dports ldap,ldaps -m state --state NEW,ESTABLISHED -j ACCEPT
389
	$IPTABLES -A OUTPUT -p udp -d $LDAP_IP -m multiport --dports ldap,ldaps -m state --state NEW,ESTABLISHED -j ACCEPT
615 richard 390
fi
783 richard 391
 
1159 crox53 392
 
783 richard 393
#############################
394
#       POSTROUTING         #
395
#############################
498 richard 396
# Traduction dynamique d'adresse en sortie
476 richard 397
# Dynamic NAT on EXTIF
1 root 398
$IPTABLES -A POSTROUTING -t nat -o $EXTIF -j MASQUERADE
399
 
476 richard 400
# Save all rules
1 root 401
/etc/init.d/iptables save
402
 
476 richard 403
# End of script
1 root 404