Projet

Général

Profil

Mentiodns » Historique » Version 20

sacha, 25/06/2018 22:33

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