本文整理汇总了Python中golismero.api.data.db.Database类的典型用法代码示例。如果您正苦于以下问题:Python Database类的具体用法?Python Database怎么用?Python Database使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Database类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __iterate_data
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
示例2: import_results
def import_results(self, input_file):
results = NmapScanPlugin.parse_nmap_results(None, input_file)
if results:
Database.async_add_many(results)
Logger.log("Loaded %d elements from file: %s" % (len(results), input_file))
else:
Logger.log_verbose("No data found in file: %s" % input_file)
示例3: notify_summary
def notify_summary(self, audit_name):
"""
This method is called when an audit ends and when a plugin ends.
:param audit_name: Name of the audit.
:type audit_name: str
"""
# Get the number of vulnerabilities in the database.
vulns_number = Database.count(Data.TYPE_VULNERABILITY)
# Count the vulnerabilities by severity.
vulns_counter = collections.defaultdict(int)
for l_vuln in Database.iterate(Data.TYPE_VULNERABILITY):
vulns_counter[l_vuln.level] += 1
# Get the number of IP addresses and hostnames.
total_hosts = Database.count(Data.TYPE_RESOURCE,
Resource.RESOURCE_DOMAIN)
total_hosts += Database.count(Data.TYPE_RESOURCE,
Resource.RESOURCE_IP)
# Substract the ones that were passed as targets.
discovered_hosts = total_hosts - len(Config.audit_scope.targets)
discovered_hosts = discovered_hosts if discovered_hosts > 0 else 0
# Send the summary.
packet = ("summary", audit_name, vulns_number, discovered_hosts, total_hosts,
vulns_counter['info'], vulns_counter['low'], vulns_counter['medium'],
vulns_counter['high'], vulns_counter['critical'],)
self.bridge.send(packet)
示例4: import_results
def import_results(self, input_file):
results, count = SSLScanPlugin.parse_sslscan_results(input_file)
if results:
Database.async_add_many(results)
Logger.log("Loaded %d hosts and %d vulnerabilities from file: %s" %
(len(results) - count, count, input_file))
else:
Logger.log_verbose("No data found in file: %s" % input_file)
示例5: import_results
def import_results(self, input_file):
try:
results, vuln_count = NiktoPlugin.parse_nikto_results(
None, input_file)
if results:
Database.async_add_many(results)
except Exception, e:
Logger.log_error(
"Could not load Nikto results from file: %s" % input_file)
Logger.log_error_verbose(str(e))
Logger.log_error_more_verbose(format_exc())
示例6: import_results
def import_results(self, input_file):
try:
openvas_results = report_parser(input_file);
golismero_results = OpenVASPlugin.parse_results(openvas_results)
if golismero_results:
Database.async_add_many(golismero_results)
except Exception, e:
fmt = format_exc()
Logger.log_error(
"Could not load OpenVAS results from file: %s" % input_file)
Logger.log_error_verbose(str(e))
Logger.log_error_more_verbose(fmt)
示例7: import_results
def import_results(self, input_file):
try:
xml_results = etree.parse(input_file)
openvas_results = VulnscanManager.transform(xml_results.getroot())
golismero_results = OpenVASPlugin.parse_results(openvas_results)
if golismero_results:
Database.async_add_many(golismero_results)
except Exception, e:
Logger.log_error(
"Could not load OpenVAS results from file: %s" % input_file)
Logger.log_error_verbose(str(e))
Logger.log_error_more_verbose(format_exc())
示例8: test_import
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
示例9: do_audit_results
def do_audit_results(self, audit_name, data_type = "all"): # TODO: control audits with error at start
"""
Implementation of: /audit/results
:param audit_name: Name of the audit to query.
:type audit_name: str
:param data_type: Data type to request. Case insensitive.
Must be one of the following values:
- "all": All data types.
- "information": Information type.
- "resource": Resource type.
- "vulnerability": Vulnerability type.
:type data_type: str
:returns: Result IDs.
:rtype: list(str)
:raises KeyError: Data type unknown.
"""
if self.is_audit_running(audit_name):
with SwitchToAudit(audit_name):
i_data_type = {
"all": None,
"information": Data.TYPE_INFORMATION,
"resource": Data.TYPE_RESOURCE,
"vulnerability": Data.TYPE_VULNERABILITY,
}[data_type.strip().lower()]
return sorted( Database.keys(i_data_type) )
else:
# XXX TODO open the database manually here
raise NotImplementedError(
"Querying finished audits is not implemented yet!")
示例10: do_scan_details
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)
示例11: common_get_resources
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
示例12: run
def run(self, info):
if not isinstance(info, Data):
raise TypeError("Expected Data, got %r instead" % type(info))
print "-" * 79
print "ID: %s" % info.identity
print "Data: %r" % info
history = Database.get_plugin_history(info.identity)
if history:
print "History:"
for plugin_id in history:
print " " + plugin_id
print
示例13: generate_report
def generate_report(self, output_file):
# Dump all objects in the database.
print "-" * 79
print "Report:"
for data in Database.iterate():
print
print data.identity
print repr(data)
print sorted(data.links)
for linked in data.linked_data:
print "--> " + linked.identity
print "--> " + repr(linked)
print
示例14: do_audit_details
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!")
示例15: list
- "resource": Resource type.
- "vulnerability": Vulnerability type.
:type data_type: str
:returns: Result IDs.
:rtype: list(str)
:raises KeyError: Data type unknown.
"""
i_data_type = {
"all": None,
"information": Data.TYPE_INFORMATION,
"resource": Data.TYPE_RESOURCE,
"vulnerability": Data.TYPE_VULNERABILITY,
}[data_type.strip().lower()]
return sorted( Database.keys(i_data_type) )
#--------------------------------------------------------------------------
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)
#--------------------------------------------------------------------------
def do_plugin_list(self):