-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
chkdm
executable file
·274 lines (243 loc) · 8.87 KB
/
chkdm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
#!/usr/bin/env bash
# chkdm (chkdomain)
# https://github.com/PeterDaveHello/chkdomain
# Copyright (C) 2022 ~ Peter Dave Hello
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# ColorEchoForShell #
# https://github.com/PeterDaveHello/ColorEchoForShell
# Copyright (C) 2015 ~ Peter Dave Hello
function echo.Red() {
echo -e "\\033[31m$*\\033[m"
}
function echo.Green() {
echo -e "\\033[32m$*\\033[m"
}
function echo.Cyan() {
echo -e "\\033[36m$*\\033[m"
}
function echo.BoldBlack
{
echo -e "\033[1;30m$*\033[m"
}
# ColorEchoForShell End #
function error() {
echo.Red >&2 "$@"
exit 1
}
if [ "$#" -ne "1" ]; then
echo.Red "You need to give me just one domain name to run the check!"
exit 1
fi
for cmd in dig nslookup sed head awk sort dirname readlink; do
if ! command -v $cmd > /dev/null 2>&1; then
error "command: $cmd not found!"
fi
done
shopt -s extglob
domain="${1%%+(.)}"
shopt -u extglob
declare -A nofilterDNS secureDNS adblockDNS
nofilterDNS[AdGuard]="94.140.14.140"
nofilterDNS[Cloudflare]="1.1.1.1"
nofilterDNS[dns0.eu]="193.110.81.254"
nofilterDNS[Freenom World]="80.80.81.81"
nofilterDNS[Gcore]="95.85.95.85"
nofilterDNS[Google]="8.8.8.8"
nofilterDNS[Hinet]="168.95.1.1"
nofilterDNS[UltraDNS]="64.6.64.6"
nofilterDNS[OpenDNS]="208.67.222.2"
nofilterDNS[Quad9]="9.9.9.10"
nofilterDNS[Yandex]="77.88.8.1"
secureDNS[CleanBrowsing]="185.228.168.9"
secureDNS[Cloudflare]="1.1.1.2"
secureDNS[Comodo]="8.26.56.26"
secureDNS[CONTROL D]="76.76.2.1"
secureDNS[dns0.eu]="193.110.81.0"
secureDNS[UltraDNS]="156.154.70.2"
secureDNS[SafeDNS]="195.46.39.39"
secureDNS[OpenDNS]="208.67.222.222"
secureDNS[Quad101]="101.101.101.101"
secureDNS[Quad9]="9.9.9.9"
secureDNS[Yandex]="77.88.8.2"
adblockDNS[AdGuard]="94.140.14.14"
adblockDNS[AhaDNS]="5.2.75.75"
adblockDNS[CONTROL D]="76.76.2.2"
adblockDNS[dnsforge.de]="176.9.93.198"
adblockDNS[OVPN]="192.165.9.157"
adblockDNS[Tiarap]="188.166.206.224"
PaloAltoSinkholeCname="sinkhole.paloaltonetworks.com."
NextDNSBlockPageCname="blockpage.nextdns.io."
NextDNSBlockPageIP="$(dig +short $NextDNSBlockPageCname)"
function query() {
domain="$1"
dns="$2"
filterDetect="$3"
result="$(dig +short "$domain" @"$dns" | xargs)"
echo "$result"
if echo "$result" | grep -Eq "(^| )$PaloAltoSinkholeCname($| )"; then
return 2
elif [ "" != "$NextDNSBlockPageIP" ]; then
if echo "$result" | grep -Eq "(^| )$NextDNSBlockPageCname($| )" || [ "$NextDNSBlockPageIP" = "$result" ]; then
return 3
fi
elif [ ";; connection timed out; no servers could be reached" = "$result" ]; then
return 4
elif echo "$result" | grep -E ";; communications error to $dns#[1-9]+: timed out"; then
return 4
elif echo "$result" | grep -E ";; communications error to $dns#[0-9]+: connection refused"; then
return 5
elif [ "filterDetect" != "$filterDetect" ]; then
test "" != "$result"
return $?
fi
# Determine if domain blocked by specified DNS
#
# Some DNS resolvers returned a not routable IP address,
# some DNS resolvers returned a specified IP for blocked domain to display a notice page
resultHead="$(echo "$result" | awk '{print $1}')"
case "$resultHead" in
# NXDOMAIN, CleanBrowsing, dns0.eu & Quad9 return it for blocked domain (OpenDNS sometimes return NXDOMAIN)
"") ;&
# dnsforge.de or Pi-Hole based blockers
"127.0.0.1" ) ;&
# Cloudflare & CONTROL D blocked domain
"0.0.0.0" | "::") ;&
# SafeDNS blocked domain (blockpage.safedns.com)
"127.0.0.2" | "195.46.39.1" ) ;&
# UltraDNS
"156.154.112.16" | "156.154.113.16") ;&
# Comodo (warn.recursive.dnsbycomodo.com)
"52.15.96.207") ;&
# OpenDNS (hit-phish.opendns.com)
"146.112.61.108") ;&
# Yandex (safe1.yandex.ru)
"safe1.yandex.ru." | "213.180.193.250" | "93.158.134.250" | "2a02:6b8::b10c:bad" | "2a02:6b8::b10c:babe")
return 1 ;;
# Other cases, consider properly resolved
*)
return 0 ;;
esac
}
function detailQuery() {
domain="$1"
dns="$2"
nslookup "$domain" "$dns" | sed -E -e 's/^(Server|Address):\t.+//g' -e 's/.+answer:$//g' -e 's/^Name:\t+.+$//g' -e '/^$/d' -e 's/^/ /g' | sort -V | uniq
}
function chkDomain() {
domain="$1"
dns="$2"
filterDetect="$3"
queryResult="$(query "$domain" "$dns" "$filterDetect")"
queryStatus="$?"
if [ "0" = "$queryStatus" ]; then
printf "%s" "$(echo.Green "OK!")"
echo.BoldBlack " ($queryResult)"
elif [ "1" = "$queryStatus" ]; then
echo.Red "Failed!"
detailQuery "$domain" "$dns"
elif [ "2" = "$queryStatus" ]; then
echo.Red "Palo Alto DNS Sinkhole detected!"
elif [ "3" = "$queryStatus" ]; then
echo.Red "NextDNS Block Page detected!"
elif [ "4" = "$queryStatus" ]; then
echo "Connection timed out ..."
elif [ "5" = "$queryStatus" ]; then
echo "Connection refused ..."
else
error "Unknown error"
fi
}
function checkNofilterDNS() {
echo.Cyan "\nRunning dig/nslookup over ${#nofilterDNS[@]} nofilter DNS:"
keys=()
while IFS='' read -r line; do keys+=("$line"); done < <(for DNS in "${!nofilterDNS[@]}"; do echo "$DNS"; done | sort)
for DNS in "${keys[@]}"; do
printf " - %s ... " "$DNS $(echo.BoldBlack "(${nofilterDNS[$DNS]})")"
chkDomain "$domain" "${nofilterDNS[$DNS]}" noFilterDetect
done
}
function checkSecureDNS() {
echo.Cyan "\nRunning dig/nslookup over ${#secureDNS[@]} secure DNS:"
keys=()
while IFS='' read -r line; do keys+=("$line"); done < <(for DNS in "${!secureDNS[@]}"; do echo "$DNS"; done | sort)
for DNS in "${keys[@]}"; do
printf " - %s ... " "$DNS $(echo.BoldBlack "(${secureDNS[$DNS]})")"
chkDomain "$domain" "${secureDNS[$DNS]}" filterDetect
done
}
function checkAdblockDNS() {
echo.Cyan "\nRunning dig/nslookup over ${#adblockDNS[@]} AD(and tracker)-blocking DNS:"
keys=()
while IFS='' read -r line; do keys+=("$line"); done < <(for DNS in "${!adblockDNS[@]}"; do echo "$DNS"; done | sort)
for DNS in "${keys[@]}"; do
printf " - %s ... " "$DNS $(echo.BoldBlack "(${adblockDNS[$DNS]})")"
chkDomain "$domain" "${adblockDNS[$DNS]}" filterDetect
done
}
function checkDefaultDNS() {
defaultDNS="$(nslookup wikipedia.org | awk '/Server:/ {print $2}' | head -n 1 )"
echo.Cyan "\nRunning nslookup over default DNS ($defaultDNS):"
printf " - %s ... " "$defaultDNS"
chkDomain "$domain" "$defaultDNS" filterDetect
}
function checkCustomDNS() {
DefaultCustomDNSFile="$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")/CustomDNS.txt"
if [ -z "$CustomDNSFile" ] && [ -r "$DefaultCustomDNSFile" ]; then
CustomDNSFile="$DefaultCustomDNSFile"
fi
test -r "$CustomDNSFile" || return 0
readarray -t customDNS < <(grep -v -E '^(#|$)' "$CustomDNSFile" | sed 's/#.*$//g' | grep -Eo '(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){1,3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])' | xargs -n 1)
echo.Cyan "\nRunning nslookup over ${#customDNS[@]} custom DNS:"
for DNS in "${customDNS[@]}"; do
printf " - %s ... " "$DNS"
chkDomain "$domain" "$DNS" filterDetect
done
}
function showDomainIntel() {
echo.Cyan "\nGet more intels about this domain from:"
cat <<HEREDOC
AlienVault Open Threat Exchange
- https://otx.alienvault.com/indicator/domain/$domain
Bitdefender TrafficLight
- https://trafficlight.bitdefender.com/info/?url=https%3A%2F%2F$domain
Google Safe Browsing
- https://transparencyreport.google.com/safe-browsing/search?url=$domain
Kaspersky Threat Intelligence Portal
- https://opentip.kaspersky.com/$domain?tab=web
McAfee SiteAdvisor
- https://siteadvisor.com/sitereport.html?url=$domain
Norton Safe Web
- https://safeweb.norton.com/report/show?url=$domain
OpenDNS
- https://domain.opendns.com/$domain
URLVoid
- https://www.urlvoid.com/scan/$domain/
urlscan.io
- https://urlscan.io/domain/$domain
VirusTotal
- https://www.virustotal.com/gui/domain/$domain/detection
Whois.com
- https://www.whois.com/whois/$domain
Yandex Site safety report
- https://yandex.com/safety/?l10n=en&url=$domain
HEREDOC
}
echo.Cyan "You are checking domain: $domain"
checkNofilterDNS
checkSecureDNS
checkAdblockDNS
checkDefaultDNS
checkCustomDNS
showDomainIntel