Skip to content

Commit

Permalink
Change: Improve application-detection requests,
Browse files Browse the repository at this point in the history
The application-detection script now requests details for each report
individually with minimum results, which is usually faster for gathering
the host data and ensures all hosts are included.

Also, only hosts where a matching app was found are output.
  • Loading branch information
timopollmeier committed Sep 28, 2023
1 parent e3a363c commit 6f6e2a7
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions scripts/application-detection.gmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,18 @@ def check_args(args):


def print_assets(gmp, appname):
res = gmp.get_reports(details=True)
res = gmp.get_reports(details=False)

reports = res.xpath("/get_reports_response/report")
for report in reports:
report_id = report.attrib["id"]
print_assets_for_host(gmp, appname, report_id)


def print_assets_for_host(gmp, appname, report_id):
res = gmp.get_report(
report_id, details=True, filter_string="rows=1 result_hosts_only=0"
)

hosts = res.xpath("/get_reports_response/report/report/host")

Expand All @@ -56,11 +67,14 @@ def print_assets(gmp, appname):
else:
hostname = hostname[0]

print(f"{ip} ({hostname})")
apps = host.xpath(
'detail/name[text() = "App"]/../value['
f'contains(text(), "{appname}")]/text()'
)
if len(apps) == 0:
continue

print(f"{ip} ({hostname})")
for app in apps:
print("\t" + app)
print("\n")
Expand Down

0 comments on commit 6f6e2a7

Please sign in to comment.