Advertisement
Guest User

Untitled

a guest
May 26th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.42 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. """
  3. maskify.py
  4.  
  5. Creates password categorization masks from big password lists
  6. in a multithreaded fashion. Note that it assumes you have enough
  7. RAM to hold the unique mask dict in memory. Used to analyze a 300M+
  8. unique password list for types and occurrences.
  9.  
  10. On an ODROID-C2, runs at about 50-52K passwords/sec.
  11.  
  12. Output file is mask like:
  13.  
  14. ?l?l?l?l?l?d:n
  15.  
  16. where n is the number of occurrences of this mask.
  17. """
  18.  
  19. from multiprocessing import Pool, cpu_count
  20. import re
  21. import sys
  22. import time
  23.  
  24. NUM_THREADS = cpu_count()
  25. WORK_BLOCK_SIZE = 1024
  26.  
  27. LOWERCASE = "etaoinshrdlcumwfgypbvkjxqz" #?l
  28. UPPERCASE = "ETAOINSHRDLCUMWFGYPBVKJXQZ" #?L
  29. NUMBER = "0123456789" #?d
  30. PUNCT_1 = "~!@#$%^&*()_+" #?t
  31. PUNCT_2 = "`[];',./-=\\ " #?c
  32. PUNCT_3 = ":\"<>?|{}" #?C
  33.  
  34. PATTERNS = {
  35. "?l": LOWERCASE,
  36. "?L": UPPERCASE,
  37. "?d": NUMBER,
  38. "?t": PUNCT_1,
  39. "?c": PUNCT_2,
  40. "?C": PUNCT_3
  41. }
  42.  
  43. def worker(line):
  44. """Make a pattern from a line or lines"""
  45. pat = ""
  46. patlen = 0
  47. for char in line:
  48. # uncomment the below block if you want to short circuit at a length of 16
  49. """
  50. if patlen == 16:
  51. break
  52. """
  53. for pattern_key in PATTERNS:
  54. if char in PATTERNS[pattern_key]:
  55. patlen += 1
  56. pat += str(pattern_key)
  57. return pat
  58.  
  59. if __name__ == '__main__':
  60. if len(sys.argv) != 3:
  61. print("Usage: maskify.py input_pwlist output_masklist")
  62. sys.exit(1)
  63. start = time.time()
  64. print("Utilising %d cores for processing." % NUM_THREADS)
  65.  
  66. p = Pool(NUM_THREADS)
  67. u = dict()
  68. f = open(sys.argv[1], 'r')
  69. length_warn = False
  70.  
  71. interval = 0
  72. checked = 0
  73. with p:
  74. patterns = p.imap_unordered(worker, f, WORK_BLOCK_SIZE)
  75. for pat in patterns:
  76. checked += 1
  77.  
  78. if pat not in u:
  79. u[pat] = 1
  80. else:
  81. u[pat] += 1
  82.  
  83. now = time.time()
  84. if interval == 0 or (interval + 5) < now:
  85. print("Processing. Speed: %f patterns/sec" % (checked / 5.0), end="\r")
  86. interval = now
  87. checked = 0
  88.  
  89.  
  90. print("\nSaving unique patterns to disk")
  91. with open(sys.argv[2], 'w') as g:
  92. for pattern in u:
  93. if pattern == '':
  94. continue
  95. g.write("%s:%d\n" % (pattern, u[pattern]))
  96. diff = time.time() - start
  97. print("Done. Took %f sec." % diff)
  98. sys.exit(0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement