本文整理汇总了Python中vulners.Vulners方法的典型用法代码示例。如果您正苦于以下问题:Python vulners.Vulners方法的具体用法?Python vulners.Vulners怎么用?Python vulners.Vulners使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vulners
的用法示例。
在下文中一共展示了vulners.Vulners方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_vulnerabilities_report
# 需要导入模块: import vulners [as 别名]
# 或者: from vulners import Vulners [as 别名]
def get_vulnerabilities_report(self) -> dict:
"""
Collect all reports and bulletins connected with list of vulnerabilities
:return: dictionary with reports
"""
cprint(
"Vulners: Collect all documents related to vulnerabilities...",
"blue",
attrs=["bold"],
)
try:
vulners_api = Vulners(api_key=self.api_key)
except ValueError as wrong_key:
print("Error:", wrong_key)
return {}
vulnerabilities_list = list(self._vulnerabilities.keys())
if not vulnerabilities_list:
return {}
vulnerabilities_report = vulners_api.documentList(vulnerabilities_list)
return vulnerabilities_report
示例2: get_critical_vulnerabilities_report
# 需要导入模块: import vulners [as 别名]
# 或者: from vulners import Vulners [as 别名]
def get_critical_vulnerabilities_report(
self, vulnerabilities_report: dict = None, critical_cvss: int = 9.0
) -> dict:
"""
Count critical vulnerabilities from all vulnerabilities
:param vulnerabilities_report: previously received vulnerabilities report (if exists)
:param critical_cvss: lower boundary of critical level - 9.0 by CVSS 3.0 rating (default)
:return: dictionary with critical vulnerabilities
"""
cprint("Vulners: Separate critical vulnerabilities...", "blue", attrs=["bold"])
if not vulnerabilities_report:
vulnerabilities_report = self.get_vulnerabilities_report()
if not vulnerabilities_report:
return {}
critical_cve_data = {}
for cve, cve_information in vulnerabilities_report.items():
if not cve_information.get("cvss"):
continue
if not cve_information["cvss"].get("score"):
continue
if not float(cve_information["cvss"]["score"]) >= critical_cvss:
continue
critical_cve_data.update({cve: cve_information})
return critical_cve_data
示例3: _search_cpe_exploits
# 需要导入模块: import vulners [as 别名]
# 或者: from vulners import Vulners [as 别名]
def _search_cpe_exploits(
self, unique_cpe: list, database_name: str = "exploit"
) -> dict:
"""
Search for exploits that connected with particular software
by CPE fingerprint
:param unique_cpe: list of unique CPEs
:param database_name: name of required database/bulletin to search
:return: dictionary with CPEs and found exploits
"""
try:
vulners_api = Vulners(api_key=self.api_key)
except ValueError as wrong_key:
print("Error:", wrong_key)
return {}
cpe_with_exploits = {}
for cpe in unique_cpe:
cpe_results = vulners_api.cpeVulnerabilities(cpe)
print(
f" - Software: {cpe}, available databases: {list(cpe_results.keys())}"
)
if not cpe_results:
continue
cpe_exploit_list = cpe_results.get(database_name)
if not cpe_exploit_list:
continue
cpe_with_exploits.update({cpe: cpe_exploit_list})
return cpe_with_exploits
示例4: get_exploits_for_software
# 需要导入模块: import vulners [as 别名]
# 或者: from vulners import Vulners [as 别名]
def get_exploits_for_software(self, hosts: dict = None):
"""
Parse CPEs and search exploits for them with Vulners
:param hosts: already scanned hosts with info
:return: dictionary with software exploits
"""
if not hosts and self._hosts:
hosts = self._hosts
if not hosts and not self._hosts:
return {}
cprint("Vulners: Collect all software exploits...", "blue", attrs=["bold"])
host_to_cpe = self._parse_cpes()
if not host_to_cpe:
return {}
unique_cpe = self._count_unique_cpes(host_to_cpe)
if not unique_cpe:
return {}
cpe_with_exploits = self._search_cpe_exploits(unique_cpe)
if not cpe_with_exploits:
return {}
copy_host_to_cpe = deepcopy(host_to_cpe)
for ip, port_cpe in copy_host_to_cpe.items():
for port, cpe in port_cpe.items():
if not cpe.get("cpe_id") in cpe_with_exploits.keys():
host_to_cpe[ip].pop(port)
continue
host_to_cpe[ip][port]["cpe_info"] = cpe_with_exploits[cpe.get("cpe_id")]
if not host_to_cpe.get(ip):
host_to_cpe.pop(ip)
return host_to_cpe
示例5: __init__
# 需要导入模块: import vulners [as 别名]
# 或者: from vulners import Vulners [as 别名]
def __init__(self, username="aliasrobotics", repo="RVD"):
"""Init with other repo as target"""
# Fetch the Github token
self.token()
# Init the API
self.api = vulners.Vulners(api_key=self.token)
示例6: get_critical_vulnerabilities_hosts_report
# 需要导入模块: import vulners [as 别名]
# 或者: from vulners import Vulners [as 别名]
def get_critical_vulnerabilities_hosts_report(
self, critical_vulnerabilities_report: dict = None, hosts: dict = None
) -> dict:
"""
Count hosts with critical vulnerabilities
:param critical_vulnerabilities_report: previously received critical vulnerabilities
:param hosts: already scanned hosts with info
:return: dictionary with ips of hosts
"""
cprint(
"Vulners: Separate hosts with critical vulnerabilities...",
"blue",
attrs=["bold"],
)
if not critical_vulnerabilities_report:
critical_vulnerabilities_report = self.get_critical_vulnerabilities_report()
if not critical_vulnerabilities_report:
return {}
if not hosts and self._hosts:
hosts = self._hosts
if not hosts and not self._hosts:
return {}
critical_cves = list(critical_vulnerabilities_report.keys())
if not critical_cves:
return {}
critical_cve_hosts = {}
for ip, host_info in hosts.items():
vulnerabilities = host_info.get("vulnerabilities")
if not vulnerabilities:
continue
all_host_vulnerabilities = []
if vulnerabilities.get("shodan_vulnerabilities"):
shodan_host_vulnerabilities = list(
vulnerabilities.get("shodan_vulnerabilities").keys()
)
all_host_vulnerabilities.extend(shodan_host_vulnerabilities)
if vulnerabilities.get("vulners_vulnerabilities"):
vulners_host_vulnerabilities = list(
vulnerabilities.get("vulners_vulnerabilities").keys()
)
all_host_vulnerabilities.extend(vulners_host_vulnerabilities)
if not all_host_vulnerabilities:
continue
all_unique_host_vulnerabilities = list(set(all_host_vulnerabilities))
check_if_any_critical = any(
vulnerability in all_unique_host_vulnerabilities
for vulnerability in critical_cves
)
if check_if_any_critical:
critical_cve_hosts.update({ip: host_info})
return critical_cve_hosts
示例7: sort_by_cvss_rating
# 需要导入模块: import vulners [as 别名]
# 或者: from vulners import Vulners [as 别名]
def sort_by_cvss_rating(self, vulnerabilities_report: dict = None) -> dict:
"""
Sort vulnerabilities by cvss rating
:param cve_data: previously received vulnerabilities report
:return: dictionary with cve by levels
"""
cprint(
"Vulners: Sort vulnerabilities by CVSS levels...", "blue", attrs=["bold"]
)
if not vulnerabilities_report:
vulnerabilities_report = self.get_vulnerabilities_report()
if not vulnerabilities_report:
return {}
# CVSS v3.0 Ratings
# Severity Base Score Range
# None 0.0
# Low 0.1-3.9
# Medium 4.0-6.9
# High 7.0-8.9
# Critical 9.0-10.0
groupped_cve = {}
for cve, cve_information in vulnerabilities_report.items():
if not cve_information.get("cvss"):
continue
if not cve_information["cvss"].get("score"):
continue
score = float(cve_information["cvss"]["score"])
level = ""
if score == 0.0:
level = "None"
elif 0.1 <= score <= 3.9:
level = "Low"
elif 4.0 <= score <= 6.9:
level = "Medium"
elif 7.0 <= score <= 8.9:
level = "High"
elif 9.0 <= score <= 10.0:
level = "Critical"
if level == "":
continue
if not groupped_cve.get(level):
groupped_cve[level] = [cve]
else:
groupped_cve[level].append(cve)
return groupped_cve
示例8: sort_by_cvss_rating_hosts
# 需要导入模块: import vulners [as 别名]
# 或者: from vulners import Vulners [as 别名]
def sort_by_cvss_rating_hosts(
self, cvss_groupped_vulnerabilties_report: dict = None, hosts: dict = None
) -> dict:
"""
Sort hosts by CVSS rating
:param cvss_groupped_vulnerabilties_report: already groupped vulnerabilities by CVSS rating
:param hosts: already scanned hosts with info
:return: dictionary with hosts groupped by cvss level
"""
cprint("Vulners: Sort nodes by CVSS levels...", "blue", attrs=["bold"])
if not cvss_groupped_vulnerabilties_report:
cvss_groupped_vulnerabilties_report = self.sort_by_cvss_rating()
if not cvss_groupped_vulnerabilties_report:
return {}
if not hosts and self._hosts:
hosts = self._hosts
if not hosts and not self._hosts:
return {}
groupped_cve_hosts = {}
for ip, host_info in hosts.items():
vulnerabilities = host_info.get("vulnerabilities")
if not vulnerabilities:
continue
all_host_vulnerabilities = []
if vulnerabilities.get("shodan_vulnerabilities"):
shodan_host_vulnerabilities = list(
vulnerabilities.get("shodan_vulnerabilities").keys()
)
all_host_vulnerabilities.extend(shodan_host_vulnerabilities)
if vulnerabilities.get("vulners_vulnerabilities"):
vulners_host_vulnerabilities = list(
vulnerabilities.get("vulners_vulnerabilities").keys()
)
all_host_vulnerabilities.extend(vulners_host_vulnerabilities)
if not all_host_vulnerabilities:
continue
all_unique_host_vulnerabilities = list(set(all_host_vulnerabilities))
for (
group,
groupped_vulnerabilities,
) in cvss_groupped_vulnerabilties_report.items():
check_if_group_match = any(
vulnerability in all_unique_host_vulnerabilities
for vulnerability in groupped_vulnerabilities
)
if not check_if_group_match:
continue
if not groupped_cve_hosts.get(group):
groupped_cve_hosts[group] = [host_info]
else:
groupped_cve_hosts[group].append(host_info)
return groupped_cve_hosts
示例9: _parse_cpes
# 需要导入模块: import vulners [as 别名]
# 或者: from vulners import Vulners [as 别名]
def _parse_cpes(self, hosts: dict = None):
"""
Parse compatible with Vulners API CPEs from hosts
see: https://nmap.org/book/output-formats-cpe.html
see: https://cpe.mitre.org/specification/
:param hosts: hosts to check CPE
:return: dictionary with CPEs
"""
if not hosts and self._hosts:
hosts = self._hosts
if not hosts and not self._hosts:
return {}
host_to_cpe = {}
# This regexp helps to find at least software with major version
# from CPE
valid_cpe = compile(r"cpe:\/\S:\w+:\w+:.+")
for host_ip, host_information in hosts.items():
if not host_information.get("nmap_scan"):
continue
if not host_information["nmap_scan"].get("tcp"):
continue
for port_number, port_information in host_information["nmap_scan"][
"tcp"
].items():
if not port_information.get("cpe"):
continue
cpe_search = valid_cpe.findall(port_information.get("cpe"))
if not cpe_search:
continue
if not host_to_cpe.get(host_ip):
host_to_cpe.update(
{
host_ip: {
port_number: {
"cpe_id": port_information.get("cpe"),
"cpe_info": [],
}
}
}
)
else:
host_to_cpe[host_ip].update(
{
port_number: {
"cpe_id": port_information.get("cpe"),
"cpe_info": [],
}
}
)
return host_to_cpe
示例10: Search
# 需要导入模块: import vulners [as 别名]
# 或者: from vulners import Vulners [as 别名]
def Search(Query_List, Task_ID, **kwargs):
try:
Data_to_Cache = []
Directory = General.Make_Directory(Plugin_Name.lower())
logger = logging.getLogger()
logger.setLevel(logging.INFO)
Log_File = General.Logging(Directory, Plugin_Name.lower())
handler = logging.FileHandler(os.path.join(Directory, Log_File), "w")
handler.setLevel(logging.DEBUG)
formatter = logging.Formatter("%(levelname)s - %(message)s")
handler.setFormatter(formatter)
logger.addHandler(handler)
Cached_Data = General.Get_Cache(Directory, Plugin_Name)
Query_List = General.Convert_to_List(Query_List)
Limit = General.Get_Limit(kwargs)
for Query in Query_List:
vulners_api = vulners.Vulners(api_key=Load_Configuration())
Search_Response = vulners_api.search(Query, limit=int(Limit))
JSON_Response = json.dumps(Search_Response, indent=4, sort_keys=True)
Main_File = General.Main_File_Create(Directory, Plugin_Name, JSON_Response, Query, The_File_Extensions["Main"])
Output_Connections = General.Connections(Query, Plugin_Name, "vulners.com", "Exploit", Task_ID, Plugin_Name.lower())
for Search_Result in Search_Response:
if Search_Result["bulletinFamily"] not in Unacceptable_Bulletins:
Result_Title = Search_Result["title"]
Result_URL = Search_Result["vhref"]
Search_Result_Response = requests.get(Result_URL).text
if Result_URL not in Cached_Data and Result_URL not in Data_to_Cache:
Output_file = General.Create_Query_Results_Output_File(Directory, Query, Plugin_Name, Search_Result_Response, Result_Title, The_File_Extensions["Query"])
if Output_file:
Output_Connections.Output([Main_File, Output_file], Result_URL, Result_Title, Plugin_Name.lower())
Data_to_Cache.append(Result_URL)
else:
logging.warning(f"{General.Date()} - {__name__.strip('plugins.')} - Failed to create output file. File may already exist.")
else:
logging.info(f"{General.Date()} - {__name__.strip('plugins.')} - Skipping as bulletin type is not supported.")
if Cached_Data:
General.Write_Cache(Directory, Data_to_Cache, Plugin_Name, "a")
else:
General.Write_Cache(Directory, Data_to_Cache, Plugin_Name, "w")
except Exception as e:
logging.warning(f"{General.Date()} - {__name__.strip('plugins.')} - {str(e)}")