Example #1
0
 def __iterate_data(self, identities = None, data_type = None, data_subtype = None):
     if identities is None:
         identities = list(Database.keys(data_type))
     if identities:
         for page in xrange(0, len(identities), 100):
             for data in Database.get_many(identities[page:page + 100], data_type):
                 yield data
Example #2
0
    def do_scan_details(self, id_list):
        """
        Implementation of: /scan/details

        :param id_list: List of result IDs.
        :type id_list: list(str)
        """
        return Database.get_many(id_list)
Example #3
0
 def __iterate_data(self,
                    identities=None,
                    data_type=None,
                    data_subtype=None):
     if identities is None:
         identities = list(Database.keys(data_type, data_subtype))
     if identities:
         for page in xrange(0, len(identities), 100):
             for data in Database.get_many(identities[page:page + 100]):
                 yield data
Example #4
0
def test_import():
    print "Testing OpenVAS importer..."
    orchestrator_config = OrchestratorConfig()
    orchestrator_config.ui_mode = "disabled"
    audit_config = AuditConfig()
    audit_config.targets  = ["192.168.56.101"]
    audit_config.audit_db = ":memory:"
    with PluginTester(orchestrator_config, audit_config) as t:
        t.run_plugin("import/xml_openvas", path.join(here, "test_openvas.xml"))
        results = Database.get_many( Database.keys(Data.TYPE_VULNERABILITY) )
        assert len(results) == 1, len(results)
        v = results[0]
        assert v.level == "informational", v.level
        assert v.plugin_id == "import/xml_openvas", v.plugin_id
        assert "Remote web server does not reply with 404 error code." in v.description, v.description
    def do_audit_details(self, audit_name, id_list): # TODO: control audits with error at start
        """
        Implementation of: /audit/details

        :param audit_name: Name of the audit to query.
        :type audit_name: str

        :param id_list: List of result IDs.
        :type id_list: list(str)
        """
        if self.is_audit_running(audit_name):
            with SwitchToAudit(audit_name):
                return Database.get_many(id_list)
        else:
            # XXX TODO open the database manually here
            raise NotImplementedError(
                "Querying finished audits is not implemented yet!")
Example #6
0
    def common_get_resources(self, data_type=None, data_subtype=None):
        """
        Get a list of datas.

        :return: List of resources.
        :rtype: list(Resource)
        """
        # Get each resource
        m_resource = None
        m_len_urls = Database.count(data_type, data_type)
        if m_len_urls < 200:   # increase as you see fit...
            # fast but memory consuming method
            m_resource   = Database.get_many( Database.keys(data_type=data_type, data_subtype=data_subtype))
        else:
            # slow but lean method
            m_resource   = Database.iterate(data_type=data_type, data_subtype=data_subtype)

        return m_resource
Example #7
0
    def common_get_resources(self, data_type=None, data_subtype=None):
        """
        Get a list of datas.

        :return: List of resources.
        :rtype: list(Resource)
        """
        # Get each resource
        m_resource = None
        m_len_urls = Database.count(data_type, data_type)
        if m_len_urls < 200:  # increase as you see fit...
            # fast but memory consuming method
            m_resource = Database.get_many(
                Database.keys(data_type=data_type, data_subtype=data_subtype))
        else:
            # slow but lean method
            m_resource = Database.iterate(data_type=data_type,
                                          data_subtype=data_subtype)

        return m_resource
Example #8
0
 def __iterate(self, data_type = None, data_subtype = None):
     if Database.count(data_type, data_type) < 100:
         return Database.get_many(
             Database.keys(data_type=data_type, data_subtype=data_subtype)
         )
     return Database.iterate(data_type=data_type, data_subtype=data_subtype)
Example #9
0
 def __iterate(self, data_type = None, data_subtype = None):
     if Database.count(data_type=data_type, data_subtype=data_subtype) <100:
         return Database.get_many(
             Database.keys(data_type=data_type, data_subtype=data_subtype)
         )
     return Database.iterate(data_type=data_type, data_subtype=data_subtype)