2012/02/22

#18. Renew TOR identity in python with vidalia bundle to automate worldwide testing of your website

First of all you need to have the Vidalia Bundle, and configure the torrc config file, find the value HashedControlPassword and uncomment it, next you need to create the hashed password, to do it, you can execute in a command line "tor --hash-password {pass}"
Copy the hash and save it in the config file. Restart Vidalia.
Taken this code from Moshe Basanchig, I've written this code wich authenticates against TOR:

def renewTorIdentity(self, passAuth):
try:
s = socket.socket()
s.connect(('localhost', 9051))
s.send('AUTHENTICATE "{0}"\r\n'.format(passAuth))
resp = s.recv(1024)
if resp.startswith('250'):
s.send("signal NEWNYM\r\n")
resp = s.recv(1024)
if resp.startswith('250'):
print "Identity renewed"
else:
print "response 2:", resp
else:
print "response 1:", resp
except Exception as e:
print "Can't renew identity: ", e
view raw renew.py hosted with ❤ by GitHub


Be careful, you should pass to the function the password you created the hash for, not the hashed string!. Also check out this book, it is a good and fast read:

1 comment:

Post a Comment