コード例 #1
0
    def main(self):
        '''
        Initialization of logger system and banner ascii.
        http://www.figlet.org/examples.html
        '''
        fonts = ['slant','doom','avatar', 'barbwire', 'big', 'bigchief', 'binary', 'calgphy2', 'chunky', 'colossal', 'computer','cosmic','cosmike','cyberlarge','digital','doh','dotmatrix',
                 'drpepper', 'eftitalic','eftiwater','epic','gothic','isometric1','invita', 'isometric2','isometric3', 'isometric4','larry3d', 'lean','linux','madrid','mini','ntgreek', 'ogre',
                 'poison','puffy','roman','rounded','runyc','script','shadow','slscript','small','speed','standard','starwars','straight','twopoint','univers','weird']
        bannerTortazo = Figlet(font=random.choice(fonts))
        print bannerTortazo.renderText('Tortazo v %s.%s' %(tortazoConfiguration.tortazo_majorversion,tortazoConfiguration.tortazo_minorversion) )

        bannerAuthor = Figlet(font='digital')
        print bannerAuthor.renderText('By Adastra ' )
        print bannerAuthor.renderText('@jdaanial \n' )

        self.logger = log
        self.exitNodes = []
        if tortazoConfiguration.dbPostgres:
            self.database = TortazoPostgreSQL()
        elif tortazoConfiguration.dbMySQL:
            self.database = TortazoMySQL()
        else:
            self.database = TortazoSQLiteDB()

        if self.verbose:
            self.logger.basicConfig(format="%(levelname)s: %(message)s", level=log.DEBUG)
            self.logger.debug(term.format("[+] Verbose mode activated.", term.Color.GREEN))
        self.logger.info(term.format("[+] Process started at " + strftime("%Y-%m-%d %H:%M:%S", gmtime()), term.Color.YELLOW))

        if self.cleanDatabase:
            self.logger.info(term.format("[+] Cleaning database... Deleting all records.", term.Color.YELLOW))
            self.database.initDatabase()
            self.database.cleanDatabaseState()

        if self.listPlugins:
            print "[*] Plugins list... "
            import pluginsDeployed
            for plugin in pluginsDeployed.plugins.keys():
                completeModulePath = pluginsDeployed.plugins.get(plugin)
                pluginModule = completeModulePath[:completeModulePath.rfind(".")]
                module = __import__(pluginModule)
                components = completeModulePath.split('.')
                for comp in components[1:]:
                    module = getattr(module, comp)
                inst = module([])
                print "Plugin package: %s" %(completeModulePath)
                print "Plugin Name: %s" %(inst.name)
                print "Plugin Description: %s" %(inst.desc)
                print "Plugin Version: %s" %(inst.version)
                print "Plugin Author: %s" %(inst.author)
                print "Plugin Arguments Available: %s" %(inst.pluginConfigs.keys())
                print "\n"
            return

        if self.torLocalInstance:
            if os.path.exists(self.torLocalInstance) and os.path.isfile(self.torLocalInstance):
                torrcFile = open(self.torLocalInstance,'r')
                torConfig = {}
                import pwd

                if pwd.getpwuid(os.getuid()).pw_uid != 0:
                    #Running TOR as non-root user. GOOD!
                    for line in torrcFile:
                        if line.startswith("#", 0, len(line)) is False and len(line.split()) > 0:
                            torOptionName = line.split()[0]
                            if len(line.split()) > 1:
                                torOptionValue = line[len(torOptionName)+1 : ]
                                torConfig[torOptionName] = torOptionValue
                    try:
                        self.logger.info(term.format("[+] Starting TOR Local instance with the following options: ", term.Color.YELLOW))
                        for config in torConfig.keys():
                            self.logger.info(term.format("[+] Config: %s value: %s " %(config, torConfig[config]), term.Color.YELLOW))
                        self.torProcess = stem.process.launch_tor_with_config(config = torConfig, tor_cmd = tortazoConfiguration.torExecutablePath, init_msg_handler=self.logsTorInstance)
                        time.sleep(5)
                        if self.torProcess > 0:
                            #If SocksListenAddress or SocksPort properties are empty but the process has been started, the socks proxy will use the default values.
                            self.logger.debug(term.format("[+] TOR Process created. PID %s " %(self.torProcess.pid),  term.Color.GREEN))
                            if torConfig.has_key('SocksListenAddress'):
                                self.socksHost = torConfig['SocksListenAddress']
                            else:
                                self.socksHost = '127.0.0.1'
                            if torConfig.has_key('SocksPort'):
                                self.socksPort = torConfig['SocksPort']
                            else:
                                #Starting TOR from the command "tor". The default Socks port in that case is '9050'. If you run tor with tor bundle, the default socks port is '9150'
                                self.socksPort = '9050'
                    except OSError, ose:
                        print sys.exc_info()
                        #OSError: Stem exception raised. Tipically, caused because the "tor" command is not in the path.
                        exc_type, exc_value, exc_traceback = sys.exc_info()
                        self.logger.warn(term.format("Exception raised during the startup of TOR Local instance.... "+str(ose), term.Color.RED))
                        self.logger.warn(term.format("Details Below: \n", term.Color.RED))
                        self.logger.warn(term.format("Type: %s " %(str(exc_type)), term.Color.RED))
                        self.logger.warn(term.format("Value: %s " %(str(exc_value)), term.Color.RED))
                        self.logger.warn(term.format("Traceback: %s " %(str(exc_traceback)), term.Color.RED))
                else:
                    self.logger.warn(term.format("You cannot run TOR as root user! Please, use an account with limited privileges ", term.Color.RED))
                    return

            else:
                self.logger.warn(term.format("The specified torrc file is not valid: %s " %(str(self.torLocalInstance)), term.Color.RED))