Projet

Général

Profil

Mentiodns » Historique » Version 19

sacha, 25/06/2018 22:15

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