Exemplo n.º 1
0
 def _init_db(self):
     """
     初始化数据库
     """
     model_prefix = self.target_host + "_" + str(self.target_port)
     self.new_scan_model = NewRequestModel(model_prefix)
     self.new_scan_model.reset_unscanned_item()
     report_model = ReportModel(model_prefix)
     Communicator().set_internal_shared("report_model", report_model)
def scan_plugin_fixture():
    
    report_model = ReportModel("www.test-host.com_80")
    Communicator().set_internal_shared("report_model", report_model)

    plugin_ins = sql_basic.ScanPlugin()

    plugin_ins.send_request = types.MethodType(send_request, plugin_ins)
    plugin_ins.report = types.MethodType(report, plugin_ins)

    yield plugin_ins
Exemplo n.º 3
0
 def _init_db(self):
     """
     初始化数据库
     """
     model_prefix = self.target_host + "_" + str(self.target_port)
     self.new_scan_model = NewRequestModel(
         model_prefix, multiplexing_conn=True)
     self.new_scan_model.reset_unscanned_item()
     report_model = ReportModel(model_prefix, multiplexing_conn=True)
     Communicator().set_internal_shared("report_model", report_model)
     Communicator().set_internal_shared("failed_task_set", set())
    def clean_target(self, host, port, url_only=False):
        """
        清空目标对应的数据库,同时重置预处理lru

        Parameters:
            host - str, 目标host
            port - int, 目标port
            url_only - bool, 是否仅清空url
        
        Raises:
            exceptions.DatabaseError - 数据库出错时引发此异常
        """
        table_prefix = host + "_" + str(port)
        if url_only:
            NewRequestModel(table_prefix,
                            multiplexing_conn=True).truncate_table()
        else:
            NewRequestModel(table_prefix, multiplexing_conn=True).drop_table()
            ReportModel(table_prefix, multiplexing_conn=True).drop_table()
            self.config_model.delete(table_prefix)
        Communicator().set_clean_lru([table_prefix])
Exemplo n.º 5
0
    def clean_target(self, host, port, url_only=False):
        """
        清空目标对应的数据库,同时重置预处理lru

        Parameters:
            host - str, 目标host
            port - int, 目标port
            url_only - bool, 是否仅清空url

        Raises:
            exceptions.DatabaseError - 数据库出错时引发此异常
        """
        host_port = common.concat_host(host, port)
        if self._scanner_info.get_scanner_id(host_port) is not None:
            raise exceptions.TargetIsScanning
        if url_only:
            NewRequestModel(host_port, multiplexing_conn=True).truncate_table()
        else:
            NewRequestModel(host_port, multiplexing_conn=True).drop_table()
            ReportModel(host_port, multiplexing_conn=True).drop_table()
            self._config.del_config(host_port)
        Communicator().set_clean_lru([host_port])
Exemplo n.º 6
0
    async def get_report(self, host_port, page, perpage):
        """
        获取扫描结果

        Parameters:
            host_port - str, 获取的目标主机的 host + "_" + str(port) 组成
            page - int, 获取的页码
            perpage - int, 每页条数

        Returns:
            {"total":数据总条数, "data":[ RaspResult的json字符串, ...]}

        Raises:
            exceptions.DatabaseError - 数据库错误引发此异常
        """
        try:
            model = ReportModel(
                host_port, create_table=False, multiplexing_conn=True)
        except exceptions.TableNotExist:
            data = {"total": 0, "data": []}
        else:
            data = await model.get(page, perpage)
        return data