예제 #1
0
 def save_db(self):
     lock.acquire()
     db_conn = database.connect_db()
     table_name = self.domain.replace('.', '_')
     database.create_table(db_conn, table_name)
     source, results = self.results
     database.save_db(db_conn, table_name, results, source)  # 将结果存入数据库中
     lock.release()
예제 #2
0
    def run(self, rx_queue=None):
        self.domains = utils.get_domains(self.target)
        while self.domains:
            self.domain = self.domains.pop()
            start = time.time()
            db_conn = database.connect_db()
            table_name = self.domain.replace('.', '_')
            database.create_table(db_conn, table_name)
            if not rx_queue:
                rx_queue = queue.Queue()
            logger.log('INFOR', f'开始执行{self.source}模块爆破域名{self.domain}')
            logger.log(
                'INFOR',
                f'{self.source}模块使用{self.processes}个进程乘{self.coroutine}个协程')
            # logger.log('INFOR', f'{self.source}模块使用个进程乘{self.coroutine}个协程')
            if self.recursive_brute and not self.fuzz:  # fuzz模式不使用递归爆破
                logger.log('INFOR', f'开始递归爆破{self.domain}的第1层子域')
            loop = asyncio.get_event_loop()
            asyncio.set_event_loop(loop)
            loop.run_until_complete(self.main(self.domain, rx_queue))

            # 递归爆破下一层的子域
            if self.recursive_brute and not self.fuzz:  # fuzz模式不使用递归爆破
                for layer_num in range(
                        1,
                        self.recursive_depth):  # 之前已经做过1层子域爆破 当前实际递归层数是layer+1
                    logger.log('INFOR',
                               f'开始递归爆破{self.domain}的第{layer_num + 1}层子域')
                    for subdomain in self.subdomains.copy():
                        if subdomain.count('.') - self.domain.count(
                                '.') == layer_num:  # 进行下一层子域爆破的限制条件
                            loop.run_until_complete(
                                self.main(subdomain, rx_queue))

            while not rx_queue.empty():  # 队列不空就一直取数据存数据库
                source, results = rx_queue.get()
                database.save_db(db_conn, table_name, results,
                                 source)  # 将结果存入数据库中
            database.copy_table(db_conn, table_name)
            database.deduplicate_subdomain(db_conn, table_name)
            database.remove_invalid(db_conn, table_name)

            end = time.time()
            self.elapsed = round(end - start, 1)
            logger.log('INFOR', f'结束执行{self.source}模块爆破域名{self.domain}')
            logger.log(
                'INFOR',
                f'{self.source}模块耗时{self.elapsed}秒发现{self.domain}的域名{len(self.subdomains)}个'
            )
            logger.log(
                'DEBUG',
                f'{self.source}模块发现{self.domain}的的域名 {self.subdomains}')
예제 #3
0
    def run(self, rx_queue=None):
        """
        类运行入口
        """
        start = time.time()
        self.get_mod()
        self.import_func()

        if not rx_queue:
            rx_queue = queue.Queue(maxsize=len(self.collect_func))  # 结果集队列
        threads = []
        # 创建多个子域收集线程
        for collect_func in self.collect_func:
            thread = threading.Thread(target=collect_func,
                                      args=(self.domain, rx_queue),
                                      daemon=True)
            threads.append(thread)
        # 启动所有线程
        for thread in threads:
            thread.start()
        # 等待所有线程完成
        for thread in threads:
            thread.join()

        db_conn = database.connect_db()
        table_name = self.domain.replace('.', '_')
        database.create_table(db_conn, table_name)
        database.copy_table(db_conn, table_name)
        database.deduplicate_subdomain(db_conn, table_name)
        database.remove_invalid(db_conn, table_name)
        db_conn.close()
        # 数据库导出
        if self.export:
            if not self.path:
                self.path = config.result_save_path.joinpath(
                    f'{self.domain}.{self.format}')
            dbexport.export(table_name, path=self.path, format=self.format)
        end = time.time()
        self.elapsed = round(end - start, 1)