bind to random control port

This commit is contained in:
Kevin 2018-09-07 13:57:20 -05:00
parent 67be0bebc2
commit a44d511e1d

View File

@ -21,7 +21,7 @@
import subprocess, os, random, sys, logger, time, signal, config, base64 import subprocess, os, random, sys, logger, time, signal, config, base64
from stem.control import Controller from stem.control import Controller
from onionrblockapi import Block from onionrblockapi import Block
from dependencies import secrets
class NetController: class NetController:
''' '''
This class handles hidden service setup on Tor and I2P This class handles hidden service setup on Tor and I2P
@ -69,6 +69,8 @@ class NetController:
plaintext = base64.b64encode(os.urandom(50)).decode() plaintext = base64.b64encode(os.urandom(50)).decode()
config.set('tor.controlpassword', plaintext, savefile=True) config.set('tor.controlpassword', plaintext, savefile=True)
controlPort = random.randint(1025, 65535)
hashedPassword = subprocess.Popen([self.torBinary, '--hash-password', plaintext], stdout=subprocess.PIPE, stderr=subprocess.PIPE) hashedPassword = subprocess.Popen([self.torBinary, '--hash-password', plaintext], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
for line in iter(hashedPassword.stdout.readline, b''): for line in iter(hashedPassword.stdout.readline, b''):
password = line.decode() password = line.decode()
@ -80,7 +82,7 @@ HiddenServiceDir data/hs/
HiddenServicePort 80 127.0.0.1:''' + str(self.hsPort) + ''' HiddenServicePort 80 127.0.0.1:''' + str(self.hsPort) + '''
DataDirectory data/tordata/ DataDirectory data/tordata/
CookieAuthentication 1 CookieAuthentication 1
ControlPort 9051 ControlPort ''' + str(controlPort) + '''
HashedControlPassword ''' + str(password) + ''' HashedControlPassword ''' + str(password) + '''
''' '''
torrc = open(self.torConfigLocation, 'w') torrc = open(self.torConfigLocation, 'w')