Projet

Général

Profil

Mentiodns » Historique » Version 18

sacha, 25/06/2018 22:13

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