Skip to content

Commit

Permalink
Merge branch 'tkt_31_add_tags' into 'dev'
Browse files Browse the repository at this point in the history
add tags support

Closes #31

See merge request faradaysec/faraday-cli!35
  • Loading branch information
Nicolas Rebagliati committed Apr 16, 2021
2 parents 4cab738 + 4d6a2e5 commit 432edff
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 23 deletions.
1 change: 1 addition & 0 deletions CHANGELOG/current/add_tags_support.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[MOD] Add support for tags
13 changes: 10 additions & 3 deletions docs/docs/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Password:
Saving config
✔ Authenticated with faraday: http://localhost:5985
```
*Optional rguments:*
*Optional arguments:*

| Syntax | Description |
|:----- |------: |
Expand Down Expand Up @@ -418,7 +418,11 @@ $ faraday-cli process_report $HOME/Downloads/openvas-report.xml
| Syntax | Description |
|:----- |------: |
| `-w WORKSPACE_NAME` | Workspace name |
| `--plugin-id` | Plugin ID (force detection) |
| `--plugin-id PLUGIN_ID` | Plugin ID (force detection) |
| `-j/--json-output` | Show output in json (dont send it to faraday) |
| `--tag-vuln TAG_VULN` | Tag to add to vulnerabilities |
| `--tag-host TAG_HOST` | Tag to add to hosts |
| `--tag-service TAG_SERVICE` | Tag to add to services |

### process_tool

Expand Down Expand Up @@ -458,8 +462,11 @@ Nmap done: 1 IP address (1 host up) scanned in 11.12 seconds
| Syntax | Description |
|:----- |------: |
| `-w WORKSPACE_NAME` | Workspace name |
| `--plugin-id` | Plugin ID (force detection) |
| `--plugin-id PLUGIN_ID` | Plugin ID (force detection) |
| `-j/--json-output` | Show output in json (dont send it to faraday) |
| `--tag-vuln TAG_VULN` | Tag to add to vulnerabilities |
| `--tag-host TAG_HOST` | Tag to add to hosts |
| `--tag-service TAG_SERVICE` | Tag to add to services |

## Run tools like a shell in faraday-cli

Expand Down
46 changes: 34 additions & 12 deletions faraday_cli/shell/modules/reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import getpass
import json

from faraday_cli.shell.utils import apply_tags
from cmd2 import with_argparser, with_default_category, CommandSet, style
from faraday_cli.config import active_config

Expand All @@ -28,6 +29,24 @@ def __init__(self):
action="store_true",
help="Show output in json (dont send to faraday)",
)
report_parser.add_argument(
"--tag-vuln",
type=str,
help="Tag to add to vulnerabilities",
required=False,
)
report_parser.add_argument(
"--tag-host",
type=str,
help="Tag to add to hosts",
required=False,
)
report_parser.add_argument(
"--tag-service",
type=str,
help="Tag to add to services",
required=False,
)
report_parser.add_argument("report_path", help="Path of the report file")

@with_argparser(report_parser, preserve_quotes=True)
Expand All @@ -37,19 +56,20 @@ def do_process_report(self, args):
if not report_path.is_file():
self._cmd.perror(f"File {report_path} dont exists")
return
if not args.workspace_name:
if active_config.workspace:
workspace_name = active_config.workspace
if not args.json_output:
if not args.workspace_name:
if active_config.workspace:
workspace_name = active_config.workspace
else:
self._cmd.perror("No active Workspace")
return
else:
self._cmd.perror("No active Workspace")
workspace_name = args.workspace_name
if not self._cmd.api_client.is_workspace_valid(workspace_name):
self._cmd.perror(f"Invalid workspace: {workspace_name}")
return
else:
workspace_name = args.workspace_name
if not self._cmd.api_client.is_workspace_valid(workspace_name):
self._cmd.perror(f"Invalid workspace: {workspace_name}")
return
else:
destination_workspace = workspace_name
else:
destination_workspace = workspace_name
if args.plugin_id:
plugin = self._cmd.plugins_manager.get_plugin(args.plugin_id)
if not plugin:
Expand All @@ -74,7 +94,9 @@ def do_process_report(self, args):
plugin.processReport(
report_path.absolute().as_posix(), getpass.getuser()
)
report_json = plugin.get_data()
report_json = apply_tags(
plugin.get_data(), args.tag_host, args.tag_service, args.tag_vuln
)
if args.json_output:
self._cmd.poutput(json.dumps(report_json, indent=4))
else:
Expand Down
45 changes: 37 additions & 8 deletions faraday_cli/shell/modules/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,43 @@ def __init__(self):
action="store_true",
help="Show output in json (dont send it to faraday)",
)

tool_parser.add_argument(
"--tag-vuln",
type=str,
help="Tag to add to vulnerabilities",
required=False,
)
tool_parser.add_argument(
"--tag-host",
type=str,
help="Tag to add to hosts",
required=False,
)
tool_parser.add_argument(
"--tag-service",
type=str,
help="Tag to add to services",
required=False,
)
tool_parser.add_argument("command", help="Command of the tool to process")

@with_argparser(tool_parser, preserve_quotes=False)
def do_process_tool(self, args):
"""Process Tool execution in Faraday"""
if not args.workspace_name:
if active_config.workspace:
workspace_name = active_config.workspace
if not args.json_output:
if not args.workspace_name:
if active_config.workspace:
workspace_name = active_config.workspace
else:
self._cmd.perror("No active Workspace")
return
else:
self._cmd.perror("No active Workspace")
workspace_name = args.workspace_name
if not self._cmd.api_client.is_workspace_valid(workspace_name):
self._cmd.perror(f"Invalid workspace: {workspace_name}")
return
else:
workspace_name = args.workspace_name
else:
destination_workspace = workspace_name

if args.plugin_id:
plugin = self._cmd.plugins_manager.get_plugin(args.plugin_id)
Expand Down Expand Up @@ -72,12 +95,18 @@ def do_process_tool(self, args):
f"{self.emojis['cross']} Command execution error!!"
)
else:
command_json = utils.apply_tags(
command_json,
args.tag_host,
args.tag_service,
args.tag_vuln,
)
if args.json_output:
self._cmd.poutput(json.dumps(command_json, indent=4))
else:
self._cmd.data_queue.put(
{
"workspace": workspace_name,
"workspace": destination_workspace,
"json_data": command_json,
}
)
Expand Down
18 changes: 18 additions & 0 deletions faraday_cli/shell/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,21 @@ def run_tool(plugin, user, command, show_output=True):
return plugin.get_data()
else:
return None


def apply_tags(data, tag_host, tag_service, tag_vuln):
if tag_vuln or tag_host or tag_service:
for host in data["hosts"]:
if tag_host:
host["tags"].append(tag_host)
if tag_vuln:
for vuln in host["vulnerabilities"]:
vuln["tags"].append(tag_vuln)
if tag_vuln or tag_service:
for service in host["services"]:
if tag_service:
service["tags"].append(tag_service)
if tag_vuln:
for vuln in service["vulnerabilities"]:
vuln["tags"].append(tag_vuln)
return data

0 comments on commit 432edff

Please sign in to comment.