Projet

Général

Profil

Mentiodns » Historique » Version 23

sacha, 25/06/2018 23:06

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