Codebase list faraday-plugins / 40caa59
Import upstream version 1.5.1 Kali Janitor 2 years ago
15 changed file(s) with 68 addition(s) and 21 deletion(s). Raw diff Collapse all Expand all
0 cwe, capec, references, tags, impact, resolution, easeofresolution
0 Jul 27th, 2021
0 [FIX] Fix improt of CSV with big fields
0 Fix sslyze json bug with port
0 Only show report name in command data
0 1.5.1 [Jul 27th, 2021]:
1 ---
2 * cwe, capec, references, tags, impact, resolution, easeofresolution
3 * add os openvas
4 * [FIX] Fix improt of CSV with big fields
5 * Fix sslyze json bug with port
6 * Only show report name in command data
7
08 1.5.0 [Jun 28th, 2021]:
19 ---
210 * Add Nipper Plugin
0 __version__ = '1.5.0'
0 __version__ = '1.5.1'
55 import shlex
66 import subprocess
77 import sys
8 from pathlib import Path
89
910 import click
1011 from tabulate import tabulate
7980 if not plugin:
8081 click.echo(click.style(f"Failed to detect report: {report_file}", fg="red"), err=True)
8182 return
82 plugin.processReport(report_file, getpass.getuser())
83 plugin.processReport(Path(report_file), getpass.getuser())
8384 if summary:
8485 click.echo(json.dumps(plugin.get_summary(), indent=4))
8586 else:
1313 import zipfile
1414 from collections import defaultdict
1515 from datetime import datetime
16 from pathlib import Path
1617
1718 import pytz
1819 import simplejson as json
276277 params = " ".join(command_string.split()[2:])
277278 else:
278279 params = " ".join(command_string.split()[1:])
279 self.vulns_data["command"]["params"] = params
280 self.vulns_data["command"]["params"] = params if not self.ignore_info else f"{params} (Info ignored)"
280281 self.vulns_data["command"]["user"] = username
281282 self.vulns_data["command"]["import_source"] = "shell"
282283 if self._use_temp_file:
299300
300301 def processOutput(self, command_output):
301302 if self.has_custom_output():
302 self._parse_filename(self.get_custom_file_path())
303 self._parse_filename(Path(self.get_custom_file_path()))
303304 else:
304305 self.parseOutputString(command_output)
305306
306 def _parse_filename(self, filename):
307 with open(filename, **self.open_options) as output:
307 def _parse_filename(self, filename: Path):
308 with filename.open(**self.open_options) as output:
308309 self.parseOutputString(output.read())
309310 if self._delete_temp_file:
310311 try:
311 if os.path.isfile(filename):
312 if filename.is_file():
312313 os.remove(filename)
313 elif os.path.isdir(filename):
314 elif filename.is_dir():
314315 shutil.rmtree(filename)
315316 except Exception as e:
316317 self.logger.error("Error on delete file: (%s) [%s]", filename, e)
317318
318 def processReport(self, filepath, user="faraday"):
319 if os.path.isfile(filepath):
320 self.vulns_data["command"]["params"] = filepath if not self.ignore_info else f"{filepath} (Info ignored)"
319 def processReport(self, filepath: Path, user="faraday"):
320 if type(filepath) == str: # TODO workaround for compatibility, remove in the future
321 filepath = Path(filepath)
322 if filepath.is_file():
323 self.vulns_data["command"]["params"] = filepath.name if not self.ignore_info else f"{filepath.name} (Info ignored)"
321324 self.vulns_data["command"]["user"] = user
322325 self.vulns_data["command"]["import_source"] = "report"
323326 self._parse_filename(filepath)
565568 def processOutput(self, term_output):
566569 # we discard the term_output since it's not necessary
567570 # for this type of plugins
568 self.processReport(self._output_file_path)
571 self.processReport(Path(self._output_file_path))
569572
570573
571574 class PluginByExtension(PluginBase):
22 Copyright (C) 2013 Infobyte LLC (http://www.infobytesec.com/)
33 See the file 'doc/LICENSE' for the license information
44 """
5 import sys
56 import re
67 import csv
78 from ast import literal_eval
5960
6061 def parse_csv(self, output):
6162 items = []
63 csv.field_size_limit(sys.maxsize)
6264 reader = csv.DictReader(output, delimiter=',')
6365 obj_to_import = self.check_objects_to_import(reader.fieldnames)
6466 if not obj_to_import:
44
55 """
66 import socket
7 import re
78 import json
89 import dateutil
910 from collections import defaultdict
1516 __copyright__ = "Copyright (c) 2021, Infobyte LLC"
1617 __credits__ = ["Nicolas Rebagliati"]
1718 __license__ = ""
18 __version__ = "0.0.1"
19 __version__ = "1.0.0"
1920 __maintainer__ = "Nicolas Rebagliati"
2021 __email__ = "[email protected]"
2122 __status__ = "Development"
3031 super().__init__(*arg, **kwargs)
3132 self.id = "nuclei"
3233 self.name = "Nuclei"
33 self.plugin_version = "0.1"
34 self.version = "2.3.0"
34 self.plugin_version = "1.0.0"
35 self.version = "2.3.8"
3536 self.json_keys = {"matched", "templateID", "host"}
3637
3738 def parseOutputString(self, output, debug=False):
5960 description='web server')
6061 matched = vuln_dict.get('matched')
6162 matched_data = urlparse(matched)
62 references = [f"author: {vuln_dict['info'].get('author', '')}"]
63 reference = vuln_dict["info"].get('reference', [])
64 if reference:
65 if isinstance(reference, str):
66 if re.match('^- ', reference):
67 reference = list(filter(None, [re.sub('^- ','', elem) for elem in reference.split('\n')]))
68 else:
69 reference = [reference]
70 references = vuln_dict["info"].get('references', [])
71 if references:
72 if isinstance(references, str):
73 if re.match('^- ', references):
74 references = list(filter(None, [re.sub('^- ','', elem) for elem in references.split('\n')]))
75 else:
76 references = [references]
77 cwe = vuln_dict['info'].get('cwe', [])
78 capec = vuln_dict['info'].get('capec', [])
79 refs = list(set(reference + references + cwe + capec)).sort()
80 tags = vuln_dict['info'].get('tags', '').split(',')
81 impact = vuln_dict['info'].get('impact')
82 resolution = vuln_dict['info'].get('resolution', '')
83 easeofresolution = vuln_dict['info'].get('easeofresolution')
6384 request = vuln_dict.get('request', '')
6485 if request:
6586 method = request.split(" ")[0]
7899 service_id,
79100 name=name,
80101 desc=vuln_dict["info"].get("description", name),
81 ref=references,
102 ref=refs,
82103 severity=vuln_dict["info"].get('severity'),
104 tags=tags,
105 impact=impact,
106 resolution=resolution,
107 easeofresolution=easeofresolution,
83108 website=host,
84109 request=request,
85110 response=vuln_dict.get('response', ''),
321321 from the xml where it expects it to be present.
322322 """
323323 parser = OpenvasXmlParser(output, self.logger)
324 web = False
325324 ids = {}
326325 # The following threats values will not be taken as vulns
327326 self.ignored_severities = ['Log', 'Debug']
328327 for ip, values in parser.hosts.items():
329328 # values contains: ip details and ip hostnames
329 os_report = values['details'].get('best_os_txt')
330330 h_id = self.createAndAddHost(
331331 ip,
332 os_report[0] if os_report else '',
332333 hostnames=values['hostnames']
333334 )
334335 ids[ip] = h_id
7474 hostname = server_location.get('hostname', None)
7575 ip = server_location.get('ip_address', resolve_hostname(hostname))
7676 if port != 443:
77 url = 'https://' + hostname + ':' + port
77 url = f"https://{hostname}:{port}"
7878 else:
79 url = 'https://' + hostname
79 url = f"https://{hostname}"
8080
8181 json_host = {
8282 "name": 'https',
11 import socket
22 import json
33 import pytest
4 from pathlib import Path
45 from faraday_plugins.plugins.manager import PluginsManager, ReportAnalyzer
56 from faraday_plugins.plugins.plugin import PluginBase
67 from faraday.server.api.modules.bulk_create import BulkCreateSchema
4445 if not plugin_json:
4546 plugin = get_plugin_from_cache(report_file)
4647 if plugin:
47 plugin.processReport(report_file)
48 plugin.processReport(Path(report_file))
4849 plugin_json = json.loads(plugin.get_json())
4950 REPORTS_JSON_CACHE[report_file] = plugin_json
5051 else: