Projet

Général

Profil

Mentiodns » Historique » Version 59

Anonyme, 07/01/2020 21:42

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