Projet

Général

Profil

Mentiodns » Check.DNS.Censorshit.sh

louis.leveque, 19/06/2018 23:07

 
1
#!/usr/bin/env bash
2
#orange
3
#sudo ip r a 80.10.246.0/24 via 192.168.1.1
4
#sudo ip r a 81.253.149.0/24 via 192.168.1.1
5
#numericable
6
#sudo ip r a 89.2.0.0/24 via 192.168.0.1
7
#sfr
8
#sudo ip r a 109.0.66.0/24 via 192.168.0.1
9
#free
10
#sudo ip r a 212.27.40.0/24 via $(ip n s dev usb0 | head -1 | cut -d " " -f1)
11
#bouygues
12
#sudo ip r a 194.158.122..0/24 via 192.168.0.1
13

    
14
details=false
15
Orange=false
16
OBS=false
17
Bouygues=false
18
SFR=false
19
Numericable=false
20
Free=false
21
Google=false
22
Local=false
23
Trusted=false
24
All=false
25
Random=false
26
site=""
27
DNSREP=""
28

    
29
DNS_Orange=(80.10.246.{1,2,3,5,7,129,130,132,134,136} 81.253.149.{1,2,6,9,10})
30
DNS_OBS=(194.2.0.{20,50})
31
DNS_Numericable=(89.2.0.{1,2})
32
DNS_SFR=(109.0.66.{10,11,12,15,20,21,22,25})
33
DNS_Free=(212.27.40.24{0,1,4,5})
34
DNS_Google=(8.8.{4.4,8.8})
35
DNS_Bouygues=(194.158.122.{10,15,53}) #untested
36
#DNS_FFDN=($(dig +short -t A mondns.eu.org)) #;) <3
37
DNS_FFDN=(80.67.169.{12,40} 80.67.188.188 89.234.141.66 89.234.186.18 185.233.100.100)
38

    
39

    
40
usage() {
41
	echo "Usage: $0 -u <address> -opbsnfgltar" 1>&2
42
	echo "-d print details (otherwise hidden) non lying and/or NOERROR but empty A record" 1>&2
43
	echo "   Operator DNS resolver" 1>&2
44
	echo "-o Orange" 1>&2
45
	echo "-p OBS (Orange Pro)" 1>&2
46
	echo "-b Bouygues" 1>&2
47
	echo "-s SFR" 1>&2
48
	echo "-n Numericable" 1>&2
49
	echo "-f Free" 1>&2
50
	echo "-g Google" 1>&2
51
	echo "-l Local" 1>&2
52
	echo "-t Trusted FFDN <3" 1>&2
53
	echo "-a All" 1>&2
54
	echo "-r Randomly pick a dns server from operator's known ones" 1>&2
55
	echo "MUST have a _specific_ /24 route to theses resolvers (except for p,g,t and l)." 1>&2
56
	echo "" 1>&2
57
	echo "Note : For Google, Local and Trusted resolvers, simply exit on NXDOMAIN answer." 1>&2
58
	echo "Note : For suspicious answers with NOERROR status, also check parent." 1>&2
59
	echo "" 1>&2
60
	echo "Output form :" 1>&2
61
	echo "Operator : answer_status;address;\"TTL A_record\";dns_addr;date;epoch;\"serial ttl (from SOA record)\";-(suspicious)/+ (otherwise);" 1>&2
62
	exit 1
63
}
64

    
65
while getopts "U:u:OoPpBbSsNnFfGgLlTtAaHhDdRr" opt; do
66
#echo $opt
67
  case $opt in
68
    D|d)  details=true ;;
69
    U|u)  site=$OPTARG ;;
70
    O|o)  Orange=true ;;
71
    P|p)  OBS=true ;;
72
    B|b)  Bouygues=true ;;
73
    S|s)  SFR=true ;;
74
    N|n)  Numericable=true ;;
75
    F|f)  Free=true ;;
76
    G|g)  Google=true ;;
77
    L|l)  Local=true ;;
78
    T|t)  Trusted=true ;;
79
    A|a)  All=true;Orange=true;OBS=true;Bouygues=true;SFR=true;Numericable=true;Free=true;Google=true;Local=true;Trusted=true ;;
80
    R|r)  Random=true ;;
81
    H|h)  usage ;;
82
    \?)   usage ;;
83
     :)   echo missing argument ;;
84
  esac
85
done
86

    
87
[ -z $1 ]&&usage
88
[ -z $site ]&&usage
89

    
90
#echo -e "Site:"$site "\nOrange:"$Orange "\nOBS:"$OBS "\nBouygues:"$Bouygues "\nSFR:"$SFR "\nNumericable:"$Numericable "\nFree:"$Free "\nGoogle:"$Google "\nLocal:"$Local "\nAll:"$All"\n"
91

    
92
function Do_Resolv {
93
	local site=$1;DNS=$2;
94
	DNSREP=$(dig +time=1 -t A +short @$DNS $site 2>/dev/null | sort)
95
	if [[ -z $DNSREP ]];then
96
		DATE=$(date +%Y%m%d_%H%M%S\;%s)
97
		REP=$(echo $Operator" : "$(dig -t A +time=2 $site @$DNS | awk -v date="${DATE}" -v dns=$DNS -v site=$site /status/'{print $6";"site";""\""}'/^$site/'{if ( $4=="A" ) print $2" "$5}'/SERVER/'{print "\""";"dns";"}'/WHEN/'{print date";\"\";-;"}') | sed "s/,//;s/;\ /;/;s/"\""\ /"\""/;s/\ "\""/"\""/")
98
		STATUS=$(echo $REP | awk -F":|;" '{ print $2}')
99
		if [ $STATUS != "NOERROR" ];then
100
			echo $REP
101
		elif $details ;then
102
			echo $REP
103
		fi
104
#todo		Update_DB_With $REP
105
	elif [[ $DNSREP =~ ^127\. ]]||[[ $DNSREP =~ ^90\.85\.16\.5. ]];then
106
		DATE=$(date +%Y%m%d_%H%M%S\;%s)
107
		SOASN=$(dig -t SOA $site @$DNS | grep -A1 -E "AUTHORITY SECTION|ANSWER SECTION" | tail -1 | awk '{ print $7" "$NF}')
108
		REP=$(echo $Operator" : "$(dig -t A +time=2 $site @$DNS | awk -v date="${DATE}" -v soasn="${SOASN}" -v dns=$DNS -v site=$site /status/'{print $6";"site";""\""}'/^$site/'{if ( $4=="A" ) print $2" "$5}'/SERVER/'{print "\""";"dns";"}'/WHEN/'{print date";\""soasn"\";-;"}') | sed "s/,//;s/;\ /;/;s/"\""\ /"\""/;s/\ "\""/"\""/")
109
		STATUS=$(echo $REP | awk -F":|;" '{ print $2}')
110
		echo $REP
111
		if [ $(echo $site| awk -F"." '{print NF}') -gt 2 ]; then
112
			Do_Resolv $(echo $site|awk -F"." '{for(i=2; i<NF;i++){printf $i"."}printf $NF"\n"}') $DNS
113
		fi
114
#todo		Update_DB_With $REP
115
	else
116
		if $details ;then
117
			DATE=$(date +%Y%m%d_%H%M%S\;%s)
118
			SOASN=$(dig -t SOA $site @$DNS | grep -A1 -E "AUTHORITY SECTION|ANSWER SECTION" | tail -1 | awk '{ print $7" "$NF}')
119
			echo $Operator" : NOERROR;"$site";\""$DNSREP"\";"${DNS}";"${DATE}";\""${SOASN}"\";+;"
120
		fi
121
		STATUS=NOERROR
122
	fi
123
}
124

    
125
function OneOfOrange {
126
local rand=$[ $RANDOM % ${#DNS_Orange[@]} ]
127
echo ${DNS_Orange[$rand]}
128
}
129
function OneOfOBS {
130
local rand=$[ $RANDOM % ${#DNS_OBS[@]} ]
131
echo ${DNS_OBS[$rand]}
132
}
133
function OneOfNumericable {
134
local rand=$[ $RANDOM % ${#DNS_Numericable[@]} ]
135
echo ${DNS_Numericable[$rand]}
136
}
137
function OneOfSFR {
138
local rand=$[ $RANDOM % ${#DNS_SFR[@]} ]
139
echo ${DNS_SFR[$rand]}
140
}
141
function OneOfFree {
142
local rand=$[ $RANDOM % ${#DNS_Free[@]} ]
143
echo ${DNS_Free[$rand]}
144
}
145
function OneOfGoogle {
146
local rand=$[ $RANDOM % ${#DNS_Google[@]} ]
147
echo ${DNS_Google[$rand]}
148
}
149
function OneOfBouygues {
150
local rand=$[ $RANDOM % ${#DNS_Bouygues[@]} ]
151
echo ${DNS_Bouygues[$rand]}
152
}
153
function OneOfFFDN {
154
local rand=$[ $RANDOM % ${#DNS_FFDN[@]} ]
155
echo ${DNS_FFDN[$rand]}
156
}
157

    
158
if $Local; then
159
	Operator=Local
160
	DNS=127.0.0.1
161
	Do_Resolv $site $DNS
162
	if [ $STATUS == "NXDOMAIN" ];then echo "NXDOMAIN, not testing others resolvers (if asked)." ; exit ;fi
163
fi
164

    
165
if $Trusted; then
166
        Operator=FFDN
167
        if $Random ;then
168
                DNS=$(OneOfFFDN)
169
        else
170
                DNS=80.67.169.40
171
        fi
172
        Do_Resolv $site $DNS
173
        if [ $STATUS == "NXDOMAIN" ];then echo "NXDOMAIN, not testing others resolvers (if asked)." ; exit ;fi
174
fi
175

    
176
if $Google; then
177
        Operator=Google
178
        if $Random ;then
179
                DNS=$(OneOfGoogle)
180
        else
181
                DNS=8.8.4.4
182
        fi
183
        Do_Resolv $site $DNS
184
        if [ $STATUS == "NXDOMAIN" ];then echo "NXDOMAIN, not testing others resolvers (if asked)." ; exit ;fi
185
fi
186

    
187
if $Orange; then
188
	Operator=Orange
189
	if $Random ;then
190
		DNS=$(OneOfOrange)
191
	else
192
		DNS=80.10.246.1
193
	fi
194
	if [[ $(ip r s 80.10.246.0/24 2>/dev/null|grep via) ]]&&[[ $(ip r s 81.253.149.0/24 2>/dev/null|grep via) ]] ;then
195
		Do_Resolv $site $DNS
196
#	else
197
#		echo $Operator": No specific route to DNS."
198
	fi
199
fi
200

    
201
if $OBS; then
202
	Operator=OBS
203
	if $Random ;then
204
		DNS=$(OneOfOBS)
205
	else
206
		DNS=194.2.0.20
207
	fi
208
#	if [[ $(ip r s 194.2.0.0/24 2>/dev/null|grep via) ]] ;then
209
	Do_Resolv $site $DNS
210
#	else
211
#		echo $Operator": No specific route to DNS."
212
#	fi
213
fi
214

    
215
if $Bouygues; then
216
	Operator=Bouygues
217
	if $Random ;then
218
		DNS=$(OneOfBouygues)
219
	else
220
		DNS=194.158.122.10
221
	fi
222
	if [[ $(ip r s 194.158.122.0/24 2>/dev/null|grep via) ]] ;then
223
		Do_Resolv $site $DNS
224
#	else
225
#		echo $Operator": No specific route to DNS."
226
	fi
227
fi
228

    
229
if $SFR; then
230
	Operator=SFR
231
	if $Random ;then
232
		DNS=$(OneOfSFR)
233
	else
234
		DNS=109.0.66.10
235
	fi
236
	if [[ $(ip r s 109.0.66.0/24 2>/dev/null|grep via) ]] ;then
237
		Do_Resolv $site $DNS
238
#	else
239
#		echo $Operator": No specific route to DNS."
240
	fi
241
fi
242

    
243
if $Numericable; then
244
	Operator=Numericable
245
	if $Random ;then
246
		DNS=$(OneOfNumericable)
247
	else
248
		DNS=89.2.0.2
249
	fi
250
	if [[ $(ip r s 89.2.0.0/24 2>/dev/null|grep via) ]] ;then
251
		Do_Resolv $site $DNS
252
#	else
253
#		echo $Operator": No specific route to DNS."
254
	fi
255
fi
256

    
257
if $Free; then
258
	Operator=Free
259
	if $Random ;then
260
		DNS=$(OneOfFree)
261
	else
262
		DNS=212.27.40.240
263
	fi
264
	if [[ $(ip r s 212.27.40.0/24 2>/dev/null|grep via) ]] ;then
265
		Do_Resolv $site $DNS
266
#	else
267
#		echo $Operator": No specific route to DNS."
268
	fi
269
fi
    (1-1/1)