-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpassword_bruteforce.py
43 lines (31 loc) · 1.65 KB
/
password_bruteforce.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
"""
SenPy can, of course, be useful in applications that aren't Data Science related.
In fact it can be used for any long computation you encounter in python, especially
if it is difficult to estimate the time required to perform the task.
Here's an example in cryptography with brute force of a password using hashes,
which is a traditional cyber security class exercise.
"""
import requests
import hashlib
from senpy import notify_me, ntm
# fetch the common passwords online
COMMON_PASSWORDS = str(requests.get("https://raw.githubusercontent.com/danielmiessler/SecLists/master/Passwords/probable-v2-top12000.txt").content).split('\\')
SEEKED_HASH = '5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8'
def hash(password):
result = hashlib.sha1(password.encode())
return result.hexdigest()
def bruteforce(common_password_list, actual_password_hash):
# ========================================= #
with ntm(common_password_list, disable_end_message=True) as common_passwords:
# with ntm, SenPy let's you keep track of the amount of hashed studied
# we don't want the basic end message to be send, we send our own with
# a string of our own
# ========================================== #
for guess_password in common_passwords:
if hash(guess_password) == actual_password_hash:
return guess_password
if __name__ == '__main__':
password = bruteforce(COMMON_PASSWORDS, SEEKED_HASH)
# with notify_me, SenPy let's you know when the script is done and
# if it returned a successful result
notify_me(f"password found : {password}" if password is not None else "None of the common passwords matched")