Import upstream version 1.4.6
Kali Janitor
2 years ago
0 | [flake8] | |
1 | ignore = W391, E722, E303, E701, W291, E222, E241, E225, E115, E117, E122, E123, E124, E501, E261, E127, E265, F401, W292, W293, W605, E231, E221, E222, F841, E128, W504, E202, F811, E251, E226, E203, E262, E225, E305, E302, E305 | |
2 | exclude= report-collection⏎ |
0 | # Created by .ignore support plugin (hsz.mobi) | |
1 | ### Python template | |
2 | # Byte-compiled / optimized / DLL files | |
3 | __pycache__/ | |
4 | *.py[cod] | |
5 | *$py.class | |
6 | ||
7 | # C extensions | |
8 | *.so | |
9 | ||
10 | # Distribution / packaging | |
11 | .Python | |
12 | build/ | |
13 | develop-eggs/ | |
14 | dist/ | |
15 | downloads/ | |
16 | eggs/ | |
17 | .eggs/ | |
18 | lib/ | |
19 | lib64/ | |
20 | parts/ | |
21 | sdist/ | |
22 | var/ | |
23 | wheels/ | |
24 | pip-wheel-metadata/ | |
25 | share/python-wheels/ | |
26 | *.egg-info/ | |
27 | .installed.cfg | |
28 | *.egg | |
29 | MANIFEST | |
30 | ||
31 | # PyInstaller | |
32 | # Usually these files are written by a python script from a template | |
33 | # before PyInstaller builds the exe, so as to inject date/other infos into it. | |
34 | *.manifest | |
35 | *.spec | |
36 | ||
37 | # Installer logs | |
38 | pip-log.txt | |
39 | pip-delete-this-directory.txt | |
40 | ||
41 | # Unit test / coverage reports | |
42 | htmlcov/ | |
43 | .tox/ | |
44 | .nox/ | |
45 | .coverage | |
46 | .coverage.* | |
47 | .cache | |
48 | nosetests.xml | |
49 | coverage.xml | |
50 | *.cover | |
51 | .hypothesis/ | |
52 | .pytest_cache/ | |
53 | ||
54 | # Translations | |
55 | *.mo | |
56 | *.pot | |
57 | ||
58 | # Django stuff: | |
59 | *.log | |
60 | local_settings.py | |
61 | db.sqlite3 | |
62 | db.sqlite3-journal | |
63 | ||
64 | # Flask stuff: | |
65 | instance/ | |
66 | .webassets-cache | |
67 | ||
68 | # Scrapy stuff: | |
69 | .scrapy | |
70 | ||
71 | # Sphinx documentation | |
72 | docs/_build/ | |
73 | ||
74 | # PyBuilder | |
75 | target/ | |
76 | ||
77 | # Jupyter Notebook | |
78 | .ipynb_checkpoints | |
79 | ||
80 | # IPython | |
81 | profile_default/ | |
82 | ipython_config.py | |
83 | ||
84 | # pyenv | |
85 | .python-version | |
86 | ||
87 | # pipenv | |
88 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. | |
89 | # However, in case of collaboration, if having platform-specific dependencies or dependencies | |
90 | # having no cross-platform support, pipenv may install dependencies that don't work, or not | |
91 | # install all needed dependencies. | |
92 | #Pipfile.lock | |
93 | ||
94 | # celery beat schedule file | |
95 | celerybeat-schedule | |
96 | ||
97 | # SageMath parsed files | |
98 | *.sage.py | |
99 | ||
100 | # Environments | |
101 | .env | |
102 | .venv | |
103 | env/ | |
104 | venv/ | |
105 | ENV/ | |
106 | env.bak/ | |
107 | venv.bak/ | |
108 | ||
109 | # Spyder project settings | |
110 | .spyderproject | |
111 | .spyproject | |
112 | ||
113 | # Rope project settings | |
114 | .ropeproject | |
115 | ||
116 | # mkdocs documentation | |
117 | /site | |
118 | ||
119 | # mypy | |
120 | .mypy_cache/ | |
121 | .dmypy.json | |
122 | dmypy.json | |
123 | ||
124 | # Pyre type checker | |
125 | .pyre/ | |
126 | ||
127 | .idea | |
128 | /report-collection/ | |
129 | ||
130 | #project settings | |
131 | *.project⏎ |
0 | stages: | |
1 | - pre_testing | |
2 | - testing | |
3 | - post_testing | |
4 | - publish | |
5 | ||
6 | before_script: | |
7 | - apt-get update -qy | |
8 | - pip install pip -U | |
9 | ||
10 | workflow: | |
11 | rules: | |
12 | - if: $CI_MERGE_REQUEST_ID | |
13 | when: never | |
14 | - when: always | |
15 | ||
16 | .install_faraday_venv: &install_faraday_venv | |
17 | - pip3 install virtualenv | |
18 | - virtualenv -p python3 faraday_venv | |
19 | - source faraday_venv/bin/activate | |
20 | - pip3 install pytest pytest-xdist pytest-cov | |
21 | - git clone https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.com/faradaysec/faraday.git | |
22 | - cd faraday | |
23 | - pip3 install $PIP_FLAGS . | |
24 | - pip uninstall faraday-plugins -y # we need to install fardaysec for marshmallow schemas, we remove plugins from pypi | |
25 | - cd .. | |
26 | ||
27 | .clone_reports: &clone_reports | |
28 | - git clone https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.com/faradaysec/support/report-collection.git | |
29 | - cd report-collection | |
30 | - (git branch -a | grep $CI_COMMIT_BRANCH) && export REPORT_REF=$CI_COMMIT_BRANCH || export REPORT_REF=master | |
31 | - git checkout $REPORT_REF | |
32 | - cd .. | |
33 | ||
34 | ||
35 | flake8: | |
36 | image: python:3 | |
37 | stage: pre_testing | |
38 | before_script: | |
39 | - pip install flake8 | |
40 | # Help flake8 to find the Python files without .py extension. | |
41 | - find . -name '*.py' >> files.txt | |
42 | - sort -u files.txt | tee files.processed | |
43 | script: | |
44 | - python -m flake8 --statistics --count $(cat files.processed) --verbose | |
45 | after_script: | |
46 | - wc -l files.processed | |
47 | ||
48 | .test_base: | |
49 | stage: testing | |
50 | coverage: '/TOTAL\s+\d+\s+\d+\s+(\d+%)/' | |
51 | script: | |
52 | - *clone_reports | |
53 | - *install_faraday_venv | |
54 | - pip3 install $PIP_FLAGS . | |
55 | - pytest tests --capture=sys -v --cov=faraday_plugins --color=yes --disable-warnings $PYTEST_FLAGS | |
56 | ||
57 | tests: | |
58 | extends: .test_base | |
59 | image: python:3 | |
60 | ||
61 | test_performance: | |
62 | extends: .test_base | |
63 | image: python:3 | |
64 | stage: post_testing | |
65 | allow_failure: true | |
66 | variables: | |
67 | PYTEST_FLAGS: --performance | |
68 | rules: | |
69 | - if: '$CI_COMMIT_BRANCH == "dev"' | |
70 | when: on_success | |
71 | ||
72 | publish_pypi: | |
73 | image: python:3 | |
74 | stage: publish | |
75 | script: | |
76 | - apt-get update -qy | |
77 | - apt-get install twine -y | |
78 | - python setup.py sdist bdist_wheel | |
79 | - twine upload -u $PYPI_USER -p $PYPI_PASS dist/* --verbose | |
80 | rules: | |
81 | - if: '$CI_COMMIT_TAG' | |
82 | when: on_success | |
83 |
0 | add a default value to plugin_version⏎ |
0 | Add --output-file parameter to faraday-plugins process command⏎ |
0 | Bug fix: Arachni Plugin 'NoneType' object has no attribute 'find' |
0 | Bug fix: Openvas Plugin - Import xml from OpenVas doesnt work |
0 | Bug fix: QualysWebApp Plugin, error in get info OPERATING_SYSTEM |
0 | Fix Hydra plugin to resolve ip address⏎ |
0 | Update the fields of the nuclei output used to create a vuln⏎ |
0 | Add new plugin base class, for multi line json⏎ |
0 | Fix missing ip in some arachni reports⏎ |
0 | Change the way we detect json reports when they are lists of dictionaries⏎ |
0 | ADD microsoft baseline security analyzer plugin |
0 | Add Ignore information vulnerabilities option |
0 | Faraday CSV Plugin do not consider ignore_info |
0 | Use background for description and detail for data en Burp plugin. |
0 | Metadata-Version: 1.0 | |
1 | Name: faraday-plugins | |
2 | Version: 1.4.6 | |
3 | Summary: Faraday plugins package | |
4 | Home-page: UNKNOWN | |
5 | Author: Faradaysec | |
6 | Author-email: [email protected] | |
7 | License: GNU General Public License v3 | |
8 | Description: UNKNOWN | |
9 | Platform: UNKNOWN |
0 | 1.4.5 [Apr 15th, 2021]: | |
1 | --- | |
2 | * Add Bandit plugin | |
3 | * Use background for description and detail for data en Burp plugin. | |
4 | * Rewrite Appscan Plugin | |
5 | * Parse Nmap vulners script data | |
6 | ||
7 | 1.4.4 [Mar 30th, 2021]: | |
8 | --- | |
9 | * Faraday CSV Plugin do not consider ignore_info | |
10 | ||
11 | 1.4.3 [Mar 17th, 2021]: | |
12 | --- | |
13 | * Add Ignore information vulnerabilities option | |
14 | ||
15 | 1.4.2 [Mar 10th, 2021]: | |
16 | --- | |
17 | * Fix bug with sslyze output file | |
18 | * FIX change id sslyze for JSON/XML | |
19 | ||
20 | 1.4.1 [Feb 26th, 2021]: | |
21 | --- | |
22 | * ADD microsoft baseline security analyzer plugin | |
23 | * ADD nextnet plugin | |
24 | * ADD openscap plugin | |
25 | * FIX old versions of Nessus plugins bugs | |
26 | ||
27 | 1.4.0 [Dec 23rd, 2020]: | |
28 | --- | |
29 | * Update the fields of the nuclei output used to create a vuln | |
30 | ||
31 | 1.4.0b2 [Dec 15th, 2020]: | |
32 | --- | |
33 | * Fix nuclei plugin bug when url is None | |
34 | ||
35 | 1.4.0b1 [Dec 14th, 2020]: | |
36 | --- | |
37 | * Add new plugin base class, for multi line json | |
38 | * New ncrack plugin | |
39 | * New nuclei plugin | |
40 | * New sslyze json plugin | |
41 | * New WhatWeb plugin | |
42 | * Fix missing ip in some arachni reports | |
43 | * Fix change name vuln in Netsparker plugin | |
44 | * Fix whois plugin, command whois IP not parse data | |
45 | * Change the way we detect json reports when they are lists of dictionaries | |
46 | ||
47 | 1.3.0 [Sep 2nd, 2020]: | |
48 | --- | |
49 | * ADD plugin AppSpider | |
50 | * Add tests to faraday-plugins cli | |
51 | * add a default value to plugin_version | |
52 | * Add --output-file parameter to faraday-plugins process command | |
53 | * Add plugins prowler | |
54 | * Add plugins ssl labs | |
55 | * Add support for tenable io | |
56 | * delete old deprecated methods | |
57 | * Bug fix: Arachni Plugin 'NoneType' object has no attribute 'find' | |
58 | * Bug fix: Openvas Plugin - Import xml from OpenVas doesnt work | |
59 | * Bug fix: QualysWebApp Plugin, error in get info OPERATING_SYSTEM | |
60 | * Fix Hydra plugin to resolve ip address | |
61 | * Fix Nessus mod severity HIGH for Low | |
62 | * Bug Fix: Detect plugins AWS Prowler | |
63 | * Fix broken xml on nmap plugin | |
64 | * Add new rdpscan plugin | |
65 | * UPDATE xml report to appscan | |
66 | * Update Readme | |
67 | * Fix how ZAP genereate vulns | |
68 |
0 | with import <nixpkgs> {}; | |
1 | pkgs.python38Packages.buildPythonPackage rec { | |
2 | name = "env"; | |
3 | ||
4 | env = buildEnv { name = name; paths = buildInputs; }; | |
5 | ||
6 | buildInputs = [ | |
7 | (python38.buildEnv.override { | |
8 | ignoreCollisions = true; | |
9 | extraLibs = with python38Packages; [ | |
10 | requests | |
11 | click | |
12 | simplejson | |
13 | requests | |
14 | lxml | |
15 | html2text | |
16 | beautifulsoup4 | |
17 | pytz | |
18 | python-dateutil | |
19 | colorama | |
20 | ]; | |
21 | }) | |
22 | ]; | |
23 | } |
0 | ## Write you own plugins | |
1 | ||
2 | > XML report plugin | |
3 | ||
4 | ```python | |
5 | class XXXPLugin(PluginXMLFormat): | |
6 | ||
7 | def __init__(self): | |
8 | super().__init__() | |
9 | # Tags to be compared with the xml mail tag, can be a list or a string | |
10 | self.identifier_tag = ["tag1", "tag2"] | |
11 | self.id = 'SOME_PLUGIN_ID' # Can't be repeated | |
12 | self.name = 'Some plugin name' | |
13 | self.plugin_version = 'X.X' | |
14 | # The extension is optional, only if its different than xml | |
15 | self.extension = ".xxx" | |
16 | ``` | |
17 | ||
18 | > JSON report plugin | |
19 | ||
20 | ```python | |
21 | class XXXPLugin(PluginJsonFormat): | |
22 | ||
23 | def __init__(self): | |
24 | super().__init__() | |
25 | # keys of the json that identify the report | |
26 | # you don't need to put all the keys, just some of them | |
27 | # it must be a set and will be compared as a subset of the json report keys | |
28 | self.json_keys = {"target_url", "effective_url", "interesting_findings"} | |
29 | self.id = 'SOME_PLUGIN_ID' # Can't be repeated | |
30 | self.name = 'Some plugin name' | |
31 | self.plugin_version = 'X.X' | |
32 | # The extension is optional, only if its different than json | |
33 | self.extension = ".xxx" | |
34 | ```⏎ |
0 | import getpass | |
0 | 1 | import io |
2 | import json | |
1 | 3 | import logging |
2 | 4 | import os |
5 | import shlex | |
6 | import subprocess | |
3 | 7 | import sys |
4 | import json | |
8 | ||
5 | 9 | import click |
6 | import subprocess | |
7 | import shlex | |
8 | import getpass | |
10 | from tabulate import tabulate | |
9 | 11 | |
12 | from faraday_plugins import __version__ | |
10 | 13 | from faraday_plugins.plugins.manager import PluginsManager, ReportAnalyzer, CommandAnalyzer |
11 | 14 | from faraday_plugins.plugins.plugin import PluginByExtension |
12 | 15 | |
20 | 23 | root_logger.addHandler(out_hdlr) |
21 | 24 | root_logger.setLevel(logging.DEBUG) |
22 | 25 | |
26 | CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help']) | |
23 | 27 | |
24 | @click.group() | |
28 | @click.group(context_settings=CONTEXT_SETTINGS) | |
29 | @click.version_option(__version__, '-v', '--version') | |
25 | 30 | def cli(): |
26 | 31 | pass |
27 | 32 | |
30 | 35 | @click.option('-cpf', '--custom-plugins-folder', type=str) |
31 | 36 | def list_plugins(custom_plugins_folder): |
32 | 37 | plugins_manager = PluginsManager(custom_plugins_folder) |
33 | click.echo(click.style("Available Plugins:", fg="cyan")) | |
38 | click.echo(click.style(f"Faraday Plugins v{__version__}", fg="cyan")) | |
39 | click.echo(click.style("Available Plugins :", fg="cyan")) | |
34 | 40 | loaded_plugins = 0 |
41 | plugins_data = [] | |
35 | 42 | for plugin_id, plugin in plugins_manager.get_plugins(): |
36 | 43 | console_enabled = plugin._command_regex is not None |
37 | 44 | console_enabled_color = "green" if console_enabled else "red" |
39 | 46 | report_enabled = isinstance(plugin, PluginByExtension) |
40 | 47 | report_enabled_color = "green" if report_enabled else "red" |
41 | 48 | report_enabled_text = click.style(f"{'Yes' if report_enabled else 'No'}", fg=report_enabled_color) |
42 | click.echo(f"{plugin.id:15} - [Command: {console_enabled_text:>12} - Report: {report_enabled_text:>12}] - {plugin.name} ") | |
43 | ||
44 | loaded_plugins += 1 | |
45 | click.echo(click.style(f"Loaded Plugins: {loaded_plugins}", fg="cyan")) | |
49 | plugins_data.append({"Name": plugin.name, "ID": plugin.id, "Command": console_enabled_text, | |
50 | "Report": report_enabled_text}) | |
51 | click.echo(tabulate( | |
52 | plugins_data, | |
53 | headers="keys", | |
54 | tablefmt="simple", | |
55 | )) | |
56 | click.echo(click.style(f"Loaded Plugins: {len(plugins_data)}", fg="cyan")) | |
46 | 57 | |
47 | 58 | |
48 | 59 | @cli.command() |
0 | import csv | |
1 | import json | |
0 | 2 | import logging |
3 | import os | |
4 | import pkgutil | |
5 | import re | |
6 | import sys | |
1 | 7 | import traceback |
2 | import re | |
3 | import os | |
4 | import sys | |
5 | import json | |
6 | import pkgutil | |
8 | import xml.etree.ElementTree as ET | |
7 | 9 | import zipfile |
8 | 10 | from importlib import import_module |
9 | 11 | from importlib.machinery import SourceFileLoader |
10 | import csv | |
11 | 12 | from io import StringIO |
12 | 13 | |
13 | 14 | from . import repo |
14 | 15 | |
15 | 16 | logger = logging.getLogger("faraday").getChild(__name__) |
16 | ||
17 | try: | |
18 | import xml.etree.cElementTree as ET | |
19 | except ImportError: | |
20 | logger.warning("cElementTree could not be imported. Using ElementTree instead") | |
21 | import xml.etree.ElementTree as ET | |
22 | 17 | |
23 | 18 | |
24 | 19 | class ReportAnalyzer: |
34 | 29 | else: |
35 | 30 | file_name = os.path.basename(report_path) |
36 | 31 | plugin = self._get_plugin_by_name(file_name) |
37 | if not plugin: # Was unable to detect plugin from report file name | |
32 | if not plugin: # Was unable to detect plugin from report file name | |
38 | 33 | logger.debug("Plugin by name not found") |
39 | 34 | plugin = self._get_plugin_by_file_type(report_path) |
40 | 35 | if not plugin: |
67 | 62 | file_name_base, file_extension = os.path.splitext(file_name) |
68 | 63 | file_extension = file_extension.lower() |
69 | 64 | main_tag = None |
70 | file_json_keys = {} | |
71 | 65 | file_csv_headers = set() |
72 | 66 | file_json_keys = set() |
73 | 67 | files_in_zip = set() |
150 | 144 | |
151 | 145 | class PluginsManager: |
152 | 146 | |
153 | def __init__(self, custom_plugins_folder=None, ignore_info = False): | |
147 | def __init__(self, custom_plugins_folder=None, ignore_info=False): | |
154 | 148 | self.ignore_info = ignore_info |
155 | 149 | self.plugins = {} |
156 | 150 | self.plugin_modules = {} |
3 | 3 | See the file 'doc/LICENSE' for the license information |
4 | 4 | |
5 | 5 | """ |
6 | import hashlib | |
7 | import logging | |
6 | 8 | import os |
9 | import re | |
7 | 10 | import shutil |
8 | 11 | import tempfile |
9 | ||
12 | import uuid | |
13 | import zipfile | |
10 | 14 | from collections import defaultdict |
15 | from datetime import datetime | |
11 | 16 | |
12 | 17 | import pytz |
13 | import re | |
14 | import uuid | |
15 | import logging | |
16 | 18 | import simplejson as json |
17 | import zipfile | |
18 | from datetime import datetime | |
19 | import hashlib | |
20 | ||
21 | 19 | |
22 | 20 | logger = logging.getLogger("faraday").getChild(__name__) |
23 | 21 | |
24 | 22 | VALID_SERVICE_STATUS = ("open", "closed", "filtered") |
25 | 23 | VULN_SKIP_FIELDS_TO_HASH = ['run_date'] |
24 | ||
26 | 25 | |
27 | 26 | class PluginBase: |
28 | 27 | # TODO: Add class generic identifier |
40 | 39 | self.name = None |
41 | 40 | self.description = "" |
42 | 41 | self._command_regex = None |
42 | self.command = None | |
43 | 43 | self._output_file_path = None |
44 | 44 | self._use_temp_file = False |
45 | 45 | self._delete_temp_file = False |
101 | 101 | if severity[0:3] in sev: |
102 | 102 | return sev |
103 | 103 | return severity |
104 | ||
104 | 105 | severity = align_string_based_vulns(severity) |
105 | 106 | # Transform numeric severity into desc severity |
106 | 107 | numeric_severities = {"0": "info", |
124 | 125 | self._hosts_cache[cache_id] = obj_uuid |
125 | 126 | else: |
126 | 127 | obj_uuid = self._hosts_cache[cache_id] |
128 | if host['hostnames']: | |
129 | chached_host = self.get_from_cache(obj_uuid) | |
130 | chached_host['hostnames'] = list(set(chached_host['hostnames'] + host['hostnames'])) | |
127 | 131 | return obj_uuid |
128 | 132 | |
129 | 133 | def save_service_cache(self, host_id, service): |
169 | 173 | def _get_dict_hash(d, keys): |
170 | 174 | return hash(frozenset(map(lambda x: (x, d.get(x, None)), keys))) |
171 | 175 | |
172 | ||
173 | 176 | @classmethod |
174 | 177 | def get_host_cache_id(cls, host): |
175 | 178 | cache_id = cls._get_dict_hash(host, ['ip']) |
186 | 189 | def get_service_vuln_cache_id(cls, host_id, service_id, vuln): |
187 | 190 | vuln_copy = vuln.copy() |
188 | 191 | vuln_copy.update({"host_cache_id": host_id, "service_cache_id": service_id}) |
189 | cache_id = cls._get_dict_hash(vuln_copy, ['host_cache_id', 'service_cache_id', 'name', 'desc', 'website', 'path', 'pname', 'method']) | |
192 | cache_id = cls._get_dict_hash(vuln_copy, | |
193 | ['host_cache_id', 'service_cache_id', 'name', 'desc', 'website', 'path', 'pname', | |
194 | 'method']) | |
190 | 195 | return cache_id |
191 | 196 | |
192 | 197 | @classmethod |
193 | 198 | def get_host_vuln_cache_id(cls, host_id, vuln): |
194 | 199 | vuln_copy = vuln.copy() |
195 | 200 | vuln_copy.update({"host_cache_id": host_id}) |
196 | cache_id = cls._get_dict_hash(vuln_copy, ['host_cache_id', 'name', 'desc', 'website', 'path', 'pname', 'method']) | |
201 | cache_id = cls._get_dict_hash(vuln_copy, | |
202 | ['host_cache_id', 'name', 'desc', 'website', 'path', 'pname', 'method']) | |
197 | 203 | return cache_id |
198 | 204 | |
199 | 205 | def save_cache(self, obj): |
227 | 233 | for param, (param_type, value) in self._settings.items(): |
228 | 234 | yield param, value |
229 | 235 | |
230 | def get_ws(self): # TODO Borrar | |
236 | def get_ws(self): # TODO Borrar | |
231 | 237 | return "" |
232 | 238 | |
233 | 239 | def getSetting(self, name): |
248 | 254 | This method can be overriden in the plugin implementation |
249 | 255 | if a different kind of check is needed |
250 | 256 | """ |
251 | return (self._command_regex is not None and | |
252 | self._command_regex.match(current_input.strip()) is not None) | |
257 | if (self._command_regex is not None and | |
258 | self._command_regex.match(current_input.strip()) is not None): | |
259 | self.command = self.get_command(current_input) | |
260 | return True | |
261 | ||
262 | def get_command(self, current_input: str) -> str: | |
263 | command = self._command_regex.findall(current_input)[0] | |
264 | if isinstance(command, tuple): | |
265 | return "".join(command).strip() | |
266 | ||
267 | return command.strip() | |
253 | 268 | |
254 | 269 | def processCommandString(self, username, current_path, command_string): |
255 | 270 | """ |
333 | 348 | tags = [] |
334 | 349 | if isinstance(tags, str): |
335 | 350 | tags = [tags] |
336 | host = {"ip": name, "os": os, "hostnames": hostnames, "description": description, "mac": mac, | |
351 | host = {"ip": name, "os": os, "hostnames": hostnames, "description": description, "mac": mac, | |
337 | 352 | "credentials": [], "services": [], "vulnerabilities": [], "tags": tags} |
338 | 353 | host_id = self.save_host_cache(host) |
339 | 354 | return host_id |
340 | 355 | |
341 | 356 | def createAndAddServiceToHost(self, host_id, name, |
342 | protocol="tcp", ports=None, | |
343 | status="open", version="unknown", | |
344 | description="", tags=None): | |
357 | protocol="tcp", ports=None, | |
358 | status="open", version="", | |
359 | description="", tags=None): | |
345 | 360 | if ports: |
346 | 361 | if isinstance(ports, list): |
347 | 362 | ports = int(ports[0]) |
411 | 426 | tags = [tags] |
412 | 427 | vulnerability = {"name": name, "desc": desc, "severity": self.normalize_severity(severity), "refs": ref, |
413 | 428 | "external_id": external_id, "type": "Vulnerability", "resolution": resolution, "data": data, |
414 | "custom_fields": custom_fields, "status": status, "impact": impact, "policyviolations": policyviolations, | |
429 | "custom_fields": custom_fields, "status": status, "impact": impact, | |
430 | "policyviolations": policyviolations, | |
415 | 431 | "easeofresolution": easeofresolution, "confirmed": confirmed, "tags": tags |
416 | 432 | } |
417 | 433 | if run_date: |
425 | 441 | response="", method="", pname="", |
426 | 442 | params="", query="", category="", data="", external_id=None, |
427 | 443 | confirmed=False, status="", easeofresolution=None, impact=None, |
428 | policyviolations=None, status_code=None, custom_fields=None, run_date=None, tags=None): | |
444 | policyviolations=None, status_code=None, custom_fields=None, run_date=None, | |
445 | tags=None): | |
429 | 446 | if params is None: |
430 | 447 | params = "" |
431 | 448 | if response is None: |
475 | 492 | def createAndAddNoteToHost(self, host_id, name, text): |
476 | 493 | return None |
477 | 494 | |
478 | ||
479 | 495 | def createAndAddNoteToService(self, host_id, service_id, name, text): |
480 | 496 | return None |
481 | 497 | |
491 | 507 | |
492 | 508 | def get_data(self): |
493 | 509 | self.vulns_data["command"]["tool"] = self.id |
494 | self.vulns_data["command"]["command"] = self.id | |
510 | self.vulns_data["command"]["command"] = self.command if self.command else self.id | |
495 | 511 | self.vulns_data["command"]["duration"] = (datetime.now() - self.start_date).microseconds |
496 | 512 | return self.vulns_data |
497 | 513 | |
528 | 544 | summary['vuln_hashes'].append(dict_hash) |
529 | 545 | return summary |
530 | 546 | |
547 | ||
531 | 548 | # TODO Borrar |
532 | 549 | class PluginTerminalOutput(PluginBase): |
533 | 550 | def __init__(self): |
666 | 683 | match = bool(self.files_list & files_in_zip) |
667 | 684 | self.logger.debug("Files List Match: [%s =/in %s] -> %s", files_in_zip, self.files_list, match) |
668 | 685 | return match |
669 | ||
670 |
3 | 3 | See the file 'doc/LICENSE' for the license information |
4 | 4 | |
5 | 5 | """ |
6 | import logging | |
6 | 7 | import os |
7 | import logging | |
8 | 8 | import socket |
9 | from collections import defaultdict | |
10 | ||
11 | 9 | from urllib.parse import urlsplit |
12 | ||
13 | 10 | |
14 | 11 | SERVICE_MAPPER = None |
15 | 12 | |
23 | 20 | "website": "{}://{}".format(parse.scheme, parse.netloc), |
24 | 21 | "path": parse.path, |
25 | 22 | "query": parse.query |
26 | } | |
23 | } | |
24 | ||
27 | 25 | |
28 | 26 | def filter_services(): |
29 | 27 | global SERVICE_MAPPER |
110 | 108 | else: |
111 | 109 | return ip_address |
112 | 110 | |
111 | ||
113 | 112 | def get_severity_from_cvss(cvss): |
114 | 113 | try: |
115 | 114 | if type(cvss) != float: |
116 | 115 | cvss = float(cvss) |
117 | ||
118 | cvss_ranges = [(0.0, 0.1, 'info'), | |
119 | (0.1, 4.0, 'low'), | |
120 | (4.0, 7.0, 'med'), | |
121 | (7.0, 9.0, 'high'), | |
122 | (9.0, 10.1, 'critical')] | |
116 | ||
117 | cvss_ranges = [(0.0, 0.1, 'info'), | |
118 | (0.1, 4.0, 'low'), | |
119 | (4.0, 7.0, 'med'), | |
120 | (7.0, 9.0, 'high'), | |
121 | (9.0, 10.1, 'critical')] | |
123 | 122 | for (lower, upper, severity) in cvss_ranges: |
124 | 123 | if lower <= cvss < upper: |
125 | 124 | return severity |
126 | 125 | except ValueError: |
127 | 126 | return 'unclassified' |
128 |
4 | 4 | |
5 | 5 | """ |
6 | 6 | from urllib.parse import urlsplit |
7 | import re | |
8 | import os | |
9 | 7 | |
10 | 8 | from lxml import etree |
11 | ||
12 | try: | |
13 | import xml.etree.cElementTree as ET | |
14 | import xml.etree.ElementTree as ET_ORIG | |
15 | ETREE_VERSION = ET_ORIG.VERSION | |
16 | except ImportError: | |
17 | import xml.etree.ElementTree as ET | |
18 | ETREE_VERSION = ET.VERSION | |
19 | 9 | |
20 | 10 | from faraday_plugins.plugins.plugin import PluginXMLFormat |
21 | 11 | from faraday_plugins.plugins.plugins_utils import resolve_hostname |
22 | ||
23 | ETREE_VERSION = [int(i) for i in ETREE_VERSION.split(".")] | |
24 | ||
25 | 12 | |
26 | 13 | __author__ = "Francisco Amato" |
27 | 14 | __copyright__ = "Copyright (c) 2013, Infobyte LLC" |
52 | 39 | else: |
53 | 40 | self.sites = [] |
54 | 41 | |
55 | def parse_xml(self, xml_output): | |
42 | @staticmethod | |
43 | def parse_xml(xml_output): | |
56 | 44 | """ |
57 | 45 | Open and parse an xml file. |
58 | 46 | |
70 | 58 | |
71 | 59 | return tree |
72 | 60 | |
73 | def get_items(self, tree): | |
61 | @staticmethod | |
62 | def get_items(tree): | |
74 | 63 | """ |
75 | 64 | @return items A list of Host instances |
76 | 65 | """ |
85 | 74 | |
86 | 75 | @return An attribute value |
87 | 76 | """ |
88 | global ETREE_VERSION | |
89 | node = None | |
90 | ||
91 | if ETREE_VERSION[0] <= 1 and ETREE_VERSION[1] < 3: | |
92 | ||
93 | match_obj = re.search("([^\@]+?)\[\@([^=]*?)=\'([^\']*?)\'", subnode_xpath_expr) | |
94 | ||
95 | if match_obj is not None: | |
96 | node_to_find = match_obj.group(1) | |
97 | xpath_attrib = match_obj.group(2) | |
98 | xpath_value = match_obj.group(3) | |
99 | for node_found in xml_node.findall(node_to_find): | |
100 | if node_found.attrib[xpath_attrib] == xpath_value: | |
101 | node = node_found | |
102 | break | |
103 | else: | |
104 | node = xml_node.find(subnode_xpath_expr) | |
105 | ||
106 | else: | |
107 | node = xml_node.find(subnode_xpath_expr) | |
77 | ||
78 | node = xml_node.find(subnode_xpath_expr) | |
108 | 79 | |
109 | 80 | if node is not None: |
110 | 81 | return node.get(attrib_name) |
286 | 257 | ref=item.ref) |
287 | 258 | del parser |
288 | 259 | |
289 | def setHost(self): | |
290 | pass | |
291 | ||
292 | 260 | |
293 | 261 | def createPlugin(ignore_info=False): |
294 | return AcunetixPlugin(ignore_info=ignore_info)⏎ | |
262 | return AcunetixPlugin(ignore_info=ignore_info) |
3 | 3 | See the file 'doc/LICENSE' for the license information |
4 | 4 | """ |
5 | 5 | import argparse |
6 | import random | |
6 | import re | |
7 | 7 | import shlex |
8 | import tempfile | |
8 | import socket | |
9 | 9 | |
10 | 10 | from faraday_plugins.plugins.plugin import PluginBase |
11 | import socket | |
12 | import re | |
13 | import os | |
14 | ||
15 | from faraday_plugins.plugins.plugins_utils import resolve_hostname | |
16 | ||
17 | 11 | |
18 | 12 | |
19 | 13 | class AmapPlugin(PluginBase): |
30 | 24 | self._command_regex = re.compile(r'^(amap|sudo amap)\s+.*?') |
31 | 25 | self._use_temp_file = True |
32 | 26 | self._hosts = [] |
27 | self.args = None | |
33 | 28 | |
34 | 29 | def parseOutputString(self, output): |
35 | 30 | services = {} |
106 | 101 | |
107 | 102 | return ip6[0][4][0] |
108 | 103 | |
109 | def setHost(self): | |
110 | pass | |
111 | ||
112 | 104 | def processCommandString(self, username, current_path, command_string): |
113 | 105 | """ |
114 | 106 | Adds the -m parameter to get machine readable output. |
135 | 127 | cmd.remove("-6") |
136 | 128 | cmd.insert(1, "-6") |
137 | 129 | |
138 | args = None | |
139 | 130 | if len(cmd) > 4: |
140 | 131 | try: |
141 | args, unknown = parser.parse_known_args(cmd) | |
132 | self.args, unknown = parser.parse_known_args(cmd) | |
142 | 133 | except SystemExit: |
143 | 134 | pass |
144 | 135 | |
145 | self.args = args | |
146 | 136 | return final |
147 | 137 | |
148 | 138 | |
149 | 139 | def createPlugin(ignore_info=False): |
150 | 140 | return AmapPlugin(ignore_info=ignore_info) |
151 | ||
152 |
0 | from urllib.parse import urlparse | |
1 | ||
0 | 2 | from faraday_plugins.plugins.plugin import PluginXMLFormat |
1 | 3 | from faraday_plugins.plugins.plugins_utils import resolve_hostname |
2 | import dateutil.parser | |
3 | from urllib.parse import urlparse | |
4 | try: | |
5 | import xml.etree.cElementTree as ET | |
6 | except ImportError: | |
7 | import xml.etree.ElementTree as ET | |
8 | ||
4 | ||
5 | import xml.etree.ElementTree as ET | |
9 | 6 | |
10 | 7 | __author__ = "Nicolas Rebagliati" |
11 | 8 | __copyright__ = "Copyright (c) 2021, Infobyte LLC" |
32 | 29 | self.entities = self.get_entity_groups(tree.find('entity-group')) |
33 | 30 | self.issues = self.get_dast_issues(tree.find("issue-group")) |
34 | 31 | |
35 | ||
36 | ||
37 | def parse_xml(self, xml_output): | |
32 | @staticmethod | |
33 | def parse_xml(xml_output): | |
38 | 34 | try: |
39 | 35 | tree = ET.fromstring(xml_output) |
40 | 36 | except SyntaxError as err: |
42 | 38 | return None |
43 | 39 | return tree |
44 | 40 | |
45 | def get_fixes(self, tree): | |
41 | @staticmethod | |
42 | def get_fixes(tree): | |
46 | 43 | fixes = {} |
47 | 44 | for item in tree: |
48 | 45 | fix_id = item.attrib['id'] |
51 | 48 | fixes[fix_id] = {"library": library, "location": location} |
52 | 49 | return fixes |
53 | 50 | |
54 | def get_issue_types(self, tree): | |
51 | @staticmethod | |
52 | def get_issue_types(tree): | |
55 | 53 | issue_types = {} |
56 | 54 | for item in tree: |
57 | 55 | type_id = item.attrib['id'] |
59 | 57 | issue_types[type_id] = name |
60 | 58 | return issue_types |
61 | 59 | |
62 | def get_remediations(self, tree): | |
60 | @staticmethod | |
61 | def get_remediations(tree): | |
63 | 62 | remediations = {} |
64 | 63 | for item in tree: |
65 | 64 | remediation_id = item.attrib['id'] |
67 | 66 | remediations[remediation_id] = name |
68 | 67 | return remediations |
69 | 68 | |
70 | def get_hosts(self, tree): | |
69 | @staticmethod | |
70 | def get_hosts(tree): | |
71 | 71 | hosts = {} |
72 | 72 | for item in tree: |
73 | 73 | host = item.find("host").text |
83 | 83 | "service_name": service_name} |
84 | 84 | return hosts |
85 | 85 | |
86 | def get_entity_groups(self, tree): | |
86 | @staticmethod | |
87 | def get_entity_groups(tree): | |
87 | 88 | entity_groups = {} |
88 | 89 | for item in tree: |
89 | 90 | entity_id = item.attrib['id'] |
237 | 238 | return sast_issues |
238 | 239 | |
239 | 240 | |
240 | ||
241 | 241 | class AppScanPlugin(PluginXMLFormat): |
242 | 242 | |
243 | 243 | def __init__(self, *arg, **kwargs): |
249 | 249 | self.version = '1.0.0' |
250 | 250 | self.framework_version = '1.0.0' |
251 | 251 | |
252 | ||
253 | 252 | def parseOutputString(self, output): |
254 | 253 | parser = AppScanParser(output) |
255 | 254 | scan_type = parser.scan_type |
256 | ||
257 | 255 | |
258 | 256 | if scan_type == 'DAST': |
259 | 257 | for issue in parser.issues: |
260 | 258 | host = issue.pop("host") |
261 | 259 | port = issue.pop("port") |
262 | host_os = issue.pop("os") | |
263 | 260 | service_name = issue.pop("service_name") |
264 | 261 | ip = resolve_hostname(host) |
265 | host_id = self.createAndAddHost(ip, hostnames=host) | |
262 | host_os = issue.pop("os") | |
263 | host_id = self.createAndAddHost(ip, hostnames=host, os=host_os) | |
266 | 264 | service_id = self.createAndAddServiceToHost(host_id, service_name, ports=port) |
267 | 265 | self.createAndAddVulnWebToService(host_id=host_id, service_id=service_id, **issue) |
268 | 266 |
4 | 4 | Copyright (C) 2016 Infobyte LLC (http://www.infobytesec.com/) |
5 | 5 | See the file 'doc/LICENSE' for the license information |
6 | 6 | """ |
7 | import xml.etree.ElementTree as ET | |
8 | from datetime import datetime | |
9 | ||
7 | 10 | from faraday_plugins.plugins.plugin import PluginXMLFormat |
8 | from datetime import datetime | |
9 | try: | |
10 | import xml.etree.cElementTree as ET | |
11 | except ImportError: | |
12 | import xml.etree.ElementTree as ET | |
13 | 11 | |
14 | 12 | __author__ = 'Blas Moyano' |
15 | 13 | __copyright__ = 'Copyright 2020, Faraday Project' |
24 | 22 | self.tree = self.parse_xml(xml_output) |
25 | 23 | if self.tree: |
26 | 24 | self.vuln_list = self.tree.find('VulnList') |
27 | self.name_scan = self.tree.find('ScanName').text | |
25 | self.name_scan = self.tree.findtext('ScanName') | |
28 | 26 | else: |
29 | 27 | self.tree = None |
30 | 28 | |
31 | def parse_xml(self, xml_output): | |
29 | @staticmethod | |
30 | def parse_xml(xml_output): | |
32 | 31 | try: |
33 | 32 | tree = ET.fromstring(xml_output) |
34 | 33 | except SyntaxError as err: |
71 | 70 | data_info = [] |
72 | 71 | |
73 | 72 | for vulns in parser.vuln_list: |
74 | vuln_name = vulns.find('VulnType').text | |
75 | vuln_desc = vulns.find('Description').text | |
76 | vuln_ref = vulns.find('VulnUrl').text | |
77 | severity = vulns.find('AttackScore').text | |
78 | vuln_resolution = vulns.find('Recommendation').text | |
79 | vuln_external_id = vulns.find('DbId').text | |
80 | vuln_run_date = vulns.find('ScanDate').text | |
81 | data_info.append(vulns.find('AttackClass').text) | |
82 | data_info.append(vulns.find('CweId').text) | |
83 | data_info.append(vulns.find('CAPEC').text) | |
84 | data_info.append(vulns.find('DISSA_ASC').text) | |
85 | data_info.append(vulns.find('OWASP2007').text) | |
86 | data_info.append(vulns.find('OWASP2010').text) | |
87 | data_info.append(vulns.find('OWASP2013').text) | |
88 | data_info.append(vulns.find('OVAL').text) | |
89 | data_info.append(vulns.find('WASC').text) | |
73 | vuln_name = vulns.findtext('VulnType') | |
74 | vuln_desc = vulns.findtext('Description') | |
75 | vuln_ref = vulns.findtext('VulnUrl') | |
76 | severity = vulns.findtext('AttackScore') | |
77 | vuln_resolution = vulns.findtext('Recommendation') | |
78 | vuln_external_id = vulns.findtext('DbId') | |
79 | vuln_run_date = vulns.findtext('ScanDate') | |
80 | data_info.append(vulns.findtext('AttackClass')) | |
81 | data_info.append(vulns.findtext('CweId')) | |
82 | data_info.append(vulns.findtext('CAPEC')) | |
83 | data_info.append(vulns.findtext('DISSA_ASC')) | |
84 | data_info.append(vulns.findtext('OWASP2007')) | |
85 | data_info.append(vulns.findtext('OWASP2010')) | |
86 | data_info.append(vulns.findtext('OWASP2013')) | |
87 | data_info.append(vulns.findtext('OVAL')) | |
88 | data_info.append(vulns.findtext('WASC')) | |
90 | 89 | |
91 | 90 | if severity == '1-Informational': |
92 | 91 | severity = 0 |
2 | 2 | Copyright (C) 2016 Infobyte LLC (http://www.infobytesec.com/) |
3 | 3 | See the file 'doc/LICENSE' for the license information |
4 | 4 | """ |
5 | import os | |
5 | 6 | import re |
7 | import xml.etree.ElementTree as ET | |
6 | 8 | from urllib.parse import urlparse |
7 | import os | |
9 | ||
8 | 10 | from faraday_plugins.plugins.plugin import PluginXMLFormat |
9 | 11 | from faraday_plugins.plugins.plugins_utils import resolve_hostname |
10 | ||
11 | try: | |
12 | import xml.etree.cElementTree as ET | |
13 | except ImportError: | |
14 | import xml.etree.ElementTree as ET | |
15 | 12 | |
16 | 13 | __author__ = 'Ezequiel Tavella' |
17 | 14 | __copyright__ = 'Copyright 2016, Faraday Project' |
199 | 196 | else: |
200 | 197 | options_string = None |
201 | 198 | |
202 | ||
203 | 199 | try: |
204 | 200 | self.user_agent = self.node.find('user_agent').text |
205 | 201 | except: |
230 | 226 | |
231 | 227 | def getNote(self): |
232 | 228 | result = ('Scan url:\n {} \nUser Agent:\n {} \nVersion Arachni:\n {} \nStart time:\n {} \nFinish time:\n {}' |
233 | '\nAudited Elements:\n {} \nModules:\n {} \nCookies:\n {}').format(self.url, self.user_agent, | |
234 | self.version, self.start_time, | |
235 | self.finish_time, | |
236 | self.audited_elements, | |
237 | self.modules, self.cookies) | |
229 | '\nAudited Elements:\n {} \nModules:\n {} \nCookies:\n {}').format(self.url, self.user_agent, | |
230 | self.version, self.start_time, | |
231 | self.finish_time, | |
232 | self.audited_elements, | |
233 | self.modules, self.cookies) | |
238 | 234 | |
239 | 235 | return result |
240 | 236 | |
241 | 237 | |
242 | 238 | class Plugins(): |
243 | ||
244 | 239 | """ |
245 | 240 | Support: |
246 | 241 | WAF (Web Application Firewall) Detector (waf_detector) |
492 | 487 | |
493 | 488 | def createPlugin(ignore_info=False): |
494 | 489 | return ArachniPlugin(ignore_info=ignore_info) |
495 | ||
496 |
94 | 94 | severity=3) |
95 | 95 | |
96 | 96 | |
97 | def setHost(self): | |
98 | pass | |
99 | ||
100 | 97 | |
101 | 98 | def createPlugin(ignore_info=False): |
102 | 99 | return BeefPlugin(ignore_info=ignore_info) |
3 | 3 | See the file 'doc/LICENSE' for the license information |
4 | 4 | |
5 | 5 | """ |
6 | import re | |
7 | import os | |
8 | 6 | import base64 |
7 | import distutils.util # pylint: disable=import-error | |
8 | import xml.etree.ElementTree as ET | |
9 | from urllib.parse import urlsplit | |
10 | ||
9 | 11 | from bs4 import BeautifulSoup, Comment |
12 | ||
10 | 13 | from faraday_plugins.plugins.plugin import PluginXMLFormat |
11 | from urllib.parse import urlsplit | |
12 | import distutils.util #pylint: disable=import-error | |
13 | ||
14 | ||
15 | try: | |
16 | import xml.etree.cElementTree as ET | |
17 | import xml.etree.ElementTree as ET_ORIG | |
18 | ETREE_VERSION = ET_ORIG.VERSION | |
19 | except ImportError: | |
20 | import xml.etree.ElementTree as ET | |
21 | ETREE_VERSION = ET.VERSION | |
22 | ||
23 | ETREE_VERSION = [int(i) for i in ETREE_VERSION.split(".")] | |
24 | ||
25 | 14 | |
26 | 15 | __author__ = "Francisco Amato" |
27 | 16 | __copyright__ = "Copyright (c) 2013, Infobyte LLC" |
77 | 66 | """ |
78 | 67 | @return items A list of Host instances |
79 | 68 | """ |
80 | bugtype = '' | |
81 | 69 | |
82 | 70 | for node in tree.findall('issue'): |
83 | 71 | yield Item(node) |
89 | 77 | |
90 | 78 | @return An attribute value |
91 | 79 | """ |
92 | global ETREE_VERSION | |
93 | node = None | |
94 | ||
95 | if ETREE_VERSION[0] <= 1 and ETREE_VERSION[1] < 3: | |
96 | ||
97 | match_obj = re.search( | |
98 | "([^\@]+?)\[\@([^=]*?)=\'([^\']*?)\'", subnode_xpath_expr) | |
99 | if match_obj is not None: | |
100 | ||
101 | node_to_find = match_obj.group(1) | |
102 | xpath_attrib = match_obj.group(2) | |
103 | xpath_value = match_obj.group(3) | |
104 | for node_found in xml_node.findall(node_to_find): | |
105 | if node_found.attrib[xpath_attrib] == xpath_value: | |
106 | node = node_found | |
107 | break | |
108 | else: | |
109 | node = xml_node.find(subnode_xpath_expr) | |
110 | ||
111 | else: | |
112 | node = xml_node.find(subnode_xpath_expr) | |
80 | node = xml_node.find(subnode_xpath_expr) | |
113 | 81 | |
114 | 82 | if node is not None: |
115 | 83 | return node.get(attrib_name) |
164 | 132 | self.background = background |
165 | 133 | self.external_id = external_id.text |
166 | 134 | |
167 | ||
168 | def do_clean(self, value): | |
135 | @staticmethod | |
136 | def do_clean(value): | |
169 | 137 | |
170 | 138 | myreturn = "" |
171 | 139 | if value is not None: |
221 | 189 | self._current_output = None |
222 | 190 | self.target = None |
223 | 191 | |
224 | ||
225 | 192 | def parseOutputString(self, output): |
226 | 193 | |
227 | 194 | parser = BurpXmlParser(output) |
247 | 214 | data = self.removeHtml(data) |
248 | 215 | resolution = self.removeHtml(item.remediation) if item.remediation else "" |
249 | 216 | |
250 | v_id = self.createAndAddVulnWebToService( | |
217 | self.createAndAddVulnWebToService( | |
251 | 218 | h_id, |
252 | 219 | s_id, |
253 | 220 | item.name, |
263 | 230 | |
264 | 231 | del parser |
265 | 232 | |
266 | ||
267 | 233 | def removeHtml(self, markup): |
268 | 234 | soup = BeautifulSoup(markup, "html.parser") |
269 | 235 | |
291 | 257 | |
292 | 258 | return str(soup) |
293 | 259 | |
294 | def setHost(self): | |
295 | pass | |
296 | ||
297 | 260 | |
298 | 261 | def createPlugin(ignore_info=False): |
299 | 262 | return BurpPlugin(ignore_info=ignore_info) |
300 | ||
301 |
2 | 2 | Copyright (C) 2016 Infobyte LLC (http://www.infobytesec.com/) |
3 | 3 | See the file 'doc/LICENSE' for the license information |
4 | 4 | """ |
5 | import re | |
5 | import xml.etree.ElementTree as ET | |
6 | 6 | from urllib.parse import urlparse |
7 | 7 | |
8 | 8 | from faraday_plugins.plugins.plugin import PluginXMLFormat |
9 | ||
10 | ||
11 | try: | |
12 | import xml.etree.cElementTree as ET | |
13 | except ImportError: | |
14 | import xml.etree.ElementTree as ET | |
15 | 9 | |
16 | 10 | __author__ = 'Blas Moyano' |
17 | 11 | __copyright__ = 'Copyright 2020, Faraday Project' |
69 | 63 | for info_pn in pn: |
70 | 64 | if info_pn.tag == 'Snippet': |
71 | 65 | valor = ( |
72 | 'Number', info_pn.find('Line').find('Number').text, 'Code', info_pn.find('Line').find('Code').text) | |
66 | 'Number', info_pn.find('Line').find('Number').text, 'Code', | |
67 | info_pn.find('Line').find('Code').text) | |
73 | 68 | else: |
74 | 69 | valor = (info_pn.tag, info_pn.text) |
75 | 70 | lista_v.append(valor) |
88 | 83 | self.version = '1.0.0' |
89 | 84 | self.framework_version = '1.0.0' |
90 | 85 | self.options = None |
91 | ||
92 | 86 | |
93 | 87 | def parseOutputString(self, output): |
94 | 88 | parser = CheckmarxXmlParser(output) |
139 | 133 | |
140 | 134 | def createPlugin(ignore_info=False): |
141 | 135 | return CheckmarxPlugin(ignore_info=ignore_info) |
142 |
25 | 25 | self.plugin_version = "0.0.1" |
26 | 26 | self.version = "2.22" |
27 | 27 | self.regexpUrl = r'((http[s]?)\:\/\/([\w\.]+)[.\S]+)' |
28 | self._command_regex = re.compile(r'^(?:sudo dirb|dirb|\.\/dirb|sudo \.\/dirb)\s+(?:(http[s]?)' | |
29 | r'\:\/\/([\w\.]+)[.\S]+)') | |
28 | self._command_regex = re.compile(r'^(sudo dirb|dirb|\.\/dirb|sudo \.\/dirb)\s+.*?') | |
29 | ||
30 | 30 | self.text = [] |
31 | 31 | |
32 | 32 | def getPort(self, host, proto): |
58 | 58 | self.name = "dirsearch" |
59 | 59 | self.plugin_version = "0.0.1" |
60 | 60 | self.version = "0.0.1" |
61 | self._command_regex = re.compile(r'^(sudo )?(python[0-9\.]? )?dirsearch(\.py)\s+?') | |
61 | self._command_regex = re.compile(r'^(sudo )?(python[0-9\.]? )?(dirsearch\.py)\s+?') | |
62 | 62 | self.addSetting("Ignore 403", str, "1") |
63 | 63 | self._use_temp_file = True |
64 | 64 | self._temp_file_extension = "json" |
65 | 65 | |
66 | 66 | def parseOutputString(self, output): |
67 | 67 | self.parse_json(output) |
68 | ||
69 | 68 | |
70 | 69 | @property |
71 | 70 | def should_ignore_403(self): |
3 | 3 | See the file 'doc/LICENSE' for the license information |
4 | 4 | |
5 | 5 | """ |
6 | import re | |
7 | import xml.etree.ElementTree as ET | |
8 | ||
6 | 9 | from faraday_plugins.plugins.plugin import PluginBase |
7 | import re | |
8 | import os | |
9 | ||
10 | try: | |
11 | import xml.etree.cElementTree as ET | |
12 | import xml.etree.ElementTree as ET_ORIG | |
13 | ETREE_VERSION = ET_ORIG.VERSION | |
14 | except ImportError: | |
15 | import xml.etree.ElementTree as ET | |
16 | ETREE_VERSION = ET.VERSION | |
17 | ||
18 | ETREE_VERSION = [int(i) for i in ETREE_VERSION.split(".")] | |
19 | ||
20 | 10 | |
21 | 11 | __author__ = "Francisco Amato" |
22 | 12 | __copyright__ = "Copyright (c) 2013, Infobyte LLC" |
68 | 58 | """ |
69 | 59 | @return items A list of Host instances |
70 | 60 | """ |
71 | bugtype = '' | |
72 | 61 | |
73 | 62 | node = tree.findall('testdata')[0] |
74 | 63 | for hostnode in node.findall('host'): |
81 | 70 | |
82 | 71 | @return An attribute value |
83 | 72 | """ |
84 | global ETREE_VERSION | |
85 | node = None | |
86 | 73 | |
87 | if ETREE_VERSION[0] <= 1 and ETREE_VERSION[1] < 3: | |
88 | ||
89 | match_obj = re.search( | |
90 | "([^\@]+?)\[\@([^=]*?)=\'([^\']*?)\'", subnode_xpath_expr) | |
91 | if match_obj is not None: | |
92 | node_to_find = match_obj.group(1) | |
93 | xpath_attrib = match_obj.group(2) | |
94 | xpath_value = match_obj.group(3) | |
95 | for node_found in xml_node.findall(node_to_find): | |
96 | if node_found.attrib[xpath_attrib] == xpath_value: | |
97 | node = node_found | |
98 | break | |
99 | else: | |
100 | node = xml_node.find(subnode_xpath_expr) | |
101 | ||
102 | else: | |
103 | node = xml_node.find(subnode_xpath_expr) | |
74 | node = xml_node.find(subnode_xpath_expr) | |
104 | 75 | |
105 | 76 | if node is not None: |
106 | 77 | return node.get(attrib_name) |
175 | 146 | parser = DnsenumXmlParser(output) |
176 | 147 | |
177 | 148 | for item in parser.items: |
178 | h_id = self.createAndAddHost(item.ip, hostnames=[item.hostname]) | |
149 | self.createAndAddHost(item.ip, hostnames=[item.hostname]) | |
179 | 150 | |
180 | 151 | del parser |
181 | 152 | |
192 | 163 | else: |
193 | 164 | return re.sub(arg_match.group(1), r"-o %s" % self._output_file_path, command_string) |
194 | 165 | |
195 | def setHost(self): | |
196 | pass | |
197 | ||
198 | 166 | |
199 | 167 | def createPlugin(ignore_info=False): |
200 | 168 | return DnsenumPlugin(ignore_info=ignore_info) |
201 | ||
202 |
2 | 2 | Copyright (C) 2013 Infobyte LLC (http://www.infobytesec.com/) |
3 | 3 | See the file 'doc/LICENSE' for the license information |
4 | 4 | """ |
5 | from faraday_plugins.plugins.plugin import PluginBase | |
6 | 5 | import re |
7 | 6 | from collections import defaultdict |
8 | 7 | |
8 | from faraday_plugins.plugins.plugin import PluginBase | |
9 | 9 | |
10 | 10 | __author__ = "Francisco Amato" |
11 | 11 | __copyright__ = "Copyright (c) 2013, Infobyte LLC" |
103 | 103 | self._use_temp_file = True |
104 | 104 | self._temp_file_extension = "txt" |
105 | 105 | |
106 | ||
107 | 106 | def canParseCommandString(self, current_input): |
108 | 107 | if self._command_regex.match(current_input.strip()): |
108 | self.command = self.get_command(current_input) | |
109 | 109 | return True |
110 | 110 | else: |
111 | 111 | return False |
138 | 138 | |
139 | 139 | def createPlugin(ignore_info=False): |
140 | 140 | return DnsmapPlugin(ignore_info=ignore_info) |
141 | ||
142 |
2 | 2 | Copyright (C) 2013 Infobyte LLC (http://www.infobytesec.com/) |
3 | 3 | See the file 'doc/LICENSE' for the license information |
4 | 4 | """ |
5 | import re | |
6 | import xml.etree.ElementTree as ET | |
7 | ||
5 | 8 | from faraday_plugins.plugins.plugin import PluginBase |
6 | import re | |
7 | ||
8 | try: | |
9 | import xml.etree.cElementTree as ET | |
10 | import xml.etree.ElementTree as ET_ORIG | |
11 | ETREE_VERSION = ET_ORIG.VERSION | |
12 | except ImportError: | |
13 | import xml.etree.ElementTree as ET | |
14 | ETREE_VERSION = ET.VERSION | |
15 | ||
16 | ETREE_VERSION = [int(i) for i in ETREE_VERSION.split(".")] | |
17 | ||
18 | 9 | |
19 | 10 | __author__ = "Francisco Amato" |
20 | 11 | __copyright__ = "Copyright (c) 2013, Infobyte LLC" |
77 | 68 | |
78 | 69 | @return An attribute value |
79 | 70 | """ |
80 | global ETREE_VERSION | |
81 | node = None | |
82 | ||
83 | if ETREE_VERSION[0] <= 1 and ETREE_VERSION[1] < 3: | |
84 | ||
85 | match_obj = re.search( | |
86 | "([^\@]+?)\[\@([^=]*?)=\'([^\']*?)\'", subnode_xpath_expr) | |
87 | if match_obj is not None: | |
88 | ||
89 | node_to_find = match_obj.group(1) | |
90 | xpath_attrib = match_obj.group(2) | |
91 | xpath_value = match_obj.group(3) | |
92 | for node_found in xml_node.findall(node_to_find): | |
93 | if node_found.attrib[xpath_attrib] == xpath_value: | |
94 | node = node_found | |
95 | break | |
96 | else: | |
97 | node = xml_node.find(subnode_xpath_expr) | |
98 | ||
99 | else: | |
100 | node = xml_node.find(subnode_xpath_expr) | |
71 | ||
72 | node = xml_node.find(subnode_xpath_expr) | |
101 | 73 | |
102 | 74 | if node is not None: |
103 | 75 | return node.get(attrib_name) |
204 | 176 | status="open") |
205 | 177 | |
206 | 178 | if host.zonetransfer == "success": |
207 | v_id = self.createAndAddVulnToService( | |
179 | self.createAndAddVulnToService( | |
208 | 180 | h_id, |
209 | 181 | s_id, |
210 | 182 | name="Zone transfer", |
238 | 210 | r"--xml %s" % self._output_file_path, |
239 | 211 | command_string) |
240 | 212 | |
241 | def setHost(self): | |
242 | pass | |
243 | ||
244 | 213 | |
245 | 214 | def createPlugin(ignore_info=False): |
246 | 215 | return DnsreconPlugin(ignore_info=ignore_info) |
247 | ||
248 |
4 | 4 | |
5 | 5 | """ |
6 | 6 | import re |
7 | import os | |
8 | 7 | |
9 | 8 | from faraday_plugins.plugins.plugin import PluginBase |
10 | 9 | from faraday_plugins.plugins.plugins_utils import resolve_hostname |
11 | ||
12 | 10 | |
13 | 11 | __author__ = "Francisco Amato" |
14 | 12 | __copyright__ = "Copyright (c) 2013, Infobyte LLC" |
41 | 39 | for line in lists: |
42 | 40 | mregex = re.search("WARN: ([\w\.]+) ([\w]+) ([\w\.]+):", line) |
43 | 41 | if mregex is not None: |
44 | ||
45 | 42 | item = { |
46 | 43 | 'host': mregex.group(1), |
47 | 44 | 'ip': mregex.group(3), |
62 | 59 | self.items.append(item) |
63 | 60 | |
64 | 61 | |
65 | ||
66 | 62 | class DnswalkPlugin(PluginBase): |
67 | 63 | """ |
68 | 64 | Example plugin to parse dnswalk output. |
79 | 75 | self._command_regex = re.compile( |
80 | 76 | r'^(sudo dnswalk|dnswalk|\.\/dnswalk)\s+.*?') |
81 | 77 | |
82 | ||
83 | 78 | def canParseCommandString(self, current_input): |
84 | 79 | if self._command_regex.match(current_input.strip()): |
80 | self.command = self.get_command(current_input) | |
85 | 81 | return True |
86 | 82 | else: |
87 | 83 | return False |
114 | 110 | |
115 | 111 | def createPlugin(ignore_info=False): |
116 | 112 | return DnswalkPlugin(ignore_info=ignore_info) |
117 | ||
118 |
126 | 126 | else: |
127 | 127 | return False |
128 | 128 | |
129 | def setHost(self): | |
130 | pass | |
129 | ||
131 | 130 | |
132 | 131 | |
133 | 132 | def createPlugin(ignore_info=False): |
3 | 3 | See the file 'doc/LICENSE' for the license information |
4 | 4 | |
5 | 5 | """ |
6 | import re | |
6 | ||
7 | import xml.etree.ElementTree as ET | |
7 | 8 | |
8 | 9 | from faraday_plugins.plugins.plugin import PluginXMLFormat |
9 | try: | |
10 | import xml.etree.cElementTree as ET | |
11 | import xml.etree.ElementTree as ET_ORIG | |
12 | ETREE_VERSION = ET_ORIG.VERSION | |
13 | except ImportError: | |
14 | import xml.etree.ElementTree as ET | |
15 | ETREE_VERSION = ET.VERSION | |
16 | ||
17 | ETREE_VERSION = [int(i) for i in ETREE_VERSION.split(".")] | |
18 | ||
19 | 10 | |
20 | 11 | __author__ = "Francisco Amato" |
21 | 12 | __copyright__ = "Copyright (c) 2013, Infobyte LLC" |
41 | 32 | def __init__(self, xml_output): |
42 | 33 | tree = self.parse_xml(xml_output) |
43 | 34 | if tree: |
44 | self.items = [data for data in self.get_items(tree)] | |
35 | self.items = self.get_items(tree) | |
45 | 36 | else: |
46 | 37 | self.items = [] |
47 | 38 | |
103 | 94 | agentip = node.get('name').split("/")[1] |
104 | 95 | |
105 | 96 | if self.ip == agentip: |
106 | ||
107 | 97 | self.agentip = agentip |
108 | 98 | |
109 | 99 | self.ipfrom = self.get_text_from_subnode( |
227 | 217 | mapped_services = {} |
228 | 218 | mapped_ports = {} |
229 | 219 | for item in parser.items: |
230 | os_string = f"{item.os} {item.arch }" | |
220 | os_string = f"{item.os} {item.arch}" | |
231 | 221 | h_id = self.createAndAddHost(item.ip, os=os_string, hostnames=[item.host]) |
232 | 222 | |
233 | 223 | for service in item.services: |
281 | 271 | del parser |
282 | 272 | |
283 | 273 | |
284 | def setHost(self): | |
285 | pass | |
286 | ||
287 | ||
288 | 274 | def createPlugin(ignore_info=False): |
289 | 275 | return ImpactPlugin(ignore_info=ignore_info) |
290 | ||
291 |
4 | 4 | |
5 | 5 | """ |
6 | 6 | import os |
7 | ||
7 | 8 | from lxml import etree |
9 | ||
8 | 10 | from faraday_plugins.plugins.plugin import PluginXMLFormat |
9 | ||
10 | ||
11 | try: | |
12 | import xml.etree.cElementTree as ET | |
13 | import xml.etree.ElementTree as ET_ORIG | |
14 | ETREE_VERSION = ET_ORIG.VERSION | |
15 | except ImportError: | |
16 | import xml.etree.ElementTree as ET | |
17 | ETREE_VERSION = ET.VERSION | |
18 | ||
19 | ETREE_VERSION = [int(i) for i in ETREE_VERSION.split(".")] | |
20 | 11 | |
21 | 12 | current_path = os.path.abspath(os.getcwd()) |
22 | 13 | |
66 | 57 | self.items = [data for data in self.get_items(tree)] |
67 | 58 | else: |
68 | 59 | self.items = [] |
69 | ||
60 | ||
70 | 61 | def parse_xml(self, xml_output): |
71 | 62 | """ |
72 | 63 | Open and parse an xml file. |
132 | 123 | self._current_output = None |
133 | 124 | |
134 | 125 | def parseOutputString(self, output): |
135 | ||
136 | 126 | parser = JunitXmlParser(output) |
137 | 127 | for item in parser.items: |
138 | 128 | h_id = self.createAndAddHost(item.host, os="Linux") |
2 | 2 | Copyright (C) 2015 Infobyte LLC (http://www.infobytesec.com/) |
3 | 3 | See the file 'doc/LICENSE' for the license information |
4 | 4 | """ |
5 | import xml.etree.ElementTree as ET | |
6 | import zipfile | |
7 | ||
5 | 8 | from faraday_plugins.plugins.plugin import PluginZipFormat |
6 | import re | |
7 | import os | |
8 | import zipfile | |
9 | ||
10 | 9 | from faraday_plugins.plugins.plugins_utils import resolve_hostname |
11 | ||
12 | try: | |
13 | import xml.etree.cElementTree as ET | |
14 | import xml.etree.ElementTree as ET_ORIG | |
15 | ETREE_VERSION = ET_ORIG.VERSION | |
16 | except ImportError: | |
17 | import xml.etree.ElementTree as ET | |
18 | ETREE_VERSION = ET.VERSION | |
19 | ||
20 | ETREE_VERSION = [int(i) for i in ETREE_VERSION.split(".")] | |
21 | ||
22 | 10 | |
23 | 11 | __author__ = "Ezequiel Tavella" |
24 | 12 | __copyright__ = "Copyright (c) 2015, Infobyte LLC" |
169 | 157 | entity = node.find( |
170 | 158 | "{http://graphml.graphdrawing.org/xmlns}data/" |
171 | 159 | "{http://maltego.paterva.com/xml/mtgx}MaltegoEntity") |
172 | ||
173 | 160 | |
174 | 161 | # Check if is IPv4Address |
175 | 162 | if entity.get("type") not in ("maltego.IPv4Address", "maltego.Domain", "maltego.Website"): |
418 | 405 | try: |
419 | 406 | text = f'Location:\n {host.location["name"]} \nArea:\n {host.location["area"]} ' \ |
420 | 407 | f'\nArea 2:\n {host.location["area_2"]} ' \ |
421 | f'\nCountry_code:\n { host.location["country_code"]} ' \ | |
408 | f'\nCountry_code:\n {host.location["country_code"]} ' \ | |
422 | 409 | f'\nLatitude:\n {host.location["latitude"]} \nLongitude:\n {host.location["longitude"]}' |
423 | 410 | except TypeError: |
424 | 411 | text = "unknown" |
466 | 453 | host_ip = '0.0.0.0' |
467 | 454 | host_id = self.createAndAddHost(name=host_ip, hostnames=hostnames) |
468 | 455 | |
469 | ||
470 | 456 | if maltego_parser.xml.get('location'): |
471 | 457 | location_name = maltego_parser.getInfoMtgl(maltego_parser.xml['location'], 'location.name') |
472 | 458 | location_area = maltego_parser.getInfoMtgl(maltego_parser.xml['location'], 'location.area') |
509 | 495 | description="DNS Server") |
510 | 496 | |
511 | 497 | |
512 | ||
513 | ||
514 | 498 | def createPlugin(ignore_info=False): |
515 | 499 | return MaltegoPlugin(ignore_info=ignore_info) |
129 | 129 | else: |
130 | 130 | return False |
131 | 131 | |
132 | def setHost(self): | |
133 | pass | |
132 | ||
134 | 133 | |
135 | 134 | |
136 | 135 | def createPlugin(ignore_info=False): |
2 | 2 | Copyright (C) 2013 Infobyte LLC (http://www.infobytesec.com/) |
3 | 3 | See the file 'doc/LICENSE' for the license information |
4 | 4 | """ |
5 | import xml.etree.ElementTree as ET | |
6 | ||
5 | 7 | from faraday_plugins.plugins.plugin import PluginXMLFormat |
6 | import re | |
7 | ||
8 | ||
9 | try: | |
10 | import xml.etree.cElementTree as ET | |
11 | import xml.etree.ElementTree as ET_ORIG | |
12 | ETREE_VERSION = ET_ORIG.VERSION | |
13 | except ImportError: | |
14 | import xml.etree.ElementTree as ET | |
15 | ETREE_VERSION = ET.VERSION | |
16 | ||
17 | ETREE_VERSION = [int(i) for i in ETREE_VERSION.split(".")] | |
18 | 8 | |
19 | 9 | __author__ = "Francisco Amato" |
20 | 10 | __copyright__ = "Copyright (c) 2013, Infobyte LLC" |
76 | 66 | """ |
77 | 67 | @return items A list of Host instances |
78 | 68 | """ |
79 | bugtype = "" | |
80 | 69 | |
81 | 70 | for node in tree.findall('hosts/host'): |
82 | 71 | yield Host(node, webVulns) |
85 | 74 | """ |
86 | 75 | @return items A list of WebVuln instances |
87 | 76 | """ |
88 | bugtype = "" | |
89 | 77 | for node in tree.findall('web_vulns/web_vuln'): |
90 | 78 | yield WebVuln(node, services) |
91 | 79 | |
96 | 84 | |
97 | 85 | @return An attribute value |
98 | 86 | """ |
99 | global ETREE_VERSION | |
100 | node = None | |
101 | ||
102 | if ETREE_VERSION[0] <= 1 and ETREE_VERSION[1] < 3: | |
103 | ||
104 | match_obj = re.search( | |
105 | "([^\@]+?)\[\@([^=]*?)=\'([^\']*?)\'", subnode_xpath_expr) | |
106 | if match_obj is not None: | |
107 | node_to_find = match_obj.group(1) | |
108 | xpath_attrib = match_obj.group(2) | |
109 | xpath_value = match_obj.group(3) | |
110 | for node_found in xml_node.findall(node_to_find): | |
111 | if node_found.attrib[xpath_attrib] == xpath_value: | |
112 | node = node_found | |
113 | break | |
114 | else: | |
115 | node = xml_node.find(subnode_xpath_expr) | |
116 | ||
117 | else: | |
118 | node = xml_node.find(subnode_xpath_expr) | |
87 | ||
88 | node = xml_node.find(subnode_xpath_expr) | |
119 | 89 | |
120 | 90 | if node is not None: |
121 | 91 | return node.get(attrib_name) |
210 | 180 | self.query = self.get_text_from_subnode('query') |
211 | 181 | self.request = self.get_text_from_subnode('request') |
212 | 182 | self.category = self.get_text_from_subnode('category-id') |
213 | self.service_id = services[self.get_text_from_subnode('web-site-id')] | |
183 | web_id = self.get_text_from_subnode('web-site-id') | |
184 | self.service_id = None | |
185 | if web_id: | |
186 | self.service_id = services[web_id] | |
187 | ||
214 | 188 | self.isWeb = True |
215 | 189 | |
216 | 190 | def get_text_from_subnode(self, subnode_xpath_expr): |
219 | 193 | |
220 | 194 | @return An attribute value |
221 | 195 | """ |
196 | ||
222 | 197 | sub_node = self.node.find(subnode_xpath_expr) |
223 | 198 | if sub_node is not None: |
224 | 199 | if sub_node.text is not None: |
335 | 310 | self.options = None |
336 | 311 | self.target = None |
337 | 312 | |
338 | ||
339 | 313 | def parseOutputString(self, output): |
340 | 314 | """ |
341 | 315 | This method will discard the output the shell sends, it will read it from |
348 | 322 | self.hostnames = [] |
349 | 323 | if item.host: |
350 | 324 | self.hostnames = [item.host] |
351 | ||
325 | ||
352 | 326 | h_id = self.createAndAddHost(item.ip, os=item.os, hostnames=self.hostnames) |
353 | 327 | |
354 | 328 | if item.id + "_" in item.notesByService: |
356 | 330 | self.createAndAddNoteToHost(h_id, n.ntype, n.data) |
357 | 331 | |
358 | 332 | for v in item.vulnsByHost: |
359 | v_id = self.createAndAddVulnToHost( | |
333 | self.createAndAddVulnToHost( | |
360 | 334 | h_id, v.name, v.desc, ref=v.refs) |
361 | 335 | |
362 | 336 | for s in item.services: |
363 | 337 | s_id = self.createAndAddServiceToHost(h_id, s['name'], |
364 | protocol=s['proto'], | |
365 | ports=[s['port']], | |
366 | status=s['state'], | |
367 | description=s['info']) | |
338 | protocol=s['proto'], | |
339 | ports=[s['port']], | |
340 | status=s['state'], | |
341 | description=s['info']) | |
368 | 342 | |
369 | 343 | if item.id + "_" + s['id'] in item.notesByService: |
370 | 344 | for n in item.notesByService[item.id + "_" + s['id']]: |
375 | 349 | for c in item.credsByService[s['port']]: |
376 | 350 | self.createAndAddCredToService( |
377 | 351 | h_id, s_id, c.user, c.passwd) |
378 | self.createAndAddVulnToService(h_id, s_id, "Weak Credentials", "[metasploit found the following credentials]\nuser:%s\npass:%s" % ( | |
379 | c.user, c.passwd), severity="high") | |
352 | self.createAndAddVulnToService(h_id, s_id, "Weak Credentials", | |
353 | "[metasploit found the following credentials]\nuser:%s\npass:%s" % ( | |
354 | c.user, c.passwd), severity="high") | |
380 | 355 | |
381 | 356 | for v in item.vulnsByService[s['id']]: |
382 | 357 | if v.isWeb: |
383 | v_id = self.createAndAddVulnWebToService(h_id, s_id, v.name, v.desc, | |
358 | self.createAndAddVulnWebToService(h_id, s_id, v.name, v.desc, | |
384 | 359 | severity=v.risk, website=v.host, |
385 | 360 | path=v.path, request=v.request, method=v.method, |
386 | 361 | pname=v.pname, params=v.params, query=v.query, |
387 | 362 | category=v.category) |
388 | 363 | else: |
389 | v_id = self.createAndAddVulnToService( | |
364 | self.createAndAddVulnToService( | |
390 | 365 | h_id, s_id, v.name, v.desc, ref=v.refs) |
391 | 366 | |
392 | 367 | del parser |
393 | 368 | |
394 | def _isIPV4(self, ip): | |
369 | @staticmethod | |
370 | def _isIPV4(ip): | |
395 | 371 | if len(ip.split(".")) == 4: |
396 | 372 | return True |
397 | 373 | else: |
398 | 374 | return False |
399 | 375 | |
400 | 376 | |
401 | def setHost(self): | |
402 | pass | |
403 | ||
404 | ||
405 | 377 | def createPlugin(ignore_info=False): |
406 | 378 | return MetasploitPlugin(ignore_info=ignore_info) |
407 | ||
408 |
0 | """ | |
1 | Faraday Plugins | |
2 | Copyright (c) 2021 Faraday Security LLC (https://www.faradaysec.com/) | |
3 | See the file 'doc/LICENSE' for the license information | |
4 | ||
5 | """ | |
6 | import socket | |
7 | import json | |
8 | import re | |
9 | from faraday_plugins.plugins.plugin import PluginMultiLineJsonFormat | |
10 | ||
11 | __author__ = 'Emilio Couto' | |
12 | __copyright__ = 'Copyright (c) 2021, Faraday Security LLC' | |
13 | __credits__ = ['Emilio Couto'] | |
14 | __license__ = '' | |
15 | __version__ = '0.0.1' | |
16 | __maintainer__ = 'Emilio Couto' | |
17 | __email__ = '[email protected]' | |
18 | __status__ = 'Development' | |
19 | ||
20 | ||
21 | class NaabuPlugin(PluginMultiLineJsonFormat): | |
22 | """ | |
23 | Parse Naabu (from Project Discovery) scanner JSON output | |
24 | """ | |
25 | ||
26 | def __init__(self, *arg, **kwargs): | |
27 | super().__init__(*arg, **kwargs) | |
28 | self.id = 'naabu' | |
29 | self.name = 'Naabu' | |
30 | self.plugin_version = '0.1' | |
31 | self.version = '2.0.3' | |
32 | self.json_keys = {'host', 'ip', 'port'} | |
33 | self._command_regex = re.compile(r'^(sudo naabu|naabu|\.\/nmap)\s+.*?') | |
34 | ||
35 | def parseOutputString(self, output, debug=False): | |
36 | for host_json in filter(lambda x: x != '', output.split('\n')): | |
37 | host_dict = json.loads(host_json) | |
38 | host = host_dict.get('host') | |
39 | ip = host_dict.get('ip') | |
40 | port = host_dict.get('port') | |
41 | try: | |
42 | service = socket.getservbyport(port) | |
43 | except socket.error: | |
44 | service = 'Unknown service on port ' + str(port) | |
45 | host_id = self.createAndAddHost( | |
46 | name=ip, | |
47 | hostnames=[host]) | |
48 | self.createAndAddServiceToHost( | |
49 | host_id, | |
50 | name=service, | |
51 | ports=port, | |
52 | protocol='tcp', | |
53 | status='open', | |
54 | version='', | |
55 | description='') | |
56 | ||
57 | def processCommandString(self, username, current_path, command_string): | |
58 | """ | |
59 | Adds the -oX parameter to get xml output to the command string that the | |
60 | user has set. | |
61 | """ | |
62 | super().processCommandString(username, current_path, command_string) | |
63 | if " -json" not in command_string: | |
64 | command_string += " -json" | |
65 | if " -silent" not in command_string: | |
66 | command_string += " -silent" | |
67 | return command_string | |
68 | ||
69 | def createPlugin(ignore_info=False): | |
70 | return NaabuPlugin(ignore_info=ignore_info) |
4 | 4 | |
5 | 5 | """ |
6 | 6 | |
7 | import xml.etree.ElementTree as ET | |
8 | ||
7 | 9 | from faraday_plugins.plugins.plugin import PluginXMLFormat |
8 | try: | |
9 | import xml.etree.cElementTree as ET | |
10 | except ImportError: | |
11 | import xml.etree.ElementTree as ET | |
12 | ||
13 | 10 | |
14 | 11 | __author__ = "Blas Moyano" |
15 | 12 | __copyright__ = "Copyright (c) 2020, Infobyte LLC" |
6 | 6 | from faraday_plugins.plugins.plugin import PluginBase |
7 | 7 | import re |
8 | 8 | |
9 | try: | |
10 | import xml.etree.cElementTree as ET | |
11 | import xml.etree.ElementTree as ET_ORIG | |
12 | except ImportError: | |
13 | import xml.etree.ElementTree as ET | |
9 | import xml.etree.ElementTree as ET | |
14 | 10 | |
15 | 11 | __author__ = 'Ezequiel Tavella' |
16 | 12 | __copyright__ = 'Copyright (c) 2016, Infobyte LLC' |
0 | from typing import List | |
1 | ||
2 | ||
3 | class Attachment: | |
4 | def __init__(self, node): | |
5 | self.node = node | |
6 | ||
7 | @property | |
8 | def name_attr(self): | |
9 | return self.node.get("name") | |
10 | ||
11 | @property | |
12 | def type_attr(self): | |
13 | return self.node.get("type") | |
14 | ||
15 | @property | |
16 | def text(self): | |
17 | return self.node.text | |
18 | ||
19 | ||
20 | class ReportItem: | |
21 | def __init__(self, node): | |
22 | self.node = node | |
23 | ||
24 | @property | |
25 | def port_attr(self): | |
26 | return self.node.get("port") | |
27 | ||
28 | @property | |
29 | def svc_name_attr(self): | |
30 | return self.node.get("svc_name") | |
31 | ||
32 | @property | |
33 | def protocol_attr(self): | |
34 | return self.node.get("protocol") | |
35 | ||
36 | @property | |
37 | def severity_attr(self): | |
38 | return self.node.get("severity") | |
39 | ||
40 | @property | |
41 | def plugin_id_attr(self): | |
42 | plugin_id = self.node.get("pluginID") | |
43 | if plugin_id: | |
44 | plugin_id = f'NESSUS-{plugin_id}' | |
45 | return plugin_id | |
46 | ||
47 | @property | |
48 | def plugin_name_attr(self): | |
49 | return self.node.get("pluginName") | |
50 | ||
51 | @property | |
52 | def plugin_family_attr(self): | |
53 | return self.node.get("pluginFamily") | |
54 | ||
55 | @property | |
56 | def agent(self): | |
57 | return self.node.findtext("agent") | |
58 | ||
59 | @property | |
60 | def description(self): | |
61 | return self.node.findtext("description", "Not Description") | |
62 | ||
63 | @property | |
64 | def fname(self): | |
65 | return self.node.findtext("fname") | |
66 | ||
67 | @property | |
68 | def plugin_modification_date(self): | |
69 | return self.node.findtext("plugin_modification_date") | |
70 | ||
71 | @property | |
72 | def plugin_name(self): | |
73 | ||
74 | plugin_name = self.node.findtext("plugin_name") | |
75 | if not plugin_name: | |
76 | plugin_name = self.plugin_name_attr | |
77 | return plugin_name | |
78 | ||
79 | @property | |
80 | def plugin_publication_date(self): | |
81 | return self.node.findtext("plugin_publication_date") | |
82 | ||
83 | @property | |
84 | def plugin_type(self): | |
85 | return self.node.findtext("plugin_type") | |
86 | ||
87 | @property | |
88 | def risk_factor(self): | |
89 | risk_factor = self.node.findtext("risk_factor") | |
90 | if risk_factor == 'None' or risk_factor is None: | |
91 | risk_factor = self.severity_attr # I checked several external id and most of them were info | |
92 | return risk_factor | |
93 | ||
94 | @property | |
95 | def script_version(self): | |
96 | return self.node.findtext("script_version") | |
97 | ||
98 | @property | |
99 | def see_also(self): | |
100 | return self.node.findtext("see_also") | |
101 | ||
102 | @property | |
103 | def solution(self): | |
104 | return self.node.findtext("solution", '') | |
105 | ||
106 | @property | |
107 | def synopsis(self): | |
108 | return self.node.findtext("synopsis") | |
109 | ||
110 | @property | |
111 | def plugin_output(self): | |
112 | return self.node.findtext("plugin_output", "") | |
113 | ||
114 | @property | |
115 | def always_run(self): | |
116 | return self.node.findtext("always_run") | |
117 | ||
118 | @property | |
119 | def asset_inventory(self): | |
120 | return self.node.findtext("asset_inventory") | |
121 | ||
122 | @property | |
123 | def canvas_package(self): | |
124 | return self.node.findtext("canvas_package") | |
125 | ||
126 | @property | |
127 | def cvss3_base_score(self): | |
128 | cvss_base_score = self.node.findtext("cvss3_base_score") | |
129 | if cvss_base_score: | |
130 | cvss_base_score = f"CVSS3:{cvss_base_score}" | |
131 | return cvss_base_score | |
132 | ||
133 | @property | |
134 | def cvss3_temporal_score(self): | |
135 | return self.node.findtext("cvss3_temporal_score") | |
136 | ||
137 | @property | |
138 | def cpe(self): | |
139 | return self.node.findtext("cpe") | |
140 | ||
141 | @property | |
142 | def cvss3_temporal_vector(self): | |
143 | return self.node.findtext("cvss3_temporal_vector") | |
144 | ||
145 | @property | |
146 | def cvss3_vector(self): | |
147 | return self.node.findtext("cvss3_vector") | |
148 | ||
149 | @property | |
150 | def cvss_base_score(self): | |
151 | cvss_base_score = self.node.findtext("cvss_base_score") | |
152 | if cvss_base_score: | |
153 | cvss_base_score = f"CVSS:{cvss_base_score}" | |
154 | return cvss_base_score | |
155 | ||
156 | @property | |
157 | def cvss_score_rationale(self): | |
158 | return self.node.findtext("cvss_score_rationale") | |
159 | ||
160 | @property | |
161 | def cvss_score_source(self): | |
162 | return self.node.findtext("cvss_score_source") | |
163 | ||
164 | @property | |
165 | def cvss_temporal_score(self): | |
166 | return self.node.findtext("cvss_temporal_score") | |
167 | ||
168 | @property | |
169 | def cvss_temporal_vector(self): | |
170 | return self.node.findtext("cvss_temporal_vector") | |
171 | ||
172 | @property | |
173 | def cvss_vector(self): | |
174 | cvss_vector = self.node.findtext("cvss_vector") | |
175 | if cvss_vector: | |
176 | cvss_vector = f"CVSSVECTOR:{cvss_vector}" | |
177 | return cvss_vector | |
178 | ||
179 | @property | |
180 | def exploit_available(self): | |
181 | exploit_avalible = self.node.findtext("exploit_available", "") | |
182 | if exploit_avalible: | |
183 | exploit_avalible = f"Exploit available: {exploit_avalible.capitalize()}\n" | |
184 | return exploit_avalible | |
185 | ||
186 | @property | |
187 | def exploit_framework_canvas(self): | |
188 | return self.node.findtext("exploit_framework_canvas") | |
189 | ||
190 | @property | |
191 | def exploit_framework_core(self): | |
192 | return self.node.findtext("exploit_framework_core") | |
193 | ||
194 | @property | |
195 | def exploit_framework_d2_elliot(self): | |
196 | return self.node.findtext("exploit_framework_d2_elliot") | |
197 | ||
198 | @property | |
199 | def exploit_framework_metasploit(self): | |
200 | return self.node.findtext("exploit_framework_metasploit") | |
201 | ||
202 | @property | |
203 | def exploitability_ease(self): | |
204 | return self.node.findtext("exploitability_ease") | |
205 | ||
206 | @property | |
207 | def exploited_by_malware(self): | |
208 | return self.node.findtext("exploited_by_malware") | |
209 | ||
210 | @property | |
211 | def exploited_by_nessus(self): | |
212 | return self.node.findtext("exploited_by_nessus") | |
213 | ||
214 | @property | |
215 | def hardware_inventory(self): | |
216 | return self.node.findtext("hardware_inventory") | |
217 | ||
218 | @property | |
219 | def iava(self): | |
220 | return self.node.findtext("iava") | |
221 | ||
222 | @property | |
223 | def iavb(self): | |
224 | return self.node.findtext("iavb") | |
225 | ||
226 | @property | |
227 | def iavt(self): | |
228 | return self.node.findtext("iavt") | |
229 | ||
230 | @property | |
231 | def in_the_news(self): | |
232 | return self.node.findtext("in_the_news") | |
233 | ||
234 | @property | |
235 | def metasploit_name(self): | |
236 | return self.node.findtext("metasploit_name") | |
237 | ||
238 | @property | |
239 | def os_identification(self): | |
240 | return self.node.findtext("os_identification") | |
241 | ||
242 | @property | |
243 | def owasp(self): | |
244 | return self.node.findtext("owasp") | |
245 | ||
246 | @property | |
247 | def patch_publication_date(self): | |
248 | return self.node.findtext("patch_publication_date") | |
249 | ||
250 | ||
251 | @property | |
252 | def stig_severity(self): | |
253 | return self.node.findtext("stig_severity") | |
254 | ||
255 | @property | |
256 | def d2_elliot_name(self): | |
257 | return self.node.findtext("d2_elliot_name") | |
258 | ||
259 | @property | |
260 | def unsupported_by_vendor(self): | |
261 | return self.node.findtext("unsupported_by_vendor") | |
262 | ||
263 | @property | |
264 | def vuln_publication_date(self): | |
265 | return self.node.findtext("vuln_publication_date") | |
266 | ||
267 | @property | |
268 | def msft(self): | |
269 | return self.node.findtext("msft") | |
270 | ||
271 | ||
272 | @property | |
273 | def cert(self) -> list: | |
274 | return self.node.findall("cert") | |
275 | ||
276 | @property | |
277 | def bid(self) -> list: | |
278 | return self.node.findall("bid") | |
279 | ||
280 | @property | |
281 | def cve(self) -> list: | |
282 | return [i.text for i in self.node.findall("cve")] | |
283 | ||
284 | @property | |
285 | def cwe(self) -> list: | |
286 | return [i.text for i in self.node.findall("cwe")] | |
287 | ||
288 | @property | |
289 | def edb_id(self) -> list: | |
290 | return self.node.findall("edb-id") | |
291 | ||
292 | @property | |
293 | def mskb(self) -> list: | |
294 | return self.node.findall("mskb") | |
295 | ||
296 | @property | |
297 | def xref(self) -> str: | |
298 | return self.node.findtext("xref") | |
299 | ||
300 | @property | |
301 | def attachment(self) -> Attachment: | |
302 | attachment = self.node.find("attachment") | |
303 | return Attachment(attachment) if attachment else None | |
304 | ||
305 | def get_data(self): | |
306 | item_tags = {} | |
307 | for i in self.node: | |
308 | item_tags.setdefault(i.tag, i.text) | |
309 | return item_tags | |
310 | ||
311 | ||
312 | class Tag: | |
313 | def __init__(self, node): | |
314 | self.node = node | |
315 | ||
316 | @property | |
317 | def name_attr(self) -> str: | |
318 | return self.node.get("name") | |
319 | ||
320 | @property | |
321 | def text(self) -> str: | |
322 | return self.node.text | |
323 | ||
324 | ||
325 | class HostProperties: | |
326 | def __init__(self, node): | |
327 | self.node = node | |
328 | ||
329 | @property | |
330 | def tag(self) -> list: | |
331 | return [Tag(i) for i in self.node.findall('tag')] | |
332 | ||
333 | @property | |
334 | def host_end(self) -> str: | |
335 | _dict = self.dict_tags | |
336 | return _dict.get("HOST_END") | |
337 | ||
338 | @property | |
339 | def mac_address(self) -> str: | |
340 | _dict = self.dict_tags | |
341 | return _dict.get("mac-address", "") | |
342 | ||
343 | @property | |
344 | def operating_system(self) -> str: | |
345 | _dict = self.dict_tags | |
346 | return _dict.get("operating-system", None) | |
347 | ||
348 | @property | |
349 | def host_ip(self) -> str: | |
350 | _dict = self.dict_tags | |
351 | ||
352 | return _dict.get("host-ip", None) | |
353 | ||
354 | @property | |
355 | def host_fqdn(self) -> str: | |
356 | _dict = self.dict_tags | |
357 | return _dict.get("host-fqdn", None) | |
358 | ||
359 | @property | |
360 | def dict_tags(self): | |
361 | host_tags = {} | |
362 | for t in self.node: | |
363 | host_tags.setdefault(t.attrib.get('name'), t.text) | |
364 | return host_tags | |
365 | ||
366 | ||
367 | class ReportHost: | |
368 | def __init__(self, node): | |
369 | self.node = node | |
370 | ||
371 | @property | |
372 | def name(self) -> str: | |
373 | return self.node.get("name") | |
374 | ||
375 | @property | |
376 | def host_properties(self) -> HostProperties: | |
377 | return HostProperties(self.node.find("HostProperties")) | |
378 | ||
379 | @property | |
380 | def report_items(self) -> List[ReportItem]: | |
381 | return [ReportItem(i) for i in self.node.findall("ReportItem")] | |
382 | ||
383 | ||
384 | class Report: | |
385 | ||
386 | def __init__(self, node): | |
387 | self.node = node | |
388 | ||
389 | @property | |
390 | def name_attr(self) -> str: | |
391 | return self.node.get("name") | |
392 | ||
393 | @property | |
394 | def report_hosts(self) -> List[ReportHost]: | |
395 | return [ReportHost(i) for i in self.node.findall('ReportHost')] | |
396 |
3 | 3 | See the file 'doc/LICENSE' for the license information |
4 | 4 | |
5 | 5 | """ |
6 | import dateutil | |
7 | from collections import namedtuple | |
8 | 6 | |
9 | from faraday_plugins.plugins.plugin import PluginXMLFormat | |
10 | 7 | import xml.etree.ElementTree as ET |
11 | 8 | |
9 | import dateutil | |
10 | from faraday_plugins.plugins.plugin import PluginXMLFormat | |
12 | 11 | |
13 | 12 | __author__ = "Blas" |
14 | 13 | __copyright__ = "Copyright (c) 2019, Infobyte LLC" |
19 | 18 | __email__ = "[email protected]" |
20 | 19 | __status__ = "Development" |
21 | 20 | |
22 | ReportItem = namedtuple('ReportItem', ['port', 'svc_name', 'protocol', 'severity', 'plugin_id', | |
23 | 'plugin_name', 'plugin_family', 'description', 'plugin_output', 'info']) | |
21 | from faraday_plugins.plugins.repo.nessus.DTO import ReportHost, Report, ReportItem | |
22 | ||
24 | 23 | |
25 | 24 | class NessusParser: |
26 | 25 | """ |
35 | 34 | |
36 | 35 | def __init__(self, output): |
37 | 36 | self.tree = ET.fromstring(output) |
38 | self.tag_control = [] | |
39 | for x in self.tree: | |
40 | self.tag_control.append(x) | |
37 | self.report = [] | |
41 | 38 | if self.tree: |
42 | self.policy = self.getPolicy(self.tree) | |
43 | self.report = self.getReport(self.tree) | |
44 | else: | |
45 | self.policy = None | |
46 | self.report = None | |
39 | self.report = self.__get_report() | |
47 | 40 | |
48 | def getPolicy(self, tree): | |
49 | policy_tree = tree.find('Policy') | |
50 | if policy_tree: | |
51 | return Policy(policy_tree) | |
52 | else: | |
53 | return None | |
41 | def __get_report(self) -> Report: | |
42 | report = self.tree.find('Report') | |
43 | return Report(report) if report else None | |
54 | 44 | |
55 | def getReport(self, tree): | |
56 | report_tree = tree.find('Report') | |
57 | return Report(report_tree) | |
58 | ||
59 | def parse_compliance_data(self, data: dict): | |
60 | compliance_data = {} | |
61 | for key, value in data.items(): | |
62 | if 'compliance-' in key: | |
63 | compliance_name = key.split("}")[-1] | |
64 | compliance_data[compliance_name] = value | |
65 | return compliance_data | |
66 | ||
67 | class Policy(): | |
68 | def __init__(self, policy_node): | |
69 | self.node = policy_node | |
70 | self.policy_name = self.node.find('policyName').text | |
71 | self.preferences = self.getPreferences(self.node.find('Preferences')) | |
72 | self.family_selection = self.getFamilySelection(self.node.find('FamilySelection')) | |
73 | self.individual_plugin_selection = self.getIndividualPluginSelection( | |
74 | self.node.find('IndividualPluginSelection')) | |
75 | ||
76 | def getPreferences(self, preferences): | |
77 | server_preferences = preferences.find('ServerPreferences') | |
78 | plugins_preferences = preferences.find('PluginsPreferences') | |
79 | server_preferences_all = [] | |
80 | plugins_preferences_json = {} | |
81 | plugins_preferences_all = [] | |
82 | for sp in server_preferences: | |
83 | sp_value = sp.find('value').text | |
84 | sp_name = sp.find('name').text | |
85 | server_preferences_all.append("Server Preferences name: {}, Server Preferences value: {}".format(sp_name, | |
86 | sp_value)) | |
87 | for pp in plugins_preferences: | |
88 | for pp_detail in pp: | |
89 | plugins_preferences_json.setdefault(pp_detail.tag, pp_detail.text) | |
90 | plugins_preferences_all.append(plugins_preferences_json) | |
91 | return server_preferences_all, plugins_preferences_all | |
92 | ||
93 | def getFamilySelection(self, family): | |
94 | family_all = [] | |
95 | for f in family: | |
96 | family_name = f.find('FamilyName').text | |
97 | family_value = f.find('Status').text | |
98 | family_all.append("Family Name: {}, Family Value: {}".format(family_name, family_value)) | |
99 | return family_all | |
100 | ||
101 | def getIndividualPluginSelection(self, individual): | |
102 | item_plugin = [] | |
103 | for i in individual: | |
104 | plugin_id = i.find('PluginId').text | |
105 | plugin_name = i.find('PluginName').text | |
106 | plugin_family = i.find('Family').text | |
107 | plugin_status = i.find('Status').text | |
108 | item_plugin.append("Plugin ID: {}, Plugin Name: {}, Family: {}, Status: {}".format(plugin_id, plugin_name, | |
109 | plugin_family, | |
110 | plugin_status)) | |
111 | return item_plugin | |
112 | ||
113 | class Report(): | |
114 | def __init__(self, report_node): | |
115 | self.node = report_node | |
116 | self.report_name = self.node.attrib.get('name') | |
117 | self.report_host = self.node.find('ReportHost') | |
118 | self.report_desc = [] | |
119 | self.report_ip = [] | |
120 | self.report_serv = [] | |
121 | self.report_json = {} | |
122 | if self.report_host is not None: | |
123 | for x in self.node: | |
124 | report_host_ip = x.attrib.get('name') | |
125 | host_properties = self.gethosttag(x.find('HostProperties')) | |
126 | report_items = self.getreportitems(x.findall('ReportItem')) | |
127 | self.report_ip.append(report_host_ip) | |
128 | self.report_desc.append(host_properties) | |
129 | self.report_serv.append(report_items) | |
130 | self.report_json['ip'] = self.report_ip | |
131 | self.report_json['desc'] = self.report_desc | |
132 | self.report_json['serv'] = self.report_serv | |
133 | self.report_json['host_end'] = host_properties.get('HOST_END') | |
134 | ||
135 | else: | |
136 | self.report_host_ip = None | |
137 | self.host_properties = None | |
138 | self.report_items = None | |
139 | self.report_json = None | |
140 | ||
141 | def getreportitems(self, items): | |
142 | report_items = [] | |
143 | ||
144 | for item in items: | |
145 | port = item.attrib.get('port') | |
146 | svc_name = item.attrib.get('svc_name') | |
147 | protocol = item.attrib.get('protocol') | |
148 | severity = item.attrib.get('severity') | |
149 | plugin_id = item.attrib.get('pluginID') | |
150 | plugin_name = item.attrib.get('pluginName') | |
151 | plugin_family = item.attrib.get('pluginFamily') | |
152 | if item.find('plugin_output') is not None: | |
153 | plugin_output = item.find('plugin_output').text | |
154 | else: | |
155 | plugin_output = "Not Description" | |
156 | if item.find('description') is not None: | |
157 | description = item.find('description').text | |
158 | else: | |
159 | description = "Not Description" | |
160 | info = self.getinfoitem(item) | |
161 | report_items.append(ReportItem(*[port, svc_name, protocol, severity, plugin_id, | |
162 | plugin_name, plugin_family, description, plugin_output, info])) | |
163 | return report_items | |
164 | ||
165 | def getinfoitem(self, item): | |
166 | item_tags = {} | |
167 | for i in item: | |
168 | item_tags.setdefault(i.tag, i.text) | |
169 | return item_tags | |
170 | ||
171 | def gethosttag(self, tags): | |
172 | host_tags = {} | |
173 | for t in tags: | |
174 | host_tags.setdefault(t.attrib.get('name'), t.text) | |
175 | return host_tags | |
176 | 45 | |
177 | 46 | class NessusPlugin(PluginXMLFormat): |
178 | 47 | """ |
190 | 59 | self.framework_version = "1.0.1" |
191 | 60 | self.options = None |
192 | 61 | |
62 | @staticmethod | |
63 | def parse_compliance_data(data: dict): | |
64 | compliance_data = {} | |
65 | for key, value in data.items(): | |
66 | if 'compliance-' in key: | |
67 | compliance_name = key.split("}")[-1] | |
68 | compliance_data[compliance_name] = value | |
69 | return compliance_data | |
70 | ||
71 | @staticmethod | |
72 | def map_properties(host: ReportHost): | |
73 | return { | |
74 | "name": host.host_properties.host_ip if host.host_properties.host_ip else host.name, | |
75 | "hostnames": host.host_properties.host_fqdn, | |
76 | "mac": host.host_properties.mac_address, | |
77 | "os": host.host_properties.operating_system | |
78 | } | |
79 | ||
80 | @staticmethod | |
81 | def map_item(host_id, run_date, plugin_name, item: ReportItem) -> dict: | |
82 | cvss_base_score = item.cvss_base_score | |
83 | data = item.plugin_output | |
84 | data += f'{item.exploit_available}' | |
85 | return { | |
86 | "host_id": host_id, | |
87 | "name": plugin_name, | |
88 | "severity": item.risk_factor, | |
89 | "data": data, | |
90 | "external_id": item.plugin_id_attr, | |
91 | "run_date": run_date, | |
92 | "desc": item.description, | |
93 | "resolution": item.solution, | |
94 | "ref": [cvss_base_score] if cvss_base_score else [] | |
95 | } | |
96 | ||
97 | def map_policy_general(self, kwargs, item: ReportItem): | |
98 | kwargs.update({"policyviolations": []}) | |
99 | if item.plugin_family_attr == 'Policy Compliance': | |
100 | data = item.get_data() | |
101 | bis_benchmark_data = kwargs["desc"].split('\n') | |
102 | compliance_data = self.parse_compliance_data(data) | |
103 | compliance_info = compliance_data.get('compliance-info', '') | |
104 | if compliance_info and not kwargs["desc"]: | |
105 | kwargs["desc"] = compliance_info | |
106 | compliance_reference = compliance_data.get( | |
107 | 'compliance-reference', '').replace('|', ':').split(',') | |
108 | compliance_result = compliance_data.get('compliance-result', '') | |
109 | for reference in compliance_reference: | |
110 | kwargs["ref"].append(reference) | |
111 | compliance_check_name = compliance_data.get('compliance-check-name', '') | |
112 | compliance_solution = compliance_data.get('compliance-solution', '') | |
113 | if compliance_solution and not kwargs["resolution"]: | |
114 | kwargs["resolution"] = compliance_solution | |
115 | policy_item = f'{compliance_check_name} - {compliance_result}' | |
116 | for policy_check_data in bis_benchmark_data: | |
117 | if 'ref.' in policy_check_data: | |
118 | kwargs["ref"].append(policy_check_data) | |
119 | if 'compliance-see-also' in compliance_data: | |
120 | kwargs["ref"].append(compliance_data.get('compliance-see-also')) | |
121 | # We used this info from tenable: https://community.tenable.com/s/article/Compliance-checks-in-SecurityCenter | |
122 | kwargs["policyviolations"].append(policy_item) | |
123 | kwargs["name"] = f'{kwargs["name"]}: {policy_item}' | |
124 | ||
125 | return kwargs | |
126 | ||
193 | 127 | def parseOutputString(self, output): |
194 | 128 | """ |
195 | 129 | This method will discard the output the shell sends, it will read it from |
198 | 132 | NOTE: if 'debug' is true then it is being run from a test case and the |
199 | 133 | output being sent is valid. |
200 | 134 | """ |
135 | ||
201 | 136 | try: |
202 | 137 | parser = NessusParser(output) |
203 | 138 | except Exception as e: |
204 | 139 | self.logger.error(str(e)) |
205 | 140 | return None |
141 | report_hosts = parser.report.report_hosts | |
206 | 142 | |
207 | if parser.report.report_json is not None: | |
208 | run_date = parser.report.report_json.get('host_end') | |
209 | if run_date: | |
210 | run_date = dateutil.parser.parse(run_date) | |
211 | for set_info, ip in enumerate(parser.report.report_json['ip'], start=1): | |
212 | website = None | |
213 | mac = parser.report.report_json['desc'][set_info - 1].get('mac-address', '') | |
214 | os = parser.report.report_json['desc'][set_info - 1].get('operating-system', None) | |
215 | ip_host = parser.report.report_json['desc'][set_info - 1].get('host-ip', ip) | |
216 | host_name = parser.report.report_json['desc'][set_info - 1].get('host-fqdn', None) | |
217 | if host_name: | |
218 | website = host_name | |
219 | host_id = self.createAndAddHost(ip_host, os=os, hostnames=host_name, mac=mac) | |
143 | if report_hosts: | |
144 | for host in report_hosts: | |
145 | run_date = host.host_properties.host_end | |
146 | if run_date: | |
147 | run_date = dateutil.parser.parse(run_date) | |
148 | website = host.host_properties.host_fqdn | |
149 | host_id = self.createAndAddHost(**self.map_properties(host)) | |
220 | 150 | |
221 | for report_item in parser.report.report_json['serv'][set_info -1]: | |
222 | vulnerability_name = report_item.plugin_name | |
151 | for item in host.report_items: | |
152 | vulnerability_name = item.plugin_name | |
223 | 153 | if not vulnerability_name: |
224 | 154 | continue |
225 | item_name = report_item.svc_name | |
226 | item_port = report_item.port | |
227 | item_protocol = report_item.protocol | |
228 | item_severity = report_item.severity | |
229 | external_id = report_item.plugin_id | |
230 | serv_description = report_item.description | |
231 | #cve.append(report_item.plugin_output) | |
232 | description = report_item.plugin_output | |
233 | data = report_item.info | |
234 | risk_factor = data.get('risk_factor', None) | |
235 | cve = [] | |
236 | ref = [] | |
237 | if risk_factor == 'None' or risk_factor is None: | |
238 | risk_factor = item_severity # I checked several external id and most of them were info | |
155 | item_name = item.svc_name_attr | |
156 | ||
157 | _main_data = self.map_item( | |
158 | host_id, run_date, vulnerability_name, item) | |
159 | ||
160 | _main_data = self.map_add_ref(_main_data, item) | |
239 | 161 | if item_name == 'general': |
240 | description = data.get('description', '') | |
241 | resolution = data.get('solution', '') | |
242 | data_pluin_ouput = data.get('plugin_output', '') | |
243 | if 'cvss_base_score' in data: | |
244 | cvss_base_score = f"CVSS:{data['cvss_base_score']}" | |
245 | ref.append(cvss_base_score) | |
246 | policyviolations = [] | |
247 | if report_item.plugin_family == 'Policy Compliance': | |
248 | # This condition was added to support CIS Benchmark in policy violation field. | |
249 | bis_benchmark_data = report_item.description.split('\n') | |
250 | compliance_data = parser.parse_compliance_data(data) | |
251 | compliance_info = compliance_data.get('compliance-info', '') | |
252 | if compliance_info and not description: | |
253 | description = compliance_info | |
254 | compliance_reference = compliance_data.get('compliance-reference', '').replace('|', ':').split(',') | |
255 | compliance_result = compliance_data.get('compliance-result', '') | |
256 | for reference in compliance_reference: | |
257 | ref.append(reference) | |
258 | compliance_check_name = compliance_data.get('compliance-check-name', '') | |
259 | compliance_solution = compliance_data.get('compliance-solution', '') | |
260 | if compliance_solution and not resolution: | |
261 | resolution = compliance_solution | |
262 | policy_item = f'{compliance_check_name} - {compliance_result}' | |
263 | for policy_check_data in bis_benchmark_data: | |
264 | if 'ref.' in policy_check_data: | |
265 | ref.append(policy_check_data) | |
266 | if 'compliance-see-also' in compliance_data: | |
267 | ref.append(compliance_data.get('compliance-see-also')) | |
268 | # We used this info from tenable: https://community.tenable.com/s/article/Compliance-checks-in-SecurityCenter | |
269 | policyviolations.append(policy_item) | |
270 | vulnerability_name = f'{vulnerability_name}: {policy_item}' | |
271 | self.createAndAddVulnToHost(host_id, | |
272 | vulnerability_name, | |
273 | desc=description, | |
274 | severity=risk_factor, | |
275 | resolution=resolution, | |
276 | data=data_pluin_ouput, | |
277 | ref=ref, | |
278 | policyviolations=policyviolations, | |
279 | external_id=external_id, | |
280 | run_date=run_date) | |
162 | _main_data = self.map_policy_general(_main_data, item) | |
163 | self.createAndAddVulnToHost(**_main_data) | |
281 | 164 | else: |
282 | vulnerability_name = report_item.plugin_name | |
283 | description = data.get('description', '') | |
284 | resolution = data.get('solution', '') | |
285 | data_pluin_ouput = data.get('plugin_output', '') | |
286 | if 'cvss_base_score' in data: | |
287 | cvss_base_score = f"CVSS:{data['cvss_base_score']}" | |
288 | ref.append(cvss_base_score) | |
289 | if 'cvss_vector' in data: | |
290 | cvss_vector = f"CVSSVECTOR:{data['cvss_vector']}" | |
291 | ref.append(cvss_vector) | |
292 | if 'see_also' in data: | |
293 | ref.append(data['see_also']) | |
294 | if 'cpe' in data: | |
295 | ref.append(data['cpe']) | |
296 | if 'xref' in data: | |
297 | ref.append(data['xref']) | |
165 | _main_data["service_id"] = self.createAndAddServiceToHost( | |
166 | host_id, name=item_name, protocol=item.protocol_attr, | |
167 | ports=item.port_attr) | |
168 | if item_name == 'www' or item_name == 'http': | |
169 | _main_data.update({"website": website}) | |
170 | self.createAndAddVulnWebToService(**_main_data) | |
171 | else: | |
172 | self.createAndAddVulnToService(**_main_data) | |
298 | 173 | |
299 | service_id = self.createAndAddServiceToHost(host_id, name=item_name, protocol=item_protocol, | |
300 | ports=item_port) | |
174 | @staticmethod | |
175 | def map_add_ref(kwargs, item: ReportItem): | |
301 | 176 | |
302 | if item_name == 'www' or item_name == 'http': | |
303 | self.createAndAddVulnWebToService(host_id, | |
304 | service_id, | |
305 | name=vulnerability_name, | |
306 | desc=description, | |
307 | data=data_pluin_ouput, | |
308 | severity=risk_factor, | |
309 | resolution=resolution, | |
310 | ref=ref, | |
311 | external_id=external_id, | |
312 | website=website, | |
313 | run_date=run_date) | |
314 | else: | |
315 | self.createAndAddVulnToService(host_id, | |
316 | service_id, | |
317 | name=vulnerability_name, | |
318 | severity=risk_factor, | |
319 | desc=description, | |
320 | ref=ref, | |
321 | data=data_pluin_ouput, | |
322 | external_id=external_id, | |
323 | resolution=resolution, | |
324 | run_date=run_date) | |
177 | if item.cvss_vector: | |
178 | kwargs["ref"].append(item.cvss_vector) | |
179 | if item.see_also: | |
180 | kwargs["ref"].append(item.see_also) | |
181 | if item.cpe: | |
182 | kwargs["ref"].append(item.cpe) | |
183 | if item.xref: | |
184 | kwargs["ref"].append(item.xref) | |
185 | if item.cve: | |
186 | kwargs["ref"] = kwargs["ref"] + item.cve | |
187 | if item.cvss3_base_score: | |
188 | kwargs["ref"].append(item.cvss3_base_score) | |
189 | if item.cvss3_vector: | |
190 | kwargs["ref"].append(item.cvss3_vector) | |
191 | ||
192 | return kwargs | |
325 | 193 | |
326 | 194 | |
327 | 195 | def createPlugin(ignore_info=False): |
4 | 4 | |
5 | 5 | """ |
6 | 6 | import re |
7 | import xml.etree.ElementTree as ET | |
8 | ||
7 | 9 | from bs4 import BeautifulSoup |
10 | ||
8 | 11 | from faraday_plugins.plugins.plugin import PluginXMLFormat |
9 | 12 | from faraday_plugins.plugins.plugins_utils import resolve_hostname |
10 | ||
11 | try: | |
12 | import xml.etree.cElementTree as ET | |
13 | import xml.etree.ElementTree as ET_ORIG | |
14 | ETREE_VERSION = ET_ORIG.VERSION | |
15 | except ImportError: | |
16 | import xml.etree.ElementTree as ET | |
17 | ETREE_VERSION = ET.VERSION | |
18 | ||
19 | ETREE_VERSION = [int(i) for i in ETREE_VERSION.split(".")] | |
20 | ||
21 | 13 | |
22 | 14 | __author__ = "Francisco Amato" |
23 | 15 | __copyright__ = "Copyright (c) 2013, Infobyte LLC" |
82 | 74 | @param item_node A item_node taken from an netsparker xml tree |
83 | 75 | """ |
84 | 76 | |
85 | def re_map_severity(self, severity): | |
86 | if severity == "Important": | |
87 | return "high" | |
88 | return severity | |
89 | ||
90 | def __init__(self, item_node, encoding="ascii"): | |
77 | def __init__(self, item_node): | |
91 | 78 | self.node = item_node |
92 | 79 | self.url = self.get_text_from_subnode("url") |
93 | 80 | |
117 | 104 | self.param = self.get_text_from_subnode("vulnerableparameter") |
118 | 105 | self.paramval = self.get_text_from_subnode("vulnerableparametervalue") |
119 | 106 | self.reference = self.get_text_from_subnode("externalReferences") |
120 | self.resolution = self.get_text_from_subnode("actionsToTake") | |
107 | remedy = self.get_text_from_subnode("remedy") | |
108 | self.resolution = self.get_text_from_subnode("actionsToTake") + remedy if remedy else "" | |
121 | 109 | self.request = self.get_text_from_subnode("rawrequest") |
122 | 110 | self.response = self.get_text_from_subnode("rawresponse") |
123 | 111 | self.kvulns = [] |
166 | 154 | repr(self.paramval) if self.paramval else "" |
167 | 155 | self.data += "\nExtra: " + "\n".join(self.extra) if self.extra else "" |
168 | 156 | |
157 | @staticmethod | |
158 | def re_map_severity(severity): | |
159 | if severity == "Important": | |
160 | return "high" | |
161 | return severity | |
162 | ||
169 | 163 | def get_text_from_subnode(self, subnode_xpath_expr): |
170 | 164 | """ |
171 | 165 | Finds a subnode in the host node and the retrieves a value from it. |
207 | 201 | ports=[str(i.port)], |
208 | 202 | status="open") |
209 | 203 | first = False |
204 | ||
210 | 205 | if i.resolution is not None: |
211 | 206 | resolution = BeautifulSoup(i.resolution, "lxml").text |
212 | 207 | else: |
220 | 215 | name = i.name |
221 | 216 | else: |
222 | 217 | name = i.name_title |
223 | v_id = self.createAndAddVulnWebToService(h_id, s_id, name, ref=i.ref, website=i.hostname, | |
218 | self.createAndAddVulnWebToService(h_id, s_id, name, ref=i.ref, website=i.hostname, | |
224 | 219 | severity=i.severity, desc=desc, path=i.url, method=i.method, |
225 | 220 | request=i.request, response=i.response, resolution=resolution, |
226 | 221 | pname=i.param, data=i.data) |
4 | 4 | |
5 | 5 | """ |
6 | 6 | import re |
7 | import xml.etree.ElementTree as ET | |
7 | 8 | from urllib.parse import urlparse |
9 | ||
8 | 10 | from faraday_plugins.plugins.plugin import PluginXMLFormat |
9 | 11 | from faraday_plugins.plugins.plugins_utils import resolve_hostname |
10 | ||
11 | try: | |
12 | import xml.etree.cElementTree as ET | |
13 | import xml.etree.ElementTree as ET_ORIG | |
14 | ETREE_VERSION = ET_ORIG.VERSION | |
15 | except ImportError: | |
16 | import xml.etree.ElementTree as ET | |
17 | ETREE_VERSION = ET.VERSION | |
18 | ||
19 | ETREE_VERSION = [int(i) for i in ETREE_VERSION.split(".")] | |
20 | ||
21 | 12 | |
22 | 13 | __author__ = "Francisco Amato" |
23 | 14 | __copyright__ = "Copyright (c) 2013, Infobyte LLC" |
29 | 20 | __status__ = "Development" |
30 | 21 | |
31 | 22 | |
32 | ||
33 | 23 | def get_urls(string): |
34 | 24 | if isinstance(string, bytes): |
35 | 25 | string_decode = string.decode("utf-8") |
54 | 44 | self.filepath = xml_output |
55 | 45 | tree = self.parse_xml(xml_output) |
56 | 46 | if tree: |
57 | self.items = [data for data in self.get_items(tree)] | |
47 | self.items = self.get_items(tree) | |
58 | 48 | else: |
59 | 49 | self.items = [] |
60 | 50 | |
89 | 79 | |
90 | 80 | @param item_node A item_node taken from an netsparkercloud xml tree |
91 | 81 | """ |
82 | ||
92 | 83 | def re_map_severity(self, severity): |
93 | 84 | if severity == "Important": |
94 | 85 | return "high" |
119 | 110 | self.response = self.get_text_from_subnode("content") |
120 | 111 | self.extra = [] |
121 | 112 | for v in item_node.findall("extra-information/info"): |
122 | self.extra.append(v.get('name') + ":" + v.get('value') ) | |
113 | self.extra.append(v.get('name') + ":" + v.get('value')) | |
123 | 114 | |
124 | 115 | self.node = item_node.find("classification") |
125 | 116 | self.owasp = self.get_text_from_subnode("owasp") |
205 | 196 | del parser |
206 | 197 | |
207 | 198 | |
208 | def setHost(self): | |
209 | pass | |
210 | ||
211 | ||
212 | 199 | def createPlugin(ignore_info=False): |
213 | 200 | return NetsparkerCloudPlugin(ignore_info=ignore_info) |
3 | 3 | See the file 'doc/LICENSE' for the license information |
4 | 4 | |
5 | 5 | """ |
6 | import re | |
7 | import xml.etree.ElementTree as ET | |
8 | ||
6 | 9 | from faraday_plugins.plugins.plugin import PluginXMLFormat |
7 | import re | |
8 | ||
9 | try: | |
10 | import xml.etree.cElementTree as ET | |
11 | import xml.etree.ElementTree as ET_ORIG | |
12 | ||
13 | ETREE_VERSION = ET_ORIG.VERSION | |
14 | except ImportError: | |
15 | import xml.etree.ElementTree as ET | |
16 | ||
17 | ETREE_VERSION = ET.VERSION | |
18 | ||
19 | ETREE_VERSION = [int(i) for i in ETREE_VERSION.split(".")] | |
20 | ||
21 | 10 | |
22 | 11 | __author__ = "Micaela Ranea Sanchez" |
23 | 12 | __copyright__ = "Copyright (c) 2013, Infobyte LLC" |
50 | 39 | else: |
51 | 40 | self.items = [] |
52 | 41 | |
53 | def parse_xml(self, xml_output): | |
42 | @staticmethod | |
43 | def parse_xml(xml_output): | |
54 | 44 | """ |
55 | 45 | Open and parse an xml file. |
56 | 46 | |
121 | 111 | |
122 | 112 | for tests in node.findall('tests'): |
123 | 113 | for test in tests.iter('test'): |
124 | vuln = dict() | |
125 | 114 | if test.get('id').lower() in vulnsDefinitions: |
126 | 115 | vuln = vulnsDefinitions[test.get('id').lower()].copy() |
127 | 116 | key = test.get('key', '') |
274 | 263 | h_id = self.createAndAddHost(item['name'], item['os'], hostnames=item['hostnames'], mac=mac) |
275 | 264 | for v in item['vulns']: |
276 | 265 | v['data'] = {"vulnerable_since": v['vulnerable_since'], "scan_id": v['scan_id'], "PCI": v['pci']} |
277 | v_id = self.createAndAddVulnToHost( | |
266 | self.createAndAddVulnToHost( | |
278 | 267 | h_id, |
279 | 268 | v['name'], |
280 | 269 | v['desc'], |
284 | 273 | ) |
285 | 274 | |
286 | 275 | for s in item['services']: |
287 | web = False | |
288 | 276 | version = s.get("version", "") |
289 | 277 | s_id = self.createAndAddServiceToHost( |
290 | 278 | h_id, |
297 | 285 | for v in s['vulns']: |
298 | 286 | |
299 | 287 | if v['is_web']: |
300 | v_id = self.createAndAddVulnWebToService( | |
288 | self.createAndAddVulnWebToService( | |
301 | 289 | h_id, |
302 | 290 | s_id, |
303 | 291 | v['name'], |
307 | 295 | v['resolution'], |
308 | 296 | path=v.get('path', '')) |
309 | 297 | else: |
310 | v_id = self.createAndAddVulnToService( | |
298 | self.createAndAddVulnToService( | |
311 | 299 | h_id, |
312 | 300 | s_id, |
313 | 301 | v['name'], |
320 | 308 | del parser |
321 | 309 | |
322 | 310 | |
323 | def setHost(self): | |
324 | pass | |
325 | ||
326 | ||
327 | 311 | def createPlugin(ignore_info=False): |
328 | 312 | return NexposeFullPlugin(ignore_info=ignore_info) |
329 | ||
330 |
3 | 3 | See the file 'doc/LICENSE' for the license information |
4 | 4 | """ |
5 | 5 | import re |
6 | import xml.etree.ElementTree as ET | |
6 | 7 | from html.parser import HTMLParser |
8 | ||
9 | from faraday_plugins.plugins import plugins_utils | |
7 | 10 | from faraday_plugins.plugins.plugin import PluginXMLFormat |
8 | from faraday_plugins.plugins import plugins_utils | |
9 | ||
10 | ||
11 | try: | |
12 | import xml.etree.cElementTree as ET | |
13 | import xml.etree.ElementTree as ET_ORIG | |
14 | ETREE_VERSION = ET_ORIG.VERSION | |
15 | except ImportError: | |
16 | import xml.etree.ElementTree as ET | |
17 | ETREE_VERSION = ET.VERSION | |
18 | ||
19 | ETREE_VERSION = [int(i) for i in ETREE_VERSION.split(".")] | |
20 | ||
21 | 11 | |
22 | 12 | __author__ = "Francisco Amato" |
23 | 13 | __copyright__ = "Copyright (c) 2013, Infobyte LLC" |
45 | 35 | tree = self.parse_xml(xml_output) |
46 | 36 | |
47 | 37 | if tree: |
48 | self.hosts = [host for host in self.get_hosts(tree)] | |
38 | self.hosts = self.get_hosts(tree) | |
49 | 39 | else: |
50 | 40 | self.hosts = [] |
51 | 41 | |
84 | 74 | |
85 | 75 | @return An attribute value |
86 | 76 | """ |
87 | global ETREE_VERSION | |
88 | node = None | |
89 | ||
90 | if ETREE_VERSION[0] <= 1 and ETREE_VERSION[1] < 3: | |
91 | ||
92 | match_obj = re.search( | |
93 | "([^\@]+?)\[\@([^=]*?)=\'([^\']*?)\'", subnode_xpath_expr) | |
94 | if match_obj is not None: | |
95 | ||
96 | node_to_find = match_obj.group(1) | |
97 | xpath_attrib = match_obj.group(2) | |
98 | xpath_value = match_obj.group(3) | |
99 | for node_found in xml_node.findall(node_to_find): | |
100 | ||
101 | if node_found.attrib[xpath_attrib] == xpath_value: | |
102 | node = node_found | |
103 | break | |
104 | else: | |
105 | node = xml_node.find(subnode_xpath_expr) | |
106 | ||
107 | else: | |
108 | node = xml_node.find(subnode_xpath_expr) | |
77 | ||
78 | node = xml_node.find(subnode_xpath_expr) | |
109 | 79 | |
110 | 80 | if node is not None: |
111 | 81 | return node.get(attrib_name) |
221 | 191 | self.starttime = self.node.get('starttime') |
222 | 192 | self.sitename = self.node.get('sitename') |
223 | 193 | self.siteip = self.node.get('hostheader') |
224 | self.items = [item for item in self.get_items()] | |
194 | self.items = self.get_items() | |
225 | 195 | |
226 | 196 | def get_items(self): |
227 | 197 | """ |
300 | 270 | "-vhost+": "Virtual host (for Host header)", |
301 | 271 | } |
302 | 272 | |
303 | ||
304 | ||
305 | 273 | def parseOutputString(self, output): |
306 | 274 | """ |
307 | 275 | This method will discard the output the shell sends, it will read it from |
329 | 297 | ) |
330 | 298 | |
331 | 299 | for item in host.items: |
332 | ||
333 | v_id = self.createAndAddVulnWebToService( | |
300 | self.createAndAddVulnWebToService( | |
334 | 301 | h_id, |
335 | 302 | s_id, |
336 | 303 | name=item.desc, |
342 | 309 | |
343 | 310 | del parser |
344 | 311 | |
345 | ||
346 | ||
347 | 312 | def processCommandString(self, username, current_path, command_string): |
348 | 313 | """ |
349 | 314 | Adds the -oX parameter to get xml output to the command string that the |
359 | 324 | data = re.sub(" \-Format XML", "", command_string) |
360 | 325 | return re.sub(arg_match.group(1), r"-output %s -Format XML" % self._output_file_path, data) |
361 | 326 | |
362 | def setHost(self): | |
363 | pass | |
364 | ||
365 | 327 | |
366 | 328 | def createPlugin(ignore_info=False): |
367 | 329 | return NiktoPlugin(ignore_info=ignore_info) |
368 | ||
369 |
0 | import os | |
1 | import re | |
2 | from io import BytesIO | |
3 | ||
0 | 4 | """ |
1 | 5 | Faraday Penetration Test IDE |
2 | 6 | Copyright (C) 2013 Infobyte LLC (http://www.infobytesec.com/) |
3 | 7 | See the file 'doc/LICENSE' for the license information |
4 | 8 | |
5 | 9 | """ |
6 | ||
7 | import re | |
8 | import os | |
9 | from io import BytesIO | |
10 | ||
11 | try: | |
12 | import xml.etree.cElementTree as ET | |
13 | import xml.etree.ElementTree as ET_ORIG | |
14 | ETREE_VERSION = ET_ORIG.VERSION | |
15 | except ImportError: | |
16 | import xml.etree.ElementTree as ET | |
17 | ETREE_VERSION = ET.VERSION | |
18 | 10 | from lxml import etree |
19 | 11 | from lxml.etree import XMLParser |
20 | 12 | from faraday_plugins.plugins.plugin import PluginXMLFormat |
21 | 13 | from faraday_plugins.plugins.plugins_utils import get_severity_from_cvss |
22 | 14 | |
23 | ETREE_VERSION = [int(i) for i in ETREE_VERSION.split(".")] | |
24 | 15 | current_path = os.path.abspath(os.getcwd()) |
25 | ||
26 | 16 | |
27 | 17 | |
28 | 18 | class NmapXmlParser: |
60 | 50 | magical_parser = XMLParser(recover=True) |
61 | 51 | return etree.parse(BytesIO(xml_output), magical_parser) |
62 | 52 | except SyntaxError as err: |
63 | #logger.error("SyntaxError: %s." % (err)) | |
53 | # logger.error("SyntaxError: %s." % (err)) | |
64 | 54 | return None |
65 | 55 | |
66 | 56 | def get_hosts(self, tree): |
77 | 67 | |
78 | 68 | @return An attribute value |
79 | 69 | """ |
80 | global ETREE_VERSION | |
81 | node = None | |
82 | ||
83 | if ETREE_VERSION[0] <= 1 and ETREE_VERSION[1] < 3: | |
84 | ||
85 | match_obj = re.search( | |
86 | "([^\@]+?)\[\@([^=]*?)=\'([^\']*?)\'", | |
87 | subnode_xpath_expr) | |
88 | ||
89 | if match_obj is not None: | |
90 | ||
91 | node_to_find = match_obj.group(1) | |
92 | xpath_attrib = match_obj.group(2) | |
93 | xpath_value = match_obj.group(3) | |
94 | ||
95 | for node_found in xml_node.findall(node_to_find): | |
96 | if node_found.attrib[xpath_attrib] == xpath_value: | |
97 | node = node_found | |
98 | break | |
99 | else: | |
100 | node = xml_node.find(subnode_xpath_expr) | |
101 | ||
102 | else: | |
103 | node = xml_node.find(subnode_xpath_expr) | |
70 | ||
71 | node = xml_node.find(subnode_xpath_expr) | |
104 | 72 | |
105 | 73 | if node is not None: |
106 | 74 | return node.get(attrib_name) |
242 | 210 | ostype = service.get("ostype", "unknown") |
243 | 211 | yield ("%s" % ostype, 0) |
244 | 212 | |
245 | ||
246 | 213 | def top_os_guess(self): |
247 | 214 | """ |
248 | 215 | @return The most accurate os_guess_id or 'unknown'. |
295 | 262 | @param port_node A port_node taken from an nmap xml tree |
296 | 263 | """ |
297 | 264 | |
265 | PORT_STATUS_FIX = {"filtered": "closed", "open|filtered": "closed"} | |
266 | ||
298 | 267 | def __init__(self, port_node): |
299 | 268 | self.node = port_node |
300 | 269 | |
322 | 291 | |
323 | 292 | @return (state, reason, reason_ttl) or ('unknown','unknown','unknown') |
324 | 293 | """ |
325 | state = self.get_attrib_from_subnode('state', 'state') | |
294 | state = self.PORT_STATUS_FIX.get(self.get_attrib_from_subnode('state', 'state'), | |
295 | self.get_attrib_from_subnode('state', 'state')) | |
326 | 296 | reason = self.get_attrib_from_subnode('state', 'reason') |
327 | 297 | reason_ttl = self.get_attrib_from_subnode('state', 'reason_ttl') |
328 | 298 | |
381 | 351 | self.table[e.get("key")] = str(e.text) |
382 | 352 | |
383 | 353 | self.name = self.table["id"] |
384 | ||
354 | ||
385 | 355 | self.desc = script_node.get("id") + "-" + self.table["id"] |
386 | 356 | if self.table["is_exploit"] == 'true': |
387 | 357 | self.desc += " *EXPLOIT*" |
388 | ||
358 | ||
389 | 359 | self.refs = ["https://vulners.com/" + self.table["type"] + "/" + self.table["id"]] |
390 | 360 | self.refs.append("CVSS: " + self.table["cvss"]) |
391 | 361 | self.response = "" |
422 | 392 | |
423 | 393 | self.name = script_node.get("id") |
424 | 394 | self.desc = script_node.get("output") |
425 | self.refs = self.parse_output(self.desc) | |
395 | self.refs = self.parse_output(self.desc) | |
426 | 396 | self.response = "" |
427 | 397 | for k in script_node.findall("elem"): |
428 | 398 | self.response += "\n" + str(k.get('key')) + ": " + str(k.text) |
547 | 517 | description=srvname) |
548 | 518 | |
549 | 519 | for v in port.vulns: |
550 | ||
520 | ||
551 | 521 | desc = v.desc |
552 | 522 | refs = v.refs |
553 | 523 | |
561 | 531 | severity = "unclassified" |
562 | 532 | if re.search(r"Couldn't", desc): |
563 | 533 | severity = "unclassified" |
564 | ||
534 | ||
565 | 535 | if v.web: |
566 | 536 | v_id = self.createAndAddVulnWebToService( |
567 | 537 | h_id, |
568 | 538 | s_id, |
569 | 539 | v.name, |
570 | 540 | desc=desc, |
571 | response = v.response if v.response else "", | |
541 | response=v.response if v.response else "", | |
572 | 542 | ref=refs, |
573 | 543 | severity=severity, |
574 | 544 | website=minterfase, |
600 | 570 | r"-oX %s" % self._output_file_path, |
601 | 571 | command_string) |
602 | 572 | |
573 | ||
603 | 574 | def createPlugin(ignore_info=False): |
604 | 575 | return NmapPlugin(ignore_info=ignore_info) |
605 | ||
606 |
5 | 5 | """ |
6 | 6 | import socket |
7 | 7 | import json |
8 | import dateutil | |
9 | from collections import defaultdict | |
8 | 10 | from urllib.parse import urlparse |
9 | 11 | from faraday_plugins.plugins.plugin import PluginMultiLineJsonFormat |
10 | 12 | from faraday_plugins.plugins.plugins_utils import resolve_hostname |
11 | 13 | |
12 | __author__ = "Blas Moyano" | |
13 | __copyright__ = "Copyright (c) 2020, Infobyte LLC" | |
14 | __credits__ = ["Blas Moyano"] | |
14 | __author__ = "Nicolas Rebagliati" | |
15 | __copyright__ = "Copyright (c) 2021, Infobyte LLC" | |
16 | __credits__ = ["Nicolas Rebagliati"] | |
15 | 17 | __license__ = "" |
16 | 18 | __version__ = "0.0.1" |
17 | __maintainer__ = "Blas Moyano" | |
18 | __email__ = "[email protected]" | |
19 | __maintainer__ = "Nicolas Rebagliati" | |
20 | __email__ = "[email protected]" | |
19 | 21 | __status__ = "Development" |
20 | ||
21 | ||
22 | class NucleiJsonParser: | |
23 | ||
24 | def __init__(self, json_output): | |
25 | self.list_to_vulns = json_output.split("\n") | |
26 | 22 | |
27 | 23 | |
28 | 24 | class NucleiPlugin(PluginMultiLineJsonFormat): |
35 | 31 | self.id = "nuclei" |
36 | 32 | self.name = "Nuclei" |
37 | 33 | self.plugin_version = "0.1" |
38 | self.version = "0.0.1" | |
39 | self.json_keys = {"matched", "template"} | |
34 | self.version = "2.3.0" | |
35 | self.json_keys = {"matched", "templateID", "host"} | |
40 | 36 | |
41 | 37 | def parseOutputString(self, output, debug=False): |
42 | parser = NucleiJsonParser(output) | |
43 | matched_list = [] | |
44 | matched_json = {} | |
45 | for vuln in parser.list_to_vulns: | |
46 | if vuln != '': | |
47 | json_vuln = json.loads(vuln) | |
48 | matched = json_vuln.get('matched', None) | |
49 | ||
50 | if matched is not None: | |
51 | url_parser = urlparse(matched) | |
52 | url_scheme = f'{url_parser.scheme}://{url_parser.hostname}' | |
53 | ||
54 | if url_scheme in matched_list: | |
55 | matched_json[url_scheme].append(json_vuln) | |
56 | else: | |
57 | matched_list.append(url_scheme) | |
58 | matched_json[url_scheme] = [json_vuln] | |
59 | ||
60 | for url in matched_list: | |
61 | url_data = urlparse(url) | |
62 | url_name = url_data.hostname | |
63 | url_protocol = url_data.scheme | |
64 | ip = resolve_hostname(url_name) | |
38 | for vuln_json in filter(lambda x: x != '', output.split("\n")): | |
39 | vuln_dict = json.loads(vuln_json) | |
40 | host = vuln_dict.get('host') | |
41 | url_data = urlparse(host) | |
42 | ip = vuln_dict.get("ip", resolve_hostname(url_data.hostname)) | |
65 | 43 | host_id = self.createAndAddHost( |
66 | 44 | name=ip, |
67 | hostnames=[url_name]) | |
68 | port = 80 | |
69 | if url_parser.scheme == 'https': | |
70 | port = 443 | |
71 | ||
45 | hostnames=[url_data.hostname]) | |
46 | port = url_data.port | |
47 | if not port: | |
48 | if url_data.scheme == 'https': | |
49 | port = 443 | |
50 | else: | |
51 | port = 80 | |
72 | 52 | service_id = self.createAndAddServiceToHost( |
73 | 53 | host_id, |
74 | name=url_parser.scheme, | |
54 | name=url_data.scheme, | |
75 | 55 | ports=port, |
76 | 56 | protocol="tcp", |
77 | 57 | status='open', |
78 | 58 | version='', |
79 | description='') | |
59 | description='web server') | |
60 | matched = vuln_dict.get('matched') | |
61 | matched_data = urlparse(matched) | |
62 | references = [f"author: {vuln_dict['info'].get('author', '')}"] | |
63 | request = vuln_dict.get('request', '') | |
64 | if request: | |
65 | method = request.split(" ")[0] | |
66 | else: | |
67 | method = "" | |
68 | data = [f"Matched: {vuln_dict.get('matched')}", | |
69 | f"Tags: {vuln_dict['info'].get('tags')}", | |
70 | f"Template ID: {vuln_dict['templateID']}"] | |
80 | 71 | |
81 | for info_vuln in matched_json[url]: | |
82 | desc = f'{info_vuln.get("template", None)} - {info_vuln.get("author", None)}' | |
83 | if info_vuln.get("author", None): | |
84 | ref = [f"author: {info_vuln.get('author', None)}"] | |
85 | else: | |
86 | ref = None | |
87 | self.createAndAddVulnWebToService( | |
88 | host_id, | |
89 | service_id, | |
90 | name=info_vuln.get('template', ""), | |
91 | desc=info_vuln.get('description', info_vuln.get('name', None)), | |
92 | ref=ref, | |
93 | severity=info_vuln.get('severity', ""), | |
94 | website=url, | |
95 | request=info_vuln.get('request', None), | |
96 | response=info_vuln.get('response', None), | |
97 | method=info_vuln.get('type', None), | |
98 | data=info_vuln.get('matcher_name', info_vuln.get('name', None)), | |
99 | external_id=info_vuln.get('template', "")) | |
72 | name = vuln_dict["info"].get("name") | |
73 | run_date = vuln_dict.get('timestamp') | |
74 | if run_date: | |
75 | run_date = dateutil.parser.parse(run_date) | |
76 | self.createAndAddVulnWebToService( | |
77 | host_id, | |
78 | service_id, | |
79 | name=name, | |
80 | desc=vuln_dict["info"].get("description", name), | |
81 | ref=references, | |
82 | severity=vuln_dict["info"].get('severity'), | |
83 | website=host, | |
84 | request=request, | |
85 | response=vuln_dict.get('response', ''), | |
86 | method=method, | |
87 | query=matched_data.query, | |
88 | params=matched_data.params, | |
89 | path=matched_data.path, | |
90 | data="\n".join(data), | |
91 | external_id=f"NUCLEI-{vuln_dict.get('templateID', '')}", | |
92 | run_date=run_date | |
93 | ) | |
94 | ||
95 | ||
100 | 96 | |
101 | 97 | |
102 | 98 | def createPlugin(ignore_info=False): |
4 | 4 | Copyright (C) 2020 Infobyte LLC (http://www.infobytesec.com/) |
5 | 5 | See the file 'doc/LICENSE' for the license information |
6 | 6 | """ |
7 | import ipaddress | |
8 | from datetime import datetime | |
9 | ||
10 | from lxml import etree | |
11 | ||
7 | 12 | from faraday_plugins.plugins.plugin import PluginXMLFormat |
8 | from datetime import datetime | |
9 | from lxml import etree | |
10 | import ipaddress | |
11 | ||
12 | try: | |
13 | import xml.etree.cElementTree as ET | |
14 | except ImportError: | |
15 | import xml.etree.ElementTree as ET | |
16 | 13 | |
17 | 14 | __author__ = 'Blas Moyano' |
18 | 15 | __copyright__ = 'Copyright 2020, Faraday Project' |
0 | import re | |
1 | from collections import defaultdict | |
2 | from copy import copy | |
3 | ||
0 | 4 | """ |
1 | 5 | Faraday Penetration Test IDE |
2 | 6 | Copyright (C) 2013 Infobyte LLC (http://www.infobytesec.com/) |
3 | 7 | See the file 'doc/LICENSE' for the license information |
4 | 8 | |
5 | 9 | """ |
6 | import re | |
7 | from collections import defaultdict | |
8 | from copy import copy | |
9 | ||
10 | try: | |
11 | import xml.etree.cElementTree as ET | |
12 | import xml.etree.ElementTree as ET_ORIG | |
13 | ETREE_VERSION = ET_ORIG.VERSION | |
14 | except ImportError: | |
15 | import xml.etree.ElementTree as ET | |
16 | ETREE_VERSION = ET.VERSION | |
17 | 10 | |
18 | 11 | from faraday_plugins.plugins.plugin import PluginXMLFormat |
19 | 12 | from faraday_plugins.plugins.plugins_utils import filter_services |
20 | 13 | |
21 | ETREE_VERSION = [int(i) for i in ETREE_VERSION.split(".")] | |
22 | ||
14 | import xml.etree.ElementTree as ET | |
23 | 15 | |
24 | 16 | __author__ = "Francisco Amato" |
25 | 17 | __copyright__ = "Copyright (c) 2013, Infobyte LLC" |
135 | 127 | |
136 | 128 | @return An attribute value |
137 | 129 | """ |
138 | global ETREE_VERSION | |
139 | node = None | |
140 | ||
141 | if ETREE_VERSION[0] <= 1 and ETREE_VERSION[1] < 3: | |
142 | ||
143 | match_obj = re.search( | |
144 | "([^\@]+?)\[\@([^=]*?)=\'([^\']*?)\'", | |
145 | subnode_xpath_expr) | |
146 | ||
147 | if match_obj is not None: | |
148 | node_to_find = match_obj.group(1) | |
149 | xpath_attrib = match_obj.group(2) | |
150 | xpath_value = match_obj.group(3) | |
151 | for node_found in xml_node.findall(node_to_find): | |
152 | if node_found.attrib[xpath_attrib] == xpath_value: | |
153 | node = node_found | |
154 | break | |
155 | else: | |
156 | node = xml_node.find(subnode_xpath_expr) | |
157 | ||
158 | else: | |
159 | node = xml_node.find(subnode_xpath_expr) | |
130 | ||
131 | node = xml_node.find(subnode_xpath_expr) | |
160 | 132 | |
161 | 133 | if node is not None: |
162 | 134 | return node.get(attrib_name) |
335 | 307 | with open(report_path) as f: |
336 | 308 | output = f.read() |
337 | 309 | return re.search("OpenVAS", output) is not None \ |
338 | or re.search('<omp>', output) is not None\ | |
310 | or re.search('<omp>', output) is not None \ | |
339 | 311 | or re.search('<owner>', output) is not None |
340 | 312 | return False |
341 | 313 | |
442 | 414 | else: |
443 | 415 | return False |
444 | 416 | |
445 | def setHost(self): | |
446 | pass | |
447 | ||
448 | 417 | |
449 | 418 | def createPlugin(ignore_info=False): |
450 | 419 | return OpenvasPlugin(ignore_info=ignore_info) |
451 | ||
452 |
3 | 3 | See the file 'doc/LICENSE' for the license information |
4 | 4 | |
5 | 5 | """ |
6 | import re | |
7 | ||
6 | 8 | from faraday_plugins.plugins.plugin import PluginBase |
7 | import re | |
8 | 9 | |
9 | 10 | __author__ = "Facundo de Guzmán, Esteban Guillardoy" |
10 | 11 | __copyright__ = "Copyright (c) 2013, Infobyte LLC" |
34 | 35 | |
35 | 36 | reg = re.search(r"PING ([\w\.-:]+)( |)\(([\w\.:]+)\)", output) |
36 | 37 | if re.search("0 received|unknown host", output) is None and reg is not None: |
37 | ||
38 | 38 | ip_address = reg.group(3) |
39 | 39 | hostname = reg.group(1) |
40 | h_id = self.createAndAddHost(ip_address, hostnames=[hostname]) | |
40 | self.createAndAddHost(ip_address, hostnames=[hostname]) | |
41 | 41 | return True |
42 | 42 | |
43 | 43 | def _isIPV4(self, ip): |
47 | 47 | return False |
48 | 48 | |
49 | 49 | |
50 | ||
51 | 50 | def createPlugin(ignore_info=False): |
52 | 51 | return CmdPingPlugin(ignore_info=ignore_info) |
53 | ||
54 | ||
55 |
3 | 3 | See the file 'doc/LICENSE' for the license information |
4 | 4 | """ |
5 | 5 | import re |
6 | import xml.etree.ElementTree as ET | |
7 | ||
6 | 8 | from faraday_plugins.plugins.plugin import PluginXMLFormat |
7 | ||
8 | import xml.etree.ElementTree as ET | |
9 | ETREE_VERSION = ET.VERSION | |
10 | ||
11 | ETREE_VERSION = [int(i) for i in ETREE_VERSION.split('.')] | |
12 | ||
13 | 9 | |
14 | 10 | __author__ = 'Francisco Amato' |
15 | 11 | __copyright__ = 'Copyright (c) 2013, Infobyte LLC' |
349 | 345 | |
350 | 346 | parser = QualysguardXmlParser(output) |
351 | 347 | |
352 | ||
353 | 348 | for item in parser.items: |
354 | 349 | h_id = self.createAndAddHost( |
355 | 350 | item.ip, |
414 | 409 | del parser |
415 | 410 | |
416 | 411 | |
417 | def setHost(self): | |
418 | pass | |
419 | ||
420 | ||
421 | 412 | def createPlugin(ignore_info=False): |
422 | 413 | return QualysguardPlugin(ignore_info=ignore_info) |
423 | ||
424 |
4 | 4 | Copyright (C) 2016 Infobyte LLC (http://www.infobytesec.com/) |
5 | 5 | See the file 'doc/LICENSE' for the license information |
6 | 6 | """ |
7 | import re | |
7 | import xml.etree.ElementTree as ET | |
8 | 8 | from urllib.parse import urlparse |
9 | 9 | |
10 | 10 | from dateutil.parser import parse |
11 | 11 | |
12 | 12 | from faraday_plugins.plugins.plugin import PluginXMLFormat |
13 | ||
14 | try: | |
15 | import xml.etree.cElementTree as ET | |
16 | except ImportError: | |
17 | import xml.etree.ElementTree as ET | |
18 | 13 | |
19 | 14 | __author__ = 'Blas Moyano' |
20 | 15 | __copyright__ = 'Copyright 2020, Faraday Project' |
79 | 74 | class Glossary(): |
80 | 75 | def __init__(self, glossary_tags): |
81 | 76 | self.lista_qid = self.get_qid_list(glossary_tags) |
82 | ||
83 | 77 | |
84 | 78 | def get_qid_list(self, qid_list_tags): |
85 | 79 | self.dict_result_qid = {} |
4 | 4 | |
5 | 5 | """ |
6 | 6 | import re |
7 | import xml.etree.ElementTree as ET | |
8 | ||
7 | 9 | from faraday_plugins.plugins.plugin import PluginXMLFormat |
8 | ||
9 | ||
10 | try: | |
11 | import xml.etree.cElementTree as ET | |
12 | import xml.etree.ElementTree as ET_ORIG | |
13 | ETREE_VERSION = ET_ORIG.VERSION | |
14 | except ImportError: | |
15 | import xml.etree.ElementTree as ET | |
16 | ETREE_VERSION = ET.VERSION | |
17 | ||
18 | ETREE_VERSION = [int(i) for i in ETREE_VERSION.split(".")] | |
19 | ||
20 | 10 | |
21 | 11 | __author__ = "Francisco Amato" |
22 | 12 | __copyright__ = "Copyright (c) 2013, Infobyte LLC" |
42 | 32 | def __init__(self, xml_output): |
43 | 33 | tree = self.parse_xml(xml_output) |
44 | 34 | if tree: |
45 | self.items = [data for data in self.get_items(tree)] | |
35 | self.items = self.get_items(tree) | |
46 | 36 | else: |
47 | 37 | self.items = [] |
48 | 38 | |
116 | 106 | return None |
117 | 107 | |
118 | 108 | |
119 | class Results(): | |
109 | class Results: | |
120 | 110 | |
121 | 111 | def __init__(self, issue_node): |
122 | 112 | self.node = issue_node |
181 | 171 | self.framework_version = "1.0.0" |
182 | 172 | self.options = None |
183 | 173 | |
184 | ||
185 | 174 | def parseOutputString(self, output): |
186 | 175 | |
187 | 176 | parser = RetinaXmlParser(output) |
188 | 177 | for item in parser.items: |
189 | 178 | hostname = item.hostname if item.hostname else None |
190 | h_id = self.createAndAddHost(item.ip, item.os,hostnames=[hostname]) | |
179 | h_id = self.createAndAddHost(item.ip, item.os, hostnames=[hostname]) | |
191 | 180 | |
192 | 181 | if not item.netbiosname == 'N/A': |
193 | 182 | self.createAndAddNoteToHost( |
222 | 211 | del parser |
223 | 212 | |
224 | 213 | |
225 | def setHost(self): | |
226 | pass | |
227 | ||
228 | ||
229 | 214 | def createPlugin(ignore_info=False): |
230 | 215 | return RetinaPlugin(ignore_info=ignore_info) |
231 | ||
232 |
147 | 147 | p = SkipfishParser(self._output_file_path) |
148 | 148 | |
149 | 149 | hostc = {} |
150 | port = 80 | |
151 | 150 | for issue in p.issues: |
152 | req = "" | |
153 | res = "" | |
154 | 151 | for sample in issue["samples"]: |
155 | 152 | if not sample["url"] in hostc: |
156 | 153 | reg = re.search( |
175 | 172 | 'host': host, |
176 | 173 | 'protocol': protocol, |
177 | 174 | 's_id': s_id} |
178 | ||
179 | try: | |
180 | req = open("%s/request.dat" % sample["dir"], "r").read() | |
181 | except: | |
182 | pass | |
183 | ||
184 | try: | |
185 | res = open("%s/request.dat" % sample["dir"], "r").read() | |
186 | except Exception: | |
187 | pass | |
188 | 175 | |
189 | 176 | d = hostc[sample["url"]] |
190 | 177 | self.createAndAddVulnWebToService( |
213 | 200 | else: |
214 | 201 | return re.sub(arg_match.group(1), r"-o %s" % self._output_file_path, command_string, 1) |
215 | 202 | |
216 | def setHost(self): | |
217 | pass | |
203 | ||
218 | 204 | |
219 | 205 | |
220 | 206 | def createPlugin(ignore_info=False): |
0 | """ | |
1 | Faraday Penetration Test IDE | |
2 | Copyright (C) 2013 Infobyte LLC (http://www.infobytesec.com/) | |
3 | See the file 'doc/LICENSE' for the license information | |
4 | """⏎ |
0 | """ | |
1 | Faraday Penetration Test IDE | |
2 | Copyright (C) 2021 Infobyte LLC (http://www.infobytesec.com/) | |
3 | See the file 'doc/LICENSE' for the license information | |
4 | ||
5 | """ | |
6 | import json | |
7 | from faraday_plugins.plugins.plugin import PluginJsonFormat | |
8 | from datetime import datetime | |
9 | import dateutil | |
10 | ||
11 | VULNERABILITY = "VULNERABILITY" | |
12 | ||
13 | # ATTENTION: The following mappings are created following the common sense in order to integrate F! with SQ. You | |
14 | # can see what term means in the following website: https://docs.sonarqube.org/latest/user-guide/issues/ | |
15 | SEVERITIES = { | |
16 | 'INFO': 'unclassified', | |
17 | 'MINOR': 'low', | |
18 | 'MAJOR': 'medium', | |
19 | 'CRITICAL': 'high', | |
20 | 'BLOCKER': 'critical' | |
21 | } | |
22 | STATUSES = { | |
23 | 'OPEN': 'open', | |
24 | 'CONFIRMED': 'opened', | |
25 | 'REOPENED': 're-opened', | |
26 | 'CLOSED': 'closed', | |
27 | 'RESOLVED': 'closed' | |
28 | } | |
29 | ||
30 | ||
31 | class SonarQubeAPIParser: | |
32 | def __init__(self, json_output): | |
33 | json_data = json.loads(json_output) | |
34 | ||
35 | self.vulns = self._parse_vulns(json_data) | |
36 | ||
37 | def _parse_vulns(self, json_data): | |
38 | vulns = [] | |
39 | components = {item['key']: | |
40 | {'name': item['name'], 'longName': item['longName']} | |
41 | for item in json_data['components'] } | |
42 | for issue in json_data['issues']: | |
43 | if issue['type'] != VULNERABILITY: | |
44 | continue | |
45 | ||
46 | component = issue['component'] | |
47 | path = components[component]['longName'] | |
48 | vuln_description = f"Issue found in line {issue['line']} of {path}" | |
49 | project = f"Project: {issue['project']}" | |
50 | severity = SEVERITIES[issue['severity']] | |
51 | message = issue['message'] | |
52 | status = STATUSES[issue['status']] | |
53 | tags = issue['tags'] | |
54 | external_id = issue['rule'] | |
55 | creation_date = dateutil.parser.parse(issue['creationDate']) | |
56 | data = [] if not issue['flows'] else ["Flows:"] | |
57 | for flow in issue['flows']: | |
58 | for location in flow['locations']: | |
59 | location_message = f"\"{location['msg']}\" in line {location['textRange']['startLine']} " \ | |
60 | f"of {components[component]['longName']}" | |
61 | data.append(location_message) | |
62 | vulns.append( | |
63 | {'name': message, 'description': vuln_description, 'project': project, 'path': path, 'severity': severity, 'status': status, 'tags': tags, | |
64 | 'creation_date': creation_date, 'data': "\n".join(data), 'external_id': external_id}) | |
65 | ||
66 | return vulns | |
67 | ||
68 | ||
69 | class SonarQubeAPIPlugin(PluginJsonFormat): | |
70 | def __init__(self, *arg, **kwargs): | |
71 | super().__init__(*arg, **kwargs) | |
72 | self.json_keys = {'total', 'effortTotal', 'issues', 'components', 'facets'} | |
73 | self.id = "sonarqubeAPI" | |
74 | self.name = "SonarQube API Plugin" | |
75 | self.plugin_version = "0.0.1" | |
76 | ||
77 | ||
78 | def parseOutputString(self, output, debug=False): | |
79 | parser = SonarQubeAPIParser(output) | |
80 | for vuln in parser.vulns: | |
81 | host_id = self.createAndAddHost(vuln['path'], description=vuln['project']) | |
82 | ||
83 | self.createAndAddVulnToHost( | |
84 | host_id=host_id, | |
85 | name=vuln['name'], | |
86 | desc=vuln['description'], | |
87 | status=vuln['status'], | |
88 | run_date=vuln['creation_date'], | |
89 | severity=vuln['severity'], | |
90 | tags=vuln['tags'], | |
91 | data=vuln['data'], | |
92 | external_id=vuln['external_id'] | |
93 | ) | |
94 | ||
95 | ||
96 | def createPlugin(ignore_info=False): | |
97 | return SonarQubeAPIPlugin(ignore_info=ignore_info) |
6 | 6 | import re |
7 | 7 | import json |
8 | 8 | from faraday_plugins.plugins.plugin import PluginJsonFormat |
9 | from faraday_plugins.plugins.plugins_utils import resolve_hostname | |
9 | 10 | |
10 | 11 | __author__ = "Blas Moyano" |
11 | 12 | __copyright__ = "Copyright (c) 2020, Infobyte LLC" |
70 | 71 | |
71 | 72 | def get_host(self, server_location): |
72 | 73 | port = server_location.get('port', None) |
73 | protocol = '' | |
74 | if port is not None: | |
75 | if port == 443: | |
76 | protocol = 'https' | |
77 | else: | |
78 | protocol = 'http' | |
74 | hostname = server_location.get('hostname', None) | |
75 | ip = server_location.get('ip_address', resolve_hostname(hostname)) | |
79 | 76 | |
80 | 77 | json_host = { |
81 | "url": server_location.get('hostname', None), | |
82 | "ip": server_location.get('ip_address', '0.0.0.0'), | |
78 | "name": 'https', | |
79 | "ip": ip, | |
80 | "hostname": hostname, | |
83 | 81 | "port": port, |
84 | "protocol": protocol | |
82 | "protocol": 'tcp' | |
85 | 83 | } |
86 | 84 | |
87 | 85 | return json_host |
177 | 175 | parser = SslyzeJsonParser(output) |
178 | 176 | |
179 | 177 | for info_sslyze in parser.list_vul: |
180 | info_sslyze['host_info'].get('url') | |
178 | info_sslyze['host_info'].get('hostname') | |
181 | 179 | host_id = self.createAndAddHost( |
182 | 180 | info_sslyze['host_info'].get('ip'), |
183 | 181 | os="unknown", |
184 | 182 | hostnames=[ |
185 | info_sslyze['host_info'].get('url') | |
183 | info_sslyze['host_info'].get('hostname') | |
186 | 184 | ] |
187 | 185 | ) |
188 | 186 | service_id = self.createAndAddServiceToHost( |
189 | 187 | host_id, |
190 | name=info_sslyze['host_info'].get('protocol'), | |
188 | name=info_sslyze['host_info'].get('name'), | |
191 | 189 | protocol=info_sslyze['host_info'].get('protocol'), |
192 | 190 | ports=[ |
193 | 191 | info_sslyze['host_info'].get('port') |
4 | 4 | |
5 | 5 | """ |
6 | 6 | import re |
7 | import xml.etree.ElementTree as ET | |
7 | 8 | from urllib.parse import urlparse |
9 | ||
8 | 10 | from faraday_plugins.plugins.plugin import PluginXMLFormat |
9 | 11 | from faraday_plugins.plugins.plugins_utils import resolve_hostname |
10 | ||
11 | try: | |
12 | import xml.etree.cElementTree as ET | |
13 | import xml.etree.ElementTree as ET_ORIG | |
14 | ETREE_VERSION = ET_ORIG.VERSION | |
15 | except ImportError: | |
16 | import xml.etree.ElementTree as ET | |
17 | ETREE_VERSION = ET.VERSION | |
18 | ||
19 | ETREE_VERSION = [int(i) for i in ETREE_VERSION.split(".")] | |
20 | ||
21 | 12 | |
22 | 13 | __author__ = "Francisco Amato" |
23 | 14 | __copyright__ = "Copyright (c) 2013, Infobyte LLC" |
72 | 63 | """ |
73 | 64 | @return items A list of Host instances |
74 | 65 | """ |
75 | bugtype = "" | |
76 | 66 | |
77 | 67 | if len(tree.findall('scan-info')) == 0: |
78 | 68 | scaninfo = tree.findall('scaninfo')[0] |
103 | 93 | |
104 | 94 | @return An attribute value |
105 | 95 | """ |
106 | global ETREE_VERSION | |
107 | node = None | |
108 | ||
109 | if ETREE_VERSION[0] <= 1 and ETREE_VERSION[1] < 3: | |
110 | ||
111 | match_obj = re.search( | |
112 | "([^\@]+?)\[\@([^=]*?)=\'([^\']*?)\'", subnode_xpath_expr) | |
113 | if match_obj is not None: | |
114 | node_to_find = match_obj.group(1) | |
115 | xpath_attrib = match_obj.group(2) | |
116 | xpath_value = match_obj.group(3) | |
117 | for node_found in xml_node.findall(node_to_find): | |
118 | if node_found.attrib[xpath_attrib] == xpath_value: | |
119 | node = node_found | |
120 | break | |
121 | else: | |
122 | node = xml_node.find(subnode_xpath_expr) | |
123 | ||
124 | else: | |
125 | node = xml_node.find(subnode_xpath_expr) | |
96 | node = xml_node.find(subnode_xpath_expr) | |
126 | 97 | |
127 | 98 | if node is not None: |
128 | 99 | return node.get(attrib_name) |
225 | 196 | } |
226 | 197 | |
227 | 198 | def parseOutputString(self, output): |
228 | ||
229 | 199 | parser = W3afXmlParser(output) |
230 | 200 | ip = resolve_hostname(parser.host) |
231 | 201 | h_id = self.createAndAddHost(ip, hostnames=[parser.host]) |
232 | 202 | s_id = self.createAndAddServiceToHost(h_id, "http", "tcp", ports=[parser.port], status="open") |
233 | 203 | |
234 | 204 | for item in parser.items: |
235 | v_id = self.createAndAddVulnWebToService(h_id, s_id, item.name, | |
205 | self.createAndAddVulnWebToService(h_id, s_id, item.name, | |
236 | 206 | item.detail, pname=item.param, path=item.url, website=parser.host, |
237 | 207 | severity=item.severity, method=item.method, request=item.req, |
238 | 208 | resolution=item.resolution, ref=item.ref, response=item.resp) |
239 | 209 | del parser |
240 | 210 | |
241 | 211 | |
242 | ||
243 | 212 | def createPlugin(ignore_info=False): |
244 | 213 | return W3afPlugin(ignore_info=ignore_info) |
245 | ||
246 |
4 | 4 | |
5 | 5 | """ |
6 | 6 | import re |
7 | import xml.etree.ElementTree as ET | |
7 | 8 | from urllib.parse import urlparse |
9 | ||
8 | 10 | from faraday_plugins.plugins.plugin import PluginXMLFormat |
9 | 11 | from faraday_plugins.plugins.plugins_utils import resolve_hostname |
10 | ||
11 | try: | |
12 | import xml.etree.cElementTree as ET | |
13 | import xml.etree.ElementTree as ET_ORIG | |
14 | ETREE_VERSION = ET_ORIG.VERSION | |
15 | except ImportError: | |
16 | import xml.etree.ElementTree as ET | |
17 | ETREE_VERSION = ET.VERSION | |
18 | ||
19 | ETREE_VERSION = [int(i) for i in ETREE_VERSION.split(".")] | |
20 | ||
21 | 12 | |
22 | 13 | __author__ = "Francisco Amato" |
23 | 14 | __copyright__ = "Copyright (c) 2013, Infobyte LLC" |
72 | 63 | yield Item(tree) |
73 | 64 | |
74 | 65 | |
75 | ||
76 | 66 | def get_attrib_from_subnode(xml_node, subnode_xpath_expr, attrib_name): |
77 | 67 | """ |
78 | 68 | Finds a subnode in the item node and the retrieves a value from it |
79 | 69 | |
80 | 70 | @return An attribute value |
81 | 71 | """ |
82 | global ETREE_VERSION | |
83 | node = None | |
84 | ||
85 | if ETREE_VERSION[0] <= 1 and ETREE_VERSION[1] < 3: | |
86 | match_obj = re.search( | |
87 | "([^\@]+?)\[\@([^=]*?)=\'([^\']*?)\'", subnode_xpath_expr) | |
88 | if match_obj is not None: | |
89 | node_to_find = match_obj.group(1) | |
90 | xpath_attrib = match_obj.group(2) | |
91 | xpath_value = match_obj.group(3) | |
92 | for node_found in xml_node.findall(node_to_find): | |
93 | if node_found.attrib[xpath_attrib] == xpath_value: | |
94 | node = node_found | |
95 | break | |
96 | else: | |
97 | node = xml_node.find(subnode_xpath_expr) | |
98 | else: | |
99 | node = xml_node.find(subnode_xpath_expr) | |
72 | ||
73 | node = xml_node.find(subnode_xpath_expr) | |
100 | 74 | if node is not None: |
101 | 75 | return node.get(attrib_name) |
102 | 76 | return None |
147 | 121 | target = self.get_info(item_node, 'target') |
148 | 122 | return urlparse(target) |
149 | 123 | |
150 | def get_info(self, item_node,name): | |
124 | def get_info(self, item_node, name): | |
151 | 125 | path = item_node.findall('report_infos/info') |
152 | 126 | |
153 | 127 | for item in path: |
170 | 144 | for vuln in vulns_node: |
171 | 145 | vulns_dict = {} |
172 | 146 | vulns_dict['id'] = vuln.attrib['name'] |
173 | vulns_dict['description'] = self.get_text_from_subnode(vuln,'description') | |
174 | vulns_dict['solution'] = self.get_text_from_subnode(vuln,'solution') | |
147 | vulns_dict['description'] = self.get_text_from_subnode(vuln, 'description') | |
148 | vulns_dict['solution'] = self.get_text_from_subnode(vuln, 'solution') | |
175 | 149 | vulns_dict['references'] = self.get_references(vuln) |
176 | 150 | vulns_dict['entries'] = self.get_entries(vuln) |
177 | 151 | vulns_list.append(vulns_dict) |
182 | 156 | refs = node.findall('references/reference') |
183 | 157 | references_list = [] |
184 | 158 | for ref in refs: |
185 | references_list.append('Title: ' + self.get_text_from_subnode(ref,'title')) | |
186 | references_list.append('URL: ' + self.get_text_from_subnode(ref,'url')) | |
159 | references_list.append('Title: ' + self.get_text_from_subnode(ref, 'title')) | |
160 | references_list.append('URL: ' + self.get_text_from_subnode(ref, 'url')) | |
187 | 161 | |
188 | 162 | return references_list |
189 | 163 | |
190 | def get_entries(self,node): | |
164 | def get_entries(self, node): | |
191 | 165 | entries = node.findall('entries/entry') |
192 | 166 | entries_list = [] |
193 | 167 | for entry in entries: |
194 | 168 | entries_dict = {} |
195 | entries_dict['method'] = self.get_text_from_subnode(entry,'method') | |
196 | entries_dict['path'] = self.get_text_from_subnode(entry,'path') | |
169 | entries_dict['method'] = self.get_text_from_subnode(entry, 'method') | |
170 | entries_dict['path'] = self.get_text_from_subnode(entry, 'path') | |
197 | 171 | entries_dict['level'] = self.severity_format(entry) |
198 | entries_dict['parameter'] = self.get_text_from_subnode(entry,'parameter') | |
199 | entries_dict['http_request'] = self.get_text_from_subnode(entry,'http_request') | |
200 | entries_dict['curl_command'] = self.get_text_from_subnode(entry,'curl_command') | |
172 | entries_dict['parameter'] = self.get_text_from_subnode(entry, 'parameter') | |
173 | entries_dict['http_request'] = self.get_text_from_subnode(entry, 'http_request') | |
174 | entries_dict['curl_command'] = self.get_text_from_subnode(entry, 'curl_command') | |
201 | 175 | entries_list.append(entries_dict) |
202 | 176 | |
203 | 177 | return entries_list |
288 | 262 | return re.search("Wapiti", output) is not None |
289 | 263 | return False |
290 | 264 | |
291 | ||
292 | 265 | def parseOutputString(self, output): |
293 | 266 | """ |
294 | 267 | This method will discard the output the shell sends, it will read it from |
295 | 268 | the xml where it expects it to be present. |
296 | 269 | """ |
297 | ||
270 | ||
298 | 271 | parser = WapitiXmlParser(output) |
299 | 272 | for item in parser.items: |
300 | 273 | host_id = self.createAndAddHost(item.ip, hostnames=[item.hostname]) |
306 | 279 | for vuln in item.vulns: |
307 | 280 | for entry in vuln['entries']: |
308 | 281 | vuln_id = self.createAndAddVulnWebToService(host_id, |
309 | service_id, | |
310 | vuln['id'], | |
311 | desc=vuln['description'], | |
312 | ref=vuln['references'], | |
313 | resolution=vuln['solution'], | |
314 | severity=entry['level'], | |
315 | website=entry['curl_command'], | |
316 | path=entry['path'], | |
317 | request=entry['http_request'], | |
318 | method=entry['method'], | |
319 | params=entry['parameter']) | |
282 | service_id, | |
283 | vuln['id'], | |
284 | desc=vuln['description'], | |
285 | ref=vuln['references'], | |
286 | resolution=vuln['solution'], | |
287 | severity=entry['level'], | |
288 | website=entry['curl_command'], | |
289 | path=entry['path'], | |
290 | request=entry['http_request'], | |
291 | method=entry['method'], | |
292 | params=entry['parameter']) | |
320 | 293 | |
321 | 294 | def processCommandString(self, username, current_path, command_string): |
322 | 295 | """ |
338 | 311 | self.port = host.group(11) |
339 | 312 | if self.protocol == 'https': |
340 | 313 | self.port = 443 |
341 | self.logger.debug("host = %s, port = %s",self.host, self.port) | |
314 | self.logger.debug("host = %s, port = %s", self.host, self.port) | |
342 | 315 | return "%s -o %s -f xml \n" % (command_string, self._output_file_path) |
343 | ||
344 | def setHost(self): | |
345 | pass | |
346 | 316 | |
347 | 317 | |
348 | 318 | def createPlugin(ignore_info=False): |
349 | 319 | return WapitiPlugin(ignore_info=ignore_info) |
350 | ||
351 |
2 | 2 | Copyright (C) 2013 Infobyte LLC (http://www.infobytesec.com/) |
3 | 3 | See the file 'doc/LICENSE' for the license information |
4 | 4 | """ |
5 | import re | |
6 | import xml.etree.ElementTree as ET | |
7 | ||
5 | 8 | from faraday_plugins.plugins.plugin import PluginBase |
6 | import re | |
7 | import os | |
8 | import sys | |
9 | import random | |
10 | ||
11 | try: | |
12 | import xml.etree.cElementTree as ET | |
13 | import xml.etree.ElementTree as ET_ORIG | |
14 | ETREE_VERSION = ET_ORIG.VERSION | |
15 | except ImportError: | |
16 | import xml.etree.ElementTree as ET | |
17 | ETREE_VERSION = ET.VERSION | |
18 | ||
19 | ETREE_VERSION = [int(i) for i in ETREE_VERSION.split(".")] | |
20 | ||
21 | 9 | |
22 | 10 | __author__ = "Morgan Lemarechal" |
23 | 11 | __copyright__ = "Copyright 2014, Faraday Project" |
91 | 79 | self._temp_file_extension = "xml" |
92 | 80 | self.xml_arg_re = re.compile(r"^.*(--xml\s*[^\s]+).*$") |
93 | 81 | |
94 | ||
95 | 82 | def parseOutputString(self, output): |
96 | 83 | """ |
97 | 84 | This method will discard the output the shell sends, it will read it from |
114 | 101 | if parser.scaninfo[file]['type'] == "webconfig": |
115 | 102 | vuln_name = f"{parser.scaninfo[file]['file']}: {str(parser.result[file][vuln][3])}" |
116 | 103 | vuln_description = f"{str(parser.result[file][vuln][3])} : {str(parser.result[file][vuln][2])} = {str(parser.result[file][vuln][0])}\n{str(parser.result[file][vuln][1])}" |
117 | v_id = self.createAndAddVulnToService(h_id, s_id, vuln_name, desc=vuln_description, severity=0) | |
118 | ||
119 | ||
104 | self.createAndAddVulnToService(h_id, s_id, vuln_name, desc=vuln_description, severity=0) | |
120 | 105 | |
121 | 106 | def processCommandString(self, username, current_path, command_string): |
122 | 107 | """ |
134 | 119 | |
135 | 120 | def createPlugin(ignore_info=False): |
136 | 121 | return WcscanPlugin(ignore_info=ignore_info) |
137 | ||
138 |
7 | 7 | from faraday_plugins.plugins.plugin import PluginXMLFormat |
8 | 8 | from faraday_plugins.plugins.plugins_utils import get_vulnweb_url_fields |
9 | 9 | |
10 | try: | |
11 | import xml.etree.cElementTree as ET | |
12 | except ImportError: | |
13 | import xml.etree.ElementTree as ET | |
10 | import xml.etree.ElementTree as ET | |
14 | 11 | |
15 | 12 | |
16 | 13 | def cleanhtml(raw_html): |
3 | 3 | See the file 'doc/LICENSE' for the license information |
4 | 4 | |
5 | 5 | """ |
6 | import os | |
7 | import re | |
8 | import xml.etree.ElementTree as ET | |
9 | ||
6 | 10 | from faraday_plugins.plugins.plugin import PluginXMLFormat |
7 | import re | |
8 | import os | |
9 | import sys | |
10 | ||
11 | try: | |
12 | import xml.etree.cElementTree as ET | |
13 | import xml.etree.ElementTree as ET_ORIG | |
14 | ETREE_VERSION = ET_ORIG.VERSION | |
15 | except ImportError: | |
16 | import xml.etree.ElementTree as ET | |
17 | ETREE_VERSION = ET.VERSION | |
18 | ||
19 | ETREE_VERSION = [int(i) for i in ETREE_VERSION.split(".")] | |
20 | 11 | |
21 | 12 | current_path = os.path.abspath(os.getcwd()) |
22 | 13 | |
133 | 124 | self.resolution = self.get_text_from_subnode('solution') |
134 | 125 | self.ref = [] |
135 | 126 | for r in issue_node.findall('refs/reference'): |
136 | ||
137 | 127 | self.ref.append(r.get('type') + "-" + r.get('text')) |
138 | 128 | |
139 | 129 | def get_text_from_subnode(self, subnode_xpath_expr): |
166 | 156 | self._current_output = None |
167 | 157 | self._command_regex = re.compile(r'^(sudo x1|\.\/x1)\s+.*?') |
168 | 158 | |
169 | ||
170 | ||
171 | 159 | def parseOutputString(self, output): |
172 | 160 | |
173 | 161 | parser = X1XmlParser(output) |
188 | 176 | del parser |
189 | 177 | |
190 | 178 | |
191 | def setHost(self): | |
192 | pass | |
193 | ||
194 | ||
195 | 179 | def createPlugin(ignore_info=False): |
196 | 180 | return X1Plugin(ignore_info=ignore_info) |
197 | ||
198 |
0 | /* | |
1 | * Zed Attack Proxy (ZAP) and its related class files. | |
2 | * | |
3 | * ZAP is an HTTP/HTTPS proxy for assessing web application security. | |
4 | * | |
5 | * Copyright 2018 The ZAP Development Team | |
6 | * | |
7 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
8 | * you may not use this file except in compliance with the License. | |
9 | * You may obtain a copy of the License at | |
10 | * | |
11 | * http://www.apache.org/licenses/LICENSE-2.0 | |
12 | * | |
13 | * Unless required by applicable law or agreed to in writing, software | |
14 | * distributed under the License is distributed on an "AS IS" BASIS, | |
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
16 | * See the License for the specific language governing permissions and | |
17 | * limitations under the License. | |
18 | */ | |
19 | ||
20 | package org.zaproxy.zap.extension.faraday; | |
21 | ||
22 | import org.parosproxy.paros.Constant; | |
23 | ||
24 | import javax.swing.*; | |
25 | import java.io.*; | |
26 | import java.util.Properties; | |
27 | ||
28 | public class Configuration { | |
29 | private String server; | |
30 | private String user; | |
31 | private String password; | |
32 | private String session; | |
33 | private String workspace; | |
34 | private boolean autoImport; | |
35 | private static Configuration _instance; | |
36 | ||
37 | private Configuration() { | |
38 | this.user = ""; | |
39 | this.password = ""; | |
40 | this.server = "http://127.0.0.1:5985/"; | |
41 | this.autoImport = false; | |
42 | } | |
43 | ||
44 | public static Configuration getSingleton() { | |
45 | if (_instance == null) | |
46 | _instance = new Configuration(); | |
47 | return _instance; | |
48 | } | |
49 | ||
50 | public boolean save() throws IOException { | |
51 | ||
52 | Properties prop = new Properties(); | |
53 | OutputStream output = null; | |
54 | ||
55 | String userHome = System.getProperty("user.home"); | |
56 | String outputFolder = Constant.getZapHome() + "faraday"; | |
57 | File folder = new File(outputFolder); | |
58 | if (!folder.exists()) { | |
59 | folder.mkdir(); | |
60 | } | |
61 | ||
62 | ||
63 | String filePath = outputFolder + File.separator + this.getUser() + ".properties"; | |
64 | output = new FileOutputStream(filePath); | |
65 | ||
66 | // set the properties value | |
67 | prop.setProperty("fuser", this.getUser()); | |
68 | prop.setProperty("fpassword", this.getPassword()); | |
69 | prop.setProperty("fserver", this.getServer()); | |
70 | prop.setProperty("fworkspace", this.getWorkspace()); | |
71 | prop.setProperty("fsession", this.getSession()); | |
72 | ||
73 | // save properties to project root folder | |
74 | prop.store(output, null); | |
75 | ||
76 | if (output != null) { | |
77 | try { | |
78 | output.close(); | |
79 | } catch (IOException e) { | |
80 | e.printStackTrace(); | |
81 | return false; | |
82 | } | |
83 | } | |
84 | ||
85 | return true; | |
86 | } | |
87 | ||
88 | ||
89 | public void restore(String fUser) throws IOException { | |
90 | Properties prop = new Properties(); | |
91 | InputStream input = null; | |
92 | ||
93 | String outputFolder = Constant.getZapHome() + "faraday"; | |
94 | String filePath = outputFolder + File.separator + fUser + ".properties"; | |
95 | input = new FileInputStream(filePath); | |
96 | ||
97 | // load a properties file | |
98 | prop.load(input); | |
99 | ||
100 | this.setUser(prop.getProperty("fuser")); | |
101 | this.setPassword(prop.getProperty("fpassword")); | |
102 | this.setServer(prop.getProperty("fserver")); | |
103 | this.setWorkspace(prop.getProperty("fworkspace")); | |
104 | ||
105 | if (input != null) { | |
106 | try { | |
107 | input.close(); | |
108 | } catch (IOException e) { | |
109 | e.printStackTrace(); | |
110 | } | |
111 | } | |
112 | ||
113 | } | |
114 | ||
115 | public String getUser() { | |
116 | return user; | |
117 | } | |
118 | ||
119 | public void setUser(String user) { | |
120 | this.user = user; | |
121 | } | |
122 | ||
123 | public String getPassword() { | |
124 | return password; | |
125 | } | |
126 | ||
127 | public void setPassword(String password) { | |
128 | this.password = password; | |
129 | } | |
130 | ||
131 | public String getServer() { | |
132 | return server; | |
133 | } | |
134 | ||
135 | public void setServer(String server) { | |
136 | this.server = server; | |
137 | } | |
138 | ||
139 | public boolean isAutoImport() { | |
140 | return autoImport; | |
141 | } | |
142 | ||
143 | public void setAutoImport(boolean autoImport) { | |
144 | this.autoImport = autoImport; | |
145 | } | |
146 | ||
147 | public String getSession() { | |
148 | return session; | |
149 | } | |
150 | ||
151 | public void setSession(String session) { | |
152 | this.session = session; | |
153 | } | |
154 | ||
155 | public String getWorkspace() { | |
156 | return workspace; | |
157 | } | |
158 | ||
159 | public void setWorkspace(String workspace) { | |
160 | this.workspace = workspace; | |
161 | } | |
162 | } |
0 | package org.zaproxy.zap.extension.faraday; | |
1 | ||
2 | ||
3 | import org.apache.log4j.Logger; | |
4 | import org.parosproxy.paros.Constant; | |
5 | ||
6 | import javax.swing.*; | |
7 | import javax.swing.border.Border; | |
8 | import java.awt.*; | |
9 | import java.awt.event.*; | |
10 | import java.io.*; | |
11 | import java.util.ArrayList; | |
12 | import java.util.Properties; | |
13 | import java.util.ResourceBundle; | |
14 | ||
15 | public class ConfigurationDialog extends JFrame { | |
16 | private static final Logger logger = Logger.getLogger(ConfigurationDialog.class); | |
17 | private ResourceBundle messages = null; | |
18 | private FaradayClient faradayClient; | |
19 | ||
20 | private static String LOGIN_BUTTON = "Login"; | |
21 | private static String LOGOUT_BUTTON = "Logout"; | |
22 | private static String WORKSPACES_FIELD = "Select faraday workspace"; | |
23 | private static String IMPORT_NEW_VULNS_FIELD = "Import new vulnerabilities"; | |
24 | private static String SET_CONFIG_AS_DEFAULT = "Set this configuration as default"; | |
25 | private static String IMPORT_BUTTON = "Import vulnerabilities"; | |
26 | private static String REFRESH_BUTTON = "Refresh"; | |
27 | private static String RESTORE_BUTTON = "Restore"; | |
28 | private static String SAVE_BUTTON = "Save"; | |
29 | ||
30 | private JTabbedPane tabbedPane; | |
31 | private JPanel authPanel; | |
32 | private JPanel configPanel; | |
33 | ||
34 | private JTextField fldUser; | |
35 | private JTextField fldPass; | |
36 | private JTextField fldServer; | |
37 | ||
38 | private JComboBox cmbWorkspaces; | |
39 | private JCheckBox cboxSetConfigDefault; | |
40 | ||
41 | ||
42 | private JButton loginButton; | |
43 | private JButton logoutButton; | |
44 | private JButton refreshButton; | |
45 | private JButton restoreButton; | |
46 | private JButton importButton; | |
47 | private JButton saveButton; | |
48 | private JButton closeButton; | |
49 | ||
50 | ||
51 | public ConfigurationDialog(String s) throws HeadlessException { | |
52 | super(s); | |
53 | } | |
54 | ||
55 | ||
56 | public void init() { | |
57 | logger.debug("Init Faraday configuration dialog"); | |
58 | messages = ResourceBundle.getBundle( | |
59 | this.getClass().getPackage().getName() + | |
60 | ".Messages", Constant.getLocale()); | |
61 | // Setup the content-pane of JFrame in BorderLayout | |
62 | Container cp = this.getContentPane(); | |
63 | cp.setLayout(new BorderLayout(5, 5)); | |
64 | Border padding = BorderFactory.createEmptyBorder(10, 10, 10, 10); | |
65 | ||
66 | ||
67 | String USERNAME_FIELD = messages.getString("faraday.config.dialog.auth.user"); | |
68 | String PASS_FIELD = messages.getString("faraday.config.dialog.auth.pass"); | |
69 | String SERVER_FIELD = messages.getString("faraday.config.dialog.server"); | |
70 | LOGIN_BUTTON = messages.getString("faraday.config.dialog.auth.login"); | |
71 | LOGOUT_BUTTON = messages.getString("faraday.config.dialog.auth.logout"); | |
72 | WORKSPACES_FIELD = messages.getString("faraday.config.dialog.workspace"); | |
73 | IMPORT_NEW_VULNS_FIELD = messages.getString("faraday.config.dialog.import.new"); | |
74 | SET_CONFIG_AS_DEFAULT = messages.getString("faraday.config.dialog.default"); | |
75 | IMPORT_BUTTON = messages.getString("faraday.config.dialog.import.new"); | |
76 | REFRESH_BUTTON = messages.getString("faraday.config.dialog.refresh"); | |
77 | RESTORE_BUTTON = messages.getString("faraday.config.dialog.restore"); | |
78 | SAVE_BUTTON = messages.getString("faraday.config.dialog.save"); | |
79 | tabbedPane = new JTabbedPane(); | |
80 | ||
81 | JPanel buttonLoginPanel = new JPanel(); | |
82 | buttonLoginPanel.setLayout(new FlowLayout(FlowLayout.RIGHT)); | |
83 | ||
84 | JPanel buttonConfigPanel = new JPanel(); | |
85 | buttonConfigPanel.setLayout(new FlowLayout(FlowLayout.RIGHT)); | |
86 | ||
87 | authPanel = new JPanel(new GridLayout(4, 2, 10, 2)); | |
88 | authPanel.setBorder(padding); | |
89 | configPanel = new JPanel(new GridLayout(3, 2, 10, 2)); | |
90 | configPanel.setBorder(padding); | |
91 | ||
92 | ||
93 | Configuration configuration = Configuration.getSingleton(); | |
94 | faradayClient = new FaradayClient(configuration.getServer()); | |
95 | ||
96 | authPanel.add(new JLabel(USERNAME_FIELD)); | |
97 | fldUser = new JTextField(10); | |
98 | authPanel.add(fldUser); | |
99 | ||
100 | authPanel.add(new JLabel(PASS_FIELD)); | |
101 | fldPass = new JPasswordField(10); | |
102 | authPanel.add(fldPass); | |
103 | ||
104 | authPanel.add(new JLabel(SERVER_FIELD)); | |
105 | fldServer = new JTextField(10); | |
106 | fldServer.setText(configuration.getServer()); | |
107 | authPanel.add(fldServer); | |
108 | ||
109 | configPanel.add(getCBoxSetDefaultConfig()); | |
110 | ||
111 | buttonConfigPanel.add(getCloseButton()); | |
112 | buttonConfigPanel.add(getCloseButton()); | |
113 | buttonConfigPanel.add(getRefreshButton()); | |
114 | buttonConfigPanel.add(getRestoreButton()); | |
115 | buttonConfigPanel.add(getSaveButton()); | |
116 | // buttonConfigPanel.add(getImportButton()); | |
117 | buttonConfigPanel.add(getLoginButton()); | |
118 | buttonConfigPanel.add(getLogoutButton()); | |
119 | ||
120 | ||
121 | authPanel.addComponentListener(new ComponentListener() { | |
122 | @Override | |
123 | public void componentResized(ComponentEvent componentEvent) { | |
124 | ||
125 | } | |
126 | ||
127 | @Override | |
128 | public void componentMoved(ComponentEvent componentEvent) { | |
129 | ||
130 | } | |
131 | ||
132 | @Override | |
133 | public void componentShown(ComponentEvent componentEvent) { | |
134 | ||
135 | refreshButton.setVisible(false); | |
136 | restoreButton.setVisible(false); | |
137 | // importButton.setVisible(false); | |
138 | saveButton.setVisible(false); | |
139 | } | |
140 | ||
141 | @Override | |
142 | public void componentHidden(ComponentEvent componentEvent) { | |
143 | refreshButton.setVisible(true); | |
144 | restoreButton.setVisible(true); | |
145 | // importButton.setVisible(true); | |
146 | saveButton.setVisible(true); | |
147 | } | |
148 | }); | |
149 | ||
150 | configPanel.addComponentListener(new ComponentListener() { | |
151 | @Override | |
152 | public void componentResized(ComponentEvent componentEvent) { | |
153 | ||
154 | } | |
155 | ||
156 | @Override | |
157 | public void componentMoved(ComponentEvent componentEvent) { | |
158 | ||
159 | } | |
160 | ||
161 | @Override | |
162 | public void componentShown(ComponentEvent componentEvent) { | |
163 | loginButton.setVisible(false); | |
164 | logoutButton.setVisible(false); | |
165 | } | |
166 | ||
167 | @Override | |
168 | public void componentHidden(ComponentEvent componentEvent) { | |
169 | if (configuration.getSession().equals("")) { | |
170 | loginButton.setVisible(true); | |
171 | } else { | |
172 | logoutButton.setVisible(true); | |
173 | } | |
174 | } | |
175 | }); | |
176 | ||
177 | tabbedPane.addTab(messages.getString("faraday.config.dialog.tab.auth"), null, authPanel, null); | |
178 | tabbedPane.setMnemonicAt(0, KeyEvent.VK_1); | |
179 | ||
180 | ||
181 | tabbedPane.addTab(messages.getString("faraday.config.dialog.tabs.conf"), null, configPanel, null); | |
182 | tabbedPane.setMnemonicAt(1, KeyEvent.VK_2); | |
183 | ||
184 | tabbedPane.setEnabledAt(1, false); | |
185 | ||
186 | cp.add(tabbedPane, BorderLayout.NORTH); | |
187 | cp.add(buttonConfigPanel, BorderLayout.SOUTH); | |
188 | ||
189 | if (configuration.getSession() != null && !configuration.getSession().equals("")) { | |
190 | logoutButton.setVisible(true); | |
191 | loginButton.setVisible(false); | |
192 | } else { | |
193 | loginButton.setVisible(true); | |
194 | logoutButton.setVisible(false); | |
195 | } | |
196 | ||
197 | ||
198 | if (!configuration.getUser().equals("") && !configuration.getPassword().equals("")) { | |
199 | if (faradayClient.Login(configuration.getUser(), configuration.getPassword(), configuration.getServer())) { | |
200 | fldUser.setText(configuration.getUser()); | |
201 | fldPass.setText(configuration.getPassword()); | |
202 | fldServer.setText(configuration.getServer()); | |
203 | ||
204 | tabbedPane.setEnabledAt(1, true); | |
205 | tabbedPane.setSelectedIndex(1); | |
206 | ||
207 | cboxSetConfigDefault.setSelected(true); | |
208 | ||
209 | if (cmbWorkspaces == null) { | |
210 | configPanel.add(new JLabel(WORKSPACES_FIELD)); | |
211 | configPanel.add(getWSComboBox()); | |
212 | } | |
213 | } | |
214 | } | |
215 | ||
216 | this.setSize(550, 300); | |
217 | this.setResizable(false); | |
218 | this.setLocationRelativeTo(null); | |
219 | this.setVisible(true); | |
220 | } | |
221 | ||
222 | ||
223 | private JButton getLoginButton() { | |
224 | if (this.loginButton == null) { | |
225 | this.loginButton = new JButton(); | |
226 | this.loginButton.setText(LOGIN_BUTTON); | |
227 | this.loginButton.addActionListener(new ActionListener() { | |
228 | public void actionPerformed(ActionEvent e) { | |
229 | if (fldUser.getText().equals("") || fldPass.getText().equals("") || fldServer.getText().equals("")) { | |
230 | showMessage(messages.getString("faraday.message.invalid.check.credentials"), messages.getString("faraday.dialog.login.title"), JOptionPane.ERROR_MESSAGE); | |
231 | } else { | |
232 | if (faradayClient.Login(fldUser.getText(), fldPass.getText(), fldServer.getText())) { | |
233 | logoutButton.setVisible(true); | |
234 | loginButton.setVisible(false); | |
235 | if (!tabbedPane.isEnabledAt(1)) { | |
236 | tabbedPane.setEnabledAt(1, true); | |
237 | } | |
238 | tabbedPane.setSelectedIndex(1); | |
239 | if (cmbWorkspaces == null) { | |
240 | configPanel.add(new JLabel(WORKSPACES_FIELD)); | |
241 | configPanel.add(getWSComboBox()); | |
242 | } else { | |
243 | configPanel.remove(cmbWorkspaces); | |
244 | configPanel.add(getWSComboBox()); | |
245 | } | |
246 | } else { | |
247 | showMessage(messages.getString("faraday.message.invalid.credentials"), messages.getString("faraday.dialog.login.title"), JOptionPane.ERROR_MESSAGE); | |
248 | } | |
249 | } | |
250 | ||
251 | ||
252 | } | |
253 | }); | |
254 | ||
255 | ||
256 | } | |
257 | ||
258 | return this.loginButton; | |
259 | } | |
260 | ||
261 | ||
262 | private JButton getLogoutButton() { | |
263 | if (this.logoutButton == null) { | |
264 | this.logoutButton = new JButton(); | |
265 | this.logoutButton.setText(LOGOUT_BUTTON); | |
266 | this.logoutButton.addActionListener(new ActionListener() { | |
267 | public void actionPerformed(ActionEvent e) { | |
268 | Configuration configuration = Configuration.getSingleton(); | |
269 | String userTemp = configuration.getUser(); | |
270 | if (faradayClient.Logout()) { | |
271 | logoutButton.setVisible(false); | |
272 | loginButton.setVisible(true); | |
273 | ||
274 | if (tabbedPane.isEnabledAt(1)) { | |
275 | tabbedPane.setEnabledAt(1, false); | |
276 | } | |
277 | tabbedPane.setSelectedIndex(0); | |
278 | ||
279 | Properties prop = new Properties(); | |
280 | InputStream input = null; | |
281 | try { | |
282 | String filePath = Constant.getZapHome() + "faraday" + File.separator + "default.properties"; | |
283 | input = new FileInputStream(filePath); | |
284 | // load a properties file | |
285 | prop.load(input); | |
286 | // set the properties value | |
287 | String fUser = prop.getProperty("default"); | |
288 | if (fUser.equals(userTemp)) { | |
289 | removeDefaultConfig(); | |
290 | } | |
291 | ||
292 | } catch (IOException io) { | |
293 | System.out.println("We can't found default.properties file"); | |
294 | } finally { | |
295 | if (input != null) { | |
296 | try { | |
297 | input.close(); | |
298 | } catch (IOException er) { | |
299 | er.printStackTrace(); | |
300 | } | |
301 | } | |
302 | } | |
303 | ||
304 | ||
305 | showMessage(messages.getString("faraday.dialog.logout.success"), messages.getString("faraday.dialog.logout.title"), JOptionPane.INFORMATION_MESSAGE); | |
306 | } else { | |
307 | showMessage(messages.getString("faraday.dialog.logout.error"), messages.getString("faraday.dialog.logout.title"), JOptionPane.ERROR_MESSAGE); | |
308 | } | |
309 | } | |
310 | }); | |
311 | } | |
312 | ||
313 | return this.logoutButton; | |
314 | } | |
315 | ||
316 | ||
317 | private JButton getRefreshButton() { | |
318 | if (this.refreshButton == null) { | |
319 | this.refreshButton = new JButton(); | |
320 | this.refreshButton.setText(REFRESH_BUTTON); | |
321 | this.refreshButton.addActionListener(new ActionListener() { | |
322 | public void actionPerformed(ActionEvent e) { | |
323 | refreshWorkspaces(true); | |
324 | } | |
325 | }); | |
326 | } | |
327 | ||
328 | return this.refreshButton; | |
329 | } | |
330 | ||
331 | ||
332 | private JButton getCloseButton() { | |
333 | if (this.closeButton == null) { | |
334 | this.closeButton = new JButton(); | |
335 | this.closeButton.setText(messages.getString("faraday.dialog.button.close")); | |
336 | this.closeButton.addActionListener(new ActionListener() { | |
337 | public void actionPerformed(ActionEvent e) { | |
338 | setVisible(false); | |
339 | dispose(); | |
340 | } | |
341 | }); | |
342 | } | |
343 | ||
344 | return this.closeButton; | |
345 | } | |
346 | ||
347 | ||
348 | private JButton getRestoreButton() { | |
349 | if (this.restoreButton == null) { | |
350 | this.restoreButton = new JButton(); | |
351 | this.restoreButton.setText(RESTORE_BUTTON); | |
352 | this.restoreButton.addActionListener(new ActionListener() { | |
353 | public void actionPerformed(ActionEvent e) { | |
354 | String fUser = JOptionPane.showInputDialog(messages.getString("faraday.config.dialog.restore"), messages.getString("faraday.dialog.enter.user")); | |
355 | if (fUser != null) { | |
356 | restoreConfiguration(fUser); | |
357 | } | |
358 | } | |
359 | }); | |
360 | } | |
361 | ||
362 | return this.restoreButton; | |
363 | } | |
364 | ||
365 | ||
366 | private JButton getImportButton() { | |
367 | if (this.importButton == null) { | |
368 | this.importButton = new JButton(); | |
369 | this.importButton.setText(IMPORT_BUTTON); | |
370 | this.importButton.addActionListener(new ActionListener() { | |
371 | public void actionPerformed(ActionEvent e) { | |
372 | ||
373 | } | |
374 | }); | |
375 | } | |
376 | ||
377 | return this.importButton; | |
378 | } | |
379 | ||
380 | ||
381 | private JButton getSaveButton() { | |
382 | if (this.saveButton == null) { | |
383 | this.saveButton = new JButton(); | |
384 | this.saveButton.setText(SAVE_BUTTON); | |
385 | this.saveButton.addActionListener(new ActionListener() { | |
386 | public void actionPerformed(ActionEvent e) { | |
387 | saveConfiguration(); | |
388 | } | |
389 | }); | |
390 | } | |
391 | ||
392 | return this.saveButton; | |
393 | } | |
394 | ||
395 | ||
396 | private JComboBox getWSComboBox() { | |
397 | Configuration configuration = Configuration.getSingleton(); | |
398 | ||
399 | ArrayList<String> wsList = faradayClient.GetWorkspaces(); | |
400 | String[] workspaces = new String[wsList.size()]; | |
401 | for (int i = 0; i < wsList.size(); i++) { | |
402 | workspaces[i] = wsList.get(i); | |
403 | } | |
404 | cmbWorkspaces = new JComboBox(workspaces); | |
405 | if (workspaces.length > 0) { | |
406 | if (configuration.getWorkspace() != null) { | |
407 | cmbWorkspaces.setSelectedItem(configuration.getWorkspace()); | |
408 | } else { | |
409 | configuration.setWorkspace(workspaces[0]); | |
410 | } | |
411 | } | |
412 | cmbWorkspaces.addActionListener(new ActionListener() { | |
413 | @Override | |
414 | public void actionPerformed(ActionEvent actionEvent) { | |
415 | Configuration.getSingleton().setWorkspace(cmbWorkspaces.getSelectedItem().toString()); | |
416 | } | |
417 | }); | |
418 | ||
419 | ||
420 | return cmbWorkspaces; | |
421 | } | |
422 | ||
423 | ||
424 | private JCheckBox getCBoxSetDefaultConfig() { | |
425 | if (this.cboxSetConfigDefault == null) { | |
426 | cboxSetConfigDefault = new JCheckBox(SET_CONFIG_AS_DEFAULT, false); | |
427 | ||
428 | cboxSetConfigDefault.addActionListener(new ActionListener() { | |
429 | @Override | |
430 | public void actionPerformed(ActionEvent actionEvent) { | |
431 | if (cboxSetConfigDefault.isSelected()) { | |
432 | setConfigAsDefault(); | |
433 | } else { | |
434 | removeDefaultConfig(); | |
435 | } | |
436 | } | |
437 | }); | |
438 | } | |
439 | ||
440 | return cboxSetConfigDefault; | |
441 | } | |
442 | ||
443 | ||
444 | private void showMessage(String message, String title, int icon) { | |
445 | JOptionPane.showMessageDialog( | |
446 | this, | |
447 | message, | |
448 | title, | |
449 | icon); | |
450 | } | |
451 | ||
452 | ||
453 | private void saveConfiguration() { | |
454 | try { | |
455 | if (Configuration.getSingleton().save()) { | |
456 | JOptionPane.showMessageDialog( | |
457 | this, | |
458 | messages.getString("faraday.save.config.success"), | |
459 | messages.getString("faraday.config.dialog.title"), | |
460 | JOptionPane.INFORMATION_MESSAGE); | |
461 | } else { | |
462 | JOptionPane.showMessageDialog( | |
463 | this, | |
464 | messages.getString("faraday.save.config.error"), | |
465 | messages.getString("faraday.config.dialog.title"), | |
466 | JOptionPane.ERROR_MESSAGE); | |
467 | ||
468 | } | |
469 | } catch (IOException io) { | |
470 | JOptionPane.showMessageDialog( | |
471 | this, | |
472 | messages.getString("faraday.save.config.error"), | |
473 | messages.getString("faraday.config.dialog.title"), | |
474 | JOptionPane.ERROR_MESSAGE); | |
475 | io.printStackTrace(); | |
476 | ||
477 | } | |
478 | } | |
479 | ||
480 | ||
481 | private void restoreConfiguration(String fUser) { | |
482 | try { | |
483 | Configuration configuration = Configuration.getSingleton(); | |
484 | configuration.restore(fUser); | |
485 | if (faradayClient.Login(configuration.getUser(), configuration.getPassword(), configuration.getServer())) { | |
486 | fldUser.setText(configuration.getUser()); | |
487 | fldPass.setText(configuration.getPassword()); | |
488 | fldServer.setText(configuration.getServer()); | |
489 | ||
490 | tabbedPane.setEnabledAt(1, true); | |
491 | tabbedPane.setSelectedIndex(0); | |
492 | ||
493 | cboxSetConfigDefault.setSelected(false); | |
494 | refreshWorkspaces(false); | |
495 | } else { | |
496 | JOptionPane.showMessageDialog( | |
497 | this, | |
498 | messages.getString("faraday.restore.config.error.login"), | |
499 | messages.getString("faraday.config.dialog.title"), | |
500 | JOptionPane.ERROR_MESSAGE); | |
501 | } | |
502 | } catch (IOException ex) { | |
503 | JOptionPane.showMessageDialog( | |
504 | this, | |
505 | messages.getString("faraday.restore.config.error"), | |
506 | messages.getString("faraday.config.dialog.title"), | |
507 | JOptionPane.ERROR_MESSAGE); | |
508 | } | |
509 | ||
510 | } | |
511 | ||
512 | ||
513 | private void setConfigAsDefault() { | |
514 | Configuration configuration = Configuration.getSingleton(); | |
515 | ||
516 | Properties prop = new Properties(); | |
517 | OutputStream output = null; | |
518 | ||
519 | try { | |
520 | String outputFolder = Constant.getZapHome() + "faraday"; | |
521 | File folder = new File(outputFolder); | |
522 | if (!folder.exists()) { | |
523 | folder.mkdir(); | |
524 | } | |
525 | ||
526 | String filePath = outputFolder + File.separator + "default.properties"; | |
527 | output = new FileOutputStream(filePath); | |
528 | ||
529 | // set the properties value | |
530 | prop.setProperty("default", configuration.getUser()); | |
531 | ||
532 | // save properties to project root folder | |
533 | prop.store(output, null); | |
534 | ||
535 | } catch (IOException io) { | |
536 | JOptionPane.showMessageDialog( | |
537 | this, | |
538 | messages.getString("faraday.set.default.config.error"), | |
539 | messages.getString("faraday.config.dialog.title"), | |
540 | JOptionPane.ERROR_MESSAGE); | |
541 | io.printStackTrace(); | |
542 | } finally { | |
543 | if (output != null) { | |
544 | try { | |
545 | output.close(); | |
546 | } catch (IOException e) { | |
547 | e.printStackTrace(); | |
548 | } | |
549 | } | |
550 | ||
551 | } | |
552 | } | |
553 | ||
554 | ||
555 | private void removeDefaultConfig() { | |
556 | try { | |
557 | ||
558 | String filePath = Constant.getZapHome() + "faraday" + File.separator + "default.properties"; | |
559 | File file = new File(filePath); | |
560 | if (file.delete()) { | |
561 | System.out.println(file.getName() + " is deleted!"); | |
562 | } else { | |
563 | System.out.println("Delete operation is failed."); | |
564 | } | |
565 | ||
566 | } catch (Exception e) { | |
567 | ||
568 | e.printStackTrace(); | |
569 | ||
570 | } | |
571 | } | |
572 | ||
573 | ||
574 | private void refreshWorkspaces(boolean canShowAlert) { | |
575 | if (cmbWorkspaces != null) { | |
576 | configPanel.remove(cmbWorkspaces); | |
577 | configPanel.add(getWSComboBox()); | |
578 | if (canShowAlert) { | |
579 | JOptionPane.showMessageDialog( | |
580 | this, | |
581 | messages.getString("faraday.refresh.workspace.done"), | |
582 | messages.getString("faraday.config.dialog.title"), | |
583 | JOptionPane.INFORMATION_MESSAGE); | |
584 | } | |
585 | } | |
586 | } | |
587 | ||
588 | } |
0 | package org.zaproxy.zap.extension.faraday; | |
1 | ||
2 | import net.sf.json.JSONArray; | |
3 | import net.sf.json.JSONObject; | |
4 | import org.apache.commons.httpclient.URIException; | |
5 | import org.apache.commons.httpclient.methods.PostMethod; | |
6 | import org.apache.http.HttpEntity; | |
7 | import org.apache.http.HttpResponse; | |
8 | ||
9 | import org.apache.http.client.ClientProtocolException; | |
10 | import org.apache.http.client.HttpClient; | |
11 | import org.apache.http.entity.StringEntity; | |
12 | import org.apache.http.client.entity.UrlEncodedFormEntity; | |
13 | import org.apache.http.client.methods.HttpGet; | |
14 | import org.apache.http.client.methods.HttpPost; | |
15 | import org.apache.http.impl.client.HttpClients; | |
16 | import org.apache.http.NameValuePair; | |
17 | import org.apache.http.message.BasicNameValuePair; | |
18 | import org.apache.http.util.EntityUtils; | |
19 | import org.parosproxy.paros.Constant; | |
20 | import org.parosproxy.paros.core.scanner.Alert; | |
21 | import org.parosproxy.paros.model.HistoryReference; | |
22 | ||
23 | import java.io.*; | |
24 | import java.net.*; | |
25 | import java.nio.charset.StandardCharsets; | |
26 | import java.sql.Time; | |
27 | import java.time.Instant; | |
28 | import java.util.*; | |
29 | ||
30 | ||
31 | public class FaradayClient { | |
32 | ||
33 | private String baseUrl; | |
34 | private ResourceBundle messages = null; | |
35 | ||
36 | public FaradayClient(String baseUrl) { | |
37 | this.baseUrl = baseUrl; | |
38 | messages = ResourceBundle.getBundle( | |
39 | this.getClass().getPackage().getName() + | |
40 | ".Messages", Constant.getLocale()); | |
41 | ||
42 | } | |
43 | ||
44 | public boolean Login(String username, String password, String server) { | |
45 | Logout(); | |
46 | HttpClient httpClient = HttpClients.createDefault(); | |
47 | String LOGIN_URL = "_api/login"; | |
48 | HttpPost httpPost = new HttpPost(server + LOGIN_URL); | |
49 | ||
50 | // Request parameters and other properties. | |
51 | List<BasicNameValuePair> params = new ArrayList<>(2); | |
52 | params.add(new BasicNameValuePair("email", username)); | |
53 | params.add(new BasicNameValuePair("password", password)); | |
54 | ||
55 | try { | |
56 | httpPost.setEntity(new UrlEncodedFormEntity(params, "UTF-8")); | |
57 | HttpResponse response = httpClient.execute(httpPost); | |
58 | if (response.getFirstHeader("Set-Cookie") != null) { | |
59 | Configuration configuration = Configuration.getSingleton(); | |
60 | configuration.setSession(response.getFirstHeader("Set-Cookie").getValue()); | |
61 | configuration.setUser(username); | |
62 | configuration.setPassword(password); | |
63 | configuration.setServer(server); | |
64 | setBaseUrl(server); | |
65 | return true; | |
66 | } else if (response.getStatusLine().getStatusCode() == 302) { | |
67 | return true; | |
68 | } | |
69 | return false; | |
70 | } catch (UnsupportedEncodingException e) { | |
71 | // writing error to Log | |
72 | e.printStackTrace(); | |
73 | return false; | |
74 | } catch (ClientProtocolException e) { | |
75 | e.printStackTrace(); | |
76 | return false; | |
77 | } catch (IOException e) { | |
78 | e.printStackTrace(); | |
79 | return false; | |
80 | } | |
81 | ||
82 | } | |
83 | ||
84 | public boolean Logout() { | |
85 | String LOGOUT_URL = "_api/logout"; | |
86 | HttpGet httpGet = new HttpGet(this.baseUrl + LOGOUT_URL); | |
87 | Configuration configuration = Configuration.getSingleton(); | |
88 | ||
89 | if (!Objects.equals(configuration.getSession(), "")) { | |
90 | httpGet.setHeader("Cookie", configuration.getSession()); | |
91 | ||
92 | //Execute and get the response. | |
93 | HttpResponse response = null; | |
94 | ||
95 | try { | |
96 | HttpClient httpClient = HttpClients.createDefault(); | |
97 | response = httpClient.execute(httpGet); | |
98 | HttpEntity entity = response.getEntity(); | |
99 | if (response.getStatusLine().getStatusCode() == 200) { | |
100 | configuration.setSession(""); | |
101 | configuration.setUser(""); | |
102 | configuration.setPassword(""); | |
103 | return true; | |
104 | } | |
105 | return false; | |
106 | } catch (IOException e) { | |
107 | e.printStackTrace(); | |
108 | return false; | |
109 | } | |
110 | } | |
111 | return true; | |
112 | } | |
113 | ||
114 | public ArrayList<String> GetWorkspaces() { | |
115 | ArrayList<String> workspaces = new ArrayList<>(); | |
116 | String WORKSPACES_URL = "_api/v2/ws/"; | |
117 | HttpGet httpGet = new HttpGet(this.baseUrl + WORKSPACES_URL); | |
118 | Configuration configuration = Configuration.getSingleton(); | |
119 | ||
120 | if (configuration.getSession() != "") { | |
121 | httpGet.setHeader("Cookie", configuration.getSession()); | |
122 | ||
123 | //Execute and get the response. | |
124 | HttpResponse response = null; | |
125 | InputStream instream = null; | |
126 | try { | |
127 | HttpClient httpClient = HttpClients.createDefault(); | |
128 | response = httpClient.execute(httpGet); | |
129 | HttpEntity entity = response.getEntity(); | |
130 | ||
131 | if (entity != null && response.getStatusLine().getStatusCode() == 200) { | |
132 | instream = entity.getContent(); | |
133 | ||
134 | BufferedReader br = new BufferedReader(new InputStreamReader(instream)); | |
135 | String output; | |
136 | JSONArray jsonArray = new JSONArray(); | |
137 | while ((output = br.readLine()) != null) { | |
138 | System.out.println(output); | |
139 | jsonArray = JSONArray.fromObject(output); | |
140 | } | |
141 | ||
142 | for (int i = 0; i < jsonArray.size(); i++) { | |
143 | JSONObject jsonObject = jsonArray.getJSONObject(i); | |
144 | workspaces.add(jsonObject.get("name").toString()); | |
145 | } | |
146 | } | |
147 | } catch (IOException e) { | |
148 | e.printStackTrace(); | |
149 | } finally { | |
150 | try { | |
151 | instream.close(); | |
152 | } catch (IOException e) { | |
153 | e.printStackTrace(); | |
154 | } | |
155 | } | |
156 | } | |
157 | ||
158 | return workspaces; | |
159 | } | |
160 | ||
161 | ||
162 | private int AddCommand(String commandName, String workspace, String session) { | |
163 | String COMMAND_URL = "_api/v2/ws/" + workspace + "/commands/"; | |
164 | HttpClient httpClient = HttpClients.createDefault(); | |
165 | HttpPost httpPost = new HttpPost(this.baseUrl + COMMAND_URL); | |
166 | ||
167 | try { | |
168 | StringEntity stringEntity = new StringEntity(ConvertCommandToParams(commandName).toString()); | |
169 | httpPost.setHeader("Cookie", session); | |
170 | httpPost.setHeader("Content-Type", "application/json"); | |
171 | httpPost.setEntity(stringEntity); | |
172 | HttpResponse response = httpClient.execute(httpPost); | |
173 | HttpEntity entity = response.getEntity(); | |
174 | ||
175 | if (response.getStatusLine().getStatusCode() == 200 || response.getStatusLine().getStatusCode() == 201 || response.getStatusLine().getStatusCode() == 409) { | |
176 | BufferedReader br = new BufferedReader(new InputStreamReader(entity.getContent())); | |
177 | String output; | |
178 | JSONObject json; | |
179 | String commandStr = "-1"; | |
180 | while ((output = br.readLine()) != null) { | |
181 | json = JSONObject.fromObject(output); | |
182 | if (response.getStatusLine().getStatusCode() == 409) { | |
183 | JSONObject jsonObject = JSONObject.fromObject(json.get("object")); | |
184 | commandStr = jsonObject.get("_id").toString(); | |
185 | } else { | |
186 | commandStr = json.get("_id").toString(); | |
187 | } | |
188 | } | |
189 | return Integer.parseInt(commandStr); | |
190 | } | |
191 | return -1; | |
192 | } catch (UnsupportedEncodingException e) { | |
193 | // writing error to Log | |
194 | e.printStackTrace(); | |
195 | return -1; | |
196 | } catch (ClientProtocolException e) { | |
197 | e.printStackTrace(); | |
198 | return -1; | |
199 | } catch (IOException e) { | |
200 | e.printStackTrace(); | |
201 | return -1; | |
202 | } | |
203 | } | |
204 | ||
205 | private int AddHost(Alert alert, String workspace, String session) { | |
206 | String VULN_URL = "_api/v2/ws/" + workspace + "/hosts/"; | |
207 | HttpClient httpClient = HttpClients.createDefault(); | |
208 | HttpPost httpPost = new HttpPost(this.baseUrl + VULN_URL); | |
209 | ||
210 | try { | |
211 | StringEntity stringEntity = new StringEntity(ConvertHostToParams(alert).toString()); | |
212 | httpPost.setHeader("Cookie", session); | |
213 | httpPost.setHeader("Content-Type", "application/json"); | |
214 | httpPost.setEntity(stringEntity); | |
215 | HttpResponse response = httpClient.execute(httpPost); | |
216 | HttpEntity entity = response.getEntity(); | |
217 | ||
218 | if (response.getStatusLine().getStatusCode() == 200 || response.getStatusLine().getStatusCode() == 201 || response.getStatusLine().getStatusCode() == 409) { | |
219 | BufferedReader br = new BufferedReader(new InputStreamReader(entity.getContent())); | |
220 | String output; | |
221 | JSONObject json; | |
222 | String hostStr = "-1"; | |
223 | while ((output = br.readLine()) != null) { | |
224 | json = JSONObject.fromObject(output); | |
225 | if (response.getStatusLine().getStatusCode() == 409) { | |
226 | JSONObject jsonObject = JSONObject.fromObject(json.get("object")); | |
227 | hostStr = jsonObject.get("id").toString(); | |
228 | } else { | |
229 | hostStr = json.get("id").toString(); | |
230 | } | |
231 | } | |
232 | return Integer.parseInt(hostStr); | |
233 | } | |
234 | return -1; | |
235 | } catch (UnsupportedEncodingException e) { | |
236 | // writing error to Log | |
237 | e.printStackTrace(); | |
238 | return -1; | |
239 | } catch (ClientProtocolException e) { | |
240 | e.printStackTrace(); | |
241 | return -1; | |
242 | } catch (IOException e) { | |
243 | e.printStackTrace(); | |
244 | return -1; | |
245 | } | |
246 | } | |
247 | ||
248 | private int AddService(Alert alert, String workspace, String session, int hostId) { | |
249 | String VULN_URL = "_api/v2/ws/" + workspace + "/services/"; | |
250 | HttpClient httpClient = HttpClients.createDefault(); | |
251 | HttpPost httpPost = new HttpPost(this.baseUrl + VULN_URL); | |
252 | ||
253 | try { | |
254 | StringEntity stringEntity = new StringEntity(ConvertServiceToParams(alert, hostId).toString()); | |
255 | httpPost.setHeader("Cookie", session); | |
256 | httpPost.setHeader("Content-Type", "application/json"); | |
257 | httpPost.setEntity(stringEntity); | |
258 | HttpResponse response = httpClient.execute(httpPost); | |
259 | HttpEntity entity = response.getEntity(); | |
260 | ||
261 | BufferedReader br = new BufferedReader(new InputStreamReader(entity.getContent())); | |
262 | String output; | |
263 | if (response.getStatusLine().getStatusCode() == 200 || response.getStatusLine().getStatusCode() == 201 || response.getStatusLine().getStatusCode() == 409) { | |
264 | JSONObject json; | |
265 | String serviceStr = "-1"; | |
266 | while ((output = br.readLine()) != null) { | |
267 | json = JSONObject.fromObject(output); | |
268 | if (response.getStatusLine().getStatusCode() == 409) { | |
269 | JSONObject jsonObject = JSONObject.fromObject(json.get("object")); | |
270 | serviceStr = jsonObject.get("id").toString(); | |
271 | } else { | |
272 | serviceStr = json.get("id").toString(); | |
273 | } | |
274 | } | |
275 | return Integer.parseInt(serviceStr); | |
276 | } else { | |
277 | while ((output = br.readLine()) != null) { | |
278 | System.out.println(output); | |
279 | } | |
280 | ||
281 | return -1; | |
282 | } | |
283 | ||
284 | } catch (UnsupportedEncodingException e) { | |
285 | // writing error to Log | |
286 | e.printStackTrace(); | |
287 | return -1; | |
288 | } catch (ClientProtocolException e) { | |
289 | e.printStackTrace(); | |
290 | return -1; | |
291 | } catch (IOException e) { | |
292 | e.printStackTrace(); | |
293 | return -1; | |
294 | } | |
295 | } | |
296 | ||
297 | public int AddVulnerability(Alert alert, String workspace, String session) { | |
298 | int hostId = AddHost(alert, workspace, session); | |
299 | if (hostId == -1) { | |
300 | return 500; | |
301 | } | |
302 | ||
303 | String parentType = "Service"; | |
304 | int serviceId = AddService(alert, workspace, session, hostId); | |
305 | if (serviceId == -1) { | |
306 | return 500; | |
307 | } | |
308 | ||
309 | ||
310 | String commandName = messages.getString("faraday.tool.command.name"); | |
311 | int commandId = AddCommand(commandName, workspace, session); | |
312 | if (commandId == -1) { | |
313 | return 500; | |
314 | } | |
315 | ||
316 | ||
317 | String VULN_URL = "_api/v2/ws/" + workspace + "/vulns/?command_id=" + commandId; | |
318 | HttpClient httpClient = HttpClients.createDefault(); | |
319 | HttpPost httpPost = new HttpPost(this.baseUrl + VULN_URL); | |
320 | try { | |
321 | ||
322 | StringEntity stringEntity = new StringEntity(ConvertAlertToParams(alert, workspace, parentType, serviceId).toString()); | |
323 | httpPost.setHeader("Cookie", session); | |
324 | httpPost.setHeader("Content-Type", "application/json"); | |
325 | httpPost.setEntity(stringEntity); | |
326 | HttpResponse response = httpClient.execute(httpPost); | |
327 | return response.getStatusLine().getStatusCode(); | |
328 | ||
329 | } catch (UnsupportedEncodingException e) { | |
330 | // writing error to Log | |
331 | e.printStackTrace(); | |
332 | return 402; | |
333 | } catch (ClientProtocolException e) { | |
334 | e.printStackTrace(); | |
335 | return 402; | |
336 | } catch (IOException e) { | |
337 | e.printStackTrace(); | |
338 | return 402; | |
339 | } | |
340 | } | |
341 | ||
342 | private JSONObject ConvertAlertToParams(Alert alert, String workspace, String parentType, int parentId) { | |
343 | // Request parameters and other properties. | |
344 | JSONObject params = new JSONObject(); | |
345 | ||
346 | params.put("name", alert.getName()); | |
347 | params.put("ws", workspace); | |
348 | params.put("request", alert.getMessage().getRequestHeader().toString()); | |
349 | params.put("response", alert.getMessage().getResponseHeader().toString()); | |
350 | String desc = !alert.getParam().equals("") ? alert.getDescription() + "\nWith parameter: '" + alert.getParam() + "'" : | |
351 | alert.getDescription(); | |
352 | params.put("desc", desc); | |
353 | params.put("resolution", alert.getSolution()); | |
354 | params.put("type", "VulnerabilityWeb"); | |
355 | params.put("data", alert.getPostData()); | |
356 | params.put("policyviolations", "[]"); | |
357 | params.put("parent_type", parentType); | |
358 | params.put("parent", parentId); | |
359 | params.put("params", alert.getParam()); | |
360 | ||
361 | JSONObject metadata = new JSONObject(); | |
362 | metadata.put("creator", "OWASP"); | |
363 | params.put("metadata", metadata); | |
364 | ||
365 | String hostname = alert.getMessage().getRequestHeader().getHostName(); | |
366 | String IpAddres = GetIPFromHostname(hostname); | |
367 | JSONArray hostNamesArray = new JSONArray(); | |
368 | hostNamesArray.add(hostname); | |
369 | hostNamesArray.add(IpAddres); | |
370 | params.put("hostnames", hostNamesArray); | |
371 | params.put("target", IpAddres); | |
372 | params.put("website", hostname); | |
373 | ||
374 | JSONArray refsJsonArray = new JSONArray(); | |
375 | String[] resfArray = alert.getReference().split("\n"); | |
376 | Collections.addAll(refsJsonArray, resfArray); | |
377 | params.put("refs", refsJsonArray); | |
378 | ||
379 | try { | |
380 | params.put("path", alert.getMsgUri().getPath()); | |
381 | } catch (URIException e) { | |
382 | e.printStackTrace(); | |
383 | } | |
384 | ||
385 | if (alert.getConfidence() == 4) { | |
386 | params.put("confirmed", true); | |
387 | } | |
388 | ||
389 | switch (alert.getRisk()) { | |
390 | case 0: | |
391 | params.put("severity", "informational"); | |
392 | break; | |
393 | case 1: | |
394 | params.put("severity", "low"); | |
395 | break; | |
396 | case 2: | |
397 | params.put("severity", "medium"); | |
398 | break; | |
399 | case 3: | |
400 | params.put("severity", "high"); | |
401 | break; | |
402 | } | |
403 | return params; | |
404 | ||
405 | } | |
406 | ||
407 | private JSONObject ConvertHostToParams(Alert alert) { | |
408 | // Request parameters and other properties. | |
409 | JSONObject params = new JSONObject(); | |
410 | ||
411 | try { | |
412 | String ipAddress = GetIPFromHostname(alert.getMsgUri().getHost()); | |
413 | params.put("ip", ipAddress); | |
414 | params.put("name", alert.getMsgUri().getName()); | |
415 | params.put("os", "Unknown"); | |
416 | params.put("description", ""); | |
417 | JSONObject metadata = new JSONObject(); | |
418 | metadata.put("creator", "Zap"); | |
419 | params.put("metadata", metadata); | |
420 | ||
421 | String hostname = alert.getMessage().getRequestHeader().getHostName(); | |
422 | JSONArray hostNamesArray = new JSONArray(); | |
423 | hostNamesArray.add(hostname); | |
424 | params.put("hostnames", hostNamesArray); | |
425 | ||
426 | } catch (URIException e) { | |
427 | e.printStackTrace(); | |
428 | } | |
429 | return params; | |
430 | } | |
431 | ||
432 | private JSONObject ConvertServiceToParams(Alert alert, int parentId) { | |
433 | // Request parameters and other properties. | |
434 | JSONObject params = new JSONObject(); | |
435 | JSONArray portsJson = new JSONArray(); | |
436 | portsJson.add(alert.getMessage().getRequestHeader().getHostPort()); | |
437 | params.put("ports", portsJson); | |
438 | params.put("parent", parentId); | |
439 | params.put("status", "open"); | |
440 | params.put("type", "Service"); | |
441 | params.put("description", ""); | |
442 | JSONObject metadata = new JSONObject(); | |
443 | metadata.put("creator", "OWASP"); | |
444 | params.put("metadata", metadata); | |
445 | ||
446 | switch (alert.getMessage().getRequestHeader().getHostPort()) { | |
447 | case 21: | |
448 | params.put("name", "FTP"); | |
449 | params.put("protocol", "tcp"); | |
450 | break; | |
451 | case 22: | |
452 | params.put("name", "SSH"); | |
453 | params.put("protocol", "tcp"); | |
454 | break; | |
455 | case 23: | |
456 | params.put("name", "TELNET"); | |
457 | params.put("protocol", "tcp"); | |
458 | break; | |
459 | case 25: | |
460 | params.put("name", "SMTP"); | |
461 | params.put("protocol", "tcp"); | |
462 | break; | |
463 | case 80: | |
464 | params.put("name", "HTTP"); | |
465 | params.put("protocol", "tcp"); | |
466 | break; | |
467 | case 110: | |
468 | params.put("name", "POP"); | |
469 | params.put("protocol", "tcp"); | |
470 | break; | |
471 | case 443: | |
472 | params.put("name", "SSL"); | |
473 | params.put("protocol", "tcp"); | |
474 | break; | |
475 | default: | |
476 | params.put("name", "unknown"); | |
477 | params.put("protocol", "unknown"); | |
478 | break; | |
479 | } | |
480 | ||
481 | return params; | |
482 | } | |
483 | ||
484 | private JSONObject ConvertCommandToParams(String commandName) { | |
485 | // Request parameters and other properties. | |
486 | JSONObject params = new JSONObject(); | |
487 | params.put("itime", Instant.EPOCH.getEpochSecond()); | |
488 | params.put("import_source", "shell"); | |
489 | params.put("duration", ""); | |
490 | params.put("command", "Zap"); | |
491 | params.put("tool", commandName); | |
492 | return params; | |
493 | } | |
494 | ||
495 | private String GetIPFromHostname(String hostname) { | |
496 | try { | |
497 | InetAddress inetAddr = InetAddress.getByName(hostname); | |
498 | byte[] addr = inetAddr.getAddress(); | |
499 | ||
500 | // Convert to dot representation | |
501 | String ipAddr = ""; | |
502 | for (int i = 0; i < addr.length; i++) { | |
503 | if (i > 0) { | |
504 | ipAddr += "."; | |
505 | } | |
506 | ||
507 | ipAddr += addr[i] & 0xFF; | |
508 | } | |
509 | ||
510 | System.out.println("IP Address: " + ipAddr); | |
511 | return ipAddr; | |
512 | } catch (UnknownHostException e) { | |
513 | System.out.println("Host not found: " + e.getMessage()); | |
514 | return ""; | |
515 | } | |
516 | } | |
517 | ||
518 | public void setBaseUrl(String baseUrl) { | |
519 | this.baseUrl = baseUrl; | |
520 | } | |
521 | } | |
522 | ||
523 | ||
524 |
0 | /* | |
1 | * Zed Attack Proxy (ZAP) and its related class files. | |
2 | * | |
3 | * ZAP is an HTTP/HTTPS proxy for assessing web application security. | |
4 | * | |
5 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
6 | * you may not use this file except in compliance with the License. | |
7 | * You may obtain a copy of the License at | |
8 | * | |
9 | * http://www.apache.org/licenses/LICENSE-2.0 | |
10 | * | |
11 | * Unless required by applicable law or agreed to in writing, software | |
12 | * distributed under the License is distributed on an "AS IS" BASIS, | |
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
14 | * See the License for the specific language governing permissions and | |
15 | * limitations under the License. | |
16 | */ | |
17 | package org.zaproxy.zap.extension.faraday; | |
18 | ||
19 | import org.apache.log4j.Logger; | |
20 | import org.parosproxy.paros.Constant; | |
21 | import org.parosproxy.paros.control.Control; | |
22 | import org.parosproxy.paros.extension.ExtensionAdaptor; | |
23 | import org.parosproxy.paros.extension.ExtensionHook; | |
24 | import org.parosproxy.paros.extension.ExtensionPopupMenuItem; | |
25 | import org.zaproxy.zap.view.ZapMenuItem; | |
26 | ||
27 | import javax.swing.*; | |
28 | import java.awt.*; | |
29 | import java.awt.event.KeyEvent; | |
30 | import java.io.*; | |
31 | import java.util.Properties; | |
32 | import java.util.ResourceBundle; | |
33 | ||
34 | public class FaradayExtension extends ExtensionAdaptor { | |
35 | private static final Logger logger = Logger.getLogger(FaradayExtension.class); | |
36 | private ZapMenuItem menuItemFaradayConfig; | |
37 | private ConfigurationDialog configurationDialog; | |
38 | private PopupMenuItemSendAlert popupMenuItemSendAlert; | |
39 | private PopupMenuItemSendRequest popupMenuItemSendRequest; | |
40 | private ResourceBundle messages = null; | |
41 | ||
42 | ||
43 | ||
44 | public FaradayExtension(String name) { | |
45 | super(name); | |
46 | } | |
47 | ||
48 | ||
49 | public FaradayExtension() { | |
50 | super(); | |
51 | initialize(); | |
52 | } | |
53 | ||
54 | ||
55 | private void initialize() { | |
56 | messages = ResourceBundle.getBundle( | |
57 | this.getClass().getPackage().getName() + | |
58 | ".Messages", Constant.getLocale()); | |
59 | this.setName(messages.getString("faraday.extension.name")); | |
60 | this.initConfiguration(); | |
61 | } | |
62 | ||
63 | @Override | |
64 | public String getAuthor() { | |
65 | return messages.getString("faraday.extension.author"); | |
66 | } | |
67 | ||
68 | @Override | |
69 | public void hook(ExtensionHook extensionHook) { | |
70 | super.hook(extensionHook); | |
71 | ||
72 | if (getView() != null) { | |
73 | extensionHook.getHookMenu().addToolsMenuItem(getMenuItemFaradayConfig()); | |
74 | extensionHook.getHookMenu().addPopupMenuItem(this.getPopupMenuItem()); | |
75 | extensionHook.getHookMenu().addPopupMenuItem(this.getPopupMenuItemRequest()); | |
76 | } | |
77 | } | |
78 | ||
79 | @Override | |
80 | public boolean canUnload() { | |
81 | return true; | |
82 | } | |
83 | ||
84 | private ZapMenuItem getMenuItemFaradayConfig() { | |
85 | if (menuItemFaradayConfig == null) { | |
86 | menuItemFaradayConfig = new ZapMenuItem( | |
87 | "faraday.menu.tools.label", | |
88 | KeyStroke.getKeyStroke( | |
89 | KeyEvent.VK_F, | |
90 | Toolkit.getDefaultToolkit().getMenuShortcutKeyMask() | KeyEvent.ALT_DOWN_MASK, | |
91 | false)); | |
92 | menuItemFaradayConfig.setEnabled(Control.getSingleton().getMode() != Control.Mode.safe); | |
93 | ||
94 | menuItemFaradayConfig.addActionListener(new java.awt.event.ActionListener() { | |
95 | ||
96 | @Override | |
97 | public void actionPerformed(java.awt.event.ActionEvent e) { | |
98 | showConfigurationDialog(); | |
99 | } | |
100 | }); | |
101 | } | |
102 | return menuItemFaradayConfig; | |
103 | } | |
104 | ||
105 | ||
106 | private void showConfigurationDialog() { | |
107 | if (configurationDialog == null) { | |
108 | configurationDialog = new ConfigurationDialog(messages.getString("faraday.config.dialog.title")); | |
109 | configurationDialog.init(); | |
110 | } | |
111 | configurationDialog.setVisible(true); | |
112 | } | |
113 | ||
114 | ||
115 | private ExtensionPopupMenuItem getPopupMenuItem() { | |
116 | if (popupMenuItemSendAlert == null) { | |
117 | popupMenuItemSendAlert = new PopupMenuItemSendAlert(messages.getString("faraday.button.send.alert")); | |
118 | } | |
119 | ||
120 | return popupMenuItemSendAlert; | |
121 | ||
122 | } | |
123 | ||
124 | ||
125 | private ExtensionPopupMenuItem getPopupMenuItemRequest() { | |
126 | if (popupMenuItemSendRequest == null) { | |
127 | popupMenuItemSendRequest = new PopupMenuItemSendRequest(messages.getString("faraday.button.send.request")); | |
128 | } | |
129 | ||
130 | return popupMenuItemSendRequest; | |
131 | ||
132 | } | |
133 | ||
134 | ||
135 | private void initConfiguration() { | |
136 | Configuration configuration = Configuration.getSingleton(); | |
137 | ||
138 | Properties prop = new Properties(); | |
139 | InputStream input = null; | |
140 | ||
141 | try { | |
142 | String filePath = Constant.getZapHome() + "faraday" + File.separator + "default.properties"; | |
143 | input = new FileInputStream(filePath); | |
144 | ||
145 | // load a properties file | |
146 | prop.load(input); | |
147 | ||
148 | // set the properties value | |
149 | String fUser = prop.getProperty("default"); | |
150 | configuration.restore(fUser); | |
151 | ||
152 | } catch (IOException io) { | |
153 | System.out.println("We can't found default.properties file"); | |
154 | } finally { | |
155 | if (input != null) { | |
156 | try { | |
157 | input.close(); | |
158 | } catch (IOException e) { | |
159 | e.printStackTrace(); | |
160 | } | |
161 | } | |
162 | ||
163 | } | |
164 | } | |
165 | ||
166 | } |
0 | # An example ZAP extension which adds a top level menu item. | |
1 | # | |
2 | # This file defines the default (English) variants of all of the | |
3 | ||
4 | faraday.extension.name = Faraday Extension | |
5 | faraday.extension.author = Jorge Luis Gonzàlez Iznaga | |
6 | ||
7 | faraday.menu.tools.label = Faraday configuration options | |
8 | faraday.config.dialog.title = Faraday configuration | |
9 | faraday.config.dialog.tabs.auth = Authorization | |
10 | faraday.config.dialog.tabs.conf = Configuration | |
11 | faraday.config.dialog.auth.user = Faraday user | |
12 | faraday.config.dialog.auth.pass = Faraday password | |
13 | faraday.config.dialog.server = Faraday server | |
14 | faraday.config.dialog.auth.login = Login | |
15 | faraday.config.dialog.auth.logout = Logout | |
16 | faraday.config.dialog.import.current = Import current vulnerabilities | |
17 | faraday.config.dialog.import.new = Import new vulnerabilities | |
18 | faraday.config.dialog.restore = Restore configuration | |
19 | faraday.config.dialog.refresh = Refresh | |
20 | faraday.config.dialog.save = Save configuration | |
21 | faraday.config.dialog.workspace = Select faraday workspace | |
22 | faraday.config.dialog.default = Set this configuration as default | |
23 | ||
24 | faraday.config.dialog.tab.auth = Authorization | |
25 | faraday.config.dialog.tab.conf = Configuration | |
26 | ||
27 | faraday.dialog.enter.user = Please enter your user | |
28 | ||
29 | ||
30 | faraday.button.send.alert = Send alert to Faraday | |
31 | faraday.button.send.request = Send request to Faraday | |
32 | ||
33 | faraday.message.invalid.check.credentials = Please, check your credentials | |
34 | faraday.message.invalid.credentials = Invalid credentials | |
35 | faraday.dialog.login.title = Faraday login | |
36 | faraday.dialog.logout.title = Faraday logout | |
37 | faraday.dialog.logout.success = You're logout successfully ! | |
38 | faraday.dialog.logout.error = We can't complete logout operation | |
39 | ||
40 | faraday.dialog.button.close = Close | |
41 | ||
42 | faraday.save.config.success = Configuration saved successfully | |
43 | faraday.save.config.error = We can't save your configuration, please check home ZAP directory | |
44 | faraday.restore.config.error = You haven't a configuration saved with this user | |
45 | faraday.refresh.workspace.done = Your workspaces are up to date | |
46 | faraday.restore.config.error.login = Unable to restore this configuration | |
47 | faraday.set.default.config.error = We can't set your configuration | |
48 | ||
49 | faraday.send.alert.permissions.error = You should check your current workspace and your permissions | |
50 | faraday.send.alert.conflict = This alert already exists in Faraday | |
51 | faraday.send.request.conflict = This request already exists in Faraday | |
52 | faraday.send.alert.success = Alert added successfully | |
53 | faraday.send.request.success = Request added successfully | |
54 | ||
55 | faraday.tool.command.name = OWASP⏎ |
0 | package org.zaproxy.zap.extension.faraday; | |
1 | ||
2 | import org.apache.log4j.Logger; | |
3 | import org.parosproxy.paros.Constant; | |
4 | import org.parosproxy.paros.core.scanner.Alert; | |
5 | import org.parosproxy.paros.view.View; | |
6 | import org.zaproxy.zap.extension.alert.AlertNode; | |
7 | import org.zaproxy.zap.extension.alert.PopupMenuItemAlert; | |
8 | ||
9 | import javax.swing.*; | |
10 | import java.awt.*; | |
11 | import java.util.ResourceBundle; | |
12 | ||
13 | public class PopupMenuItemSendAlert extends PopupMenuItemAlert { | |
14 | private static final Logger logger = Logger.getLogger(PopupMenuItemSendAlert.class); | |
15 | private FaradayClient faradayClient; | |
16 | private ResourceBundle messages = null; | |
17 | private int selectionCount = 0; | |
18 | private int totalSelectionCount = 0; | |
19 | private boolean treeAlertParentSelected = false; | |
20 | ||
21 | public PopupMenuItemSendAlert(String label) { | |
22 | super(label, true); | |
23 | Configuration configuration = Configuration.getSingleton(); | |
24 | faradayClient = new FaradayClient(configuration.getServer()); | |
25 | messages = ResourceBundle.getBundle( | |
26 | this.getClass().getPackage().getName() + | |
27 | ".Messages", Constant.getLocale()); | |
28 | } | |
29 | ||
30 | @Override | |
31 | protected void performAction(Alert alert) { | |
32 | Configuration configuration = Configuration.getSingleton(); | |
33 | String workspace = configuration.getWorkspace(); | |
34 | String session = configuration.getSession(); | |
35 | if (workspace != null && session != null && !workspace.equals("") && !session.equals("")) { | |
36 | int responseCode = faradayClient.AddVulnerability(alert, configuration.getWorkspace(), session); | |
37 | String message; | |
38 | int iconMessage = 1; | |
39 | switch (responseCode) { | |
40 | case 200: | |
41 | case 201: | |
42 | case 409: | |
43 | message = messages.getString("faraday.send.alert.success"); | |
44 | break; | |
45 | case 403: | |
46 | message = messages.getString("faraday.send.alert.permissions.error"); | |
47 | iconMessage = JOptionPane.WARNING_MESSAGE; | |
48 | break; | |
49 | // case 409: | |
50 | // message = messages.getString("faraday.send.alert.conflict"); | |
51 | // iconMessage = JOptionPane.WARNING_MESSAGE; | |
52 | // break; | |
53 | case 400: | |
54 | case 500: | |
55 | message = "Unable to send " + alert.getName() + " to Faraday"; | |
56 | iconMessage = JOptionPane.ERROR_MESSAGE; | |
57 | break; | |
58 | ||
59 | default: | |
60 | message = "Unable to send " + alert.getName() + " to Faraday"; | |
61 | iconMessage = JOptionPane.ERROR_MESSAGE; | |
62 | break; | |
63 | } | |
64 | ||
65 | if (canShowMessageDialog()/*this.selectionCount == 1 && !treeAlertParentSelected*/) { | |
66 | JOptionPane.showMessageDialog( | |
67 | this, | |
68 | message, | |
69 | messages.getString("faraday.button.send.alert"), | |
70 | iconMessage); | |
71 | } | |
72 | ||
73 | ||
74 | logger.error(message); | |
75 | if (View.isInitialised()) { | |
76 | // Report info to the Output tab | |
77 | View.getSingleton().getOutputPanel().append(message + "\n"); | |
78 | } | |
79 | ||
80 | ||
81 | } else { | |
82 | if (canShowMessageDialog()) { | |
83 | JOptionPane.showMessageDialog( | |
84 | this, | |
85 | messages.getString("faraday.send.alert.permissions.error"), | |
86 | messages.getString("faraday.button.send.alert"), | |
87 | JOptionPane.ERROR_MESSAGE); | |
88 | logger.error(messages.getString("faraday.send.alert.permissions.error")); | |
89 | } | |
90 | ||
91 | ||
92 | if (View.isInitialised()) { | |
93 | // Report info to the Output tab | |
94 | View.getSingleton().getOutputPanel().append(messages.getString("faraday.send.alert.permissions.error") + "\n"); | |
95 | } | |
96 | } | |
97 | ||
98 | } | |
99 | ||
100 | @Override | |
101 | public boolean isEnableForComponent(Component invoker) { | |
102 | logger.info(invoker.getName()); | |
103 | this.totalSelectionCount = 0; | |
104 | try { | |
105 | if (Configuration.getSingleton().getSession() == null || Configuration.getSingleton().getSession().equals("")) { | |
106 | return false; | |
107 | } | |
108 | treeAlertParentSelected = ((JTree) invoker).isRowSelected(0); | |
109 | if (super.isEnableForComponent(invoker) || treeAlertParentSelected) { | |
110 | this.selectionCount = ((JTree) invoker).getSelectionCount(); | |
111 | for (int i = 0; i < ((JTree) invoker).getSelectionPaths().length; i++) { | |
112 | AlertNode nodeTemp = (AlertNode) ((JTree) invoker).getSelectionPaths()[i].getLastPathComponent(); | |
113 | this.totalSelectionCount += getTotalAlertsToProcess(nodeTemp); | |
114 | } | |
115 | ||
116 | setEnabled(true); | |
117 | return true; | |
118 | } | |
119 | return false; | |
120 | } catch (Exception e) { | |
121 | return false; | |
122 | } | |
123 | } | |
124 | ||
125 | ||
126 | private int getTotalAlertsToProcess(AlertNode node) { | |
127 | if (node.getChildCount() > 0) { | |
128 | int total = 0; | |
129 | for (int i = 0; i < node.getChildCount(); i++) { | |
130 | total += getTotalAlertsToProcess(node.getChildAt(i)); | |
131 | } | |
132 | return total; | |
133 | } else { | |
134 | return 1; | |
135 | } | |
136 | ||
137 | } | |
138 | ||
139 | private boolean canShowMessageDialog() { | |
140 | this.totalSelectionCount--; | |
141 | if (this.treeAlertParentSelected) { | |
142 | this.totalSelectionCount = 1; | |
143 | this.treeAlertParentSelected = false; | |
144 | } | |
145 | ||
146 | return this.totalSelectionCount == 0; | |
147 | } | |
148 | } |
0 | package org.zaproxy.zap.extension.faraday; | |
1 | ||
2 | import org.apache.log4j.Logger; | |
3 | import org.parosproxy.paros.Constant; | |
4 | import org.parosproxy.paros.core.scanner.Alert; | |
5 | import org.parosproxy.paros.db.DatabaseException; | |
6 | import org.parosproxy.paros.db.RecordAlert; | |
7 | import org.parosproxy.paros.model.HistoryReference; | |
8 | import org.parosproxy.paros.network.HttpMalformedHeaderException; | |
9 | import org.parosproxy.paros.view.View; | |
10 | import org.zaproxy.zap.extension.alert.PopupMenuAlert; | |
11 | import org.zaproxy.zap.view.messagecontainer.http.HttpMessageContainer; | |
12 | import org.zaproxy.zap.view.popup.PopupMenuItemHistoryReferenceContainer; | |
13 | ||
14 | import javax.swing.*; | |
15 | import java.awt.*; | |
16 | import java.util.Iterator; | |
17 | import java.util.List; | |
18 | import java.util.ResourceBundle; | |
19 | ||
20 | ||
21 | public class PopupMenuItemSendRequest extends PopupMenuItemHistoryReferenceContainer { | |
22 | private FaradayClient faradayClient; | |
23 | private ResourceBundle messages = null; | |
24 | private int selectionCount = 0; | |
25 | private static final Logger logger = Logger.getLogger(PopupMenuItemSendRequest.class); | |
26 | ||
27 | ||
28 | public PopupMenuItemSendRequest(String label) { | |
29 | super(label, true); | |
30 | Configuration configuration = Configuration.getSingleton(); | |
31 | faradayClient = new FaradayClient(configuration.getServer()); | |
32 | messages = ResourceBundle.getBundle( | |
33 | this.getClass().getPackage().getName() + | |
34 | ".Messages", Constant.getLocale()); | |
35 | } | |
36 | ||
37 | @Override | |
38 | public void performAction(HistoryReference href) { | |
39 | try { | |
40 | Alert alert = new Alert(new RecordAlert(), href); | |
41 | alert.setName(href.getSiteNode().getName()); | |
42 | alert.setUri(href.getURI().toString()); | |
43 | alert.setMessage(href.getHttpMessage()); | |
44 | alert.setDescription(""); | |
45 | alert.setRiskConfidence(0, 0); | |
46 | ||
47 | Configuration configuration = Configuration.getSingleton(); | |
48 | String workspace = configuration.getWorkspace(); | |
49 | String session = configuration.getSession(); | |
50 | if (workspace != null && session != null && !workspace.equals("") && !session.equals("")) { | |
51 | int responseCode = faradayClient.AddVulnerability(alert, configuration.getWorkspace(), session); | |
52 | String message = ""; | |
53 | int iconMessage = 1; | |
54 | switch (responseCode) { | |
55 | case 403: | |
56 | message = messages.getString("faraday.send.alert.permissions.error"); | |
57 | iconMessage = JOptionPane.WARNING_MESSAGE; | |
58 | break; | |
59 | case 409: | |
60 | message = messages.getString("faraday.send.request.conflict"); | |
61 | iconMessage = JOptionPane.WARNING_MESSAGE; | |
62 | break; | |
63 | case 500: | |
64 | message = "Unable to send " + alert.getName() + " to Faraday"; | |
65 | iconMessage = JOptionPane.ERROR_MESSAGE; | |
66 | break; | |
67 | case 201: | |
68 | message = messages.getString("faraday.send.request.success"); | |
69 | break; | |
70 | } | |
71 | ||
72 | if (this.selectionCount == 1) { | |
73 | JOptionPane.showMessageDialog( | |
74 | this, | |
75 | message, | |
76 | messages.getString("faraday.button.send.alert"), | |
77 | iconMessage); | |
78 | } | |
79 | ||
80 | logger.error(message); | |
81 | if (View.isInitialised()) { | |
82 | // Report info to the Output tab | |
83 | View.getSingleton().getOutputPanel().append(message + "\n"); | |
84 | } | |
85 | ||
86 | ||
87 | } else { | |
88 | JOptionPane.showMessageDialog( | |
89 | this, | |
90 | messages.getString("faraday.send.alert.permissions.error"), | |
91 | messages.getString("faraday.button.send.request"), | |
92 | JOptionPane.ERROR_MESSAGE); | |
93 | ||
94 | logger.error(messages.getString("faraday.send.alert.permissions.error")); | |
95 | if (View.isInitialised()) { | |
96 | // Report info to the Output tab | |
97 | View.getSingleton().getOutputPanel().append(messages.getString("faraday.send.alert.permissions.error") + "\n"); | |
98 | } | |
99 | } | |
100 | ||
101 | ||
102 | } catch (HttpMalformedHeaderException e) { | |
103 | e.printStackTrace(); | |
104 | } catch (DatabaseException e) { | |
105 | e.printStackTrace(); | |
106 | } | |
107 | } | |
108 | ||
109 | ||
110 | @Override | |
111 | public void performHistoryReferenceActions(List<HistoryReference> hrefs) { | |
112 | this.selectionCount = hrefs.size(); | |
113 | ||
114 | for (HistoryReference href : hrefs) { | |
115 | this.performAction(href); | |
116 | } | |
117 | } | |
118 | ||
119 | @Override | |
120 | public boolean isEnableForInvoker(Invoker invoker, HttpMessageContainer httpMessageContainer) { | |
121 | if (Configuration.getSingleton().getSession() == null || Configuration.getSingleton().getSession().equals("") || | |
122 | invoker.name().equals("ALERTS_PANEL")) { | |
123 | return false; | |
124 | } | |
125 | return super.isEnableForInvoker(invoker, httpMessageContainer); | |
126 | } | |
127 | ||
128 | @Override | |
129 | public boolean isButtonEnabledForHistoryReference(HistoryReference href) { | |
130 | if (Configuration.getSingleton().getSession() == null || Configuration.getSingleton().getSession().equals("")) { | |
131 | return false; | |
132 | } | |
133 | ||
134 | return href.getSiteNode() != null && super.isButtonEnabledForHistoryReference(href); | |
135 | } | |
136 | }⏎ |
0 | <zapaddon> | |
1 | <name>Faraday</name> | |
2 | <version>1</version> | |
3 | <status>release</status> | |
4 | <description>This extension integrates ZAP with the Faraday Integrated Penetration-Test Environment</description> | |
5 | <author>Jorge Luis González Iznaga</author> | |
6 | <extensions> | |
7 | <extension>org.zaproxy.zap.extension.faraday.FaradayExtension</extension> | |
8 | </extensions> | |
9 | <ascanrules/> | |
10 | <pscanrules/> | |
11 | <not-before-version>2.7.0</not-before-version> | |
12 | <not-from-version/> | |
13 | </zapaddon> |
3 | 3 | See the file 'doc/LICENSE' for the license information |
4 | 4 | """ |
5 | 5 | import re |
6 | import xml.etree.ElementTree as ET | |
6 | 7 | from urllib.parse import urlparse |
8 | ||
7 | 9 | from faraday_plugins.plugins.plugin import PluginXMLFormat |
8 | 10 | from faraday_plugins.plugins.plugins_utils import resolve_hostname |
9 | ||
10 | try: | |
11 | import xml.etree.cElementTree as ET | |
12 | ETREE_VERSION = ET.VERSION | |
13 | except ImportError: | |
14 | import xml.etree.ElementTree as ET | |
15 | ETREE_VERSION = ET.VERSION | |
16 | ||
17 | ETREE_VERSION = [int(i) for i in ETREE_VERSION.split(".")] | |
18 | ||
19 | 11 | |
20 | 12 | __author__ = "Francisco Amato" |
21 | 13 | __copyright__ = "Copyright (c) 2013, Infobyte LLC" |
27 | 19 | __status__ = "Development" |
28 | 20 | |
29 | 21 | |
30 | ||
31 | 22 | class ZapXmlParser: |
32 | 23 | """ |
33 | 24 | The objective of this class is to parse an xml |
51 | 42 | else: |
52 | 43 | self.sites = [] |
53 | 44 | |
54 | def parse_xml(self, xml_output): | |
45 | @staticmethod | |
46 | def parse_xml(xml_output): | |
55 | 47 | """ |
56 | 48 | Open and parse an xml file. |
57 | 49 | |
71 | 63 | |
72 | 64 | return tree |
73 | 65 | |
74 | def get_items(self, tree): | |
66 | @staticmethod | |
67 | def get_items(tree): | |
75 | 68 | """ |
76 | 69 | @return items A list of Host instances |
77 | 70 | """ |
85 | 78 | |
86 | 79 | @return An attribute value |
87 | 80 | """ |
88 | global ETREE_VERSION | |
89 | node = None | |
90 | ||
91 | if ETREE_VERSION[0] <= 1 and ETREE_VERSION[1] < 3: | |
92 | ||
93 | match_obj = re.search( | |
94 | "([^\@]+?)\[\@([^=]*?)=\'([^\']*?)\'", | |
95 | subnode_xpath_expr) | |
96 | ||
97 | if match_obj is not None: | |
98 | ||
99 | node_to_find = match_obj.group(1) | |
100 | xpath_attrib = match_obj.group(2) | |
101 | xpath_value = match_obj.group(3) | |
102 | ||
103 | for node_found in xml_node.findall(node_to_find): | |
104 | ||
105 | if node_found.attrib[xpath_attrib] == xpath_value: | |
106 | node = node_found | |
107 | break | |
108 | else: | |
109 | node = xml_node.find(subnode_xpath_expr) | |
110 | ||
111 | else: | |
112 | node = xml_node.find(subnode_xpath_expr) | |
81 | ||
82 | node = xml_node.find(subnode_xpath_expr) | |
113 | 83 | |
114 | 84 | if node is not None: |
115 | 85 | return node.get(attrib_name) |
116 | 86 | |
117 | 87 | return None |
88 | ||
89 | ||
90 | def strip_tags(data): | |
91 | """ | |
92 | Remove html tags from a string | |
93 | @return Stripped string | |
94 | """ | |
95 | clean = re.compile('<.*?>') | |
96 | return re.sub(clean, '', data) | |
118 | 97 | |
119 | 98 | |
120 | 99 | class Site: |
126 | 105 | self.host = self.node.get('host') |
127 | 106 | self.ip = resolve_hostname(self.host) |
128 | 107 | self.port = self.node.get('port') |
108 | self.ssl = self.node.get('ssl') | |
129 | 109 | |
130 | 110 | self.items = [] |
131 | 111 | for alert in self.node.findall('alerts/alertitem'): |
141 | 121 | if sub_node is not None: |
142 | 122 | return sub_node.text |
143 | 123 | return None |
144 | ||
145 | 124 | |
146 | 125 | |
147 | 126 | class Item: |
159 | 138 | self.name = self.get_text_from_subnode('alert') |
160 | 139 | self.severity = self.get_text_from_subnode('riskcode') |
161 | 140 | self.desc = self.get_text_from_subnode('desc') |
162 | ||
163 | 141 | if self.get_text_from_subnode('solution'): |
164 | 142 | self.resolution = self.get_text_from_subnode('solution') |
165 | 143 | else: |
166 | 144 | self.resolution = '' |
167 | 145 | |
146 | self.ref = [] | |
168 | 147 | if self.get_text_from_subnode('reference'): |
169 | self.desc += '\nReference: ' + \ | |
170 | self.get_text_from_subnode('reference') | |
171 | ||
172 | self.ref = [] | |
148 | links = self.get_text_from_subnode('reference') | |
149 | for link in links.split("</p>"): | |
150 | link = link.strip().replace("\n", "") | |
151 | if link != "": | |
152 | self.ref.append(strip_tags(link)) | |
153 | ||
173 | 154 | if self.get_text_from_subnode('cweid'): |
174 | self.ref.append("CWE-" + self.get_text_from_subnode('cweid')) | |
155 | self.ref.append("CWE:" + self.get_text_from_subnode('cweid')) | |
156 | ||
157 | if self.get_text_from_subnode('wascid'): | |
158 | self.ref.append("WASC:" + self.get_text_from_subnode('wascid')) | |
175 | 159 | |
176 | 160 | self.items = [] |
177 | 161 | |
182 | 166 | |
183 | 167 | for elem in arr: |
184 | 168 | uri = elem.find('uri').text |
185 | method_element = elem.find('method') | |
186 | if method_element: | |
187 | method = elem.find('method').text | |
169 | method = elem.findtext('method', "") | |
170 | item = self.parse_uri(uri, method) | |
171 | ||
172 | param = elem.findtext("param", "") | |
173 | attack = elem.findtext("attack", "") | |
174 | if attack and param: | |
175 | item["data"] = f"URL:\n {uri}\n Payload:\n {param} = {attack}" | |
188 | 176 | else: |
189 | method = "" | |
190 | self.parse_uri(uri, method) | |
191 | ||
192 | def parse_uri(self, uri, method): | |
177 | item["data"] = f"URL:\n {uri}\n Parameter:\n {param}" | |
178 | ||
179 | evidence = elem.findtext("evidence", "") | |
180 | if evidence: | |
181 | item["data"] = f"URL:\n {uri}\n Parameter:\n {param}\n Evidence:\n {evidence}" | |
182 | else: | |
183 | item["data"] = f"URL:\n {uri}\n" | |
184 | ||
185 | item["pname"] = elem.findtext("param", "") | |
186 | ||
187 | self.items.append(item) | |
188 | ||
189 | def parse_uri(self, uri, method) -> dict: | |
193 | 190 | |
194 | 191 | parsed_url = urlparse(uri) |
195 | 192 | protocol = parsed_url.scheme |
196 | 193 | host = parsed_url.netloc |
197 | 194 | port = parsed_url.port |
198 | ||
199 | try: | |
200 | params = [i.split('=')[0] | |
201 | for i in uri.split('?')[1].split('&')] | |
202 | except Exception as e: | |
203 | params = '' | |
204 | ||
205 | item = { | |
195 | params = self.extract_params_from_uri(uri) | |
196 | ||
197 | return { | |
206 | 198 | 'uri': uri, |
207 | 199 | 'params': ', '.join(params), |
208 | 200 | 'host': host, |
211 | 203 | 'port': port, |
212 | 204 | 'method': method, |
213 | 205 | 'path': parsed_url.path, |
214 | 'query': parsed_url.query | |
206 | 'query': parsed_url.query, | |
207 | 'data': "" | |
215 | 208 | } |
216 | self.items.append(item) | |
209 | ||
210 | @staticmethod | |
211 | def extract_params_from_uri(uri): | |
212 | params = re.findall("(\w+)=", uri) | |
213 | return params if params else '' | |
217 | 214 | |
218 | 215 | def get_text_from_subnode(self, subnode_xpath_expr): |
219 | 216 | """ |
238 | 235 | self.identifier_tag = "OWASPZAPReport" |
239 | 236 | self.id = "Zap" |
240 | 237 | self.name = "Zap XML Output Plugin" |
241 | self.plugin_version = "0.0.3" | |
242 | self.version = "2.4.3" | |
238 | self.plugin_version = "0.0.4" | |
239 | self.version = "2.10.0" | |
243 | 240 | self.framework_version = "1.0.0" |
244 | 241 | self.options = None |
245 | ||
246 | 242 | |
247 | 243 | def parseOutputString(self, output): |
248 | 244 | """ |
258 | 254 | if site.host != site.ip: |
259 | 255 | host = [site.host] |
260 | 256 | |
257 | if site.ssl == "true": | |
258 | service = "https" | |
259 | else: | |
260 | service = "http" | |
261 | ||
261 | 262 | h_id = self.createAndAddHost(site.ip, hostnames=host) |
262 | 263 | |
263 | s_id = self.createAndAddServiceToHost(h_id, "http", "tcp", ports=[site.port], status='open') | |
264 | s_id = self.createAndAddServiceToHost(h_id, service, "tcp", ports=[site.port], status='open') | |
264 | 265 | |
265 | 266 | for item in site.items: |
266 | 267 | for instance in item.items: |
268 | 269 | h_id, |
269 | 270 | s_id, |
270 | 271 | item.name, |
271 | item.desc, | |
272 | strip_tags(item.desc), | |
272 | 273 | website=instance['website'], |
273 | 274 | query=instance['query'], |
274 | 275 | severity=item.severity, |
276 | 277 | params=instance['params'], |
277 | 278 | method=instance['method'], |
278 | 279 | ref=item.ref, |
279 | resolution=item.resolution | |
280 | resolution=strip_tags(item.resolution), | |
281 | data=instance["data"], | |
282 | pname=instance["pname"], | |
283 | external_id="ZAP-" + str(item.id) | |
280 | 284 | ) |
281 | 285 | |
282 | 286 | del parser |
283 | ||
284 | ||
285 | def setHost(self): | |
286 | pass | |
287 | 287 | |
288 | 288 | |
289 | 289 | def createPlugin(ignore_info=False): |
0 | <?xml version="1.0" encoding="UTF-8"?><report> | |
1 | Report generated at Tue, 12 Jul 2011 08:32:22. | |
2 | <alertitem> | |
3 | <pluginid>40000</pluginid> | |
4 | <alert>Cookie set without HttpOnly flag</alert> | |
5 | <riskcode>1</riskcode> | |
6 | <reliability>2</reliability> | |
7 | <riskdesc>Low (Warning)</riskdesc> | |
8 | <desc>A cookie has been set without the HttpOnly flag, which means that the cookie can be accessed by JavaScript. If a malicious script can be run on this page then the cookie will be accessible and can be transmitted to another site. If this is a session cookie then session hijacking may be possible. | |
9 | </desc> | |
10 | <uri>http://192.168.1.100/</uri> | |
11 | <param>ASPSESSIONIDQSDRBCRQ=EEFHJOACLHOKLJHFNAFBBECK; path=/</param> | |
12 | <otherinfo/> | |
13 | <uri>http://www.web3.com.ar/ServFotoPorNoticia.asp</uri> | |
14 | <param>ASPSESSIONIDCQATADBB=LMFPHGLBHIIEDFILGFJEJNGE; path=/</param> | |
15 | <otherinfo/> | |
16 | <uri>http://www.web1.com.ar/acceso/include/valida.asp</uri> | |
17 | <param>ASPSESSIONIDSCBABSTB=MNPOKADDPAIDCDNBPGFDHGBF; path=/</param> | |
18 | <otherinfo/> | |
19 | <uri>http://www.web3.com.ar/files/</uri> | |
20 | <param>ASPSESSIONIDCSCTCABB=HFCNOPJBMNJEAHDHMCKAHOBN; path=/</param> | |
21 | <otherinfo/> | |
22 | <uri>http://www.web2.com.ar/acceso/include/valida.asp</uri> | |
23 | <param>ASPSESSIONIDQAASDACB=HADJFCIBOIANGBGNAOIDBGIL; path=/</param> | |
24 | <otherinfo/> | |
25 | <uri>http://www.web3.com.ar/</uri> | |
26 | <param>ASPSESSIONIDSABQACDB=PAJBMJHBLOFELCIKBNLAAKKJ; path=/</param> | |
27 | <otherinfo/> | |
28 | <solution>Ensure that the HttpOnly flag is set for all cookies. | |
29 | </solution> | |
30 | <reference>www.owasp.org/index.php/HttpOnly | |
31 | </reference> | |
32 | </alertitem> | |
33 | <alertitem> | |
34 | <pluginid>40001</pluginid> | |
35 | <alert>Password Autocomplete in browser</alert> | |
36 | <riskcode>1</riskcode> | |
37 | <reliability>2</reliability> | |
38 | <riskdesc>Low (Warning)</riskdesc> | |
39 | <desc>AUTOCOMPLETE attribute is not disabled in HTML FORM/INPUT element containing password type input. Passwords may be stored in browsers and retrieved. | |
40 | </desc> | |
41 | <uri>http://192.168.1.100/</uri> | |
42 | <param>input</param> | |
43 | <otherinfo/> | |
44 | <uri>http://www.web3.com.ar/</uri> | |
45 | <param>input</param> | |
46 | <otherinfo/> | |
47 | <uri>http://www.web3.com.ar/default.asp?errsession=1</uri> | |
48 | <param>input</param> | |
49 | <otherinfo/> | |
50 | <uri>http://www.web3.com.ar/</uri> | |
51 | <param>input</param> | |
52 | <otherinfo/> | |
53 | <uri>http://www.web3.com.ar/</uri> | |
54 | <param>input</param> | |
55 | <otherinfo/> | |
56 | <uri>http://www.web2.com.ar/dealers.htm</uri> | |
57 | <param>input</param> | |
58 | <otherinfo/> | |
59 | <uri>http://www.web3.com.ar/</uri> | |
60 | <param>input</param> | |
61 | <otherinfo/> | |
62 | <solution>Turn off AUTOCOMPLETE attribute in form or individual input elements containing password by using AUTOCOMPLETE='OFF' | |
63 | </solution> | |
64 | <reference>http://msdn.microsoft.com/library/default.asp?url=/workshop/author/forms/autocomplete_ovr.asp | |
65 | </reference> | |
66 | </alertitem> | |
67 | <alertitem> | |
68 | <pluginid>40003</pluginid> | |
69 | <alert>Cross site scripting</alert> | |
70 | <riskcode>3</riskcode> | |
71 | <reliability>2</reliability> | |
72 | <riskdesc>High (Warning)</riskdesc> | |
73 | <desc>Cross-site scripting or HTML injection is possible. Malicious script may be injected into the browser which appeared to be genuine content from the original site. These scripts can be used to execute arbitrary code or steal customer sensitive information such as user password or cookies. | |
74 | Very often this is in the form of a hyperlink with the injected script embeded in the query strings. However, XSS is possible via FORM POST data, cookies, user data sent from another user or shared data retrieved from database. | |
75 | Currently this check does not verify XSS from cookie or database. They should be checked manually if the application retrieve database records from another user's input. | |
76 | </desc> | |
77 | <uri>http://www.web3.com.ar/Mes.asp?hhFrm=frm&hhDia=DiaF&hhMes=MesF&hhAnno=%3CSCRIPT%3Ealert(%22OWASP%20ZAP%22);%3C/SCRIPT%3E</uri> | |
78 | <param>hhAnno=<SCRIPT>alert("OWASP ZAP");</SCRIPT></param> | |
79 | <otherinfo/> | |
80 | <uri>http://www.web3.com.ar/Mes.asp?hhFrm=frm&hhDia=DiaF&hhMes=%3CSCRIPT%3Ealert(%22OWASP%20ZAP%22);%3C/SCRIPT%3E&hhAnno=AnnoF</uri> | |
81 | <param>hhMes=<SCRIPT>alert("OWASP ZAP");</SCRIPT></param> | |
82 | <otherinfo/> | |
83 | <uri>http://www.web3.com.ar/Mes.asp?hhFrm=frm&hhDia=%3CSCRIPT%3Ealert(%22OWASP%20ZAP%22);%3C/SCRIPT%3E&hhMes=MesF&hhAnno=AnnoF</uri> | |
84 | <param>hhDia=<SCRIPT>alert("OWASP ZAP");</SCRIPT></param> | |
85 | <otherinfo/> | |
86 | <uri>http://www.web3.com.ar/Mes.asp?hhFrm=%3CSCRIPT%3Ealert(%22OWASP%20ZAP%22);%3C/SCRIPT%3E&hhDia=DiaF&hhMes=MesF&hhAnno=AnnoF</uri> | |
87 | <param>hhFrm=<SCRIPT>alert("OWASP ZAP");</SCRIPT></param> | |
88 | <otherinfo/> | |
89 | <solution>Do not trust client side input even if there is client side validation. Sanitize potentially danger characters in the server side. Very often filtering the <, >, " characters prevented injected script to be executed in most cases. However, sometimes other danger meta-characters such as ' , (, ), /, &, ; etc are also needed. | |
90 | In addition (or if these characters are needed), HTML encode meta-characters in the response. For example, encode < as &lt; | |
91 | ||
92 | </solution> | |
93 | <reference>The OWASP guide at http://www.owasp.org/documentation/guide | |
94 | http://www.technicalinfo.net/papers/CSS.html | |
95 | http://www.cgisecurity.org/articles/xss-faq.shtml | |
96 | http://www.cert.org/tech_tips/malicious_code_FAQ.html | |
97 | http://sandsprite.com/Sleuth/papers/RealWorld_XSS_1.html | |
98 | ||
99 | </reference> | |
100 | </alertitem> | |
101 | <alertitem> | |
102 | <pluginid>40004</pluginid> | |
103 | <alert>Cross site scripting without brackets</alert> | |
104 | <riskcode>3</riskcode> | |
105 | <reliability>1</reliability> | |
106 | <riskdesc>High (Suspicious)</riskdesc> | |
107 | <desc>Cross-site scripting or HTML injection is possible without '<' and '>'. Malicious script may be injected into the browser which appeared to be genuine content from the original site. These scripts can be used to execute arbitrary code or steal customer sensitive information such as user password or cookies. | |
108 | Very often this is in the form of a hyperlink with the injected script embeded in the query strings. However, XSS is possible via FORM POST data, cookies, user data sent from another user or shared data retrieved from database. | |
109 | Currently this check does not verify XSS from cookie or database. They should be checked manually if the application retrieve database records from another user's input. | |
110 | </desc> | |
111 | <uri>http://www.web3.com.ar/Mes.asp?hhFrm=frm&hhDia=DiaF&hhMes=MesF&hhAnno=paros%22%20style=%22background:url(javascript:alert('OWASP%20ZAP'))</uri> | |
112 | <param>hhAnno=paros" style="background:url(javascript:alert('OWASP ZAP'))</param> | |
113 | <otherinfo/> | |
114 | <uri>http://www.web3.com.ar/Mes.asp?hhFrm=frm&hhDia=DiaF&hhMes=paros%22%20style=%22background:url(javascript:alert('OWASP%20ZAP'))&hhAnno=%3CSCRIPT%3Ealert(%22OWASP%20ZAP%22);%3C/SCRIPT%3E</uri> | |
115 | <param>hhMes=paros" style="background:url(javascript:alert('OWASP ZAP'))</param> | |
116 | <otherinfo/> | |
117 | <uri>http://www.web3.com.ar/Mes.asp?hhFrm=frm&hhDia=paros%22%20style=%22background:url(javascript:alert('OWASP%20ZAP'))&hhMes=MesF&hhAnno=%3CSCRIPT%3Ealert(%22OWASP%20ZAP%22);%3C/SCRIPT%3E</uri> | |
118 | <param>hhDia=paros" style="background:url(javascript:alert('OWASP ZAP'))</param> | |
119 | <otherinfo/> | |
120 | <uri>http://www.web3.com.ar/Mes.asp?hhFrm=paros%22%20style=%22background:url(javascript:alert('OWASP%20ZAP'))&hhDia=DiaF&hhMes=MesF&hhAnno=%3CSCRIPT%3Ealert(%22OWASP%20ZAP%22);%3C/SCRIPT%3E</uri> | |
121 | <param>hhFrm=paros" style="background:url(javascript:alert('OWASP ZAP'))</param> | |
122 | <otherinfo/> | |
123 | <solution>Do not trust client side input even if there is client side validation. Sanitize potentially danger characters in the server side. Very often filtering the <, >, " characters prevented injected script to be executed in most cases. However, sometimes other danger meta-characters such as ' , (, ), /, &, ; etc are also needed. | |
124 | In addition (or if these characters are needed), HTML encode meta-characters in the response. For example, encode < as &lt; | |
125 | ||
126 | </solution> | |
127 | <reference>The OWASP guide at http://www.owasp.org/documentation/guide | |
128 | http://www.technicalinfo.net/papers/CSS.html | |
129 | http://www.cgisecurity.org/articles/xss-faq.shtml | |
130 | http://www.cert.org/tech_tips/malicious_code_FAQ.html | |
131 | http://sandsprite.com/Sleuth/papers/RealWorld_XSS_1.html | |
132 | ||
133 | </reference> | |
134 | </alertitem> | |
135 | <alertitem> | |
136 | <pluginid>40030</pluginid> | |
137 | <alert>SQL Injection</alert> | |
138 | <riskcode>3</riskcode> | |
139 | <reliability>2</reliability> | |
140 | <riskdesc>High (Warning)</riskdesc> | |
141 | <desc>SQL injection is possible. User parameters submitted will be formulated into a SQL query for database processing. If the query is built by simple 'string concatenation', it is possible to modify the meaning of the query by carefully crafting the parameters. Depending on the access right and type of database used, tampered query can be used to retrieve sensitive information from the database or execute arbitrary code. MS SQL and PostGreSQL, which supports multiple statements, may be exploited if the database access right is more powerful. | |
142 | This can occur in URL query strings, POST paramters or even cookies. Currently check on cookie is not supported by Paros. You should check SQL injection manually as well as some blind SQL injection areas cannot be discovered by this check. | |
143 | </desc> | |
144 | <uri>http://www.web3.com.ar/buscador.asp</uri> | |
145 | <param>hId=&hAreturn=&hAccion=OK&txtBuscar=test&x=0&y=0%27+AND+%271%27%3D%271</param> | |
146 | <otherinfo/> | |
147 | <uri>http://www.web3.com.ar/buscador.asp</uri> | |
148 | <param>hId=&hAreturn=&hAccion=OK%22+OR+%221%22%3D%221&txtBuscar=test&x=0&y=0</param> | |
149 | <otherinfo/> | |
150 | <solution>Do not trust client side input even if there is client side validation. In general, If the input string is numeric, type check it. | |
151 | If the application used JDBC, use PreparedStatement or CallableStatement with parameters passed by '?' | |
152 | If the application used ASP, use ADO Command Objects with strong type checking and parameterized query. | |
153 | If stored procedure or bind variables can be used, use it for parameter passing into query. Do not just concatenate string into query in the stored procedure! | |
154 | Do not create dynamic SQL query by simple string concatentation. | |
155 | Use minimum database user privilege for the application. This does not eliminate SQL injection but minimize its damage. Eg if the application require reading one table only, grant such access to the application. Avoid using 'sa' or 'db-owner'. | |
156 | ||
157 | </solution> | |
158 | <reference>The OWASP guide at http://www.owasp.org/documentation/guide | |
159 | http://www.sqlsecurity.com/DesktopDefault.aspx?tabid=23 | |
160 | http://www.spidynamics.com/whitepapers/WhitepaperSQLInjection.pdf | |
161 | For Oracle database, refer to http://www.integrigy.com/info/IntegrigyIntrotoSQLInjectionAttacks.pdf | |
162 | ||
163 | </reference> | |
164 | </alertitem> | |
165 | </report>⏎ |
0 | Metadata-Version: 1.0 | |
1 | Name: faraday-plugins | |
2 | Version: 1.4.6 | |
3 | Summary: Faraday plugins package | |
4 | Home-page: UNKNOWN | |
5 | Author: Faradaysec | |
6 | Author-email: [email protected] | |
7 | License: GNU General Public License v3 | |
8 | Description: UNKNOWN | |
9 | Platform: UNKNOWN |
0 | MANIFEST.in | |
1 | README.md | |
2 | setup.py | |
3 | faraday_plugins/__init__.py | |
4 | faraday_plugins/__main__.py | |
5 | faraday_plugins/commands.py | |
6 | faraday_plugins.egg-info/PKG-INFO | |
7 | faraday_plugins.egg-info/SOURCES.txt | |
8 | faraday_plugins.egg-info/dependency_links.txt | |
9 | faraday_plugins.egg-info/entry_points.txt | |
10 | faraday_plugins.egg-info/requires.txt | |
11 | faraday_plugins.egg-info/top_level.txt | |
12 | faraday_plugins/plugins/__init__.py | |
13 | faraday_plugins/plugins/manager.py | |
14 | faraday_plugins/plugins/plugin.py | |
15 | faraday_plugins/plugins/plugins_utils.py | |
16 | faraday_plugins/plugins/port_mapper.txt | |
17 | faraday_plugins/plugins/repo/__init__.py | |
18 | faraday_plugins/plugins/repo/acunetix/__init__.py | |
19 | faraday_plugins/plugins/repo/acunetix/plugin.py | |
20 | faraday_plugins/plugins/repo/amap/__init__.py | |
21 | faraday_plugins/plugins/repo/amap/plugin.py | |
22 | faraday_plugins/plugins/repo/appscan/__init__.py | |
23 | faraday_plugins/plugins/repo/appscan/plugin.py | |
24 | faraday_plugins/plugins/repo/appspider/__init__.py | |
25 | faraday_plugins/plugins/repo/appspider/plugin.py | |
26 | faraday_plugins/plugins/repo/arachni/__init__.py | |
27 | faraday_plugins/plugins/repo/arachni/plugin.py | |
28 | faraday_plugins/plugins/repo/arp_scan/__init__.py | |
29 | faraday_plugins/plugins/repo/arp_scan/plugin.py | |
30 | faraday_plugins/plugins/repo/awsprowler/__init__.py | |
31 | faraday_plugins/plugins/repo/awsprowler/plugin.py | |
32 | faraday_plugins/plugins/repo/bandit/__init__.py | |
33 | faraday_plugins/plugins/repo/bandit/plugin.py | |
34 | faraday_plugins/plugins/repo/beef/__init__.py | |
35 | faraday_plugins/plugins/repo/beef/plugin.py | |
36 | faraday_plugins/plugins/repo/brutexss/__init__.py | |
37 | faraday_plugins/plugins/repo/brutexss/plugin.py | |
38 | faraday_plugins/plugins/repo/burp/__init__.py | |
39 | faraday_plugins/plugins/repo/burp/plugin.py | |
40 | faraday_plugins/plugins/repo/checkmarx/__init__.py | |
41 | faraday_plugins/plugins/repo/checkmarx/plugin.py | |
42 | faraday_plugins/plugins/repo/cobalt/__init__.py | |
43 | faraday_plugins/plugins/repo/cobalt/plugin.py | |
44 | faraday_plugins/plugins/repo/dig/__init__.py | |
45 | faraday_plugins/plugins/repo/dig/plugin.py | |
46 | faraday_plugins/plugins/repo/dirb/__init__.py | |
47 | faraday_plugins/plugins/repo/dirb/plugin.py | |
48 | faraday_plugins/plugins/repo/dirsearch/__init__.py | |
49 | faraday_plugins/plugins/repo/dirsearch/plugin.py | |
50 | faraday_plugins/plugins/repo/dnsenum/__init__.py | |
51 | faraday_plugins/plugins/repo/dnsenum/plugin.py | |
52 | faraday_plugins/plugins/repo/dnsmap/__init__.py | |
53 | faraday_plugins/plugins/repo/dnsmap/plugin.py | |
54 | faraday_plugins/plugins/repo/dnsrecon/__init__.py | |
55 | faraday_plugins/plugins/repo/dnsrecon/plugin.py | |
56 | faraday_plugins/plugins/repo/dnswalk/__init__.py | |
57 | faraday_plugins/plugins/repo/dnswalk/plugin.py | |
58 | faraday_plugins/plugins/repo/faraday_csv/__init__.py | |
59 | faraday_plugins/plugins/repo/faraday_csv/plugin.py | |
60 | faraday_plugins/plugins/repo/fierce/__init__.py | |
61 | faraday_plugins/plugins/repo/fierce/plugin.py | |
62 | faraday_plugins/plugins/repo/fortify/__init__.py | |
63 | faraday_plugins/plugins/repo/fortify/plugin.py | |
64 | faraday_plugins/plugins/repo/fruitywifi/__init__.py | |
65 | faraday_plugins/plugins/repo/fruitywifi/fruitywifi.py | |
66 | faraday_plugins/plugins/repo/fruitywifi/plugin.py | |
67 | faraday_plugins/plugins/repo/ftp/__init__.py | |
68 | faraday_plugins/plugins/repo/ftp/plugin.py | |
69 | faraday_plugins/plugins/repo/goohost/__init__.py | |
70 | faraday_plugins/plugins/repo/goohost/plugin.py | |
71 | faraday_plugins/plugins/repo/hping3/__init__.py | |
72 | faraday_plugins/plugins/repo/hping3/plugin.py | |
73 | faraday_plugins/plugins/repo/hydra/__init__.py | |
74 | faraday_plugins/plugins/repo/hydra/plugin.py | |
75 | faraday_plugins/plugins/repo/impact/__init__.py | |
76 | faraday_plugins/plugins/repo/impact/plugin.py | |
77 | faraday_plugins/plugins/repo/ip360/__init__.py | |
78 | faraday_plugins/plugins/repo/ip360/plugin.py | |
79 | faraday_plugins/plugins/repo/junit/__init__.py | |
80 | faraday_plugins/plugins/repo/junit/plugin.py | |
81 | faraday_plugins/plugins/repo/lynis/__init__.py | |
82 | faraday_plugins/plugins/repo/lynis/plugin.py | |
83 | faraday_plugins/plugins/repo/maltego/__init__.py | |
84 | faraday_plugins/plugins/repo/maltego/plugin.py | |
85 | faraday_plugins/plugins/repo/mbsa/__init__.py | |
86 | faraday_plugins/plugins/repo/mbsa/plugin.py | |
87 | faraday_plugins/plugins/repo/medusa/__init__.py | |
88 | faraday_plugins/plugins/repo/medusa/plugin.py | |
89 | faraday_plugins/plugins/repo/metasploit/__init__.py | |
90 | faraday_plugins/plugins/repo/metasploit/plugin.py | |
91 | faraday_plugins/plugins/repo/naabu/__init__.py | |
92 | faraday_plugins/plugins/repo/naabu/plugin.py | |
93 | faraday_plugins/plugins/repo/ncrack/__init__.py | |
94 | faraday_plugins/plugins/repo/ncrack/plugin.py | |
95 | faraday_plugins/plugins/repo/ndiff/__init__.py | |
96 | faraday_plugins/plugins/repo/ndiff/plugin.py | |
97 | faraday_plugins/plugins/repo/nessus/DTO.py | |
98 | faraday_plugins/plugins/repo/nessus/__init__.py | |
99 | faraday_plugins/plugins/repo/nessus/plugin.py | |
100 | faraday_plugins/plugins/repo/netdiscover/__init__.py | |
101 | faraday_plugins/plugins/repo/netdiscover/plugin.py | |
102 | faraday_plugins/plugins/repo/netsparker/__init__.py | |
103 | faraday_plugins/plugins/repo/netsparker/plugin.py | |
104 | faraday_plugins/plugins/repo/netsparkercloud/__init__.py | |
105 | faraday_plugins/plugins/repo/netsparkercloud/plugin.py | |
106 | faraday_plugins/plugins/repo/nexpose_full/__init__.py | |
107 | faraday_plugins/plugins/repo/nexpose_full/plugin.py | |
108 | faraday_plugins/plugins/repo/nextnet/__init__.py | |
109 | faraday_plugins/plugins/repo/nextnet/plugin.py | |
110 | faraday_plugins/plugins/repo/nikto/__init__.py | |
111 | faraday_plugins/plugins/repo/nikto/plugin.py | |
112 | faraday_plugins/plugins/repo/nmap/__init__.py | |
113 | faraday_plugins/plugins/repo/nmap/plugin.py | |
114 | faraday_plugins/plugins/repo/nuclei/__init__.py | |
115 | faraday_plugins/plugins/repo/nuclei/plugin.py | |
116 | faraday_plugins/plugins/repo/openscap/__init__.py | |
117 | faraday_plugins/plugins/repo/openscap/plugin.py | |
118 | faraday_plugins/plugins/repo/openvas/__init__.py | |
119 | faraday_plugins/plugins/repo/openvas/plugin.py | |
120 | faraday_plugins/plugins/repo/pasteanalyzer/__init__.py | |
121 | faraday_plugins/plugins/repo/pasteanalyzer/plugin.py | |
122 | faraday_plugins/plugins/repo/peepingtom/__init__.py | |
123 | faraday_plugins/plugins/repo/peepingtom/plugin.py | |
124 | faraday_plugins/plugins/repo/ping/__init__.py | |
125 | faraday_plugins/plugins/repo/ping/plugin.py | |
126 | faraday_plugins/plugins/repo/propecia/__init__.py | |
127 | faraday_plugins/plugins/repo/propecia/plugin.py | |
128 | faraday_plugins/plugins/repo/qualysguard/__init__.py | |
129 | faraday_plugins/plugins/repo/qualysguard/plugin.py | |
130 | faraday_plugins/plugins/repo/qualyswebapp/__init__.py | |
131 | faraday_plugins/plugins/repo/qualyswebapp/plugin.py | |
132 | faraday_plugins/plugins/repo/rdpscan/__init__.py | |
133 | faraday_plugins/plugins/repo/rdpscan/plugin.py | |
134 | faraday_plugins/plugins/repo/reconng/__init__.py | |
135 | faraday_plugins/plugins/repo/reconng/plugin.py | |
136 | faraday_plugins/plugins/repo/retina/__init__.py | |
137 | faraday_plugins/plugins/repo/retina/plugin.py | |
138 | faraday_plugins/plugins/repo/reverseraider/__init__.py | |
139 | faraday_plugins/plugins/repo/reverseraider/plugin.py | |
140 | faraday_plugins/plugins/repo/skipfish/__init__.py | |
141 | faraday_plugins/plugins/repo/skipfish/plugin.py | |
142 | faraday_plugins/plugins/repo/sonarqubeapi/__init__.py | |
143 | faraday_plugins/plugins/repo/sonarqubeapi/plugin.py | |
144 | faraday_plugins/plugins/repo/sourceclear/__init__.py | |
145 | faraday_plugins/plugins/repo/sourceclear/plugin.py | |
146 | faraday_plugins/plugins/repo/sshdefaultscan/__init__.py | |
147 | faraday_plugins/plugins/repo/sshdefaultscan/plugin.py | |
148 | faraday_plugins/plugins/repo/ssl_labs/__init__.py | |
149 | faraday_plugins/plugins/repo/ssl_labs/plugin.py | |
150 | faraday_plugins/plugins/repo/sslyze/__init__.py | |
151 | faraday_plugins/plugins/repo/sslyze/plugin.py | |
152 | faraday_plugins/plugins/repo/sslyzejson/__init__.py | |
153 | faraday_plugins/plugins/repo/sslyzejson/plugin.py | |
154 | faraday_plugins/plugins/repo/telnet/__init__.py | |
155 | faraday_plugins/plugins/repo/telnet/plugin.py | |
156 | faraday_plugins/plugins/repo/theharvester/__init__.py | |
157 | faraday_plugins/plugins/repo/theharvester/plugin.py | |
158 | faraday_plugins/plugins/repo/traceroute/__init__.py | |
159 | faraday_plugins/plugins/repo/traceroute/plugin.py | |
160 | faraday_plugins/plugins/repo/w3af/__init__.py | |
161 | faraday_plugins/plugins/repo/w3af/plugin.py | |
162 | faraday_plugins/plugins/repo/wapiti/__init__.py | |
163 | faraday_plugins/plugins/repo/wapiti/plugin.py | |
164 | faraday_plugins/plugins/repo/wcscan/__init__.py | |
165 | faraday_plugins/plugins/repo/wcscan/plugin.py | |
166 | faraday_plugins/plugins/repo/webfuzzer/__init__.py | |
167 | faraday_plugins/plugins/repo/webfuzzer/plugin.py | |
168 | faraday_plugins/plugins/repo/webinspect/__init__.py | |
169 | faraday_plugins/plugins/repo/webinspect/plugin.py | |
170 | faraday_plugins/plugins/repo/wfuzz/__init__.py | |
171 | faraday_plugins/plugins/repo/wfuzz/plugin.py | |
172 | faraday_plugins/plugins/repo/whatweb/__init__.py | |
173 | faraday_plugins/plugins/repo/whatweb/plugin.py | |
174 | faraday_plugins/plugins/repo/whitesource/__init__.py | |
175 | faraday_plugins/plugins/repo/whitesource/plugin.py | |
176 | faraday_plugins/plugins/repo/whois/__init__.py | |
177 | faraday_plugins/plugins/repo/whois/plugin.py | |
178 | faraday_plugins/plugins/repo/wpscan/__init__.py | |
179 | faraday_plugins/plugins/repo/wpscan/plugin.py | |
180 | faraday_plugins/plugins/repo/x1/__init__.py | |
181 | faraday_plugins/plugins/repo/x1/plugin.py | |
182 | faraday_plugins/plugins/repo/xsssniper/__init__.py | |
183 | faraday_plugins/plugins/repo/xsssniper/plugin.py | |
184 | faraday_plugins/plugins/repo/zap/__init__.py | |
185 | faraday_plugins/plugins/repo/zap/plugin.py⏎ |
0 | Click | |
1 | beautifulsoup4 | |
2 | colorama | |
3 | html2text | |
4 | lxml | |
5 | python-dateutil | |
6 | pytz | |
7 | requests | |
8 | simplejson | |
9 | tabulate |
0 | faraday_plugins |
13 | 13 | 'beautifulsoup4', |
14 | 14 | 'pytz', |
15 | 15 | 'python-dateutil', |
16 | 'colorama' | |
16 | 'colorama', | |
17 | 'tabulate' | |
17 | 18 | ] |
18 | 19 | |
19 | 20 | |
22 | 23 | version=version, |
23 | 24 | packages=find_packages(include=['faraday_plugins', 'faraday_plugins.*']), |
24 | 25 | url='', |
25 | license='', | |
26 | license="GNU General Public License v3", | |
26 | 27 | author='Faradaysec', |
27 | 28 | author_email='[email protected]', |
28 | 29 | description='Faraday plugins package', |
0 | { | |
1 | "commands": [ | |
2 | {"plugin_id": "ping", "command": "ping -c4 faradaysec.com"}, | |
3 | {"plugin_id": "whois", "command": "whois fradaysec.com"}, | |
4 | {"plugin_id": "nmap", "command": "nmap fradaysec.com"}, | |
5 | {"plugin_id": "skipfish", "command": "skipfish http://fradaysec.com"} | |
6 | ] | |
7 | }⏎ |
0 | import pytest | |
1 | ||
2 | ||
3 | def pytest_addoption(parser): | |
4 | parser.addoption( | |
5 | "--performance", action="store_true", default=False, help="run performance tests" | |
6 | ) | |
7 | ||
8 | ||
9 | def pytest_configure(config): | |
10 | config.addinivalue_line("markers", "performance: mark test as performance") | |
11 | ||
12 | ||
13 | def pytest_collection_modifyitems(config, items): | |
14 | if config.getoption("--performance"): | |
15 | # --performance given in cli: do not skip performance tests | |
16 | return | |
17 | performance = pytest.mark.skip(reason="need --performance option to run") | |
18 | for item in items: | |
19 | if "performance" in item.keywords: | |
20 | item.add_marker(performance)⏎ |
0 | #!/usr/bin/env python | |
1 | import hashlib | |
2 | import os | |
3 | import shutil | |
4 | import json | |
5 | import click | |
6 | import colorama | |
7 | from faraday_plugins.plugins.manager import PluginsManager, ReportAnalyzer | |
8 | from faraday_plugins.plugins.plugin import PluginBase | |
9 | ||
10 | colorama.init(autoreset=True) | |
11 | ||
12 | BLACK_LIST = [ | |
13 | 'LICENSE', | |
14 | 'README.md', | |
15 | '.gitignore', | |
16 | '.gitkeep', | |
17 | 'faraday_plugins_tests', | |
18 | ] | |
19 | ||
20 | REPORT_COLLECTION_DIR = '../report-collection' | |
21 | FARADAY_PLUGINS_TESTS_DIR = 'faraday_plugins_tests' | |
22 | REPORTS_CHECKSUM = [] | |
23 | ||
24 | def list_report_files(): | |
25 | report_filenames = os.walk(os.path.join(REPORT_COLLECTION_DIR)) | |
26 | for root, directory, filenames in report_filenames: | |
27 | if '.git' in directory or FARADAY_PLUGINS_TESTS_DIR in root: | |
28 | continue | |
29 | for filename in filenames: | |
30 | if filename in BLACK_LIST: | |
31 | continue | |
32 | if '.git' in root: | |
33 | continue | |
34 | yield os.path.join(root, filename) | |
35 | ||
36 | ||
37 | @click.command() | |
38 | @click.option('--force', is_flag=True) | |
39 | @click.option('--debug', is_flag=False) | |
40 | def generate_reports_tests(force, debug): | |
41 | generated_summaries = 0 | |
42 | analysed_reports = 0 | |
43 | click.echo(f"{colorama.Fore.GREEN}Generate Faraday Plugins Tests Summary") | |
44 | plugins_manager = PluginsManager() | |
45 | analyzer = ReportAnalyzer(plugins_manager) | |
46 | for report_file_path in list_report_files(): | |
47 | if debug: | |
48 | click.echo(f"File: {report_file_path}") | |
49 | plugin: PluginBase = analyzer.get_plugin(report_file_path) | |
50 | if not plugin: | |
51 | click.echo(f"{colorama.Fore.YELLOW}Plugin for file: ({report_file_path}) not found") | |
52 | else: | |
53 | with open(report_file_path, 'rb') as f: | |
54 | m = hashlib.md5(f.read()) | |
55 | file_checksum = m.hexdigest() | |
56 | if file_checksum not in REPORTS_CHECKSUM: | |
57 | REPORTS_CHECKSUM.append(file_checksum) | |
58 | else: | |
59 | click.echo(f"{colorama.Fore.YELLOW}Ignore duplicated file: ({report_file_path})") | |
60 | continue | |
61 | analysed_reports += 1 | |
62 | report_file_name = os.path.basename(report_file_path) | |
63 | plugin_name = plugin.id | |
64 | plugin_path = os.path.join(REPORT_COLLECTION_DIR, FARADAY_PLUGINS_TESTS_DIR, plugin_name) | |
65 | if not os.path.isdir(plugin_path): | |
66 | os.mkdir(plugin_path) | |
67 | dst_report_file_path = os.path.join(plugin_path, report_file_name) | |
68 | summary_needed = False | |
69 | summary_file = f"{os.path.splitext(dst_report_file_path)[0]}_summary.json" | |
70 | if not os.path.isfile(dst_report_file_path) or force: | |
71 | summary_needed = True | |
72 | shutil.copyfile(report_file_path, dst_report_file_path) | |
73 | if not os.path.isfile(summary_file) or force: | |
74 | summary_needed = True | |
75 | if summary_needed: | |
76 | try: | |
77 | plugin.processReport(report_file_path) | |
78 | click.echo(f"{colorama.Fore.GREEN}Generate Summary for: {dst_report_file_path} [{plugin}]") | |
79 | summary = plugin.get_summary() | |
80 | with open(summary_file, "w") as f: | |
81 | json.dump(summary, f) | |
82 | generated_summaries += 1 | |
83 | except Exception as e: | |
84 | click.echo(f"{colorama.Fore.RED}Error generating summary for file: {report_file_path} [{plugin}]: [{e}]") | |
85 | click.echo(f"Generated {generated_summaries} summaries of {analysed_reports} reports") | |
86 | ||
87 | ||
88 | if __name__ == "__main__": | |
89 | generate_reports_tests() |
0 | import json | |
1 | import os | |
2 | import re | |
3 | from tempfile import NamedTemporaryFile | |
4 | from click.testing import CliRunner | |
5 | from faraday_plugins.commands import list_plugins, detect_command, process_command, detect_report, process_report | |
6 | ||
7 | ||
8 | def test_list_plugins(): | |
9 | runner = CliRunner() | |
10 | result = runner.invoke(list_plugins) | |
11 | assert result.exit_code == 0 | |
12 | loaded_plugins = re.search(r'Loaded Plugins: (?P<loaded_plugins>\d+)', result.output) | |
13 | assert loaded_plugins | |
14 | assert int(loaded_plugins.groupdict().get('loaded_plugins', 0)) > 0 | |
15 | ||
16 | ||
17 | def test_detect_invalid_command(): | |
18 | runner = CliRunner() | |
19 | result = runner.invoke(detect_command, args=['invalid_command']) | |
20 | assert result.exit_code == 0 | |
21 | assert result.output.strip() == "Failed to detect command: invalid_command" | |
22 | ||
23 | ||
24 | def test_detect_command(): | |
25 | runner = CliRunner() | |
26 | result = runner.invoke(detect_command, args=['ping -c 1 www.google.com']) | |
27 | assert result.exit_code == 0 | |
28 | assert result.output.strip() == "Faraday Plugin: ping" | |
29 | ||
30 | ||
31 | def test_process_command(): | |
32 | runner = CliRunner() | |
33 | result = runner.invoke(process_command, args=['ping -c 1 www.google.com', '--summary']) | |
34 | assert result.exit_code == 0 | |
35 | summary = json.loads(result.output.strip()) | |
36 | assert summary['hosts'] == 1 | |
37 | ||
38 | ||
39 | def test_process_command_to_file(): | |
40 | runner = CliRunner() | |
41 | with runner.isolated_filesystem() as file_system: | |
42 | output_file = os.path.join(file_system, "test.json") | |
43 | result = runner.invoke(process_command, args=['ping -c 1 www.google.com', '-o', output_file]) | |
44 | assert result.exit_code == 0 | |
45 | assert os.path.isfile(output_file) | |
46 | with open(output_file) as f: | |
47 | vuln_json = json.load(f) | |
48 | assert len(vuln_json['hosts']) == 1 | |
49 | ||
50 | ||
51 | def test_detect_report(): | |
52 | report_file = os.path.join('./report-collection', 'faraday_plugins_tests', 'Nmap', 'nmap_5.21.xml') | |
53 | runner = CliRunner() | |
54 | result = runner.invoke(detect_report, args=[report_file]) | |
55 | assert result.exit_code == 0 | |
56 | assert "Faraday Plugin: Nmap" == result.output.strip() | |
57 | ||
58 | ||
59 | def test_detect_report_dont_exists(): | |
60 | report_file = os.path.join('./report-collection', 'faraday_plugins_tests', 'Nmap', 'invalid_report.xml') | |
61 | runner = CliRunner() | |
62 | result = runner.invoke(detect_report, args=[report_file]) | |
63 | assert result.exit_code == 0 | |
64 | assert "Don't Exists" in result.output.strip() | |
65 | ||
66 | ||
67 | def test_process_report_summary(): | |
68 | report_file = os.path.join('./report-collection', 'faraday_plugins_tests', 'Nmap', 'nmap_5.21.xml') | |
69 | summary_file = os.path.join('./report-collection', 'faraday_plugins_tests', 'Nmap', 'nmap_5.21_summary.json') | |
70 | runner = CliRunner() | |
71 | result = runner.invoke(process_report, args=[report_file, '--summary']) | |
72 | assert result.exit_code == 0 | |
73 | summary = json.loads(result.output.strip()) | |
74 | with open(summary_file) as f: | |
75 | saved_summary = json.load(f) | |
76 | vuln_hashes = set(summary['vuln_hashes']) | |
77 | saved_vuln_hashes = set(saved_summary.get('vuln_hashes', [])) | |
78 | assert summary['hosts'] == saved_summary['hosts'] | |
79 | assert summary['services'] == saved_summary['services'] | |
80 | assert summary['hosts_vulns'] == saved_summary['hosts_vulns'] | |
81 | assert summary['services_vulns'] == saved_summary['services_vulns'] | |
82 | assert summary['severity_vulns'] == saved_summary['severity_vulns'] | |
83 | assert vuln_hashes == saved_vuln_hashes | |
84 |
0 | import json | |
1 | import pytest | |
2 | from faraday_plugins.plugins.manager import PluginsManager, CommandAnalyzer | |
3 | from faraday_plugins.plugins.plugin import PluginBase | |
4 | ||
5 | ||
6 | plugins_manager = PluginsManager() | |
7 | analyzer = CommandAnalyzer(plugins_manager) | |
8 | ||
9 | COMMANDS_FILE = './tests/commands.json' | |
10 | ||
11 | def list_commands(): | |
12 | with open(COMMANDS_FILE) as f: | |
13 | commands_dict = json.load(f) | |
14 | for command_data in commands_dict["commands"]: | |
15 | yield command_data | |
16 | ||
17 | ||
18 | @pytest.mark.parametrize("command_data", list_commands()) | |
19 | def test_autodetected_on_commands(command_data): | |
20 | plugin_id = command_data["plugin_id"] | |
21 | command_string = command_data["command"] | |
22 | plugin: PluginBase = analyzer.get_plugin(command_string) | |
23 | assert plugin, command_string | |
24 | assert plugin.id.lower() == plugin_id.lower() | |
25 |
0 | from faraday_plugins.plugins.plugin import PluginBase | |
1 | ||
2 | ||
3 | def test_get_host_cache_id_with_same_host(): | |
4 | host_1 = {'ip': '127.0.0.1'} | |
5 | host_2 = {'ip': '127.0.0.1', 'description': 'test desc'} | |
6 | cache_id_1 = PluginBase.get_host_cache_id(host_1) | |
7 | cache_id_2 = PluginBase.get_host_cache_id(host_2) | |
8 | ||
9 | assert cache_id_1 == cache_id_2 | |
10 | ||
11 | ||
12 | def test_get_host_cache_id_with_diffent_ip(): | |
13 | host_1 = {'ip': '127.0.0.1'} | |
14 | host_2 = {'ip': '192.168.0.1', 'description': 'test desc'} | |
15 | cache_id_1 = PluginBase.get_host_cache_id(host_1) | |
16 | cache_id_2 = PluginBase.get_host_cache_id(host_2) | |
17 | ||
18 | assert cache_id_1 != cache_id_2 | |
19 | ||
20 | ||
21 | def test_get_host_service_cache_id_same_objects(): | |
22 | host_1 = {'ip': '127.0.0.1'} | |
23 | host_cache_id_1 = PluginBase.get_host_cache_id(host_1) | |
24 | service_1 = {'protocol': 'tcp', 'port': 80} | |
25 | host_2 = {'ip': '127.0.0.1'} | |
26 | host_cache_id_2 = PluginBase.get_host_cache_id(host_2) | |
27 | service_2 = {'protocol': 'tcp', 'port': 80} | |
28 | ||
29 | cache_1 = PluginBase.get_host_service_cache_id(host_cache_id_1, service_1) | |
30 | cache_2 = PluginBase.get_host_service_cache_id(host_cache_id_2, service_2) | |
31 | ||
32 | assert cache_1 == cache_2 | |
33 | ||
34 | ||
35 | def test_get_host_service_cache_id_different_host(): | |
36 | host_1 = {'ip': '127.0.0.1'} | |
37 | host_cache_id_1 = PluginBase.get_host_cache_id(host_1) | |
38 | service_1 = {'protocol': 'tcp', 'port': 80} | |
39 | host_2 = {'ip': '192.168.0.1'} | |
40 | host_cache_id_2 = PluginBase.get_host_cache_id(host_2) | |
41 | service_2 = {'protocol': 'tcp', 'port': 80} | |
42 | ||
43 | cache_1 = PluginBase.get_host_service_cache_id(host_cache_id_1, service_1) | |
44 | cache_2 = PluginBase.get_host_service_cache_id(host_cache_id_2, service_2) | |
45 | ||
46 | assert cache_1 != cache_2 | |
47 | ||
48 | ||
49 | def test_get_host_vuln_cache_id_severity_does_not_affect_duplicate(): | |
50 | host_1 = {'ip': '127.0.0.1'} | |
51 | host_cache_id_1 = PluginBase.get_host_cache_id(host_1) | |
52 | vuln_1 = {'name': 'test', 'desc': 'test', 'severity': 'low'} | |
53 | ||
54 | host_2 = {'ip': '127.0.0.1'} | |
55 | host_cache_id_2 = PluginBase.get_host_cache_id(host_2) | |
56 | vuln_2 = {'name': 'test', 'desc': 'test', 'severity': 'high'} | |
57 | ||
58 | ||
59 | cache_1 = PluginBase.get_host_vuln_cache_id(host_cache_id_1, vuln_1) | |
60 | cache_2 = PluginBase.get_host_vuln_cache_id(host_cache_id_2, vuln_2) | |
61 | ||
62 | assert cache_1 == cache_2 | |
63 | ||
64 | ||
65 | def test_get_host_vuln_cache_id_description_makes_different_cache_ids(): | |
66 | host_1 = {'ip': '127.0.0.1'} | |
67 | host_cache_id_1 = PluginBase.get_host_cache_id(host_1) | |
68 | vuln_1 = {'name': 'test', 'desc': 'test', 'severity': 'low'} | |
69 | ||
70 | host_2 = {'ip': '127.0.0.1'} | |
71 | host_cache_id_2 = PluginBase.get_host_cache_id(host_2) | |
72 | vuln_2 = {'name': 'test', 'new desc': 'test', 'severity': 'high'} | |
73 | ||
74 | ||
75 | cache_1 = PluginBase.get_host_vuln_cache_id(host_cache_id_1, vuln_1) | |
76 | cache_2 = PluginBase.get_host_vuln_cache_id(host_cache_id_2, vuln_2) | |
77 | ||
78 | assert cache_1 != cache_2 | |
79 | ||
80 | ||
81 | def test_get_service_vuln_cache_id_severity_does_not_affect_cache_id(): | |
82 | host_1 = {'ip': '127.0.0.1'} | |
83 | host_cache_id_1 = PluginBase.get_host_cache_id(host_1) | |
84 | service_1 = {'protocol': 'tcp', 'port': 80} | |
85 | ||
86 | host_2 = {'ip': '127.0.0.1'} | |
87 | host_cache_id_2 = PluginBase.get_host_cache_id(host_2) | |
88 | host_2 = {'ip': '127.0.0.1'} | |
89 | host_cache_id_2 = PluginBase.get_host_cache_id(host_2) | |
90 | service_2 = {'protocol': 'tcp', 'port': 80} | |
91 | ||
92 | service_cache_1 = PluginBase.get_host_service_cache_id(host_cache_id_1, service_1) | |
93 | service_cache_2 = PluginBase.get_host_service_cache_id(host_cache_id_2, service_2) | |
94 | ||
95 | vuln_2 = {'name': 'test', 'desc': 'test', 'severity': 'high', 'method': 'GET'} | |
96 | vuln_1 = {'name': 'test', 'desc': 'test', 'severity': 'low', 'method': 'GET'} | |
97 | ||
98 | cache_1 = PluginBase.get_service_vuln_cache_id(host_cache_id_1, service_cache_1, vuln_1) | |
99 | cache_2 = PluginBase.get_service_vuln_cache_id(host_cache_id_2, service_cache_2, vuln_2) | |
100 | ||
101 | assert cache_1 == cache_2 | |
102 | ||
103 | def test_get_service_vuln_cache_id_with_different_service_return_different_id(): | |
104 | host_1 = {'ip': '127.0.0.1'} | |
105 | host_cache_id_1 = PluginBase.get_host_cache_id(host_1) | |
106 | service_1 = {'protocol': 'tcp', 'port': 80} | |
107 | ||
108 | host_2 = {'ip': '127.0.0.1'} | |
109 | host_cache_id_2 = PluginBase.get_host_cache_id(host_2) | |
110 | host_2 = {'ip': '127.0.0.1'} | |
111 | host_cache_id_2 = PluginBase.get_host_cache_id(host_2) | |
112 | service_2 = {'protocol': 'tcp', 'port': 22} | |
113 | ||
114 | service_cache_1 = PluginBase.get_host_service_cache_id(host_cache_id_1, service_1) | |
115 | service_cache_2 = PluginBase.get_host_service_cache_id(host_cache_id_2, service_2) | |
116 | ||
117 | vuln_2 = {'name': 'test', 'desc': 'test', 'severity': 'high', 'method': 'GET'} | |
118 | vuln_1 = {'name': 'test', 'desc': 'test', 'severity': 'low', 'method': 'GET'} | |
119 | ||
120 | cache_1 = PluginBase.get_service_vuln_cache_id(host_cache_id_1, service_cache_1, vuln_1) | |
121 | cache_2 = PluginBase.get_service_vuln_cache_id(host_cache_id_2, service_cache_2, vuln_2) | |
122 | ||
123 | assert cache_1 != cache_2⏎ |
0 | import os | |
1 | import socket | |
2 | import json | |
3 | import pytest | |
4 | from faraday_plugins.plugins.manager import PluginsManager, ReportAnalyzer | |
5 | from faraday_plugins.plugins.plugin import PluginBase | |
6 | from faraday.server.api.modules.bulk_create import BulkCreateSchema | |
7 | ||
8 | BLACK_LIST = [ | |
9 | 'LICENSE', | |
10 | 'README.md', | |
11 | '.gitignore', | |
12 | '.gitkeep', | |
13 | 'faraday_plugins_tests', | |
14 | ||
15 | ] | |
16 | ||
17 | plugins_manager = PluginsManager() | |
18 | analyzer = ReportAnalyzer(plugins_manager) | |
19 | ||
20 | PLUGINS_CACHE = {} | |
21 | REPORTS_JSON_CACHE = {} | |
22 | ||
23 | SKIP_IP_PLUGINS = ['Fortify'] | |
24 | ||
25 | REPORTS_SUMMARY_DIR = './report-collection/faraday_plugins_tests' | |
26 | ||
27 | ||
28 | def get_plugin_from_cache(report_file): | |
29 | plugin = PLUGINS_CACHE.get(report_file) | |
30 | if not plugin: | |
31 | plugin: PluginBase = analyzer.get_plugin(report_file) | |
32 | if plugin: | |
33 | save_plugin_in_cache(report_file, plugin) | |
34 | return plugin | |
35 | ||
36 | ||
37 | def save_plugin_in_cache(report_file, plugin): | |
38 | if report_file not in PLUGINS_CACHE: | |
39 | PLUGINS_CACHE[report_file] = plugin | |
40 | ||
41 | ||
42 | def get_report_json_from_cache(report_file): | |
43 | plugin_json = REPORTS_JSON_CACHE.get(report_file) | |
44 | if not plugin_json: | |
45 | plugin = get_plugin_from_cache(report_file) | |
46 | if plugin: | |
47 | plugin.processReport(report_file) | |
48 | plugin_json = json.loads(plugin.get_json()) | |
49 | REPORTS_JSON_CACHE[report_file] = plugin_json | |
50 | else: | |
51 | plugin = get_plugin_from_cache(report_file) | |
52 | return plugin, plugin_json | |
53 | ||
54 | ||
55 | def list_report_files(): | |
56 | report_filenames = os.walk(REPORTS_SUMMARY_DIR) | |
57 | for root, directory, filenames in report_filenames: | |
58 | if '.git' in directory or 'faraday_plugins_tests' in directory: | |
59 | continue | |
60 | for filename in filenames: | |
61 | if filename in BLACK_LIST: | |
62 | continue | |
63 | if '.git' in root: | |
64 | continue | |
65 | if not filename.endswith('_summary.json'): | |
66 | yield os.path.join(root, filename) | |
67 | ||
68 | ||
69 | def is_valid_ipv4_address(address): | |
70 | try: | |
71 | socket.inet_pton(socket.AF_INET, address) | |
72 | except AttributeError: # no inet_pton here, sorry | |
73 | try: | |
74 | socket.inet_aton(address) | |
75 | except socket.error: | |
76 | return False | |
77 | return address.count('.') == 3 | |
78 | except socket.error: # not a valid address | |
79 | return False | |
80 | return True | |
81 | ||
82 | ||
83 | def is_valid_ipv6_address(address): | |
84 | try: | |
85 | socket.inet_pton(socket.AF_INET6, address) | |
86 | except socket.error: # not a valid address | |
87 | return False | |
88 | return True | |
89 | ||
90 | ||
91 | def is_valid_ip_address(address): | |
92 | return (is_valid_ipv4_address(address) or is_valid_ipv6_address(address)) | |
93 | ||
94 | def test_reports_collection_exists(): | |
95 | assert os.path.isdir(REPORTS_SUMMARY_DIR) is True, "Please clone the report-collection repo!" | |
96 | ||
97 | @pytest.mark.parametrize("report_filename", list_report_files()) | |
98 | def test_autodetected_on_all_report_collection(report_filename): | |
99 | plugin: PluginBase = get_plugin_from_cache(report_filename) | |
100 | assert plugin, report_filename | |
101 | ||
102 | ||
103 | @pytest.mark.parametrize("report_filename", list_report_files()) | |
104 | def test_schema_on_all_reports(report_filename): | |
105 | plugin, plugin_json = get_report_json_from_cache(report_filename) | |
106 | if plugin_json: | |
107 | serializer = BulkCreateSchema() | |
108 | res = serializer.loads(json.dumps(plugin_json)) | |
109 | assert set(res.keys()) == {'hosts', 'command'} | |
110 | ||
111 | ||
112 | ||
113 | ||
114 | @pytest.mark.skip(reason="Skip validate ip format") | |
115 | @pytest.mark.parametrize("report_filename", list_report_files()) | |
116 | def test_host_ips_all_reports(report_filename): | |
117 | plugin, plugin_json = get_report_json_from_cache(report_filename) | |
118 | if plugin_json: | |
119 | if plugin.id not in SKIP_IP_PLUGINS: | |
120 | for host in plugin_json['hosts']: | |
121 | assert is_valid_ip_address(host['ip']) is True | |
122 | ||
123 | ||
124 | @pytest.mark.parametrize("report_filename", list_report_files()) | |
125 | def test_summary_reports(report_filename): | |
126 | plugin, plugin_json = get_report_json_from_cache(report_filename) | |
127 | if plugin_json: | |
128 | summary_file = f"{os.path.splitext(report_filename)[0]}_summary.json" | |
129 | assert os.path.isfile(summary_file) is True | |
130 | with open(summary_file) as f: | |
131 | saved_summary = json.load(f) | |
132 | summary = plugin.get_summary() | |
133 | vuln_hashes = set(summary['vuln_hashes']) | |
134 | saved_vuln_hashes = set(saved_summary.get('vuln_hashes', [])) | |
135 | assert summary['hosts'] == saved_summary['hosts'] | |
136 | assert summary['services'] == saved_summary['services'] | |
137 | assert summary['hosts_vulns'] == saved_summary['hosts_vulns'] | |
138 | assert summary['services_vulns'] == saved_summary['services_vulns'] | |
139 | assert summary['severity_vulns'] == saved_summary['severity_vulns'] | |
140 | assert vuln_hashes == saved_vuln_hashes | |
141 | ||
142 | ||
143 | @pytest.mark.performance | |
144 | @pytest.mark.parametrize("report_filename", list_report_files()) | |
145 | def test_detected_tools_on_all_report_collection(report_filename, benchmark): | |
146 | plugins_manager = PluginsManager() | |
147 | analyzer = ReportAnalyzer(plugins_manager) | |
148 | plugin: PluginBase = analyzer.get_plugin(report_filename) | |
149 | if not plugin: | |
150 | return | |
151 | assert plugin, report_filename | |
152 | benchmark(plugin.processReport, report_filename) | |
153 | plugin_json = json.loads(plugin.get_json()) | |
154 | assert "hosts" in plugin_json | |
155 | assert "command" in plugin_json | |
156 | assert os.path.isfile(report_filename) is True | |
157 |