Skip to content

Instantly share code, notes, and snippets.

@agrif
Created December 21, 2011 11:36
Show Gist options
  • Save agrif/1505729 to your computer and use it in GitHub Desktop.
Save agrif/1505729 to your computer and use it in GitHub Desktop.
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
j = min_max[0]
while j < min_max[1]:
i = j
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)
j = j + 1
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:
dispatcher.MultiprocessingDispatcher.start_manual_process(('hesperus.gammalevel.com', 8010), 'hackme')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment