-
-
Save brownan/1506289 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from overviewer_core import dispatcher | |
from overviewer_core import signals | |
import hashlib | |
import string | |
import os | |
import sys | |
import socket | |
def md5(s): | |
return hashlib.md5(s).hexdigest() | |
class HashChecker(object): | |
on_find = signals.Signal('HashChecker', 'on_find') | |
def __init__(self, length, letters=string.ascii_lowercase, hasher=md5, target="000"): | |
super(HashChecker, self).__init__() | |
self.length = length | |
self.letters = letters | |
self.num_letters = len(letters) | |
self.hasher = hasher | |
self.target = target | |
def do_preprocessing(self): | |
pass | |
def get_num_phases(self): | |
return 1 | |
def iterate_work_items(self, phase): | |
for length in xrange(self.length): | |
length = length + 1 | |
batch_size = 32 ** 4 | |
space_size = self.num_letters ** length | |
batches = space_size // batch_size | |
if space_size % batch_size > 0: | |
batches += 1 | |
i = 0 | |
while i < batches: | |
yield ((length, (batch_size * i, min(batch_size * (i + 1), space_size))), []) | |
i += 1 | |
def do_work(self, workobj): | |
length, min_max = workobj | |
print "=== checking length", length, "range", min_max | |
for i in xrange(*min_max): | |
source_letters = [] | |
while i != 0: | |
source_letters.append(i % self.num_letters) | |
i = i // self.num_letters | |
while len(source_letters) < length: | |
source_letters.append(0) | |
source = ''.join(map(lambda j: self.letters[j], source_letters)) | |
self.check_hash(source) | |
def check_hash(self, src): | |
hash = self.hasher(src) | |
if hash.startswith(self.target): | |
print "reporting", repr(src), "hashes to", hash | |
self.on_find(src, hash, os.getpid(), socket.gethostname()) | |
@HashChecker.on_find.register | |
def on_find_listener(src, hash, pid, hostname): | |
prefix = "[{1}:{0}]".format(pid, hostname) | |
while len(prefix) < 20: | |
prefix = prefix + " " | |
print prefix, "source", repr(src), "hashes to", hash | |
if __name__ == "__main__": | |
if "-server" in sys.argv: | |
d = dispatcher.MultiprocessingDispatcher(local_procs=0, address=('', 8010), authkey='hackme') | |
hash1 = HashChecker(8, target='deadbeef') | |
d.render_all([hash1], None) | |
d.close() | |
else: | |
processes = [] | |
import multiprocessing | |
for _ in xrange(multiprocessing.cpu_count()): | |
p = multiprocessing.Process(target=dispatcher.MultiprocessingDispatcher.start_manual_process, args=(('hesperus.gammalevel.com', 8010), 'hackme') | |
) | |
p.start() | |
processes.append(p) | |
import time | |
while True: | |
time.sleep(999999) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment