Skip to content
Snippets Groups Projects
Commit 9490708a authored by Gioacchino Vino's avatar Gioacchino Vino
Browse files

Added logic accepted/know issues during oid validation

parent 8d5c9e62
No related branches found
No related tags found
1 merge request!147Debug paas ci
Pipeline #169149 passed
......@@ -449,8 +449,10 @@ class Task:
def get_report_info(self,
accepted_issues: List[str],
known_issues: List[str]) -> Dict:
known_issues: List[str]) -> Tuple[Dict,List[str]]:
report = dict()
accepted_oids = []
new_oids = []
res = self.client.get_report(self.report_id,
report_format_id=ReportFormats.anonymous_xml,
ignore_pagination=True,
......@@ -466,16 +468,18 @@ class Task:
msg = f"Detected oid: {o}, severity: {s}, threat: {t} and port: {p}"
if s >= 4: # If severity is not negligible
if o in accepted_issues:
accepted_oids.append(msg)
msg += " => ACCEPTED"
logging.debug(msg)
else:
if o in known_issues:
msg += " => DROPPED (not accepted but known)"
logging.debug(msg)
continue
else:
new_oids.append(msg)
msg += " => NEW (not accepted and not known)"
logging.debug(msg)
logging.debug(msg)
if p in report:
if s > report[p]['severity']:
report[p] = {'severity': s, 'threat': t}
......@@ -485,7 +489,8 @@ class Task:
glob_severity = s
glob_threat = t
report['global'] = {'threat': glob_threat, 'severity': glob_severity}
return report
return report, accepted_oids, new_oids
class GVMClient():
"""
......
......@@ -86,6 +86,9 @@ targets = list()
port_lists = list()
reports = dict()
accepted_oids = []
new_oids = []
for host,ports in endpoints.items():
logging.info(f"endpoint: {host}:{ports}")
......@@ -94,6 +97,7 @@ for host,ports in endpoints.items():
port_list_name = f"{auth_name}_pl_{dep_name}_{host}"
report_filename = f"{output_dir}/{host}-report"
summary_filename = f"{output_dir}/summary-report.json"
oids_filename = f"{output_dir}/oids.txt"
# Create PortList obj related to endpoint
port_list = PortList(client = gvm.client,
......@@ -124,7 +128,10 @@ for host,ports in endpoints.items():
filename = f"{report_filename}.pdf")
task.save_report(format = ReportFormats.txt,
filename = f"{report_filename}.txt")
reports[host] = task.get_report_info(accepted_issues, known_issues)
reports[host], task_accepted_oids, task_new_oids = \
task.get_report_info(accepted_issues, known_issues)
accepted_oids += task_accepted_oids
new_oids += task_new_oids
else:
reports[host] = {'global': {"severity": -1, "threat": f"Scan Error. task.id: {task.id}"} }
......@@ -137,4 +144,16 @@ logging.info(pretty_json(reports))
# Write global reports on file
with open(summary_filename, "w") as f:
f.write(json.dumps(reports))
\ No newline at end of file
f.write(json.dumps(reports))
# Writing oids details on file
if len(accepted_oids) > 1:
with open(oids_filename, "a") as f:
f.write("ACCEPTED OIDs\n")
f.writelines([msg + "\n" for msg in accepted_oids])
f.write("\n")
if len(accepted_oids) > 1:
with open(oids_filename, "a") as f:
f.write("NEW OIDs\n")
f.writelines([msg + "\n" for msg in new_oids])
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment