Projet

Général

Profil

Mentiodns » Historique » Version 16

sacha, 25/06/2018 19:53

1 1 sacha
h1. Mentiodns
2
3
Validation des DNS à partir d'une liste sur un unbound et un DNS grand FAI et comparaison des résultats ;)
4
5 4 sacha
h2. Noeud actifs
6
7
|_. Nom |_. Bloc |
8
| Mezzanine | domain_names.com_sortedad |
9
| Millicent | domain_names.com_sortedab |
10 9 sacha
| Sacha | domain_names.org_sortedaa |
11
| Sacha | domain_names.org_sortedab |
12
| Sacha | domain_names.org_sortedab |
13 10 sacha
| Sacha | domain_names.org_sortedac |
14
| Sacha | domain_names.org_sortedac |
15 4 sacha
| Taziden | domain_names.com_sortedac |
16
17
h2. Mentio
18
19
<pre>
20
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+--+-#
21
#  MENTIODNS : Check for lying DNS (France)  #
22
#--------------------------------------------#
23 16 sacha
#  Version 1.6 - conf file                   # 
24 13 sacha
#  Version 1.5 - test Dig resolving          #
25
#  Version 1.4 - Socat SSL sending results   # 
26
#  Version 1.3 - tld optioN                  #
27 1 sacha
#  Version 1.2 - Round robin on DNS_ISP_LIST #
28 13 sacha
#		 For each request	     #
29 4 sacha
#  Version 1.1 - Allow resume on basename    #
30
#  Version 1.0 - Parallel process with DIG   #
31
#--------------------------------------------#
32 1 sacha
# (c) Sacha at Aquilenet.fr part of FFDN.org #
33
#--------------------------------------------#
34
35
# This shity script intend to bruteforce the ISP lying DNS Servers to identify which one
36
# is going on Ministry of Interior Blocking page and compare the IP result from your favorite DNS server
37 16 sacha
# Use this script with the following parameters 
38
# $1 MODE: client server local
39
# $2 File source: list of domain names whithout tld
40
# $3 tld: com, org, ...
41
# $4 count number (if none from zero or from count file based on file name)
42
43
44 1 sacha
# If you relanch the script it will check if it has a counter for the given file to resume
45
# Blacklisted sites in $BLACKLIST_LOG file
46 13 sacha
# Diff ip from a domain name are in $DIFF_LOG 
47 1 sacha
48 13 sacha
# 1st launch creating config file
49 1 sacha
50 14 sacha
# Copy generated certificates:
51
# FILENAME=mentio_ssl-server 
52 1 sacha
# openssl genrsa -out $FILENAME.key 1024
53 13 sacha
# openssl req -new -key $FILENAME.key -x509 -days 3653 -out $FILENAME.crt
54 1 sacha
# cat $FILENAME.key $FILENAME.crt >$FILENAME.pem
55 13 sacha
# FILENAME=mentio_ssl-client
56
# ...
57
58 16 sacha
##########################################################
59 1 sacha
HOMEDIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
60 13 sacha
MENTIOCONF="$HOMEDIR/mentio.conf"
61
# Number of parallel requests thruw dig
62
parallel=10
63 16 sacha
##########################################################
64 1 sacha
65 16 sacha
66
##########################################################
67 13 sacha
### CHECK CONFIG
68
if [ ! -f $MENTIOCONF ]; then
69
echo "=================================================================="
70
echo "MENTIODNS"
71
echo "------------------------------------------------------------------" 
72
echo "1st time configuring"
73
echo -n "IP UNBOUND ? "
74
read DNS_MY
75 1 sacha
76 13 sacha
echo 'HOMEDIR="'$HOMEDIR'"' > $MENTIOCONF
77
echo 'DNS_MY="'$DNS_MY'"' >> $MENTIOCONF
78 1 sacha
IP_PUB=`curl ifconfig.io`
79 13 sacha
ASN=`whois -h whois.cymru.com $IP_PUB |cut -d' ' -f1|sed -n "2p"`
80 1 sacha
DNS_LIST="$HOMEDIR/mentio-DNS_ISP_LIST"
81
DNS_ISP_LIST=`grep $ASN $DNS_LIST|cut -d' ' -f3-`
82
echo 'DNS_ISP_LIST="'$DNS_ISP_LIST'"' >> $MENTIOCONF
83
echo "------------------------------------------------------------------"
84
echo " CONFIGURATION FILE:"
85
echo " please check and relaunch"
86
echo "------------------------------------------------------------------"
87
cat $MENTIOCONF
88
echo "------------------------------------------------------------------"
89
exit 1
90
fi
91 16 sacha
##########################################################
92 1 sacha
93 16 sacha
94
##########################################################
95
### PARAMETERS to execute the script
96
# Mode Log export with socat "client" "server" "local"
97
98
MODE=$1
99
100
if [ $MODE == "server" ]; then
101
socat -v -u openssl-listen:65522,fork,reuseaddr,cert=mentio_ssl-server.pem,cafile=mentio_ssl-client.crt OPEN:$HOMEDIR/MENTIO-DNS_DIFF,creat,append
102
exit 1
103
fi
104
##########################################################
105
106
107
##########################################################
108
### Check if commandline parameters are less than 3
109
110 1 sacha
if [ $# -lt 3 ]; then
111
echo "=================================================================="
112
echo "MENTIODNS"
113
echo "------------------------------------------------------------------"
114 14 sacha
echo "Missing Parameter, please enter:"
115 13 sacha
echo
116 1 sacha
echo "mentio-check client|server|local filename tld (count number)"
117 13 sacha
echo
118
exit 1
119
fi
120 16 sacha
##########################################################
121 13 sacha
122 16 sacha
123
##########################################################
124
### Get parameters
125
126
# From config file
127 1 sacha
source $MENTIOCONF
128 13 sacha
129 16 sacha
# From command line
130 1 sacha
# $2 DNS source file name
131 13 sacha
DNS_SOURCE=$2
132 1 sacha
# $3 TLD name (com, org...)
133 13 sacha
tld=$3
134 1 sacha
# line counter from the dns source file, nothing for auto-resuming
135
COUNT=$4
136
137 16 sacha
##########################################################
138 13 sacha
### SOCAT
139
SERVER="10.11.12.22:65522"
140
SENDSOCAT="socat stdio openssl-connect:$SERVER,verify=0,cert=$HOMEDIR/mentio_ssl-client.pem,cafile=$HOMEDIR/mentio_ssl-server.crt"
141 16 sacha
##########################################################
142 13 sacha
### COLORS 
143
RED='\e[31m'
144
GREEN='\e[32m'
145
YELLOW='\e[33m'
146 1 sacha
GRAY='\e[90m'
147
NC='\033[0m' # No Color
148 16 sacha
##########################################################
149
### Various variables
150 13 sacha
DNS_SOURCE_BASENAME=`basename $DNS_SOURCE`
151 1 sacha
DIFF_LOG="$HOMEDIR/DNS_DIFF"
152
BLACKLIST_LOG="$HOMEDIR/DNS_BLACKLISTED"
153
lines=`wc -l $DNS_SOURCE|awk -F " " '{print $1}'`
154 13 sacha
countfile="$HOMEDIR/DNS_Count-$DNS_SOURCE_BASENAME"
155 4 sacha
dateus=`date +%Y%m%d-%H%M%S`
156 16 sacha
##########################################################
157
### Dig parameters
158 1 sacha
DIG_FAST="+nodnssec +short +timeout=1 +tries=2"
159
DIG_SLOW="+nodnssec +short +timeout=5 +tries=3 "
160 16 sacha
##########################################################
161 13 sacha
162 16 sacha
163
##########################################################
164
### Generate list for dig: round robin from dns list
165
### Like (@DNS-server domain) x parallel 
166 1 sacha
_check(){
167
i=0
168 13 sacha
url=""
169
while [ $i -lt $parallel ]
170 1 sacha
do
171
n=`expr $count + $i`
172
ISP_DNS=`echo $DNS_ISP_LIST | xargs -n 1| sort -R | head -n 1`
173
url="$url @$ISP_DNS `awk -v n="${n}" 'NR==n {print;exit}' $DNS_SOURCE`.$tld"
174
i=`expr $i + 1`
175
done
176
}
177 16 sacha
##########################################################
178 1 sacha
179
180 16 sacha
##########################################################
181
### Counter: create one if not existing, use existing instead
182 1 sacha
if [ -z $COUNT ]; then
183 13 sacha
	if [ -f $countfile ]; then
184 1 sacha
	count=`cat $countfile`
185
	else
186 13 sacha
	count=0
187
	echo $count > $countfile
188
	fi
189
else count=$COUNT
190
echo $count > $countfile
191 4 sacha
fi
192 16 sacha
##########################################################
193 4 sacha
194 16 sacha
195
##########################################################
196
### MAIN LOOP
197
198 4 sacha
while [ "$count" != "$lines" ]; do
199
echo $count > $countfile
200
_check
201 13 sacha
site="$url"
202
echo "-------------------------------------------------------------------------------"
203
echo "#$count $dateus SITE:$site"
204
if nomentio=`dig @$DNS_MY $DIG_SLOW $site|sort -n -t . -k 1,1 -k 2,2 -k 3,3 -k 4,4| tr '\r\n' ' '` && [ -z "$nomentio" ]; then
205
	echo -e "$GRAY Unknown zone $site $NC" 
206
fi
207
if mentio=`dig $DIG_SLOW $site|sort -n -t . -k 1,1 -k 2,2 -k 3,3 -k 4,4| tr '\r\n' ' '` && [ -z "$mentio" ]; then
208
	echo -e "$GRAY Unknown zone $site $NC"
209 4 sacha
fi
210
211 13 sacha
if [ -n "$nomentio" ] && [ -n "$mentio" ]; then
212
    if [ "$nomentio" != "$mentio" ]; then
213
	for i in $site; do
214 1 sacha
		if nomentio1=`dig $DIG_FAST @$DNS_MY $i|sort -n -t . -k 1,1 -k 2,2 -k 3,3 -k 4,4| tr '\r\n' ' '` && [ -z "$nomentio1" ]; then
215 13 sacha
			echo -e "$GRAY Unknown zone $i $NC"
216
		fi
217
		ISP_DNS=`echo $DNS_ISP_LIST | xargs -n 1| sort -R | head -n 1`
218
		if mentio1=`dig $DIG_FAST @$ISP_DNS $i|sort -n -t . -k 1,1 -k 2,2 -k 3,3 -k 4,4| tr '\r\n' ' '` && [ -z "$mentio1" ]; then
219
			echo -e "$GRAY Unknown zone $i $NC"
220
		fi
221
			if [ "$nomentio1" != "$mentio1" ]; then
222
        			if [[ $mentio1 == 90.85.* ]]; then
223
		                        if [ $MODE == "client" ]; then
224
                		        	echo "!!! $dateus `hostname` SITE:$i ISPDNS:$ISP_DNS REAL:$nomentio1 MENTIO:$mentio1 $NC" | $SENDSOCAT
225
                        		fi
226
					echo -e "$RED !!! $dateus SITE:$i ISPDNS:$ISP_DNS REAL:$nomentio1 MENTIO:$mentio1 $NC"
227
					echo "!!! $dateus SITE:$i ISPDNS:$ISP_DNS REAL:$nomentio1 MENTIO:$mentio1" >> $BLACKLIST_LOG
228
				else
229
                        			if [ $MODE == "client" ]; then
230
                        				echo ">>> $dateus `hostname` SITE:$i ISPDNS:$ISP_DNS REAL:$nomentio1 MENTIO:$mentio1" | $SENDSOCAT
231
                        			fi                   
232
					echo -e "$YELLOW >>> SITE:$i ISPDNS:$ISP_DNS REAL:$nomentio1 MENTIO:$mentio1 $NC"
233
					echo ">>> $dateus SITE:$i ISPDNS:$ISP_DNS REAL:$nomentio1 MENTIO:$mentio1" >> $DIFF_LOG
234
				fi
235
			fi
236 1 sacha
	done
237 13 sacha
    else
238 3 sacha
    echo -e "$GREEN#$count  SITE:$site  $NC"
239 1 sacha
    fi
240
fi
241
242
count=`expr $count + $parallel`
243
244 14 sacha
done
245 16 sacha
##########################################################
246 14 sacha
247 7 sacha
248 3 sacha
</pre>
249 2 sacha
250
h2. Test (valide au 14/06/18)
251 1 sacha
252 7 sacha
 dig +short shahamat1.com
253 3 sacha
 90.85.16.52
254 1 sacha
255
h2. Liste de serveurs DNS FAI Français
256
257 11 sacha
h3. Free - ASN12322
258 12 sacha
259 11 sacha
212.27.40.240
260
212.27.40.241
261
212.27.40.244
262 7 sacha
212.27.40.245
263 3 sacha
264 1 sacha
h3. Bouygues - ASN5410
265
266
194.158.122.10
267
194.158.122.15
268
269
h3. SFR/Numericable - ASN5410
270
271
89.2.0.1
272
89.2.0.2
273
274
h3. SFR - ASN15557
275
276
109.0.66.10
277
109.0.66.20
278
279
h3. Orange - ASN3215
280 2 sacha
281 3 sacha
80.10.246.1
282 1 sacha
80.10.246.2
283
80.10.246.3
284 6 sacha
80.10.246.5
285
80.10.246.7
286
80.10.246.129
287
80.10.246.130
288
80.10.246.132
289 8 sacha
80.10.246.134
290
80.10.246.136
291
81.253.149.1
292
81.253.149.2
293 1 sacha
81.253.149.6
294 11 sacha
81.253.149.9
295 1 sacha
81.253.149.10
296
297
h3. OBS (ouverts)
298
299
194.2.0.20
300
194.2.0.50
301
302
h2. Vigies de la neutralité
303
304
https://ooni.torproject.org
305
https://respectmynet.eu
306
307
h2. Cadre légal
308
309
https://www.legifrance.gouv.fr/affichTexte.do?cidTexte=JORFTEXT000000801164&fastPos;=2&fastReqId;=606073666&categorieLien;=cid&oldAction;=rechTexte#LEGIARTI000029756525        
310
le décret https://www.legifrance.gouv.fr/affichTexte.do;jsessionid=FE6BFDED672BF1E2EFC5CA70705CF26E.tplgfr21s_3?cidTexte=LEGITEXT000030315036&dateTexte;=20150305&categorieLien;=cid#LEGITEXT000030315036  
311 15 sacha
https://www.legifrance.gouv.fr/affichTexte.do;jsessionid=FE6BFDED672BF1E2EFC5CA70705CF26E.tplgfr21s_3?cidTexte=JORFTEXT000030195477&dateTexte;=20180619
312
313
h2. Ansible divers
314
315
Copy file:
316
317
 ansible mentio -m copy -a "src=mentio-check6 dest=~/MENTIODNS/"
318
319
320
Copy file single host:
321
322
 ansible mentio --limit dam -m copy -a "src=mentio-check6 dest=~/MENTIODNS/"
323
324
ansible-playbook /etc/ansible/playbooks/mentio.yml 
325
326
327
<pre>
328
---
329
330
- hosts: mentio 
331
  sudo: no
332
  tasks:
333
    - name: copyfiles 
334
      copy:
335
        src: "{{ item.src }}"
336
        dest: "{{ item.dest }}"
337
      with_items:
338
        - { src: '/home/sacha/0nmyway/00_Aquilenet/FFDN/mentiodns.fr/mentio-check6',dest: '~/MENTIODNS/' }
339
        - { src: '/home/sacha/0nmyway/00_Aquilenet/FFDN/mentiodns.fr/mentio-DNS_ISP_LIST',dest: '~/MENTIODNS/' }
340
        - { src: '/home/sacha/0nmyway/00_Aquilenet/FFDN/mentiodns.fr/mentio_ssl-client.crt',dest: '~/MENTIODNS/' }
341
        - { src: '/home/sacha/0nmyway/00_Aquilenet/FFDN/mentiodns.fr/mentio_ssl-client.key',dest: '~/MENTIODNS/' }
342
        - { src: '/home/sacha/0nmyway/00_Aquilenet/FFDN/mentiodns.fr/mentio_ssl-client.pem',dest: '~/MENTIODNS/' }
343
        - { src: '/home/sacha/0nmyway/00_Aquilenet/FFDN/mentiodns.fr/mentio_ssl-server.crt',dest: '~/MENTIODNS/' }
344
345
346 1 sacha
</pre>