Hack Forums
[Python] MD5 Hash Cracker - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [Python] MD5 Hash Cracker (/showthread.php?tid=5451454)



MD5 Hash Cracker - bhop_alex - Nov 1, 2016

I'm just getting back into learning python. I wrote a bruteforce hash crack script, it is probably very unoptimized and would like critique/tips on what I could do better. Thanks!

PHP Code

<?php 
import hashlib
, string, time

def words
(chars=string.ascii_letters + string.digits):
    yield from 
chars
    
for word in words(chars):
        for 
char in chars:
            yield 
word + char
            
def hashcrack
(h):
    if 
len(h) == 32:
        
startTime = time.clock()
        print(
"Working...")
        for 
word in words('abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ`~!@#$%^&*()-=_+[]\{}|;:\'",./<>?'):
            
hash = hashlib.md5(word.encode('utf-8')).hexdigest()
            if 
hash == h:
                print(
"Success! The string was {}".format(word))
                print(
"Time taken: {}".format(time.clock()-startTime))
                
input()
    else:
        
hash = input("Try again, what is the hash?\n")
        
hashcrack(hash)
    
hash = input("What is the hash?\n")
hashcrack(hash) 



* - M5DD - Nov 2, 2016

use itertools, it's going to make your code a lot more easier


* - Goodies - Nov 2, 2016

You have no idea how slow this is just fyi...


* - bhop_alex - Nov 2, 2016

(Nov 2, 2016 02:28 PM)Goodies Wrote:  You have no idea how slow this is just fyi...

Any tips on improving speed? I do understand it is probably one of the the worst ways I could go about this, because I am pretty new to it.


* - M5DD - Nov 2, 2016

(Nov 2, 2016 03:25 PM)bhop_alex Wrote:  Any tips on improving speed? I do understand it is probably one of the the worst ways I could go about this, because I am pretty new to it.

To be honest, there really isn't a faster way to do this using python. You'd have to re-write your code in a native language as the python interpreter is rather slow.


* - Oowoosh0 - Nov 2, 2016

I guess it depends on what you want to achieve. Do you want to find fastest way to brute-force an md5 hash with python, just for fun and learning purposes, or do you want to actually crack an md5 hash. Because in that case you're probably better off not brute-forcing it and using another programming language.


* - Goodies - Nov 2, 2016

(Nov 2, 2016 03:25 PM)bhop_alex Wrote:  Any tips on improving speed? I do understand it is probably one of the the worst ways I could go about this, because I am pretty new to it.

Yeah. Use another langusge. If you're dead set in Python (I have no idea why you would be, but alright)

1) multiprocessing NOT MULTITHREADING
2) use native standard libraries like itertools
3) some GPU APIs have Python implementations. Maybe check those out.


* - bhop_alex - Nov 4, 2016

Thanks for the help, everyone!


* - 0xBD - Nov 13, 2016

(Nov 2, 2016 05:34 PM)M5DD Wrote:  To be honest, there really isn't a faster way to do this using python. You'd have to re-write your code in a native language as the python interpreter is rather slow.

Or just use a different interpreter.