Skip to content

Instantly share code, notes, and snippets.

@mateusza
Last active January 8, 2019 23:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mateusza/2fd169b943679d05589e064e8f78f92a to your computer and use it in GitHub Desktop.
Save mateusza/2fd169b943679d05589e064e8f78f92a to your computer and use it in GitHub Desktop.
import sys
import sha
import base64
import time
import Crypto.PublicKey.RSA
cmd, prefix, suffix = map( lambda x:x.lower(), sys.argv + [ "", "" ] )[0:3]
print "usage: %s [PREFIX [SUFFIX]]" % cmd
print "searching for RSA keypair corresponding to TOR hostname [%s%s%s]:" % ( prefix, "_" * ( 16 - len(suffix+prefix)), suffix )
reqlen = len(suffix)+len(prefix)
reqspace = 32**reqlen
print "request len: %d" % reqlen
print "estimated space to search: %d" % reqspace
def hostname( privkey ):
return base64.b32encode( sha.sha( privkey.publickey().exportKey('DER')[22:] ).digest() ).lower()[:16]
def timeunit( t ):
if t < 100:
return (t, "s")
if t < 4000:
return (t//60, "min")
if t < 144000:
return (t//3600, "h")
if t < 3456000:
return (t//3600//24, "days")
return (100, "forever")
i=0
cols = 60
starttime = time.time()
while True:
key = Crypto.PublicKey.RSA.generate( 1024 )
name = hostname( key )
if name.startswith(prefix) and name.endswith(suffix):
print "FOUND [%s]" % name
break
i += 1
if i % 2 == 0:
tnow = time.time()
sys.stdout.write("\r")
sys.stdout.write("[%s%s%s] " % ( "=" * int( cols * 1.0 * i / reqspace), ">" if (i<reqspace) else "!", "." * int( cols * (1.0 - 1.0 * i / reqspace ) ) ) )
sys.stdout.write("%5.1f%% " % ( 100.0*i/reqspace ) )
sys.stdout.write("%.1f keys/s " % ( 1.0*i / (tnow-starttime) ) )
timeleft = timeunit( ( 0.0 + reqspace - i ) / i * ( 0.0+tnow-starttime) )
sys.stdout.write("ETA %d %s " % ( timeleft[0], timeleft[1]) )
sys.stdout.flush()
print "searched %d (%6.1f%%)" % ( i, 100.0 * i / (32**reqlen) )
pem = key.exportKey("PEM")
print "http://%s.onion/" % name
print pem
file("%s.key" % (name),"w").write( pem )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment