From 7eb1cf16a87fe42f54236dfa047a6f9a71026402 Mon Sep 17 00:00:00 2001 From: martinboller Date: Wed, 17 Apr 2024 21:59:12 +0200 Subject: [PATCH 1/7] Additional and changed scripts for maintaining Greenbone Scanner --- scripts/USAGE.md | 231 +++++++++++++ scripts/clean-sensor.gmp.py | 150 +++++++-- scripts/create-alerts-from-csv.gmp.py | 254 ++++++++++++++ scripts/create-credentials-from-csv.gmp.py | 224 +++++++++++++ scripts/create-filters-from-csv.gmp.py | 216 ++++++++++++ scripts/create-report-format-from-csv.gmp.py | 181 ++++++++++ scripts/create-schedules-from-csv.gmp.py | 169 ++++++++++ scripts/create-tags-from-csv.gmp.py | 327 +++++++++++++++++++ scripts/create-targets-from-csv.gmp.py | 215 ++++++++++++ scripts/create-tasks-from-csv.gmp.py | 296 +++++++++++++++++ scripts/dummy_def.gmp.py | 12 + scripts/empty-trash.gmp.py | 45 +++ scripts/export-csv-report.gmp.py | 102 ++++++ scripts/export-pdf-report.gmp.py | 17 +- scripts/export-xml-report.gmp.py | 102 ++++++ scripts/list-alerts.gmp.py | 70 ++++ scripts/list-credentials.gmp.py | 79 +++++ scripts/list-feeds.gmp.py | 68 ++++ scripts/list-filters.gmp.py | 63 ++++ scripts/list-groups.gmp.py | 62 ++++ scripts/list-policies.gmp.py | 62 ++++ scripts/list-portlists.gmp.py | 64 ++++ scripts/list-report-formats.gmp.py | 61 ++++ scripts/list-reports.gmp.py | 153 +++++++++ scripts/list-roles.gmp.py | 62 ++++ scripts/list-scan-configs.gmp.py | 62 ++++ scripts/list-scanners.gmp.py | 62 ++++ scripts/list-schedules.gmp.py | 64 ++++ scripts/list-tags.gmp.py | 64 ++++ scripts/list-targets.gmp.py | 66 ++++ scripts/list-tasks.gmp.py | 27 +- scripts/list-tickets.gmp.py | 70 ++++ scripts/list-users.gmp.py | 63 ++++ scripts/start-scans-from-csv.py | 157 +++++++++ scripts/stop-all-scans.gmp.py | 53 +++ scripts/stop-scans-from-csv.py | 160 +++++++++ 36 files changed, 4089 insertions(+), 44 deletions(-) create mode 100644 scripts/USAGE.md create mode 100755 scripts/create-alerts-from-csv.gmp.py create mode 100755 scripts/create-credentials-from-csv.gmp.py create mode 100755 scripts/create-filters-from-csv.gmp.py create mode 100755 scripts/create-report-format-from-csv.gmp.py create mode 100755 scripts/create-schedules-from-csv.gmp.py create mode 100755 scripts/create-tags-from-csv.gmp.py create mode 100755 scripts/create-targets-from-csv.gmp.py create mode 100755 scripts/create-tasks-from-csv.gmp.py create mode 100644 scripts/dummy_def.gmp.py create mode 100755 scripts/empty-trash.gmp.py create mode 100755 scripts/export-csv-report.gmp.py create mode 100755 scripts/export-xml-report.gmp.py create mode 100755 scripts/list-alerts.gmp.py create mode 100755 scripts/list-credentials.gmp.py create mode 100755 scripts/list-feeds.gmp.py create mode 100755 scripts/list-filters.gmp.py create mode 100755 scripts/list-groups.gmp.py create mode 100755 scripts/list-policies.gmp.py create mode 100755 scripts/list-portlists.gmp.py create mode 100755 scripts/list-report-formats.gmp.py create mode 100755 scripts/list-reports.gmp.py create mode 100755 scripts/list-roles.gmp.py create mode 100755 scripts/list-scan-configs.gmp.py create mode 100755 scripts/list-scanners.gmp.py create mode 100755 scripts/list-schedules.gmp.py create mode 100755 scripts/list-tags.gmp.py create mode 100755 scripts/list-targets.gmp.py create mode 100755 scripts/list-tickets.gmp.py create mode 100755 scripts/list-users.gmp.py create mode 100755 scripts/start-scans-from-csv.py create mode 100755 scripts/stop-all-scans.gmp.py create mode 100755 scripts/stop-scans-from-csv.py diff --git a/scripts/USAGE.md b/scripts/USAGE.md new file mode 100644 index 00000000..ca4fe826 --- /dev/null +++ b/scripts/USAGE.md @@ -0,0 +1,231 @@ +# Greenbone Vulnerability Manager Python scripts + +## Python scripts that can be used to configure your Greenbone Community Edition Scanner + +[API Reference for GVM 22.5](https://docs.greenbone.net/API/GMP/gmp-22.5.html) + +[Python GVM API](https://greenbone.github.io/python-gvm/api/api.html) + +## Running Python GVM Scripts +For details on Python GVM, please refer to https://gvm-tools.readthedocs.io/en/latest/scripting.html#gvm-scripts, but for these scripts, use +- gvm-script --gmp-username *admin-user* --gmp-password *password* socket *script-name* - Example: +- gvm-script --gmp-username admin --gmp-password SecretPassword socket list-alerts.gmp.py +When you just want to get the XML from Greenbone to look for values/value names, it's easy to use gvm-cli, like this: +- gvm-cli --gmp-username *admin-user* --gmp-password *password* socket --xml="" + +## Python Scripts in this repo: +### clean-sensor.gmp.py +**Script provided by Greenbone as part of GVM-Tools. Used when cleaning up after testing scripts (or starting over)** +- Usage: gvm-script --gmp-username admin --gmp-password '0f6fa69b-32bb-453a-9aa4-b8c9e56b3d00' socket clean-sensor.gmp.py +- clean-sensor now cleans alerts, filters, schedules and tags too. + +### create-Alerts-from-csv.gmp.py +**Creates alerts as specified in a csv-file. See alerts.csv for file format/contents.** +- Usage: gvm-script --gmp-username *admin-user* --gmp-password *password* socket create-alerts-from-csv.gmp.py alerts.csv +- For SMB Alerts use something like %N_%CT%z in the naming of the report, as shown in the example alerts.csv +- %N is the name for the object or the associated task for reports, %C is the creation date in the format YYYYMMDD, and %c is the creation time in the format HHMMSS. +- The script only support EMAIL and SMB Alerts, please note that the fields are quite different between the two alert types, but refer to the sample alerts.csv +- The CSV must starts with name, type (EMAIL or SMB). The remaining fields then depend on the type chosen, specifically: +- EMAIL; *senders email*, *recipients email*, *mail subject*, *message body*, *notice type* (0=Report in message 1=Simple Notice or 2=Attach Report), *Report Type* (e.g. CSV Results), *Status* (Done, Requested) +- SMB; *SMB Credentials*,*SMB Share Path*,*Report Name*, *Report Folder* (if not stored in the root of the share), *Not used*, *Report Type* (e.g. CSV Results), *Status* (Done, Requested) +- A simple example below with 1 EMAIL alert and 1 SMB Alert. +Alert_EMAIL_Stop,EMAIL,"martin@example.org","noc@example.org","Message Subject","Message Body",1,"CSV Results","Stop Requested" +Alert_SMB_Done,SMB,"Cred_Storage_SMB","\\smbserver\share","%N_%CT%cZ","Reports",,"CSV Results","Done" + +**Note**: This script relies on credentials as/if specified in alerts.csv as well as a working SMTP server on the Greenbone primary server. If you're using SMB add the required credentials first using [create-credentials-from-csv.gmp.py](#create-credentials-from-csvgmppy). + + +### create-schedules-from-csv.gmp.py +**Creates schedules as specified in a csv-file. See schedules.csv for file format/contents.** +Usage: gvm-script --gmp-username *admin-user* --gmp-password *password* socket create-schedules-from-csv.gmp.py ./schedules.csv +**Note**: create schedules, then credentials, then targets, then tasks and make sure to use the same names between the input csv-files. +The sample files should serve as examples, however a short explanation of a VCALENDAR stream exported from Greenbone below¹. + +Example Key:Value pair | Comment +---|--- +BEGIN:VCALENDAR | Begin VCalendar Entry +VERSION:2.0 | iCalendar Version number +PRODID:-//Greenbone.net//NONSGML Greenbone Security Manager 23.1.0//EN | As generated by Greenbone replace with something else if you want to +BEGIN:VEVENT | Start of Vevent +DTSTART:20231125T220000Z | Start date +DURATION:PT1H | Duration of scan. PT0S means "Entire Operation". S = seconds, M = minutes, H = hours +RRULE:FREQ=HOURLY;INTERVAL=4 | Frequency; Yearly, Monthly, Weekly, Hourly. Optionally Interval withs same unit +DTSTAMP:20231125T212042Z | Date stamp created +END:VEVENT | End Vevent +END:VCALENDAR | End VCalendar Entry + +¹ See also https://www.rfc-editor.org/rfc/rfc5545.txt Internet Calendaring and Scheduling Core Object Specification (iCalendar) + +### create-credentials-from-csv.gmp.py +**Creates credentials as specified in a csv-file. See credentials.csv for file format/contents.** +Usage: gvm-script --gmp-username *admin-user* --gmp-password *password* socket create-credentials-from-csv.gmp.py ./credentials.csv +**Note**: create schedules, then credentials, then targets, then tasks and make sure to use the same names between the input csv-files. +The sample files should serve as an example. + +### create-filters-from-csv.gmp.py +**Creates filters as specified in a csv-file. See filters.csv for file format/contents.** +- Usage: gvm-script --gmp-username *admin-user* --gmp-password *password* socket create-filters-from-csv.gmp.py ./filters.csv +- CSV-file; filterType, filterName, filterDescription, filterTerm, where + - filterType is one of Alert, Config (scan-config), Credential, Report, Scanner, Schedule, Target, or Task. + - filterName is the name of the filter. + - filterDescription is your description of the filter. + - FilterTerm is the actual term used to define the filter, such as \~Labnet. + +### create-tags-from-csv.gmp.py +**Creates tags as specified in a csv-file. See tags.csv for file format/contents.** +- Usage: gvm-script --gmp-username *admin-user* --gmp-password *password* socket create-tags-from-csv.gmp.py ./tags.csv +- May contain up to 10 resources to assign to tag. Currently only creates tags for Credential, Target, and Tasks +- Use tag:*searchforthis* as filter. Example: *tag:bsecure* +- Will add reports when I've figured out if tags are really dynamic and a filter will do it for new reports. + +### create-targets-from-csv.gmp.py +**Creates targets as specified in a csv-file. See targets.csv for file format/contents.** +- Usage: gvm-script --gmp-username *admin-user* --gmp-password *password* socket create-targets-from-csv.gmp.py ./targets.csv +- Alive test can be: + +No | Alive Test | Notes +---|---|--- +1 | Scan Config Default | ICMP Ping is used by default with the Built-in Scan Configurations +2 | ICMP Ping | ICMP echo request and echo reply messages +3 | TCP-ACK Service Ping | Sends TCP packets with only the ACK bit set. Target is required by [RFC 793](http://www.rfc-editor.org/rfc/rfc793.txt) to respond with a RST packet +4 | TCP-SYN Service Ping | SYN only scans (never sends an ACK even if target replies with SYN/ACK) +5 | ICMP & TCP-ACK Service Ping | ICMP & TCP-ACK tests combined +6 | ICMP & ARP Ping | ICMP Ping & sends a broadcast ARP request to solicit a reply from the host that uses the specified IP address +7 | TCP-ACK Service & ARP Ping | TCP-ACK and ARP Ping combined +8 | ICMP, TCP-ACK Service & ARP Ping | ICMP, TCP-ACK, and ARP Ping combined +9 | Consider Alive | Consider the target alive. This may take considerably longer to finish. + + +### create-tasks-from-csv.gmp.py +**Creates tasks as specified in a csv-file. See tasks.csv for file format/contents** +- Usage: gvm-script --gmp-username *admin-user* --gmp-password *password* socket create-tasks-from-csv.gmp.py ./task.csv

+- Change Hosts Scan Ordering by changing #5 within CSV to Random, Sequential or Reverse in script. +- Specify up to 5 alerts in CSV, blanks will be discarded. +**Note**: Make sure that all other configurations that the tasks may rely on are already created, including alerts, schedules, credentials, and targets, +in other words if it is referenced in tasks.csv it must already exist. + +### empty-trash.gmp.py +- Does what is says on the tin, empties the trashcan in Greenbone. +- Use it when you're testing like crazy and have a trashcan with ~ a gazillion objects +- You can also just use gvm-cli --gmp-username *admin-user* --gmp-password *password* socket --pretty --xml="" + +### export-csv-report.gmp.py +**Requests the report specified and exports it as a csv formatted report locally.** +- Usage: gvm-script --gmp-username *admin-user* --gmp-password *password* socket export-csv-report.gmp.py *report_uuid* ./output.csv +- Get the *report_uuid* with list-reports.gmp.py or find it in the UI. If the output is not specified it will be named *report_uuid.csv* +- Note the only changes to this script is an added ignore_pagination=True, details=True to get the full report. + +### export-pdf-report.gmp.py +**Requests the report specified and exports it as a pdf formatted report locally.** +- Usage: gvm-script --gmp-username *admin-user* --gmp-password *password* socket export-pdf-report.gmp.py *report_uuid* ./output.pdf +- Get the *report_uuid* with list-reports.gmp.py or find it in the UI. If the output is not specified it will be named *report_uuid.pdf* +**Note**: the only changes to this script is an added ignore_pagination=True, details=True to get the full report. + +## list-alerts.gmp.py +**Lists all alerts configured with name and uuid.** +- Usage: gvm-script --gmp-username *admin-user* --gmp-password *password* socket list-alerts.gmp.py + +## list-credentials.gmp.py +**Lists all credentials configured with name and uuid.** +- Usage: gvm-script --gmp-username *admin-user* --gmp-password *password* socket list-credentials.gmp.py +- returns Credential uuid, Name, Type, & if insecure use is allowed + +### list-feeds.gmp.py +**Lists feeds and their status.** +- Usage: gvm-script --gmp-username *admin-user* --gmp-password *password* socket list-feeds.gmp.py + +### list-filters.gmp.py +**Lists filters.** +- Usage: gvm-script --gmp-username *admin-user* --gmp-password *password* socket list-filters.gmp.py +- Returns Filter Name, uuid, type, and the term (filter) + +### list-groups.gmp.py +**Lists all groups** +- Usage: gvm-script --gmp-username *admin-user* --gmp-password *password* socket list-groups.gmp.py +- Returns Group Name, uuid, members + +### list-policies.gmp.py +**Lists compliance policies.** +- Usage: gvm-script --gmp-username *admin-user* --gmp-password *password* socket list-policies.gmp.py + +### list-portlists.gmp.py +**Lists port lists.** +- Usage: gvm-script --gmp-username *admin-user* --gmp-password *password* socket list-portlists.gmp.py + +### list-report-formats.gmp.py +**Lists all report formats with name and uuid.** +- Usage: gvm-script --gmp-username *admin-user* --gmp-password *password* socket list-report-formats.gmp.py + +### list-reports.gmp.py +**Lists all reports that have specified status** +- Usage: gvm-script --gmp-username *admin-user* --gmp-password *password* socket list-reports.gmp.py *Status* +- where status is "All", "Requested", "Queued", "Interrupted", "Running", "Stop Requested", "Stopped", or "Done" +- Case matters, so "Done" or "Stopped" will work while "done" or "stopped" will not. +- Script now shows, in percentage, how far the scan/report is. +- There are no reports generated before at least one scan task has been started. + +### list-roles.gmp.py +**Lists all roles** +- Usage: gvm-script --gmp-username *admin-user* --gmp-password *password* socket list-roles.gmp.py +- Returns Role Name, uuid, members + +### list-scan-configs.gmp.py +**Lists all scan configs.** +- Usage: gvm-script --gmp-username *admin-user* --gmp-password *password* socket list-scan-configs.gmp.py + +### list-scanners.gmp.py +**Lists all scanners currently configured.** +- Usage: gvm-script --gmp-username *admin-user* --gmp-password *password* socket list-scanners.gmp.py +- Returns the scanners Name, uuid, & the host on which it resides (note CVE scanner does not return a host and sockets are local) + +## list-schedules.gmp.py +**Lists all schedules configured with name, uuid, timezone, and iCalendar information.** +- Usage: gvm-script --gmp-username *admin-user* --gmp-password *password* socket list-schedules.gmp.py + +### list-tags.gmp.py +**Lists all tags currently configured.** +- Usage: gvm-script --gmp-username *admin-user* --gmp-password *password* socket list-tags.gmp.py +- Returns Tag name, uuid, Modified Date, Value, Type, and Count of ressources assigned to tag. + +### list-targets.gmp.py +**Lists all targets currently configured.** +- Usage: gvm-script --gmp-username *admin-user* --gmp-password *password* socket list-targets.gmp.py +- No targets configured by default, however using the provided files in this repo, you should now have a few (5). +- Returns targets Name, uuid, number of Hosts, and credentials (SSH, SMB, ESXi, & SNMP Credentials) + +### list-tasks.gmp.py +**Lists all tasks configured** +- Usage: gvm-script --gmp-username *admin-user* --gmp-password *password* socket list-tasks.gmp.py +- No tasks configured by default, however using the provided files in this repo, you should now have some (9). +- Returns the tasks Name, uuid, Target, Scanner, the order in which hosts are scanned¹, and the highest severity (empty if no reports) + +### list-tickets.gmp.py +**Lists all tickets created** +- Usage: gvm-script --gmp-username *admin-user* --gmp-password *password* socket list-tickets.gmp.py +- Returns the tickets name, Host, Associated Task, Status, and Note (depending on status either Open-, Fixed-, or Closed note). + +### list-users.gmp.py +**Lists all users** +- Usage: gvm-script --gmp-username *admin-user* --gmp-password *password* socket list-users.gmp.py +- Returns user Name, uuid, role, groups + + +¹ The default order is "None" which equals sequential, meaning that if this field is empty scanning will be sequential as it will be if specifically set to sequential. Possible results are None, Sequential, Reverse, or Random. + +### start-scans-from-csv.gmp.py +**starts scans (tasks) specified in csv file** +- Usage: gvm-script --gmp-username *admin-user* --gmp-password *password* socket start-scans-from-csv.gmp.py *csv-file with task names* +- Starts the tasks specified in the file (example startscan.csv) +- Returns the number of tasks started. + +### stop-all-scans.gmp.py +**stops scans (tasks) that are in status running, queued, or requested** +- Usage: gvm-script --gmp-username *admin-user* --gmp-password *password* socket stop-all-scans.gmp.py +- Stops all scans +- Returns the number of tasks stopped. + +### stop-scans-from-csv.gmp.py +**stops scans (tasks) specified in csv file** +- Usage: gvm-script --gmp-username *admin-user* --gmp-password *password* socket stop-scans-from-csv.gmp.py *csv-file with task names* +- Stops the tasks specified in the file (example startscan.csv works for both scripts) +- Returns the number of tasks stopped. diff --git a/scripts/clean-sensor.gmp.py b/scripts/clean-sensor.gmp.py index 3f28cbaa..882adec0 100644 --- a/scripts/clean-sensor.gmp.py +++ b/scripts/clean-sensor.gmp.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright (C) 2017-2021 Greenbone AG +# Copyright (C) 2017-2021 Greenbone Networks GmbH # # SPDX-License-Identifier: GPL-3.0-or-later # @@ -19,6 +19,7 @@ from argparse import Namespace from gvm.protocols.gmp import Gmp +from gvm.errors import GvmResponseError def clean_sensor(gmp: Gmp) -> None: @@ -28,61 +29,140 @@ def clean_sensor(gmp: Gmp) -> None: "status="Stop Requested"" ) - for task_id in tasks.xpath("task/@id"): - print(f"Removing task {task_id} ... ") - status_text = gmp.delete_task(task_id, ultimate=True).xpath( - "@status_text" - )[0] - print(status_text) + try: + for task_id in tasks.xpath("task/@id"): + print(f"Removing task {task_id} ... ") + status_text = gmp.delete_task(task_id, ultimate=True).xpath( + "@status_text" + )[0] + print(status_text) + except GvmResponseError as gvmerr: + print(f"{gvmerr=}") + pass targets = gmp.get_targets(filter_string="rows=-1 not _owner=""") - for target_id in targets.xpath("target/@id"): - print(f"Removing target {target_id} ... ") - status_text = gmp.delete_target(target_id, ultimate=True).xpath( - "@status_text" - )[0] - print(status_text) + try: + for target_id in targets.xpath("target/@id"): + print(f"Removing target {target_id} ... ") + status_text = gmp.delete_target(target_id, ultimate=True).xpath( + "@status_text" + )[0] + print(status_text) + except GvmResponseError as gvmerr: + print(f"{gvmerr=}") + pass configs = gmp.get_scan_configs( filter_string="rows=-1 not _owner=""" ) - for config_id in configs.xpath("config/@id"): - print(f"Removing config {config_id} ... ") - status_text = gmp.delete_scan_config(config_id, ultimate=True).xpath( - "@status_text" - )[0] - print(status_text) + try: + for config_id in configs.xpath("config/@id"): + print(f"Removing config {config_id} ... ") + status_text = gmp.delete_scan_config(config_id, ultimate=True).xpath( + "@status_text" + )[0] + print(status_text) + except GvmResponseError as gvmerr: + print(f"{gvmerr=}") + pass port_lists = gmp.get_port_lists( filter_string="rows=-1 not _owner=""" ) - for port_list_id in port_lists.xpath("port_list/@id"): - print(f"Removing port_list {port_list_id} ... ") - status_text = gmp.delete_port_list(port_list_id, ultimate=True).xpath( - "@status_text" - )[0] - print(status_text) + try: + for port_list_id in port_lists.xpath("port_list/@id"): + print(f"Removing port_list {port_list_id} ... ") + status_text = gmp.delete_port_list(port_list_id, ultimate=True).xpath( + "@status_text" + )[0] + print(status_text) + except GvmResponseError as gvmerr: + print(f"{gvmerr=}") + pass + + alerts = gmp.get_alerts( + filter_string="rows=-1 not _owner=""" + ) + try: + for alert_id in alerts.xpath("alert/@id"): + print(f"Removing alert {alert_id} ... ") + status_text = gmp.delete_alert(alert_id, ultimate=True).xpath( + "@status_text" + )[0] + print(status_text) + except GvmResponseError as gvmerr: + print(f"{gvmerr=}") + pass + + schedules = gmp.get_schedules( + filter_string="rows=-1 not _owner=""" + ) + try: + for schedule_id in schedules.xpath("schedule/@id"): + print(f"Removing schedule {schedule_id} ... ") + status_text = gmp.delete_schedule(schedule_id, ultimate=True).xpath( + "@status_text" + )[0] + print(status_text) + except GvmResponseError as gvmerr: + print(f"{gvmerr=}") + pass + + tags = gmp.get_tags( + filter_string="rows=-1 not _owner=""" + ) + try: + for tag_id in tags.xpath("tag/@id"): + print(f"Removing tag {tag_id} ... ") + status_text = gmp.delete_tag(tag_id, ultimate=True).xpath( + "@status_text" + )[0] + print(status_text) + except GvmResponseError as gvmerr: + print(f"{gvmerr=}") + pass + + filters = gmp.get_filters( + filter_string="rows=-1 not _owner=""" + ) + try: + for filter_id in filters.xpath("filter/@id"): + print(f"Removing filter {filter_id} ... ") + status_text = gmp.delete_filter(filter_id, ultimate=True).xpath( + "@status_text" + )[0] + print(status_text) + except GvmResponseError as gvmerr: + print(f"{gvmerr=}") + pass credentials = gmp.get_credentials( filter_string="rows=-1 not _owner=""" ) - for config_id in credentials.xpath("credential/@id"): - print(f"Removing credential {config_id} ... ") - status_text = gmp.delete_credential(config_id, ultimate=True).xpath( - "@status_text" - )[0] - print(status_text) + try: + for config_id in credentials.xpath("credential/@id"): + print(f"Removing credential {config_id} ... ") + status_text = gmp.delete_credential(config_id, ultimate=True).xpath( + "@status_text" + )[0] + print(status_text) + except GvmResponseError as gvmerr: + print(f"{gvmerr=}") + pass print("Emptying trash... ") - status_text = gmp.empty_trashcan().xpath("@status_text")[0] - print(status_text) - + try: + status_text = gmp.empty_trashcan().xpath("@status_text")[0] + print(status_text) + except GvmResponseError as gvmerr: + print(f"{gvmerr=}") + pass def main(gmp: Gmp, args: Namespace) -> None: # pylint: disable=unused-argument print( - "This script removes all resources from a sensor, except active tasks." + "This script removes all resources from a sensor, except active tasks.\n" ) clean_sensor(gmp) diff --git a/scripts/create-alerts-from-csv.gmp.py b/scripts/create-alerts-from-csv.gmp.py new file mode 100755 index 00000000..2e5e8b1f --- /dev/null +++ b/scripts/create-alerts-from-csv.gmp.py @@ -0,0 +1,254 @@ +# -*- coding: utf-8 -*- +# +# Loosely based on Greenbone sample scripts +# As provided by Greenbone in the gvm-tools repo +# +# Martin Boller +# +# SPDX-License-Identifier: GPL-3.0-or-later +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +# Run with gvm-script --gmp-username admin-user --gmp-password password socket create-alerts-from-csv.gmp.py alerts.csv +# +# +# Information on Variables to be used in alerts: https://docs.greenbone.net/GSM-Manual/gos-22.04/en/scanning.html#using-alerts +# Example script: https://forum.greenbone.net/t/working-example-of-creating-an-alert-using-script/7511/2 + +import sys +import time +import csv +import json + +from argparse import ArgumentParser, Namespace, RawTextHelpFormatter +from pathlib import Path +from typing import List +from gvm.errors import GvmResponseError + +from gvm.protocols.gmp import Gmp + +from gvmtools.helper import error_and_exit + +HELP_TEXT = ( + "This script pulls alert information " + "from a csv file and creates a alert for each row. \n" + "use the same alert names when creating tasks! \n\n" + "Use example alerts.csv as a template \n\n" + "It should be rather self explanatory." +) + +def check_args(args): + len_args = len(args.script) - 1 + if len_args != 2: + message = """ + This script pulls alerts from a csv file and creates a \ +alert for each row in the csv file. + One parameter after the script name is required. + + 1. -- csv file containing names and secrets required for scan alerts + + Example: + $ gvm-script --gmp-username name --gmp-password pass \ +ssh --hostname scripts/create_alerts_from_csv.gmp.py \ + + """ + print(message) + sys.exit() + + +def parse_args(args: Namespace) -> Namespace: # pylint: disable=unused-argument + """Parsing args ...""" + + parser = ArgumentParser( + prefix_chars="+", + add_help=False, + formatter_class=RawTextHelpFormatter, + description=HELP_TEXT, + ) + + parser.add_argument( + "+h", + "++help", + action="help", + help="Show this help message and exit.", + ) + + parser.add_argument( + "alert_file", + type=str, + help=("CSV File containing alerts"), + ) + script_args, _ = parser.parse_known_args(args) + return script_args + +def alert_id( + gmp: Gmp, + alert_name: str, +): + response_xml = gmp.get_alerts(filter_string="rows=-1, name=" + alert_name) + alerts_xml = response_xml.xpath("alert") + alert_id = "" + + for alert in alerts_xml: + name = "".join(alert.xpath("name/text()")) + alert_id = alert.get("id") + return alert_id + +def credential_id( + gmp: Gmp, + credential_name: str, +): + response_xml = gmp.get_credentials(filter_string="rows=-1, name=" + credential_name) + credentials_xml = response_xml.xpath("credential") + credential_id = "" + + for credential in credentials_xml: + name = "".join(credential.xpath("name/text()")) + credential_id = credential.get("id") + return credential_id + +def report_format_id( + gmp: Gmp, + report_format_name: str, +): + response_xml = gmp.get_report_formats(details=True, filter_string="rows=-1, name=" + report_format_name) + report_formats_xml = response_xml.xpath("report_format") + report_format_id = "" + + for report_format in report_formats_xml: + name = "".join(report_format.xpath("name/text()")) + report_format_id = report_format.get("id") + return report_format_id + +def event_list(string): + event_list = list(string.split(" ")) + return event_list + + +def create_alerts( + gmp: Gmp, + alert_file: Path, +): + try: + numberalerts = 0 + with open(alert_file, encoding="utf-8") as csvFile: + content = csv.reader(csvFile, delimiter=',') #read the data + for row in content: #loop through each row + if len(row) == 0: + continue + alert_name = row[0] + str_alert_type = row[1] + strRow2 = row[2] + strRow3 = row[3] + strRow4 = row[4] + strRow5 = row[5] + strRow6 = row[6] + report_format = report_format_id(gmp, row[7]) + event_data = row[8] + + comment = f"Created: {time.strftime('%Y/%m/%d-%H:%M:%S')}" + alert_type=getattr(gmp.types.AlertMethod, str_alert_type) + + if alert_id(gmp, alert_name): + print(f"Alert: {alert_name} exist, not creating...") + continue + + if str_alert_type == "EMAIL": + sender_email = strRow2 + recipient_email = strRow3 + subject = strRow4 + message = strRow5 + notice_type = strRow6 + try: + print("Creating alert: " + alert_name) + gmp.create_alert( + name=alert_name, + comment=comment, + event=gmp.types.AlertEvent.TASK_RUN_STATUS_CHANGED, + event_data={"status": event_data}, + condition=gmp.types.AlertCondition.ALWAYS, + method=alert_type, + method_data={ + "message": message, + "notice": notice_type, + "from_address": sender_email, + "subject": subject, + "notice_report_format": report_format, + "notice_attach_format": report_format, + "to_address": recipient_email, + }, + ) + numberalerts = numberalerts + 1 + except GvmResponseError as gvmerr: + print(f"{gvmerr=}, name: {alert_name}") + pass + else: + smb_credential = credential_id(gmp, strRow2) + smb_share_path = strRow3 + smb_report_name = strRow4 + smb_folder = strRow5 + smb_file_path = smb_folder + "/" + smb_report_name + + try: + print("Creating alert: " + alert_name) + gmp.create_alert( + name=alert_name, + comment=comment, + event=gmp.types.AlertEvent.TASK_RUN_STATUS_CHANGED, + event_data={"status": event_data}, + condition=gmp.types.AlertCondition.ALWAYS, + method=alert_type, + method_data={ + "smb_credential": smb_credential, + "smb_share_path": smb_share_path, + "smb_report_format": report_format, + "smb_file_path": smb_file_path, + }, + ) + numberalerts = numberalerts + 1 + except GvmResponseError as gvmerr: + print(f"{gvmerr=}, name: {alert_name}") + pass + csvFile.close() #close the csv file + + except IOError as e: + error_and_exit(f"Failed to read alert_file: {str(e)} (exit)") + + if len(row) == 0: + error_and_exit("alerts file is empty (exit)") + + return numberalerts + +def main(gmp: Gmp, args: Namespace) -> None: + # pylint: disable=undefined-variable + if args.script: + args = args.script[1:] + + parsed_args = parse_args(args=args) + + print( + "Creating alerts.\n" + ) + + numberalerts = create_alerts( + gmp, + parsed_args.alert_file, + ) + + numberalerts = str(numberalerts) + print(" [" + numberalerts + "] alert(s) created!\n") + + +if __name__ == "__gmp__": + main(gmp, args) diff --git a/scripts/create-credentials-from-csv.gmp.py b/scripts/create-credentials-from-csv.gmp.py new file mode 100755 index 00000000..fbbadb63 --- /dev/null +++ b/scripts/create-credentials-from-csv.gmp.py @@ -0,0 +1,224 @@ +# -*- coding: utf-8 -*- +# +# Loosely based on the create-targets-from-host-list.gmp.py +# As provided by Greenbone in the gvm-tools repo +# +# Martin Boller +# +# SPDX-License-Identifier: GPL-3.0-or-later +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +# Run with gvm-script --gmp-username admin-user --gmp-password password socket create-credentials-from-csv.gmp.py credentials.csv +# +# + +import sys +import time +import csv + +from argparse import ArgumentParser, Namespace, RawTextHelpFormatter +from pathlib import Path +from typing import List +from gvm.errors import GvmResponseError + +from gvm.protocols.gmp import Gmp + +from gvmtools.helper import error_and_exit + +HELP_TEXT = ( + "This script pulls Credential information " + "from a csv file and creates a credential for each row. \n" + "use the same credential names when creating targets! \n\n" + "csv file may contain Name of target, Login, password, and ssh-key \n" + "Name,Type,Login,Password,ssh-key \n\n" + "Please note: SNMP and ESX not supported yet " +) + + +def check_args(args): + len_args = len(args.script) - 1 + if len_args != 2: + message = """ + This script pulls credentials from a csv file and creates a \ +credential for each row in the csv file. + One parameter after the script name is required. + + 1. -- csv file containing names and secrets required for scan credentials + + Example: + $ gvm-script --gmp-username name --gmp-password pass \ +ssh --hostname scripts/create_credentials_from_csv.gmp.py \ + + """ + print(message) + sys.exit() + + +def parse_args(args: Namespace) -> Namespace: # pylint: disable=unused-argument + """Parsing args ...""" + + parser = ArgumentParser( + prefix_chars="+", + add_help=False, + formatter_class=RawTextHelpFormatter, + description=HELP_TEXT, + ) + + parser.add_argument( + "+h", + "++help", + action="help", + help="Show this help message and exit.", + ) + + parser.add_argument( + "cred_file", + type=str, + help=("CSV File containing credentials"), + ) + script_args, _ = parser.parse_known_args(args) + return script_args + +def credential_id( + gmp: Gmp, + credName: str, +): + response_xml = gmp.get_credentials(filter_string="rows=-1, name=" + credName) + credentials_xml = response_xml.xpath("credential") + cred_id = "" + + for credential in credentials_xml: + name = "".join(credential.xpath("name/text()")) + cred_id = credential.get("id") + return cred_id + +def create_credentials( + gmp: Gmp, + cred_file: Path, +): + try: + numberCredentials = 0 + with open(cred_file, encoding="utf-8") as csvFile: + content = csv.reader(csvFile, delimiter=',') #read the data + for row in content: #loop through each row + if len(row) == 0: + continue + cred_name = row[0] + cred_type = row[1] + userName = row[2] + userPW = row[3] + comment = f"Created: {time.strftime('%Y/%m/%d-%H:%M:%S')}" + + if credential_id(gmp, cred_name): + print(f"Credential: {cred_name} exist, not creating...") + continue + + if cred_type == "UP": + try: + print("Creating credential: " + cred_name) + gmp.create_credential( + name=cred_name, + credential_type=gmp.types.CredentialType.USERNAME_PASSWORD, + login=userName, + password=userPW, + comment=comment, + ) + numberCredentials = numberCredentials + 1 + except GvmResponseError as gvmerr: + print(f"{gvmerr=}, name: {cred_name}") + pass + elif cred_type == "SSH": + with open(row[4]) as key_file: + key = key_file.read() + + try: + print("Creating credential: " + cred_name) + gmp.create_credential( + name=cred_name, + credential_type=gmp.types.CredentialType.USERNAME_SSH_KEY, + login=userName, + key_phrase=userPW, + private_key=key, + comment=comment, + ) + numberCredentials = numberCredentials + 1 + except GvmResponseError as gvmerr: + print(f"{gvmerr=}, name: {cred_name}") + pass + elif cred_type == "SNMP": + # Unfinished, copy of UP for now + try: + print("Creating credential: " + cred_name) + gmp.create_credential( + name=cred_name, + credential_type=gmp.types.CredentialType.USERNAME_SSH_KEY, + login=userName, + key_phrase=userPW, + private_key=key, + comment=comment, + ) + numberCredentials = numberCredentials + 1 + except GvmResponseError as gvmerr: + print(f"{gvmerr=}, name: {cred_name}") + pass + + elif cred_type == "ESX": + # Unfinished, copy of UP for now + try: + print("Creating credential: " + cred_name) + gmp.create_credential( + name=cred_name, + credential_type=gmp.types.CredentialType.USERNAME_SSH_KEY, + login=userName, + key_phrase=userPW, + private_key=key, + comment=comment, + ) + numberCredentials = numberCredentials + 1 + except GvmResponseError as gvmerr: + print(f"{gvmerr=}, name: {cred_name}") + pass + csvFile.close() #close the csv file + + except IOError as e: + error_and_exit(f"Failed to read cred_file: {str(e)} (exit)") + + if len(row) == 0: + error_and_exit("Credentials file is empty (exit)") + + return numberCredentials + +def main(gmp: Gmp, args: Namespace) -> None: + # pylint: disable=undefined-variable + if args.script: + args = args.script[1:] + + parsed_args = parse_args(args=args) + + print( + "Creating credentials.\n" + ) + + numberCredentials = create_credentials( + gmp, + parsed_args.cred_file, + ) + + numberCredentials = str(numberCredentials) + print(" [" + numberCredentials + "] Credential(s) created!\n") + + +if __name__ == "__gmp__": + main(gmp, args) diff --git a/scripts/create-filters-from-csv.gmp.py b/scripts/create-filters-from-csv.gmp.py new file mode 100755 index 00000000..5d48a9f8 --- /dev/null +++ b/scripts/create-filters-from-csv.gmp.py @@ -0,0 +1,216 @@ +# -*- coding: utf-8 -*- +# +# Loosely based on the create-filterw-from-host-list +# As provided by Greenbone in the gvm-tools repo +# +# Martin Boller +# +# SPDX-License-Identifier: GPL-3.0-or-later +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +# Run with gvm-script --gmp-username admin-user --gmp-password password socket create-filters-from-csv.gmp.py hostname-server filters.csv +# +# + +import sys +import time +import csv + +from argparse import ArgumentParser, Namespace, RawTextHelpFormatter +from pathlib import Path +from typing import List +from gvm.errors import GvmResponseError + +from gvm.protocols.gmp import Gmp + +from gvmtools.helper import error_and_exit + +HELP_TEXT = ( + "This script pulls filtername, hostnames/IP addresses, and credentials " + "from a csv file and creates a filter for each row. \n\n" + "csv file to contain name of filter, ips, and up to 4 credentials previously created \n" + "name,ip-addresses,credential1,credential2,credential3,credential4" +) + + +def check_args(args): + len_args = len(args.script) - 1 + if len_args != 1: + message = """ + This script pulls filter names from a csv file and creates a filter \ +for each row. + One parameter after the script name is required. + + 1. -- text file containing filtername and hostnames or IP-addresses + + Example: + $ gvm-script --gmp-username name --gmp-password pass \ +ssh --hostname scripts/create_filters_from_csv.gmp + """ + print(message) + sys.exit() + + +def parse_args(args: Namespace) -> Namespace: # pylint: disable=unused-argument + """Parsing args ...""" + + parser = ArgumentParser( + prefix_chars="+", + add_help=False, + formatter_class=RawTextHelpFormatter, + description=HELP_TEXT, + ) + + parser.add_argument( + "+h", + "++help", + action="help", + help="Show this help message and exit.", + ) + + parser.add_argument( + "filters_csv_file", + type=str, + help=("File containing host names / IPs"), + ) + + script_args, _ = parser.parse_known_args(args) + return script_args + +def filter_id( + gmp: Gmp, + filter_name: str, +): + response_xml = gmp.get_filters(filter_string="rows=-1, name=" + filter_name) + filters_xml = response_xml.xpath("filter") + filter_id = "" + + for filter in filters_xml: + name = "".join(filter.xpath("name/text()")) + filter_id = filter.get("id") + return filter_id + +def create_filters( + gmp: Gmp, + filter_csv_file: Path, +): + try: + numberfilters = 0 + with open(filter_csv_file, encoding="utf-8") as csvFile: + content = csv.reader(csvFile, delimiter=',') #read the data + for row in content: #loop through each row + if len(row) == 0: + continue + filterType = row[0] + filterName = row[1] + filterDescription = row[2] + filterTerm = row[3] + filterNameFull = filterName + ":" + filterDescription + ":" + filterType + comment = f"Created: {time.strftime('%Y/%m/%d-%H:%M:%S')}" + filterResources = [] + if filterType == "FAIL!": + print(filterType.upper()) + elif filterType.upper() == "ALERT": + resource_type=gmp.types.FilterType.ALERT + elif filterType.upper() == "ASSET": + resource_type=gmp.types.FilterType.ASSET + elif filterType.upper() == "CONFIG": + resource_type=gmp.types.FilterType.SCAN_CONFIG + elif filterType.upper() == "CREDENTIAL": + resource_type=gmp.types.FilterType.CREDENTIAL + elif filterType.upper() == "HOST": + resource_type=gmp.types.FilterType.HOST + elif filterType.upper() == "SECINFO": + resource_type=gmp.types.FilterType.ALL_SECINFO + elif filterType.upper() == "NOTE": + resource_type=gmp.types.FilterType.NOTE + elif filterType.upper() == "OS": + resource_type=gmp.types.FilterType.OPERATING_SYSTEM + elif filterType.upper() == "OVERRIDE": + resource_type=gmp.types.FilterType.OVERRIDE + elif filterType.upper() == "PERMISSION": + resource_type=gmp.types.FilterType.PERMISSION + elif filterType.upper() == "PORT_LIST": + resource_type=gmp.types.FilterType.PORT_LIST + elif filterType.upper() == "REPORT": + resource_type=gmp.types.FilterType.REPORT + elif filterType.upper() == "REPORT_FORMAT": + resource_type=gmp.types.FilterType.REPORT_FORMAT + elif filterType.upper() == "RESULT": + resource_type=gmp.types.FilterType.RESULT + elif filterType.upper() == "ROLE": + resource_type=gmp.types.FilterType.ROLE + elif filterType.upper() == "SCHEDULE": + resource_type=gmp.types.FilterType.SCHEDULE + elif filterType.upper() == "TAG": + resource_type=gmp.types.FilterType.TAG + elif filterType.upper() == "TARGET": + resource_type=gmp.types.FilterType.TARGET + elif filterType.upper() == "TASK": + resource_type=gmp.types.FilterType.TASK + elif filterType.upper() == "TICKET": + resource_type=gmp.types.FilterType.TICKET + elif filterType.upper() == "TLS_CERTIFICATE": + resource_type=gmp.types.FilterType.TLS_CERTIFICATE + elif filterType.upper() == "USER": + resource_type=gmp.types.FilterType.USER + elif filterType.upper() == "VULNERABILITY": + resource_type=gmp.types.FilterType.VULNERABILITY + else: + print("FilterType: " + filterType.upper() + " Not supported") + try: + if filter_id(gmp, filterNameFull): + print(f"Filter: {filterNameFull} exist, not creating...") + continue + + print("Creating filter: " + filterNameFull) + gmp.create_filter( + name=filterNameFull, comment=comment, filter_type=resource_type, term=filterTerm, + ) + numberfilters = numberfilters + 1 + except GvmResponseError as gvmerr: + print(f"{gvmerr=}, name: {filterNameFull}") + pass + csvFile.close() #close the csv file + except IOError as e: + error_and_exit(f"Failed to read filter_csv_file: {str(e)} (exit)") + + if len(row) == 0: + error_and_exit("filter file is empty (exit)") + + return numberfilters + +def main(gmp: Gmp, args: Namespace) -> None: + # pylint: disable=undefined-variable + if args.script: + args = args.script[1:] + + parsed_args = parse_args(args=args) + + print( + "Creating filters.\n" + ) + + numberfilters = create_filters( + gmp, + parsed_args.filters_csv_file, + ) + + numberfilters = str(numberfilters) + print(" [" + numberfilters + "] filter(s) created!\n") + + +if __name__ == "__gmp__": + main(gmp, args) diff --git a/scripts/create-report-format-from-csv.gmp.py b/scripts/create-report-format-from-csv.gmp.py new file mode 100755 index 00000000..2a1285b4 --- /dev/null +++ b/scripts/create-report-format-from-csv.gmp.py @@ -0,0 +1,181 @@ +# -*- coding: utf-8 -*- +# +# Loosely based on the create-targets-from-host-list.gmp.py +# As provided by Greenbone in the gvm-tools repo +# +# Martin Boller +# +# SPDX-License-Identifier: GPL-3.0-or-later +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +# Run with gvm-script --gmp-username admin-user --gmp-password password socket create-report_formats-from-csv.gmp.py report_formats.csv +# +# + +import sys +import time +import csv + +from argparse import ArgumentParser, Namespace, RawTextHelpFormatter +from pathlib import Path +from typing import List +from gvm.errors import GvmResponseError + +from gvm.protocols.gmp import Gmp + +from gvmtools.helper import error_and_exit + +HELP_TEXT = ( + "This script pulls report-format information " + "from a csv file and creates a report-format for each row. \n" + "csv file may contain Name of target, Login, password, and ssh-key \n" + "Name,Type,Login,Password,ssh-key \n\n" + "Please note: SNMP and ESX not supported yet " +) + + +def check_args(args): + len_args = len(args.script) - 1 + if len_args != 2: + message = """ + This script pulls report-format data from a csv file and creates a \ +report-format for each row in the csv file. + One parameter after the script name is required. + + 1. -- csv file containing names and secrets required for scan report_formats + + Example: + $ gvm-script --gmp-username name --gmp-password pass \ +ssh --hostname scripts/create_report_formats_from_csv.gmp.py \ + + """ + print(message) + sys.exit() + + +def parse_args(args: Namespace) -> Namespace: # pylint: disable=unused-argument + """Parsing args ...""" + + parser = ArgumentParser( + prefix_chars="+", + add_help=False, + formatter_class=RawTextHelpFormatter, + description=HELP_TEXT, + ) + + parser.add_argument( + "+h", + "++help", + action="help", + help="Show this help message and exit.", + ) + + parser.add_argument( + "cred_file", + type=str, + help=("CSV File containing report_formats"), + ) + script_args, _ = parser.parse_known_args(args) + return script_args + +def create_report_formats( + gmp: Gmp, + cred_file: Path, +): + try: + numberreport_formats = 0 + with open(cred_file, encoding="utf-8") as csvFile: + content = csv.reader(csvFile, delimiter=',') #read the data + for row in content: #loop through each row + numberreport_formats = numberreport_formats + 1 + REPORT_FORMAT_XML_STRING = ( + '' + '' + "CSV vulnscan.dk" + 'name=CSV first=1 rows=10 sort=name' + '' + '' + 'name' + '=' + 'CSV' + '' + '' + 'first' + '=' + '1' + '' + '' + 'rows' + '=' + '10' + '' + '' + 'sort' + '=' + 'name' + '' + '' + 'csv' + 'text/csv' + "vulnscan.dk CSV Report Format. Version 2023-03-31." + "vulnscan.dk CSV Report Format" + 'Complete scan report in GMP XML format. Version 20200827.' + '1' + '0' + '1' + '1' + "2024-03-31T10:48:03Z" + "2024-03-31T10:48:03Z" + '' + '500' + "" + "" + ) + + rf_copy = "c1645568-627a-11e3-a660-406186ea4fc5" + comment = f"Created: {time.strftime('%Y/%m/%d-%H:%M:%S')}" + + gmp.import_report_format( + REPORT_FORMAT_XML_STRING + ) + + csvFile.close() #close the csv file + + except IOError as e: + error_and_exit(f"Failed to read cred_file: {str(e)} (exit)") + + if len(row) == 0: + error_and_exit("report_formats file is empty (exit)") + + return numberreport_formats + +def main(gmp: Gmp, args: Namespace) -> None: + # pylint: disable=undefined-variable + if args.script: + args = args.script[1:] + + parsed_args = parse_args(args=args) + + numberreport_formats = create_report_formats( + gmp, + parsed_args.cred_file, + ) + + numberreport_formats = str(numberreport_formats) + print(" \n [" + numberreport_formats + "] report_format(s) created!\n") + + +if __name__ == "__gmp__": + main(gmp, args) diff --git a/scripts/create-schedules-from-csv.gmp.py b/scripts/create-schedules-from-csv.gmp.py new file mode 100755 index 00000000..ddc3b2f7 --- /dev/null +++ b/scripts/create-schedules-from-csv.gmp.py @@ -0,0 +1,169 @@ +# -*- coding: utf-8 -*- +# +# Loosely based on the create-targets-from-host-list.gmp.py +# As provided by Greenbone in the gvm-tools repo +# +# Martin Boller +# +# SPDX-License-Identifier: GPL-3.0-or-later +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +# Run with gvm-script --gmp-username admin-user --gmp-password password socket create-schedules-from-csv.gmp.py schedules.csv +# +# + +import sys +import time +import csv + +from argparse import ArgumentParser, Namespace, RawTextHelpFormatter +from pathlib import Path +from typing import List +from gvm.errors import GvmResponseError + +from gvm.protocols.gmp import Gmp + +from gvmtools.helper import error_and_exit + +HELP_TEXT = ( + "This script pulls schedule information " + "from a csv file and creates a schedule for each row. \n" + "use the same schedule names when creating tasks! \n\n" + "csv file may contain Name of schedule, Timezone, Icalendar entry \n" + "Use example schedules.csv as a template \n\n" + "It should be rather self explanatory." +) + + +def check_args(args): + len_args = len(args.script) - 1 + if len_args != 2: + message = """ + This script pulls schedules from a csv file and creates a \ +schedule for each row in the csv file. + One parameter after the script name is required. + + 1. -- csv file containing names and secrets required for scan schedules + + Example: + $ gvm-script --gmp-username name --gmp-password pass \ +ssh --hostname scripts/create_schedules_from_csv.gmp.py \ + + """ + print(message) + sys.exit() + + +def parse_args(args: Namespace) -> Namespace: # pylint: disable=unused-argument + """Parsing args ...""" + + parser = ArgumentParser( + prefix_chars="+", + add_help=False, + formatter_class=RawTextHelpFormatter, + description=HELP_TEXT, + ) + + parser.add_argument( + "+h", + "++help", + action="help", + help="Show this help message and exit.", + ) + + parser.add_argument( + "sched_file", + type=str, + help=("CSV File containing schedules"), + ) + script_args, _ = parser.parse_known_args(args) + return script_args + +def schedule_id( + gmp: Gmp, + schedule_name: str, +): + response_xml = gmp.get_schedules(filter_string="rows=-1, name=" + schedule_name) + schedules_xml = response_xml.xpath("schedule") + schedule_id = "" + + for schedule in schedules_xml: + name = "".join(schedule.xpath("name/text()")) + schedule_id = schedule.get("id") + return schedule_id + + +def create_schedules( + gmp: Gmp, + sched_file: Path, +): + try: + numberschedules = 0 + with open(sched_file, encoding="utf-8") as csvFile: + content = csv.reader(csvFile, delimiter=',') #read the data + for row in content: #loop through each row + if len(row) == 0: + continue + sched_name = row[0] + sched_tz = row[1] + sched_ical = row[2] + comment = f"Created: {time.strftime('%Y/%m/%d-%H:%M:%S')}" + try: + if schedule_id(gmp, sched_name): + print(f"Schedule: {sched_name} exist, not creating...") + continue + print("Creating schedule: " + sched_name) + gmp.create_schedule( + name=sched_name, + timezone=sched_tz, + icalendar=sched_ical, + comment=comment + ) + numberschedules = numberschedules + 1 + except GvmResponseError as gvmerr: + print(f"{gvmerr=}, name: {sched_name}") + pass + csvFile.close() #close the csv file + + except IOError as e: + error_and_exit(f"Failed to read sched_file: {str(e)} (exit)") + + if len(row) == 0: + error_and_exit("schedules file is empty (exit)") + + return numberschedules + +def main(gmp: Gmp, args: Namespace) -> None: + # pylint: disable=undefined-variable + if args.script: + args = args.script[1:] + + parsed_args = parse_args(args=args) + + print( + "Creating schedules.\n" + ) + + numberschedules = create_schedules( + gmp, + parsed_args.sched_file, + ) + + numberschedules = str(numberschedules) + print(" [" + numberschedules + "] schedule(s) created!\n") + + +if __name__ == "__gmp__": + main(gmp, args) diff --git a/scripts/create-tags-from-csv.gmp.py b/scripts/create-tags-from-csv.gmp.py new file mode 100755 index 00000000..8c06431d --- /dev/null +++ b/scripts/create-tags-from-csv.gmp.py @@ -0,0 +1,327 @@ +# -*- coding: utf-8 -*- +# +# Loosely based on the create-tagw-from-host-list +# As provided by Greenbone in the gvm-tools repo +# +# Martin Boller +# +# SPDX-License-Identifier: GPL-3.0-or-later +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +# Run with gvm-script --gmp-username admin-user --gmp-password password socket create-tags-from-csv.gmp.py hostname-server tags.csv +# +# + +import sys +import time +import csv + +from argparse import ArgumentParser, Namespace, RawTextHelpFormatter +from pathlib import Path +from typing import List + +from gvm.protocols.gmp import Gmp +from gvm.errors import GvmResponseError +from gvmtools.helper import error_and_exit + +HELP_TEXT = ( + "This script pulls tagname, hostnames/IP addresses, and credentials " + "from a csv file and creates a tag for each row. \n\n" + "csv file to contain name of tag, ips, and up to 4 credentials previously created \n" + "name,ip-addresses,credential1,credential2,credential3,credential4" +) + + +def check_args(args): + len_args = len(args.script) - 1 + if len_args != 1: + message = """ + This script pulls tag names from a csv file and creates a tag \ +for each row. + One parameter after the script name is required. + + 1. -- text file containing tagname and hostnames or IP-addresses + + Example: + $ gvm-script --gmp-username name --gmp-password pass \ +ssh --hostname scripts/create_tags_from_csv.gmp + """ + print(message) + sys.exit() + + +def parse_args(args: Namespace) -> Namespace: # pylint: disable=unused-argument + """Parsing args ...""" + + parser = ArgumentParser( + prefix_chars="+", + add_help=False, + formatter_class=RawTextHelpFormatter, + description=HELP_TEXT, + ) + + parser.add_argument( + "+h", + "++help", + action="help", + help="Show this help message and exit.", + ) + + parser.add_argument( + "tags_csv_file", + type=str, + help=("File containing host names / IPs"), + ) + + script_args, _ = parser.parse_known_args(args) + return script_args + +def config_id( + gmp: Gmp, + config_name: str, +): + response_xml = gmp.get_scan_configs(filter_string="rows=-1, name= " + config_name) + scan_configs_xml = response_xml.xpath("config") + config_id = "" + + for scan_config in scan_configs_xml: + name = "".join(scan_config.xpath("name/text()")) + config_id = scan_config.get("id") + return config_id + +def alert_id( + gmp: Gmp, + alert_name: str, +): + response_xml = gmp.get_alerts(filter_string="rows=-1, name=" + alert_name) + alerts_xml = response_xml.xpath("alert") + alert_id = "" + + for alert in alerts_xml: + name = "".join(alert.xpath("name/text()")) + alert_id = alert.get("id") + return alert_id + +def credential_id( + gmp: Gmp, + credName: str, +): + response_xml = gmp.get_credentials(filter_string="rows=-1, name=" + credName) + credentials_xml = response_xml.xpath("credential") + cred_id = "" + + for credential in credentials_xml: + name = "".join(credential.xpath("name/text()")) + cred_id = credential.get("id") + return cred_id + +def target_id( + gmp: Gmp, + targetName: str, +): + response_xml = gmp.get_targets(filter_string="rows=-1, name=" + targetName) + targets_xml = response_xml.xpath("target") + target_id = "" + + for target in targets_xml: + name = "".join(target.xpath("name/text()")) + target_id = target.get("id") + return target_id + +def task_id( + gmp: Gmp, + taskName: str, +): + response_xml = gmp.get_tasks(filter_string="rows=-1, name=" + taskName) + tasks_xml = response_xml.xpath("task") + task_id = "" + + for task in tasks_xml: + name = "".join(task.xpath("name/text()")) + task_id = task.get("id") + return task_id + +def tag_id( + gmp: Gmp, + tagName: str, +): + response_xml = gmp.get_tags(filter_string="rows=-1, name=" + tagName) + tags_xml = response_xml.xpath("tag") + tag_id = "" + + for tag in tags_xml: + name = "".join(tag.xpath("name/text()")) + tag_id = tag.get("id") + return tag_id + +def scanner_id( + gmp: Gmp, + scanner_name: str, +): + response_xml = gmp.get_scanners(filter_string="rows=-1, name=" + scanner_name) + scanners_xml = response_xml.xpath("scanner") + scanner_id = "" + + for scanner in scanners_xml: + name = "".join(scanner.xpath("name/text()")) + scanner_id = scanner.get("id") + return scanner_id + +def schedule_id( + gmp: Gmp, + schedule_name: str, +): + response_xml = gmp.get_schedules(filter_string="rows=-1, name=" + schedule_name) + schedules_xml = response_xml.xpath("schedule") + schedule_id = "" + + for schedule in schedules_xml: + name = "".join(schedule.xpath("name/text()")) + schedule_id = schedule.get("id") + return schedule_id + +def create_tags( + gmp: Gmp, + tag_csv_file: Path, +): + try: + numbertags = 0 + with open(tag_csv_file, encoding="utf-8") as csvFile: + content = csv.reader(csvFile, delimiter=',') #read the data + for row in content: #loop through each row + if len(row) == 0: + continue + tagType = row[0] + tagName = row[1] + tagDescription = row[2] + tagNameFull = tagName + ":" + tagDescription + ":" + tagType + if tag_id(gmp, tagNameFull): + print(f"Tag: {tagNameFull} already exist") + continue + # Up to ten resources (rows 3 - 12) + tagResources = [] + if tagType.upper() == "FAIL!": + print("Failed!") + elif tagType.upper() == "ALERT": + getUUID=alert_id + resource_type=gmp.types.EntityType.ALERT + elif tagType.upper() == "CONFIG": + getUUID=config_id + resource_type=gmp.types.EntityType.SCAN_CONFIG + elif tagType.upper() == "CREDENTIAL": + getUUID=credential_id + resource_type=gmp.types.EntityType.CREDENTIAL + elif tagType.upper() == "REPORT": + filter = "~" + tagName + resource_type=gmp.types.EntityType.REPORT + elif tagType.upper() == "SCANNER": + getUUID=scanner_id + resource_type=gmp.types.EntityType.SCANNER + elif tagType.upper() == "SCHEDULE": + getUUID=schedule_id + resource_type=gmp.types.EntityType.SCHEDULE + elif tagType.upper() == "TARGET": + getUUID=target_id + resource_type=gmp.types.EntityType.TARGET + elif tagType.upper() == "TASK": + getUUID=task_id + resource_type=gmp.types.EntityType.TASK + else: + print("Only alert, config, credential, report, scanner, schedule, target, and task supported") + exit() + + if len(row[3]) >= 1: + tagResource = (getUUID(gmp, row[3])) + tagResources.append(tagResource) + if len(row[4]) >= 1: + tagResource = (getUUID(gmp, row[4])) + tagResources.append(tagResource) + if len (row[5]) >= 1: + tagResource = (getUUID(gmp, row[5])) + tagResources.append(tagResource) + if len(row[6]) >= 1: + tagResource = (getUUID(gmp, row[6])) + tagResources.append(tagResource) + if len(row[7]) >= 1: + tagResource = (getUUID(gmp, row[7])) + tagResources.append(tagResource) + if len (row[8]) >= 1: + tagResource = (getUUID(gmp, row[8])) + tagResources.append(tagResource) + if len(row[9]) >= 1: + tagResource = (getUUID(gmp, row[9])) + tagResources.append(tagResource) + tagResource = (getUUID(gmp, row[10])) + if len(row[10]) >= 1: + tagResources.append(tagResource) + if len(row[11]) >= 1: + tagResource = (getUUID(gmp, row[11])) + tagResources.append(tagResource) + if len(row[12]) >= 1: + tagResource = (getUUID(gmp, row[12])) + tagResources.append(tagResource) + comment = f"Created: {time.strftime('%Y/%m/%d-%H:%M:%S')}" + + if tagType.upper() == "REPORT": + try: + print("Creating tag: " + tagNameFull) + gmp.create_tag( + name=tagNameFull, comment=comment, value=tagName, resource_type=resource_type, resource_filter=filter, + ) + numbertags = numbertags + 1 + except GvmResponseError as gvmerr: + print(f"{gvmerr=}, name: {tagNameFull}") + pass + else: + try: + print("Creating tag: " + tagNameFull) + gmp.create_tag( + name=tagNameFull, comment=comment, value=tagName, resource_type=resource_type, resource_ids=tagResources, + ) + numbertags = numbertags + 1 + except GvmResponseError as gvmerr: + print(f"{gvmerr=}, name: {tagNameFull}") + pass + csvFile.close() #close the csv file + except IOError as e: + error_and_exit(f"Failed to read tag_csv_file: {str(e)} (exit)") + + if len(row) == 0: + error_and_exit("tag file is empty (exit)") + + return numbertags + +def main(gmp: Gmp, args: Namespace) -> None: + # pylint: disable=undefined-variable + if args.script: + args = args.script[1:] + + parsed_args = parse_args(args=args) + + print( + "Creating tags.\n" + ) + + numbertags = create_tags( + gmp, + parsed_args.tags_csv_file, + ) + + numbertags = str(numbertags) + print(" [" + numbertags + "] tag(s) created!\n") + + +if __name__ == "__gmp__": + main(gmp, args) diff --git a/scripts/create-targets-from-csv.gmp.py b/scripts/create-targets-from-csv.gmp.py new file mode 100755 index 00000000..203920ff --- /dev/null +++ b/scripts/create-targets-from-csv.gmp.py @@ -0,0 +1,215 @@ +# -*- coding: utf-8 -*- +# +# Loosely based on the create-targetw-from-host-list +# As provided by Greenbone in the gvm-tools repo +# +# Martin Boller +# +# SPDX-License-Identifier: GPL-3.0-or-later +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +# Run with gvm-script --gmp-username admin-user --gmp-password password socket create-targets-from-csv.gmp.py hostname-server targets.csv +# +# + +import sys +import time +import csv + +from argparse import ArgumentParser, Namespace, RawTextHelpFormatter +from pathlib import Path +from typing import List +from gvm.errors import GvmResponseError +from gvm.protocols.gmp import Gmp +from gvmtools.helper import error_and_exit + +HELP_TEXT = ( + "This script pulls targetname, hostnames/IP addresses, and credentials " + "from a csv file and creates a target for each row. \n\n" + "csv file to contain name of target, ips, and up to 4 credentials previously created \n" + "name,ip-addresses,credential1,credential2,credential3,credential4" +) + + +def check_args(args): + len_args = len(args.script) - 1 + if len_args != 1: + message = """ + This script pulls target names from a csv file and creates a target \ +for each row. + One parameter after the script name is required. + + 1. -- text file containing Targetname and hostnames or IP-addresses + + Example: + $ gvm-script --gmp-username name --gmp-password pass \ +ssh --hostname scripts/create_targets_from_csv.gmp + """ + print(message) + sys.exit() + + +def parse_args(args: Namespace) -> Namespace: # pylint: disable=unused-argument + """Parsing args ...""" + + parser = ArgumentParser( + prefix_chars="+", + add_help=False, + formatter_class=RawTextHelpFormatter, + description=HELP_TEXT, + ) + + parser.add_argument( + "+h", + "++help", + action="help", + help="Show this help message and exit.", + ) + + parser.add_argument( + "targets_csv_file", + type=str, + help=("File containing host names / IPs"), + ) + + ports = parser.add_mutually_exclusive_group() + ports.add_argument( + "+pl", + "++port-list-id", + type=str, + dest="port_list_id", + help="UUID of existing port list.", + ) + ports.add_argument( + "+pr", + "++port-range", + dest="port_range", + type=str, + help=( + "Port range to create port list from, e.g. " + "T:1-1234 for ports 1-1234/TCP" + ), + ) + + ports.set_defaults( + port_list_id="730ef368-57e2-11e1-a90f-406186ea4fc5" + ) # All TCP and Nmap top 100 UDP + # Default portlists see also script list-portlists.gmp.py + # | Name | ID + # - | ----------------------------- | ------------------------------------ + # 1 | All IANA assigned TCP | 33d0cd82-57c6-11e1-8ed1-406186ea4fc5 + # 2 | All IANA assigned TCP and UDP | 4a4717fe-57d2-11e1-9a26-406186ea4fc5 + # 3 | All TCP and Nmap top 100 UDP | 730ef368-57e2-11e1-a90f-406186ea4fc5 + + script_args, _ = parser.parse_known_args(args) + return script_args + +def credential_id( + gmp: Gmp, + credName: str, +): + response_xml = gmp.get_credentials(filter_string="rows=-1, name=" + credName) + credentials_xml = response_xml.xpath("credential") + cred_id = "" + + for credential in credentials_xml: + name = "".join(credential.xpath("name/text()")) + cred_id = credential.get("id") + return cred_id + +def target_id( + gmp: Gmp, + targetName: str, +): + response_xml = gmp.get_targets(filter_string="rows=-1, name=" + targetName) + targets_xml = response_xml.xpath("target") + target_id = "" + + for target in targets_xml: + name = "".join(target.xpath("name/text()")) + target_id = target.get("id") + return target_id + +def create_targets( + gmp: Gmp, + target_csv_file: Path, + port_list_id: str, +): + try: + numberTargets = 0 + with open(target_csv_file, encoding="utf-8") as csvFile: + content = csv.reader(csvFile, delimiter=',') #read the data + for row in content: #loop through each row + if len(row) == 0: + continue + name = row[0] + hosts = [row[1]] + smbCred = credential_id(gmp, row[2]) + sshCred = credential_id(gmp, row[3]) + snmpCred = credential_id(gmp, row[4]) + esxCred = credential_id(gmp, row[5]) + aliveTest = row[6] + if not aliveTest: + aliveTest = "Scan Config Default" + alive_test = gmp.types.AliveTest( + (aliveTest) + ) + comment = f"Created: {time.strftime('%Y/%m/%d-%H:%M:%S')}" + try: + if target_id(gmp, name): + print(f"Target: {name} exist, not creating...") + continue + + print("Creating target: " + name) + gmp.create_target( + name=name, comment=comment, hosts=hosts, port_list_id=port_list_id, smb_credential_id=smbCred, ssh_credential_id=sshCred, alive_test=alive_test + ) + numberTargets = numberTargets + 1 + except GvmResponseError as gvmerr: + print(f"{gvmerr=}, name: {name}") + pass + csvFile.close() #close the csv file + except IOError as e: + error_and_exit(f"Failed to read target_csv_file: {str(e)} (exit)") + + if len(row) == 0: + error_and_exit("Host file is empty (exit)") + + return numberTargets + +def main(gmp: Gmp, args: Namespace) -> None: + # pylint: disable=undefined-variable + if args.script: + args = args.script[1:] + + parsed_args = parse_args(args=args) + #port_list_id="4a4717fe-57d2-11e1-9a26-406186ea4fc5" + + print( + "Creating targets.\n" + ) + + numberTargets = create_targets( + gmp, + parsed_args.targets_csv_file, + parsed_args.port_list_id + ) + + numberTargets = str(numberTargets) + print(" [" + numberTargets + "] Target(s) created!\n") + + +if __name__ == "__gmp__": + main(gmp, args) diff --git a/scripts/create-tasks-from-csv.gmp.py b/scripts/create-tasks-from-csv.gmp.py new file mode 100755 index 00000000..e03ebd0b --- /dev/null +++ b/scripts/create-tasks-from-csv.gmp.py @@ -0,0 +1,296 @@ +# -*- coding: utf-8 -*- +# +# Loosely based on the create-targets-from-host-list +# As provided by Greenbone in the gvm-tools repo +# +# Martin Boller +# +# SPDX-License-Identifier: GPL-3.0-or-later +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +# Run with gvm-script --gmp-username admin-user --gmp-password password socket create-tasks-from-csv.gmp.py hostname-server tasks.csv +# +# +# Note: for some weird reason theres a space in front of the default scan config " Full and fast" +# Examples of all defaults in tasks.csv +# + +import sys +import time +import csv + +from argparse import ArgumentParser, Namespace, RawTextHelpFormatter +from pathlib import Path +from typing import List +from gvm.protocols.gmpv208.entities.hosts import HostsOrdering #Only available in version 20.8 +from gvm.protocols.gmp import Gmp +from gvm.errors import GvmResponseError +from gvmtools.helper import error_and_exit + +HELP_TEXT = ( + "This script pulls taskname, scanner, & scan config " + "from a csv file and creates a task for each row. \n\n" + "csv file to contain name of task, target name, scanner name, and scan config name \n" + "name,target,scanner,scan config" +) + + +def check_args(args): + len_args = len(args.script) - 1 + if len_args != 1: + message = """ + This script pulls taskinformation from a csv file and creates a task \ +for each row. + One parameter after the script name is required. + + 1. -- text file containing taskname, target name, scanner name, and scan config name + + Example: + $ gvm-script --gmp-username name --gmp-password pass \ +ssh --hostname scripts/create_tasks_from_csv.gmp + """ + print(message) + sys.exit() + + +def parse_args(args: Namespace) -> Namespace: # pylint: disable=unused-argument + """Parsing args ...""" + + parser = ArgumentParser( + prefix_chars="+", + add_help=False, + formatter_class=RawTextHelpFormatter, + description=HELP_TEXT, + ) + + parser.add_argument( + "+h", + "++help", + action="help", + help="Show this help message and exit.", + ) + + parser.add_argument( + "tasks_csv_file", + type=str, + help=("File containing host names / IPs"), + ) + + ports = parser.add_mutually_exclusive_group() + ports.add_argument( + "+pl", + "++port-list-id", + type=str, + dest="port_list_id", + help="UUID of existing port list.", + ) + ports.add_argument( + "+pr", + "++port-range", + dest="port_range", + type=str, + help=( + "Port range to create port list from, e.g. " + "T:1-1234 for ports 1-1234/TCP" + ), + ) + + ports.set_defaults( + port_list_id="730ef368-57e2-11e1-a90f-406186ea4fc5" + ) # All IANA assigned TCP and Top 100 UDP, use the list-portlists.gmp.py script to get the UUID for all. + # Defaults are + # # | Name | ID + # - | ----------------------------- | ------------------------------------ + # 1 | All IANA assigned TCP | 33d0cd82-57c6-11e1-8ed1-406186ea4fc5 + # 2 | All IANA assigned TCP and UDP | 4a4717fe-57d2-11e1-9a26-406186ea4fc5 + # 3 | All TCP and Nmap top 100 UDP | 730ef368-57e2-11e1-a90f-406186ea4fc5 + + script_args, _ = parser.parse_known_args(args) + return script_args + +def config_id( + gmp: Gmp, + config_name: str, +): + response_xml = gmp.get_scan_configs(filter_string="rows=-1, name= " + config_name +) + scan_configs_xml = response_xml.xpath("config") + config_id = "" + + for scan_config in scan_configs_xml: + name = "".join(scan_config.xpath("name/text()")) + config_id = scan_config.get("id") + return config_id + +def alert_id( + gmp: Gmp, + alert_name: str, +): + response_xml = gmp.get_alerts(filter_string="rows=-1, name=" + alert_name) + alerts_xml = response_xml.xpath("alert") + alert_id = "" + + for alert in alerts_xml: + name = "".join(alert.xpath("name/text()")) + alert_id = alert.get("id") + return alert_id + +def target_id( + gmp: Gmp, + target_name: str, +): + response_xml = gmp.get_targets(filter_string="rows=-1, name=" + target_name) + targets_xml = response_xml.xpath("target") + target_id = "" + + for target in targets_xml: + name = "".join(target.xpath("name/text()")) + target_id = target.get("id") + return target_id + +def scanner_id( + gmp: Gmp, + scanner_name: str, +): + response_xml = gmp.get_scanners(filter_string="rows=-1, name=" + scanner_name) + scanners_xml = response_xml.xpath("scanner") + scanner_id = "" + + for scanner in scanners_xml: + name = "".join(scanner.xpath("name/text()")) + scanner_id = scanner.get("id") + return scanner_id + +def schedule_id( + gmp: Gmp, + schedule_name: str, +): + response_xml = gmp.get_schedules(filter_string="rows=-1, name=" + schedule_name) + schedules_xml = response_xml.xpath("schedule") + schedule_id = "" + + for schedule in schedules_xml: + name = "".join(schedule.xpath("name/text()")) + schedule_id = schedule.get("id") + return schedule_id + +def task_id( + gmp: Gmp, + taskName: str, +): + response_xml = gmp.get_tasks(filter_string="rows=-1, name=" + taskName) + tasks_xml = response_xml.xpath("task") + task_id = "" + + for task in tasks_xml: + name = "".join(task.xpath("name/text()")) + task_id = task.get("id") + return task_id + +def create_tasks( + gmp: Gmp, + task_csv_file: Path, + port_list_id: str, +): + try: + numberTasks = 0 + with open(task_csv_file, encoding="utf-8") as csvFile: + content = csv.reader(csvFile, delimiter=',') #read the data + for row in content: #loop through each row + if len(row) == 0: + continue + name = row[0] + targetId = target_id(gmp, row[1]) + scannerId = scanner_id(gmp, row[2]) + alterable = "True" + configId = config_id(gmp, row[3]) + scheduleId = schedule_id(gmp, row[4]) + + newOrder = row[5].upper() + if newOrder == "RANDOM": + order = HostsOrdering.RANDOM + elif newOrder == "SEQUENTIAL": + order = HostsOrdering.SEQUENTIAL + elif newOrder == "REVERSE": + order = HostsOrdering.REVERSE + else: + order = HostsOrdering.RANDOM + + alerts = [] + if len(row[6]) > 1: + alert = alert_id(gmp, row[6]) + alerts.append(alert) + if len(row[7]) > 1: + alert = alert_id(gmp, row[7]) + alerts.append(alert) + if len (row[8]) > 1: + alert = alert_id(gmp, row[8]) + alerts.append(alert) + if len(row[9]) > 1: + alert = alert_id(gmp, row[9]) + alerts.append(alert) + if len(row[10]) > 1: + alert = alert_id(gmp, row[10]) + alerts.append(alert) + + scanOrder = order # Use SEQUENTIAL, REVERSE, or RANDOM + comment = f"Created: {time.strftime('%Y/%m/%d-%H:%M:%S')}" + + try: + if task_id(gmp, name): + print(f"Task: {name} exist already") + continue + print("Creating task: " + name) + gmp.create_task( + name=name, comment=comment, config_id=configId, target_id=targetId, hosts_ordering=scanOrder, scanner_id=scannerId, alterable=alterable, schedule_id=scheduleId, alert_ids=alerts + ) + numberTasks = numberTasks + 1 + except GvmResponseError as gvmerr: + print(f"{gvmerr=}, name: {name}") + pass + csvFile.close() #close the csv file + + except IOError as e: + error_and_exit(f"Failed to read task_csv_file: {str(e)} (exit)") + + if len(row) == 0: + error_and_exit("Host file is empty (exit)") + + return numberTasks + +def main(gmp: Gmp, args: Namespace) -> None: + # pylint: disable=undefined-variable + if args.script: + args = args.script[1:] + + parsed_args = parse_args(args=args) + #port_list_id="4a4717fe-57d2-11e1-9a26-406186ea4fc5" + + print( + "Creating tasks\n" + ) + + numberTasks = create_tasks( + gmp, + parsed_args.tasks_csv_file, + parsed_args.port_list_id + ) + + numberTasks = str(numberTasks) + print(" [" + numberTasks + "] task(s) created!\n") + + +if __name__ == "__gmp__": + main(gmp, args) diff --git a/scripts/dummy_def.gmp.py b/scripts/dummy_def.gmp.py new file mode 100644 index 00000000..d53b4f81 --- /dev/null +++ b/scripts/dummy_def.gmp.py @@ -0,0 +1,12 @@ +def alert_id( + gmp: Gmp, + alert_name: str, +): + response_xml = gmp.get_alerts(filter_string="rows=-1, name=" + alert_name) + alerts_xml = response_xml.xpath("alert") + alert_id = "" + + for alert in alerts_xml: + name = "".join(alert.xpath("name/text()")) + alert_id = alert.get("id") + return alert_id diff --git a/scripts/empty-trash.gmp.py b/scripts/empty-trash.gmp.py new file mode 100755 index 00000000..66dbb5ef --- /dev/null +++ b/scripts/empty-trash.gmp.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 2019-2021 Greenbone Networks GmbH +# +# SPDX-License-Identifier: GPL-3.0-or-later +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +# Based on other Greenbone scripts +# +# Martin Boller +# + +from argparse import Namespace + +from gvm.protocols.gmp import Gmp + +from gvmtools.helper import Table + + + +def main(gmp: Gmp, args: Namespace) -> None: + + print( + "Emptying Trash...\n" + ) + + try: + status_text = gmp.empty_trashcan().xpath("@status_text")[0] + print(status_text) + except: + pass + +if __name__ == "__gmp__": + main(gmp, args) diff --git a/scripts/export-csv-report.gmp.py b/scripts/export-csv-report.gmp.py new file mode 100755 index 00000000..807b0100 --- /dev/null +++ b/scripts/export-csv-report.gmp.py @@ -0,0 +1,102 @@ +# -*- coding: utf-8 -*- +# +# Based on the Greenbone export-pdf-report script and modified to +# create csv and return more (all) details. +# Martin Boller +# +# Copyright (C) 2019-2021 Greenbone Networks GmbH +# +# SPDX-License-Identifier: GPL-3.0-or-later +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +# 2022-11-02 - Martin B +# Added ignore_pagination=True, details=True to get the full report +# + +import sys + +from base64 import b64decode +from pathlib import Path +from argparse import Namespace +from gvm.protocols.gmp import Gmp + + +def check_args(args): + len_args = len(args.script) - 1 + if len_args < 1: + message = """ + This script requests the given report and exports it as a csv + file locally. It requires one parameter after the script name. + + 1. -- ID of the report + + Optional a file name to save the csv in. + + Examples: + $ gvm-script --gmp-username name --gmp-password pass \ +ssh --hostname scripts/export-csv-report.gmp.py + $ gvm-script --gmp-username admin --gmp-password '0f6fa69b-32bb-453a-9aa4-b8c9e56b3d00' socket export-csv-report.gmp.py b26229cd-94c8-44f8-9cb6-27486a3dedad ./test.csv + """ + print(message) + sys.exit() + + +def main(gmp: Gmp, args: Namespace) -> None: + # check if report id and CSV filename are provided to the script + # argv[0] contains the script name + check_args(args) + + report_id = args.argv[1] + if len(args.argv) == 3: + csv_filename = args.argv[2] + ".csv" + else: + csv_filename = args.argv[1] + ".csv" + + csv_report_format_id = "c1645568-627a-11e3-a660-406186ea4fc5" + + response = gmp.get_report( + report_id=report_id, report_format_id=csv_report_format_id, ignore_pagination=True, details=True + ) + + report_element = response.find("report") + # get the full content of the report element + content = report_element.find("report_format").tail + + if not content: + print( + 'Requested report is empty. Either the report does not contain any ' + ' results or the necessary tools for creating the report are ' + 'not installed.', + file=sys.stderr, + ) + sys.exit(1) + + # convert content to 8-bit ASCII bytes + binary_base64_encoded_csv = content.encode('ascii') + + # decode base64 + binary_csv = b64decode(binary_base64_encoded_csv) + + # write to file and support ~ in filename path + csv_path = Path(csv_filename).expanduser() + + csv_path.write_bytes(binary_csv) + + print('Done. CSV created: ' + str(csv_path)) + + +if __name__ == '__gmp__': + main(gmp, args) + diff --git a/scripts/export-pdf-report.gmp.py b/scripts/export-pdf-report.gmp.py index 3465ee74..3bd0af96 100644 --- a/scripts/export-pdf-report.gmp.py +++ b/scripts/export-pdf-report.gmp.py @@ -1,5 +1,10 @@ # -*- coding: utf-8 -*- -# Copyright (C) 2019-2021 Greenbone AG +# +# Based on the Greenbone export-pdf-report script and modified to +# return more (all) details. +# Martin Boller +# +# Copyright (C) 2019-2021 Greenbone Networks GmbH # # SPDX-License-Identifier: GPL-3.0-or-later # @@ -15,6 +20,10 @@ # # You should have received a copy of the GNU General Public License # along with this program. If not, see . +# +# 2022-11-02 - Martin B +# Added ignore_pagination=True, details=True to get the full report +# import sys from argparse import Namespace @@ -50,14 +59,14 @@ def main(gmp: Gmp, args: Namespace) -> None: report_id = args.argv[1] if len(args.argv) == 3: - pdf_filename = args.argv[2] + pdf_filename = args.argv[2] + ".pdf" else: pdf_filename = args.argv[1] + ".pdf" pdf_report_format_id = "c402cc3e-b531-11e1-9163-406186ea4fc5" response = gmp.get_report( - report_id=report_id, report_format_id=pdf_report_format_id + report_id=report_id, report_format_id=pdf_report_format_id, ignore_pagination=True, details=True ) report_element = response.find("report") @@ -67,7 +76,7 @@ def main(gmp: Gmp, args: Namespace) -> None: if not content: print( "Requested report is empty. Either the report does not contain any " - " results or the necessary tools for creating the report are " + "results or the necessary tools for creating the report are " "not installed.", file=sys.stderr, ) diff --git a/scripts/export-xml-report.gmp.py b/scripts/export-xml-report.gmp.py new file mode 100755 index 00000000..9e0e377d --- /dev/null +++ b/scripts/export-xml-report.gmp.py @@ -0,0 +1,102 @@ +# -*- coding: utf-8 -*- +# +# Based on the Greenbone export-xml-report script and modified to +# return more (all) details. +# Martin Boller +# +# Copyright (C) 2019-2021 Greenbone Networks GmbH +# +# SPDX-License-Identifier: GPL-3.0-or-later +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +# 2022-11-02 - Martin B +# Added ignore_pagination=True, details=True to get the full report +# + +import sys +from argparse import Namespace +from base64 import b64decode +from pathlib import Path + +from gvm.protocols.gmp import Gmp + +from gvm.xml import pretty_print + +def check_args(args): + len_args = len(args.script) - 1 + if len_args < 1: + message = """ + This script requests the given report and exports it as a xml + file locally. It requires one parameters after the script name. + + 1. -- ID of the report + + Optional a file name to save the xml in. + + Example: + $ gvm-script --gmp-username name --gmp-password pass \ +ssh --hostname scripts/export-xml-report.gmp.py + """ + print(message) + sys.exit() + + +def main(gmp: Gmp, args: Namespace) -> None: + # check if report id and xml filename are provided to the script + # argv[0] contains the script name + check_args(args) + + report_id = args.argv[1] + if len(args.argv) == 3: + xml_filename = args.argv[2] + ".xml" + else: + xml_filename = args.argv[1] + ".xml" + + xml_report_format_id = "5057e5cc-b825-11e4-9d0e-28d24461215b" + + response = gmp.get_report( + report_id=report_id, report_format_id=xml_report_format_id, ignore_pagination=True, details=True + ) + + report_element = response.find("report") + data = pretty_print(report_element) + # get the full content of the report element + content = report_element.find("report_format").tail + + if not content: + print( + "Requested report is empty. Either the report does not contain any" + " results or the necessary tools for creating the report are " + "not installed.", + file=sys.stderr, + ) + sys.exit(1) + + # convert content to 8-bit ASCII bytes + binary_base64_encoded_xml = content.encode("ascii") + + # decode base64 + binary_xml = b64decode(binary_base64_encoded_xml) + + # write to file and support ~ in filename path + xml_path = Path(xml_filename).expanduser() + + xml_path.write_bytes(data) + + print("Done. xml created: " + str(xml_path)) + + +if __name__ == "__gmp__": + main(gmp, args) diff --git a/scripts/list-alerts.gmp.py b/scripts/list-alerts.gmp.py new file mode 100755 index 00000000..a8ce6e3f --- /dev/null +++ b/scripts/list-alerts.gmp.py @@ -0,0 +1,70 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 2019-2021 Greenbone Networks GmbH +# +# SPDX-License-Identifier: GPL-3.0-or-later +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +# Based on other Greenbone scripts +# +# Martin Boller +# + +from argparse import Namespace + +from gvm.protocols.gmp import Gmp + +from gvmtools.helper import Table + + +def main(gmp: Gmp, args: Namespace) -> None: + # pylint: disable=unused-argument + + response_xml = gmp.get_alerts(filter_string="rows=-1") + alerts_xml = response_xml.xpath("alert") + + heading = ["#", "Name", "Id", "Event", "Event type", "Method", "Condition", "In use"] + + rows = [] + numberRows = 0 + + print( + "Listing alerts.\n" + ) + + for alert in alerts_xml: + # Count number of reports + numberRows = numberRows + 1 + # Cast/convert to text to show in list + rowNumber = str(numberRows) + + name = "".join(alert.xpath("name/text()")) + alert_id = alert.get("id") + alert_condition = "".join(alert.xpath("condition/text()")) + alert_method = "".join(alert.xpath("method/text()")) + alert_event_type = "".join(alert.xpath("event/data/text()")) + alert_event = "".join(alert.xpath("event/text()")) + alert_inuse = "".join(alert.xpath("in_use/text()")) + if alert_inuse == "1": + alert_inuse = "Yes" + else: + alert_inuse = "No" + + rows.append([rowNumber, name, alert_id, alert_event, alert_event_type, alert_method, alert_condition, alert_inuse]) + + print(Table(heading=heading, rows=rows)) + + +if __name__ == "__gmp__": + main(gmp, args) diff --git a/scripts/list-credentials.gmp.py b/scripts/list-credentials.gmp.py new file mode 100755 index 00000000..65cd4f47 --- /dev/null +++ b/scripts/list-credentials.gmp.py @@ -0,0 +1,79 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 2019-2021 Greenbone Networks GmbH +# +# SPDX-License-Identifier: GPL-3.0-or-later +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +# Based on other Greenbone scripts +# +# Martin Boller +# + +from argparse import Namespace + +from gvm.protocols.gmp import Gmp + +from gvmtools.helper import Table + + +def main(gmp: Gmp, args: Namespace) -> None: + # pylint: disable=unused-argument + + response_xml = gmp.get_credentials(filter_string="rows=-1") + credentials_xml = response_xml.xpath("credential") + + heading = ["#", "Id", "Name", "Type", "Insecure use"] + + rows = [] + numberRows = 0 + + print( + "Listing credentials.\n" + ) + + for credential in credentials_xml: + # Count number of reports + numberRows = numberRows + 1 + # Cast/convert to text to show in list + rowNumber = str(numberRows) + + name = "".join(credential.xpath("name/text()")) + credential_id = credential.get("id") + cred_type = "".join(credential.xpath("type/text()")) + if cred_type.upper() == "UP": + cred_type = "Username + Password (up)" + elif cred_type.upper() == "USK": + cred_type = "Username + SSH Key (usk)" + elif cred_type.upper() == "SMIME": + cred_type = "S/MIME Certificate (smime)" + elif cred_type.upper() == "PGP": + cred_type = "PGP Encryption Key (pgp)" + elif cred_type.upper() == "SNMP": + cred_type = "Simple Network Management Protocol (snmp)" + elif cred_type.upper() == "PW": + cred_type = "Password only (pw)" + cred_insecureuse = "".join(credential.xpath("allow_insecure/text()")) + if cred_insecureuse == "1": + cred_insecureuse = "Yes" + else: + cred_insecureuse = "No" + + rows.append([rowNumber, credential_id, name, cred_type, cred_insecureuse]) + + print(Table(heading=heading, rows=rows)) + + +if __name__ == "__gmp__": + main(gmp, args) diff --git a/scripts/list-feeds.gmp.py b/scripts/list-feeds.gmp.py new file mode 100755 index 00000000..94a79a37 --- /dev/null +++ b/scripts/list-feeds.gmp.py @@ -0,0 +1,68 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 2019-2021 Greenbone Networks GmbH +# +# SPDX-License-Identifier: GPL-3.0-or-later +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +# +# Based on other Greenbone scripts +# +# Martin Boller +# + +from argparse import Namespace + +from gvm.protocols.gmp import Gmp + +from gvmtools.helper import Table + +#from gvm.xml import pretty_print + +def main(gmp: Gmp, args: Namespace) -> None: + # pylint: disable=unused-argument + + response_xml = gmp.get_feeds() + feeds_xml = response_xml.xpath("feed") + heading = ["#", "Name", "Version", "Status"] + rows = [] + numberRows = 0 +# pretty_print(feeds_xml) + + print( + "Listing feeds and their status.\n" + ) + + for feed in feeds_xml: + # Count number of reports + numberRows = numberRows + 1 + # Cast/convert to text to show in list + rowNumber = str(numberRows) + name = "".join(feed.xpath("name/text()")) + version = "".join(feed.xpath("version/text()")) + type = "".join(feed.xpath("type/text()")) + status = "".join(feed.xpath("currently_syncing/timestamp/text()")) + if not status: + status = "Up-to-date..." + else: + status = "Update in progress..." + + + rows.append([rowNumber, name, version, status]) + + print(Table(heading=heading, rows=rows)) + + +if __name__ == "__gmp__": + main(gmp, args) diff --git a/scripts/list-filters.gmp.py b/scripts/list-filters.gmp.py new file mode 100755 index 00000000..18f69886 --- /dev/null +++ b/scripts/list-filters.gmp.py @@ -0,0 +1,63 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 2019-2021 Greenbone Networks GmbH +# +# SPDX-License-Identifier: GPL-3.0-or-later +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +# Based on other Greenbone scripts +# +# Martin Boller +# + +from argparse import Namespace + +from gvm.protocols.gmp import Gmp + +from gvmtools.helper import Table + + +def main(gmp: Gmp, args: Namespace) -> None: + # pylint: disable=unused-argument + + response_xml = gmp.get_filters(filter_string="rows=-1") + filters_xml = response_xml.xpath("filter") + + heading = ["#", "Name", "Id", "Modified", "Type", "Term"] + + rows = [] + numberRows = 0 + + print( + "Listing filters.\n" + ) + + for filter in filters_xml: + # Count number of reports + numberRows = numberRows + 1 + # Cast/convert to text to show in list + rowNumber = str(numberRows) + + name = "".join(filter.xpath("name/text()")) + modified = "".join(filter.xpath("modification_time/text()")) + term = "".join(filter.xpath("term/text()")) + type = "".join(filter.xpath("type/text()")) + filter_id = filter.get("id") + rows.append([rowNumber, name, filter_id, modified, type, term]) + + print(Table(heading=heading, rows=rows)) + + +if __name__ == "__gmp__": + main(gmp, args) diff --git a/scripts/list-groups.gmp.py b/scripts/list-groups.gmp.py new file mode 100755 index 00000000..6146981b --- /dev/null +++ b/scripts/list-groups.gmp.py @@ -0,0 +1,62 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 2019-2021 Greenbone Networks GmbH +# +# SPDX-License-Identifier: GPL-3.0-or-later +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +# Based on other Greenbone scripts +# +# Martin Boller +# + +from argparse import Namespace + +from gvm.protocols.gmp import Gmp + +from gvmtools.helper import Table + + +def main(gmp: Gmp, args: Namespace) -> None: + # pylint: disable=unused-argument + + response_xml = gmp.get_groups(filter_string="rows=-1") + groups_xml = response_xml.xpath("group") + + heading = ["#", "Name", "Id", "Members"] + + rows = [] + numberRows = 0 + + print( + "Listing groups.\n" + ) + + for group in groups_xml: + # Count number of reports + numberRows = numberRows + 1 + # Cast/convert to text to show in list + rowNumber = str(numberRows) + + name = "".join(group.xpath("name/text()")) + group_id = group.get("id") + group_members = "".join(group.xpath("users/text()")) + + rows.append([rowNumber, name, group_id, group_members]) + + print(Table(heading=heading, rows=rows)) + + +if __name__ == "__gmp__": + main(gmp, args) diff --git a/scripts/list-policies.gmp.py b/scripts/list-policies.gmp.py new file mode 100755 index 00000000..10429e6a --- /dev/null +++ b/scripts/list-policies.gmp.py @@ -0,0 +1,62 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 2019-2021 Greenbone Networks GmbH +# +# SPDX-License-Identifier: GPL-3.0-or-later +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +# Based on other Greenbone scripts +# +# Martin Boller +# + +from argparse import Namespace + +from gvm.protocols.gmp import Gmp + +from gvmtools.helper import Table + + +def main(gmp: Gmp, args: Namespace) -> None: + # pylint: disable=unused-argument + + response_xml = gmp.get_policies(filter_string="rows=-1") + policies_xml = response_xml.xpath("config") + + heading = ["#", "Name", "Id", "NVT Count"] + + rows = [] + numberRows = 0 + + print( + "Listing compliance policies.\n" + ) + + for policy in policies_xml: + # Count number of reports + numberRows = numberRows + 1 + # Cast/convert to text to show in list + rowNumber = str(numberRows) + + name = "".join(policy.xpath("name/text()")) + policy_id = policy.get("id") + policy_nvt = "".join(policy.xpath("nvt_count/text()")) + + rows.append([rowNumber, name, policy_id, policy_nvt]) + + print(Table(heading=heading, rows=rows)) + + +if __name__ == "__gmp__": + main(gmp, args) diff --git a/scripts/list-portlists.gmp.py b/scripts/list-portlists.gmp.py new file mode 100755 index 00000000..4a01857c --- /dev/null +++ b/scripts/list-portlists.gmp.py @@ -0,0 +1,64 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 2019-2021 Greenbone Networks GmbH +# +# SPDX-License-Identifier: GPL-3.0-or-later +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +# Based on other Greenbone scripts +# +# Martin Boller +# + +from argparse import Namespace + +from gvm.protocols.gmp import Gmp + +from gvmtools.helper import Table + + +def main(gmp: Gmp, args: Namespace) -> None: + # pylint: disable=unused-argument + + response_xml = gmp.get_port_lists(filter_string="rows=-1") + portlists_xml = response_xml.xpath("port_list") + + heading = ["#", "Name", "Id", "Ports All", "Ports TCP", "Ports UDP"] + + rows = [] + numberRows = 0 + + print( + "Listing portlists.\n" + ) + + for portlist in portlists_xml: + # Count number of reports + numberRows = numberRows + 1 + # Cast/convert to text to show in list + rowNumber = str(numberRows) + + name = "".join(portlist.xpath("name/text()")) + port_list_id = portlist.get("id") + port_all = "".join(portlist.xpath("port_count/all/text()")) + port_tcp = "".join(portlist.xpath("port_count/tcp/text()")) + port_udp = "".join(portlist.xpath("port_count/udp/text()")) + + rows.append([rowNumber, name, port_list_id, port_all, port_tcp, port_udp]) + + print(Table(heading=heading, rows=rows)) + + +if __name__ == "__gmp__": + main(gmp, args) diff --git a/scripts/list-report-formats.gmp.py b/scripts/list-report-formats.gmp.py new file mode 100755 index 00000000..93314c37 --- /dev/null +++ b/scripts/list-report-formats.gmp.py @@ -0,0 +1,61 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 2019-2021 Greenbone Networks GmbH +# +# SPDX-License-Identifier: GPL-3.0-or-later +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +# +# Based on other Greenbone scripts +# +# Martin Boller +# + +from argparse import Namespace + +from gvm.protocols.gmp import Gmp + +from gvmtools.helper import Table + + +def main(gmp: Gmp, args: Namespace) -> None: + # pylint: disable=unused-argument + + response_xml = gmp.get_report_formats(details=True, filter_string="rows=-1") + report_formats_xml = response_xml.xpath("report_format") + heading = ["#", "Name", "Id", "Summary"] + rows = [] + numberRows = 0 + + print( + "Listing report formats.\n" + ) + + for report_format in report_formats_xml: + # Count number of reports + numberRows = numberRows + 1 + # Cast/convert to text to show in list + rowNumber = str(numberRows) + name = "".join(report_format.xpath("name/text()")) + report_format_id = report_format.get("id") + report_format_summary = "".join(report_format.xpath("summary/text()")) + report_format_description = "".join(report_format.xpath("description/text()")) + + rows.append([rowNumber, name, report_format_id, report_format_summary]) + + print(Table(heading=heading, rows=rows)) + + +if __name__ == "__gmp__": + main(gmp, args) diff --git a/scripts/list-reports.gmp.py b/scripts/list-reports.gmp.py new file mode 100755 index 00000000..e8cb1e20 --- /dev/null +++ b/scripts/list-reports.gmp.py @@ -0,0 +1,153 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 2019-2021 Greenbone Networks GmbH +# +# SPDX-License-Identifier: GPL-3.0-or-later +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +# Based on other Greenbone scripts +# +# Martin Boller 2023-05-15 +# +# run script with e.g. gvm-script --gmp-username username --gmp-password password socket list-reports.gmp.py All +# + +from gvm.protocols.gmp import Gmp + +from gvmtools.helper import Table + +from argparse import ArgumentParser, Namespace, RawTextHelpFormatter + +HELP_TEXT = ( + "This script list reports with the status " + "defined on the commandline. Status can be: \n" + "Requested, Queued, Interrupted, Running, or Done \n" + "Note: Case matters. E.g. - done - won't work, but - Done - will" +) + + +def check_args(args): + len_args = len(args.script) - 1 + if len_args != 1: + message = """ + This script lists all reports depending on status. + One parameter after the script name is required. + + 1. Status -- Either \"All\", \"Requested\", \"Queued\", \"Interrupted\", \"Running\", \"StopRequested\", \"Stopped\", or \"Done\" + + Example: + $ gvm-script --gmp-username name --gmp-password pass \ +socket list-reports.gmp.py Done \n + """ + print(message) + sys.exit() + +def parse_args(args: Namespace) -> Namespace: # pylint: disable=unused-argument + """Parsing args ...""" + + parser = ArgumentParser( + prefix_chars="+", + add_help=False, + formatter_class=RawTextHelpFormatter, + description=HELP_TEXT, + ) + + parser.add_argument( + "+h", + "++help", + action="help", + help="Show this help message and exit.", + ) + + parser.add_argument( + "status_cmd", + type=str, + help=("Status: \"All\", \"Queued\", \"Requested\", \"Interrupted\", \"Running\", \"Stop Requested\", \"Stopped\" or \"Done\""), + ) + script_args, _ = parser.parse_known_args(args) + return script_args + +def list_reports ( + gmp: Gmp, + status: str, +): + str_status = status + if status.upper() == "ALL": + status = "All" + elif status.upper() == "REQUESTED": + str_status = "Requested" + elif status.upper() == "INTERRUPTED": + str_status = "Interrupted" + elif status.upper() == "QUEUED": + str_status = "Queued" + elif status.upper()[:6] == "STOPRE": + str_status = "Stop Requested" + elif status.upper()[:6] == "STOP R": + str_status = "Stop Requested" + elif status.upper() == "DONE": + str_status = "Done" + elif status.upper() == "RUNNING": + str_status = "Running" + elif status.upper() == "STOPPED": + str_status = "Stopped" + else: + str_status="All" + + print("Reports with status: " + str_status + "\n") + + if str_status == "All": + response_xml = gmp.get_reports(ignore_pagination=True, details=True, filter_string="rows=-1") + else: + response_xml = gmp.get_reports(ignore_pagination=True, details=True, filter_string="status=" + str_status + " and sort-reverse=name and rows=-1") + + reports_xml = response_xml.xpath("report") + heading = ["#", "Id", "Creation Time", "Modification Time", "Task Name", "Status", "Progress"] + rows = [] + numberRows = 0 + + for report in reports_xml: + # Count number of reports + numberRows = numberRows + 1 + # Cast/convert to text to show in list + rowNumber = str(numberRows) + creation_time = "".join(report.xpath("creation_time/text()")) + #report_name = "".join(report.xpath("name/text()")) # Report name is the same as Creation Time + report_id = report.get("id") + report_task = "".join(report.xpath("task/name/text()")) + mod_time = "".join(report.xpath("modification_time/text()")) + report_status = "".join(report.xpath("report/scan_run_status/text()")) + report_progress = "".join(report.xpath("report/task/progress/text()")) + "%" + rows.append([rowNumber, report_id, creation_time, mod_time, report_task, report_status, report_progress]) + + print(Table(heading=heading, rows=rows)) + +def main(gmp: Gmp, args: Namespace) -> None: + # pylint: disable=unused-argument + if args.script: + args = args.script[1:] + + parsed_args = parse_args(args = args) + + print( + "Listing reports.\n" + ) + + list_reports ( + gmp, + parsed_args.status_cmd + ) + +if __name__ == "__gmp__": + main(gmp, args) + diff --git a/scripts/list-roles.gmp.py b/scripts/list-roles.gmp.py new file mode 100755 index 00000000..eebea991 --- /dev/null +++ b/scripts/list-roles.gmp.py @@ -0,0 +1,62 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 2019-2021 Greenbone Networks GmbH +# +# SPDX-License-Identifier: GPL-3.0-or-later +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +# Based on other Greenbone scripts +# +# Martin Boller +# + +from argparse import Namespace + +from gvm.protocols.gmp import Gmp + +from gvmtools.helper import Table + + +def main(gmp: Gmp, args: Namespace) -> None: + # pylint: disable=unused-argument + + response_xml = gmp.get_roles(filter_string="rows=-1") + roles_xml = response_xml.xpath("role") + + heading = ["#", "Name", "Id", "Members"] + + rows = [] + numberRows = 0 + + print( + "Listing roles.\n" + ) + + for role in roles_xml: + # Count number of reports + numberRows = numberRows + 1 + # Cast/convert to text to show in list + rowNumber = str(numberRows) + + name = "".join(role.xpath("name/text()")) + role_id = role.get("id") + role_members = "".join(role.xpath("users/text()")) + + rows.append([rowNumber, name, role_id, role_members]) + + print(Table(heading=heading, rows=rows)) + + +if __name__ == "__gmp__": + main(gmp, args) diff --git a/scripts/list-scan-configs.gmp.py b/scripts/list-scan-configs.gmp.py new file mode 100755 index 00000000..6bd66490 --- /dev/null +++ b/scripts/list-scan-configs.gmp.py @@ -0,0 +1,62 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 2019-2021 Greenbone Networks GmbH +# +# SPDX-License-Identifier: GPL-3.0-or-later +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +# Based on other Greenbone scripts +# +# Martin Boller +# + +from argparse import Namespace + +from gvm.protocols.gmp import Gmp + +from gvmtools.helper import Table + + +def main(gmp: Gmp, args: Namespace) -> None: + # pylint: disable=unused-argument + + response_xml = gmp.get_scan_configs(filter_string="rows=-1") + scan_configs_xml = response_xml.xpath("config") + + heading = ["#", "Name", "Id", "NVT Count"] + + rows = [] + numberRows = 0 + + print( + "Listing scan configurations.\n" + ) + + for scan_config in scan_configs_xml: + # Count number of reports + numberRows = numberRows + 1 + # Cast/convert to text to show in list + rowNumber = str(numberRows) + + name = "".join(scan_config.xpath("name/text()")) + scan_config_id = scan_config.get("id") + scan_config_nvt = "".join(scan_config.xpath("nvt_count/text()")) + + rows.append([rowNumber, name, scan_config_id, scan_config_nvt]) + + print(Table(heading=heading, rows=rows)) + + +if __name__ == "__gmp__": + main(gmp, args) diff --git a/scripts/list-scanners.gmp.py b/scripts/list-scanners.gmp.py new file mode 100755 index 00000000..8c2aebe4 --- /dev/null +++ b/scripts/list-scanners.gmp.py @@ -0,0 +1,62 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 2019-2021 Greenbone Networks GmbH +# +# SPDX-License-Identifier: GPL-3.0-or-later +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +# Based on other Greenbone scripts +# +# Martin Boller +# + +from argparse import Namespace + +from gvm.protocols.gmp import Gmp + +from gvmtools.helper import Table + + +def main(gmp: Gmp, args: Namespace) -> None: + # pylint: disable=unused-argument + + response_xml = gmp.get_scanners(filter_string="rows=-1") + scanners_xml = response_xml.xpath("scanner") + + heading = ["#", "Name", "Id", "host"] + + rows = [] + numberRows = 0 + + print( + "Listing scanners.\n" + ) + + for scanner in scanners_xml: + # Count number of reports + numberRows = numberRows + 1 + # Cast/convert to text to show in list + rowNumber = str(numberRows) + + name = "".join(scanner.xpath("name/text()")) + scanner_id = scanner.get("id") + host = "".join(scanner.xpath("host/text()")) + + rows.append([rowNumber, name, scanner_id, host]) + + print(Table(heading=heading, rows=rows)) + + +if __name__ == "__gmp__": + main(gmp, args) diff --git a/scripts/list-schedules.gmp.py b/scripts/list-schedules.gmp.py new file mode 100755 index 00000000..fd731d0f --- /dev/null +++ b/scripts/list-schedules.gmp.py @@ -0,0 +1,64 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 2019-2021 Greenbone Networks GmbH +# +# SPDX-License-Identifier: GPL-3.0-or-later +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +# Based on other Greenbone scripts +# +# Martin Boller +# + +from argparse import Namespace + +from gvm.protocols.gmp import Gmp + +from gvmtools.helper import Table + + +def main(gmp: Gmp, args: Namespace) -> None: + # pylint: disable=unused-argument + + response_xml = gmp.get_schedules(filter_string="rows=-1") + schedules_xml = response_xml.xpath("schedule") + + heading = ["#", "Name", "Id", "TZ", "iCalendar"] + + rows = [] + numberRows = 0 + + print( + "Listing schedules.\n" + ) + + for schedule in schedules_xml: + # Count number of reports + numberRows = numberRows + 1 + # Cast/convert to text to show in list + rowNumber = str(numberRows) + + name = "".join(schedule.xpath("name/text()")) + schedule_id = schedule.get("id") + icalendar = "".join(schedule.xpath("icalendar/text()")) + timezone = "".join(schedule.xpath("timezone/text()")) + rows.append([rowNumber, name, schedule_id, timezone, icalendar]) + #print(icalendar) + + print(Table(heading=heading, rows=rows)) + + +if __name__ == "__gmp__": + main(gmp, args) + diff --git a/scripts/list-tags.gmp.py b/scripts/list-tags.gmp.py new file mode 100755 index 00000000..ad2e0155 --- /dev/null +++ b/scripts/list-tags.gmp.py @@ -0,0 +1,64 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 2019-2021 Greenbone Networks GmbH +# +# SPDX-License-Identifier: GPL-3.0-or-later +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +# Based on other Greenbone scripts +# +# Martin Boller +# + +from argparse import Namespace + +from gvm.protocols.gmp import Gmp + +from gvmtools.helper import Table + + +def main(gmp: Gmp, args: Namespace) -> None: + # pylint: disable=unused-argument + + response_xml = gmp.get_tags(filter_string="rows=-1") + tags_xml = response_xml.xpath("tag") + + heading = ["#", "Name", "Id", "Modified", "Value", "Type", "Count"] + + rows = [] + numberRows = 0 + + print( + "Listing tags.\n" + ) + + for tag in tags_xml: + # Count number of reports + numberRows = numberRows + 1 + # Cast/convert to text to show in list + rowNumber = str(numberRows) + + name = "".join(tag.xpath("name/text()")) + modified = "".join(tag.xpath("modification_time/text()")) + value = "".join(tag.xpath("value/text()")) + type = "".join(tag.xpath("resources/type/text()")) + count = "".join(tag.xpath("resources/count/total/text()")) + tag_id = tag.get("id") + rows.append([rowNumber, name, tag_id, modified, value, type, count]) + + print(Table(heading=heading, rows=rows)) + + +if __name__ == "__gmp__": + main(gmp, args) diff --git a/scripts/list-targets.gmp.py b/scripts/list-targets.gmp.py new file mode 100755 index 00000000..5ccfbfaf --- /dev/null +++ b/scripts/list-targets.gmp.py @@ -0,0 +1,66 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 2019-2021 Greenbone Networks GmbH +# +# SPDX-License-Identifier: GPL-3.0-or-later +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +# Based on other Greenbone scripts +# +# Martin Boller +# + +from argparse import Namespace + +from gvm.protocols.gmp import Gmp + +from gvmtools.helper import Table + + +def main(gmp: Gmp, args: Namespace) -> None: + # pylint: disable=unused-argument + + response_xml = gmp.get_targets(filter_string="rows=-1") + targets_xml = response_xml.xpath("target") + + heading = ["#", "Name", "Id", "Count", "SSH Credential", "SMB Cred", "ESXi Cred", "SNMP Cred", "Alive test"] + + rows = [] + numberRows = 0 + + print( + "Listing targets.\n" + ) + + for target in targets_xml: + # Count number of reports + numberRows = numberRows + 1 + # Cast/convert to text to show in list + rowNumber = str(numberRows) + + name = "".join(target.xpath("name/text()")) + maxhosts = "".join(target.xpath("max_hosts/text()")) + sshcred = "".join(target.xpath("ssh_credential/name/text()")) + smbcred = "".join(target.xpath("smb_credential/name/text()")) + esxicred = "".join(target.xpath("esxi_credential/name/text()")) + snmpcred = "".join(target.xpath("snmp_credential/name/text()")) + target_id = target.get("id") + alive_test = "".join(target.xpath("alive_tests/text()")) + rows.append([rowNumber, name, target_id, maxhosts, sshcred, smbcred, esxicred, snmpcred, alive_test]) + + print(Table(heading=heading, rows=rows)) + + +if __name__ == "__gmp__": + main(gmp, args) diff --git a/scripts/list-tasks.gmp.py b/scripts/list-tasks.gmp.py index a5f2bc1e..05ebe5fa 100644 --- a/scripts/list-tasks.gmp.py +++ b/scripts/list-tasks.gmp.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright (C) 2019-2021 Greenbone AG +# Copyright (C) 2019-2021 Greenbone Networks GmbH # # SPDX-License-Identifier: GPL-3.0-or-later # @@ -15,6 +15,11 @@ # # You should have received a copy of the GNU General Public License # along with this program. If not, see . +# +# Based on other Greenbone scripts +# +# Martin Boller +# from argparse import Namespace @@ -26,19 +31,31 @@ def main(gmp: Gmp, args: Namespace) -> None: # pylint: disable=unused-argument - response_xml = gmp.get_tasks() + response_xml = gmp.get_tasks(details=True, filter_string="rows=-1") tasks_xml = response_xml.xpath("task") - heading = ["ID", "Name", "Severity"] + heading = ["#", "Name", "Id", "Target", "Scanner", "Scan Order", "Severity"] rows = [] + numberRows = 0 + + print( + "Listing tasks.\n" + ) for task in tasks_xml: + # Count number of reports + numberRows = numberRows + 1 + # Cast/convert to text to show in list + rowNumber = str(numberRows) + name = "".join(task.xpath("name/text()")) task_id = task.get("id") + targetname = "".join(task.xpath("target/name/text()")) + scanner = "".join(task.xpath("scanner/name/text()")) severity = "".join(task.xpath("last_report/report/severity/text()")) - - rows.append([task_id, name, severity]) + order = "".join(task.xpath("hosts_ordering/text()")) + rows.append([rowNumber, name, task_id, targetname, scanner, order, severity]) print(Table(heading=heading, rows=rows)) diff --git a/scripts/list-tickets.gmp.py b/scripts/list-tickets.gmp.py new file mode 100755 index 00000000..84e7bd15 --- /dev/null +++ b/scripts/list-tickets.gmp.py @@ -0,0 +1,70 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 2019-2021 Greenbone Networks GmbH +# +# SPDX-License-Identifier: GPL-3.0-or-later +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +# Based on other Greenbone scripts +# +# Martin Boller +# + +from argparse import Namespace + +from gvm.protocols.gmp import Gmp + +from gvmtools.helper import Table + + +def main(gmp: Gmp, args: Namespace) -> None: + # pylint: disable=unused-argument + + response_xml = gmp.get_tickets(filter_string="rows=-1") + tickets_xml = response_xml.xpath("ticket") + + heading = ["#", "Name", "Host", "Task", "Status", "Note"] + + rows = [] + numberRows = 0 + + print( + "Listing tickets.\n" + ) + + for ticket in tickets_xml: + # Count number of reports + numberRows = numberRows + 1 + # Cast/convert to text to show in list + rowNumber = str(numberRows) + + name = "".join(ticket.xpath("name/text()")) + ticket_id = ticket.get("id") + ticket_status = "".join(ticket.xpath("status/text()")) + ticket_task = "".join(ticket.xpath("task/name/text()")) + ticket_host = "".join(ticket.xpath("host/text()")) + if ticket_status.upper() == "OPEN": + ticket_note = "".join(ticket.xpath("open_note/text()")) + elif ticket_status.upper() == "FIXED": + ticket_note = "".join(ticket.xpath("fixed_note/text()")) + elif ticket_status.upper() == "CLOSED": + ticket_note = "".join(ticket.xpath("closed_note/text()")) + + rows.append([rowNumber, name, ticket_host, ticket_task, ticket_status, ticket_note]) + + print(Table(heading=heading, rows=rows)) + + +if __name__ == "__gmp__": + main(gmp, args) diff --git a/scripts/list-users.gmp.py b/scripts/list-users.gmp.py new file mode 100755 index 00000000..99c3e906 --- /dev/null +++ b/scripts/list-users.gmp.py @@ -0,0 +1,63 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 2019-2021 Greenbone Networks GmbH +# +# SPDX-License-Identifier: GPL-3.0-or-later +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +# Based on other Greenbone scripts +# +# Martin Boller +# + +from argparse import Namespace + +from gvm.protocols.gmp import Gmp + +from gvmtools.helper import Table + + +def main(gmp: Gmp, args: Namespace) -> None: + # pylint: disable=unused-argument + + response_xml = gmp.get_users(filter_string="rows=-1") + users_xml = response_xml.xpath("user") + + heading = ["#", "Name", "Id", "Role", "Groups"] + + rows = [] + numberRows = 0 + + print( + "Listing users.\n" + ) + + for user in users_xml: + # Count number of reports + numberRows = numberRows + 1 + # Cast/convert to text to show in list + rowNumber = str(numberRows) + + name = "".join(user.xpath("name/text()")) + user_id = user.get("id") + user_role = "".join(user.xpath("role/name/text()")) + user_groups = "".join(user.xpath("groups/group/name/text()")) + + rows.append([rowNumber, name, user_id, user_role, user_groups]) + + print(Table(heading=heading, rows=rows)) + + +if __name__ == "__gmp__": + main(gmp, args) diff --git a/scripts/start-scans-from-csv.py b/scripts/start-scans-from-csv.py new file mode 100755 index 00000000..a10e5b6d --- /dev/null +++ b/scripts/start-scans-from-csv.py @@ -0,0 +1,157 @@ +# -*- coding: utf-8 -*- +# +# Loosely based on Greenbone sample scripts +# As provided by Greenbone in the gvm-tools repo +# +# Martin Boller +# +# SPDX-License-Identifier: GPL-3.0-or-later +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +# Run with gvm-script --gmp-username admin-user --gmp-password password socket start-scans-from-csv.gmp.py startscans.csv +# + +import sys +import time +import csv +import json + +from argparse import ArgumentParser, Namespace, RawTextHelpFormatter +from pathlib import Path +from typing import List +from gvm.errors import GvmResponseError + +from gvm.protocols.gmp import Gmp + +from gvmtools.helper import error_and_exit + +HELP_TEXT = ( + "This script pulls task names from a csv file and starts the tasks listed in every row. \n" +) + +def check_args(args): + len_args = len(args.script) - 1 + if len_args != 2: + message = """ + This script pulls tasks from a csv file and creates a \ +task for each row in the csv file. + One parameter after the script name is required. + + 1. -- csv file containing names and secrets required for scan tasks + + Example: + $ gvm-script --gmp-username name --gmp-password pass \ +ssh --hostname scripts/start_tasks_from_csv.gmp.py \ + + """ + print(message) + sys.exit() + + +def parse_args(args: Namespace) -> Namespace: # pylint: disable=unused-argument + """Parsing args ...""" + + parser = ArgumentParser( + prefix_chars="+", + add_help=False, + formatter_class=RawTextHelpFormatter, + description=HELP_TEXT, + ) + + parser.add_argument( + "+h", + "++help", + action="help", + help="Show this help message and exit.", + ) + + parser.add_argument( + "task_file", + type=str, + help=("CSV File containing tasks"), + ) + script_args, _ = parser.parse_known_args(args) + return script_args + +def task_id( + gmp: Gmp, + task_name: str, +): + response_xml = gmp.get_tasks(filter_string="rows=-1, not status=Running and " + "not status=Requested and not " + "status=Queued " + "and name=" + task_name) + tasks_xml = response_xml.xpath("task") + task_id = "" + + for task in tasks_xml: + name = "".join(task.xpath("name/text()")) + task_id = task.get("id") + #print("Requesting start of task: " + task_name + " Task UUID: " + task_id) + return task_id + +def start_tasks( + gmp: Gmp, + task_file: Path, +): + try: + numbertasks = 0 + with open(task_file, encoding="utf-8") as csvFile: + content = csv.reader(csvFile, delimiter=',') #read the data + try: + for row in content: #loop through each row + if len(row) == 0: + continue + task_start = task_id(gmp, row[0]) + if task_start: + numbertasks = numbertasks + 1 + print(f"Starting task name: {row[0]} with uuid: {task_start} ...") + status_text = gmp.start_task(task_start).xpath( + "@status_text" + )[0] + print(status_text) + else: + print("Task " + row[0] + " is either in status Requested, Queued, Running, or does not exist on this system.\n") + except GvmResponseError as gvmerr: + print(f"{gvmerr=}, task: {task_start}") + pass + csvFile.close() #close the csv file + + except IOError as e: + error_and_exit(f"Failed to read task_file: {str(e)} (exit)") + + return numbertasks + +def main(gmp: Gmp, args: Namespace) -> None: + # pylint: disable=undefined-variable + if args.script: + args = args.script[1:] + + parsed_args = parse_args(args=args) + + print( + "Starting tasks.\n" + ) + + numbertasks = start_tasks( + gmp, + parsed_args.task_file, + ) + + numbertasks = str(numbertasks) + print(" \n [" + numbertasks + "] task(s)/scan(s) started!\n") + +if __name__ == "__gmp__": + main(gmp, args) diff --git a/scripts/stop-all-scans.gmp.py b/scripts/stop-all-scans.gmp.py new file mode 100755 index 00000000..2feffc79 --- /dev/null +++ b/scripts/stop-all-scans.gmp.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 2019-2021 Greenbone Networks GmbH +# +# SPDX-License-Identifier: GPL-3.0-or-later +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +# Based on other Greenbone scripts +# +# Martin Boller +# + +from argparse import Namespace + +from gvm.protocols.gmp import Gmp + +from gvmtools.helper import Table + +def stop_tasks(gmp: Gmp) -> None: + tasks = gmp.get_tasks( + filter_string="rows=-1 status=Running or status=Requested or status=Queued" + ) + try: + for task_id in tasks.xpath("task/@id"): + print(f"Stopping task {task_id} ... ") + gmp.stop_task(task_id).xpath( + "@status_text" + )[0] + print(status_text) + except: + pass + +def main(gmp: Gmp, args: Namespace) -> None: + # pylint: disable=undefined-variable + print( + "This script stops all tasks on the system.\n" + ) + + stop_tasks(gmp) + +if __name__ == "__gmp__": + main(gmp, args) diff --git a/scripts/stop-scans-from-csv.py b/scripts/stop-scans-from-csv.py new file mode 100755 index 00000000..c80ee3c5 --- /dev/null +++ b/scripts/stop-scans-from-csv.py @@ -0,0 +1,160 @@ +# -*- coding: utf-8 -*- +# +# Loosely based on Greenbone sample scripts +# As provided by Greenbone in the gvm-tools repo +# +# Martin Boller +# +# SPDX-License-Identifier: GPL-3.0-or-later +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +# Run with gvm-script --gmp-username admin-user --gmp-password password socket start-scans-from-csv.gmp.py startscans.csv +# + +import sys +import time +import csv +import json + +from argparse import ArgumentParser, Namespace, RawTextHelpFormatter +from pathlib import Path +from typing import List +from gvm.errors import GvmResponseError + +from gvm.protocols.gmp import Gmp + +from gvmtools.helper import error_and_exit + +HELP_TEXT = ( + "This script pulls task names from a csv file and starts the tasks listed in every row. \n" +) + +def check_args(args): + len_args = len(args.script) - 1 + if len_args != 2: + message = """ + This script pulls tasks from a csv file and creates a \ +task for each row in the csv file. + One parameter after the script name is required. + + 1. -- csv file containing names and secrets required for scan tasks + + Example: + $ gvm-script --gmp-username name --gmp-password pass \ +ssh --hostname scripts/stop_tasks_from_csv.gmp.py \ + + """ + print(message) + sys.exit() + + +def parse_args(args: Namespace) -> Namespace: # pylint: disable=unused-argument + """Parsing args ...""" + + parser = ArgumentParser( + prefix_chars="+", + add_help=False, + formatter_class=RawTextHelpFormatter, + description=HELP_TEXT, + ) + + parser.add_argument( + "+h", + "++help", + action="help", + help="Show this help message and exit.", + ) + + parser.add_argument( + "task_file", + type=str, + help=("CSV File containing tasks"), + ) + script_args, _ = parser.parse_known_args(args) + return script_args + +def task_id( + gmp: Gmp, + task_name: str, +): + response_xml = gmp.get_tasks(filter_string="rows=-1, status=Running " + "or status=Requested " + "or status=Queued " + "and name=" + task_name) + tasks_xml = response_xml.xpath("task") + task_id = "" + + for task in tasks_xml: + name = "".join(task.xpath("name/text()")) + task_id = task.get("id") + #print("Requesting stop of task: " + task_name + " Task UUID: " + task_id) + return task_id + +def stop_tasks( + gmp: Gmp, + task_file: Path, +): + try: + numbertasks = 0 + with open(task_file, encoding="utf-8") as csvFile: + content = csv.reader(csvFile, delimiter=',') #read the data + try: + for row in content: #loop through each row + if len(row) == 0: + continue + task_stop = task_id(gmp, row[0]) + if task_stop: + numbertasks = numbertasks + 1 + print(f"Stopping task name: {row[0]} with uuid: {task_stop} ...") + status_text = gmp.stop_task(task_stop).xpath( + "@status_text" + )[0] + print(status_text) + else: + print("Task " + row[0] + " is either in status Stopped, Stop Requested, or does not exist on this system.\n") + except GvmResponseError as gvmerr: + print(f"{gvmerr=}, task: {task_stop}") + pass + csvFile.close() #close the csv file + + except IOError as e: + error_and_exit(f"Failed to read task_file: {str(e)} (exit)") + + if len(row) == 0: + error_and_exit("tasks file is empty (exit)") + + return numbertasks + +def main(gmp: Gmp, args: Namespace) -> None: + # pylint: disable=undefined-variable + if args.script: + args = args.script[1:] + + parsed_args = parse_args(args=args) + + print( + "Stopping tasks.\n" + ) + + numbertasks = stop_tasks( + gmp, + parsed_args.task_file, + ) + + numbertasks = str(numbertasks) + print(" \n [" + numbertasks + "] task(s)/scan(s) stopped!\n") + +if __name__ == "__gmp__": + main(gmp, args) From a82c6052cabe0688747e4e853b3c91f770a8c713 Mon Sep 17 00:00:00 2001 From: Martin Boller Date: Fri, 3 May 2024 19:50:21 +0200 Subject: [PATCH 2/7] Update scripts/create-alerts-from-csv.gmp.py Co-authored-by: Jaspar S. --- scripts/create-alerts-from-csv.gmp.py | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/scripts/create-alerts-from-csv.gmp.py b/scripts/create-alerts-from-csv.gmp.py index 2e5e8b1f..3a4633dd 100755 --- a/scripts/create-alerts-from-csv.gmp.py +++ b/scripts/create-alerts-from-csv.gmp.py @@ -1,24 +1,10 @@ -# -*- coding: utf-8 -*- -# -# Loosely based on Greenbone sample scripts -# As provided by Greenbone in the gvm-tools repo -# -# Martin Boller +# SPDX-FileCopyrightText: 2024 Martin Boller # # SPDX-License-Identifier: GPL-3.0-or-later # -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . + +# Loosely based on Greenbone sample scripts +# As provided by Greenbone in the gvm-tools repo # # Run with gvm-script --gmp-username admin-user --gmp-password password socket create-alerts-from-csv.gmp.py alerts.csv # From 112f513c94d824ccc606507d3ff671ff33fc8bad Mon Sep 17 00:00:00 2001 From: Martin Boller Date: Fri, 3 May 2024 19:50:48 +0200 Subject: [PATCH 3/7] Update scripts/create-alerts-from-csv.gmp.py Co-authored-by: Jaspar S. --- scripts/create-alerts-from-csv.gmp.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/scripts/create-alerts-from-csv.gmp.py b/scripts/create-alerts-from-csv.gmp.py index 3a4633dd..bffe009a 100755 --- a/scripts/create-alerts-from-csv.gmp.py +++ b/scripts/create-alerts-from-csv.gmp.py @@ -223,9 +223,7 @@ def main(gmp: Gmp, args: Namespace) -> None: parsed_args = parse_args(args=args) - print( - "Creating alerts.\n" - ) + print("Creating alerts.\n") numberalerts = create_alerts( gmp, From 49dbaec711d05c0e5d63fa4873b4b8563a3c659d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ricks?= Date: Wed, 19 Jun 2024 09:34:25 +0200 Subject: [PATCH 4/7] Merge scripts USAGE doc into README --- scripts/README.md | 343 +++++++++++++++++++++++++++++++++++++++++++++- scripts/USAGE.md | 231 ------------------------------- 2 files changed, 341 insertions(+), 233 deletions(-) delete mode 100644 scripts/USAGE.md diff --git a/scripts/README.md b/scripts/README.md index ec5051e7..351f8e31 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -115,7 +115,7 @@ This script pulls hostnames from a text file and creates a target for each. ### Arguments -* ``: IP of the GVM host +* ``: IP of the GVM host * ``: text file containing hostnames ### Example @@ -257,7 +257,7 @@ This script starts a new scan on the given host. --- -## `send-delta-emails.gmp.py` +## `send-delta-emails.gmp.py` This script, once started, will continuously send delta reports via email for selected tasks. The routine follows this procedure: @@ -389,3 +389,342 @@ This script will update target hosts information for a desired task. ### Example `$ gvm-script --gmp-username name --gmp-password pass ssh --hostname scripts/update-task-target.gmp.py hosts_file.csv "303fa0a6-aa9b-43c4-bac0-66ae0b2d1698"` + +## `create-alerts-from-csv.gmp.py` + +Creates alerts as specified in a csv-file. See alerts.csv for file format/contents. + +### Example + +`$ gvm-script --gmp-username *admin-user* --gmp-password *password* socket create-alerts-from-csv.gmp.py alerts.csv ` + +- For SMB Alerts use something like %N_%CT%z in the naming of the report, as shown in the example alerts.csv +- %N is the name for the object or the associated task for reports, %C is the creation date in the format YYYYMMDD, and %c is the creation time in the format HHMMSS. +- The script only support EMAIL and SMB Alerts, please note that the fields are quite different between the two alert types, but refer to the sample alerts.csv +- The CSV must starts with name, type (EMAIL or SMB). The remaining fields then depend on the type chosen, specifically: +- EMAIL; *senders email*, *recipients email*, *mail subject*, *message body*, *notice type* (0=Report in message 1=Simple Notice or 2=Attach Report), *Report Type* (e.g. CSV Results), *Status* (Done, Requested) +- SMB; *SMB Credentials*,*SMB Share Path*,*Report Name*, *Report Folder* (if not stored in the root of the share), *Not used*, *Report Type* (e.g. CSV Results), *Status* (Done, Requested) +- A simple example below with 1 EMAIL alert and 1 SMB Alert. +Alert_EMAIL_Stop,EMAIL,"martin@example.org","noc@example.org","Message Subject","Message Body",1,"CSV Results","Stop Requested" +Alert_SMB_Done,SMB,"Cred_Storage_SMB","\\smbserver\share","%N_%CT%cZ","Reports",,"CSV Results","Done" + +**Note**: This script relies on credentials as/if specified in alerts.csv as well as a working SMTP server on the Greenbone primary server. If you're using SMB add the required credentials first using [create-credentials-from-csv.gmp.py](#create-credentials-from-csvgmppy). + +## `create-schedules-from-csv.gmp.py` + +Creates schedules as specified in a csv-file. See schedules.csv for file format/contents. + +### Example +`$ gvm-script --gmp-username *admin-user* --gmp-password *password* socket create-schedules-from-csv.gmp.py ./schedules.csv` + +**Note**: create schedules, then credentials, then targets, then tasks and make sure to use the same names between the input csv-files. +The sample files should serve as examples, however a short explanation of a VCALENDAR stream exported from Greenbone below¹. + +``` +Example Key:Value pair | Comment +---|--- +BEGIN:VCALENDAR | Begin VCalendar Entry +VERSION:2.0 | iCalendar Version number +PRODID:-//Greenbone.net//NONSGML Greenbone Security Manager 23.1.0//EN | As generated by Greenbone replace with something else if you want to +BEGIN:VEVENT | Start of Vevent +DTSTART:20231125T220000Z | Start date +DURATION:PT1H | Duration of scan. PT0S means "Entire Operation". S = seconds, M = minutes, H = hours +RRULE:FREQ=HOURLY;INTERVAL=4 | Frequency; Yearly, Monthly, Weekly, Hourly. Optionally Interval withs same unit +DTSTAMP:20231125T212042Z | Date stamp created +END:VEVENT | End Vevent +END:VCALENDAR | End VCalendar Entry +``` + +¹ See also https://www.rfc-editor.org/rfc/rfc5545.txt Internet Calendaring and Scheduling Core Object Specification (iCalendar) + +## `create-credentials-from-csv.gmp.py` + +Creates credentials as specified in a csv-file. See credentials.csv for file format/contents. + +### Example + +`$ gvm-script --gmp-username *admin-user* --gmp-password *password* socket create-credentials-from-csv.gmp.py ./credentials.csv` + +**Note**: create schedules, then credentials, then targets, then tasks and make sure to use the same names between the input csv-files. +The sample files should serve as an example. + +## `create-filters-from-csv.gmp.py` + +Creates filters as specified in a csv-file. See filters.csv for file format/contents. + +### Example + +`$ gvm-script --gmp-username *admin-user* --gmp-password *password* socket create-filters-from-csv.gmp.py ./filters.csv` + +- CSV-file; filterType, filterName, filterDescription, filterTerm, where + - filterType is one of Alert, Config (scan-config), Credential, Report, Scanner, Schedule, Target, or Task. + - filterName is the name of the filter. + - filterDescription is your description of the filter. + - FilterTerm is the actual term used to define the filter, such as \~Labnet. + +## `create-tags-from-csv.gmp.py` + +Creates tags as specified in a csv-file. See tags.csv for file format/contents. + +### Example + +`$ gvm-script --gmp-username *admin-user* --gmp-password *password* socket create-tags-from-csv.gmp.py ./tags.csv` + +- May contain up to 10 resources to assign to tag. Currently only creates tags for Credential, Target, and Tasks +- Use tag:*searchforthis* as filter. Example: *tag:bsecure* +- Will add reports when I've figured out if tags are really dynamic and a filter will do it for new reports. + +## `create-targets-from-csv.gmp.py` + +Creates targets as specified in a csv-file. See targets.csv for file format/contents. + +### Example + +`$ gvm-script --gmp-username *admin-user* --gmp-password *password* socket create-targets-from-csv.gmp.py ./targets.csv` + +- Alive test can be: + +``` +No | Alive Test | Notes +---|---|--- +1 | Scan Config Default | ICMP Ping is used by default with the Built-in Scan Configurations +2 | ICMP Ping | ICMP echo request and echo reply messages +3 | TCP-ACK Service Ping | Sends TCP packets with only the ACK bit set. Target is required by [RFC 793](http://www.rfc-editor.org/rfc/rfc793.txt) to respond with a RST packet +4 | TCP-SYN Service Ping | SYN only scans (never sends an ACK even if target replies with SYN/ACK) +5 | ICMP & TCP-ACK Service Ping | ICMP & TCP-ACK tests combined +6 | ICMP & ARP Ping | ICMP Ping & sends a broadcast ARP request to solicit a reply from the host that uses the specified IP address +7 | TCP-ACK Service & ARP Ping | TCP-ACK and ARP Ping combined +8 | ICMP, TCP-ACK Service & ARP Ping | ICMP, TCP-ACK, and ARP Ping combined +9 | Consider Alive | Consider the target alive. This may take considerably longer to finish. +``` + +## `create-tasks-from-csv.gmp.py` + +Creates tasks as specified in a csv-file. See tasks.csv for file format/contents + +### Example + +`$ gvm-script --gmp-username *admin-user* --gmp-password *password* socket create-tasks-from-csv.gmp.py ./task.csv` + +- Change Hosts Scan Ordering by changing #5 within CSV to Random, Sequential or Reverse in script. +- Specify up to 5 alerts in CSV, blanks will be discarded. + +**Note**: Make sure that all other configurations that the tasks may rely on are already created, including alerts, schedules, credentials, and targets, +in other words if it is referenced in tasks.csv it must already exist. + +## `empty-trash.gmp.py` + +- Does what is says on the tin, empties the trashcan in Greenbone. +- Use it when you're testing like crazy and have a trashcan with ~ a gazillion objects +- You can also just use `gvm-cli --gmp-username *admin-user* --gmp-password *password* socket --pretty --xml ""` + +## `export-csv-report.gmp.py` + +Requests the report specified and exports it as a csv formatted report locally. + +### Example +`$ gvm-script --gmp-username *admin-user* --gmp-password *password* socket export-csv-report.gmp.py *report_uuid* ./output.csv` + +- Get the *report_uuid* with list-reports.gmp.py or find it in the UI. If the output is not specified it will be named *report_uuid.csv* +- Note the only changes to this script is an added ignore_pagination=True, details=True to get the full report. + +## `export-pdf-report.gmp.py` + +Requests the report specified and exports it as a pdf formatted report locally. + +### Example + +`$ gvm-script --gmp-username *admin-user* --gmp-password *password* socket export-pdf-report.gmp.py *report_uuid* ./output.pdf` + +- Get the *report_uuid* with list-reports.gmp.py or find it in the UI. If the output is not specified it will be named *report_uuid.pdf* + +**Note**: the only changes to this script is an added ignore_pagination=True, details=True to get the full report. + +## `list-alerts.gmp.py` + +Lists all alerts configured with name and uuid. + +### Example + +`$ gvm-script --gmp-username *admin-user* --gmp-password *password* socket list-alerts.gmp.py` + +## `list-credentials.gmp.py` + +Lists all credentials configured with name and uuid. + +`$ gvm-script --gmp-username *admin-user* --gmp-password *password* socket list-credentials.gmp.py` + +Returns Credential uuid, Name, Type, & if insecure use is allowed + +## `list-feeds.gmp.py` + +Lists feeds and their status. + +### Example + +`$ gvm-script --gmp-username *admin-user* --gmp-password *password* socket list-feeds.gmp.py` + +## `list-filters.gmp.py` + +Lists filters. + +### Example +`$ gvm-script --gmp-username *admin-user* --gmp-password *password* socket list-filters.gmp.py` + +Returns Filter Name, uuid, type, and the term (filter) + +## `list-groups.gmp.py` + +Lists all groups + +### Example + +`$ gvm-script --gmp-username *admin-user* --gmp-password *password* socket list-groups.gmp.py` + +Returns Group Name, uuid, members + +## `list-policies.gmp.py` + +Lists compliance policies. + +### Example + +`$ gvm-script --gmp-username *admin-user* --gmp-password *password* socket list-policies.gmp.py` + +## `list-portlists.gmp.py` + +Lists port lists. + +### Example + +`$ gvm-script --gmp-username *admin-user* --gmp-password *password* socket list-portlists.gmp.py` + +## `list-report-formats.gmp.py` + +Lists all report formats with name and uuid. + +### Example +`$ gvm-script --gmp-username *admin-user* --gmp-password *password* socket list-report-formats.gmp.py` + +## `list-reports.gmp.py` + +Lists all reports that have specified status + +### Example +`$ gvm-script --gmp-username *admin-user* --gmp-password *password* socket list-reports.gmp.py *Status*` + +where status is "All", "Requested", "Queued", "Interrupted", "Running", "Stop Requested", "Stopped", or "Done" + +- Case matters, so "Done" or "Stopped" will work while "done" or "stopped" will not. +- Script now shows, in percentage, how far the scan/report is. +- There are no reports generated before at least one scan task has been started. + +## `list-roles.gmp.py` + +Lists all roles + +### Example +`$ gvm-script --gmp-username *admin-user* --gmp-password *password* socket list-roles.gmp.py` + +Returns Role Name, uuid, members + +## `list-scan-configs.gmp.py` + +Lists all scan configs. + +### Example + +`$ gvm-script --gmp-username *admin-user* --gmp-password *password* socket list-scan-configs.gmp.py` + +## `list-scanners.gmp.py` + +Lists all scanners currently configured. + +### Example + +`$ gvm-script --gmp-username *admin-user* --gmp-password *password* socket list-scanners.gmp.py` + +Returns the scanners Name, uuid, & the host on which it resides (note CVE scanner does not return a host and sockets are local) + +## `list-schedules.gmp.py` + +Lists all schedules configured with name, uuid, timezone, and iCalendar information. + +### Example + +`$ gvm-script --gmp-username *admin-user* --gmp-password *password* socket list-schedules.gmp.py` + +## `list-tags.gmp.py` + +Lists all tags currently configured. + +### Example + +`$ gvm-script --gmp-username *admin-user* --gmp-password *password* socket list-tags.gmp.py` + +Returns Tag name, uuid, Modified Date, Value, Type, and Count of ressources assigned to tag. + +## `list-targets.gmp.py` + +Lists all targets currently configured. + +### Example + +`$ gvm-script --gmp-username *admin-user* --gmp-password *password* socket list-targets.gmp.py` + +- No targets configured by default, however using the provided files in this repo, you should now have a few (5). +- Returns targets Name, uuid, number of Hosts, and credentials (SSH, SMB, ESXi, & SNMP Credentials) + +## `list-tickets.gmp.py` + +Lists all tickets created + +### Example + +`$ gvm-script --gmp-username *admin-user* --gmp-password *password* socket list-tickets.gmp.py` + +Returns the tickets name, Host, Associated Task, Status, and Note (depending on status either Open-, Fixed-, or Closed note). + +## `list-users.gmp.py` + +Lists all users + +### Example + +`$ gvm-script --gmp-username *admin-user* --gmp-password *password* socket list-users.gmp.py` + +Returns user Name, uuid, role, groups + +¹ The default order is "None" which equals sequential, meaning that if this field is empty scanning will be sequential as it will be if specifically set to sequential. Possible results are None, Sequential, Reverse, or Random. + +## `start-scans-from-csv.gmp.py` + +Starts scans (tasks) specified in csv file + +### Example + +`$ gvm-script --gmp-username *admin-user* --gmp-password *password* socket start-scans-from-csv.gmp.py *csv-file with task names*` + +Returns the number of tasks started. + +## `stop-all-scans.gmp.py` + +Stops scans (tasks) that are in status running, queued, or requested + +### Example + +`$ gvm-script --gmp-username *admin-user* --gmp-password *password* socket stop-all-scans.gmp.py` + +- Stops all scans +- Returns the number of tasks stopped. + +## `stop-scans-from-csv.gmp.py` + +Stops scans (tasks) specified in csv file + +### Example + +`$ gvm-script --gmp-username *admin-user* --gmp-password *password* socket stop-scans-from-csv.gmp.py *csv-file with task names*` + +- Stops the tasks specified in the file (example startscan.csv works for both scripts) +- Returns the number of tasks stopped. diff --git a/scripts/USAGE.md b/scripts/USAGE.md deleted file mode 100644 index ca4fe826..00000000 --- a/scripts/USAGE.md +++ /dev/null @@ -1,231 +0,0 @@ -# Greenbone Vulnerability Manager Python scripts - -## Python scripts that can be used to configure your Greenbone Community Edition Scanner - -[API Reference for GVM 22.5](https://docs.greenbone.net/API/GMP/gmp-22.5.html) - -[Python GVM API](https://greenbone.github.io/python-gvm/api/api.html) - -## Running Python GVM Scripts -For details on Python GVM, please refer to https://gvm-tools.readthedocs.io/en/latest/scripting.html#gvm-scripts, but for these scripts, use -- gvm-script --gmp-username *admin-user* --gmp-password *password* socket *script-name* - Example: -- gvm-script --gmp-username admin --gmp-password SecretPassword socket list-alerts.gmp.py -When you just want to get the XML from Greenbone to look for values/value names, it's easy to use gvm-cli, like this: -- gvm-cli --gmp-username *admin-user* --gmp-password *password* socket --xml="" - -## Python Scripts in this repo: -### clean-sensor.gmp.py -**Script provided by Greenbone as part of GVM-Tools. Used when cleaning up after testing scripts (or starting over)** -- Usage: gvm-script --gmp-username admin --gmp-password '0f6fa69b-32bb-453a-9aa4-b8c9e56b3d00' socket clean-sensor.gmp.py -- clean-sensor now cleans alerts, filters, schedules and tags too. - -### create-Alerts-from-csv.gmp.py -**Creates alerts as specified in a csv-file. See alerts.csv for file format/contents.** -- Usage: gvm-script --gmp-username *admin-user* --gmp-password *password* socket create-alerts-from-csv.gmp.py alerts.csv -- For SMB Alerts use something like %N_%CT%z in the naming of the report, as shown in the example alerts.csv -- %N is the name for the object or the associated task for reports, %C is the creation date in the format YYYYMMDD, and %c is the creation time in the format HHMMSS. -- The script only support EMAIL and SMB Alerts, please note that the fields are quite different between the two alert types, but refer to the sample alerts.csv -- The CSV must starts with name, type (EMAIL or SMB). The remaining fields then depend on the type chosen, specifically: -- EMAIL; *senders email*, *recipients email*, *mail subject*, *message body*, *notice type* (0=Report in message 1=Simple Notice or 2=Attach Report), *Report Type* (e.g. CSV Results), *Status* (Done, Requested) -- SMB; *SMB Credentials*,*SMB Share Path*,*Report Name*, *Report Folder* (if not stored in the root of the share), *Not used*, *Report Type* (e.g. CSV Results), *Status* (Done, Requested) -- A simple example below with 1 EMAIL alert and 1 SMB Alert. -Alert_EMAIL_Stop,EMAIL,"martin@example.org","noc@example.org","Message Subject","Message Body",1,"CSV Results","Stop Requested" -Alert_SMB_Done,SMB,"Cred_Storage_SMB","\\smbserver\share","%N_%CT%cZ","Reports",,"CSV Results","Done" - -**Note**: This script relies on credentials as/if specified in alerts.csv as well as a working SMTP server on the Greenbone primary server. If you're using SMB add the required credentials first using [create-credentials-from-csv.gmp.py](#create-credentials-from-csvgmppy). - - -### create-schedules-from-csv.gmp.py -**Creates schedules as specified in a csv-file. See schedules.csv for file format/contents.** -Usage: gvm-script --gmp-username *admin-user* --gmp-password *password* socket create-schedules-from-csv.gmp.py ./schedules.csv -**Note**: create schedules, then credentials, then targets, then tasks and make sure to use the same names between the input csv-files. -The sample files should serve as examples, however a short explanation of a VCALENDAR stream exported from Greenbone below¹. - -Example Key:Value pair | Comment ----|--- -BEGIN:VCALENDAR | Begin VCalendar Entry -VERSION:2.0 | iCalendar Version number -PRODID:-//Greenbone.net//NONSGML Greenbone Security Manager 23.1.0//EN | As generated by Greenbone replace with something else if you want to -BEGIN:VEVENT | Start of Vevent -DTSTART:20231125T220000Z | Start date -DURATION:PT1H | Duration of scan. PT0S means "Entire Operation". S = seconds, M = minutes, H = hours -RRULE:FREQ=HOURLY;INTERVAL=4 | Frequency; Yearly, Monthly, Weekly, Hourly. Optionally Interval withs same unit -DTSTAMP:20231125T212042Z | Date stamp created -END:VEVENT | End Vevent -END:VCALENDAR | End VCalendar Entry - -¹ See also https://www.rfc-editor.org/rfc/rfc5545.txt Internet Calendaring and Scheduling Core Object Specification (iCalendar) - -### create-credentials-from-csv.gmp.py -**Creates credentials as specified in a csv-file. See credentials.csv for file format/contents.** -Usage: gvm-script --gmp-username *admin-user* --gmp-password *password* socket create-credentials-from-csv.gmp.py ./credentials.csv -**Note**: create schedules, then credentials, then targets, then tasks and make sure to use the same names between the input csv-files. -The sample files should serve as an example. - -### create-filters-from-csv.gmp.py -**Creates filters as specified in a csv-file. See filters.csv for file format/contents.** -- Usage: gvm-script --gmp-username *admin-user* --gmp-password *password* socket create-filters-from-csv.gmp.py ./filters.csv -- CSV-file; filterType, filterName, filterDescription, filterTerm, where - - filterType is one of Alert, Config (scan-config), Credential, Report, Scanner, Schedule, Target, or Task. - - filterName is the name of the filter. - - filterDescription is your description of the filter. - - FilterTerm is the actual term used to define the filter, such as \~Labnet. - -### create-tags-from-csv.gmp.py -**Creates tags as specified in a csv-file. See tags.csv for file format/contents.** -- Usage: gvm-script --gmp-username *admin-user* --gmp-password *password* socket create-tags-from-csv.gmp.py ./tags.csv -- May contain up to 10 resources to assign to tag. Currently only creates tags for Credential, Target, and Tasks -- Use tag:*searchforthis* as filter. Example: *tag:bsecure* -- Will add reports when I've figured out if tags are really dynamic and a filter will do it for new reports. - -### create-targets-from-csv.gmp.py -**Creates targets as specified in a csv-file. See targets.csv for file format/contents.** -- Usage: gvm-script --gmp-username *admin-user* --gmp-password *password* socket create-targets-from-csv.gmp.py ./targets.csv -- Alive test can be: - -No | Alive Test | Notes ----|---|--- -1 | Scan Config Default | ICMP Ping is used by default with the Built-in Scan Configurations -2 | ICMP Ping | ICMP echo request and echo reply messages -3 | TCP-ACK Service Ping | Sends TCP packets with only the ACK bit set. Target is required by [RFC 793](http://www.rfc-editor.org/rfc/rfc793.txt) to respond with a RST packet -4 | TCP-SYN Service Ping | SYN only scans (never sends an ACK even if target replies with SYN/ACK) -5 | ICMP & TCP-ACK Service Ping | ICMP & TCP-ACK tests combined -6 | ICMP & ARP Ping | ICMP Ping & sends a broadcast ARP request to solicit a reply from the host that uses the specified IP address -7 | TCP-ACK Service & ARP Ping | TCP-ACK and ARP Ping combined -8 | ICMP, TCP-ACK Service & ARP Ping | ICMP, TCP-ACK, and ARP Ping combined -9 | Consider Alive | Consider the target alive. This may take considerably longer to finish. - - -### create-tasks-from-csv.gmp.py -**Creates tasks as specified in a csv-file. See tasks.csv for file format/contents** -- Usage: gvm-script --gmp-username *admin-user* --gmp-password *password* socket create-tasks-from-csv.gmp.py ./task.csv

-- Change Hosts Scan Ordering by changing #5 within CSV to Random, Sequential or Reverse in script. -- Specify up to 5 alerts in CSV, blanks will be discarded. -**Note**: Make sure that all other configurations that the tasks may rely on are already created, including alerts, schedules, credentials, and targets, -in other words if it is referenced in tasks.csv it must already exist. - -### empty-trash.gmp.py -- Does what is says on the tin, empties the trashcan in Greenbone. -- Use it when you're testing like crazy and have a trashcan with ~ a gazillion objects -- You can also just use gvm-cli --gmp-username *admin-user* --gmp-password *password* socket --pretty --xml="" - -### export-csv-report.gmp.py -**Requests the report specified and exports it as a csv formatted report locally.** -- Usage: gvm-script --gmp-username *admin-user* --gmp-password *password* socket export-csv-report.gmp.py *report_uuid* ./output.csv -- Get the *report_uuid* with list-reports.gmp.py or find it in the UI. If the output is not specified it will be named *report_uuid.csv* -- Note the only changes to this script is an added ignore_pagination=True, details=True to get the full report. - -### export-pdf-report.gmp.py -**Requests the report specified and exports it as a pdf formatted report locally.** -- Usage: gvm-script --gmp-username *admin-user* --gmp-password *password* socket export-pdf-report.gmp.py *report_uuid* ./output.pdf -- Get the *report_uuid* with list-reports.gmp.py or find it in the UI. If the output is not specified it will be named *report_uuid.pdf* -**Note**: the only changes to this script is an added ignore_pagination=True, details=True to get the full report. - -## list-alerts.gmp.py -**Lists all alerts configured with name and uuid.** -- Usage: gvm-script --gmp-username *admin-user* --gmp-password *password* socket list-alerts.gmp.py - -## list-credentials.gmp.py -**Lists all credentials configured with name and uuid.** -- Usage: gvm-script --gmp-username *admin-user* --gmp-password *password* socket list-credentials.gmp.py -- returns Credential uuid, Name, Type, & if insecure use is allowed - -### list-feeds.gmp.py -**Lists feeds and their status.** -- Usage: gvm-script --gmp-username *admin-user* --gmp-password *password* socket list-feeds.gmp.py - -### list-filters.gmp.py -**Lists filters.** -- Usage: gvm-script --gmp-username *admin-user* --gmp-password *password* socket list-filters.gmp.py -- Returns Filter Name, uuid, type, and the term (filter) - -### list-groups.gmp.py -**Lists all groups** -- Usage: gvm-script --gmp-username *admin-user* --gmp-password *password* socket list-groups.gmp.py -- Returns Group Name, uuid, members - -### list-policies.gmp.py -**Lists compliance policies.** -- Usage: gvm-script --gmp-username *admin-user* --gmp-password *password* socket list-policies.gmp.py - -### list-portlists.gmp.py -**Lists port lists.** -- Usage: gvm-script --gmp-username *admin-user* --gmp-password *password* socket list-portlists.gmp.py - -### list-report-formats.gmp.py -**Lists all report formats with name and uuid.** -- Usage: gvm-script --gmp-username *admin-user* --gmp-password *password* socket list-report-formats.gmp.py - -### list-reports.gmp.py -**Lists all reports that have specified status** -- Usage: gvm-script --gmp-username *admin-user* --gmp-password *password* socket list-reports.gmp.py *Status* -- where status is "All", "Requested", "Queued", "Interrupted", "Running", "Stop Requested", "Stopped", or "Done" -- Case matters, so "Done" or "Stopped" will work while "done" or "stopped" will not. -- Script now shows, in percentage, how far the scan/report is. -- There are no reports generated before at least one scan task has been started. - -### list-roles.gmp.py -**Lists all roles** -- Usage: gvm-script --gmp-username *admin-user* --gmp-password *password* socket list-roles.gmp.py -- Returns Role Name, uuid, members - -### list-scan-configs.gmp.py -**Lists all scan configs.** -- Usage: gvm-script --gmp-username *admin-user* --gmp-password *password* socket list-scan-configs.gmp.py - -### list-scanners.gmp.py -**Lists all scanners currently configured.** -- Usage: gvm-script --gmp-username *admin-user* --gmp-password *password* socket list-scanners.gmp.py -- Returns the scanners Name, uuid, & the host on which it resides (note CVE scanner does not return a host and sockets are local) - -## list-schedules.gmp.py -**Lists all schedules configured with name, uuid, timezone, and iCalendar information.** -- Usage: gvm-script --gmp-username *admin-user* --gmp-password *password* socket list-schedules.gmp.py - -### list-tags.gmp.py -**Lists all tags currently configured.** -- Usage: gvm-script --gmp-username *admin-user* --gmp-password *password* socket list-tags.gmp.py -- Returns Tag name, uuid, Modified Date, Value, Type, and Count of ressources assigned to tag. - -### list-targets.gmp.py -**Lists all targets currently configured.** -- Usage: gvm-script --gmp-username *admin-user* --gmp-password *password* socket list-targets.gmp.py -- No targets configured by default, however using the provided files in this repo, you should now have a few (5). -- Returns targets Name, uuid, number of Hosts, and credentials (SSH, SMB, ESXi, & SNMP Credentials) - -### list-tasks.gmp.py -**Lists all tasks configured** -- Usage: gvm-script --gmp-username *admin-user* --gmp-password *password* socket list-tasks.gmp.py -- No tasks configured by default, however using the provided files in this repo, you should now have some (9). -- Returns the tasks Name, uuid, Target, Scanner, the order in which hosts are scanned¹, and the highest severity (empty if no reports) - -### list-tickets.gmp.py -**Lists all tickets created** -- Usage: gvm-script --gmp-username *admin-user* --gmp-password *password* socket list-tickets.gmp.py -- Returns the tickets name, Host, Associated Task, Status, and Note (depending on status either Open-, Fixed-, or Closed note). - -### list-users.gmp.py -**Lists all users** -- Usage: gvm-script --gmp-username *admin-user* --gmp-password *password* socket list-users.gmp.py -- Returns user Name, uuid, role, groups - - -¹ The default order is "None" which equals sequential, meaning that if this field is empty scanning will be sequential as it will be if specifically set to sequential. Possible results are None, Sequential, Reverse, or Random. - -### start-scans-from-csv.gmp.py -**starts scans (tasks) specified in csv file** -- Usage: gvm-script --gmp-username *admin-user* --gmp-password *password* socket start-scans-from-csv.gmp.py *csv-file with task names* -- Starts the tasks specified in the file (example startscan.csv) -- Returns the number of tasks started. - -### stop-all-scans.gmp.py -**stops scans (tasks) that are in status running, queued, or requested** -- Usage: gvm-script --gmp-username *admin-user* --gmp-password *password* socket stop-all-scans.gmp.py -- Stops all scans -- Returns the number of tasks stopped. - -### stop-scans-from-csv.gmp.py -**stops scans (tasks) specified in csv file** -- Usage: gvm-script --gmp-username *admin-user* --gmp-password *password* socket stop-scans-from-csv.gmp.py *csv-file with task names* -- Stops the tasks specified in the file (example startscan.csv works for both scripts) -- Returns the number of tasks stopped. From 020ea58551d3ec996bcd9cbe003715a4b3954cfc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ricks?= Date: Wed, 19 Jun 2024 10:22:59 +0200 Subject: [PATCH 5/7] Change: Update copyright headers of all scripts Use new and current copyright header format. --- scripts/application-detection.gmp.py | 16 +---------- scripts/bulk-modify-schedules.gmp.py | 16 +---------- scripts/certbund-report.gmp.py | 20 ++------------ scripts/cfg-gen-for-certs.gmp.py | 16 +---------- scripts/check-gmp.gmp.py | 16 +---------- scripts/clean-sensor.gmp.py | 16 +---------- scripts/combine-reports.gmp.py | 16 +---------- scripts/create-alerts-from-csv.gmp.py | 4 --- scripts/create-consolidated-report.gmp.py | 16 +---------- scripts/create-credentials-from-csv.gmp.py | 24 +++-------------- scripts/create-cve-report-from-json.gmp.py | 16 +---------- scripts/create-dummy-data.gmp.py | 16 +---------- scripts/create-filters-from-csv.gmp.py | 23 +++------------- scripts/create-report-format-from-csv.gmp.py | 23 ++-------------- scripts/create-schedules-from-csv.gmp.py | 23 ++-------------- scripts/create-tags-from-csv.gmp.py | 23 ++-------------- scripts/create-targets-from-csv.gmp.py | 23 ++-------------- scripts/create-targets-from-host-list.gmp.py | 16 +---------- scripts/create-tasks-from-csv.gmp.py | 25 +++-------------- scripts/delete-overrides-by-filter.gmp.py | 16 +---------- scripts/empty-trash.gmp.py | 21 +-------------- scripts/export-csv-report.gmp.py | 28 +++----------------- scripts/export-pdf-report.gmp.py | 26 ++---------------- scripts/export-xml-report.gmp.py | 25 +---------------- scripts/generate-random-reports.gmp.py | 18 +------------ scripts/generate-random-targets.gmp.py | 16 +---------- scripts/list-alerts.gmp.py | 21 +-------------- scripts/list-credentials.gmp.py | 21 +-------------- scripts/list-feeds.gmp.py | 22 +-------------- scripts/list-filters.gmp.py | 21 +-------------- scripts/list-groups.gmp.py | 21 +-------------- scripts/list-policies.gmp.py | 21 +-------------- scripts/list-portlists.gmp.py | 21 +-------------- scripts/list-report-formats.gmp.py | 22 +-------------- scripts/list-reports.gmp.py | 23 +--------------- scripts/list-roles.gmp.py | 21 +-------------- scripts/list-scan-configs.gmp.py | 21 +-------------- scripts/list-scanners.gmp.py | 21 +-------------- scripts/list-schedules.gmp.py | 21 +-------------- scripts/list-tags.gmp.py | 21 +-------------- scripts/list-targets.gmp.py | 21 +-------------- scripts/list-tasks.gmp.py | 21 +-------------- scripts/list-tickets.gmp.py | 21 +-------------- scripts/list-users.gmp.py | 21 +-------------- scripts/monthly-report-gos4.gmp.py | 16 +---------- scripts/monthly-report.gmp.py | 16 +---------- scripts/nvt-scan.gmp.py | 16 +---------- scripts/scan-new-system.gmp.py | 16 +---------- scripts/send-delta-emails.gmp.py | 18 ++----------- scripts/send-schedules.gmp.py | 16 +---------- scripts/send-targets.gmp.py | 16 +---------- scripts/send-tasks.gmp.py | 16 +---------- scripts/start-alert-scan.gmp.py | 18 ++----------- scripts/start-multiple-alerts-scan.gmp.py | 18 ++----------- scripts/start-nvt-scan.gmp.py | 16 +---------- scripts/start-scans-from-csv.py | 23 ++-------------- scripts/stop-all-scans.gmp.py | 21 +-------------- scripts/stop-scans-from-csv.py | 23 ++-------------- scripts/sync-hosts.gmp.py | 16 +---------- scripts/update-task-target.gmp.py | 16 +---------- 60 files changed, 80 insertions(+), 1081 deletions(-) diff --git a/scripts/application-detection.gmp.py b/scripts/application-detection.gmp.py index 1035d58f..f8d4fab0 100644 --- a/scripts/application-detection.gmp.py +++ b/scripts/application-detection.gmp.py @@ -1,20 +1,6 @@ -# -*- coding: utf-8 -*- -# Copyright (C) 2017-2021 Greenbone AG +# SPDX-FileCopyrightText: 2017-2021 Greenbone AG # # SPDX-License-Identifier: GPL-3.0-or-later -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . import sys from argparse import Namespace diff --git a/scripts/bulk-modify-schedules.gmp.py b/scripts/bulk-modify-schedules.gmp.py index 4096aa22..44e6421b 100644 --- a/scripts/bulk-modify-schedules.gmp.py +++ b/scripts/bulk-modify-schedules.gmp.py @@ -1,20 +1,6 @@ -# -*- coding: utf-8 -*- -# Copyright (C) 2021 Greenbone AG +# SPDX-FileCopyrightText: 2021 Greenbone AG # # SPDX-License-Identifier: GPL-3.0-or-later -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . import sys from argparse import Namespace diff --git a/scripts/certbund-report.gmp.py b/scripts/certbund-report.gmp.py index c7dabb1a..592e067d 100644 --- a/scripts/certbund-report.gmp.py +++ b/scripts/certbund-report.gmp.py @@ -1,22 +1,6 @@ -# -*- coding: utf-8 -*- -# - -# Copyright © 2022 Thorsten Glaser -# Licensor: Greenbone Networks GmbH -# SPDX-License-Identifier: GPL-3.0-or-later -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. +# SPDX-FileCopyrightText: 2022 Greenbone AG # -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - +# SPDX-License-Identifier: GPL-3.0-or-later # List vulnerabilities with CERT-BUND IDs and severities from a report, # per host and CERT-BUND advisory. diff --git a/scripts/cfg-gen-for-certs.gmp.py b/scripts/cfg-gen-for-certs.gmp.py index 39c20cfb..024298dc 100644 --- a/scripts/cfg-gen-for-certs.gmp.py +++ b/scripts/cfg-gen-for-certs.gmp.py @@ -1,20 +1,6 @@ -# -*- coding: utf-8 -*- -# Copyright (C) 2017-2021 Greenbone AG +# SPDX-FileCopyrightText: 2017-2021 Greenbone AG # # SPDX-License-Identifier: GPL-3.0-or-later -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . import sys from argparse import Namespace diff --git a/scripts/check-gmp.gmp.py b/scripts/check-gmp.gmp.py index 6823fc83..1e1eda06 100644 --- a/scripts/check-gmp.gmp.py +++ b/scripts/check-gmp.gmp.py @@ -1,20 +1,6 @@ -# -*- coding: utf-8 -*- -# Copyright (C) 2017-2021 Greenbone AG +# SPDX-FileCopyrightText: 2017-2021 Greenbone AG # # SPDX-License-Identifier: GPL-3.0-or-later -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . # pylint: disable=too-many-lines diff --git a/scripts/clean-sensor.gmp.py b/scripts/clean-sensor.gmp.py index 882adec0..422c5e20 100644 --- a/scripts/clean-sensor.gmp.py +++ b/scripts/clean-sensor.gmp.py @@ -1,20 +1,6 @@ -# -*- coding: utf-8 -*- -# Copyright (C) 2017-2021 Greenbone Networks GmbH +# SPDX-FileCopyrightText: 2017-2021 Greenbone AG # # SPDX-License-Identifier: GPL-3.0-or-later -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . from argparse import Namespace diff --git a/scripts/combine-reports.gmp.py b/scripts/combine-reports.gmp.py index 5dd01e8a..849b8f5b 100644 --- a/scripts/combine-reports.gmp.py +++ b/scripts/combine-reports.gmp.py @@ -1,20 +1,6 @@ -# -*- coding: utf-8 -*- -# Copyright (C) 2017-2021 Greenbone AG +# SPDX-FileCopyrightText: 2017-2021 Greenbone AG # # SPDX-License-Identifier: GPL-3.0-or-later -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . # ruff: noqa: E501 diff --git a/scripts/create-alerts-from-csv.gmp.py b/scripts/create-alerts-from-csv.gmp.py index bffe009a..fa2a44aa 100755 --- a/scripts/create-alerts-from-csv.gmp.py +++ b/scripts/create-alerts-from-csv.gmp.py @@ -3,12 +3,8 @@ # SPDX-License-Identifier: GPL-3.0-or-later # -# Loosely based on Greenbone sample scripts -# As provided by Greenbone in the gvm-tools repo -# # Run with gvm-script --gmp-username admin-user --gmp-password password socket create-alerts-from-csv.gmp.py alerts.csv # -# # Information on Variables to be used in alerts: https://docs.greenbone.net/GSM-Manual/gos-22.04/en/scanning.html#using-alerts # Example script: https://forum.greenbone.net/t/working-example-of-creating-an-alert-using-script/7511/2 diff --git a/scripts/create-consolidated-report.gmp.py b/scripts/create-consolidated-report.gmp.py index b5601c95..7fed753c 100755 --- a/scripts/create-consolidated-report.gmp.py +++ b/scripts/create-consolidated-report.gmp.py @@ -1,20 +1,6 @@ -# -*- coding: utf-8 -*- -# Copyright (C) 2021 Greenbone AG +# SPDX-FileCopyrightText: 2021 Greenbone AG # # SPDX-License-Identifier: GPL-3.0-or-later -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . from argparse import ArgumentParser, Namespace, RawTextHelpFormatter from datetime import date diff --git a/scripts/create-credentials-from-csv.gmp.py b/scripts/create-credentials-from-csv.gmp.py index fbbadb63..66e8f6e1 100755 --- a/scripts/create-credentials-from-csv.gmp.py +++ b/scripts/create-credentials-from-csv.gmp.py @@ -1,28 +1,12 @@ -# -*- coding: utf-8 -*- -# -# Loosely based on the create-targets-from-host-list.gmp.py -# As provided by Greenbone in the gvm-tools repo -# -# Martin Boller +# SPDX-FileCopyrightText: 2024 Martin Boller # # SPDX-License-Identifier: GPL-3.0-or-later # -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . + +# Loosely based on the create-targets-from-host-list.gmp.py +# As provided by Greenbone in the gvm-tools repo # # Run with gvm-script --gmp-username admin-user --gmp-password password socket create-credentials-from-csv.gmp.py credentials.csv -# -# import sys import time diff --git a/scripts/create-cve-report-from-json.gmp.py b/scripts/create-cve-report-from-json.gmp.py index d8e7c0dc..73ef728a 100644 --- a/scripts/create-cve-report-from-json.gmp.py +++ b/scripts/create-cve-report-from-json.gmp.py @@ -1,20 +1,6 @@ -# -*- coding: utf-8 -*- -# Copyright (C) 2021 Greenbone AG +# SPDX-FileCopyrightText: 2021 Greenbone AG # # SPDX-License-Identifier: GPL-3.0-or-later -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . import csv import datetime diff --git a/scripts/create-dummy-data.gmp.py b/scripts/create-dummy-data.gmp.py index 25b0a8a8..b7374d74 100644 --- a/scripts/create-dummy-data.gmp.py +++ b/scripts/create-dummy-data.gmp.py @@ -1,20 +1,6 @@ -# -*- coding: utf-8 -*- -# Copyright (C) 2017-2021 Greenbone AG +# SPDX-FileCopyrightText: 2017-2021 Greenbone AG # # SPDX-License-Identifier: GPL-3.0-or-later -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . import sys from argparse import Namespace diff --git a/scripts/create-filters-from-csv.gmp.py b/scripts/create-filters-from-csv.gmp.py index 5d48a9f8..f9023d74 100755 --- a/scripts/create-filters-from-csv.gmp.py +++ b/scripts/create-filters-from-csv.gmp.py @@ -1,28 +1,11 @@ -# -*- coding: utf-8 -*- -# -# Loosely based on the create-filterw-from-host-list -# As provided by Greenbone in the gvm-tools repo -# -# Martin Boller +# SPDX-FileCopyrightText: 2024 Martin Boller # # SPDX-License-Identifier: GPL-3.0-or-later # -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . + +# Loosely based on the create-filter-from-host-list # # Run with gvm-script --gmp-username admin-user --gmp-password password socket create-filters-from-csv.gmp.py hostname-server filters.csv -# -# import sys import time diff --git a/scripts/create-report-format-from-csv.gmp.py b/scripts/create-report-format-from-csv.gmp.py index 2a1285b4..f3549ac0 100755 --- a/scripts/create-report-format-from-csv.gmp.py +++ b/scripts/create-report-format-from-csv.gmp.py @@ -1,28 +1,9 @@ -# -*- coding: utf-8 -*- -# -# Loosely based on the create-targets-from-host-list.gmp.py -# As provided by Greenbone in the gvm-tools repo -# -# Martin Boller +# SPDX-FileCopyrightText: 2024 Martin Boller # # SPDX-License-Identifier: GPL-3.0-or-later # -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -# + # Run with gvm-script --gmp-username admin-user --gmp-password password socket create-report_formats-from-csv.gmp.py report_formats.csv -# -# import sys import time diff --git a/scripts/create-schedules-from-csv.gmp.py b/scripts/create-schedules-from-csv.gmp.py index ddc3b2f7..593844e7 100755 --- a/scripts/create-schedules-from-csv.gmp.py +++ b/scripts/create-schedules-from-csv.gmp.py @@ -1,28 +1,9 @@ -# -*- coding: utf-8 -*- -# -# Loosely based on the create-targets-from-host-list.gmp.py -# As provided by Greenbone in the gvm-tools repo -# -# Martin Boller +# SPDX-FileCopyrightText: 2024 Martin Boller # # SPDX-License-Identifier: GPL-3.0-or-later # -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -# + # Run with gvm-script --gmp-username admin-user --gmp-password password socket create-schedules-from-csv.gmp.py schedules.csv -# -# import sys import time diff --git a/scripts/create-tags-from-csv.gmp.py b/scripts/create-tags-from-csv.gmp.py index 8c06431d..ed7a04c5 100755 --- a/scripts/create-tags-from-csv.gmp.py +++ b/scripts/create-tags-from-csv.gmp.py @@ -1,28 +1,9 @@ -# -*- coding: utf-8 -*- -# -# Loosely based on the create-tagw-from-host-list -# As provided by Greenbone in the gvm-tools repo -# -# Martin Boller +# SPDX-FileCopyrightText: 2024 Martin Boller # # SPDX-License-Identifier: GPL-3.0-or-later # -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -# + # Run with gvm-script --gmp-username admin-user --gmp-password password socket create-tags-from-csv.gmp.py hostname-server tags.csv -# -# import sys import time diff --git a/scripts/create-targets-from-csv.gmp.py b/scripts/create-targets-from-csv.gmp.py index 203920ff..3028e858 100755 --- a/scripts/create-targets-from-csv.gmp.py +++ b/scripts/create-targets-from-csv.gmp.py @@ -1,28 +1,9 @@ -# -*- coding: utf-8 -*- -# -# Loosely based on the create-targetw-from-host-list -# As provided by Greenbone in the gvm-tools repo -# -# Martin Boller +# SPDX-FileCopyrightText: 2024 Martin Boller # # SPDX-License-Identifier: GPL-3.0-or-later # -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -# + # Run with gvm-script --gmp-username admin-user --gmp-password password socket create-targets-from-csv.gmp.py hostname-server targets.csv -# -# import sys import time diff --git a/scripts/create-targets-from-host-list.gmp.py b/scripts/create-targets-from-host-list.gmp.py index 6e9596ca..f6217277 100644 --- a/scripts/create-targets-from-host-list.gmp.py +++ b/scripts/create-targets-from-host-list.gmp.py @@ -1,20 +1,6 @@ -# -*- coding: utf-8 -*- -# Copyright (C) 2017-2021 Greenbone AG +# SPDX-FileCopyrightText: 2017-2021 Greenbone AG # # SPDX-License-Identifier: GPL-3.0-or-later -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . import sys import time diff --git a/scripts/create-tasks-from-csv.gmp.py b/scripts/create-tasks-from-csv.gmp.py index e03ebd0b..840554e7 100755 --- a/scripts/create-tasks-from-csv.gmp.py +++ b/scripts/create-tasks-from-csv.gmp.py @@ -1,31 +1,14 @@ -# -*- coding: utf-8 -*- -# -# Loosely based on the create-targets-from-host-list -# As provided by Greenbone in the gvm-tools repo -# -# Martin Boller +# SPDX-FileCopyrightText: 2024 Martin Boller # # SPDX-License-Identifier: GPL-3.0-or-later # -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . + +# Loosely based on the create-targets-from-host-list # # Run with gvm-script --gmp-username admin-user --gmp-password password socket create-tasks-from-csv.gmp.py hostname-server tasks.csv -# -# + # Note: for some weird reason theres a space in front of the default scan config " Full and fast" # Examples of all defaults in tasks.csv -# import sys import time diff --git a/scripts/delete-overrides-by-filter.gmp.py b/scripts/delete-overrides-by-filter.gmp.py index e9332a9f..5602fb3d 100644 --- a/scripts/delete-overrides-by-filter.gmp.py +++ b/scripts/delete-overrides-by-filter.gmp.py @@ -1,20 +1,6 @@ -# -*- coding: utf-8 -*- -# Copyright (C) 2017-2021 Greenbone AG +# SPDX-FileCopyrightText: 2017-2021 Greenbone AG # # SPDX-License-Identifier: GPL-3.0-or-later -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . import sys import time diff --git a/scripts/empty-trash.gmp.py b/scripts/empty-trash.gmp.py index 66dbb5ef..492da539 100755 --- a/scripts/empty-trash.gmp.py +++ b/scripts/empty-trash.gmp.py @@ -1,25 +1,6 @@ -# -*- coding: utf-8 -*- -# Copyright (C) 2019-2021 Greenbone Networks GmbH +# SPDX-FileCopyrightText: 2014 Martin Boller # # SPDX-License-Identifier: GPL-3.0-or-later -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -# -# Based on other Greenbone scripts -# -# Martin Boller -# from argparse import Namespace diff --git a/scripts/export-csv-report.gmp.py b/scripts/export-csv-report.gmp.py index 807b0100..f906754a 100755 --- a/scripts/export-csv-report.gmp.py +++ b/scripts/export-csv-report.gmp.py @@ -1,31 +1,9 @@ -# -*- coding: utf-8 -*- -# -# Based on the Greenbone export-pdf-report script and modified to -# create csv and return more (all) details. -# Martin Boller -# -# Copyright (C) 2019-2021 Greenbone Networks GmbH +# SPDX-FileCopyrightText: 2024 Martin Boller # # SPDX-License-Identifier: GPL-3.0-or-later -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -# -# 2022-11-02 - Martin B -# Added ignore_pagination=True, details=True to get the full report -# -import sys +# Based on the export-pdf-report script and modified to +# create csv and return more (all) details. from base64 import b64decode from pathlib import Path diff --git a/scripts/export-pdf-report.gmp.py b/scripts/export-pdf-report.gmp.py index 3bd0af96..f18a3f9b 100644 --- a/scripts/export-pdf-report.gmp.py +++ b/scripts/export-pdf-report.gmp.py @@ -1,29 +1,7 @@ -# -*- coding: utf-8 -*- -# -# Based on the Greenbone export-pdf-report script and modified to -# return more (all) details. -# Martin Boller -# -# Copyright (C) 2019-2021 Greenbone Networks GmbH +# SPDX-FileCopyrightText: 2019-2021 Greenbone AG +# SPDX-FileCopyrightText: 2024 Martin Boller # # SPDX-License-Identifier: GPL-3.0-or-later -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -# -# 2022-11-02 - Martin B -# Added ignore_pagination=True, details=True to get the full report -# import sys from argparse import Namespace diff --git a/scripts/export-xml-report.gmp.py b/scripts/export-xml-report.gmp.py index 9e0e377d..b6cd3fd2 100755 --- a/scripts/export-xml-report.gmp.py +++ b/scripts/export-xml-report.gmp.py @@ -1,29 +1,6 @@ -# -*- coding: utf-8 -*- -# -# Based on the Greenbone export-xml-report script and modified to -# return more (all) details. -# Martin Boller -# -# Copyright (C) 2019-2021 Greenbone Networks GmbH +# SPDX-FileCopyrightText: 2024 Martin Boller # # SPDX-License-Identifier: GPL-3.0-or-later -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -# -# 2022-11-02 - Martin B -# Added ignore_pagination=True, details=True to get the full report -# import sys from argparse import Namespace diff --git a/scripts/generate-random-reports.gmp.py b/scripts/generate-random-reports.gmp.py index 0814074d..acc81014 100755 --- a/scripts/generate-random-reports.gmp.py +++ b/scripts/generate-random-reports.gmp.py @@ -1,22 +1,6 @@ -# -*- coding: utf-8 -*- -# Copyright (C) 2017-2023 Greenbone AG +# SPDX-FileCopyrightText: 2017-2021 Greenbone AG # # SPDX-License-Identifier: GPL-3.0-or-later -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -# pylint: disable=too-many-lines import json import textwrap diff --git a/scripts/generate-random-targets.gmp.py b/scripts/generate-random-targets.gmp.py index 4e793a66..165a1269 100644 --- a/scripts/generate-random-targets.gmp.py +++ b/scripts/generate-random-targets.gmp.py @@ -1,20 +1,6 @@ -# -*- coding: utf-8 -*- -# Copyright (C) 2017-2021 Greenbone AG +# SPDX-FileCopyrightText: 2017-2021 Greenbone AG # # SPDX-License-Identifier: GPL-3.0-or-later -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . import sys from argparse import Namespace diff --git a/scripts/list-alerts.gmp.py b/scripts/list-alerts.gmp.py index a8ce6e3f..950da1eb 100755 --- a/scripts/list-alerts.gmp.py +++ b/scripts/list-alerts.gmp.py @@ -1,25 +1,6 @@ -# -*- coding: utf-8 -*- -# Copyright (C) 2019-2021 Greenbone Networks GmbH +# SPDX-FileCopyrightText: 2024 Martin Boller # # SPDX-License-Identifier: GPL-3.0-or-later -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -# -# Based on other Greenbone scripts -# -# Martin Boller -# from argparse import Namespace diff --git a/scripts/list-credentials.gmp.py b/scripts/list-credentials.gmp.py index 65cd4f47..8bd4f719 100755 --- a/scripts/list-credentials.gmp.py +++ b/scripts/list-credentials.gmp.py @@ -1,25 +1,6 @@ -# -*- coding: utf-8 -*- -# Copyright (C) 2019-2021 Greenbone Networks GmbH +# SPDX-FileCopyrightText: 2024 Martin Boller # # SPDX-License-Identifier: GPL-3.0-or-later -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -# -# Based on other Greenbone scripts -# -# Martin Boller -# from argparse import Namespace diff --git a/scripts/list-feeds.gmp.py b/scripts/list-feeds.gmp.py index 94a79a37..bd17355b 100755 --- a/scripts/list-feeds.gmp.py +++ b/scripts/list-feeds.gmp.py @@ -1,26 +1,6 @@ -# -*- coding: utf-8 -*- -# Copyright (C) 2019-2021 Greenbone Networks GmbH +# SPDX-FileCopyrightText: 2024 Martin Boller # # SPDX-License-Identifier: GPL-3.0-or-later -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -# -# -# Based on other Greenbone scripts -# -# Martin Boller -# from argparse import Namespace diff --git a/scripts/list-filters.gmp.py b/scripts/list-filters.gmp.py index 18f69886..9cf15387 100755 --- a/scripts/list-filters.gmp.py +++ b/scripts/list-filters.gmp.py @@ -1,25 +1,6 @@ -# -*- coding: utf-8 -*- -# Copyright (C) 2019-2021 Greenbone Networks GmbH +# SPDX-FileCopyrightText: 2024 Martin Boller # # SPDX-License-Identifier: GPL-3.0-or-later -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -# -# Based on other Greenbone scripts -# -# Martin Boller -# from argparse import Namespace diff --git a/scripts/list-groups.gmp.py b/scripts/list-groups.gmp.py index 6146981b..3b327b40 100755 --- a/scripts/list-groups.gmp.py +++ b/scripts/list-groups.gmp.py @@ -1,25 +1,6 @@ -# -*- coding: utf-8 -*- -# Copyright (C) 2019-2021 Greenbone Networks GmbH +# SPDX-FileCopyrightText: 2024 Martin Boller # # SPDX-License-Identifier: GPL-3.0-or-later -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -# -# Based on other Greenbone scripts -# -# Martin Boller -# from argparse import Namespace diff --git a/scripts/list-policies.gmp.py b/scripts/list-policies.gmp.py index 10429e6a..5f65b4e4 100755 --- a/scripts/list-policies.gmp.py +++ b/scripts/list-policies.gmp.py @@ -1,25 +1,6 @@ -# -*- coding: utf-8 -*- -# Copyright (C) 2019-2021 Greenbone Networks GmbH +# SPDX-FileCopyrightText: 2024 Martin Boller # # SPDX-License-Identifier: GPL-3.0-or-later -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -# -# Based on other Greenbone scripts -# -# Martin Boller -# from argparse import Namespace diff --git a/scripts/list-portlists.gmp.py b/scripts/list-portlists.gmp.py index 4a01857c..e90e60fd 100755 --- a/scripts/list-portlists.gmp.py +++ b/scripts/list-portlists.gmp.py @@ -1,25 +1,6 @@ -# -*- coding: utf-8 -*- -# Copyright (C) 2019-2021 Greenbone Networks GmbH +# SPDX-FileCopyrightText: 2024 Martin Boller # # SPDX-License-Identifier: GPL-3.0-or-later -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -# -# Based on other Greenbone scripts -# -# Martin Boller -# from argparse import Namespace diff --git a/scripts/list-report-formats.gmp.py b/scripts/list-report-formats.gmp.py index 93314c37..bc2f285b 100755 --- a/scripts/list-report-formats.gmp.py +++ b/scripts/list-report-formats.gmp.py @@ -1,26 +1,6 @@ -# -*- coding: utf-8 -*- -# Copyright (C) 2019-2021 Greenbone Networks GmbH +# SPDX-FileCopyrightText: 2024 Martin Boller # # SPDX-License-Identifier: GPL-3.0-or-later -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -# -# -# Based on other Greenbone scripts -# -# Martin Boller -# from argparse import Namespace diff --git a/scripts/list-reports.gmp.py b/scripts/list-reports.gmp.py index e8cb1e20..015eddd7 100755 --- a/scripts/list-reports.gmp.py +++ b/scripts/list-reports.gmp.py @@ -1,27 +1,6 @@ -# -*- coding: utf-8 -*- -# Copyright (C) 2019-2021 Greenbone Networks GmbH +# SPDX-FileCopyrightText: 2024 Martin Boller # # SPDX-License-Identifier: GPL-3.0-or-later -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -# -# Based on other Greenbone scripts -# -# Martin Boller 2023-05-15 -# -# run script with e.g. gvm-script --gmp-username username --gmp-password password socket list-reports.gmp.py All -# from gvm.protocols.gmp import Gmp diff --git a/scripts/list-roles.gmp.py b/scripts/list-roles.gmp.py index eebea991..11a0c108 100755 --- a/scripts/list-roles.gmp.py +++ b/scripts/list-roles.gmp.py @@ -1,25 +1,6 @@ -# -*- coding: utf-8 -*- -# Copyright (C) 2019-2021 Greenbone Networks GmbH +# SPDX-FileCopyrightText: 2024 Martin Boller # # SPDX-License-Identifier: GPL-3.0-or-later -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -# -# Based on other Greenbone scripts -# -# Martin Boller -# from argparse import Namespace diff --git a/scripts/list-scan-configs.gmp.py b/scripts/list-scan-configs.gmp.py index 6bd66490..4ceccda8 100755 --- a/scripts/list-scan-configs.gmp.py +++ b/scripts/list-scan-configs.gmp.py @@ -1,25 +1,6 @@ -# -*- coding: utf-8 -*- -# Copyright (C) 2019-2021 Greenbone Networks GmbH +# SPDX-FileCopyrightText: 2024 Martin Boller # # SPDX-License-Identifier: GPL-3.0-or-later -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -# -# Based on other Greenbone scripts -# -# Martin Boller -# from argparse import Namespace diff --git a/scripts/list-scanners.gmp.py b/scripts/list-scanners.gmp.py index 8c2aebe4..f22f4221 100755 --- a/scripts/list-scanners.gmp.py +++ b/scripts/list-scanners.gmp.py @@ -1,25 +1,6 @@ -# -*- coding: utf-8 -*- -# Copyright (C) 2019-2021 Greenbone Networks GmbH +# SPDX-FileCopyrightText: 2024 Martin Boller # # SPDX-License-Identifier: GPL-3.0-or-later -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -# -# Based on other Greenbone scripts -# -# Martin Boller -# from argparse import Namespace diff --git a/scripts/list-schedules.gmp.py b/scripts/list-schedules.gmp.py index fd731d0f..56280d8b 100755 --- a/scripts/list-schedules.gmp.py +++ b/scripts/list-schedules.gmp.py @@ -1,25 +1,6 @@ -# -*- coding: utf-8 -*- -# Copyright (C) 2019-2021 Greenbone Networks GmbH +# SPDX-FileCopyrightText: 2024 Martin Boller # # SPDX-License-Identifier: GPL-3.0-or-later -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -# -# Based on other Greenbone scripts -# -# Martin Boller -# from argparse import Namespace diff --git a/scripts/list-tags.gmp.py b/scripts/list-tags.gmp.py index ad2e0155..8ef410a3 100755 --- a/scripts/list-tags.gmp.py +++ b/scripts/list-tags.gmp.py @@ -1,25 +1,6 @@ -# -*- coding: utf-8 -*- -# Copyright (C) 2019-2021 Greenbone Networks GmbH +# SPDX-FileCopyrightText: 2024 Martin Boller # # SPDX-License-Identifier: GPL-3.0-or-later -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -# -# Based on other Greenbone scripts -# -# Martin Boller -# from argparse import Namespace diff --git a/scripts/list-targets.gmp.py b/scripts/list-targets.gmp.py index 5ccfbfaf..1dc1bc32 100755 --- a/scripts/list-targets.gmp.py +++ b/scripts/list-targets.gmp.py @@ -1,25 +1,6 @@ -# -*- coding: utf-8 -*- -# Copyright (C) 2019-2021 Greenbone Networks GmbH +# SPDX-FileCopyrightText: 2024 Martin Boller # # SPDX-License-Identifier: GPL-3.0-or-later -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -# -# Based on other Greenbone scripts -# -# Martin Boller -# from argparse import Namespace diff --git a/scripts/list-tasks.gmp.py b/scripts/list-tasks.gmp.py index 05ebe5fa..7a1e7074 100644 --- a/scripts/list-tasks.gmp.py +++ b/scripts/list-tasks.gmp.py @@ -1,25 +1,6 @@ -# -*- coding: utf-8 -*- -# Copyright (C) 2019-2021 Greenbone Networks GmbH +# SPDX-FileCopyrightText: 2024 Martin Boller # # SPDX-License-Identifier: GPL-3.0-or-later -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -# -# Based on other Greenbone scripts -# -# Martin Boller -# from argparse import Namespace diff --git a/scripts/list-tickets.gmp.py b/scripts/list-tickets.gmp.py index 84e7bd15..15d48240 100755 --- a/scripts/list-tickets.gmp.py +++ b/scripts/list-tickets.gmp.py @@ -1,25 +1,6 @@ -# -*- coding: utf-8 -*- -# Copyright (C) 2019-2021 Greenbone Networks GmbH +# SPDX-FileCopyrightText: 2024 Martin Boller # # SPDX-License-Identifier: GPL-3.0-or-later -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -# -# Based on other Greenbone scripts -# -# Martin Boller -# from argparse import Namespace diff --git a/scripts/list-users.gmp.py b/scripts/list-users.gmp.py index 99c3e906..6f319ae9 100755 --- a/scripts/list-users.gmp.py +++ b/scripts/list-users.gmp.py @@ -1,25 +1,6 @@ -# -*- coding: utf-8 -*- -# Copyright (C) 2019-2021 Greenbone Networks GmbH +# SPDX-FileCopyrightText: 2024 Martin Boller # # SPDX-License-Identifier: GPL-3.0-or-later -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -# -# Based on other Greenbone scripts -# -# Martin Boller -# from argparse import Namespace diff --git a/scripts/monthly-report-gos4.gmp.py b/scripts/monthly-report-gos4.gmp.py index 2ee97cbe..69b1bfbd 100644 --- a/scripts/monthly-report-gos4.gmp.py +++ b/scripts/monthly-report-gos4.gmp.py @@ -1,20 +1,6 @@ -# -*- coding: utf-8 -*- -# Copyright (C) 2017-2021 Greenbone AG +# SPDX-FileCopyrightText: 2017-2021 Greenbone AG # # SPDX-License-Identifier: GPL-3.0-or-later -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . import sys from argparse import Namespace diff --git a/scripts/monthly-report.gmp.py b/scripts/monthly-report.gmp.py index 9786bd91..08809cea 100644 --- a/scripts/monthly-report.gmp.py +++ b/scripts/monthly-report.gmp.py @@ -1,20 +1,6 @@ -# -*- coding: utf-8 -*- -# Copyright (C) 2017-2021 Greenbone AG +# SPDX-FileCopyrightText: 2017-2021 Greenbone AG # # SPDX-License-Identifier: GPL-3.0-or-later -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . import sys from argparse import Namespace diff --git a/scripts/nvt-scan.gmp.py b/scripts/nvt-scan.gmp.py index c4db0709..87c2cb40 100644 --- a/scripts/nvt-scan.gmp.py +++ b/scripts/nvt-scan.gmp.py @@ -1,20 +1,6 @@ -# -*- coding: utf-8 -*- -# Copyright (C) 2017-2021 Greenbone AG +# SPDX-FileCopyrightText: 2017-2021 Greenbone AG # # SPDX-License-Identifier: GPL-3.0-or-later -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . import sys from argparse import Namespace diff --git a/scripts/scan-new-system.gmp.py b/scripts/scan-new-system.gmp.py index 1501c590..e8f26e67 100644 --- a/scripts/scan-new-system.gmp.py +++ b/scripts/scan-new-system.gmp.py @@ -1,20 +1,6 @@ -# -*- coding: utf-8 -*- -# Copyright (C) 2019-2021 Greenbone AG +# SPDX-FileCopyrightText: 2019-2021 Greenbone AG # # SPDX-License-Identifier: GPL-3.0-or-later -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . import datetime import sys diff --git a/scripts/send-delta-emails.gmp.py b/scripts/send-delta-emails.gmp.py index cf22e1a0..f575201b 100644 --- a/scripts/send-delta-emails.gmp.py +++ b/scripts/send-delta-emails.gmp.py @@ -1,22 +1,8 @@ -# -*- coding: utf-8 -*- -# Copyright (C) 2017-2021 Greenbone AG +# SPDX-FileCopyrightText: 2017-2021 Greenbone AG # # SPDX-License-Identifier: GPL-3.0-or-later -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -# GMP script for gvm-pyshell to send emails with delta reports. +# GMP script for gvm-cli to send emails with delta reports. import base64 import datetime diff --git a/scripts/send-schedules.gmp.py b/scripts/send-schedules.gmp.py index fcbf011f..f9249a1c 100644 --- a/scripts/send-schedules.gmp.py +++ b/scripts/send-schedules.gmp.py @@ -1,20 +1,6 @@ -# -*- coding: utf-8 -*- -# Copyright (C) 2017-2021 Greenbone AG +# SPDX-FileCopyrightText: 2017-2021 Greenbone AG # # SPDX-License-Identifier: GPL-3.0-or-later -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . import sys from argparse import Namespace diff --git a/scripts/send-targets.gmp.py b/scripts/send-targets.gmp.py index 2bc35dfc..b4124358 100644 --- a/scripts/send-targets.gmp.py +++ b/scripts/send-targets.gmp.py @@ -1,20 +1,6 @@ -# -*- coding: utf-8 -*- -# Copyright (C) 2018-2021 Greenbone AG +# SPDX-FileCopyrightText: 2018-2021 Greenbone AG # # SPDX-License-Identifier: GPL-3.0-or-later -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . import sys from argparse import Namespace diff --git a/scripts/send-tasks.gmp.py b/scripts/send-tasks.gmp.py index 72e3db0e..dcc0e288 100644 --- a/scripts/send-tasks.gmp.py +++ b/scripts/send-tasks.gmp.py @@ -1,20 +1,6 @@ -# -*- coding: utf-8 -*- -# Copyright (C) 2018-2021 Greenbone AG +# SPDX-FileCopyrightText: 2018-2021 Greenbone AG # # SPDX-License-Identifier: GPL-3.0-or-later -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . import sys from argparse import ArgumentParser, Namespace, RawTextHelpFormatter diff --git a/scripts/start-alert-scan.gmp.py b/scripts/start-alert-scan.gmp.py index 068ad4e0..f94a15e0 100644 --- a/scripts/start-alert-scan.gmp.py +++ b/scripts/start-alert-scan.gmp.py @@ -1,21 +1,7 @@ -# -*- coding: utf-8 -*- -# Copyright (C) 2018 Henning Häcker -# Copyright (C) 2019-2021 Greenbone AG +# SPDX-FileCopyrightText: 2018 Henning Häcker +# SPDX-FileCopyrightText: 2019-2021 Greenbone AG # # SPDX-License-Identifier: GPL-3.0-or-later -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . from argparse import ArgumentParser, Namespace, RawTextHelpFormatter from typing import List diff --git a/scripts/start-multiple-alerts-scan.gmp.py b/scripts/start-multiple-alerts-scan.gmp.py index 67f584c2..6014ddbb 100644 --- a/scripts/start-multiple-alerts-scan.gmp.py +++ b/scripts/start-multiple-alerts-scan.gmp.py @@ -1,21 +1,7 @@ -# -*- coding: utf-8 -*- -# Copyright (C) 2018 inovex GmbH -# Copyright (C) 2019-2021 Greenbone AG +# SPDX-FileCopyrightText: 2018 inovex GmbH +# SPDX-FileCopyrightText: 2019-2021 Greenbone AG # # SPDX-License-Identifier: GPL-3.0-or-later -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . import sys from argparse import Namespace diff --git a/scripts/start-nvt-scan.gmp.py b/scripts/start-nvt-scan.gmp.py index bcaa970a..987f3d2c 100644 --- a/scripts/start-nvt-scan.gmp.py +++ b/scripts/start-nvt-scan.gmp.py @@ -1,20 +1,6 @@ -# -*- coding: utf-8 -*- -# Copyright (C) 2017-2021 Greenbone AG +# SPDX-FileCopyrightText: 2017-2021 Greenbone AG # # SPDX-License-Identifier: GPL-3.0-or-later -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . import sys from argparse import Namespace diff --git a/scripts/start-scans-from-csv.py b/scripts/start-scans-from-csv.py index a10e5b6d..03061c2e 100755 --- a/scripts/start-scans-from-csv.py +++ b/scripts/start-scans-from-csv.py @@ -1,27 +1,8 @@ -# -*- coding: utf-8 -*- -# -# Loosely based on Greenbone sample scripts -# As provided by Greenbone in the gvm-tools repo -# -# Martin Boller +# SPDX-FileCopyrightText: 2024 Martin Boller # # SPDX-License-Identifier: GPL-3.0-or-later -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -# + # Run with gvm-script --gmp-username admin-user --gmp-password password socket start-scans-from-csv.gmp.py startscans.csv -# import sys import time diff --git a/scripts/stop-all-scans.gmp.py b/scripts/stop-all-scans.gmp.py index 2feffc79..0556b8cb 100755 --- a/scripts/stop-all-scans.gmp.py +++ b/scripts/stop-all-scans.gmp.py @@ -1,25 +1,6 @@ -# -*- coding: utf-8 -*- -# Copyright (C) 2019-2021 Greenbone Networks GmbH +# SPDX-FileCopyrightText: 2024 Martin Boller # # SPDX-License-Identifier: GPL-3.0-or-later -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -# -# Based on other Greenbone scripts -# -# Martin Boller -# from argparse import Namespace diff --git a/scripts/stop-scans-from-csv.py b/scripts/stop-scans-from-csv.py index c80ee3c5..c17dcb2f 100755 --- a/scripts/stop-scans-from-csv.py +++ b/scripts/stop-scans-from-csv.py @@ -1,27 +1,8 @@ -# -*- coding: utf-8 -*- -# -# Loosely based on Greenbone sample scripts -# As provided by Greenbone in the gvm-tools repo -# -# Martin Boller +# SPDX-FileCopyrightText: 2024 Martin Boller # # SPDX-License-Identifier: GPL-3.0-or-later -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -# + # Run with gvm-script --gmp-username admin-user --gmp-password password socket start-scans-from-csv.gmp.py startscans.csv -# import sys import time diff --git a/scripts/sync-hosts.gmp.py b/scripts/sync-hosts.gmp.py index 5a2b33ad..0ad39a6f 100644 --- a/scripts/sync-hosts.gmp.py +++ b/scripts/sync-hosts.gmp.py @@ -1,20 +1,6 @@ -# -*- coding: utf-8 -*- -# Copyright (C) 2017-2021 Greenbone AG +# SPDX-FileCopyrightText: 2017-2021 Greenbone AG # # SPDX-License-Identifier: GPL-3.0-or-later -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . import csv import sys diff --git a/scripts/update-task-target.gmp.py b/scripts/update-task-target.gmp.py index e0891131..a4a125bb 100644 --- a/scripts/update-task-target.gmp.py +++ b/scripts/update-task-target.gmp.py @@ -1,20 +1,6 @@ -# -*- coding: utf-8 -*- -# Copyright (C) 2017-2021 Greenbone AG +# SPDX-FileCopyrightText: 2017-2021 Greenbone AG # # SPDX-License-Identifier: GPL-3.0-or-later -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . import time from argparse import ArgumentParser, FileType, Namespace, RawTextHelpFormatter From cfeb98cc741502ff6dcbdcdae727e9a1289153f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ricks?= Date: Wed, 19 Jun 2024 10:34:40 +0200 Subject: [PATCH 6/7] Remove unused draft script --- scripts/dummy_def.gmp.py | 12 ------------ 1 file changed, 12 deletions(-) delete mode 100644 scripts/dummy_def.gmp.py diff --git a/scripts/dummy_def.gmp.py b/scripts/dummy_def.gmp.py deleted file mode 100644 index d53b4f81..00000000 --- a/scripts/dummy_def.gmp.py +++ /dev/null @@ -1,12 +0,0 @@ -def alert_id( - gmp: Gmp, - alert_name: str, -): - response_xml = gmp.get_alerts(filter_string="rows=-1, name=" + alert_name) - alerts_xml = response_xml.xpath("alert") - alert_id = "" - - for alert in alerts_xml: - name = "".join(alert.xpath("name/text()")) - alert_id = alert.get("id") - return alert_id From f708774c240ae8f2c390569a1977b97bcec7f61a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ricks?= Date: Wed, 19 Jun 2024 10:35:53 +0200 Subject: [PATCH 7/7] Fix formatting, import order and linter warnings Run black and ruff on all the scripts. --- scripts/bulk-modify-schedules.gmp.py | 1 + scripts/certbund-report.gmp.py | 3 +- scripts/clean-sensor.gmp.py | 47 +++---- scripts/combine-reports.gmp.py | 3 +- scripts/create-alerts-from-csv.gmp.py | 72 +++++----- scripts/create-consolidated-report.gmp.py | 3 +- scripts/create-credentials-from-csv.gmp.py | 73 +++++----- scripts/create-cve-report-from-json.gmp.py | 3 +- scripts/create-dummy-data.gmp.py | 1 - scripts/create-filters-from-csv.gmp.py | 93 ++++++------- scripts/create-report-format-from-csv.gmp.py | 110 +++++++--------- scripts/create-schedules-from-csv.gmp.py | 38 +++--- scripts/create-tags-from-csv.gmp.py | 132 +++++++++++-------- scripts/create-targets-from-csv.gmp.py | 57 ++++---- scripts/create-targets-from-host-list.gmp.py | 3 +- scripts/create-tasks-from-csv.gmp.py | 83 ++++++------ scripts/empty-trash.gmp.py | 12 +- scripts/export-csv-report.gmp.py | 26 ++-- scripts/export-pdf-report.gmp.py | 9 +- scripts/export-xml-report.gmp.py | 15 ++- scripts/generate-random-reports.gmp.py | 5 +- scripts/generate-random-targets.gmp.py | 1 - scripts/list-alerts.gmp.py | 29 +++- scripts/list-credentials.gmp.py | 9 +- scripts/list-feeds.gmp.py | 17 +-- scripts/list-filters.gmp.py | 5 +- scripts/list-groups.gmp.py | 5 +- scripts/list-policies.gmp.py | 5 +- scripts/list-portlists.gmp.py | 9 +- scripts/list-report-formats.gmp.py | 6 +- scripts/list-reports.gmp.py | 72 ++++++---- scripts/list-roles.gmp.py | 5 +- scripts/list-scan-configs.gmp.py | 5 +- scripts/list-scanners.gmp.py | 5 +- scripts/list-schedules.gmp.py | 8 +- scripts/list-tags.gmp.py | 5 +- scripts/list-targets.gmp.py | 31 ++++- scripts/list-tasks.gmp.py | 9 +- scripts/list-tickets.gmp.py | 19 ++- scripts/list-users.gmp.py | 5 +- scripts/scan-new-system.gmp.py | 10 +- scripts/send-schedules.gmp.py | 3 +- scripts/send-targets.gmp.py | 3 +- scripts/send-tasks.gmp.py | 3 +- scripts/start-scans-from-csv.py | 54 ++++---- scripts/stop-all-scans.gmp.py | 21 ++- scripts/stop-scans-from-csv.py | 54 ++++---- scripts/update-task-target.gmp.py | 1 - 48 files changed, 619 insertions(+), 569 deletions(-) diff --git a/scripts/bulk-modify-schedules.gmp.py b/scripts/bulk-modify-schedules.gmp.py index 44e6421b..45ed6a50 100644 --- a/scripts/bulk-modify-schedules.gmp.py +++ b/scripts/bulk-modify-schedules.gmp.py @@ -4,6 +4,7 @@ import sys from argparse import Namespace + from gvm.protocols.gmp import Gmp diff --git a/scripts/certbund-report.gmp.py b/scripts/certbund-report.gmp.py index 592e067d..37b977c9 100644 --- a/scripts/certbund-report.gmp.py +++ b/scripts/certbund-report.gmp.py @@ -12,10 +12,11 @@ from itertools import zip_longest from typing import Dict, List, Optional, Sequence, Tuple, TypeVar, overload -import ssv_csv from gvm.errors import GvmResponseError from gvm.protocols.gmp import Gmp +import ssv_csv + # from gvm.xml import pretty_print sys.path.append(os.path.dirname(args.argv[0])) # type: ignore diff --git a/scripts/clean-sensor.gmp.py b/scripts/clean-sensor.gmp.py index 422c5e20..76bd87f1 100644 --- a/scripts/clean-sensor.gmp.py +++ b/scripts/clean-sensor.gmp.py @@ -4,8 +4,8 @@ from argparse import Namespace -from gvm.protocols.gmp import Gmp from gvm.errors import GvmResponseError +from gvm.protocols.gmp import Gmp def clean_sensor(gmp: Gmp) -> None: @@ -24,7 +24,7 @@ def clean_sensor(gmp: Gmp) -> None: print(status_text) except GvmResponseError as gvmerr: print(f"{gvmerr=}") - pass + pass targets = gmp.get_targets(filter_string="rows=-1 not _owner=""") try: @@ -36,7 +36,7 @@ def clean_sensor(gmp: Gmp) -> None: print(status_text) except GvmResponseError as gvmerr: print(f"{gvmerr=}") - pass + pass configs = gmp.get_scan_configs( filter_string="rows=-1 not _owner=""" @@ -44,13 +44,13 @@ def clean_sensor(gmp: Gmp) -> None: try: for config_id in configs.xpath("config/@id"): print(f"Removing config {config_id} ... ") - status_text = gmp.delete_scan_config(config_id, ultimate=True).xpath( - "@status_text" - )[0] + status_text = gmp.delete_scan_config( + config_id, ultimate=True + ).xpath("@status_text")[0] print(status_text) except GvmResponseError as gvmerr: print(f"{gvmerr=}") - pass + pass port_lists = gmp.get_port_lists( filter_string="rows=-1 not _owner=""" @@ -58,17 +58,15 @@ def clean_sensor(gmp: Gmp) -> None: try: for port_list_id in port_lists.xpath("port_list/@id"): print(f"Removing port_list {port_list_id} ... ") - status_text = gmp.delete_port_list(port_list_id, ultimate=True).xpath( - "@status_text" - )[0] + status_text = gmp.delete_port_list( + port_list_id, ultimate=True + ).xpath("@status_text")[0] print(status_text) except GvmResponseError as gvmerr: print(f"{gvmerr=}") - pass + pass - alerts = gmp.get_alerts( - filter_string="rows=-1 not _owner=""" - ) + alerts = gmp.get_alerts(filter_string="rows=-1 not _owner=""") try: for alert_id in alerts.xpath("alert/@id"): print(f"Removing alert {alert_id} ... ") @@ -78,7 +76,7 @@ def clean_sensor(gmp: Gmp) -> None: print(status_text) except GvmResponseError as gvmerr: print(f"{gvmerr=}") - pass + pass schedules = gmp.get_schedules( filter_string="rows=-1 not _owner=""" @@ -92,11 +90,9 @@ def clean_sensor(gmp: Gmp) -> None: print(status_text) except GvmResponseError as gvmerr: print(f"{gvmerr=}") - pass + pass - tags = gmp.get_tags( - filter_string="rows=-1 not _owner=""" - ) + tags = gmp.get_tags(filter_string="rows=-1 not _owner=""") try: for tag_id in tags.xpath("tag/@id"): print(f"Removing tag {tag_id} ... ") @@ -106,11 +102,9 @@ def clean_sensor(gmp: Gmp) -> None: print(status_text) except GvmResponseError as gvmerr: print(f"{gvmerr=}") - pass + pass - filters = gmp.get_filters( - filter_string="rows=-1 not _owner=""" - ) + filters = gmp.get_filters(filter_string="rows=-1 not _owner=""") try: for filter_id in filters.xpath("filter/@id"): print(f"Removing filter {filter_id} ... ") @@ -120,7 +114,7 @@ def clean_sensor(gmp: Gmp) -> None: print(status_text) except GvmResponseError as gvmerr: print(f"{gvmerr=}") - pass + pass credentials = gmp.get_credentials( filter_string="rows=-1 not _owner=""" @@ -134,7 +128,7 @@ def clean_sensor(gmp: Gmp) -> None: print(status_text) except GvmResponseError as gvmerr: print(f"{gvmerr=}") - pass + pass print("Emptying trash... ") try: @@ -142,7 +136,8 @@ def clean_sensor(gmp: Gmp) -> None: print(status_text) except GvmResponseError as gvmerr: print(f"{gvmerr=}") - pass + pass + def main(gmp: Gmp, args: Namespace) -> None: # pylint: disable=unused-argument diff --git a/scripts/combine-reports.gmp.py b/scripts/combine-reports.gmp.py index 849b8f5b..e4d162e8 100644 --- a/scripts/combine-reports.gmp.py +++ b/scripts/combine-reports.gmp.py @@ -9,9 +9,8 @@ from argparse import Namespace from gvm.protocols.gmp import Gmp -from lxml import etree as e - from gvmtools.helper import generate_uuid +from lxml import etree as e def check_args(args: Namespace) -> None: diff --git a/scripts/create-alerts-from-csv.gmp.py b/scripts/create-alerts-from-csv.gmp.py index fa2a44aa..4614bc20 100755 --- a/scripts/create-alerts-from-csv.gmp.py +++ b/scripts/create-alerts-from-csv.gmp.py @@ -8,18 +8,14 @@ # Information on Variables to be used in alerts: https://docs.greenbone.net/GSM-Manual/gos-22.04/en/scanning.html#using-alerts # Example script: https://forum.greenbone.net/t/working-example-of-creating-an-alert-using-script/7511/2 +import csv import sys import time -import csv -import json - from argparse import ArgumentParser, Namespace, RawTextHelpFormatter from pathlib import Path -from typing import List -from gvm.errors import GvmResponseError +from gvm.errors import GvmResponseError from gvm.protocols.gmp import Gmp - from gvmtools.helper import error_and_exit HELP_TEXT = ( @@ -30,6 +26,7 @@ "It should be rather self explanatory." ) + def check_args(args): len_args = len(args.script) - 1 if len_args != 2: @@ -74,6 +71,7 @@ def parse_args(args: Namespace) -> Namespace: # pylint: disable=unused-argument script_args, _ = parser.parse_known_args(args) return script_args + def alert_id( gmp: Gmp, alert_name: str, @@ -83,50 +81,55 @@ def alert_id( alert_id = "" for alert in alerts_xml: - name = "".join(alert.xpath("name/text()")) + "".join(alert.xpath("name/text()")) alert_id = alert.get("id") return alert_id + def credential_id( gmp: Gmp, credential_name: str, ): - response_xml = gmp.get_credentials(filter_string="rows=-1, name=" + credential_name) + response_xml = gmp.get_credentials( + filter_string="rows=-1, name=" + credential_name + ) credentials_xml = response_xml.xpath("credential") credential_id = "" for credential in credentials_xml: - name = "".join(credential.xpath("name/text()")) credential_id = credential.get("id") return credential_id + def report_format_id( gmp: Gmp, report_format_name: str, ): - response_xml = gmp.get_report_formats(details=True, filter_string="rows=-1, name=" + report_format_name) + response_xml = gmp.get_report_formats( + details=True, filter_string="rows=-1, name=" + report_format_name + ) report_formats_xml = response_xml.xpath("report_format") report_format_id = "" for report_format in report_formats_xml: - name = "".join(report_format.xpath("name/text()")) report_format_id = report_format.get("id") return report_format_id + def event_list(string): event_list = list(string.split(" ")) return event_list - -def create_alerts( + +def create_alerts( gmp: Gmp, alert_file: Path, ): try: numberalerts = 0 with open(alert_file, encoding="utf-8") as csvFile: - content = csv.reader(csvFile, delimiter=',') #read the data - for row in content: #loop through each row + content = csv.reader(csvFile, delimiter=",") # read the data + for row in content: # loop through each row if len(row) == 0: continue alert_name = row[0] @@ -140,12 +143,12 @@ def create_alerts( event_data = row[8] comment = f"Created: {time.strftime('%Y/%m/%d-%H:%M:%S')}" - alert_type=getattr(gmp.types.AlertMethod, str_alert_type) + alert_type = getattr(gmp.types.AlertMethod, str_alert_type) if alert_id(gmp, alert_name): print(f"Alert: {alert_name} exist, not creating...") continue - + if str_alert_type == "EMAIL": sender_email = strRow2 recipient_email = strRow3 @@ -174,7 +177,7 @@ def create_alerts( numberalerts = numberalerts + 1 except GvmResponseError as gvmerr: print(f"{gvmerr=}, name: {alert_name}") - pass + pass else: smb_credential = credential_id(gmp, strRow2) smb_share_path = strRow3 @@ -185,33 +188,34 @@ def create_alerts( try: print("Creating alert: " + alert_name) gmp.create_alert( - name=alert_name, - comment=comment, - event=gmp.types.AlertEvent.TASK_RUN_STATUS_CHANGED, - event_data={"status": event_data}, - condition=gmp.types.AlertCondition.ALWAYS, - method=alert_type, - method_data={ - "smb_credential": smb_credential, - "smb_share_path": smb_share_path, - "smb_report_format": report_format, - "smb_file_path": smb_file_path, - }, + name=alert_name, + comment=comment, + event=gmp.types.AlertEvent.TASK_RUN_STATUS_CHANGED, + event_data={"status": event_data}, + condition=gmp.types.AlertCondition.ALWAYS, + method=alert_type, + method_data={ + "smb_credential": smb_credential, + "smb_share_path": smb_share_path, + "smb_report_format": report_format, + "smb_file_path": smb_file_path, + }, ) numberalerts = numberalerts + 1 except GvmResponseError as gvmerr: print(f"{gvmerr=}, name: {alert_name}") - pass - csvFile.close() #close the csv file + pass + csvFile.close() # close the csv file except IOError as e: error_and_exit(f"Failed to read alert_file: {str(e)} (exit)") if len(row) == 0: error_and_exit("alerts file is empty (exit)") - + return numberalerts - + + def main(gmp: Gmp, args: Namespace) -> None: # pylint: disable=undefined-variable if args.script: diff --git a/scripts/create-consolidated-report.gmp.py b/scripts/create-consolidated-report.gmp.py index 7fed753c..febf93d9 100755 --- a/scripts/create-consolidated-report.gmp.py +++ b/scripts/create-consolidated-report.gmp.py @@ -9,9 +9,8 @@ from gvm.errors import GvmError from gvm.protocols.gmp import Gmp -from lxml import etree as e - from gvmtools.helper import error_and_exit, generate_uuid +from lxml import etree as e HELP_TEXT = ( "This script creates a consolidated report and imports it to the GSM. " diff --git a/scripts/create-credentials-from-csv.gmp.py b/scripts/create-credentials-from-csv.gmp.py index 66e8f6e1..6d912179 100755 --- a/scripts/create-credentials-from-csv.gmp.py +++ b/scripts/create-credentials-from-csv.gmp.py @@ -8,17 +8,14 @@ # # Run with gvm-script --gmp-username admin-user --gmp-password password socket create-credentials-from-csv.gmp.py credentials.csv +import csv import sys import time -import csv - from argparse import ArgumentParser, Namespace, RawTextHelpFormatter from pathlib import Path -from typing import List -from gvm.errors import GvmResponseError +from gvm.errors import GvmResponseError from gvm.protocols.gmp import Gmp - from gvmtools.helper import error_and_exit HELP_TEXT = ( @@ -75,28 +72,31 @@ def parse_args(args: Namespace) -> Namespace: # pylint: disable=unused-argument script_args, _ = parser.parse_known_args(args) return script_args + def credential_id( gmp: Gmp, credName: str, ): - response_xml = gmp.get_credentials(filter_string="rows=-1, name=" + credName) + response_xml = gmp.get_credentials( + filter_string="rows=-1, name=" + credName + ) credentials_xml = response_xml.xpath("credential") cred_id = "" for credential in credentials_xml: - name = "".join(credential.xpath("name/text()")) cred_id = credential.get("id") return cred_id -def create_credentials( + +def create_credentials( gmp: Gmp, cred_file: Path, ): try: numberCredentials = 0 with open(cred_file, encoding="utf-8") as csvFile: - content = csv.reader(csvFile, delimiter=',') #read the data - for row in content: #loop through each row + content = csv.reader(csvFile, delimiter=",") # read the data + for row in content: # loop through each row if len(row) == 0: continue cred_name = row[0] @@ -113,11 +113,11 @@ def create_credentials( try: print("Creating credential: " + cred_name) gmp.create_credential( - name=cred_name, - credential_type=gmp.types.CredentialType.USERNAME_PASSWORD, - login=userName, - password=userPW, - comment=comment, + name=cred_name, + credential_type=gmp.types.CredentialType.USERNAME_PASSWORD, + login=userName, + password=userPW, + comment=comment, ) numberCredentials = numberCredentials + 1 except GvmResponseError as gvmerr: @@ -127,7 +127,7 @@ def create_credentials( with open(row[4]) as key_file: key = key_file.read() - try: + try: print("Creating credential: " + cred_name) gmp.create_credential( name=cred_name, @@ -136,22 +136,22 @@ def create_credentials( key_phrase=userPW, private_key=key, comment=comment, - ) + ) numberCredentials = numberCredentials + 1 except GvmResponseError as gvmerr: print(f"{gvmerr=}, name: {cred_name}") pass elif cred_type == "SNMP": - # Unfinished, copy of UP for now + # Unfinished, copy of UP for now try: print("Creating credential: " + cred_name) gmp.create_credential( - name=cred_name, - credential_type=gmp.types.CredentialType.USERNAME_SSH_KEY, - login=userName, - key_phrase=userPW, - private_key=key, - comment=comment, + name=cred_name, + credential_type=gmp.types.CredentialType.USERNAME_SSH_KEY, + login=userName, + key_phrase=userPW, + private_key=key, + comment=comment, ) numberCredentials = numberCredentials + 1 except GvmResponseError as gvmerr: @@ -159,31 +159,32 @@ def create_credentials( pass elif cred_type == "ESX": - # Unfinished, copy of UP for now + # Unfinished, copy of UP for now try: print("Creating credential: " + cred_name) gmp.create_credential( - name=cred_name, - credential_type=gmp.types.CredentialType.USERNAME_SSH_KEY, - login=userName, - key_phrase=userPW, - private_key=key, - comment=comment, + name=cred_name, + credential_type=gmp.types.CredentialType.USERNAME_SSH_KEY, + login=userName, + key_phrase=userPW, + private_key=key, + comment=comment, ) numberCredentials = numberCredentials + 1 except GvmResponseError as gvmerr: print(f"{gvmerr=}, name: {cred_name}") pass - csvFile.close() #close the csv file + csvFile.close() # close the csv file except IOError as e: error_and_exit(f"Failed to read cred_file: {str(e)} (exit)") if len(row) == 0: error_and_exit("Credentials file is empty (exit)") - + return numberCredentials - + + def main(gmp: Gmp, args: Namespace) -> None: # pylint: disable=undefined-variable if args.script: @@ -191,9 +192,7 @@ def main(gmp: Gmp, args: Namespace) -> None: parsed_args = parse_args(args=args) - print( - "Creating credentials.\n" - ) + print("Creating credentials.\n") numberCredentials = create_credentials( gmp, diff --git a/scripts/create-cve-report-from-json.gmp.py b/scripts/create-cve-report-from-json.gmp.py index 73ef728a..a930754c 100644 --- a/scripts/create-cve-report-from-json.gmp.py +++ b/scripts/create-cve-report-from-json.gmp.py @@ -12,9 +12,8 @@ from cpe import CPE from gvm.protocols.gmp import Gmp -from lxml import etree as e - from gvmtools.helper import error_and_exit, generate_uuid +from lxml import etree as e HELP_TEXT = ( "This script creates a cve report from a JSON document.\n" diff --git a/scripts/create-dummy-data.gmp.py b/scripts/create-dummy-data.gmp.py index b7374d74..3d57c771 100644 --- a/scripts/create-dummy-data.gmp.py +++ b/scripts/create-dummy-data.gmp.py @@ -7,7 +7,6 @@ from random import choice from gvm.protocols.gmp import Gmp - from gvmtools.helper import generate_id diff --git a/scripts/create-filters-from-csv.gmp.py b/scripts/create-filters-from-csv.gmp.py index f9023d74..3263ee38 100755 --- a/scripts/create-filters-from-csv.gmp.py +++ b/scripts/create-filters-from-csv.gmp.py @@ -7,17 +7,14 @@ # # Run with gvm-script --gmp-username admin-user --gmp-password password socket create-filters-from-csv.gmp.py hostname-server filters.csv +import csv import sys import time -import csv - from argparse import ArgumentParser, Namespace, RawTextHelpFormatter from pathlib import Path -from typing import List -from gvm.errors import GvmResponseError +from gvm.errors import GvmResponseError from gvm.protocols.gmp import Gmp - from gvmtools.helper import error_and_exit HELP_TEXT = ( @@ -72,6 +69,7 @@ def parse_args(args: Namespace) -> Namespace: # pylint: disable=unused-argument script_args, _ = parser.parse_known_args(args) return script_args + def filter_id( gmp: Gmp, filter_name: str, @@ -81,100 +79,109 @@ def filter_id( filter_id = "" for filter in filters_xml: - name = "".join(filter.xpath("name/text()")) filter_id = filter.get("id") return filter_id -def create_filters( + +def create_filters( gmp: Gmp, filter_csv_file: Path, ): try: numberfilters = 0 with open(filter_csv_file, encoding="utf-8") as csvFile: - content = csv.reader(csvFile, delimiter=',') #read the data - for row in content: #loop through each row + content = csv.reader(csvFile, delimiter=",") # read the data + for row in content: # loop through each row if len(row) == 0: continue filterType = row[0] filterName = row[1] filterDescription = row[2] filterTerm = row[3] - filterNameFull = filterName + ":" + filterDescription + ":" + filterType + filterNameFull = ( + filterName + ":" + filterDescription + ":" + filterType + ) comment = f"Created: {time.strftime('%Y/%m/%d-%H:%M:%S')}" - filterResources = [] if filterType == "FAIL!": print(filterType.upper()) elif filterType.upper() == "ALERT": - resource_type=gmp.types.FilterType.ALERT + resource_type = gmp.types.FilterType.ALERT elif filterType.upper() == "ASSET": - resource_type=gmp.types.FilterType.ASSET + resource_type = gmp.types.FilterType.ASSET elif filterType.upper() == "CONFIG": - resource_type=gmp.types.FilterType.SCAN_CONFIG + resource_type = gmp.types.FilterType.SCAN_CONFIG elif filterType.upper() == "CREDENTIAL": - resource_type=gmp.types.FilterType.CREDENTIAL + resource_type = gmp.types.FilterType.CREDENTIAL elif filterType.upper() == "HOST": - resource_type=gmp.types.FilterType.HOST + resource_type = gmp.types.FilterType.HOST elif filterType.upper() == "SECINFO": - resource_type=gmp.types.FilterType.ALL_SECINFO + resource_type = gmp.types.FilterType.ALL_SECINFO elif filterType.upper() == "NOTE": - resource_type=gmp.types.FilterType.NOTE + resource_type = gmp.types.FilterType.NOTE elif filterType.upper() == "OS": - resource_type=gmp.types.FilterType.OPERATING_SYSTEM + resource_type = gmp.types.FilterType.OPERATING_SYSTEM elif filterType.upper() == "OVERRIDE": - resource_type=gmp.types.FilterType.OVERRIDE + resource_type = gmp.types.FilterType.OVERRIDE elif filterType.upper() == "PERMISSION": - resource_type=gmp.types.FilterType.PERMISSION + resource_type = gmp.types.FilterType.PERMISSION elif filterType.upper() == "PORT_LIST": - resource_type=gmp.types.FilterType.PORT_LIST + resource_type = gmp.types.FilterType.PORT_LIST elif filterType.upper() == "REPORT": - resource_type=gmp.types.FilterType.REPORT + resource_type = gmp.types.FilterType.REPORT elif filterType.upper() == "REPORT_FORMAT": - resource_type=gmp.types.FilterType.REPORT_FORMAT + resource_type = gmp.types.FilterType.REPORT_FORMAT elif filterType.upper() == "RESULT": - resource_type=gmp.types.FilterType.RESULT + resource_type = gmp.types.FilterType.RESULT elif filterType.upper() == "ROLE": - resource_type=gmp.types.FilterType.ROLE + resource_type = gmp.types.FilterType.ROLE elif filterType.upper() == "SCHEDULE": - resource_type=gmp.types.FilterType.SCHEDULE + resource_type = gmp.types.FilterType.SCHEDULE elif filterType.upper() == "TAG": - resource_type=gmp.types.FilterType.TAG + resource_type = gmp.types.FilterType.TAG elif filterType.upper() == "TARGET": - resource_type=gmp.types.FilterType.TARGET + resource_type = gmp.types.FilterType.TARGET elif filterType.upper() == "TASK": - resource_type=gmp.types.FilterType.TASK + resource_type = gmp.types.FilterType.TASK elif filterType.upper() == "TICKET": - resource_type=gmp.types.FilterType.TICKET + resource_type = gmp.types.FilterType.TICKET elif filterType.upper() == "TLS_CERTIFICATE": - resource_type=gmp.types.FilterType.TLS_CERTIFICATE + resource_type = gmp.types.FilterType.TLS_CERTIFICATE elif filterType.upper() == "USER": - resource_type=gmp.types.FilterType.USER + resource_type = gmp.types.FilterType.USER elif filterType.upper() == "VULNERABILITY": - resource_type=gmp.types.FilterType.VULNERABILITY - else: - print("FilterType: " + filterType.upper() + " Not supported") + resource_type = gmp.types.FilterType.VULNERABILITY + else: + print( + "FilterType: " + filterType.upper() + " Not supported" + ) try: if filter_id(gmp, filterNameFull): - print(f"Filter: {filterNameFull} exist, not creating...") + print( + f"Filter: {filterNameFull} exist, not creating..." + ) continue print("Creating filter: " + filterNameFull) gmp.create_filter( - name=filterNameFull, comment=comment, filter_type=resource_type, term=filterTerm, + name=filterNameFull, + comment=comment, + filter_type=resource_type, + term=filterTerm, ) numberfilters = numberfilters + 1 except GvmResponseError as gvmerr: print(f"{gvmerr=}, name: {filterNameFull}") pass - csvFile.close() #close the csv file + csvFile.close() # close the csv file except IOError as e: error_and_exit(f"Failed to read filter_csv_file: {str(e)} (exit)") if len(row) == 0: error_and_exit("filter file is empty (exit)") - + return numberfilters - + + def main(gmp: Gmp, args: Namespace) -> None: # pylint: disable=undefined-variable if args.script: @@ -182,9 +189,7 @@ def main(gmp: Gmp, args: Namespace) -> None: parsed_args = parse_args(args=args) - print( - "Creating filters.\n" - ) + print("Creating filters.\n") numberfilters = create_filters( gmp, diff --git a/scripts/create-report-format-from-csv.gmp.py b/scripts/create-report-format-from-csv.gmp.py index f3549ac0..5fa3c206 100755 --- a/scripts/create-report-format-from-csv.gmp.py +++ b/scripts/create-report-format-from-csv.gmp.py @@ -5,17 +5,12 @@ # Run with gvm-script --gmp-username admin-user --gmp-password password socket create-report_formats-from-csv.gmp.py report_formats.csv -import sys -import time import csv - +import sys from argparse import ArgumentParser, Namespace, RawTextHelpFormatter from pathlib import Path -from typing import List -from gvm.errors import GvmResponseError from gvm.protocols.gmp import Gmp - from gvmtools.helper import error_and_exit HELP_TEXT = ( @@ -71,77 +66,74 @@ def parse_args(args: Namespace) -> Namespace: # pylint: disable=unused-argument script_args, _ = parser.parse_known_args(args) return script_args -def create_report_formats( + +def create_report_formats( gmp: Gmp, cred_file: Path, ): try: numberreport_formats = 0 with open(cred_file, encoding="utf-8") as csvFile: - content = csv.reader(csvFile, delimiter=',') #read the data - for row in content: #loop through each row + content = csv.reader(csvFile, delimiter=",") # read the data + for row in content: # loop through each row numberreport_formats = numberreport_formats + 1 REPORT_FORMAT_XML_STRING = ( - '' - '' - "CSV vulnscan.dk" - 'name=CSV first=1 rows=10 sort=name' - '' - '' - 'name' - '=' - 'CSV' - '' - '' - 'first' - '=' - '1' - '' - '' - 'rows' - '=' - '10' - '' - '' - 'sort' - '=' - 'name' - '' - '' - 'csv' - 'text/csv' - "vulnscan.dk CSV Report Format. Version 2023-03-31." - "vulnscan.dk CSV Report Format" - 'Complete scan report in GMP XML format. Version 20200827.' - '1' - '0' - '1' - '1' - "2024-03-31T10:48:03Z" - "2024-03-31T10:48:03Z" - '' - '500' - "" - "" + '' + '' + "CSV vulnscan.dk" + "name=CSV first=1 rows=10 sort=name" + "" + "" + "name" + "=" + "CSV" + "" + "" + "first" + "=" + "1" + "" + "" + "rows" + "=" + "10" + "" + "" + "sort" + "=" + "name" + "" + "" + "csv" + "text/csv" + "vulnscan.dk CSV Report Format. Version 2023-03-31." + "vulnscan.dk CSV Report Format" + "Complete scan report in GMP XML format. Version 20200827." + "1" + "0" + "1" + "1" + "2024-03-31T10:48:03Z" + "2024-03-31T10:48:03Z" + '' + "500" + "" + "" ) - - rf_copy = "c1645568-627a-11e3-a660-406186ea4fc5" - comment = f"Created: {time.strftime('%Y/%m/%d-%H:%M:%S')}" - gmp.import_report_format( - REPORT_FORMAT_XML_STRING - ) + gmp.import_report_format(REPORT_FORMAT_XML_STRING) - csvFile.close() #close the csv file + csvFile.close() # close the csv file except IOError as e: error_and_exit(f"Failed to read cred_file: {str(e)} (exit)") if len(row) == 0: error_and_exit("report_formats file is empty (exit)") - + return numberreport_formats - + + def main(gmp: Gmp, args: Namespace) -> None: # pylint: disable=undefined-variable if args.script: diff --git a/scripts/create-schedules-from-csv.gmp.py b/scripts/create-schedules-from-csv.gmp.py index 593844e7..ddc07693 100755 --- a/scripts/create-schedules-from-csv.gmp.py +++ b/scripts/create-schedules-from-csv.gmp.py @@ -5,17 +5,14 @@ # Run with gvm-script --gmp-username admin-user --gmp-password password socket create-schedules-from-csv.gmp.py schedules.csv +import csv import sys import time -import csv - from argparse import ArgumentParser, Namespace, RawTextHelpFormatter from pathlib import Path -from typing import List -from gvm.errors import GvmResponseError +from gvm.errors import GvmResponseError from gvm.protocols.gmp import Gmp - from gvmtools.helper import error_and_exit HELP_TEXT = ( @@ -72,29 +69,31 @@ def parse_args(args: Namespace) -> Namespace: # pylint: disable=unused-argument script_args, _ = parser.parse_known_args(args) return script_args + def schedule_id( gmp: Gmp, schedule_name: str, ): - response_xml = gmp.get_schedules(filter_string="rows=-1, name=" + schedule_name) + response_xml = gmp.get_schedules( + filter_string="rows=-1, name=" + schedule_name + ) schedules_xml = response_xml.xpath("schedule") schedule_id = "" for schedule in schedules_xml: - name = "".join(schedule.xpath("name/text()")) schedule_id = schedule.get("id") return schedule_id -def create_schedules( +def create_schedules( gmp: Gmp, sched_file: Path, ): try: numberschedules = 0 with open(sched_file, encoding="utf-8") as csvFile: - content = csv.reader(csvFile, delimiter=',') #read the data - for row in content: #loop through each row + content = csv.reader(csvFile, delimiter=",") # read the data + for row in content: # loop through each row if len(row) == 0: continue sched_name = row[0] @@ -107,25 +106,26 @@ def create_schedules( continue print("Creating schedule: " + sched_name) gmp.create_schedule( - name=sched_name, - timezone=sched_tz, - icalendar=sched_ical, - comment=comment + name=sched_name, + timezone=sched_tz, + icalendar=sched_ical, + comment=comment, ) numberschedules = numberschedules + 1 except GvmResponseError as gvmerr: print(f"{gvmerr=}, name: {sched_name}") pass - csvFile.close() #close the csv file + csvFile.close() # close the csv file except IOError as e: error_and_exit(f"Failed to read sched_file: {str(e)} (exit)") if len(row) == 0: error_and_exit("schedules file is empty (exit)") - + return numberschedules - + + def main(gmp: Gmp, args: Namespace) -> None: # pylint: disable=undefined-variable if args.script: @@ -133,9 +133,7 @@ def main(gmp: Gmp, args: Namespace) -> None: parsed_args = parse_args(args=args) - print( - "Creating schedules.\n" - ) + print("Creating schedules.\n") numberschedules = create_schedules( gmp, diff --git a/scripts/create-tags-from-csv.gmp.py b/scripts/create-tags-from-csv.gmp.py index ed7a04c5..4d76dffb 100755 --- a/scripts/create-tags-from-csv.gmp.py +++ b/scripts/create-tags-from-csv.gmp.py @@ -5,16 +5,14 @@ # Run with gvm-script --gmp-username admin-user --gmp-password password socket create-tags-from-csv.gmp.py hostname-server tags.csv +import csv import sys import time -import csv - from argparse import ArgumentParser, Namespace, RawTextHelpFormatter from pathlib import Path -from typing import List -from gvm.protocols.gmp import Gmp from gvm.errors import GvmResponseError +from gvm.protocols.gmp import Gmp from gvmtools.helper import error_and_exit HELP_TEXT = ( @@ -69,19 +67,22 @@ def parse_args(args: Namespace) -> Namespace: # pylint: disable=unused-argument script_args, _ = parser.parse_known_args(args) return script_args + def config_id( gmp: Gmp, config_name: str, ): - response_xml = gmp.get_scan_configs(filter_string="rows=-1, name= " + config_name) + response_xml = gmp.get_scan_configs( + filter_string="rows=-1, name= " + config_name + ) scan_configs_xml = response_xml.xpath("config") config_id = "" for scan_config in scan_configs_xml: - name = "".join(scan_config.xpath("name/text()")) config_id = scan_config.get("id") return config_id + def alert_id( gmp: Gmp, alert_name: str, @@ -91,23 +92,25 @@ def alert_id( alert_id = "" for alert in alerts_xml: - name = "".join(alert.xpath("name/text()")) alert_id = alert.get("id") return alert_id + def credential_id( gmp: Gmp, credName: str, ): - response_xml = gmp.get_credentials(filter_string="rows=-1, name=" + credName) + response_xml = gmp.get_credentials( + filter_string="rows=-1, name=" + credName + ) credentials_xml = response_xml.xpath("credential") cred_id = "" for credential in credentials_xml: - name = "".join(credential.xpath("name/text()")) cred_id = credential.get("id") return cred_id + def target_id( gmp: Gmp, targetName: str, @@ -117,10 +120,10 @@ def target_id( target_id = "" for target in targets_xml: - name = "".join(target.xpath("name/text()")) target_id = target.get("id") return target_id + def task_id( gmp: Gmp, taskName: str, @@ -130,10 +133,10 @@ def task_id( task_id = "" for task in tasks_xml: - name = "".join(task.xpath("name/text()")) task_id = task.get("id") return task_id + def tag_id( gmp: Gmp, tagName: str, @@ -143,45 +146,49 @@ def tag_id( tag_id = "" for tag in tags_xml: - name = "".join(tag.xpath("name/text()")) tag_id = tag.get("id") return tag_id + def scanner_id( gmp: Gmp, scanner_name: str, ): - response_xml = gmp.get_scanners(filter_string="rows=-1, name=" + scanner_name) + response_xml = gmp.get_scanners( + filter_string="rows=-1, name=" + scanner_name + ) scanners_xml = response_xml.xpath("scanner") scanner_id = "" for scanner in scanners_xml: - name = "".join(scanner.xpath("name/text()")) scanner_id = scanner.get("id") return scanner_id + def schedule_id( gmp: Gmp, schedule_name: str, ): - response_xml = gmp.get_schedules(filter_string="rows=-1, name=" + schedule_name) + response_xml = gmp.get_schedules( + filter_string="rows=-1, name=" + schedule_name + ) schedules_xml = response_xml.xpath("schedule") schedule_id = "" for schedule in schedules_xml: - name = "".join(schedule.xpath("name/text()")) schedule_id = schedule.get("id") return schedule_id -def create_tags( + +def create_tags( gmp: Gmp, tag_csv_file: Path, ): try: numbertags = 0 with open(tag_csv_file, encoding="utf-8") as csvFile: - content = csv.reader(csvFile, delimiter=',') #read the data - for row in content: #loop through each row + content = csv.reader(csvFile, delimiter=",") # read the data + for row in content: # loop through each row if len(row) == 0: continue tagType = row[0] @@ -196,62 +203,64 @@ def create_tags( if tagType.upper() == "FAIL!": print("Failed!") elif tagType.upper() == "ALERT": - getUUID=alert_id - resource_type=gmp.types.EntityType.ALERT + getUUID = alert_id + resource_type = gmp.types.EntityType.ALERT elif tagType.upper() == "CONFIG": - getUUID=config_id - resource_type=gmp.types.EntityType.SCAN_CONFIG + getUUID = config_id + resource_type = gmp.types.EntityType.SCAN_CONFIG elif tagType.upper() == "CREDENTIAL": - getUUID=credential_id - resource_type=gmp.types.EntityType.CREDENTIAL + getUUID = credential_id + resource_type = gmp.types.EntityType.CREDENTIAL elif tagType.upper() == "REPORT": filter = "~" + tagName - resource_type=gmp.types.EntityType.REPORT + resource_type = gmp.types.EntityType.REPORT elif tagType.upper() == "SCANNER": - getUUID=scanner_id - resource_type=gmp.types.EntityType.SCANNER + getUUID = scanner_id + resource_type = gmp.types.EntityType.SCANNER elif tagType.upper() == "SCHEDULE": - getUUID=schedule_id - resource_type=gmp.types.EntityType.SCHEDULE + getUUID = schedule_id + resource_type = gmp.types.EntityType.SCHEDULE elif tagType.upper() == "TARGET": - getUUID=target_id - resource_type=gmp.types.EntityType.TARGET + getUUID = target_id + resource_type = gmp.types.EntityType.TARGET elif tagType.upper() == "TASK": - getUUID=task_id - resource_type=gmp.types.EntityType.TASK + getUUID = task_id + resource_type = gmp.types.EntityType.TASK else: - print("Only alert, config, credential, report, scanner, schedule, target, and task supported") + print( + "Only alert, config, credential, report, scanner, schedule, target, and task supported" + ) exit() - + if len(row[3]) >= 1: - tagResource = (getUUID(gmp, row[3])) - tagResources.append(tagResource) + tagResource = getUUID(gmp, row[3]) + tagResources.append(tagResource) if len(row[4]) >= 1: - tagResource = (getUUID(gmp, row[4])) - tagResources.append(tagResource) - if len (row[5]) >= 1: - tagResource = (getUUID(gmp, row[5])) + tagResource = getUUID(gmp, row[4]) + tagResources.append(tagResource) + if len(row[5]) >= 1: + tagResource = getUUID(gmp, row[5]) tagResources.append(tagResource) if len(row[6]) >= 1: - tagResource = (getUUID(gmp, row[6])) + tagResource = getUUID(gmp, row[6]) tagResources.append(tagResource) if len(row[7]) >= 1: - tagResource = (getUUID(gmp, row[7])) + tagResource = getUUID(gmp, row[7]) tagResources.append(tagResource) - if len (row[8]) >= 1: - tagResource = (getUUID(gmp, row[8])) + if len(row[8]) >= 1: + tagResource = getUUID(gmp, row[8]) tagResources.append(tagResource) if len(row[9]) >= 1: - tagResource = (getUUID(gmp, row[9])) + tagResource = getUUID(gmp, row[9]) tagResources.append(tagResource) - tagResource = (getUUID(gmp, row[10])) + tagResource = getUUID(gmp, row[10]) if len(row[10]) >= 1: tagResources.append(tagResource) if len(row[11]) >= 1: - tagResource = (getUUID(gmp, row[11])) + tagResource = getUUID(gmp, row[11]) tagResources.append(tagResource) if len(row[12]) >= 1: - tagResource = (getUUID(gmp, row[12])) + tagResource = getUUID(gmp, row[12]) tagResources.append(tagResource) comment = f"Created: {time.strftime('%Y/%m/%d-%H:%M:%S')}" @@ -259,7 +268,11 @@ def create_tags( try: print("Creating tag: " + tagNameFull) gmp.create_tag( - name=tagNameFull, comment=comment, value=tagName, resource_type=resource_type, resource_filter=filter, + name=tagNameFull, + comment=comment, + value=tagName, + resource_type=resource_type, + resource_filter=filter, ) numbertags = numbertags + 1 except GvmResponseError as gvmerr: @@ -269,21 +282,26 @@ def create_tags( try: print("Creating tag: " + tagNameFull) gmp.create_tag( - name=tagNameFull, comment=comment, value=tagName, resource_type=resource_type, resource_ids=tagResources, + name=tagNameFull, + comment=comment, + value=tagName, + resource_type=resource_type, + resource_ids=tagResources, ) numbertags = numbertags + 1 except GvmResponseError as gvmerr: print(f"{gvmerr=}, name: {tagNameFull}") pass - csvFile.close() #close the csv file + csvFile.close() # close the csv file except IOError as e: error_and_exit(f"Failed to read tag_csv_file: {str(e)} (exit)") if len(row) == 0: error_and_exit("tag file is empty (exit)") - + return numbertags - + + def main(gmp: Gmp, args: Namespace) -> None: # pylint: disable=undefined-variable if args.script: @@ -291,9 +309,7 @@ def main(gmp: Gmp, args: Namespace) -> None: parsed_args = parse_args(args=args) - print( - "Creating tags.\n" - ) + print("Creating tags.\n") numbertags = create_tags( gmp, diff --git a/scripts/create-targets-from-csv.gmp.py b/scripts/create-targets-from-csv.gmp.py index 3028e858..b8d310e1 100755 --- a/scripts/create-targets-from-csv.gmp.py +++ b/scripts/create-targets-from-csv.gmp.py @@ -5,13 +5,12 @@ # Run with gvm-script --gmp-username admin-user --gmp-password password socket create-targets-from-csv.gmp.py hostname-server targets.csv +import csv import sys import time -import csv - from argparse import ArgumentParser, Namespace, RawTextHelpFormatter from pathlib import Path -from typing import List + from gvm.errors import GvmResponseError from gvm.protocols.gmp import Gmp from gvmtools.helper import error_and_exit @@ -88,7 +87,7 @@ def parse_args(args: Namespace) -> Namespace: # pylint: disable=unused-argument port_list_id="730ef368-57e2-11e1-a90f-406186ea4fc5" ) # All TCP and Nmap top 100 UDP # Default portlists see also script list-portlists.gmp.py - # | Name | ID + # | Name | ID # - | ----------------------------- | ------------------------------------ # 1 | All IANA assigned TCP | 33d0cd82-57c6-11e1-8ed1-406186ea4fc5 # 2 | All IANA assigned TCP and UDP | 4a4717fe-57d2-11e1-9a26-406186ea4fc5 @@ -97,19 +96,22 @@ def parse_args(args: Namespace) -> Namespace: # pylint: disable=unused-argument script_args, _ = parser.parse_known_args(args) return script_args + def credential_id( gmp: Gmp, credName: str, ): - response_xml = gmp.get_credentials(filter_string="rows=-1, name=" + credName) + response_xml = gmp.get_credentials( + filter_string="rows=-1, name=" + credName + ) credentials_xml = response_xml.xpath("credential") cred_id = "" for credential in credentials_xml: - name = "".join(credential.xpath("name/text()")) cred_id = credential.get("id") return cred_id + def target_id( gmp: Gmp, targetName: str, @@ -119,11 +121,11 @@ def target_id( target_id = "" for target in targets_xml: - name = "".join(target.xpath("name/text()")) target_id = target.get("id") return target_id -def create_targets( + +def create_targets( gmp: Gmp, target_csv_file: Path, port_list_id: str, @@ -131,22 +133,18 @@ def create_targets( try: numberTargets = 0 with open(target_csv_file, encoding="utf-8") as csvFile: - content = csv.reader(csvFile, delimiter=',') #read the data - for row in content: #loop through each row + content = csv.reader(csvFile, delimiter=",") # read the data + for row in content: # loop through each row if len(row) == 0: continue name = row[0] hosts = [row[1]] smbCred = credential_id(gmp, row[2]) sshCred = credential_id(gmp, row[3]) - snmpCred = credential_id(gmp, row[4]) - esxCred = credential_id(gmp, row[5]) aliveTest = row[6] if not aliveTest: - aliveTest = "Scan Config Default" - alive_test = gmp.types.AliveTest( - (aliveTest) - ) + aliveTest = "Scan Config Default" + alive_test = gmp.types.AliveTest((aliveTest)) comment = f"Created: {time.strftime('%Y/%m/%d-%H:%M:%S')}" try: if target_id(gmp, name): @@ -155,37 +153,40 @@ def create_targets( print("Creating target: " + name) gmp.create_target( - name=name, comment=comment, hosts=hosts, port_list_id=port_list_id, smb_credential_id=smbCred, ssh_credential_id=sshCred, alive_test=alive_test + name=name, + comment=comment, + hosts=hosts, + port_list_id=port_list_id, + smb_credential_id=smbCred, + ssh_credential_id=sshCred, + alive_test=alive_test, ) numberTargets = numberTargets + 1 except GvmResponseError as gvmerr: print(f"{gvmerr=}, name: {name}") pass - csvFile.close() #close the csv file + csvFile.close() # close the csv file except IOError as e: error_and_exit(f"Failed to read target_csv_file: {str(e)} (exit)") if len(row) == 0: error_and_exit("Host file is empty (exit)") - + return numberTargets - + + def main(gmp: Gmp, args: Namespace) -> None: # pylint: disable=undefined-variable if args.script: args = args.script[1:] parsed_args = parse_args(args=args) - #port_list_id="4a4717fe-57d2-11e1-9a26-406186ea4fc5" + # port_list_id="4a4717fe-57d2-11e1-9a26-406186ea4fc5" + + print("Creating targets.\n") - print( - "Creating targets.\n" - ) - numberTargets = create_targets( - gmp, - parsed_args.targets_csv_file, - parsed_args.port_list_id + gmp, parsed_args.targets_csv_file, parsed_args.port_list_id ) numberTargets = str(numberTargets) diff --git a/scripts/create-targets-from-host-list.gmp.py b/scripts/create-targets-from-host-list.gmp.py index f6217277..9533194e 100644 --- a/scripts/create-targets-from-host-list.gmp.py +++ b/scripts/create-targets-from-host-list.gmp.py @@ -9,7 +9,6 @@ from typing import List from gvm.protocols.gmp import Gmp - from gvmtools.helper import error_and_exit HELP_TEXT = ( @@ -26,7 +25,7 @@ def check_args(args): for each. One parameter after the script name is required. - 1. -- IP of the GVM host + 1. -- IP of the GVM host 2. -- text file containing hostnames Example: diff --git a/scripts/create-tasks-from-csv.gmp.py b/scripts/create-tasks-from-csv.gmp.py index 840554e7..80bf2096 100755 --- a/scripts/create-tasks-from-csv.gmp.py +++ b/scripts/create-tasks-from-csv.gmp.py @@ -10,16 +10,14 @@ # Note: for some weird reason theres a space in front of the default scan config " Full and fast" # Examples of all defaults in tasks.csv +import csv import sys import time -import csv - from argparse import ArgumentParser, Namespace, RawTextHelpFormatter from pathlib import Path -from typing import List -from gvm.protocols.gmpv208.entities.hosts import HostsOrdering #Only available in version 20.8 -from gvm.protocols.gmp import Gmp + from gvm.errors import GvmResponseError +from gvm.protocols.gmp import Gmp from gvmtools.helper import error_and_exit HELP_TEXT = ( @@ -94,7 +92,7 @@ def parse_args(args: Namespace) -> Namespace: # pylint: disable=unused-argument port_list_id="730ef368-57e2-11e1-a90f-406186ea4fc5" ) # All IANA assigned TCP and Top 100 UDP, use the list-portlists.gmp.py script to get the UUID for all. # Defaults are - # # | Name | ID + # # | Name | ID # - | ----------------------------- | ------------------------------------ # 1 | All IANA assigned TCP | 33d0cd82-57c6-11e1-8ed1-406186ea4fc5 # 2 | All IANA assigned TCP and UDP | 4a4717fe-57d2-11e1-9a26-406186ea4fc5 @@ -103,20 +101,22 @@ def parse_args(args: Namespace) -> Namespace: # pylint: disable=unused-argument script_args, _ = parser.parse_known_args(args) return script_args + def config_id( gmp: Gmp, config_name: str, ): - response_xml = gmp.get_scan_configs(filter_string="rows=-1, name= " + config_name -) + response_xml = gmp.get_scan_configs( + filter_string="rows=-1, name= " + config_name + ) scan_configs_xml = response_xml.xpath("config") config_id = "" for scan_config in scan_configs_xml: - name = "".join(scan_config.xpath("name/text()")) config_id = scan_config.get("id") return config_id + def alert_id( gmp: Gmp, alert_name: str, @@ -126,10 +126,10 @@ def alert_id( alert_id = "" for alert in alerts_xml: - name = "".join(alert.xpath("name/text()")) alert_id = alert.get("id") return alert_id + def target_id( gmp: Gmp, target_name: str, @@ -139,36 +139,40 @@ def target_id( target_id = "" for target in targets_xml: - name = "".join(target.xpath("name/text()")) target_id = target.get("id") return target_id + def scanner_id( gmp: Gmp, scanner_name: str, ): - response_xml = gmp.get_scanners(filter_string="rows=-1, name=" + scanner_name) + response_xml = gmp.get_scanners( + filter_string="rows=-1, name=" + scanner_name + ) scanners_xml = response_xml.xpath("scanner") scanner_id = "" for scanner in scanners_xml: - name = "".join(scanner.xpath("name/text()")) scanner_id = scanner.get("id") return scanner_id + def schedule_id( gmp: Gmp, schedule_name: str, ): - response_xml = gmp.get_schedules(filter_string="rows=-1, name=" + schedule_name) + response_xml = gmp.get_schedules( + filter_string="rows=-1, name=" + schedule_name + ) schedules_xml = response_xml.xpath("schedule") schedule_id = "" for schedule in schedules_xml: - name = "".join(schedule.xpath("name/text()")) schedule_id = schedule.get("id") return schedule_id + def task_id( gmp: Gmp, taskName: str, @@ -178,11 +182,11 @@ def task_id( task_id = "" for task in tasks_xml: - name = "".join(task.xpath("name/text()")) task_id = task.get("id") return task_id -def create_tasks( + +def create_tasks( gmp: Gmp, task_csv_file: Path, port_list_id: str, @@ -190,8 +194,8 @@ def create_tasks( try: numberTasks = 0 with open(task_csv_file, encoding="utf-8") as csvFile: - content = csv.reader(csvFile, delimiter=',') #read the data - for row in content: #loop through each row + content = csv.reader(csvFile, delimiter=",") # read the data + for row in content: # loop through each row if len(row) == 0: continue name = row[0] @@ -203,13 +207,13 @@ def create_tasks( newOrder = row[5].upper() if newOrder == "RANDOM": - order = HostsOrdering.RANDOM + order = gmp.types.HostsOrdering.RANDOM elif newOrder == "SEQUENTIAL": - order = HostsOrdering.SEQUENTIAL + order = gmp.types.HostsOrdering.SEQUENTIAL elif newOrder == "REVERSE": - order = HostsOrdering.REVERSE + order = gmp.types.HostsOrdering.REVERSE else: - order = HostsOrdering.RANDOM + order = gmp.types.HostsOrdering.RANDOM alerts = [] if len(row[6]) > 1: @@ -218,7 +222,7 @@ def create_tasks( if len(row[7]) > 1: alert = alert_id(gmp, row[7]) alerts.append(alert) - if len (row[8]) > 1: + if len(row[8]) > 1: alert = alert_id(gmp, row[8]) alerts.append(alert) if len(row[9]) > 1: @@ -228,47 +232,52 @@ def create_tasks( alert = alert_id(gmp, row[10]) alerts.append(alert) - scanOrder = order # Use SEQUENTIAL, REVERSE, or RANDOM + scanOrder = order # Use SEQUENTIAL, REVERSE, or RANDOM comment = f"Created: {time.strftime('%Y/%m/%d-%H:%M:%S')}" - + try: if task_id(gmp, name): print(f"Task: {name} exist already") continue print("Creating task: " + name) gmp.create_task( - name=name, comment=comment, config_id=configId, target_id=targetId, hosts_ordering=scanOrder, scanner_id=scannerId, alterable=alterable, schedule_id=scheduleId, alert_ids=alerts + name=name, + comment=comment, + config_id=configId, + target_id=targetId, + hosts_ordering=scanOrder, + scanner_id=scannerId, + alterable=alterable, + schedule_id=scheduleId, + alert_ids=alerts, ) numberTasks = numberTasks + 1 except GvmResponseError as gvmerr: print(f"{gvmerr=}, name: {name}") pass - csvFile.close() #close the csv file + csvFile.close() # close the csv file except IOError as e: error_and_exit(f"Failed to read task_csv_file: {str(e)} (exit)") if len(row) == 0: error_and_exit("Host file is empty (exit)") - + return numberTasks - + + def main(gmp: Gmp, args: Namespace) -> None: # pylint: disable=undefined-variable if args.script: args = args.script[1:] parsed_args = parse_args(args=args) - #port_list_id="4a4717fe-57d2-11e1-9a26-406186ea4fc5" + # port_list_id="4a4717fe-57d2-11e1-9a26-406186ea4fc5" - print( - "Creating tasks\n" - ) + print("Creating tasks\n") numberTasks = create_tasks( - gmp, - parsed_args.tasks_csv_file, - parsed_args.port_list_id + gmp, parsed_args.tasks_csv_file, parsed_args.port_list_id ) numberTasks = str(numberTasks) diff --git a/scripts/empty-trash.gmp.py b/scripts/empty-trash.gmp.py index 492da539..6c4b8b41 100755 --- a/scripts/empty-trash.gmp.py +++ b/scripts/empty-trash.gmp.py @@ -6,21 +6,17 @@ from gvm.protocols.gmp import Gmp -from gvmtools.helper import Table - - def main(gmp: Gmp, args: Namespace) -> None: - print( - "Emptying Trash...\n" - ) + print("Emptying Trash...\n") try: status_text = gmp.empty_trashcan().xpath("@status_text")[0] print(status_text) - except: - pass + except Exception as e: + print(f"{e=}") + if __name__ == "__gmp__": main(gmp, args) diff --git a/scripts/export-csv-report.gmp.py b/scripts/export-csv-report.gmp.py index f906754a..a1377619 100755 --- a/scripts/export-csv-report.gmp.py +++ b/scripts/export-csv-report.gmp.py @@ -5,9 +5,11 @@ # Based on the export-pdf-report script and modified to # create csv and return more (all) details. +import sys +from argparse import Namespace from base64 import b64decode from pathlib import Path -from argparse import Namespace + from gvm.protocols.gmp import Gmp @@ -15,11 +17,11 @@ def check_args(args): len_args = len(args.script) - 1 if len_args < 1: message = """ - This script requests the given report and exports it as a csv + This script requests the given report and exports it as a csv file locally. It requires one parameter after the script name. 1. -- ID of the report - + Optional a file name to save the csv in. Examples: @@ -45,7 +47,10 @@ def main(gmp: Gmp, args: Namespace) -> None: csv_report_format_id = "c1645568-627a-11e3-a660-406186ea4fc5" response = gmp.get_report( - report_id=report_id, report_format_id=csv_report_format_id, ignore_pagination=True, details=True + report_id=report_id, + report_format_id=csv_report_format_id, + ignore_pagination=True, + details=True, ) report_element = response.find("report") @@ -54,15 +59,15 @@ def main(gmp: Gmp, args: Namespace) -> None: if not content: print( - 'Requested report is empty. Either the report does not contain any ' - ' results or the necessary tools for creating the report are ' - 'not installed.', + "Requested report is empty. Either the report does not contain any " + " results or the necessary tools for creating the report are " + "not installed.", file=sys.stderr, ) sys.exit(1) # convert content to 8-bit ASCII bytes - binary_base64_encoded_csv = content.encode('ascii') + binary_base64_encoded_csv = content.encode("ascii") # decode base64 binary_csv = b64decode(binary_base64_encoded_csv) @@ -72,9 +77,8 @@ def main(gmp: Gmp, args: Namespace) -> None: csv_path.write_bytes(binary_csv) - print('Done. CSV created: ' + str(csv_path)) + print("Done. CSV created: " + str(csv_path)) -if __name__ == '__gmp__': +if __name__ == "__gmp__": main(gmp, args) - diff --git a/scripts/export-pdf-report.gmp.py b/scripts/export-pdf-report.gmp.py index f18a3f9b..3e45db98 100644 --- a/scripts/export-pdf-report.gmp.py +++ b/scripts/export-pdf-report.gmp.py @@ -15,11 +15,11 @@ def check_args(args): len_args = len(args.script) - 1 if len_args < 1: message = """ - This script requests the given report and exports it as a pdf + This script requests the given report and exports it as a pdf file locally. It requires one parameters after the script name. 1. -- ID of the report - + Optional a file name to save the pdf in. Example: @@ -44,7 +44,10 @@ def main(gmp: Gmp, args: Namespace) -> None: pdf_report_format_id = "c402cc3e-b531-11e1-9163-406186ea4fc5" response = gmp.get_report( - report_id=report_id, report_format_id=pdf_report_format_id, ignore_pagination=True, details=True + report_id=report_id, + report_format_id=pdf_report_format_id, + ignore_pagination=True, + details=True, ) report_element = response.find("report") diff --git a/scripts/export-xml-report.gmp.py b/scripts/export-xml-report.gmp.py index b6cd3fd2..aab6ab9e 100755 --- a/scripts/export-xml-report.gmp.py +++ b/scripts/export-xml-report.gmp.py @@ -8,18 +8,18 @@ from pathlib import Path from gvm.protocols.gmp import Gmp - from gvm.xml import pretty_print + def check_args(args): len_args = len(args.script) - 1 if len_args < 1: message = """ - This script requests the given report and exports it as a xml + This script requests the given report and exports it as a xml file locally. It requires one parameters after the script name. 1. -- ID of the report - + Optional a file name to save the xml in. Example: @@ -44,11 +44,14 @@ def main(gmp: Gmp, args: Namespace) -> None: xml_report_format_id = "5057e5cc-b825-11e4-9d0e-28d24461215b" response = gmp.get_report( - report_id=report_id, report_format_id=xml_report_format_id, ignore_pagination=True, details=True + report_id=report_id, + report_format_id=xml_report_format_id, + ignore_pagination=True, + details=True, ) report_element = response.find("report") - data = pretty_print(report_element) + pretty_print(report_element) # get the full content of the report element content = report_element.find("report_format").tail @@ -70,7 +73,7 @@ def main(gmp: Gmp, args: Namespace) -> None: # write to file and support ~ in filename path xml_path = Path(xml_filename).expanduser() - xml_path.write_bytes(data) + xml_path.write_bytes(binary_xml) print("Done. xml created: " + str(xml_path)) diff --git a/scripts/generate-random-reports.gmp.py b/scripts/generate-random-reports.gmp.py index acc81014..82f6b6ee 100755 --- a/scripts/generate-random-reports.gmp.py +++ b/scripts/generate-random-reports.gmp.py @@ -5,14 +5,13 @@ import json import textwrap from argparse import ArgumentParser, Namespace, RawTextHelpFormatter +from datetime import datetime, timedelta from pathlib import Path from random import choice, gauss, randrange, seed -from datetime import datetime, timedelta from gvm.protocols.gmp import Gmp -from lxml import etree as e - from gvmtools.helper import generate_id, generate_random_ips, generate_uuid +from lxml import etree as e __version__ = "0.3.1" diff --git a/scripts/generate-random-targets.gmp.py b/scripts/generate-random-targets.gmp.py index 165a1269..482a50c9 100644 --- a/scripts/generate-random-targets.gmp.py +++ b/scripts/generate-random-targets.gmp.py @@ -7,7 +7,6 @@ from random import choice, gauss from gvm.protocols.gmp import Gmp - from gvmtools.helper import generate_random_ips diff --git a/scripts/list-alerts.gmp.py b/scripts/list-alerts.gmp.py index 950da1eb..b7f194c9 100755 --- a/scripts/list-alerts.gmp.py +++ b/scripts/list-alerts.gmp.py @@ -5,7 +5,6 @@ from argparse import Namespace from gvm.protocols.gmp import Gmp - from gvmtools.helper import Table @@ -15,14 +14,21 @@ def main(gmp: Gmp, args: Namespace) -> None: response_xml = gmp.get_alerts(filter_string="rows=-1") alerts_xml = response_xml.xpath("alert") - heading = ["#", "Name", "Id", "Event", "Event type", "Method", "Condition", "In use"] + heading = [ + "#", + "Name", + "Id", + "Event", + "Event type", + "Method", + "Condition", + "In use", + ] rows = [] numberRows = 0 - print( - "Listing alerts.\n" - ) + print("Listing alerts.\n") for alert in alerts_xml: # Count number of reports @@ -42,7 +48,18 @@ def main(gmp: Gmp, args: Namespace) -> None: else: alert_inuse = "No" - rows.append([rowNumber, name, alert_id, alert_event, alert_event_type, alert_method, alert_condition, alert_inuse]) + rows.append( + [ + rowNumber, + name, + alert_id, + alert_event, + alert_event_type, + alert_method, + alert_condition, + alert_inuse, + ] + ) print(Table(heading=heading, rows=rows)) diff --git a/scripts/list-credentials.gmp.py b/scripts/list-credentials.gmp.py index 8bd4f719..9988fbd1 100755 --- a/scripts/list-credentials.gmp.py +++ b/scripts/list-credentials.gmp.py @@ -5,7 +5,6 @@ from argparse import Namespace from gvm.protocols.gmp import Gmp - from gvmtools.helper import Table @@ -20,9 +19,7 @@ def main(gmp: Gmp, args: Namespace) -> None: rows = [] numberRows = 0 - print( - "Listing credentials.\n" - ) + print("Listing credentials.\n") for credential in credentials_xml: # Count number of reports @@ -51,7 +48,9 @@ def main(gmp: Gmp, args: Namespace) -> None: else: cred_insecureuse = "No" - rows.append([rowNumber, credential_id, name, cred_type, cred_insecureuse]) + rows.append( + [rowNumber, credential_id, name, cred_type, cred_insecureuse] + ) print(Table(heading=heading, rows=rows)) diff --git a/scripts/list-feeds.gmp.py b/scripts/list-feeds.gmp.py index bd17355b..adffa24a 100755 --- a/scripts/list-feeds.gmp.py +++ b/scripts/list-feeds.gmp.py @@ -5,24 +5,22 @@ from argparse import Namespace from gvm.protocols.gmp import Gmp - from gvmtools.helper import Table -#from gvm.xml import pretty_print +# from gvm.xml import pretty_print + def main(gmp: Gmp, args: Namespace) -> None: # pylint: disable=unused-argument response_xml = gmp.get_feeds() feeds_xml = response_xml.xpath("feed") - heading = ["#", "Name", "Version", "Status"] + heading = ["#", "Name", "Version", "Type", "Status"] rows = [] numberRows = 0 -# pretty_print(feeds_xml) + # pretty_print(feeds_xml) - print( - "Listing feeds and their status.\n" - ) + print("Listing feeds and their status.\n") for feed in feeds_xml: # Count number of reports @@ -31,15 +29,14 @@ def main(gmp: Gmp, args: Namespace) -> None: rowNumber = str(numberRows) name = "".join(feed.xpath("name/text()")) version = "".join(feed.xpath("version/text()")) - type = "".join(feed.xpath("type/text()")) + feed_type = "".join(feed.xpath("type/text()")) status = "".join(feed.xpath("currently_syncing/timestamp/text()")) if not status: status = "Up-to-date..." else: status = "Update in progress..." - - rows.append([rowNumber, name, version, status]) + rows.append([rowNumber, name, version, feed_type, status]) print(Table(heading=heading, rows=rows)) diff --git a/scripts/list-filters.gmp.py b/scripts/list-filters.gmp.py index 9cf15387..7bae83d4 100755 --- a/scripts/list-filters.gmp.py +++ b/scripts/list-filters.gmp.py @@ -5,7 +5,6 @@ from argparse import Namespace from gvm.protocols.gmp import Gmp - from gvmtools.helper import Table @@ -20,9 +19,7 @@ def main(gmp: Gmp, args: Namespace) -> None: rows = [] numberRows = 0 - print( - "Listing filters.\n" - ) + print("Listing filters.\n") for filter in filters_xml: # Count number of reports diff --git a/scripts/list-groups.gmp.py b/scripts/list-groups.gmp.py index 3b327b40..d52954ba 100755 --- a/scripts/list-groups.gmp.py +++ b/scripts/list-groups.gmp.py @@ -5,7 +5,6 @@ from argparse import Namespace from gvm.protocols.gmp import Gmp - from gvmtools.helper import Table @@ -20,9 +19,7 @@ def main(gmp: Gmp, args: Namespace) -> None: rows = [] numberRows = 0 - print( - "Listing groups.\n" - ) + print("Listing groups.\n") for group in groups_xml: # Count number of reports diff --git a/scripts/list-policies.gmp.py b/scripts/list-policies.gmp.py index 5f65b4e4..7aa03e92 100755 --- a/scripts/list-policies.gmp.py +++ b/scripts/list-policies.gmp.py @@ -5,7 +5,6 @@ from argparse import Namespace from gvm.protocols.gmp import Gmp - from gvmtools.helper import Table @@ -20,9 +19,7 @@ def main(gmp: Gmp, args: Namespace) -> None: rows = [] numberRows = 0 - print( - "Listing compliance policies.\n" - ) + print("Listing compliance policies.\n") for policy in policies_xml: # Count number of reports diff --git a/scripts/list-portlists.gmp.py b/scripts/list-portlists.gmp.py index e90e60fd..0733833c 100755 --- a/scripts/list-portlists.gmp.py +++ b/scripts/list-portlists.gmp.py @@ -5,7 +5,6 @@ from argparse import Namespace from gvm.protocols.gmp import Gmp - from gvmtools.helper import Table @@ -20,9 +19,7 @@ def main(gmp: Gmp, args: Namespace) -> None: rows = [] numberRows = 0 - print( - "Listing portlists.\n" - ) + print("Listing portlists.\n") for portlist in portlists_xml: # Count number of reports @@ -36,7 +33,9 @@ def main(gmp: Gmp, args: Namespace) -> None: port_tcp = "".join(portlist.xpath("port_count/tcp/text()")) port_udp = "".join(portlist.xpath("port_count/udp/text()")) - rows.append([rowNumber, name, port_list_id, port_all, port_tcp, port_udp]) + rows.append( + [rowNumber, name, port_list_id, port_all, port_tcp, port_udp] + ) print(Table(heading=heading, rows=rows)) diff --git a/scripts/list-report-formats.gmp.py b/scripts/list-report-formats.gmp.py index bc2f285b..b2fb62ad 100755 --- a/scripts/list-report-formats.gmp.py +++ b/scripts/list-report-formats.gmp.py @@ -5,7 +5,6 @@ from argparse import Namespace from gvm.protocols.gmp import Gmp - from gvmtools.helper import Table @@ -18,9 +17,7 @@ def main(gmp: Gmp, args: Namespace) -> None: rows = [] numberRows = 0 - print( - "Listing report formats.\n" - ) + print("Listing report formats.\n") for report_format in report_formats_xml: # Count number of reports @@ -30,7 +27,6 @@ def main(gmp: Gmp, args: Namespace) -> None: name = "".join(report_format.xpath("name/text()")) report_format_id = report_format.get("id") report_format_summary = "".join(report_format.xpath("summary/text()")) - report_format_description = "".join(report_format.xpath("description/text()")) rows.append([rowNumber, name, report_format_id, report_format_summary]) diff --git a/scripts/list-reports.gmp.py b/scripts/list-reports.gmp.py index 015eddd7..32c8c853 100755 --- a/scripts/list-reports.gmp.py +++ b/scripts/list-reports.gmp.py @@ -2,12 +2,12 @@ # # SPDX-License-Identifier: GPL-3.0-or-later -from gvm.protocols.gmp import Gmp +import sys +from argparse import ArgumentParser, Namespace, RawTextHelpFormatter +from gvm.protocols.gmp import Gmp from gvmtools.helper import Table -from argparse import ArgumentParser, Namespace, RawTextHelpFormatter - HELP_TEXT = ( "This script list reports with the status " "defined on the commandline. Status can be: \n" @@ -31,7 +31,8 @@ def check_args(args): """ print(message) sys.exit() - + + def parse_args(args: Namespace) -> Namespace: # pylint: disable=unused-argument """Parsing args ...""" @@ -52,12 +53,15 @@ def parse_args(args: Namespace) -> Namespace: # pylint: disable=unused-argument parser.add_argument( "status_cmd", type=str, - help=("Status: \"All\", \"Queued\", \"Requested\", \"Interrupted\", \"Running\", \"Stop Requested\", \"Stopped\" or \"Done\""), + help=( + 'Status: "All", "Queued", "Requested", "Interrupted", "Running", "Stop Requested", "Stopped" or "Done"' + ), ) script_args, _ = parser.parse_known_args(args) return script_args -def list_reports ( + +def list_reports( gmp: Gmp, status: str, ): @@ -81,17 +85,33 @@ def list_reports ( elif status.upper() == "STOPPED": str_status = "Stopped" else: - str_status="All" + str_status = "All" print("Reports with status: " + str_status + "\n") if str_status == "All": - response_xml = gmp.get_reports(ignore_pagination=True, details=True, filter_string="rows=-1") + response_xml = gmp.get_reports( + ignore_pagination=True, details=True, filter_string="rows=-1" + ) else: - response_xml = gmp.get_reports(ignore_pagination=True, details=True, filter_string="status=" + str_status + " and sort-reverse=name and rows=-1") + response_xml = gmp.get_reports( + ignore_pagination=True, + details=True, + filter_string="status=" + + str_status + + " and sort-reverse=name and rows=-1", + ) reports_xml = response_xml.xpath("report") - heading = ["#", "Id", "Creation Time", "Modification Time", "Task Name", "Status", "Progress"] + heading = [ + "#", + "Id", + "Creation Time", + "Modification Time", + "Task Name", + "Status", + "Progress", + ] rows = [] numberRows = 0 @@ -101,32 +121,40 @@ def list_reports ( # Cast/convert to text to show in list rowNumber = str(numberRows) creation_time = "".join(report.xpath("creation_time/text()")) - #report_name = "".join(report.xpath("name/text()")) # Report name is the same as Creation Time + # report_name = "".join(report.xpath("name/text()")) # Report name is the same as Creation Time report_id = report.get("id") report_task = "".join(report.xpath("task/name/text()")) mod_time = "".join(report.xpath("modification_time/text()")) report_status = "".join(report.xpath("report/scan_run_status/text()")) - report_progress = "".join(report.xpath("report/task/progress/text()")) + "%" - rows.append([rowNumber, report_id, creation_time, mod_time, report_task, report_status, report_progress]) + report_progress = ( + "".join(report.xpath("report/task/progress/text()")) + "%" + ) + rows.append( + [ + rowNumber, + report_id, + creation_time, + mod_time, + report_task, + report_status, + report_progress, + ] + ) print(Table(heading=heading, rows=rows)) + def main(gmp: Gmp, args: Namespace) -> None: # pylint: disable=unused-argument if args.script: args = args.script[1:] - parsed_args = parse_args(args = args) + parsed_args = parse_args(args=args) - print( - "Listing reports.\n" - ) + print("Listing reports.\n") + + list_reports(gmp, parsed_args.status_cmd) - list_reports ( - gmp, - parsed_args.status_cmd - ) if __name__ == "__gmp__": main(gmp, args) - diff --git a/scripts/list-roles.gmp.py b/scripts/list-roles.gmp.py index 11a0c108..2cba68d6 100755 --- a/scripts/list-roles.gmp.py +++ b/scripts/list-roles.gmp.py @@ -5,7 +5,6 @@ from argparse import Namespace from gvm.protocols.gmp import Gmp - from gvmtools.helper import Table @@ -20,9 +19,7 @@ def main(gmp: Gmp, args: Namespace) -> None: rows = [] numberRows = 0 - print( - "Listing roles.\n" - ) + print("Listing roles.\n") for role in roles_xml: # Count number of reports diff --git a/scripts/list-scan-configs.gmp.py b/scripts/list-scan-configs.gmp.py index 4ceccda8..eb0f7c6e 100755 --- a/scripts/list-scan-configs.gmp.py +++ b/scripts/list-scan-configs.gmp.py @@ -5,7 +5,6 @@ from argparse import Namespace from gvm.protocols.gmp import Gmp - from gvmtools.helper import Table @@ -20,9 +19,7 @@ def main(gmp: Gmp, args: Namespace) -> None: rows = [] numberRows = 0 - print( - "Listing scan configurations.\n" - ) + print("Listing scan configurations.\n") for scan_config in scan_configs_xml: # Count number of reports diff --git a/scripts/list-scanners.gmp.py b/scripts/list-scanners.gmp.py index f22f4221..868245da 100755 --- a/scripts/list-scanners.gmp.py +++ b/scripts/list-scanners.gmp.py @@ -5,7 +5,6 @@ from argparse import Namespace from gvm.protocols.gmp import Gmp - from gvmtools.helper import Table @@ -20,9 +19,7 @@ def main(gmp: Gmp, args: Namespace) -> None: rows = [] numberRows = 0 - print( - "Listing scanners.\n" - ) + print("Listing scanners.\n") for scanner in scanners_xml: # Count number of reports diff --git a/scripts/list-schedules.gmp.py b/scripts/list-schedules.gmp.py index 56280d8b..f504724f 100755 --- a/scripts/list-schedules.gmp.py +++ b/scripts/list-schedules.gmp.py @@ -5,7 +5,6 @@ from argparse import Namespace from gvm.protocols.gmp import Gmp - from gvmtools.helper import Table @@ -20,9 +19,7 @@ def main(gmp: Gmp, args: Namespace) -> None: rows = [] numberRows = 0 - print( - "Listing schedules.\n" - ) + print("Listing schedules.\n") for schedule in schedules_xml: # Count number of reports @@ -35,11 +32,10 @@ def main(gmp: Gmp, args: Namespace) -> None: icalendar = "".join(schedule.xpath("icalendar/text()")) timezone = "".join(schedule.xpath("timezone/text()")) rows.append([rowNumber, name, schedule_id, timezone, icalendar]) - #print(icalendar) + # print(icalendar) print(Table(heading=heading, rows=rows)) if __name__ == "__gmp__": main(gmp, args) - diff --git a/scripts/list-tags.gmp.py b/scripts/list-tags.gmp.py index 8ef410a3..8de78c42 100755 --- a/scripts/list-tags.gmp.py +++ b/scripts/list-tags.gmp.py @@ -5,7 +5,6 @@ from argparse import Namespace from gvm.protocols.gmp import Gmp - from gvmtools.helper import Table @@ -20,9 +19,7 @@ def main(gmp: Gmp, args: Namespace) -> None: rows = [] numberRows = 0 - print( - "Listing tags.\n" - ) + print("Listing tags.\n") for tag in tags_xml: # Count number of reports diff --git a/scripts/list-targets.gmp.py b/scripts/list-targets.gmp.py index 1dc1bc32..94b8bf3b 100755 --- a/scripts/list-targets.gmp.py +++ b/scripts/list-targets.gmp.py @@ -5,7 +5,6 @@ from argparse import Namespace from gvm.protocols.gmp import Gmp - from gvmtools.helper import Table @@ -15,14 +14,22 @@ def main(gmp: Gmp, args: Namespace) -> None: response_xml = gmp.get_targets(filter_string="rows=-1") targets_xml = response_xml.xpath("target") - heading = ["#", "Name", "Id", "Count", "SSH Credential", "SMB Cred", "ESXi Cred", "SNMP Cred", "Alive test"] + heading = [ + "#", + "Name", + "Id", + "Count", + "SSH Credential", + "SMB Cred", + "ESXi Cred", + "SNMP Cred", + "Alive test", + ] rows = [] numberRows = 0 - print( - "Listing targets.\n" - ) + print("Listing targets.\n") for target in targets_xml: # Count number of reports @@ -38,7 +45,19 @@ def main(gmp: Gmp, args: Namespace) -> None: snmpcred = "".join(target.xpath("snmp_credential/name/text()")) target_id = target.get("id") alive_test = "".join(target.xpath("alive_tests/text()")) - rows.append([rowNumber, name, target_id, maxhosts, sshcred, smbcred, esxicred, snmpcred, alive_test]) + rows.append( + [ + rowNumber, + name, + target_id, + maxhosts, + sshcred, + smbcred, + esxicred, + snmpcred, + alive_test, + ] + ) print(Table(heading=heading, rows=rows)) diff --git a/scripts/list-tasks.gmp.py b/scripts/list-tasks.gmp.py index 7a1e7074..1c9c9cb4 100644 --- a/scripts/list-tasks.gmp.py +++ b/scripts/list-tasks.gmp.py @@ -5,7 +5,6 @@ from argparse import Namespace from gvm.protocols.gmp import Gmp - from gvmtools.helper import Table @@ -20,9 +19,7 @@ def main(gmp: Gmp, args: Namespace) -> None: rows = [] numberRows = 0 - print( - "Listing tasks.\n" - ) + print("Listing tasks.\n") for task in tasks_xml: # Count number of reports @@ -36,7 +33,9 @@ def main(gmp: Gmp, args: Namespace) -> None: scanner = "".join(task.xpath("scanner/name/text()")) severity = "".join(task.xpath("last_report/report/severity/text()")) order = "".join(task.xpath("hosts_ordering/text()")) - rows.append([rowNumber, name, task_id, targetname, scanner, order, severity]) + rows.append( + [rowNumber, name, task_id, targetname, scanner, order, severity] + ) print(Table(heading=heading, rows=rows)) diff --git a/scripts/list-tickets.gmp.py b/scripts/list-tickets.gmp.py index 15d48240..d664c0f8 100755 --- a/scripts/list-tickets.gmp.py +++ b/scripts/list-tickets.gmp.py @@ -5,7 +5,6 @@ from argparse import Namespace from gvm.protocols.gmp import Gmp - from gvmtools.helper import Table @@ -15,14 +14,12 @@ def main(gmp: Gmp, args: Namespace) -> None: response_xml = gmp.get_tickets(filter_string="rows=-1") tickets_xml = response_xml.xpath("ticket") - heading = ["#", "Name", "Host", "Task", "Status", "Note"] + heading = ["#", "ID", "Name", "Host", "Task", "Status", "Note"] rows = [] numberRows = 0 - print( - "Listing tickets.\n" - ) + print("Listing tickets.\n") for ticket in tickets_xml: # Count number of reports @@ -42,7 +39,17 @@ def main(gmp: Gmp, args: Namespace) -> None: elif ticket_status.upper() == "CLOSED": ticket_note = "".join(ticket.xpath("closed_note/text()")) - rows.append([rowNumber, name, ticket_host, ticket_task, ticket_status, ticket_note]) + rows.append( + [ + rowNumber, + ticket_id, + name, + ticket_host, + ticket_task, + ticket_status, + ticket_note, + ] + ) print(Table(heading=heading, rows=rows)) diff --git a/scripts/list-users.gmp.py b/scripts/list-users.gmp.py index 6f319ae9..16ded67d 100755 --- a/scripts/list-users.gmp.py +++ b/scripts/list-users.gmp.py @@ -5,7 +5,6 @@ from argparse import Namespace from gvm.protocols.gmp import Gmp - from gvmtools.helper import Table @@ -20,9 +19,7 @@ def main(gmp: Gmp, args: Namespace) -> None: rows = [] numberRows = 0 - print( - "Listing users.\n" - ) + print("Listing users.\n") for user in users_xml: # Count number of reports diff --git a/scripts/scan-new-system.gmp.py b/scripts/scan-new-system.gmp.py index e8f26e67..12098a2a 100644 --- a/scripts/scan-new-system.gmp.py +++ b/scripts/scan-new-system.gmp.py @@ -16,12 +16,12 @@ def check_args(args): It needs one parameters after the script name. 1. IP Address of the host system - 2. Port List UUID for scanning the host system. - Preconfigured UUID might be under - /var/lib/gvm/data-objects/gvmd/20.08/port_lists/. - ex. iana-tcp-udp is + 2. Port List UUID for scanning the host system. + Preconfigured UUID might be under + /var/lib/gvm/data-objects/gvmd/20.08/port_lists/. + ex. iana-tcp-udp is "4a4717fe-57d2-11e1-9a26-406186ea4fc5". - + Example: $ gvm-script --gmp-username name --gmp-password pass \ ssh --hostname scripts/scan-new-system.gmp.py diff --git a/scripts/send-schedules.gmp.py b/scripts/send-schedules.gmp.py index f9249a1c..aa0e70b0 100644 --- a/scripts/send-schedules.gmp.py +++ b/scripts/send-schedules.gmp.py @@ -6,9 +6,8 @@ from argparse import Namespace from gvm.protocols.gmp import Gmp -from lxml.etree import Element - from gvmtools.helper import create_xml_tree +from lxml.etree import Element def check_args(gmp: Gmp, args: Namespace) -> None: diff --git a/scripts/send-targets.gmp.py b/scripts/send-targets.gmp.py index b4124358..72900602 100644 --- a/scripts/send-targets.gmp.py +++ b/scripts/send-targets.gmp.py @@ -6,9 +6,8 @@ from argparse import Namespace from gvm.protocols.gmp import Gmp -from lxml.etree import Element - from gvmtools.helper import create_xml_tree, yes_or_no +from lxml.etree import Element def check_args(args: Namespace) -> None: diff --git a/scripts/send-tasks.gmp.py b/scripts/send-tasks.gmp.py index dcc0e288..5c22943c 100644 --- a/scripts/send-tasks.gmp.py +++ b/scripts/send-tasks.gmp.py @@ -6,13 +6,12 @@ from argparse import ArgumentParser, Namespace, RawTextHelpFormatter from gvm.protocols.gmp import Gmp - from gvmtools.helper import create_xml_tree, error_and_exit, yes_or_no HELP_TEXT = """ This script pulls tasks data from an xml document and feeds it to \ a desired GSM - Usage examples: + Usage examples: $ gvm-script --gmp-username name --gmp-password pass ssh --hostname ... send-task.gmp.py +h ... send-task.gmp.py ++x xml_file diff --git a/scripts/start-scans-from-csv.py b/scripts/start-scans-from-csv.py index 03061c2e..559b170a 100755 --- a/scripts/start-scans-from-csv.py +++ b/scripts/start-scans-from-csv.py @@ -4,23 +4,17 @@ # Run with gvm-script --gmp-username admin-user --gmp-password password socket start-scans-from-csv.gmp.py startscans.csv -import sys -import time import csv -import json - +import sys from argparse import ArgumentParser, Namespace, RawTextHelpFormatter from pathlib import Path -from typing import List -from gvm.errors import GvmResponseError +from gvm.errors import GvmResponseError from gvm.protocols.gmp import Gmp - from gvmtools.helper import error_and_exit -HELP_TEXT = ( - "This script pulls task names from a csv file and starts the tasks listed in every row. \n" -) +HELP_TEXT = "This script pulls task names from a csv file and starts the tasks listed in every row. \n" + def check_args(args): len_args = len(args.script) - 1 @@ -66,55 +60,64 @@ def parse_args(args: Namespace) -> Namespace: # pylint: disable=unused-argument script_args, _ = parser.parse_known_args(args) return script_args + def task_id( gmp: Gmp, task_name: str, ): - response_xml = gmp.get_tasks(filter_string="rows=-1, not status=Running and " + response_xml = gmp.get_tasks( + filter_string="rows=-1, not status=Running and " "not status=Requested and not " "status=Queued " - "and name=" + task_name) + "and name=" + task_name + ) tasks_xml = response_xml.xpath("task") task_id = "" for task in tasks_xml: - name = "".join(task.xpath("name/text()")) task_id = task.get("id") - #print("Requesting start of task: " + task_name + " Task UUID: " + task_id) return task_id -def start_tasks( + +def start_tasks( gmp: Gmp, task_file: Path, ): try: numbertasks = 0 with open(task_file, encoding="utf-8") as csvFile: - content = csv.reader(csvFile, delimiter=',') #read the data + content = csv.reader(csvFile, delimiter=",") # read the data try: - for row in content: #loop through each row + for row in content: # loop through each row if len(row) == 0: continue task_start = task_id(gmp, row[0]) if task_start: numbertasks = numbertasks + 1 - print(f"Starting task name: {row[0]} with uuid: {task_start} ...") + print( + f"Starting task name: {row[0]} with uuid: {task_start} ..." + ) status_text = gmp.start_task(task_start).xpath( - "@status_text" + "@status_text" )[0] print(status_text) else: - print("Task " + row[0] + " is either in status Requested, Queued, Running, or does not exist on this system.\n") + print( + "Task " + + row[0] + + " is either in status Requested, Queued, Running, or does not exist on this system.\n" + ) except GvmResponseError as gvmerr: print(f"{gvmerr=}, task: {task_start}") pass - csvFile.close() #close the csv file + csvFile.close() # close the csv file except IOError as e: error_and_exit(f"Failed to read task_file: {str(e)} (exit)") - + return numbertasks - + + def main(gmp: Gmp, args: Namespace) -> None: # pylint: disable=undefined-variable if args.script: @@ -122,9 +125,7 @@ def main(gmp: Gmp, args: Namespace) -> None: parsed_args = parse_args(args=args) - print( - "Starting tasks.\n" - ) + print("Starting tasks.\n") numbertasks = start_tasks( gmp, @@ -134,5 +135,6 @@ def main(gmp: Gmp, args: Namespace) -> None: numbertasks = str(numbertasks) print(" \n [" + numbertasks + "] task(s)/scan(s) started!\n") + if __name__ == "__gmp__": main(gmp, args) diff --git a/scripts/stop-all-scans.gmp.py b/scripts/stop-all-scans.gmp.py index 0556b8cb..be245374 100755 --- a/scripts/stop-all-scans.gmp.py +++ b/scripts/stop-all-scans.gmp.py @@ -6,29 +6,26 @@ from gvm.protocols.gmp import Gmp -from gvmtools.helper import Table def stop_tasks(gmp: Gmp) -> None: tasks = gmp.get_tasks( - filter_string="rows=-1 status=Running or status=Requested or status=Queued" - ) + filter_string="rows=-1 status=Running or status=Requested or status=Queued" + ) try: for task_id in tasks.xpath("task/@id"): print(f"Stopping task {task_id} ... ") - gmp.stop_task(task_id).xpath( - "@status_text" - )[0] + status_text = gmp.stop_task(task_id).xpath("@status_text")[0] print(status_text) - except: - pass + except Exception as e: + print(f"{e=}") + def main(gmp: Gmp, args: Namespace) -> None: # pylint: disable=undefined-variable - print( - "This script stops all tasks on the system.\n" - ) + print("This script stops all tasks on the system.\n") stop_tasks(gmp) - + + if __name__ == "__gmp__": main(gmp, args) diff --git a/scripts/stop-scans-from-csv.py b/scripts/stop-scans-from-csv.py index c17dcb2f..40e3d86d 100755 --- a/scripts/stop-scans-from-csv.py +++ b/scripts/stop-scans-from-csv.py @@ -4,23 +4,17 @@ # Run with gvm-script --gmp-username admin-user --gmp-password password socket start-scans-from-csv.gmp.py startscans.csv -import sys -import time import csv -import json - +import sys from argparse import ArgumentParser, Namespace, RawTextHelpFormatter from pathlib import Path -from typing import List -from gvm.errors import GvmResponseError +from gvm.errors import GvmResponseError from gvm.protocols.gmp import Gmp - from gvmtools.helper import error_and_exit -HELP_TEXT = ( - "This script pulls task names from a csv file and starts the tasks listed in every row. \n" -) +HELP_TEXT = "This script pulls task names from a csv file and starts the tasks listed in every row. \n" + def check_args(args): len_args = len(args.script) - 1 @@ -66,58 +60,67 @@ def parse_args(args: Namespace) -> Namespace: # pylint: disable=unused-argument script_args, _ = parser.parse_known_args(args) return script_args + def task_id( gmp: Gmp, task_name: str, ): - response_xml = gmp.get_tasks(filter_string="rows=-1, status=Running " + response_xml = gmp.get_tasks( + filter_string="rows=-1, status=Running " "or status=Requested " "or status=Queued " - "and name=" + task_name) + "and name=" + task_name + ) tasks_xml = response_xml.xpath("task") task_id = "" for task in tasks_xml: - name = "".join(task.xpath("name/text()")) task_id = task.get("id") - #print("Requesting stop of task: " + task_name + " Task UUID: " + task_id) return task_id -def stop_tasks( + +def stop_tasks( gmp: Gmp, task_file: Path, ): try: numbertasks = 0 with open(task_file, encoding="utf-8") as csvFile: - content = csv.reader(csvFile, delimiter=',') #read the data + content = csv.reader(csvFile, delimiter=",") # read the data try: - for row in content: #loop through each row + for row in content: # loop through each row if len(row) == 0: continue task_stop = task_id(gmp, row[0]) if task_stop: numbertasks = numbertasks + 1 - print(f"Stopping task name: {row[0]} with uuid: {task_stop} ...") + print( + f"Stopping task name: {row[0]} with uuid: {task_stop} ..." + ) status_text = gmp.stop_task(task_stop).xpath( - "@status_text" + "@status_text" )[0] print(status_text) else: - print("Task " + row[0] + " is either in status Stopped, Stop Requested, or does not exist on this system.\n") + print( + "Task " + + row[0] + + " is either in status Stopped, Stop Requested, or does not exist on this system.\n" + ) except GvmResponseError as gvmerr: print(f"{gvmerr=}, task: {task_stop}") pass - csvFile.close() #close the csv file + csvFile.close() # close the csv file except IOError as e: error_and_exit(f"Failed to read task_file: {str(e)} (exit)") if len(row) == 0: error_and_exit("tasks file is empty (exit)") - + return numbertasks - + + def main(gmp: Gmp, args: Namespace) -> None: # pylint: disable=undefined-variable if args.script: @@ -125,9 +128,7 @@ def main(gmp: Gmp, args: Namespace) -> None: parsed_args = parse_args(args=args) - print( - "Stopping tasks.\n" - ) + print("Stopping tasks.\n") numbertasks = stop_tasks( gmp, @@ -137,5 +138,6 @@ def main(gmp: Gmp, args: Namespace) -> None: numbertasks = str(numbertasks) print(" \n [" + numbertasks + "] task(s)/scan(s) stopped!\n") + if __name__ == "__gmp__": main(gmp, args) diff --git a/scripts/update-task-target.gmp.py b/scripts/update-task-target.gmp.py index a4a125bb..645bc04f 100644 --- a/scripts/update-task-target.gmp.py +++ b/scripts/update-task-target.gmp.py @@ -7,7 +7,6 @@ from typing import List from gvm.protocols.gmp import Gmp - from gvmtools.helper import error_and_exit HELP_TEXT = (