forked from elceef/dnstwist
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dnstwist.py
executable file
·1452 lines (1269 loc) · 45.5 KB
/
dnstwist.py
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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# _ _ _ _
# __| |_ __ ___| |___ _(_)___| |_
# / _` | '_ \/ __| __\ \ /\ / / / __| __|
# | (_| | | | \__ \ |_ \ V V /| \__ \ |_
# \__,_|_| |_|___/\__| \_/\_/ |_|___/\__| mod
#
# Generate and resolve domain variations to detect typo squatting,
# phishing and corporate espionage.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
Find similar-looking domain names that adversaries can use to attack you. Can
detect typo squatters, phishing attacks, fraud and corporate espionage. Useful
as an additional source of targeted threat intelligence.
Usage:
dnstwist DOMAIN [--registered] [--all | --banners | --dictionary=<file> | --geoip | --History=<file> | --mxcheck | --format=<file>] [--ssdeep | --threads=<n> | --whois | --tld=<file> | --nameservers=<address> | --port=<int> | --useragent=<string>]
dnstwist (-h | --help)
dnstwist --version
Options:
DOMAIN Domain name or URL to check
-a --all Show all DNS records
-b --banners Determine HTTP and SMTP service banners
-d <file> --dictionary=<file> Generate additional domains using dictionary FILE
-g --geoip Perform lookup for GeoIP location
-H <file> --History=<file> Uses Historical json file to find new domains.
-m --mxcheck Check if MX host can be used to intercept e-mails
-f <string> --format=<string> Output format of cli, csv, json, return, or idle [default: cli]
-r --registered Show only registered domain names
-s --ssdeep Fetch web pages and compare their fuzzy hashes to evaluate similarity
-t <n> --threads=<n> Start specified NUMBER of threads [default: 10]
-w --whois Perform lookup for WHOIS creation/update time (slow)
-t <file> --tld=<file> Generate additional domains by swapping TLD from file
-n <address> --nameservers=<address> Comma separated list of DNS servers to query
-p <int> --port=<int> The port number to send queries to
-u <string> --useragent=<string> User-agent STRING to send with HTTP requests (default: Mozilla/5.0 dnstwist/<version>)
-h --help Show this screen.
--version Show version.
"""
__author__ = "mod by Bryce B"
__version__ = "20200429"
__email__ = "[email protected]"
import re
import sys
import socket
import signal
import time
import threading
from random import randint
from os import path
import smtplib
import json
from docopt import docopt
from schema import And, Optional, Or, Schema, Use
try:
import queue
except ImportError:
import Queue as queue
try:
import dns.resolver
import dns.rdatatype
from dns.exception import DNSException
MODULE_DNSPYTHON = True
except ImportError:
MODULE_DNSPYTHON = False
pass
try:
import GeoIP
MODULE_GEOIP = True
except ImportError:
MODULE_GEOIP = False
pass
try:
import whois
MODULE_WHOIS = True
except ImportError:
MODULE_WHOIS = False
pass
try:
import ssdeep
MODULE_SSDEEP = True
except ImportError:
MODULE_SSDEEP = False
try:
import requests
requests.packages.urllib3.disable_warnings()
MODULE_REQUESTS = True
except ImportError:
MODULE_REQUESTS = False
pass
REQUEST_TIMEOUT_DNS = 2.5
REQUEST_RETRIES_DNS = 2
REQUEST_TIMEOUT_HTTP = 5
REQUEST_TIMEOUT_SMTP = 5
THREAD_COUNT_DEFAULT = 10
if sys.platform != "win32" and sys.stdout.isatty():
FG_RND = "\x1b[3%dm" % randint(1, 8)
FG_RED = "\x1b[31m"
FG_YEL = "\x1b[33m"
FG_GRE = "\x1b[32m"
FG_MAG = "\x1b[35m"
FG_CYA = "\x1b[36m"
FG_BLU = "\x1b[34m"
FG_RST = "\x1b[39m"
ST_BRI = "\x1b[1m"
ST_RST = "\x1b[0m"
else:
FG_RND = (
FG_RED
) = FG_YEL = FG_GRE = FG_MAG = FG_CYA = FG_BLU = FG_RST = ST_BRI = ST_RST = ""
def validate_args(args):
s = Schema(
{
"DOMAIN": str, # must exists,
Optional("--all", default=None): Or(None, bool),
Optional("--banners", default=None): Or(None, bool),
Optional("--dictionary", default=None): Or(None, path.exists),
Optional("--geoip", default=None): Or(None, bool),
Optional("--History", default=None): Or(None, path.exists),
Optional("--mxcheck", default=None): Or(None, bool),
Optional("--format", default="cli"): And(
Use(str, lambda s: s in ["cli", "csv", "json", "return", "idle"])
),
Optional("--registered", default=None): Or(None, bool),
Optional("--ssdeep", default=None): Or(None, bool),
Optional("--threads", default=10): And(Use(int), lambda n: 0 < n),
Optional("--whois", default=None): Or(None, bool),
Optional("--tld", default=None): Or(None, path.exists),
Optional("--nameservers", default=None): Or(None, str),
Optional("--port", default=None): Or(
None, And(Use(int), lambda n: 0 < n < 65536)
),
Optional("--useragent", default=f"Mozilla/5.0 dnstwist/{__version__}"): Or(
None, str
),
}
)
return s.validate(args)
def p_cli(data):
global args
if args["--format"] == "cli":
sys.stdout.write(data)
sys.stdout.flush()
def p_err(data):
sys.stderr.write(path.basename(sys.argv[0]) + ": " + data)
sys.stderr.flush()
def p_csv(data):
global args
if args["--format"] == "csv":
sys.stdout.write(data)
def p_json(data):
global args
if args["--format"] == "json":
sys.stdout.write(data)
def bye(code):
sys.stdout.write(FG_RST + ST_RST)
sys.exit(code)
def sigint_handler(signal, frame):
sys.stdout.write("\nStopping threads... ")
sys.stdout.flush()
for worker in threads:
worker.stop()
worker.join()
sys.stdout.write("Done\n")
bye(0)
class UrlParser:
def __init__(self, url):
if "://" not in url:
self.url = "http://" + url
else:
self.url = url
self.scheme = ""
self.authority = ""
self.domain = ""
self.path = ""
self.query = ""
self.__parse()
def __parse(self):
re_rfc3986_enhanced = re.compile(
r"""
^
(?:(?P<scheme>[^:/?#\s]+):)?
(?://(?P<authority>[^/?#\s]*))?
(?P<path>[^?#\s]*)
(?:\?(?P<query>[^#\s]*))?
(?:\#(?P<fragment>[^\s]*))?
$
""",
re.MULTILINE | re.VERBOSE,
)
m_uri = re_rfc3986_enhanced.match(self.url)
if m_uri:
if m_uri.group("scheme"):
if m_uri.group("scheme").startswith("http"):
self.scheme = m_uri.group("scheme")
else:
self.scheme = "http"
if m_uri.group("authority"):
self.authority = m_uri.group("authority")
self.domain = self.authority.split(":")[0].lower()
if not self.__validate_domain(self.domain):
raise ValueError("Invalid domain name")
if m_uri.group("path"):
self.path = m_uri.group("path")
if m_uri.group("query"):
if len(m_uri.group("query")):
self.query = "?" + m_uri.group("query")
def __validate_domain(self, domain):
if len(domain) > 255:
return False
if domain[-1] == ".":
domain = domain[:-1]
allowed = re.compile("\A([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,}\Z", re.IGNORECASE)
return allowed.match(domain)
def get_full_uri(self):
return self.scheme + "://" + self.domain + self.path + self.query
class DomainFuzz:
def __init__(self, domain):
self.subdomain, self.domain, self.tld = self.__domain_tld(domain)
self.domains = []
self.qwerty = {
"1": "2q",
"2": "3wq1",
"3": "4ew2",
"4": "5re3",
"5": "6tr4",
"6": "7yt5",
"7": "8uy6",
"8": "9iu7",
"9": "0oi8",
"0": "po9",
"q": "12wa",
"w": "3esaq2",
"e": "4rdsw3",
"r": "5tfde4",
"t": "6ygfr5",
"y": "7uhgt6",
"u": "8ijhy7",
"i": "9okju8",
"o": "0plki9",
"p": "lo0",
"a": "qwsz",
"s": "edxzaw",
"d": "rfcxse",
"f": "tgvcdr",
"g": "yhbvft",
"h": "ujnbgy",
"j": "ikmnhu",
"k": "olmji",
"l": "kop",
"z": "asx",
"x": "zsdc",
"c": "xdfv",
"v": "cfgb",
"b": "vghn",
"n": "bhjm",
"m": "njk",
}
self.qwertz = {
"1": "2q",
"2": "3wq1",
"3": "4ew2",
"4": "5re3",
"5": "6tr4",
"6": "7zt5",
"7": "8uz6",
"8": "9iu7",
"9": "0oi8",
"0": "po9",
"q": "12wa",
"w": "3esaq2",
"e": "4rdsw3",
"r": "5tfde4",
"t": "6zgfr5",
"z": "7uhgt6",
"u": "8ijhz7",
"i": "9okju8",
"o": "0plki9",
"p": "lo0",
"a": "qwsy",
"s": "edxyaw",
"d": "rfcxse",
"f": "tgvcdr",
"g": "zhbvft",
"h": "ujnbgz",
"j": "ikmnhu",
"k": "olmji",
"l": "kop",
"y": "asx",
"x": "ysdc",
"c": "xdfv",
"v": "cfgb",
"b": "vghn",
"n": "bhjm",
"m": "njk",
}
self.azerty = {
"1": "2a",
"2": "3za1",
"3": "4ez2",
"4": "5re3",
"5": "6tr4",
"6": "7yt5",
"7": "8uy6",
"8": "9iu7",
"9": "0oi8",
"0": "po9",
"a": "2zq1",
"z": "3esqa2",
"e": "4rdsz3",
"r": "5tfde4",
"t": "6ygfr5",
"y": "7uhgt6",
"u": "8ijhy7",
"i": "9okju8",
"o": "0plki9",
"p": "lo0m",
"q": "zswa",
"s": "edxwqz",
"d": "rfcxse",
"f": "tgvcdr",
"g": "yhbvft",
"h": "ujnbgy",
"j": "iknhu",
"k": "olji",
"l": "kopm",
"m": "lp",
"w": "sxq",
"x": "wsdc",
"c": "xdfv",
"v": "cfgb",
"b": "vghn",
"n": "bhj",
}
self.keyboards = [self.qwerty, self.qwertz, self.azerty]
def __domain_tld(self, domain):
try:
from tld import parse_tld
except ImportError:
ctld = [
"org",
"com",
"net",
"gov",
"edu",
"co",
"mil",
"nom",
"ac",
"info",
"biz",
]
d = domain.rsplit(".", 3)
if len(d) == 2:
return "", d[0], d[1]
if len(d) > 2:
if d[-2] in ctld:
return ".".join(d[:-3]), d[-3], ".".join(d[-2:])
else:
return ".".join(d[:-2]), d[-2], d[-1]
else:
d = parse_tld(domain, fix_protocol=True)[::-1]
if d[1:] == d[:-1] and None in d:
d = tuple(domain.rsplit(".", 2))
d = ("",) * (3 - len(d)) + d
return d
def __validate_domain(self, domain):
try:
domain_idna = domain.encode("idna").decode()
except UnicodeError:
# '.tla'.encode('idna') raises UnicodeError: label empty or too long
# This can be obtained when __omission takes a one-letter domain.
return False
if len(domain) == len(domain_idna) and domain != domain_idna:
return False
allowed = re.compile(
"(?=^.{4,253}$)(^((?!-)[a-zA-Z0-9-]{1,63}(?<!-)\.)+[a-zA-Z]{2,63}\.?$)",
re.IGNORECASE,
)
return allowed.match(domain_idna)
def __filter_domains(self):
seen = set()
filtered = []
for d in self.domains:
# if not self.__validate_domain(d['domain-name']):
# p_err("debug: invalid domain %s\n" % d['domain-name'])
if (
self.__validate_domain(d["domain-name"])
and d["domain-name"] not in seen
):
seen.add(d["domain-name"])
filtered.append(d)
self.domains = filtered
def __bitsquatting(self):
result = []
masks = [1, 2, 4, 8, 16, 32, 64, 128]
for i in range(0, len(self.domain)):
c = self.domain[i]
for j in range(0, len(masks)):
b = chr(ord(c) ^ masks[j])
o = ord(b)
if (o >= 48 and o <= 57) or (o >= 97 and o <= 122) or o == 45:
result.append(self.domain[:i] + b + self.domain[i + 1 :])
return result
def __homoglyph(self):
glyphs = {
"a": ["à", "á", "â", "ã", "ä", "å", "ɑ", "ạ", "ǎ", "ă", "ȧ", "ą",],
"b": ["d", "lb", "ʙ", "ɓ", "ḃ", "ḅ", "ḇ", "ƅ"],
"c": ["e", "ƈ", "ċ", "ć", "ç", "č", "ĉ"],
"d": ["b", "cl", "dl", "ɗ", "đ", "ď", "ɖ", "ḑ", "ḋ", "ḍ", "ḏ", "ḓ",],
"e": [
"c",
"é",
"è",
"ê",
"ë",
"ē",
"ĕ",
"ě",
"ė",
"ẹ",
"ę",
"ȩ",
"ɇ",
"ḛ",
],
"f": ["ƒ", "ḟ"],
"g": ["q", "ɢ", "ɡ", "ġ", "ğ", "ǵ", "ģ", "ĝ", "ǧ", "ǥ"],
"h": ["lh", "ĥ", "ȟ", "ħ", "ɦ", "ḧ", "ḩ", "ⱨ", "ḣ", "ḥ", "ḫ", "ẖ",],
"i": [
"1",
"l",
"í",
"ì",
"ï",
"ı",
"ɩ",
"ǐ",
"ĭ",
"ỉ",
"ị",
"ɨ",
"ȋ",
"ī",
],
"j": ["ʝ", "ɉ"],
"k": ["lk", "ik", "lc", "ḳ", "ḵ", "ⱪ", "ķ"],
"l": ["1", "i", "ɫ", "ł"],
"m": ["n", "nn", "rn", "rr", "ṁ", "ṃ", "ᴍ", "ɱ", "ḿ"],
"n": ["m", "r", "ń", "ṅ", "ṇ", "ṉ", "ñ", "ņ", "ǹ", "ň", "ꞑ"],
"o": ["0", "ȯ", "ọ", "ỏ", "ơ", "ó", "ö"],
"p": ["ƿ", "ƥ", "ṕ", "ṗ"],
"q": ["g", "ʠ"],
"r": ["ʀ", "ɼ", "ɽ", "ŕ", "ŗ", "ř", "ɍ", "ɾ", "ȓ", "ȑ", "ṙ", "ṛ", "ṟ",],
"s": ["ʂ", "ś", "ṣ", "ṡ", "ș", "ŝ", "š"],
"t": ["ţ", "ŧ", "ṫ", "ṭ", "ț", "ƫ"],
"u": [
"ᴜ",
"ǔ",
"ŭ",
"ü",
"ʉ",
"ù",
"ú",
"û",
"ũ",
"ū",
"ų",
"ư",
"ů",
"ű",
"ȕ",
"ȗ",
"ụ",
],
"v": ["ṿ", "ⱱ", "ᶌ", "ṽ", "ⱴ"],
"w": ["vv", "ŵ", "ẁ", "ẃ", "ẅ", "ⱳ", "ẇ", "ẉ", "ẘ"],
"y": ["ʏ", "ý", "ÿ", "ŷ", "ƴ", "ȳ", "ɏ", "ỿ", "ẏ", "ỵ"],
"z": ["ʐ", "ż", "ź", "ᴢ", "ƶ", "ẓ", "ẕ", "ⱬ"],
}
result_1pass = set()
for ws in range(1, len(self.domain)):
for i in range(0, (len(self.domain) - ws) + 1):
win = self.domain[i : i + ws]
j = 0
while j < ws:
c = win[j]
if c in glyphs:
win_copy = win
for g in glyphs[c]:
win = win.replace(c, g)
result_1pass.add(
self.domain[:i] + win + self.domain[i + ws :]
)
win = win_copy
j += 1
result_2pass = set()
for domain in result_1pass:
for ws in range(1, len(domain)):
for i in range(0, (len(domain) - ws) + 1):
win = domain[i : i + ws]
j = 0
while j < ws:
c = win[j]
if c in glyphs:
win_copy = win
for g in glyphs[c]:
win = win.replace(c, g)
result_2pass.add(domain[:i] + win + domain[i + ws :])
win = win_copy
j += 1
return list(result_1pass | result_2pass)
def __hyphenation(self):
result = []
for i in range(1, len(self.domain)):
result.append(self.domain[:i] + "-" + self.domain[i:])
return result
def __insertion(self):
result = []
for i in range(1, len(self.domain) - 1):
for keys in self.keyboards:
if self.domain[i] in keys:
for c in keys[self.domain[i]]:
result.append(
self.domain[:i] + c + self.domain[i] + self.domain[i + 1 :]
)
result.append(
self.domain[:i] + self.domain[i] + c + self.domain[i + 1 :]
)
return list(set(result))
def __omission(self):
result = []
for i in range(0, len(self.domain)):
result.append(self.domain[:i] + self.domain[i + 1 :])
n = re.sub(r"(.)\1+", r"\1", self.domain)
if n not in result and n != self.domain:
result.append(n)
return list(set(result))
def __repetition(self):
result = []
for i in range(0, len(self.domain)):
if self.domain[i].isalpha():
result.append(
self.domain[:i]
+ self.domain[i]
+ self.domain[i]
+ self.domain[i + 1 :]
)
return list(set(result))
def __replacement(self):
result = []
for i in range(0, len(self.domain)):
for keys in self.keyboards:
if self.domain[i] in keys:
for c in keys[self.domain[i]]:
result.append(self.domain[:i] + c + self.domain[i + 1 :])
return list(set(result))
def __subdomain(self):
result = []
for i in range(1, len(self.domain) - 3):
if self.domain[i] not in ["-", "."] and self.domain[i - 1] not in [
"-",
".",
]:
result.append(self.domain[:i] + "." + self.domain[i:])
return result
def __transposition(self):
result = []
for i in range(0, len(self.domain) - 1):
if self.domain[i + 1] != self.domain[i]:
result.append(
self.domain[:i]
+ self.domain[i + 1]
+ self.domain[i]
+ self.domain[i + 2 :]
)
return result
def __vowel_swap(self):
vowels = "aeiou"
result = []
for i in range(0, len(self.domain)):
for vowel in vowels:
if self.domain[i] in vowels:
result.append(self.domain[:i] + vowel + self.domain[i + 1 :])
return list(set(result))
def __addition(self):
result = []
for i in range(97, 123):
result.append(self.domain + chr(i))
return result
def generate(self):
self.domains.append(
{
"fuzzer": "Original*",
"domain-name": ".".join(
filter(None, [self.subdomain, self.domain, self.tld])
),
}
)
for domain in self.__addition():
self.domains.append(
{
"fuzzer": "Addition",
"domain-name": ".".join(
filter(None, [self.subdomain, domain, self.tld])
),
}
)
for domain in self.__bitsquatting():
self.domains.append(
{
"fuzzer": "Bitsquatting",
"domain-name": ".".join(
filter(None, [self.subdomain, domain, self.tld])
),
}
)
for domain in self.__homoglyph():
self.domains.append(
{
"fuzzer": "Homoglyph",
"domain-name": ".".join(
filter(None, [self.subdomain, domain, self.tld])
),
}
)
for domain in self.__hyphenation():
self.domains.append(
{
"fuzzer": "Hyphenation",
"domain-name": ".".join(
filter(None, [self.subdomain, domain, self.tld])
),
}
)
for domain in self.__insertion():
self.domains.append(
{
"fuzzer": "Insertion",
"domain-name": ".".join(
filter(None, [self.subdomain, domain, self.tld])
),
}
)
for domain in self.__omission():
self.domains.append(
{
"fuzzer": "Omission",
"domain-name": ".".join(
filter(None, [self.subdomain, domain, self.tld])
),
}
)
for domain in self.__repetition():
self.domains.append(
{
"fuzzer": "Repetition",
"domain-name": ".".join(
filter(None, [self.subdomain, domain, self.tld])
),
}
)
for domain in self.__replacement():
self.domains.append(
{
"fuzzer": "Replacement",
"domain-name": ".".join(
filter(None, [self.subdomain, domain, self.tld])
),
}
)
for domain in self.__subdomain():
self.domains.append(
{
"fuzzer": "Subdomain",
"domain-name": ".".join(
filter(None, [self.subdomain, domain, self.tld])
),
}
)
for domain in self.__transposition():
self.domains.append(
{
"fuzzer": "Transposition",
"domain-name": ".".join(
filter(None, [self.subdomain, domain, self.tld])
),
}
)
for domain in self.__vowel_swap():
self.domains.append(
{
"fuzzer": "Vowel-swap",
"domain-name": ".".join(
filter(None, [self.subdomain, domain, self.tld])
),
}
)
if "." in self.tld:
self.domains.append(
{
"fuzzer": "Various",
"domain-name": self.domain + "." + self.tld.split(".")[-1],
}
)
self.domains.append(
{"fuzzer": "Various", "domain-name": self.domain + self.tld}
)
if "." not in self.tld:
self.domains.append(
{
"fuzzer": "Various",
"domain-name": self.domain + self.tld + "." + self.tld,
}
)
if self.tld != "com" and "." not in self.tld:
self.domains.append(
{
"fuzzer": "Various",
"domain-name": self.domain + "-" + self.tld + ".com",
}
)
self.__filter_domains()
class DomainDict(DomainFuzz):
def __init__(self, domain):
DomainFuzz.__init__(self, domain)
self.dictionary = []
def load_dict(self, file):
if path.exists(file):
for word in open(file):
word = word.strip("\n")
if word.isalpha() and word not in self.dictionary:
self.dictionary.append(word)
def __dictionary(self):
result = []
for word in self.dictionary:
result.append(self.domain + "-" + word)
result.append(self.domain + word)
result.append(word + "-" + self.domain)
result.append(word + self.domain)
return result
def generate(self):
for domain in self.__dictionary():
self.domains.append(
{
"fuzzer": "Dictionary",
"domain-name": ".".join(
filter(None, [self.subdomain, domain, self.tld])
),
}
)
class TldDict(DomainDict):
def generate(self):
if self.tld in self.dictionary:
self.dictionary.remove(self.tld)
for tld in self.dictionary:
self.domains.append(
{
"fuzzer": "TLD-swap",
"domain-name": ".".join(
filter(None, [self.subdomain, self.domain, tld])
),
}
)
class DomainThread(threading.Thread):
def __init__(self, queue):
threading.Thread.__init__(self)
self.jobs = queue
self.kill_received = False
self.ssdeep_orig = ""
self.domain_orig = ""
self.uri_scheme = "http"
self.uri_path = ""
self.uri_query = ""
self.option_extdns = False
self.option_geoip = False
self.option_whois = False
self.option_ssdeep = False
self.option_banners = False
self.option_mxcheck = False
def __banner_http(self, ip, vhost):
try:
http = socket.socket()
http.settimeout(1)
http.connect((ip, 80))
http.send(
b"HEAD / HTTP/1.1\r\nHost: %s\r\nUser-agent: %s\r\n\r\n"
% (vhost.encode(), args["--useragent"].encode())
)
response = http.recv(1024).decode()
http.close()
except Exception:
pass
else:
sep = "\r\n" if "\r\n" in response else "\n"
headers = response.split(sep)
for field in headers:
if field.startswith("Server: "):
return field[8:]
banner = headers[0].split(" ")
if len(banner) > 1:
return "HTTP %s" % banner[1]
def __banner_smtp(self, mx):
try:
smtp = socket.socket()
smtp.settimeout(1)
smtp.connect((mx, 25))
response = smtp.recv(1024).decode()
smtp.close()
except Exception:
pass
else:
sep = "\r\n" if "\r\n" in response else "\n"
hello = response.split(sep)[0]
if hello.startswith("220"):
return hello[4:].strip()
return hello[:40]
def __mxcheck(self, mx, from_domain, to_domain):
from_addr = "randombob" + str(randint(1, 9)) + "@" + from_domain
to_addr = "randomalice" + str(randint(1, 9)) + "@" + to_domain
try:
smtp = smtplib.SMTP(mx, 25, timeout=REQUEST_TIMEOUT_SMTP)
smtp.sendmail(from_addr, to_addr, "And that's how the cookie crumbles")
smtp.quit()
except Exception:
return False
else:
return True
def stop(self):
self.kill_received = True
@staticmethod
def answer_to_list(answers):
return sorted(
list(
map(
lambda record: str(record).strip(".")
if len(str(record).split(" ")) == 1
else str(record).split(" ")[1].strip("."),
answers,
)
)
)
def run(self):
while not self.kill_received:
try:
domain = self.jobs.get(block=False)
except queue.Empty:
self.kill_received = True
return
domain["domain-name"] = domain["domain-name"].encode("idna").decode()
if self.option_extdns:
if args["--nameservers"]:
resolv = dns.resolver.Resolver(configure=False)
resolv.nameservers = args["--nameservers"].split(",")
if args["--port"]:
resolv.port = args["--port"]
else:
resolv = dns.resolver.Resolver()
resolv.lifetime = REQUEST_TIMEOUT_DNS * REQUEST_RETRIES_DNS
resolv.timeout = REQUEST_TIMEOUT_DNS
nxdomain = False
dns_ns = False
dns_a = False
dns_aaaa = False
dns_mx = False
try:
domain["dns-ns"] = self.answer_to_list(
resolv.query(domain["domain-name"], rdtype=dns.rdatatype.NS)
)
dns_ns = True
except dns.resolver.NXDOMAIN:
nxdomain = True
pass
except dns.resolver.NoNameservers: