Created
June 6, 2012 20:10
-
-
Save joshz/2884420 to your computer and use it in GitHub Desktop.
play with the linkedin password hash file
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
import hashlib | |
import shelve | |
def trim_hash(hash, offset=5): | |
"""outputs truncated hash | |
""" | |
return '0' * offset + hash[offset:] | |
def write_word_to_shelf(shelf_fn, wordfile): | |
"""write hashes of words in wordfile | |
to shelf, both 0 prefixed and full | |
""" | |
shelf = shelve.open(shelf_fn) | |
with open(wordfile, 'r') as f: | |
for line in f: | |
l = line.strip() | |
ph = hashlib.sha1(l).hexdigest() | |
shelf[ph] = l | |
shelf[trim_hash(ph)] = l | |
shelf.close() | |
def write_mine(pwd, shelf_fn): | |
"""adds your password to shelf | |
""" | |
shelf = shelve.open(shelf_fn) | |
h = hashlib.sha1(pwd).hexdigest() | |
shelf[h] = pwd | |
shelf[trim_hash(h)] = pwd | |
shelf.close() | |
print trim_hash(h), h | |
def dump(shelf_fn, out_fn, linkedin_hashes='combo_not.txt'): | |
"""dump 0 prefixed and full sha1 hashes to Python | |
shelf. | |
hash is either 0 prefixed or full, so it contains both | |
shelf[00000abcd...] = passwd1 | |
shelf[12345abcd...] = passwd1 | |
""" | |
shelf = shelve.open(shelf_fn) | |
with open(out_fn, 'w') as w: | |
with open(linkedin_hashes, 'r') as f: | |
for i, line in enumerate(f): | |
l = line.strip() | |
try: | |
v = shelf[l] | |
print '%s : %s' % (v, l) | |
w.write('%s : %s\n' % (v, l)) | |
except KeyError: | |
pass | |
shelf.close() | |
def check(p, linkedin_hashes='combo_not.txt'): | |
"""check if single password p is in file | |
""" | |
h = hashlib.sha1(p).hexdigest() | |
ph = trim_hash(h) | |
c = (h, ph) | |
with open(linkedin_hashes, 'r') as f: | |
for line in f: | |
if line.strip() in c: | |
print 'bummer' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment