Advertisement
Guest User

Untitled

a guest
Jan 25th, 2013
851
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.22 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3.  
  4. import sys, hashlib
  5. from os import isatty
  6.  
  7. def usage(i=1):
  8.         print("Usage: ./cracktrunc.py hashlist < wordlist")
  9.         exit(i)
  10.  
  11. def compHash(hashlist, md5, plain):
  12.         for h in hashlist:
  13.                 if md5.startswith(h):
  14.                         print(h + ":" + plain.decode("utf-8"))
  15.                         return [x for x in hashlist if x != h]
  16.         return hashlist
  17.  
  18.  
  19. if len(sys.argv) is not 2:
  20.         usage()
  21.  
  22. hashlist = sys.argv[1]
  23.  
  24. # we only want to read files, no interactive input
  25. if isatty(0):
  26.         usage()
  27.  
  28. # make stream binary, hahslib needs binary data
  29. stdin = sys.stdin.detach()
  30.  
  31. with open(hashlist, "r") as f:
  32.         hashlist = list(map(lambda x: x.rstrip("\r\n"), list(f)))
  33.         for word in stdin:
  34.                 # remove newline stuff
  35.                 word = word.rstrip(b"\r\n")
  36.                 # hash the candidate
  37.                 md5 = hashlib.md5(word).hexdigest()
  38.                 hashlist = compHash(hashlist, md5, word)
  39.                 if not hashlist:
  40.                         print("Everything recovered.")
  41.                         exit(0)
  42.  
  43. print("### Not found ###")
  44. for h in hashlist:
  45.         print(h)
  46. exit(5)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement