Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scraping md5s from webpage and comparing them against common password

Tags:

python

So i have the following code which scrapes through a given webpage and finds md5s using a regex (I know you never find md5s in the source code but its for a uni project). Once found the md5s it compares it against a list of common passwords which also get hashed. The problem is that its always returning that none of the md5s match which i know to be false.

If anyone could help that would be great however i feel like the problem is the inserting of md5 as it might no be iterable is my hunch.

md5s = re.findall(r'[a-zA-Z0-9]{32}',webpage.decode())
md5s.sort()
print (f'[+] {len(md5s)} md5s Found:')
for md5 in md5s:
    print(md5)

passwd_found = False

dic = []

for k in dic:
    md5hash = hashlib.md5(k.encode('utf-8'))
    #print(md5hash.hexdigest())
    if md5 in md5hash.hexdigest():
        passwd_found = True
    else:
        passwd_found = False

    if passwd_found:
         print (f'[+] Password recovered: {k}')
    else:
         print ('[-] Password not recovered')

OUTPUT FROM REGEX

`[+] 6 md5s Found: 5efweev789d3d1d09794d8f021f40f0e 5fcfd41e547aewfwefwefff47fdd3739 9d377b10ce778few2334c7g2c63a229a FEA0F1F6FEDE90BDfn89049194DEAC11 aDsxMzE0MDY7ajsx785g90f0MjAwOzQw d1133275ee2118b9739440f759fc0524

OUTPUT FROM COMPARISON

[-] Password not recovered
[-] Password not recovered
[-] Password not recovered
[-] Password not recovered
[-] Password not recovered
[-] Password not recovered
[-] Password not recovered
[-] Password not recovered
[-] Password not recovered
[-] Password not recovered
[-] Password not recovered
[-] Password not recovered
[-] Password not recovered
[-] Password not recovered
[-] Password not recovered
[-] Password not recovered
[-] Password not recovered
[-] Password not recovered
[-] Password not recovered
[-] Password not recovered
[-] Password not recovered
[-] Password not recovered
[-] Password not recovered
[-] Password not recovered
[-] Password not recovered
[-] Password not recovered
like image 285
J Doe Avatar asked Dec 09 '25 01:12

J Doe


1 Answers

In this code, what do you think is the value of md5?

for k in dic:
    md5hash = hashlib.md5(k.encode('utf-8'))
    #print(md5hash.hexdigest())
    if md5 in md5hash.hexdigest():
        passwd_found = True
    # ...

Before this snippet, md5 was used in a loop. At this point, the value of md5 is the last value from the previous loop. That's hardly what you want.

If you want to find the values of dic whose hashed value occurs in md5s (on the page you scraped), it will be better to do like this:

md5s = frozenset([m.lower() for m in md5s])
for k in dic:
    md5hash = hashlib.md5(k.encode('utf-8'))
    if md5hash.hexdigest() in md5s:
        print("found", k)

That is, turn md5s into a set, to make it fast to search in it, and then for each value in dic, check if its hashed value is contained in md5s.

like image 178
janos Avatar answered Dec 11 '25 15:12

janos



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!