Advertisement
Guest User

Untitled

a guest
Jan 21st, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.41 KB | None | 0 0
  1. from sys import argv, exit
  2. from time import time
  3. from hashlib import md5
  4. from itertools import product
  5. from datetime import datetime
  6. from string import ascii_lowercase, ascii_uppercase, digits
  7.  
  8. hash_ = "/home/thomas/TP1/shadow"
  9. special = '@_#'
  10. charset_ = '1'
  11. minlength = 6
  12. maxlength = 6
  13.  
  14. crack = []
  15.  
  16. charset = {"1": ascii_lowercase,
  17. "2": ascii_uppercase,
  18. "3": digits,
  19. "4": ascii_lowercase
  20. + ascii_uppercase,
  21. "5": ascii_lowercase
  22. + digits,
  23. "6": ascii_uppercase
  24. + digits,
  25. "7": ascii_lowercase
  26. + ascii_uppercase
  27. + digits,
  28. "8": ascii_lowercase
  29. + ascii_uppercase
  30. + digits
  31. + special
  32. }
  33. charset = charset[charset_]
  34.  
  35. colors = {"R":"\033[91m",
  36. "G":"\033[92m",
  37. "~":"\033[00m"
  38. }
  39.  
  40.  
  41.  
  42. def bruteforce(hash_, characters, min_length, max_length):
  43.  
  44. start = datetime.now()
  45. start_time = time()
  46.  
  47. for length in range(int(min_length), int(max_length) + 1):
  48. products = product(characters, repeat=length)
  49. for attempt in products:
  50. hashed = "".join(attempt).encode("utf-8")
  51. hashed = md5(hashed).hexdigest()
  52.  
  53. with open(hash_) as fileobj:
  54. for line in fileobj:
  55. password = line.split(':')
  56. crack.append(password[1][3:])
  57. i = 4
  58. while i < len(crack):
  59. hash = crack[i]
  60. if hashed != hash:
  61. #print(f"{colors['R']}{''.join(attempt)}")
  62. next
  63.  
  64. else:
  65. diff = int(time()-start_time)
  66. print(f"{colors['G']}{''.join(attempt)}")
  67. print(colors["~"])
  68. print(" Statistics")
  69. print("~~~~~~~~~~~~~~~~~")
  70. print(f"Started: {start}")
  71. print(f"Calculation time: {diff} seconds")
  72. print(f"Original hash: {crack[i]}")
  73. print(f"Found string: {''.join(attempt)}")
  74. print("~~~~~~~~~~~~~~~~~")
  75. return True
  76. i = i + 1
  77.  
  78.  
  79. def main():
  80. bruteforce(hash_, charset, minlength, maxlength)
  81.  
  82. if __name__ == "__main__":
  83. main()
  84. exit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement