Skip to content

Commit 42b244c

Browse files
author
Nicolas Rebagliati
committed
Merge branch 'tkt_71_add_soport_for_tags_plugins' into 'dev'
Replace the apply_tag function with plugins parameters Closes #71 See merge request faradaysec/faraday-cli!70
2 parents fb6f4df + f201216 commit 42b244c

File tree

6 files changed

+54
-40
lines changed

6 files changed

+54
-40
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Replace the apply_tag function with plugins parameters

faraday_cli/api_client/faraday_api.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,9 @@ def run_executor(
300300
args,
301301
ignore_info,
302302
hostname_resolution,
303+
vuln_tag,
304+
host_tag,
305+
service_tag,
303306
):
304307
body = {
305308
"executor_data": {
@@ -310,6 +313,9 @@ def run_executor(
310313
"workspaces_names": workspaces_names,
311314
"ignore_info": ignore_info,
312315
"hostname_resolution": hostname_resolution,
316+
"vuln_tag": vuln_tag,
317+
"host_tag": host_tag,
318+
"service_tag": service_tag,
313319
}
314320
response = self.faraday_api.agent.run(agent_id, body=body)
315321
return response.body

faraday_cli/shell/modules/agent.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,13 +163,43 @@ def get_agent(self, args: argparse.Namespace):
163163
type=str,
164164
help="Workspace name",
165165
)
166+
run_executor_parser.add_argument(
167+
"--vuln-tag",
168+
type=str,
169+
help="Tag to add to vulnerabilities",
170+
required=False,
171+
action="append",
172+
default=[],
173+
)
174+
run_executor_parser.add_argument(
175+
"--host-tag",
176+
type=str,
177+
help="Tag to add to hosts",
178+
required=False,
179+
action="append",
180+
default=[],
181+
)
182+
run_executor_parser.add_argument(
183+
"--service-tag",
184+
type=str,
185+
help="Tag to add to services",
186+
required=False,
187+
action="append",
188+
default=[],
189+
)
166190

167191
@cmd2.as_subcommand_to(
168192
"agent", "run", run_executor_parser, help="run an executor"
169193
)
170194
def run_executor(self, args):
171195
"""Run executor"""
172196
ask_for_parameters = False
197+
if isinstance(args.vuln_tag, str):
198+
args.vuln_tag = [args.vuln_tag]
199+
if isinstance(args.host_tag, str):
200+
args.host_tag = [args.host_tag]
201+
if isinstance(args.service_tag, str):
202+
args.service_tag = [args.service_tag]
173203
if args.stdin:
174204
executor_params = sys.stdin.read()
175205
else:
@@ -278,6 +308,9 @@ def run_executor(self, args):
278308
json.loads(executor_params),
279309
self._cmd.ignore_info_severity,
280310
self._cmd.hostname_resolution,
311+
args.vuln_tag,
312+
args.host_tag,
313+
args.service_tag,
281314
)
282315
except Exception as e:
283316
self._cmd.perror(str(e))

faraday_cli/shell/modules/reports.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import cmd2
77
from cmd2 import Fg as COLORS
88
from faraday_cli.config import active_config
9-
from faraday_cli.shell.utils import apply_tags
109

1110

1211
@cmd2.with_default_category("Tools Reports")
@@ -36,21 +35,21 @@ def __init__(self):
3635
help="Show output in json (dont send to faraday)",
3736
)
3837
report_parser.add_argument(
39-
"--tag-vuln",
38+
"--vuln-tag",
4039
type=str,
4140
help="Tag to add to vulnerabilities",
4241
required=False,
4342
action="append",
4443
)
4544
report_parser.add_argument(
46-
"--tag-host",
45+
"--host-tag",
4746
type=str,
4847
help="Tag to add to hosts",
4948
required=False,
5049
action="append",
5150
)
5251
report_parser.add_argument(
53-
"--tag-service",
52+
"--service-tag",
5453
type=str,
5554
help="Tag to add to services",
5655
required=False,
@@ -117,18 +116,18 @@ def process_report(self, args: argparse.Namespace):
117116
fg=COLORS.GREEN,
118117
)
119118
)
119+
plugin.vuln_tag = args.vuln_tag
120+
plugin.host_tag = args.host_tag
121+
plugin.service_tag = args.service_tag
120122
plugin.processReport(
121123
report_path.absolute().as_posix(), getpass.getuser()
122124
)
123-
report_json = apply_tags(
124-
plugin.get_data(), args.tag_host, args.tag_service, args.tag_vuln
125-
)
126125
if args.json_output:
127-
self._cmd.poutput(json.dumps(report_json, indent=4))
126+
self._cmd.poutput(json.dumps(plugin.get_data(), indent=4))
128127
else:
129128
self._cmd.data_queue.put(
130129
{
131130
"workspace": destination_workspace,
132-
"json_data": report_json,
131+
"json_data": plugin.get_data(),
133132
}
134133
)

faraday_cli/shell/modules/tools.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,21 @@ def __init__(self):
3434
help="Show output in json (dont send it to faraday)",
3535
)
3636
tool_parser.add_argument(
37-
"--tag-vuln",
37+
"--vuln-tag",
3838
type=str,
3939
help="Tag to add to vulnerabilities",
4040
required=False,
4141
action="append",
4242
)
4343
tool_parser.add_argument(
44-
"--tag-host",
44+
"--host-tag",
4545
type=str,
4646
help="Tag to add to hosts",
4747
required=False,
4848
action="append",
4949
)
5050
tool_parser.add_argument(
51-
"--tag-service",
51+
"--service-tag",
5252
type=str,
5353
help="Tag to add to services",
5454
required=False,
@@ -108,6 +108,9 @@ def process_tool(self, args):
108108
fg=COLORS.GREEN,
109109
)
110110
)
111+
plugin.vuln_tag = args.vuln_tag
112+
plugin.host_tag = args.host_tag
113+
plugin.service_tag = args.service_tag
111114
show_command_output = not args.json_output
112115
command_json = utils.run_tool(
113116
plugin,
@@ -120,12 +123,6 @@ def process_tool(self, args):
120123
f"{self._cmd.emojis['cross']} Command execution error!!"
121124
)
122125
else:
123-
command_json = utils.apply_tags(
124-
command_json,
125-
args.tag_host,
126-
args.tag_service,
127-
args.tag_vuln,
128-
)
129126
if args.json_output:
130127
self._cmd.poutput(json.dumps(command_json, indent=4))
131128
else:

faraday_cli/shell/utils.py

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -167,25 +167,3 @@ def run_tool(plugin, user, command, show_output=True):
167167
return plugin.get_data()
168168
else:
169169
return None
170-
171-
172-
def apply_tags(data, host_tags, service_tags, vuln_tags):
173-
if vuln_tags or host_tags or service_tags:
174-
for host in data["hosts"]:
175-
if host_tags:
176-
for tag in host_tags:
177-
host["tags"].append(tag)
178-
if vuln_tags:
179-
for vuln in host["vulnerabilities"]:
180-
for tag in vuln_tags:
181-
vuln["tags"].append(tag)
182-
if vuln_tags or service_tags:
183-
for service in host["services"]:
184-
if service_tags:
185-
for tag in service_tags:
186-
service["tags"].append(tag)
187-
if vuln_tags:
188-
for vuln in service["vulnerabilities"]:
189-
for tag in vuln_tags:
190-
vuln["tags"].append(tag)
191-
return data

0 commit comments

Comments
 (0)