🔨 Some tools to (try to) break "Magic Hashes" https://git.forestier.app/HorlogeSkynet/MagicHashes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.7 KiB

  1. #!/usr/bin/env python3
  2. """
  3. This program intents to "break" _magic_ hashes for the SHA-2 algorithms family.
  4. It will generate random strings, only containing printable ASCII characters.
  5. If a magic hash is found, it will create a text file and will write down the match.
  6. """
  7. import hashlib
  8. import random
  9. import re
  10. import string
  11. if __name__ == '__main__':
  12. # Generate "plausible" password strings, between 4 and 32-character long.
  13. BOUNDS = (4 + 1, 32 + 1)
  14. POOL = string.ascii_letters + string.digits + string.punctuation
  15. # _______________________________________________________________________
  16. # "Magic Hashes" format.
  17. PATTERN = re.compile(r'^0+e\d+$')
  18. # ______________________
  19. # Hash methods to search against.
  20. HASH_METHODS = [
  21. hashlib.sha224,
  22. hashlib.sha256,
  23. hashlib.sha384,
  24. hashlib.sha512
  25. ]
  26. # _______________________________
  27. while True:
  28. # Let's generate a random string !
  29. # pylint: disable=C0103
  30. random_string = ''.join(
  31. random.choice(POOL) for _ in range(random.randint(*BOUNDS))
  32. ).encode()
  33. # ________________________________
  34. # Compute hashes over here.
  35. for hash_method in HASH_METHODS:
  36. digest = hash_method(random_string).hexdigest()
  37. if re.search(PATTERN, digest):
  38. with open('magic_hashes.txt', 'a') as f_magic:
  39. f_magic.write(
  40. '[{0}]\t{1}\t{2}\n'.format(
  41. hash_method.__name__,
  42. random_string.decode(),
  43. digest
  44. )
  45. )
  46. # _________________________