本文整理汇总了Python中golismero.api.data.db.Database.count方法的典型用法代码示例。如果您正苦于以下问题:Python Database.count方法的具体用法?Python Database.count怎么用?Python Database.count使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类golismero.api.data.db.Database
的用法示例。
在下文中一共展示了Database.count方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: notify_summary
# 需要导入模块: from golismero.api.data.db import Database [as 别名]
# 或者: from golismero.api.data.db.Database import count [as 别名]
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)
示例2: common_get_resources
# 需要导入模块: from golismero.api.data.db import Database [as 别名]
# 或者: from golismero.api.data.db.Database import count [as 别名]
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
示例3: __iterate
# 需要导入模块: from golismero.api.data.db import Database [as 别名]
# 或者: from golismero.api.data.db.Database import count [as 别名]
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)
示例4: __write_report
# 需要导入模块: from golismero.api.data.db import Database [as 别名]
# 或者: from golismero.api.data.db.Database import count [as 别名]
def __write_report(self):
# Header
print >>self.__fd, ""
print >>self.__fd, "--= %s =--" % self.__colorize("Report", "cyan")
print >>self.__fd, ""
# Summary
start_time, stop_time, run_time = parse_audit_times( *get_audit_times() )
host_count = Database.count(Data.TYPE_RESOURCE, Resource.RESOURCE_DOMAIN)
host_count += Database.count(Data.TYPE_RESOURCE, Resource.RESOURCE_IP)
vuln_count = Database.count(Data.TYPE_VULNERABILITY)
print >>self.__fd, "-# %s #- " % self.__colorize("Summary", "yellow")
print >>self.__fd, ""
print >>self.__fd, "Audit started: %s" % self.__colorize(start_time, "yellow")
print >>self.__fd, "Audit ended: %s" % self.__colorize(stop_time, "yellow")
print >>self.__fd, "Execution time: %s" % self.__colorize(run_time, "yellow")
print >>self.__fd, ""
print >>self.__fd, "Scanned hosts: %s" % self.__colorize(str(host_count), "yellow")
print >>self.__fd, "Vulnerabilities: %s" % self.__colorize(str(vuln_count), "red" if vuln_count else "yellow")
print >>self.__fd, ""
# Audit scope
if self.__show_data or not self.__console:
table = Texttable()
scope_domains = ["*." + r for r in Config.audit_scope.roots]
scope_domains.extend(Config.audit_scope.domains)
if Config.audit_scope.addresses:
table.add_row(("IP addresses", "\n".join(Config.audit_scope.addresses)))
if scope_domains:
table.add_row(("Domains", "\n".join(scope_domains)))
if Config.audit_scope.web_pages:
table.add_row(("Web pages", "\n".join(Config.audit_scope.web_pages)))
if table._rows:
self.__fix_table_width(table)
print >>self.__fd, "-# %s #- " % self.__colorize("Audit Scope", "yellow")
print >>self.__fd, ""
print >>self.__fd, table.draw()
print >>self.__fd, ""
# Discovered hosts
if self.__show_data:
need_header = True
for domain in self.__iterate(Data.TYPE_RESOURCE, Resource.RESOURCE_DOMAIN):
table = Texttable()
self.__add_related(table, domain, Data.TYPE_RESOURCE, Resource.RESOURCE_IP, "IP Address")
self.__add_related(table, domain, Data.TYPE_INFORMATION, Information.INFORMATION_GEOLOCATION, "Location")
self.__add_related(table, domain, Data.TYPE_INFORMATION, Information.INFORMATION_WEB_SERVER_FINGERPRINT, "Web Server")
self.__add_related(table, domain, Data.TYPE_INFORMATION, Information.INFORMATION_OS_FINGERPRINT, "OS Fingerprint")
if table._rows:
if need_header:
need_header = False
print >>self.__fd, "-# %s #- " % self.__colorize("Hosts", "yellow")
print >>self.__fd, ""
table.header(("Domain Name", domain.hostname))
self.__fix_table_width(table)
text = table.draw()
if self.__color:
text = colorize_substring(text, domain.hostname, "red" if domain.get_links(Data.TYPE_VULNERABILITY) else "green")
print >>self.__fd, text
print >>self.__fd, ""
for ip in self.__iterate(Data.TYPE_RESOURCE, Resource.RESOURCE_IP):
table = Texttable()
self.__add_related(table, ip, Data.TYPE_RESOURCE, Resource.RESOURCE_DOMAIN, "Domain Name")
self.__add_related(table, ip, Data.TYPE_INFORMATION, Information.INFORMATION_GEOLOCATION, "Location")
self.__add_related(table, ip, Data.TYPE_INFORMATION, Information.INFORMATION_WEB_SERVER_FINGERPRINT, "Web Server")
self.__add_related(table, ip, Data.TYPE_INFORMATION, Information.INFORMATION_OS_FINGERPRINT, "OS Fingerprint")
self.__add_related(table, ip, Data.TYPE_INFORMATION, Information.INFORMATION_PORTSCAN, "Port Scan")
self.__add_related(table, ip, Data.TYPE_INFORMATION, Information.INFORMATION_TRACEROUTE, "Network Route")
if table._rows:
if need_header:
need_header = False
print >>self.__fd, "-# %s #- " % self.__colorize("Hosts", "yellow")
print >>self.__fd, ""
table.header(("IP Address", ip.address))
self.__fix_table_width(table)
text = table.draw()
if self.__color:
text = colorize_substring(text, ip.address, "red" if ip.get_links(Data.TYPE_VULNERABILITY) else "green")
print >>self.__fd, text
print >>self.__fd, ""
# Web servers
if self.__show_data and Database.count(Data.TYPE_RESOURCE, Resource.RESOURCE_BASE_URL):
print >>self.__fd, "-# %s #- " % self.__colorize("Web Servers", "yellow")
print >>self.__fd, ""
crawled = defaultdict(list)
vulnerable = []
for url in self.__iterate(Data.TYPE_RESOURCE, Resource.RESOURCE_URL):
crawled[url.hostname].append(url.url)
if self.__color and url.get_links(Data.TYPE_VULNERABILITY):
vulnerable.append(url)
for url in self.__iterate(Data.TYPE_RESOURCE, Resource.RESOURCE_BASE_URL):
table = Texttable()
table.header(("Base URL", url.url))
self.__add_related(table, url, Data.TYPE_INFORMATION, Information.INFORMATION_WEB_SERVER_FINGERPRINT, "Server")
self.__add_related(table, url, Data.TYPE_INFORMATION, Information.INFORMATION_OS_FINGERPRINT, "Platform")
urls = crawled[url.hostname]
if urls:
urls.sort()
#.........这里部分代码省略.........
示例5: do_audit_summary
# 需要导入模块: from golismero.api.data.db import Database [as 别名]
# 或者: from golismero.api.data.db.Database import count [as 别名]
def do_audit_summary(self, audit_name):
"""
Implementation of: /audit/summary
:param audit_name: Name of the audit to query.
:type audit_name: str
:returns:
Summary in the following format::
{
'vulns_number' : int,
'discovered_hosts' : int,
'total_hosts' : int,
'vulns_by_level' : {
'info' : int,
'low' : int,
'medium' : int,
'high' : int,
'critical' : int,
},
}
Returns None on error.
:rtype: dict(str -> \\*) | None
"""
# Checks for errors
if audit_name in self.audit_error:
return "error"
try:
if self.is_audit_running(audit_name):
with SwitchToAudit(audit_name):
# Get the number of vulnerabilities in the database.
vulns_number = Database.count(Data.TYPE_VULNERABILITY)
# Count the vulnerabilities by severity.
vulns_counter = collections.Counter()
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)
# Return the data in the expected format.
return {
'vulns_number' : vulns_number,
'discovered_hosts' : discovered_hosts,
'total_hosts' : total_hosts,
'vulns_by_level' : {
'info' : vulns_counter['info'],
'low' : vulns_counter['low'],
'medium' : vulns_counter['medium'],
'high' : vulns_counter['high'],
'critical' : vulns_counter['critical'],
}
}
else:
# XXX TODO open the database manually here
raise NotImplementedError(
"Querying finished audits is not implemented yet!")
except Exception:
Logger.log_error(traceback.format_exc())