Subversion Repositories ALCASAR

Rev

Rev 2769 | Rev 2898 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log

Rev 2769 Rev 2770
1
#!/bin/bash
1
#!/bin/bash
2
 
2
 
3
# $Id: alcasar-bl.sh 2769 2019-11-24 22:31:36Z rexy $
3
# $Id: alcasar-bl.sh 2770 2020-02-11 23:06:07Z rexy $
4
 
4
 
5
# alcasar-bl.sh
5
# alcasar-bl.sh
6
# by Franck BOUIJOUX and Richard REY
6
# by Franck BOUIJOUX and Richard REY
7
# This script is distributed under the Gnu General Public License (GPL)
7
# This script is distributed under the Gnu General Public License (GPL)
8
 
8
 
9
# Gestion de la BL pour le filtrage de domaine (via unbound) et d'URL (via E2guardian)
9
# Gestion de la BL pour le filtrage de domaine (via unbound) et d'URL (via E2guardian)
10
# Manage the BL for domain filtering (with unbound) and URL filtering (with E2guardian)
10
# Manage the BL for domain filtering (with unbound) and URL filtering (with E2guardian)
11
 
11
 
12
DIR_CONF="/usr/local/etc"
12
DIR_CONF="/usr/local/etc"
13
CONF_FILE="$DIR_CONF/alcasar.conf"
13
CONF_FILE="$DIR_CONF/alcasar.conf"
14
private_ip_mask=`grep ^PRIVATE_IP= $CONF_FILE|cut -d"=" -f2`
14
private_ip_mask=`grep ^PRIVATE_IP= $CONF_FILE|cut -d"=" -f2`
15
private_ip_mask=${private_ip_mask:=192.168.182.1/24}
15
private_ip_mask=${private_ip_mask:=192.168.182.1/24}
16
DIR_tmp="/tmp/blacklists"
16
DIR_tmp="/tmp/blacklists"
17
FILE_tmp="/tmp/filesfilter.txt"
17
FILE_tmp="/tmp/filesfilter.txt"
18
FILE_ip_tmp="/tmp/filesipfilter.txt"
18
FILE_ip_tmp="/tmp/filesipfilter.txt"
19
DIR_DG="/etc/e2guardian/lists"
19
DIR_DG="/etc/e2guardian/lists"
20
DIR_DG_BL="$DIR_DG/blacklists"
20
DIR_DG_BL="$DIR_DG/blacklists"
21
GLOBAL_USAGE="$DIR_CONF/alcasar-global-usage"				# file containing the description of the lists
21
GLOBAL_USAGE="$DIR_CONF/alcasar-global-usage"				# file containing the description of the lists
22
BL_CATEGORIES="$DIR_CONF/alcasar-bl-categories"				# list of names of the 	BL categories
22
BL_CATEGORIES="$DIR_CONF/alcasar-bl-categories"				# list of names of the 	BL categories
23
WL_CATEGORIES="$DIR_CONF/alcasar-wl-categories"				#	'	'	WL categories
23
WL_CATEGORIES="$DIR_CONF/alcasar-wl-categories"				#	'	'	WL categories
24
BL_CATEGORIES_ENABLED="$DIR_CONF/alcasar-bl-categories-enabled"		#	'	'	BL enabled categories
24
BL_CATEGORIES_ENABLED="$DIR_CONF/alcasar-bl-categories-enabled"		#	'	'	BL enabled categories
25
WL_CATEGORIES_ENABLED="$DIR_CONF/alcasar-wl-categories-enabled"		#	'	'	WL enabled categories
25
WL_CATEGORIES_ENABLED="$DIR_CONF/alcasar-wl-categories-enabled"		#	'	'	WL enabled categories
26
DIR_SHARE="/usr/local/share"
26
DIR_SHARE="/usr/local/share"
27
DIR_DNS_BL="$DIR_SHARE/unbound-bl"					# all the BL in the Unbound format
27
DIR_DNS_BL="$DIR_SHARE/unbound-bl"					# all the BL in the Unbound format
28
DIR_DNS_WL="$DIR_SHARE/unbound-wl"					# all the WL	'	'	'
28
DIR_DNS_WL="$DIR_SHARE/unbound-wl"					# all the WL	'	'	'
29
DIR_IP_BL="$DIR_SHARE/iptables-bl"					# all the IP addresses of the BL
29
DIR_IP_BL="$DIR_SHARE/iptables-bl"					# all the IP addresses of the BL
30
DIR_IP_WL="$DIR_SHARE/iptables-wl"					# IP ossi disabled WL
30
DIR_IP_WL="$DIR_SHARE/iptables-wl"					# IP ossi disabled WL
31
DIR_DNS_BL_ENABLED="$DIR_SHARE/unbound-bl-enabled"			# symbolic link to the domains BL (only enabled categories)
31
DIR_DNS_BL_ENABLED="$DIR_SHARE/unbound-bl-enabled"			# symbolic link to the domains BL (only enabled categories)
32
DIR_DNS_WL_ENABLED="$DIR_SHARE/unbound-wl-enabled"			#	'	'	'	WL	'	'
32
DIR_DNS_WL_ENABLED="$DIR_SHARE/unbound-wl-enabled"			#	'	'	'	WL	'	'
33
DIR_IP_BL_ENABLED="$DIR_SHARE/iptables-bl-enabled"			#	'	'	ip BL (only enabled categories)
33
DIR_IP_BL_ENABLED="$DIR_SHARE/iptables-bl-enabled"			#	'	'	ip BL (only enabled categories)
34
DIR_IP_WL_ENABLED="$DIR_SHARE/iptables-wl-enabled"			#	'	'	ip WL (ossi and ossi-* imported from ACC)
34
DIR_IP_WL_ENABLED="$DIR_SHARE/iptables-wl-enabled"			#	'	'	ip WL (ossi and ossi-* imported from ACC)
35
REHABILITATED_DNS_FILE="/etc/unbound/conf.d/blacklist/rehabilitated.conf"
35
REHABILITATED_DNS_FILE="/etc/unbound/conf.d/blacklist/rehabilitated.conf"
36
CNC_BL_NAME="ossi-bl-candc"
-
 
37
BL_SERVER="dsi.ut-capitole.fr"
36
BL_SERVER="dsi.ut-capitole.fr"
38
SED="/bin/sed -i"
37
SED="/bin/sed -i"
39
 
38
 
40
# enable/disable the BL & WL categories
39
# enable/disable the BL & WL categories
41
function cat_choice (){
40
function cat_choice (){
42
	mkdir -p $DIR_tmp
41
	mkdir -p $DIR_tmp
43
	for LIST in $DIR_IP_BL_ENABLED $DIR_DNS_BL_ENABLED $DIR_IP_WL_ENABLED $DIR_DNS_WL_ENABLED
42
	for LIST in $DIR_IP_BL_ENABLED $DIR_DNS_BL_ENABLED $DIR_IP_WL_ENABLED $DIR_DNS_WL_ENABLED
44
	do
43
	do
45
		if [ ! -e $LIST ] #  only on install stage
44
		if [ ! -e $LIST ] #  only on install stage
46
		then
45
		then
47
			mkdir $LIST
46
			mkdir $LIST
48
		else
47
		else
49
			rm -rf ${LIST:?}/*
48
			rm -rf ${LIST:?}/*
50
		fi
49
		fi
51
		chown root:apache $LIST
50
		chown root:apache $LIST
52
		chmod 770 $LIST
51
		chmod 770 $LIST
53
	done
52
	done
54
	# update categories with rsync
53
	# update categories with rsync
55
	if [ ! -e $DIR_CONF/update_cat.conf ]
54
	if [ ! -e $DIR_CONF/update_cat.conf ]
56
	then
55
	then
57
		touch $DIR_CONF/update_cat.conf
56
		touch $DIR_CONF/update_cat.conf
58
		chown root:apache $DIR_CONF/update_cat.conf
57
		chown root:apache $DIR_CONF/update_cat.conf
59
		chmod 660 $DIR_CONF/update_cat.conf
58
		chmod 660 $DIR_CONF/update_cat.conf
60
	fi
59
	fi
61
	$SED "/\.Include/d" $DIR_DG/bannedsitelist $DIR_DG/bannedurllist # cleaning for DG
60
	$SED "/\.Include/d" $DIR_DG/bannedsitelist $DIR_DG/bannedurllist # cleaning for DG
62
	$SED "s?^[^#]?#&?g" $BL_CATEGORIES $WL_CATEGORIES # cleaning BL & WL categories file (comment all lines)
61
	$SED "s?^[^#]?#&?g" $BL_CATEGORIES $WL_CATEGORIES # cleaning BL & WL categories file (comment all lines)
63
 
62
 
64
	# process the file $BL_CATEGORIES with the choice of categories
63
	# process the file $BL_CATEGORIES with the choice of categories
65
	for ENABLE_CATEGORIE in `cat $BL_CATEGORIES_ENABLED`
64
	for ENABLE_CATEGORIE in `cat $BL_CATEGORIES_ENABLED`
66
	do
65
	do
67
		$SED "/\/$ENABLE_CATEGORIE$/d" $BL_CATEGORIES
66
		$SED "/\/$ENABLE_CATEGORIE$/d" $BL_CATEGORIES
68
		$SED "1i\/etc\/e2guardian\/lists\/blacklists\/$ENABLE_CATEGORIE" $BL_CATEGORIES
67
		$SED "1i\/etc\/e2guardian\/lists\/blacklists\/$ENABLE_CATEGORIE" $BL_CATEGORIES
69
		ln -sf $DIR_DNS_BL/$ENABLE_CATEGORIE.conf $DIR_DNS_BL_ENABLED/$ENABLE_CATEGORIE
68
		ln -sf $DIR_DNS_BL/$ENABLE_CATEGORIE.conf $DIR_DNS_BL_ENABLED/$ENABLE_CATEGORIE
70
		ln -sf $DIR_IP_BL/$ENABLE_CATEGORIE $DIR_IP_BL_ENABLED/$ENABLE_CATEGORIE
69
		ln -sf $DIR_IP_BL/$ENABLE_CATEGORIE $DIR_IP_BL_ENABLED/$ENABLE_CATEGORIE
71
		# echo ".Include<$DIR_DG_BL/$ENABLE_CATEGORIE/domains>" >> $DIR_DG/bannedsitelist  # Blacklisted domains are managed by unbound
70
		# echo ".Include<$DIR_DG_BL/$ENABLE_CATEGORIE/domains>" >> $DIR_DG/bannedsitelist  # Blacklisted domains are managed by unbound
72
		echo ".Include<$DIR_DG_BL/$ENABLE_CATEGORIE/urls>" >> $DIR_DG/bannedurllist
71
		echo ".Include<$DIR_DG_BL/$ENABLE_CATEGORIE/urls>" >> $DIR_DG/bannedurllist
73
	done
72
	done
74
	sort +0.0 -0.2 $BL_CATEGORIES -o $FILE_tmp
73
	sort +0.0 -0.2 $BL_CATEGORIES -o $FILE_tmp
75
	mv $FILE_tmp $BL_CATEGORIES
74
	mv $FILE_tmp $BL_CATEGORIES
76
	sort +0.0 -0.2 $BL_CATEGORIES_ENABLED -o $FILE_tmp
75
	sort +0.0 -0.2 $BL_CATEGORIES_ENABLED -o $FILE_tmp
77
	mv $FILE_tmp $BL_CATEGORIES_ENABLED
76
	mv $FILE_tmp $BL_CATEGORIES_ENABLED
78
	chown root:apache $BL_CATEGORIES $BL_CATEGORIES_ENABLED
77
	chown root:apache $BL_CATEGORIES $BL_CATEGORIES_ENABLED
79
	chmod 660 $BL_CATEGORIES $BL_CATEGORIES_ENABLED
78
	chmod 660 $BL_CATEGORIES $BL_CATEGORIES_ENABLED
80
 
79
 
81
# process the file $WL_CATEGORIES with the choice of categories
80
# process the file $WL_CATEGORIES with the choice of categories
82
	for ENABLE_CATEGORIE in `cat $WL_CATEGORIES_ENABLED`
81
	for ENABLE_CATEGORIE in `cat $WL_CATEGORIES_ENABLED`
83
	do
82
	do
84
		$SED "/\/$ENABLE_CATEGORIE$/d" $WL_CATEGORIES
83
		$SED "/\/$ENABLE_CATEGORIE$/d" $WL_CATEGORIES
85
		$SED "1i\/etc\/e2guardian\/lists\/blacklists\/$ENABLE_CATEGORIE" $WL_CATEGORIES
84
		$SED "1i\/etc\/e2guardian\/lists\/blacklists\/$ENABLE_CATEGORIE" $WL_CATEGORIES
86
		ln -sf $DIR_DNS_WL/$ENABLE_CATEGORIE.conf $DIR_DNS_WL_ENABLED/$ENABLE_CATEGORIE
85
		ln -sf $DIR_DNS_WL/$ENABLE_CATEGORIE.conf $DIR_DNS_WL_ENABLED/$ENABLE_CATEGORIE
87
	done
86
	done
88
	sort +0.0 -0.2 $WL_CATEGORIES -o $FILE_tmp
87
	sort +0.0 -0.2 $WL_CATEGORIES -o $FILE_tmp
89
	mv $FILE_tmp $WL_CATEGORIES
88
	mv $FILE_tmp $WL_CATEGORIES
90
	sort +0.0 -0.2 $WL_CATEGORIES_ENABLED -o $FILE_tmp
89
	sort +0.0 -0.2 $WL_CATEGORIES_ENABLED -o $FILE_tmp
91
	mv $FILE_tmp $WL_CATEGORIES_ENABLED
90
	mv $FILE_tmp $WL_CATEGORIES_ENABLED
92
	chown root:apache $WL_CATEGORIES $WL_CATEGORIES_ENABLED
91
	chown root:apache $WL_CATEGORIES $WL_CATEGORIES_ENABLED
93
	chmod 660 $WL_CATEGORIES $WL_CATEGORIES_ENABLED
92
	chmod 660 $WL_CATEGORIES $WL_CATEGORIES_ENABLED
94
}
93
}
95
 
94
 
96
# cleaning file and split it ("domains" in $FILE_tmp & "IP" in $FILE_ip_tmp)
95
# cleaning file and split it ("domains" in $FILE_tmp & "IP" in $FILE_ip_tmp)
97
function clean_split (){
96
function clean_split (){
98
	$SED '/^#.*/d' $FILE_tmp # remove commented lines
97
	$SED '/^#.*/d' $FILE_tmp # remove commented lines
99
	$SED '/^\s*$/d' $FILE_tmp # remove empty lines
98
	$SED '/^\s*$/d' $FILE_tmp # remove empty lines
100
	$SED '/[äâëêïîöôüû@,]/d' $FILE_tmp # remove line with "chelou" characters
99
	$SED '/[äâëêïîöôüû@,]/d' $FILE_tmp # remove line with "chelou" characters
101
	# extract ip addresses for iptables.
100
	# extract ip addresses for iptables.
102
	awk '/^([0-9]{1,3}\.){3}[0-9]{1,3}$/{print "add bl_ip_blocked " $0}' $FILE_tmp > $FILE_ip_tmp
101
	awk '/^([0-9]{1,3}\.){3}[0-9]{1,3}$/{print "add bl_ip_blocked " $0}' $FILE_tmp > $FILE_ip_tmp
103
	# extract domain names for unbound.
102
	# extract domain names for unbound.
104
	$SED -n '/^\([0-9]\{1,3\}\.\)\{3\}[0-9]\{1,3\}/!p' $FILE_tmp
103
	$SED -n '/^\([0-9]\{1,3\}\.\)\{3\}[0-9]\{1,3\}/!p' $FILE_tmp
105
	# Retrieve max Top Level Domain for domain name synthax
104
	# Retrieve max Top Level Domain for domain name synthax
106
	#MAX_TLD=$(curl http://data.iana.org/TLD/tlds-alpha-by-domain.txt | grep -v '-' | grep -v '#' | wc -L)
105
	#MAX_TLD=$(curl http://data.iana.org/TLD/tlds-alpha-by-domain.txt | grep -v '-' | grep -v '#' | wc -L)
107
	#if [ $(echo $MAX_TLD | wc -c) -eq 0 ];then
106
	#if [ $(echo $MAX_TLD | wc -c) -eq 0 ];then
108
	#	MAX_TLD=18
107
	#	MAX_TLD=18
109
	#fi
108
	#fi
110
	# search for correction	egrep "([a-zA-Z0-9_-.]+\.){1,2}[a-zA-Z]{2,$MAX_TLD}" $ossi_custom_dir/domains > $FILE_tmp
109
	# search for correction	egrep "([a-zA-Z0-9_-.]+\.){1,2}[a-zA-Z]{2,$MAX_TLD}" $ossi_custom_dir/domains > $FILE_tmp
111
}
110
}
112
 
111
 
113
usage="Usage: alcasar-bl.sh { -cat_choice or --cat_choice } | { -download or --download } | { -adapt or --adapt } | { -reload or --reload } | { -install_ossi_candc or --install_ossi_candc }"
112
usage="Usage: alcasar-bl.sh { -cat_choice or --cat_choice } | { -download or --download } | { -adapt or --adapt } | { -reload or --reload }"
114
nb_args=$#
113
nb_args=$#
115
args=$1
114
args=$1
116
if [ $nb_args -eq 0 ]
115
if [ $nb_args -eq 0 ]
117
then
116
then
118
	args="-h"
117
	args="-h"
119
fi
118
fi
120
case $args in
119
case $args in
121
	-\? | -h* | --h*)
120
	-\? | -h* | --h*)
122
		echo "$usage"
121
		echo "$usage"
123
		exit 0
122
		exit 0
124
		;;
123
		;;
125
	# Retrieve Toulouse University BL
124
	# Retrieve Toulouse University BL
126
	-download | --download)
125
	-download | --download)
127
		rm -rf /tmp/con_ok.html
126
		rm -rf /tmp/con_ok.html
128
		`/usr/bin/curl $BL_SERVER -# -o /tmp/con_ok.html`
127
		`/usr/bin/curl $BL_SERVER -# -o /tmp/con_ok.html`
129
		if [ ! -e /tmp/con_ok.html ]
128
		if [ ! -e /tmp/con_ok.html ]
130
		then
129
		then
131
			echo "Erreur : le serveur de blacklist ($BL_SERVER) n'est pas joignable"
130
			echo "Erreur : le serveur de blacklist ($BL_SERVER) n'est pas joignable"
132
		else
131
		else
133
			rm -rf /tmp/con_ok.html $DIR_tmp
132
			rm -rf /tmp/con_ok.html $DIR_tmp
134
			mkdir $DIR_tmp
133
			mkdir $DIR_tmp
135
			wget -P $DIR_tmp http://$BL_SERVER/blacklists/download/blacklists.tar.gz
134
			wget -P $DIR_tmp http://$BL_SERVER/blacklists/download/blacklists.tar.gz
136
			md5sum $DIR_tmp/blacklists.tar.gz | cut -d" " -f1 > $DIR_tmp/md5sum
135
			md5sum $DIR_tmp/blacklists.tar.gz | cut -d" " -f1 > $DIR_tmp/md5sum
137
			chown -R apache:apache $DIR_tmp
136
			chown -R apache:apache $DIR_tmp
138
		fi
137
		fi
139
		;;
138
		;;
140
	# enable/disable categories (used only during the alcasar install process)
139
	# enable/disable categories (used only during the alcasar install process)
141
	-cat_choice | --cat_choice)
140
	-cat_choice | --cat_choice)
142
		cat_choice
141
		cat_choice
143
		;;
142
		;;
144
	# Adapt Toulouse University BL to ALCASAR architecture (unbound + DG + iptables)
143
	# Adapt Toulouse University BL to ALCASAR architecture (unbound + DG + iptables)
145
	-adapt | --adapt)
144
	-adapt | --adapt)
146
		echo -n "Adaptation process of Toulouse University blackList. Please wait : "
145
		echo -n "Adaptation process of Toulouse University blackList. Please wait : "
147
		if [ -f $DIR_tmp/blacklists.tar.gz ] # when downloading the last version of the BL
146
		if [ -f $DIR_tmp/blacklists.tar.gz ] # when downloading the last version of the BL
148
		then
147
		then
149
			# keep custom files (ossi)
148
			# keep custom files (ossi)
150
			for x in $(ls -1 $DIR_DG_BL | grep "^ossi-*")
149
			for x in $(ls -1 $DIR_DG_BL | grep "^ossi-*")
151
			do
150
			do
152
				mv $DIR_DG_BL/$x $DIR_tmp
151
				mv $DIR_DG_BL/$x $DIR_tmp
153
			done
152
			done
154
			rm -rf $DIR_DG_BL $DIR_IP_BL
153
			rm -rf $DIR_DG_BL $DIR_IP_BL
155
			mkdir $DIR_DG_BL $DIR_IP_BL
154
			mkdir $DIR_DG_BL $DIR_IP_BL
156
			tar zxf $DIR_tmp/blacklists.tar.gz --directory=$DIR_DG/
155
			tar zxf $DIR_tmp/blacklists.tar.gz --directory=$DIR_DG/
157
			# replace the global_usage file of the archive
156
			# replace the global_usage file of the archive
158
			cp -f $GLOBAL_USAGE $DIR_DG_BL/global_usage
157
			cp -f $GLOBAL_USAGE $DIR_DG_BL/global_usage
159
			chown -R e2guardian:apache $DIR_DG
158
			chown -R e2guardian:apache $DIR_DG
160
			chmod -R 770 $DIR_DG
159
			chmod -R 770 $DIR_DG
161
			# Add the two local categories (ossi-bl & ossi-wl) to the usage file
160
			# Add the two local categories (ossi-bl & ossi-wl) to the usage file
162
			# Add the custom categories (ossi-tor_nodes) to the usage file
161
			# Add the custom categories (ossi-tor_nodes) to the usage file
163
			cat <<EOF >> $DIR_DG_BL/global_usage
162
			cat <<EOF >> $DIR_DG_BL/global_usage
164
 
163
 
165
NAME: ossi-bl
164
NAME: ossi-bl
166
DEFAULT_TYPE: black
165
DEFAULT_TYPE: black
167
SOURCE: ALCASAR Team
166
SOURCE: ALCASAR Team
168
DESC FR: sites blacklistés ajoutés localement
167
DESC FR: sites blacklistés ajoutés localement
169
DESC EN: blacklisted sites add locally
168
DESC EN: blacklisted sites add locally
170
NAME FR: ossi-bl
169
NAME FR: ossi-bl
171
NAME EN: ossi-bl
170
NAME EN: ossi-bl
172
 
171
 
173
NAME: ossi-wl
172
NAME: ossi-wl
174
DEFAULT_TYPE: white
173
DEFAULT_TYPE: white
175
SOURCE: ALCASAR Team
174
SOURCE: ALCASAR Team
176
DESC FR: sites autorisés ajoutés localement
175
DESC FR: sites autorisés ajoutés localement
177
DESC EN: whitelisted sites add locally
176
DESC EN: whitelisted sites add locally
178
NAME FR: ossi-wl
177
NAME FR: ossi-wl
179
NAME EN: ossi-wl
178
NAME EN: ossi-wl
180
 
179
 
181
NAME: ossi-bl-tor_nodes
180
NAME: ossi-bl-tor_nodes
182
DEFAULT_TYPE: black
181
DEFAULT_TYPE: black
183
SOURCE: ALCASAR Team
182
SOURCE: ALCASAR Team
184
DESC FR: Adresses IP des noeuds (routeurs) d'entrée du réseau TOR
183
DESC FR: Adresses IP des noeuds (routeurs) d'entrée du réseau TOR
185
DESC EN: IP addresses of input TOR nodes (routers)
184
DESC EN: IP addresses of input TOR nodes (routers)
186
NAME FR: Noeuds TOR
185
NAME FR: Noeuds TOR
187
NAME EN: TOR nodes
186
NAME EN: TOR nodes
188
 
187
 
189
NAME: ossi-bl-ultrasurf
188
NAME: ossi-bl-ultrasurf
190
DEFAULT_TYPE: black
189
DEFAULT_TYPE: black
191
SOURCE: ALCASAR Team
190
SOURCE: ALCASAR Team
192
DESC FR: Adresses IP des point de sortie ULTRASURF
191
DESC FR: Adresses IP des point de sortie ULTRASURF
193
DESC EN: IP addresses of output points of ULTRASURF
192
DESC EN: IP addresses of output points of ULTRASURF
194
NAME FR: Points de sortie ULTRASURF
193
NAME FR: Points de sortie ULTRASURF
195
NAME EN: ULTRASURF output points
194
NAME EN: ULTRASURF output points
196
 
195
 
197
NAME: ossi-bl-candc
196
NAME: ossi-bl-candc
198
DEFAULT_TYPE: black
197
DEFAULT_TYPE: black
199
SOURCE: Bambenek Consulting: https://osint.bambenekconsulting.com
198
SOURCE: Bambenek Consulting: https://osint.bambenekconsulting.com
200
DESC FR: liste des URLs et IPs des serveurs command & control
199
DESC FR: liste des URLs et IPs des serveurs command & control
201
DESC EN: list of URLs and IPs of command & control servers
200
DESC EN: list of URLs and IPs of command & control servers
202
NAME FR: Serveurs Command & Control
201
NAME FR: Serveurs Command & Control
203
NAME EN: Command & Control Server
202
NAME EN: Command & Control Server
204
 
203
 
205
EOF
204
EOF
206
# Retrieve custom files (ossi)
205
# Retrieve custom files (ossi)
207
			for x in $(ls -1 $DIR_tmp | grep "^ossi-*")
206
			for x in $(ls -1 $DIR_tmp | grep "^ossi-*")
208
			do
207
			do
209
				mv $DIR_tmp/$x $DIR_DG_BL
208
				mv $DIR_tmp/$x $DIR_DG_BL
210
			done
209
			done
211
		fi
210
		fi
212
		rm -f $BL_CATEGORIES $WL_CATEGORIES
211
		rm -f $BL_CATEGORIES $WL_CATEGORIES
213
		rm -rf $DIR_DNS_BL $DIR_DNS_WL $DIR_IP_BL $DIR_IP_WL
212
		rm -rf $DIR_DNS_BL $DIR_DNS_WL $DIR_IP_BL $DIR_IP_WL
214
		rm -rf $DIR_DNS_BL_ENABLED $DIR_DNS_WL_ENABLED $DIR_IP_BL_ENABLED $DIR_IP_WL_ENABLED
213
		rm -rf $DIR_DNS_BL_ENABLED $DIR_DNS_WL_ENABLED $DIR_IP_BL_ENABLED $DIR_IP_WL_ENABLED
215
		touch $BL_CATEGORIES $WL_CATEGORIES
214
		touch $BL_CATEGORIES $WL_CATEGORIES
216
		mkdir $DIR_DNS_BL $DIR_DNS_WL $DIR_IP_BL $DIR_IP_WL
215
		mkdir $DIR_DNS_BL $DIR_DNS_WL $DIR_IP_BL $DIR_IP_WL
217
		mkdir $DIR_DNS_BL_ENABLED $DIR_DNS_WL_ENABLED $DIR_IP_BL_ENABLED $DIR_IP_WL_ENABLED
216
		mkdir $DIR_DNS_BL_ENABLED $DIR_DNS_WL_ENABLED $DIR_IP_BL_ENABLED $DIR_IP_WL_ENABLED
218
		find $DIR_DG_BL/ -type f -name domains > $FILE_tmp # retrieve directory name where a domain file exist
217
		find $DIR_DG_BL/ -type f -name domains > $FILE_tmp # retrieve directory name where a domain file exist
219
		$SED "s?\/domains??g" $FILE_tmp # remove "/domains" suffix
218
		$SED "s?\/domains??g" $FILE_tmp # remove "/domains" suffix
220
		for dir_categorie in `cat $FILE_tmp` # create the blacklist and the whitelist files
219
		for dir_categorie in `cat $FILE_tmp` # create the blacklist and the whitelist files
221
		do
220
		do
222
			categorie=`echo $dir_categorie|cut -d "/" -f6`
221
			categorie=`echo $dir_categorie|cut -d "/" -f6`
223
			categorie_type=`grep -A1 ^NAME:[$' '$'\t']*$categorie\$ $DIR_DG_BL/global_usage | grep ^DEFAULT_TYPE | cut -d":" -f2 | tr -d " \t"`
222
			categorie_type=`grep -A1 ^NAME:[$' '$'\t']*$categorie\$ $DIR_DG_BL/global_usage | grep ^DEFAULT_TYPE | cut -d":" -f2 | tr -d " \t"`
224
			if [ "$categorie_type" == "white" ]
223
			if [ "$categorie_type" == "white" ]
225
			then
224
			then
226
				echo "$dir_categorie" >> $WL_CATEGORIES
225
				echo "$dir_categorie" >> $WL_CATEGORIES
227
			else
226
			else
228
				echo "$dir_categorie" >> $BL_CATEGORIES
227
				echo "$dir_categorie" >> $BL_CATEGORIES
229
			fi
228
			fi
230
		done
229
		done
231
		rm -f $FILE_tmp
230
		rm -f $FILE_tmp
232
		# Verify that the enabled categories are effectively in the BL (need after an update of the BL)
231
		# Verify that the enabled categories are effectively in the BL (need after an update of the BL)
233
		for ENABLE_CATEGORIE in `cat $BL_CATEGORIES_ENABLED`
232
		for ENABLE_CATEGORIE in `cat $BL_CATEGORIES_ENABLED`
234
		do
233
		do
235
			ok=`grep /$ENABLE_CATEGORIE$ $BL_CATEGORIES|wc -l`
234
			ok=`grep /$ENABLE_CATEGORIE$ $BL_CATEGORIES|wc -l`
236
			if [ $ok != "1" ]
235
			if [ $ok != "1" ]
237
			then
236
			then
238
				$SED "/^$ENABLE_CATEGORIE$/d" $BL_CATEGORIES_ENABLED
237
				$SED "/^$ENABLE_CATEGORIE$/d" $BL_CATEGORIES_ENABLED
239
			fi
238
			fi
240
		done
239
		done
241
		# Verify that the enabled categories are effectively in the WL (need after an update of the WL)
240
		# Verify that the enabled categories are effectively in the WL (need after an update of the WL)
242
		for ENABLE_CATEGORIE in `cat $WL_CATEGORIES_ENABLED`
241
		for ENABLE_CATEGORIE in `cat $WL_CATEGORIES_ENABLED`
243
		do
242
		do
244
			ok=`grep /$ENABLE_CATEGORIE$ $WL_CATEGORIES|wc -l`
243
			ok=`grep /$ENABLE_CATEGORIE$ $WL_CATEGORIES|wc -l`
245
			if [ $ok != "1" ]
244
			if [ $ok != "1" ]
246
			then
245
			then
247
				$SED "/^$ENABLE_CATEGORIE$/d" $WL_CATEGORIES_ENABLED
246
				$SED "/^$ENABLE_CATEGORIE$/d" $WL_CATEGORIES_ENABLED
248
			fi
247
			fi
249
		done
248
		done
250
 
249
 
251
		# Creation of Unbound and Iptables BL and WL
250
		# Creation of Unbound and Iptables BL and WL
252
		for LIST in $BL_CATEGORIES $WL_CATEGORIES	# for each list (bl and wl)
251
		for LIST in $BL_CATEGORIES $WL_CATEGORIES	# for each list (bl and wl)
253
		do
252
		do
254
			for PATH_FILE in `cat $LIST` # for each category
253
			for PATH_FILE in `cat $LIST` # for each category
255
			do
254
			do
256
				DOMAIN=`basename $PATH_FILE`
255
				DOMAIN=`basename $PATH_FILE`
257
				echo -n "$DOMAIN, "
256
				echo -n "$DOMAIN, "
258
				if [ ! -f $PATH_FILE/urls ] # create 'urls' file if it doesn't exist
257
				if [ ! -f $PATH_FILE/urls ] # create 'urls' file if it doesn't exist
259
				then
258
				then
260
					touch $PATH_FILE/urls
259
					touch $PATH_FILE/urls
261
					chown e2guardian:apache $PATH_FILE/urls
260
					chown e2guardian:apache $PATH_FILE/urls
262
				fi
261
				fi
263
				cp $PATH_FILE/domains $FILE_tmp
262
				cp $PATH_FILE/domains $FILE_tmp
264
				clean_split # clean ossi custom files & split them for unbound and for iptables
263
				clean_split # clean ossi custom files & split them for unbound and for iptables
265
				if [ "$LIST" == "$BL_CATEGORIES" ]
264
				if [ "$LIST" == "$BL_CATEGORIES" ]
266
				then
265
				then
267
					# adapt to the unbound syntax for the blacklist
266
					# adapt to the unbound syntax for the blacklist
268
					$SED "s?.*?local-zone: & typetransparent\nlocal-zone-tag: & blacklist?g" $FILE_tmp
267
					$SED "s?.*?local-zone: & typetransparent\nlocal-zone-tag: & blacklist?g" $FILE_tmp
269
					mv $FILE_tmp $DIR_DNS_BL/$DOMAIN.conf
268
					mv $FILE_tmp $DIR_DNS_BL/$DOMAIN.conf
270
					mv $FILE_ip_tmp $DIR_IP_BL/$DOMAIN
269
					mv $FILE_ip_tmp $DIR_IP_BL/$DOMAIN
271
				else
270
				else
272
					# adapt to the unbound syntax for the whitelist
271
					# adapt to the unbound syntax for the whitelist
273
					$SED "s?.*?local-zone: & transparent?g" $FILE_tmp
272
					$SED "s?.*?local-zone: & transparent?g" $FILE_tmp
274
					mv $FILE_tmp $DIR_DNS_WL/$DOMAIN.conf
273
					mv $FILE_tmp $DIR_DNS_WL/$DOMAIN.conf
275
				fi
274
				fi
276
			done
275
			done
277
		done
276
		done
278
		echo
277
		echo
279
		chown -R root:apache $BL_CATEGORIES $WL_CATEGORIES $BL_CATEGORIES_ENABLED $WL_CATEGORIES_ENABLED $DIR_DNS_BL $DIR_DNS_WL $DIR_IP_BL $DIR_IP_WL
278
		chown -R root:apache $BL_CATEGORIES $WL_CATEGORIES $BL_CATEGORIES_ENABLED $WL_CATEGORIES_ENABLED $DIR_DNS_BL $DIR_DNS_WL $DIR_IP_BL $DIR_IP_WL
280
		chmod 770 $DIR_DNS_BL $DIR_DNS_WL $DIR_IP_BL $DIR_IP_WL
279
		chmod 770 $DIR_DNS_BL $DIR_DNS_WL $DIR_IP_BL $DIR_IP_WL
281
		chmod -f 660 $BL_CATEGORIES $WL_CATEGORIES $BL_CATEGORIES_ENABLED $WL_CATEGORIES_ENABLED $DIR_DNS_BL/* $DIR_DNS_WL/* $DIR_IP_BL/* $DIR_IP_WL/*
280
		chmod -f 660 $BL_CATEGORIES $WL_CATEGORIES $BL_CATEGORIES_ENABLED $WL_CATEGORIES_ENABLED $DIR_DNS_BL/* $DIR_DNS_WL/* $DIR_IP_BL/* $DIR_IP_WL/*
282
		rm -f $FILE_tmp $FILE_ip_tmp
281
		rm -f $FILE_tmp $FILE_ip_tmp
283
		rm -rf $DIR_tmp
282
		rm -rf $DIR_tmp
284
		;;
283
		;;
285
    # install C&C-Server Blacklist.
-
 
286
    -install_ossi_candc | --install_ossi_candc)
-
 
287
        ## download
-
 
288
        /usr/local/bin/alcasar-bl-autoupdate.sh --update_ossi-bl-candc
-
 
289
        ## enable blacklist by default by creating symlinks
-
 
290
        if [ -e ${DIR_DNS_BL_ENABLED}/${CNC_BL_NAME} ]; then
-
 
291
		    rm ${DIR_DNS_BL_ENABLED}/${CNC_BL_NAME}
-
 
292
	    fi
-
 
293
	    if [ -e ${DIR_IP_BL_ENABLED}/${CNC_BL_NAME} ]; then
-
 
294
		    rm ${DIR_IP_BL_ENABLED}/${CNC_BL_NAME}
-
 
295
	    fi
-
 
296
 		echo "Creating symlinks to enable blacklist"
-
 
297
        ln -s ${DIR_DNS_BL}/${CNC_BL_NAME}.conf ${DIR_DNS_BL_ENABLED}/${CNC_BL_NAME}
-
 
298
        ln -s ${DIR_IP_BL}/${CNC_BL_NAME} ${DIR_IP_BL_ENABLED}/${CNC_BL_NAME}
-
 
299
		exit 0
-
 
300
		;;
-
 
301
	# reload when selected categories are changed or when ossi change his custom files
284
	# reload when selected categories are changed or when ossi change his custom files
302
	-reload | --reload)
285
	-reload | --reload)
303
		# for E2Gardian
286
		# for E2Gardian
304
		cat_choice
287
		cat_choice
305
		#  for unbound (rehabilitated domain names)
288
		#  for unbound (rehabilitated domain names)
306
		rm -f $REHABILITATED_DNS_FILE
289
		rm -f $REHABILITATED_DNS_FILE
307
		if [ "$(wc -w $DIR_DG/exceptionsitelist | cut -d " " -f1)" != "0" ]
290
		if [ "$(wc -w $DIR_DG/exceptionsitelist | cut -d " " -f1)" != "0" ]
308
		then
291
		then
309
			touch $REHABILITATED_DNS_FILE
292
			touch $REHABILITATED_DNS_FILE
310
			while read -r domain; do
293
			while read -r domain; do
311
				[ -z "$domain" ] && continue
294
				[ -z "$domain" ] && continue
312
				echo "local-zone: $domain typetransparent" >> $REHABILITATED_DNS_FILE
295
				echo "local-zone: $domain typetransparent" >> $REHABILITATED_DNS_FILE
313
				echo "local-zone-tag: $domain \"\"" >> $REHABILITATED_DNS_FILE
296
				echo "local-zone-tag: $domain \"\"" >> $REHABILITATED_DNS_FILE
314
			done < $DIR_DG/exceptionsitelist
297
			done < $DIR_DG/exceptionsitelist
315
		fi
298
		fi
316
		# adapt OSSI BL & WL custom files
299
		# adapt OSSI BL & WL custom files
317
		for dir in $DIR_DNS_BL_ENABLED $DIR_DNS_WL_ENABLED $DIR_IP_BL_ENABLED $DIR_IP_WL_ENABLED $DIR_DNS_BL $DIR_DNS_WL $DIR_IP_BL $DIR_IP_WL
300
		for dir in $DIR_DNS_BL_ENABLED $DIR_DNS_WL_ENABLED $DIR_IP_BL_ENABLED $DIR_IP_WL_ENABLED $DIR_DNS_BL $DIR_DNS_WL $DIR_IP_BL $DIR_IP_WL
318
		do
301
		do
319
			rm -f $dir/ossi*
302
			rm -f $dir/ossi*
320
		done
303
		done
321
		find $DIR_DG_BL/ -type f -name domains | grep ossi- > $FILE_tmp # retrieve ossi directories name where a domain file exist
304
		find $DIR_DG_BL/ -type f -name domains | grep ossi- > $FILE_tmp # retrieve ossi directories name where a domain file exist
322
		$SED "s?\/domains??g" $FILE_tmp # remove "/domains" suffix
305
		$SED "s?\/domains??g" $FILE_tmp # remove "/domains" suffix
323
		for ossi_custom_dir in `cat $FILE_tmp` # create the blacklist and the whitelist files
306
		for ossi_custom_dir in `cat $FILE_tmp` # create the blacklist and the whitelist files
324
		do
307
		do
325
			chown -R root:apache $ossi_custom_dir
308
			chown -R root:apache $ossi_custom_dir
326
			chmod 770 $ossi_custom_dir
309
			chmod 770 $ossi_custom_dir
327
			ossi_categorie=`echo $ossi_custom_dir|cut -d "/" -f6`
310
			ossi_categorie=`echo $ossi_custom_dir|cut -d "/" -f6`
328
			short_categorie=`echo "$ossi_categorie" | cut -d"-" -f2`
311
			short_categorie=`echo "$ossi_categorie" | cut -d"-" -f2`
329
			if [ $short_categorie == "bl" ]
312
			if [ $short_categorie == "bl" ]
330
			then
313
			then
331
				categorie_type="black"
314
				categorie_type="black"
332
			else
315
			else
333
				categorie_type="white"
316
				categorie_type="white"
334
			fi
317
			fi
335
			$SED "s/\r//" $ossi_custom_dir/domains $ossi_custom_dir/urls # remove Windows <CR> from custom file
318
			$SED "s/\r//" $ossi_custom_dir/domains $ossi_custom_dir/urls # remove Windows <CR> from custom file
336
			cp $ossi_custom_dir/domains $FILE_tmp
319
			cp $ossi_custom_dir/domains $FILE_tmp
337
			clean_split # clean ossi custom files & split them for unbound and for iptables
320
			clean_split # clean ossi custom files & split them for unbound and for iptables
338
			if [ $categorie_type == "white" ]
321
			if [ $categorie_type == "white" ]
339
			then
322
			then
340
			# adapt the file to the unbound syntax and enable it if needed
323
			# adapt the file to the unbound syntax and enable it if needed
341
			# for the WL
324
			# for the WL
342
				$SED "s?.*?local-zone: & transparent?g" $FILE_tmp
325
				$SED "s?.*?local-zone: & transparent?g" $FILE_tmp
343
				mv $FILE_tmp $DIR_DNS_WL/$ossi_categorie.conf
326
				mv $FILE_tmp $DIR_DNS_WL/$ossi_categorie.conf
344
				mv $FILE_ip_tmp $DIR_IP_WL/$ossi_categorie
327
				mv $FILE_ip_tmp $DIR_IP_WL/$ossi_categorie
345
				enabled=`grep ^$ossi_categorie$ $WL_CATEGORIES_ENABLED | wc -l`
328
				enabled=`grep ^$ossi_categorie$ $WL_CATEGORIES_ENABLED | wc -l`
346
				if [ $enabled == "1" ]
329
				if [ $enabled == "1" ]
347
				then
330
				then
348
					$SED "/\/$ossi_categorie$/d" $WL_CATEGORIES
331
					$SED "/\/$ossi_categorie$/d" $WL_CATEGORIES
349
					$SED "1i\/etc\/e2guardian\/lists\/blacklists\/$ossi_categorie" $WL_CATEGORIES
332
					$SED "1i\/etc\/e2guardian\/lists\/blacklists\/$ossi_categorie" $WL_CATEGORIES
350
					ln -sf $DIR_DNS_WL/$ossi_categorie.conf $DIR_DNS_WL_ENABLED/$ossi_categorie
333
					ln -sf $DIR_DNS_WL/$ossi_categorie.conf $DIR_DNS_WL_ENABLED/$ossi_categorie
351
					ln -sf $DIR_IP_WL/$ossi_categorie $DIR_IP_WL_ENABLED/$ossi_categorie
334
					ln -sf $DIR_IP_WL/$ossi_categorie $DIR_IP_WL_ENABLED/$ossi_categorie
352
				fi
335
				fi
353
			else
336
			else
354
			# for the BL
337
			# for the BL
355
				$SED "s?.*?local-zone: & typetransparent\nlocal-zone-tag: & blacklist?g" $FILE_tmp
338
				$SED "s?.*?local-zone: & typetransparent\nlocal-zone-tag: & blacklist?g" $FILE_tmp
356
				mv $FILE_tmp $DIR_DNS_BL/$ossi_categorie.conf
339
				mv $FILE_tmp $DIR_DNS_BL/$ossi_categorie.conf
357
				mv $FILE_ip_tmp $DIR_IP_BL/$ossi_categorie
340
				mv $FILE_ip_tmp $DIR_IP_BL/$ossi_categorie
358
				enabled=`grep ^$ossi_categorie$ $BL_CATEGORIES_ENABLED | wc -l`
341
				enabled=`grep ^$ossi_categorie$ $BL_CATEGORIES_ENABLED | wc -l`
359
				if [ $enabled == "1" ]
342
				if [ $enabled == "1" ]
360
				then
343
				then
361
					$SED "/\/$ossi_categorie$/d" $BL_CATEGORIES
344
					$SED "/\/$ossi_categorie$/d" $BL_CATEGORIES
362
					$SED "1i\/etc\/e2guardian\/lists\/blacklists\/$ossi_categorie" $BL_CATEGORIES
345
					$SED "1i\/etc\/e2guardian\/lists\/blacklists\/$ossi_categorie" $BL_CATEGORIES
363
					ln -sf $DIR_DNS_BL/$ossi_categorie.conf $DIR_DNS_BL_ENABLED/$ossi_categorie
346
					ln -sf $DIR_DNS_BL/$ossi_categorie.conf $DIR_DNS_BL_ENABLED/$ossi_categorie
364
					ln -sf $DIR_IP_BL/$ossi_categorie $DIR_IP_BL_ENABLED/$ossi_categorie
347
					ln -sf $DIR_IP_BL/$ossi_categorie $DIR_IP_BL_ENABLED/$ossi_categorie
365
				fi
348
				fi
366
			fi
349
			fi
367
		done
350
		done
368
		for file in $BL_CATEGORIES $BL_CATEGORIES_ENABLED $WL_CATEGORIES $WL_CATEGORIES_ENABLED
351
		for file in $BL_CATEGORIES $BL_CATEGORIES_ENABLED $WL_CATEGORIES $WL_CATEGORIES_ENABLED
369
		do
352
		do
370
			sort +0.0 -0.2 $file -o $FILE_tmp
353
			sort +0.0 -0.2 $file -o $FILE_tmp
371
			mv $FILE_tmp $file
354
			mv $FILE_tmp $file
372
			chown root:apache $file
355
			chown root:apache $file
373
			chmod 660 $file
356
			chmod 660 $file
374
		done
357
		done
375
		chown -R root:apache $DIR_DNS_BL $DIR_DNS_WL $DIR_IP_BL $DIR_IP_WL
358
		chown -R root:apache $DIR_DNS_BL $DIR_DNS_WL $DIR_IP_BL $DIR_IP_WL
376
		chmod 660 $DIR_DNS_BL/* $DIR_DNS_WL/* $DIR_IP_BL/* $DIR_IP_WL/*
359
		chmod 660 $DIR_DNS_BL/* $DIR_DNS_WL/* $DIR_IP_BL/* $DIR_IP_WL/*
377
		if [ "$PARENT_SCRIPT" != "alcasar-conf.sh" ] # don't launch on install stage
360
		if [ "$PARENT_SCRIPT" != "alcasar-conf.sh" ] # don't launch on install stage
378
		then
361
		then
379
			/usr/bin/systemctl restart unbound-blacklist
362
			/usr/bin/systemctl restart unbound-blacklist
380
			/usr/bin/systemctl restart unbound-whitelist
363
			/usr/bin/systemctl restart unbound-whitelist
381
			/usr/bin/systemctl restart dnsmasq-whitelist
364
			/usr/bin/systemctl restart dnsmasq-whitelist
382
			/usr/bin/systemctl restart e2guardian
365
			/usr/bin/systemctl restart e2guardian
383
			/usr/local/bin/alcasar-iptables.sh
366
			/usr/local/bin/alcasar-iptables.sh
384
		fi
367
		fi
385
		;;
368
		;;
386
	*)
369
	*)
387
		echo "Argument inconnu :$1";
370
		echo "Argument inconnu :$1";
388
		echo "$usage"
371
		echo "$usage"
389
		exit 1
372
		exit 1
390
		;;
373
		;;
391
esac
374
esac
392
 
375