Skip to content

Instantly share code, notes, and snippets.

@s4w3d0ff
Forked from james-see/torhasher.py
Last active July 2, 2021 06:41
Show Gist options
  • Save s4w3d0ff/9d65ec5866d78842547183601b2fa4d5 to your computer and use it in GitHub Desktop.
Save s4w3d0ff/9d65ec5866d78842547183601b2fa4d5 to your computer and use it in GitHub Desktop.
create a tor hashed password without using `tor --hash-password`
from os import urandom
from binascii import b2a_hex
from hashlib import sha1
def getTorPassHash(secret='password'):
'''
https://gist.github.com/jamesacampbell/2f170fc17a328a638322078f42e04cbc
'''
# static 'count' value later referenced as "c"
indicator = chr(96)
# generate salt and append indicator value so that it
salt = "%s%s" % (urandom(8), indicator)
c = ord(salt[8])
# generate an even number that can be divided in subsequent sections. (Thanks Roman)
EXPBIAS = 6
count = (16+(c&15)) << ((c>>4) + EXPBIAS)
d = sha1()
# take the salt and append the password
tmp = salt[:8]+secret
# hash the salty password
slen = len(tmp)
while count:
if count > slen:
d.update(tmp)
count -= slen
else:
d.update(tmp[:count])
count = 0
hashed = d.digest()
# Put it all together into the proprietary Tor format.
return '16:%s%s%s' % (b2a_hex(salt[:8]).upper(),
b2a_hex(indicator),
b2a_hex(hashed).upper())
if __name__ == '__main__':
print(getTorPassHash(raw_input("Type something: ")))
@007-JB
Copy link

007-JB commented Jul 2, 2021

NameError: name 'raw_input' is not defined

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment