-
Notifications
You must be signed in to change notification settings - Fork 7
/
doppelganger.py
1431 lines (1237 loc) · 48.9 KB
/
doppelganger.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 -*-
#
# doppelganger.py
#
# Copyright 2017 Viktor Pavlovic <[email protected]>
#
# 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/>.
#
#
#
# Doppelgänger is a tool that creates permutations of domain names using lookalike
# unicode characters and identifies registered domains using dns queries.
# It can be used to identify phishing and typosquatting domains.
#
#
# TODO:
#
# dns round robin for speed increase / not get blocked
# use better algorithm for permutation generation (ram + speed)
# use hdf5 for working with datasets larger than ram
import itertools
import dns.resolver
from colorama import init, Fore, Style
import csv
import argparse
import textwrap
import time
import datetime
show_char_alts = False # show lookalike chars for each character
show_permutations = False # show all permutations for domain
show_debug = False # enable debug / verbose output
show_colors = True # enable color console output
show_time = False # enable benchmark for permutation finding
iinfo = "[i] "
isucc = "[+] "
iwarn = "[!] "
ierr = "[-] "
supported_tlds = ['com', 'org', 'at', 'ca', 'ch', 'de', 'dk', 'fr', 'no', 'pm', 'se', 'tf', 'wf', 'yt']
class MainOptions:
def __init__(self):
# number of permutations that can be done in reasonable time using the original (complete) algorithm
self.max_permutations = 20000
# Use Colors
self.show_colors = True
# Show Debug Output
self.show_debug = False
# show all permutations for domain
self.show_permutations = False
self.data = []
opt = MainOptions()
def init_helpers():
global iinfo, iwarn, isucc, ierr
if show_colors:
init()
iinfo = Fore.LIGHTBLUE_EX + "[i] " + Style.RESET_ALL
isucc = Fore.LIGHTGREEN_EX + "[+] " + Style.RESET_ALL
iwarn = Fore.YELLOW + "[!] " + Style.RESET_ALL
ierr = Fore.RED + "[-] " + Style.RESET_ALL
else:
iinfo = "[i] "
isucc = "[+] "
iwarn = "[!] "
ierr = "[-] "
class PermutationError(Exception):
pass
# print a list with supported TLDs
def show_tld_support():
ccomplete = "complete"
cnotsupported = "IDN not supported"
cpartial = "partial"
cpartialend = ""
if show_colors:
ccomplete = Fore.LIGHTGREEN_EX + "complete" + Style.RESET_ALL
cnotsupported = Fore.BLUE + "IDN not supported" + Style.RESET_ALL
cpartial = Fore.YELLOW + "partial"
cpartialend = Style.RESET_ALL
print(" TLD Support")
print("####################################################################")
print("")
print("gTLDs")
print("-------+------------------------------------------------------------")
print("com | " + cpartial + " - only latin and lisu script" + cpartialend)
print("org | " + cpartial + " - Korean and Chinese missing" + cpartialend)
print("net | " + cpartial + " - only latin and lisu script" + cpartialend)
print("sTLDs")
print("biz | no")
print("info | no")
print("name | no")
print("")
print("ccTLDs")
print("-------+------------------------------------------------------------")
print("ag | no")
print("ar | no")
print("at | " + ccomplete)
print("au | " + cnotsupported)
print("be | no")
print("br | no")
print("ca | not applicable (https://cira.ca/assets/Documents/Legal/IDN/faq.pdf)")
print("ch | " + ccomplete)
print("cn | no")
print("co | no")
print("cz | no")
print("de | " + ccomplete)
print("dk | " + ccomplete)
print("es | no")
print("eu | no") #
print("fi | no")
print("fm | no") #
print("fr | " + ccomplete)
print("gr | no")
print("hu | no")
print("hr | no")
print("ie | no")
print("in | no")
print("io | no") #
print("ir | " + cnotsupported)
print("is | no")
print("it | no") # charsets, no homoglyphs, http://www.crdd.it/norme/GuidelineTecnicheSincrono2.1-EN.pdf
print("jp | no")
print("me | no")
print("nl | " + cnotsupported)
print("no | " + ccomplete)
print("pl | no") # 4 language sets: latin, greek, cyrillic, -
# lookalike check in place hebrew https://www.dns.pl/IDN/idn-registration-policy.txt
print("pm | " + ccomplete)
print("рф (rf)| no")
print("rs | no")
print("ru | " + cnotsupported)
print("se | " + cpartial + " - no hebrew support" + cpartialend)
print("tf | " + ccomplete)
print("tr | no")
print("tv | no")
print("tw | no")
print("uk | " + cnotsupported)
print("us | " + cnotsupported)
print("wf | " + ccomplete)
print("yt | " + ccomplete)
def main(args):
global parsed_args
global show_colors
global show_debug
parser = argparse.ArgumentParser(prog='doppelganger',
formatter_class=argparse.RawDescriptionHelpFormatter,
description=textwrap.dedent('''doppelgänger - A tool to search for IDN lookalike/fake domains
\nCopyright \u00a9 2017 Viktor Pavlovic
\n 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/ .'''),
epilog='''General Note: Some characters seem to be easily distinguishable from others.
However on some fonts, sizes, uppercase letters, etc. these
could look alike, so they are included just to be sure.
Another Note: Keep in mind that while some doppelganger domains are created
with malicious intent, some are not. Some domains identified by
this tool were probably not meant to be a doppelganger of the
original.''')
parser.add_argument("-1", "--simple", help="Force simple algorithm: Modify only one character at a time. "
"Overrides --max-permutations (-p) setting.",
action="store_true")
parser.add_argument("-c", "--colors", help="Switch output colors on (1) and off (0). Defaults to on.",
type=int, choices=[0, 1], default=0)
parser.add_argument("-d", "--dry-run", help="Create and output permutations, don't do any DNS requests.",
action="store_true")
parser.add_argument("-k", "--keymap", help="Use specified keymap for finding typo domains.",
type=str, choices=['qwerty', 'qwertz', 'azerty'], default='qwerty')
parser.add_argument("-o", "--output-file", help="Output permutations to file, don't do anything else.",
type=str, metavar="FILENAME")
parser.add_argument("-p", "--max-permutations", help="number of calculated permutations after a switch to a simpler"
" algorithm is done. By default this software looks for all "
"doppelganger characters, however on domains with less "
"restrictive IDN rules this can easily result in several "
"million permutations that would take really long to check. "
"Simpler algorithm: Modify only one character at a time. "
"Defaults to 20000",
type=int, default=20000)
parser.add_argument("-s", "--tld-support", help="Show a table of supported TLDs.",
action="store_true")
parser.add_argument("-t", "--timing", help="Set a ms delay between DNS queries to prevent flooding DNS servers",
type=int, default=0)
parser.add_argument("-v", "--verbose", action="count", help="verbose output", default=0)
parser.add_argument("-y", "--typo-only", action="store_true", help="Domain Typosquatting mode - Generate typos, not"
" doppelgangers", default=0)
parser.add_argument("domain", help="the fqdn you want to check", nargs=1)
parsed_args = parser.parse_args()
if parsed_args.colors:
if parsed_args.colors == 1:
show_colors = True
else:
show_colors = False
init_helpers()
if parsed_args.tld_support:
show_tld_support()
sys.exit()
if not parsed_args.domain:
print(ierr + "FQDN missing")
parser.print_help()
sys.exit()
if parsed_args.verbose:
show_debug = True
fqdn = str(parsed_args.domain[0]).lower()
if parsed_args.typo_only:
if parsed_args.keymap:
if parsed_args.keymap == 'qwerty':
check_typo(fqdn, Typo.KeyMap.QWERTY)
elif parsed_args.keymap == 'qwertz':
check_typo(fqdn, Typo.KeyMap.QWERTZ)
elif parsed_args.keymap == 'azerty':
print(ierr + "AZERTY keymap support not built in yet, sorry!")
sys.exit(1)
else:
check_doppel(fqdn)
return 0
def replace_lisu(sll):
out = ""
for c in sll:
if c == 'a':
r = 0xa4ee
elif c == 'b':
r = 0xa4d0
elif c == 'c':
r = 0xa4da
elif c == 'd':
r = 0xa4d3
elif c == 'e':
r = 0xa4f0
elif c == 'f':
r = 0xa4dd
elif c == 'g':
r = 0xa4d6
elif c == 'h':
r = 0xa4e7
elif c == 'i':
r = 0xa4f2
elif c == 'j':
r = 0xa4d9
elif c == 'k':
r = 0xa4d7
elif c == 'l':
r = 0xa4e1
elif c == 'm':
r = 0xa4df
elif c == 'n':
r = 0xa4e0
elif c == 'o':
r = 0xa4f3
elif c == 'p':
r = 0xa4d1
elif c == 'r':
r = 0xa4e3
elif c == 's':
r = 0xa4e2
elif c == 't':
r = 0xa4d4
elif c == 'u':
r = 0xa4f4
elif c == 'v':
r = 0xa4e6
elif c == 'w':
r = 0xa4ea
elif c == 'x':
r = 0xa4eb
elif c == 'y':
r = 0xa4ec
elif c == 'z':
r = 0xa4dc
else:
r = ord(c)
out += chr(r)
return out
# generate complete set of permutations
def get_permutations(sll, tld, lang_code='none'):
pos = 0
sll_alts = []
all_permutations = []
if lang_code == 'lisu':
if 'q' in sll:
if show_debug:
print('q is not available in lisu - no alternatives.')
return all_permutations
else:
all_permutations.append(replace_lisu(sll) + '.' + tld + tld)
return all_permutations
if tld == 'se' and lang_code == 'hebrew':
if ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'j', 'k', 'm', 'p', 'r', 's', 'v', 'w', 'z']:
if show_debug:
print('some letters are not available in hebrew - no alternatives.')
return all_permutations
for c in sll:
if show_char_alts:
print(c, end='')
print(" Alternatives: ", end='')
curr_char = [c]
for altc in alt_chars(c, tld, lang_code):
if show_char_alts:
print(chr(altc) + " ", end='')
curr_char.append(chr(altc))
if show_char_alts:
print("")
pos += 1
sll_alts.append(curr_char)
if parsed_args.simple:
print(iinfo + "Using simpler algorithm (will contain only domains with one modified character)")
all_permutations = get_simple_permutations(sll, tld, lang_code)
else:
try:
for permutation in getcombinations(sll_alts):
perm_str = ''.join(map(str, permutation))
all_permutations.append(perm_str + '.' + tld)
if show_debug:
print("Len of all perms: " + str(len(all_permutations)))
if len(all_permutations) > parsed_args.max_permutations:
raise PermutationError(ierr + "Too Many Permutations")
except PermutationError:
print(ierr + "Too Many Permutations (max-permutations threshold)")
print(iinfo + "Trying simpler algorithm (will contain only domains with one modified character)")
all_permutations = get_simple_permutations(sll, tld, lang_code)
except MemoryError:
print(ierr + "Too Many Permutations (insufficient memory)")
print(iinfo + "Trying simpler algorithm (will contain only domains with one modified character)")
all_permutations = get_simple_permutations(sll, tld, lang_code)
return all_permutations
# generate reduced set of permutations (only permutations with one changed char)
def get_simple_permutations(sll, tld, lang_code='none'):
all_permutations = []
idx = 0
for c in sll:
for altc in alt_chars(c, tld, lang_code):
newperm = sll[:idx] + chr(int(altc)) + sll[idx + 1:] # replace original with altchar
all_permutations.append(newperm + '.' + tld)
idx += 1
return all_permutations
# Class that holds and generates typo permutations
class Typo:
def __init__(self, fqdn, keymap):
self.domain = Domain(fqdn)
self.tld = self.domain.tld
self.sll = self.domain.sll
self.neighbors = []
self.km = keymap
# swap chars next to each other
def generate_swap(self):
ret_domains = []
if show_debug:
print("Swaps:")
for i in range(0, len(self.sll) - 1):
# print( self.sll[i:i+2] )
typodomain = self.sll[0:i] + self.sll[i+1] + self.sll[i] + self.sll[i+2:]
if show_debug:
print(typodomain + "." + self.tld)
ret_domains.append(typodomain + "." + self.tld)
return ret_domains
# remove single chars
def generate_missing(self):
ret_domains = []
if show_debug:
print("Missing Chars:")
for i in range(0, len(self.sll)):
typodomain = self.sll[0:i] + self.sll[i + 1:]
if show_debug:
print(typodomain + "." + self.tld)
ret_domains.append(typodomain + "." + self.tld)
return ret_domains
# double chars
def generate_double(self):
ret_domains = []
if show_debug:
print("Double Chars:")
for i in range(0, len(self.sll)):
typodomain = self.sll[0:i] + self.sll[i] + self.sll[i] + self.sll[i + 1:]
if show_debug:
print(typodomain + "." + self.tld)
ret_domains.append(typodomain + "." + self.tld)
return ret_domains
# split domain (i.e. exa.mple.com instead of example.com)
def generate_split(self):
ret_domains = []
if show_debug:
print("Split Domain:")
for i in range(0, len(self.sll) - 1):
typodomain = self.sll[i + 1:]
if show_debug:
print(typodomain + "." + self.tld)
ret_domains.append(typodomain + "." + self.tld)
return ret_domains
# neighbor chars next to the key on different keyboard layouts
def generate_neighbor(self):
ret_domains = []
if show_debug:
print("Neighbors:")
if self.km == Typo.KeyMap.QWERTY:
km_file = "qwerty.csv"
elif self.km == Typo.KeyMap.QWERTZ:
km_file = "qwertz.csv"
elif self.km == Typo.KeyMap.AZERTY:
km_file = "azerty.csv"
else:
print(ierr + " ERROR - Unknown or unspecified Keymap!")
sys.exit(1)
try:
with open("keymaps/" + km_file, 'r') as f:
reader = csv.reader(f)
self.neighbors = list(reader)
except FileNotFoundError:
print(ierr + " Keymap file '" + km_file + "' not found!")
sys.exit(1)
for i in range(0, len(self.sll)):
alts = self.get_neighbors(self.sll[i])
for h in range(1, len(alts)):
if alts[h] not in (None, ""):
typodomain = self.sll[:i] + alts[h] + self.sll[i + 1:]
if show_debug:
print(typodomain + '.' + self.tld)
ret_domains.append(typodomain + "." + self.tld)
return ret_domains
def check(self):
typo_domains = []
typo_domains.extend(self.generate_swap())
typo_domains.extend(self.generate_double())
typo_domains.extend(self.generate_missing())
typo_domains.extend(self.generate_split())
typo_domains.extend(self.generate_neighbor())
if show_permutations:
for p in typo_domains:
print(p)
if parsed_args.output_file:
print(iinfo + "writing doppelgangers to file...")
with open(parsed_args.output_file, 'w') as file:
for perm in typo_domains:
file.writelines(perm.encode("idna").decode() + "\n")
sys.exit()
if parsed_args.dry_run:
print(isucc + " typo domains for " + self.domain.fqdn + ":")
for perm in typo_domains:
print(perm, end='')
print(" - " + perm.encode("idna").decode())
sys.exit()
check_dns(typo_domains)
class KeyMap:
QWERTY = 1
QWERTZ = 2
AZERTY = 3
def get_neighbors(self, char):
for row in self.neighbors:
if row[0] == char:
if show_debug:
print(row)
return row
class InvalidFQDNError(Exception):
pass
class Domain:
def __init__(self, fqdn):
# check if valid fqdn
if '.' not in fqdn:
raise InvalidFQDNError("'" + fqdn + "' is not a fqdn.")
elif fqdn.count('.') > 1:
raise InvalidFQDNError("'" + fqdn + "' is not a fqdn. Only second-level.tld is supported")
self.tld = fqdn.rsplit('.')[-1]
self.sll = fqdn.rsplit('.')[-2]
self.fqdn = fqdn
def is_supported(self):
# return true if tld is in supported list
if self.tld in supported_tlds:
return True
else:
return False
def check_support(self):
# check if this domain is supported
if self.tld in ['ca']:
print(iwarn + ".ca domain does not allow IDNs with doppelganger chars.")
print("if example.ca is registered only it's owner can register éxample.ca")
print("Details: https://cira.ca/assets/Documents/Legal/IDN/faq.pdf")
sys.exit()
elif self.tld in ['au', 'nl', 'uk', 'us']:
print(iwarn + '.' + self.tld + " registry does not support IDN.")
sys.exit()
elif not self.is_supported():
print(ierr + '.' + self.tld + " domains are not supported yet. Sorry.")
sys.exit()
# check fqdn for typosquatting domains
def check_typo(fqdn, keymap):
typo = Typo(fqdn, keymap)
typo.check()
# check fqdn for doppelganger domains
def check_doppel(fqdn):
print("checking " + fqdn)
# get tld
# TODO: Build class to check if tld is correct and return tld and sll
domain = Domain(fqdn)
tld = domain.tld
sll = domain.sll
domain.check_support()
# TODO: [org] zh, ko
lang_codes = {'org': ['bs', 'bg', 'be', 'mk', 'ru', 'sr', 'uk', 'da', 'de', 'hu', 'is', 'lv', 'lt', 'pl', 'es',
'sv'], 'com': ['latin', 'lisu'], 'se': ['latin']}
all_permutations = []
nx_tlds = []
existing_tlds = []
t_start = 0
if show_time:
print("Time start...")
t_start = datetime.datetime.now()
if tld in lang_codes:
print(iinfo + tld + " uses language codes")
for lc in lang_codes[tld]:
if show_debug:
print("Permutations for Lang_Code '" + lc + "':")
all_permutations += get_permutations(sll, tld, lc)
else:
all_permutations = get_permutations(sll, tld)
if show_debug:
print("All Permutations: " + str(len(all_permutations)))
unique_permutations = list(set(all_permutations))
if show_time:
t_end = datetime.datetime.now()
t_diff = t_end - t_start
print("Time: " + str(t_diff.total_seconds()) + "s")
sys.exit()
num_permutations = len(unique_permutations)
if show_colors:
print(Fore.WHITE + Style.BRIGHT + str(num_permutations) + Style.RESET_ALL + " unique combinations with allowed "
"characters for ." + tld +
" domains exist")
else:
print(str(num_permutations) + " unique combinations with allowed characters for ." + tld + " domains exist")
if show_permutations:
for p in unique_permutations:
print(p)
if parsed_args.output_file:
print(iinfo + "writing doppelgangers to file...")
with open(parsed_args.output_file, 'w') as file:
for perm in unique_permutations:
file.writelines(perm.encode("idna").decode() + "\n")
sys.exit()
if parsed_args.dry_run:
print(isucc + " doppelgangers for " + fqdn + ":")
for perm in unique_permutations:
print(perm, end='')
print(" - " + perm.encode("idna").decode())
sys.exit()
# DNS Check
check_dns(unique_permutations)
# check dns entries of a supplied list of fqdns
def check_dns(domain_permutations):
# DNS Check
print("Checking DNS...")
nx_tlds = []
existing_tlds = []
num_permutations = len(domain_permutations)
current_num = 0
for domain in domain_permutations:
sys.stdout.write("Progress: %d / %d \r" % ((current_num + 1), num_permutations))
sys.stdout.flush()
pc = domain.encode("idna").decode()
dr = dns.resolver
try:
answers = dr.query(pc, 'A')
if show_colors:
print(isucc + "Found " + Style.BRIGHT + domain + Style.RESET_ALL, end='')
else:
print(isucc + "Found " + domain, end='')
print(" IDN: " + pc, end='')
for rdata in answers:
print(' Address: ', rdata.address, end='')
print('')
existing_tlds.append(pc)
except dns.resolver.NXDOMAIN:
nx_tlds.append(pc)
except dns.resolver.Timeout:
print(" - Timed out while resolving %s" % pc)
except dns.exception.DNSException:
print(" - Unhandled exception")
current_num += 1
if parsed_args.timing != 0:
time.sleep((parsed_args.timing / 1000))
def getcombinations(slllist):
permutations = list(itertools.product(*slllist))
return permutations
# This function contains all lookalilke chars for each latin character that are allowed for each tld
def alt_chars(c, tld, lang_code='none'):
r = []
if tld == 'at':
# https://www.nic.at/media/files/pdf/IDN_Zeichentabelle.pdf
if c == 'a':
r = [0x00e0, 0x00e1, 0x00e2, 0x00e3, 0x00e4, 0x00e5, 0x00e6]
elif c == 'b':
r = [0x00fe]
elif c == 'c':
r = [0x00e7]
elif c == 'd':
r = [0x00f0]
elif c == 'e':
r = [0x00e6, 0x00e8, 0x00e9, 0x00ea, 0x00eb, 0x0153]
elif c == 'i':
r = []
elif c == 'n':
r = [0x00f1]
elif c == 'o':
r = [0x00f0, 0x00f2, 0x00f3, 0x00f4, 0x00f5, 0x00f6, 0x00f8, 0x0153]
elif c == 's':
r = [0x0161]
elif c == 'u':
r = [0x00f9, 0x00fa, 0x00fb, 0x00fc]
elif c == 'y':
r = [0x00fd]
elif c == 'z':
r = [0x017e]
else:
r = []
if tld == 'se':
# Source: https://www.iis.se/docs/teckentabell-04.pdf
if lang_code == 'latin': # Latin - source: https://www.iis.se/docs/teckentabell-04.pdf
if c == '3':
r = [0x01ef, 0x0292]
elif c == 'a':
r = [0x00e0, 0x00e1, 0x00e2, 0x00e4, 0x00e5, 0x00e6, 0x00ce]
elif c == 'b':
r = [0x0fe]
elif c == 'c':
r = [0x00e7, 0x0107, 0x010d]
elif c == 'd':
r = [0x00f0, 0x0111]
elif c == 'e':
r = [0x00e8, 0x00e9, 0x00ea, 0x00eb, 0x011b, 0x0259]
elif c == 'g':
r = [0x01e5, 0x01e7]
elif c == 'i':
r = [0x00ec, 0x00ed, 0x00ee, 0x00ef, 0x01d0, 0x0142]
elif c == 'k':
r = [0x01e9]
elif c == 'l':
r = [0x00ec, 0x00ed, 0x0142]
elif c == 'n':
r = [0x00f1, 0x0144, 0x014b]
elif c == 'o':
r = [0x00f2, 0x00f3, 0x00f4, 0x00f5, 0x00f6, 0x00f8, 0x01d2]
elif c == 'r':
r = [0x0159]
elif c == 's':
r = [0x015b, 0x0161]
elif c == 't':
r = [0x0163, 0x0167]
elif c == 'u':
r = [0x00f9, 0x00fa, 0x00fc, 0x00fd, 0x01d4]
elif c == 'y':
r = [0x00fd]
elif c == 'z':
r = [0x017a, 0x017e]
else:
r = []
elif lang_code == 'hebrew': # Hebrew - source: https://www.iis.se/docs/teckentabell-04.pdf
print("error - hebrew support not built in yet :(")
if c == '':
r = []
# if tld == 'be':
# https://www.dnsbelgium.be/en/domain-name/valid-domain-name
if tld == 'no':
# allowed chars for .no domains
# Source: https://www.norid.no/en/regelverk/navnepolitikk/#link3
if c == 'a':
r = [0x00e0, 0x00e1, 0x00e4, 0x00e5, 0x00e6]
elif c == 'c':
r = [0x00e7, 0x010d]
elif c == 'd':
r = [0x0111]
elif c == 'e':
r = [0x00e6, 0x00e8, 0x00e9, 0x00ea]
elif c == 'n':
r = [0x00f1, 0x0144, 0x014b]
elif c == 'o':
r = [0x00f2, 0x00f3, 0x00f4, 0x00f6, 0x00f8]
elif c == 's':
r = [0x0161]
elif c == 't':
r = [0x0167]
elif c == 'u':
r = [0x00fc]
elif c == 'z':
r = [0x017e]
else:
r = []
if tld == 'dk':
# allowed chars for .dk domains
# Source: https://www.dk-hostmaster.dk/en/faqs/what-characters-can-i-use-domain-name
if c == 'a':
r = [0x00e4, 0x00e5, 0x00e6]
elif c == 'e':
r = [0x00e6, 0x00e9]
elif c == 'o':
r = [0x00f6, 0x00f8]
elif c == 'u':
r = [0x00fc]
else:
r = []
if tld == 'ch':
# allowed chars for .ch domains
# Source: https://www.nic.ch/faqs/idn/
if c == 'a':
r = [0x00e0, 0x00e1, 0x00e2, 0x00e3, 0x00e4, 0x00e6]
elif c == 'b':
r = [0x00fe]
elif c == 'c':
r = [0x00e7]
elif c == 'd':
r = [0x00f0]
elif c == 'e':
r = [0x00e6] + list(range(0x00e8, (0x00eb + 1))) + [0x0153]
elif c == 'i':
r = list(range(0x00ec, (0x00ef + 1)))
elif c == 'n':
r = [0x00f1]
elif c == 'o':
r = [0x00f0] + list(range(0x00f2, (0x00f6 + 1))) + [0x00f8, 0x0153]
elif c == 'p':
r = [0x00fe]
elif c == 'u':
r = list(range(0x00f9, (0x00fc + 1)))
elif c == 'y':
r = [0x00fd, 0x00ff]
else:
r = []
if tld == 'de':
# allowed chars for .de domains
# Source: https://www.denic.de/wissen/idn-domains/idn-zeichenliste/
if c == 'a':
r = list(range(0x00e0, (0x00e6 + 1))) + [0x0101, 0x0103, 0x0105]
elif c == 'b':
r = [0x00df, 0x00fe]
elif c == 'c':
r = [0x00e7, 0x0107, 0x0109, 0x010B, 0x010D]
elif c == 'd':
r = [0x010f, 0x0111]
elif c == 'e':
r = [0x00e6, 0x00e8, 0x00e9, 0x00ea, 0x00eb, 0x0113, 0x0115, 0x0117, 0x019, 0x011b, 0x0153]
elif c == 'f':
r = [0x0155]
elif c == 'g':
r = [0x011d, 0x011f, 0x0121, 0x0123]
elif c == 'h':
r = [0x0125, 0x0127]
elif c == 'i':
r = list(range(0x00ec, (0x00ef + 1))) + [0x0129, 0x012b, 0x012d, 0x012f, 0x0131]
elif c == 'j':
r = [0x012f, 0x0135]
elif c == 'k':
r = [0x0137, 0x0138]
elif c == 'l':
r = [0x013a, 0x013c, 0x013e, 0x0142]
elif c == 'n':
r = [0x00f1, 0x0144, 0x0146, 0x0148, 0x014b]
elif c == 'o':
r = [0x00f0] + list(range(0x00f2, (0x00f6 + 1))) + [0x00f8, 0x014d, 0x014f, 0x0151, 0x0153]
elif c == 'p':
r = [0x00fe]
elif c == 'r':
r = [0x0155, 0x0157, 0x0159]
elif c == 's':
r = [0x00df, 0x015b, 0x015d, 0x015f, 0x0161]
elif c == 't':
r = [0x0163, 0x0165, 0x0167]
elif c == 'u':
r = list(range(0x00f9, (0x00fc + 1))) + [0x0169, 0x016b, 0x016d, 0x016f, 0x0171, 0x0173]
elif c == 'w':
r = [0x0175]
elif c == 'y':
r = [0x00fd, 0x00ff, 0x0177]
elif c == 'z':
r = [0x017a, 0x017c, 0x017e]
else:
r = []
if tld in ['fr', 're', 'pm', 'wf', 'tf', 'yt']:
# allowed chars for AFNIC controlled domains
# Source: https://www.afnic.fr/en/products-and-services/services/idn-convertor/
if c == 'a':
r = [0x00e0, 0x00e1, 0x00e2, 0x00e3, 0x00e4, 0x00e6]
elif c == 'b':
r = [0x00fe]
elif c == 'c':
r = [0x00e7]
elif c == 'e':
r = [0x00e6] + list(range(0x00e8, (0x00eb + 1))) + [0x0153]
elif c == 'i':
r = list(range(0x00ec, (0x00ef + 1)))
elif c == 'n':
r = [0x00f1]
elif c == 'o':
r = [0x00f0] + list(range(0x00f2, (0x00f6 + 1))) + [0x00f8, 0x0153]
elif c == 'u':
r = list(range(0x00f9, (0x00fc + 1)))
elif c == 'y':
r = [0x00fd, 0x00ff]
else:
r = []
if tld == 'org':
if lang_code == 'is': # Icelandic - source: http://de.pir.org/pdf/idn/policy_form_is-1.pdf
if c == 'a':
r = [0x00e1, 0x00e6]
elif c == 'b':
r = [0x00fe]
elif c == 'e':
r = [0x00e6, 0x00e9]
elif c == 'i':
r = [0x00ed]
elif c == 'o':
r = [0x00f0, 0x00f3, 0x00f6]
elif c == 'p':
r = [0x00fe]
elif c == 'u':
r = [0x00fa]
elif c == 'y':
r = [0x00fd]
else:
r = []
elif lang_code == 'de': # German - source: http://de.pir.org/pdf/idn/policy_form_de.pdf
if c == 'a':
r = [0x00e4]
elif c == 'o':
r = [0x00f6]
elif c == 'u':
r = [0x00fc]
else:
r = []
elif lang_code == 'da': # Danish - source: http://de.pir.org/pdf/idn/policy_form_da.pdf
if c == 'a':
r = [0x00e4, 0x00e5, 0x00e6]
elif c == 'e':
r = [0x00e6, 0x00e9]
elif c == 'o':
r = [0x00f6, 0x00f8]
elif c == 'u':
r = [0x00fc]
else:
r = []
elif lang_code == 'lv': # Latvian - source: http://de.pir.org/pdf/idn/policy_form_lv.pdf
if c == 'a':
r = [0x0101]
elif c == 'c':
r = [0x010d]
elif c == 'e':
r = [0x0113]
elif c == 'g':
r = [0x0123]
elif c == 'i':
r = [0x012b]