Codebase list faraday-plugins / b9326aa9-d215-4970-b34f-0177fd2d52fa/upstream
Import upstream version 1.5.3 Kali Janitor 2 years ago
7 changed file(s) with 39 addition(s) and 7 deletion(s). Raw diff Collapse all Expand all
0 Adding support for running nuclei through command / faraday-cli
0 Sep 7th, 2021
0 Fix missing references in nuclei
0 1.5.3 [Sep 7th, 2021]:
1 ---
2 * Adding support for running nuclei through command / faraday-cli
3 * Fix missing references in nuclei
4
05 1.5.2 [Aug 9th, 2021]:
16 ---
27 * add new structure acunetix
0 __version__ = '1.5.2'
0 __version__ = '1.5.3'
3131 super().__init__(*arg, **kwargs)
3232 self.id = "nuclei"
3333 self.name = "Nuclei"
34 self.plugin_version = "1.0.0"
34 self.plugin_version = "1.0.1"
3535 self.version = "2.3.8"
3636 self.json_keys = {"matched", "templateID", "host"}
37 self._command_regex = re.compile(r'^(sudo nuclei|nuclei|\.\/nuclei|^.*?nuclei)\s+.*?')
38 self.xml_arg_re = re.compile(r"^.*(-o\s*[^\s]+).*$")
39 self._use_temp_file = True
40 self._temp_file_extension = "json"
3741
3842 def parseOutputString(self, output, debug=False):
3943 for vuln_json in filter(lambda x: x != '', output.split("\n")):
7680 references = [references]
7781 cwe = vuln_dict['info'].get('cwe', [])
7882 capec = vuln_dict['info'].get('capec', [])
79 refs = list(set(reference + references + cwe + capec)).sort()
83 refs = sorted(list(set(reference + references + cwe + capec)))
8084 tags = vuln_dict['info'].get('tags', '').split(',')
8185 impact = vuln_dict['info'].get('impact')
8286 resolution = vuln_dict['info'].get('resolution', '')
116120 external_id=f"NUCLEI-{vuln_dict.get('templateID', '')}",
117121 run_date=run_date
118122 )
123
124 def processCommandString(self, username, current_path, command_string):
125 """
126 Adds the -oX parameter to get xml output to the command string that the
127 user has set.
128 """
129 super().processCommandString(username, current_path, command_string)
130 arg_match = self.xml_arg_re.match(command_string)
131 if arg_match is None:
132 return re.sub(r"(^.*?nuclei)",
133 r"\1 --json -irr -o %s" % self._output_file_path,
134 command_string)
135 else:
136 return re.sub(arg_match.group(1),
137 r"--json -irr -o %s" % self._output_file_path,
138 command_string)
119139
120140
121141
00 import json
11 import os
22 import re
3 from tempfile import NamedTemporaryFile
3 import pytest
44 from click.testing import CliRunner
55 from faraday_plugins.commands import list_plugins, detect_command, process_command, detect_report, process_report
66
2121 assert result.output.strip() == "Failed to detect command: invalid_command"
2222
2323
24 @pytest.mark.skip(reason="issue with docker image")
2425 def test_detect_command():
2526 runner = CliRunner()
2627 result = runner.invoke(detect_command, args=['ping -c 1 www.google.com'])
2829 assert result.output.strip() == "Faraday Plugin: ping"
2930
3031
32 @pytest.mark.skip(reason="issue with docker image")
3133 def test_process_command():
3234 runner = CliRunner()
3335 result = runner.invoke(process_command, args=['ping -c 1 www.google.com', '--summary'])
34 assert result.exit_code == 0
36 assert result.exit_code == 0, result.output
3537 summary = json.loads(result.output.strip())
3638 assert summary['hosts'] == 1
3739
3840
41 @pytest.mark.skip(reason="issue with docker image")
3942 def test_process_command_ping():
4043 runner = CliRunner()
4144 result = runner.invoke(process_command, args=['ping -c 1 www.google.com'])
42 assert result.exit_code == 0
45 assert result.exit_code == 0, result.output
4346 summary = json.loads(result.output.strip())
4447
4548 assert summary['command']["command"] == 'ping'
4649
4750
51 @pytest.mark.skip(reason="issue with docker image")
4852 def test_process_command_to_file():
4953 runner = CliRunner()
5054 with runner.isolated_filesystem() as file_system:
5155 output_file = os.path.join(file_system, "test.json")
5256 result = runner.invoke(process_command, args=['ping -c 1 www.google.com', '-o', output_file])
53 assert result.exit_code == 0
57 assert result.exit_code == 0, result.output
5458 assert os.path.isfile(output_file)
5559 with open(output_file) as f:
5660 vuln_json = json.load(f)