i trying write python sha512 brute forcer.
i use queue store values in wordlist , compare them against encrypted hash.
the problem that, instead of values being popped out of queue, reused other threads. basically, instead of having whole work split between threads make things faster, got several threads doing exact same thing. how can fix this?
i want this: https://github.com/willpennell/python/blob/master/black-hat-python/bhp-code/chapter5/content_bruter.py#l20
import threading import thread import queue import os,sys import crypt import codecs datetime import datetime,timedelta import argparse today = datetime.today() resume = none threads = 5 def build_wordlist(wordlist_file): fd = open(wordlist_file,"rb") raw_words = fd.readlines() fd.close() found_resume = false words = queue.queue() word in raw_words: word = word.rstrip() if resume not none: if found_resume: words.put(word) else: if word == resume: found_resume = true print "resuming wordlist from: %s" % resume else: words.put(word) return words def testpass(cryptpass,user): word_queue = build_wordlist('test.txt') while not word_queue.empty(): attempt = word_queue.get() ctype = cryptpass.split("$")[1] if ctype == '6': print "[+] hash type sha-512 detected ..." salt = cryptpass.split("$")[2] insalt = "$" + ctype + "$" + salt + "$" word = attempt cryptword = crypt.crypt(word,insalt) if (cryptword == cryptpass): time = time = str(datetime.today() - today) print "[+] found password user: " + user + " ====> " + word + " time: "+time+"\n" return print "password not found user: " + user print "moving on next user..." exit def main(): parse = argparse.argumentparser(description='a simple brute force /etc/shadow .') parse.add_argument('-f', action='store', dest='path', help='path shadow file, example: \'/etc/shadow\'') argus=parse.parse_args() if argus.path == none: parse.print_help() exit else: build_wordlist('test.txt') passfile = open (argus.path,'r') line in passfile.readlines(): line = line.replace("\n","").split(":") if not line[1] in [ 'x' , '*' , '!' ]: user = line[0] cryptpass = line[1] in range(threads): t = threading.thread(target=testpass,args=(cryptpass,user)) t.daemon = true t.start() if __name__=="__main__": main()
edit: realized there 2 ways can this: first, can create thread each user, not want. second, can split work of each user through several threads, want.
this can solved using classic producer , consumer problem. may find solution producer , consumer problem in python useful.
Comments
Post a Comment