hash_1_15.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. def wordpress_passwd(password, salt, count, prefix, uppercase=False):
  2. """
  3. Reference(s):
  4. http://packetstormsecurity.org/files/74448/phpassbrute.py.txt
  5. http://scriptserver.mainframe8.com/wordpress_password_hasher.php
  6. >>> wordpress_passwd(password='testpass', salt='aD9ZLmkp', count=2048, prefix='$P$9aD9ZLmkp', uppercase=False)
  7. '$P$9aD9ZLmkpsN4A83G8MefaaP888gVKX0'
  8. """
  9. def _encode64(input_, count):
  10. output = ''
  11. i = 0
  12. while i < count:
  13. value = ord(input_[i])
  14. i += 1
  15. output = output + ITOA64[value & 0x3f]
  16. if i < count:
  17. value = value | (ord(input_[i]) << 8)
  18. output = output + ITOA64[(value >> 6) & 0x3f]
  19. i += 1
  20. if i >= count:
  21. break
  22. if i < count:
  23. value = value | (ord(input_[i]) << 16)
  24. output = output + ITOA64[(value >> 12) & 0x3f]
  25. i += 1
  26. if i >= count:
  27. break
  28. output = output + ITOA64[(value >> 18) & 0x3f]
  29. return output
  30. if isinstance(password, unicode):
  31. password = password.encode(UNICODE_ENCODING)
  32. cipher = md5(salt)
  33. cipher.update(password)
  34. hash_ = cipher.digest()
  35. for i in xrange(count):
  36. _ = md5(hash_)
  37. _.update(password)
  38. hash_ = _.digest()
  39. retVal = prefix + _encode64(hash_, 16)
  40. return retVal.upper() if uppercase else retVal