gvm-tools 23.9.0__tar.gz → 23.11.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of gvm-tools might be problematic. Click here for more details.
- {gvm_tools-23.9.0 → gvm_tools-23.11.0}/PKG-INFO +2 -1
- {gvm_tools-23.9.0 → gvm_tools-23.11.0}/gvmtools/__version__.py +1 -1
- {gvm_tools-23.9.0 → gvm_tools-23.11.0}/gvmtools/cli.py +1 -1
- {gvm_tools-23.9.0 → gvm_tools-23.11.0}/gvmtools/config.py +1 -1
- {gvm_tools-23.9.0 → gvm_tools-23.11.0}/pyproject.toml +8 -4
- {gvm_tools-23.9.0 → gvm_tools-23.11.0}/scripts/application-detection.gmp.py +22 -3
- {gvm_tools-23.9.0 → gvm_tools-23.11.0}/scripts/certbund-report.gmp.py +2 -2
- {gvm_tools-23.9.0 → gvm_tools-23.11.0}/scripts/check-gmp.gmp.py +1 -6
- {gvm_tools-23.9.0 → gvm_tools-23.11.0}/scripts/combine-reports.gmp.py +3 -1
- {gvm_tools-23.9.0 → gvm_tools-23.11.0}/scripts/generate-random-reports.gmp.py +79 -38
- gvm_tools-23.11.0/scripts/ruff.toml +1 -0
- {gvm_tools-23.9.0 → gvm_tools-23.11.0}/scripts/send-delta-emails.gmp.py +3 -2
- {gvm_tools-23.9.0 → gvm_tools-23.11.0}/scripts/ssv_csv.py +1 -1
- {gvm_tools-23.9.0 → gvm_tools-23.11.0}/scripts/start-alert-scan.gmp.py +4 -4
- {gvm_tools-23.9.0 → gvm_tools-23.11.0}/scripts/start-multiple-alerts-scan.gmp.py +3 -2
- {gvm_tools-23.9.0 → gvm_tools-23.11.0}/scripts/sync-hosts.gmp.py +2 -1
- {gvm_tools-23.9.0 → gvm_tools-23.11.0}/tests/scripts/__init__.py +1 -1
- {gvm_tools-23.9.0 → gvm_tools-23.11.0}/LICENSE +0 -0
- {gvm_tools-23.9.0 → gvm_tools-23.11.0}/README.md +0 -0
- {gvm_tools-23.9.0 → gvm_tools-23.11.0}/gvmtools/__init__.py +0 -0
- {gvm_tools-23.9.0 → gvm_tools-23.11.0}/gvmtools/helper.py +0 -0
- {gvm_tools-23.9.0 → gvm_tools-23.11.0}/gvmtools/parser.py +0 -0
- {gvm_tools-23.9.0 → gvm_tools-23.11.0}/gvmtools/pyshell.py +0 -0
- {gvm_tools-23.9.0 → gvm_tools-23.11.0}/gvmtools/script.py +0 -0
- {gvm_tools-23.9.0 → gvm_tools-23.11.0}/scripts/.pylintrc +0 -0
- {gvm_tools-23.9.0 → gvm_tools-23.11.0}/scripts/README.md +0 -0
- {gvm_tools-23.9.0 → gvm_tools-23.11.0}/scripts/bulk-modify-schedules.gmp.py +0 -0
- {gvm_tools-23.9.0 → gvm_tools-23.11.0}/scripts/cfg-gen-for-certs.gmp.py +0 -0
- {gvm_tools-23.9.0 → gvm_tools-23.11.0}/scripts/clean-sensor.gmp.py +0 -0
- {gvm_tools-23.9.0 → gvm_tools-23.11.0}/scripts/create-consolidated-report.gmp.py +0 -0
- {gvm_tools-23.9.0 → gvm_tools-23.11.0}/scripts/create-cve-report-from-json.gmp.py +0 -0
- {gvm_tools-23.9.0 → gvm_tools-23.11.0}/scripts/create-dummy-data.gmp.py +0 -0
- {gvm_tools-23.9.0 → gvm_tools-23.11.0}/scripts/create-targets-from-host-list.gmp.py +0 -0
- {gvm_tools-23.9.0 → gvm_tools-23.11.0}/scripts/default_report_data.json +0 -0
- {gvm_tools-23.9.0 → gvm_tools-23.11.0}/scripts/delete-overrides-by-filter.gmp.py +0 -0
- {gvm_tools-23.9.0 → gvm_tools-23.11.0}/scripts/export-pdf-report.gmp.py +0 -0
- {gvm_tools-23.9.0 → gvm_tools-23.11.0}/scripts/generate-random-targets.gmp.py +0 -0
- {gvm_tools-23.9.0 → gvm_tools-23.11.0}/scripts/list-tasks.gmp.py +0 -0
- {gvm_tools-23.9.0 → gvm_tools-23.11.0}/scripts/monthly-report-gos4.gmp.py +0 -0
- {gvm_tools-23.9.0 → gvm_tools-23.11.0}/scripts/monthly-report.gmp.py +0 -0
- {gvm_tools-23.9.0 → gvm_tools-23.11.0}/scripts/nvt-scan.gmp.py +0 -0
- {gvm_tools-23.9.0 → gvm_tools-23.11.0}/scripts/requirements.txt +0 -0
- {gvm_tools-23.9.0 → gvm_tools-23.11.0}/scripts/scan-new-system.gmp.py +0 -0
- {gvm_tools-23.9.0 → gvm_tools-23.11.0}/scripts/send-schedules.gmp.py +0 -0
- {gvm_tools-23.9.0 → gvm_tools-23.11.0}/scripts/send-targets.gmp.py +0 -0
- {gvm_tools-23.9.0 → gvm_tools-23.11.0}/scripts/send-tasks.gmp.py +0 -0
- {gvm_tools-23.9.0 → gvm_tools-23.11.0}/scripts/start-nvt-scan.gmp.py +0 -0
- {gvm_tools-23.9.0 → gvm_tools-23.11.0}/scripts/update-task-target.gmp.py +0 -0
- {gvm_tools-23.9.0 → gvm_tools-23.11.0}/tests/__init__.py +0 -0
- {gvm_tools-23.9.0 → gvm_tools-23.11.0}/tests/root_help.3.10.snap +0 -0
- {gvm_tools-23.9.0 → gvm_tools-23.11.0}/tests/root_help.snap +0 -0
- {gvm_tools-23.9.0 → gvm_tools-23.11.0}/tests/scripts/example_schedules.xml +0 -0
- {gvm_tools-23.9.0 → gvm_tools-23.11.0}/tests/scripts/example_target.xml +0 -0
- {gvm_tools-23.9.0 → gvm_tools-23.11.0}/tests/scripts/example_task.xml +0 -0
- {gvm_tools-23.9.0 → gvm_tools-23.11.0}/tests/scripts/get_alerts.xml +0 -0
- {gvm_tools-23.9.0 → gvm_tools-23.11.0}/tests/scripts/get_scan_configs.xml +0 -0
- {gvm_tools-23.9.0 → gvm_tools-23.11.0}/tests/scripts/invalid_xml.xml +0 -0
- {gvm_tools-23.9.0 → gvm_tools-23.11.0}/tests/scripts/test_combine_reports.py +0 -0
- {gvm_tools-23.9.0 → gvm_tools-23.11.0}/tests/scripts/test_create_consolidated_report.py +0 -0
- {gvm_tools-23.9.0 → gvm_tools-23.11.0}/tests/scripts/test_send_schedules.py +0 -0
- {gvm_tools-23.9.0 → gvm_tools-23.11.0}/tests/scripts/test_send_targets.py +0 -0
- {gvm_tools-23.9.0 → gvm_tools-23.11.0}/tests/scripts/test_send_tasks.py +0 -0
- {gvm_tools-23.9.0 → gvm_tools-23.11.0}/tests/scripts/test_start_alert_scan.py +0 -0
- {gvm_tools-23.9.0 → gvm_tools-23.11.0}/tests/socket_help.3.10.snap +0 -0
- {gvm_tools-23.9.0 → gvm_tools-23.11.0}/tests/socket_help.snap +0 -0
- {gvm_tools-23.9.0 → gvm_tools-23.11.0}/tests/ssh_help.3.10.snap +0 -0
- {gvm_tools-23.9.0 → gvm_tools-23.11.0}/tests/ssh_help.snap +0 -0
- {gvm_tools-23.9.0 → gvm_tools-23.11.0}/tests/test.cfg +0 -0
- {gvm_tools-23.9.0 → gvm_tools-23.11.0}/tests/test_auth.cfg +0 -0
- {gvm_tools-23.9.0 → gvm_tools-23.11.0}/tests/test_config.py +0 -0
- {gvm_tools-23.9.0 → gvm_tools-23.11.0}/tests/test_helper.py +0 -0
- {gvm_tools-23.9.0 → gvm_tools-23.11.0}/tests/test_parser.py +0 -0
- {gvm_tools-23.9.0 → gvm_tools-23.11.0}/tests/tls_help.3.10.snap +0 -0
- {gvm_tools-23.9.0 → gvm_tools-23.11.0}/tests/tls_help.snap +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: gvm-tools
|
|
3
|
-
Version: 23.
|
|
3
|
+
Version: 23.11.0
|
|
4
4
|
Summary: Tools to control a GSM/GVM over GMP or OSP
|
|
5
5
|
Home-page: https://github.com/greenbone/gvm-tools/
|
|
6
6
|
License: GPL-3.0-or-later
|
|
@@ -18,6 +18,7 @@ Classifier: Programming Language :: Python :: 3
|
|
|
18
18
|
Classifier: Programming Language :: Python :: 3.9
|
|
19
19
|
Classifier: Programming Language :: Python :: 3.10
|
|
20
20
|
Classifier: Programming Language :: Python :: 3.11
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
22
|
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
22
23
|
Requires-Dist: python-gvm (>=23.4.2)
|
|
23
24
|
Project-URL: Documentation, https://greenbone.github.io/gvm-tools/
|
|
@@ -49,7 +49,7 @@ HELP_TEXT = """
|
|
|
49
49
|
gvm-cli socket --gmp-username foo --gmp-password foo myfile.xml
|
|
50
50
|
|
|
51
51
|
The protocol specifications for GMP and OSP are available at:
|
|
52
|
-
https://docs.greenbone.net/index.html#api_documentation"""
|
|
52
|
+
https://docs.greenbone.net/index.html#api_documentation""" # noqa: E501
|
|
53
53
|
|
|
54
54
|
|
|
55
55
|
def _load_infile(filename=None):
|
|
@@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"
|
|
|
4
4
|
|
|
5
5
|
[tool.poetry]
|
|
6
6
|
name = "gvm-tools"
|
|
7
|
-
version = "23.
|
|
7
|
+
version = "23.11.0"
|
|
8
8
|
authors = ["Greenbone AG <info@greenbone.net>"]
|
|
9
9
|
description = "Tools to control a GSM/GVM over GMP or OSP"
|
|
10
10
|
license = "GPL-3.0-or-later"
|
|
@@ -12,7 +12,7 @@ readme = "README.md"
|
|
|
12
12
|
homepage = "https://github.com/greenbone/gvm-tools/"
|
|
13
13
|
repository = "https://github.com/greenbone/gvm-tools/"
|
|
14
14
|
documentation = "https://greenbone.github.io/gvm-tools/"
|
|
15
|
-
classifiers=[
|
|
15
|
+
classifiers = [
|
|
16
16
|
# Full list: https://pypi.org/pypi?%3Aaction=list_classifiers
|
|
17
17
|
'Development Status :: 5 - Production/Stable',
|
|
18
18
|
'License :: OSI Approved :: GNU General Public License v3 (GPLv3)',
|
|
@@ -42,7 +42,7 @@ python-gvm = ">=23.4.2"
|
|
|
42
42
|
|
|
43
43
|
[tool.poetry.dev-dependencies]
|
|
44
44
|
autohooks = ">=22.8.0"
|
|
45
|
-
autohooks-plugin-
|
|
45
|
+
autohooks-plugin-ruff = ">=23.6.1"
|
|
46
46
|
autohooks-plugin-black = ">=22.8.1"
|
|
47
47
|
autohooks-plugin-isort = ">=22.8.0"
|
|
48
48
|
pontos = ">=22.8.1"
|
|
@@ -75,7 +75,11 @@ line_length = 80
|
|
|
75
75
|
|
|
76
76
|
[tool.autohooks]
|
|
77
77
|
mode = "poetry"
|
|
78
|
-
pre-commit = [
|
|
78
|
+
pre-commit = [
|
|
79
|
+
'autohooks.plugins.black',
|
|
80
|
+
'autohooks.plugins.ruff',
|
|
81
|
+
'autohooks.plugins.isort',
|
|
82
|
+
]
|
|
79
83
|
|
|
80
84
|
[tool.pontos.version]
|
|
81
85
|
version-module-file = "gvmtools/__version__.py"
|
|
@@ -39,23 +39,42 @@ def check_args(args):
|
|
|
39
39
|
|
|
40
40
|
|
|
41
41
|
def print_assets(gmp, appname):
|
|
42
|
-
res = gmp.get_reports()
|
|
42
|
+
res = gmp.get_reports(details=False)
|
|
43
43
|
|
|
44
|
-
|
|
44
|
+
reports = res.xpath("/get_reports_response/report")
|
|
45
|
+
for report in reports:
|
|
46
|
+
report_id = report.attrib["id"]
|
|
47
|
+
print_assets_for_host(gmp, appname, report_id)
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def print_assets_for_host(gmp, appname, report_id):
|
|
51
|
+
res = gmp.get_report(
|
|
52
|
+
report_id, details=True, filter_string="rows=1 result_hosts_only=0"
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
hosts = res.xpath("/get_reports_response/report/report/host")
|
|
45
56
|
|
|
46
57
|
for host in hosts:
|
|
47
58
|
ip = host.xpath("ip/text()")
|
|
59
|
+
if len(ip) == 0:
|
|
60
|
+
continue
|
|
61
|
+
else:
|
|
62
|
+
ip = ip[0]
|
|
63
|
+
|
|
48
64
|
hostname = host.xpath('detail/name[text()="hostname"]/../value/text()')
|
|
49
65
|
if len(hostname) == 0:
|
|
50
66
|
hostname = ""
|
|
51
67
|
else:
|
|
52
68
|
hostname = hostname[0]
|
|
53
69
|
|
|
54
|
-
print(f"{ip} ({hostname})")
|
|
55
70
|
apps = host.xpath(
|
|
56
71
|
'detail/name[text() = "App"]/../value['
|
|
57
72
|
f'contains(text(), "{appname}")]/text()'
|
|
58
73
|
)
|
|
74
|
+
if len(apps) == 0:
|
|
75
|
+
continue
|
|
76
|
+
|
|
77
|
+
print(f"{ip} ({hostname})")
|
|
59
78
|
for app in apps:
|
|
60
79
|
print("\t" + app)
|
|
61
80
|
print("\n")
|
|
@@ -252,7 +252,7 @@ def main(gmp: Gmp, args: Namespace) -> None:
|
|
|
252
252
|
_info(f"processing {len(hosts)}/{len(hostdatas)} hosts")
|
|
253
253
|
for hostdata in hostdatas:
|
|
254
254
|
asset = hostdata.find("asset").attrib["asset_id"]
|
|
255
|
-
if not
|
|
255
|
+
if asset not in hosts:
|
|
256
256
|
continue
|
|
257
257
|
details: Dict[str, Optional[str]] = {}
|
|
258
258
|
details["ip"] = _get_text(hostdata.find("ip"))
|
|
@@ -295,7 +295,7 @@ def main(gmp: Gmp, args: Namespace) -> None:
|
|
|
295
295
|
# warn below
|
|
296
296
|
continue
|
|
297
297
|
for cbi in cbs.findall("info"):
|
|
298
|
-
if
|
|
298
|
+
if "id" not in cbi.attrib:
|
|
299
299
|
# we have both <info id="CB-K14/1304"> (which we want)
|
|
300
300
|
# and, for some reason, <info start="1" max="10"/>
|
|
301
301
|
continue
|
|
@@ -189,16 +189,13 @@ class InstanceManager:
|
|
|
189
189
|
(self.host,),
|
|
190
190
|
)
|
|
191
191
|
db_entry = self.cursor.fetchone()
|
|
192
|
-
print(db_entry)
|
|
193
192
|
|
|
194
193
|
logger.debug("%s %s", db_entry, last_scan_end)
|
|
195
194
|
|
|
196
195
|
if not db_entry:
|
|
197
196
|
return True
|
|
198
197
|
else:
|
|
199
|
-
print(db_entry[0])
|
|
200
198
|
old = parse_date(db_entry[0])
|
|
201
|
-
print(last_scan_end)
|
|
202
199
|
new = parse_date(last_scan_end)
|
|
203
200
|
|
|
204
201
|
logger.debug(
|
|
@@ -273,7 +270,7 @@ class InstanceManager:
|
|
|
273
270
|
self.cursor.execute("DELETE FROM Report WHERE host=?", (ip,))
|
|
274
271
|
self.con_db.isolation_level = None
|
|
275
272
|
self.cursor.execute("VACUUM")
|
|
276
|
-
self.con_db.isolation_level = "" # see: https://github.com/CxAalto/gtfspy/commit/8d05c3c94a6d4ca3ed675d88af93def7d5053bfe # pylint: disable=line-too-long
|
|
273
|
+
self.con_db.isolation_level = "" # see: https://github.com/CxAalto/gtfspy/commit/8d05c3c94a6d4ca3ed675d88af93def7d5053bfe # pylint: disable=line-too-long # noqa: E501
|
|
277
274
|
# Save the changes
|
|
278
275
|
self.con_db.commit()
|
|
279
276
|
|
|
@@ -1142,8 +1139,6 @@ def parse_date(datestring, default_timezone=UTC):
|
|
|
1142
1139
|
if not isinstance(datestring, str):
|
|
1143
1140
|
raise ParseError(f"Expecting a string {datestring}")
|
|
1144
1141
|
|
|
1145
|
-
print(datestring)
|
|
1146
|
-
|
|
1147
1142
|
match = ISO8601_REGEX.match(datestring)
|
|
1148
1143
|
if not match:
|
|
1149
1144
|
raise ParseError(f"Unable to parse date string {datestring}")
|
|
@@ -16,6 +16,8 @@
|
|
|
16
16
|
# You should have received a copy of the GNU General Public License
|
|
17
17
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
18
18
|
|
|
19
|
+
# ruff: noqa: E501
|
|
20
|
+
|
|
19
21
|
import sys
|
|
20
22
|
import time
|
|
21
23
|
from argparse import Namespace
|
|
@@ -43,7 +45,7 @@ def check_args(args: Namespace) -> None:
|
|
|
43
45
|
n. <report_n_uuid> --uuid of report to be combined
|
|
44
46
|
|
|
45
47
|
Example for starting up the routine:
|
|
46
|
-
$ gvm-script --gmp-username=namessh --gmp-password=pass ssh --hostname=hostname
|
|
48
|
+
$ gvm-script --gmp-username=namessh --gmp-password=pass ssh --hostname=hostname \
|
|
47
49
|
scripts/combine-reports.gmp.py \
|
|
48
50
|
"d15a337c-56f3-4208-a462-afeb79eb03b7" \
|
|
49
51
|
"303fa0a6-aa9b-43c4-bac0-66ae0b2d1698" 'first_task'
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
# -*- coding: utf-8 -*-
|
|
2
|
-
# Copyright (C) 2017-
|
|
2
|
+
# Copyright (C) 2017-2023 Greenbone AG
|
|
3
3
|
#
|
|
4
4
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
5
5
|
#
|
|
@@ -20,20 +20,20 @@
|
|
|
20
20
|
|
|
21
21
|
import json
|
|
22
22
|
import textwrap
|
|
23
|
-
import time
|
|
24
23
|
from argparse import ArgumentParser, Namespace, RawTextHelpFormatter
|
|
25
24
|
from pathlib import Path
|
|
26
25
|
from random import choice, gauss, randrange, seed
|
|
26
|
+
from datetime import datetime, timedelta
|
|
27
27
|
|
|
28
28
|
from gvm.protocols.gmp import Gmp
|
|
29
29
|
from lxml import etree as e
|
|
30
30
|
|
|
31
31
|
from gvmtools.helper import generate_id, generate_random_ips, generate_uuid
|
|
32
32
|
|
|
33
|
-
__version__ = "0.
|
|
33
|
+
__version__ = "0.3.1"
|
|
34
34
|
|
|
35
35
|
HELP_TEXT = f"""
|
|
36
|
-
Random Report Generation Script {__version__} (C) 2017-
|
|
36
|
+
Random Report Generation Script {__version__} (C) 2017-2023 Greenbone AG
|
|
37
37
|
|
|
38
38
|
This program is free software: you can redistribute it and/or modify
|
|
39
39
|
it under the terms of the GNU General Public License as published by
|
|
@@ -52,13 +52,24 @@ HELP_TEXT = f"""
|
|
|
52
52
|
"""
|
|
53
53
|
|
|
54
54
|
LOREM_IPSUM = """Lorem ipsum dolor sit amet, consectetur adipiscing elit,
|
|
55
|
-
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
|
|
56
|
-
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut
|
|
55
|
+
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
|
|
56
|
+
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut
|
|
57
57
|
aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in
|
|
58
58
|
voluptate velit esse cillum dolore eu fugiat nulla pariatur.
|
|
59
59
|
Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia
|
|
60
60
|
deserunt mollit anim id est laborum."""
|
|
61
61
|
|
|
62
|
+
local_date_time = datetime.now()
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def calculate_timestamp(delta: int = 0) -> str:
|
|
66
|
+
return (
|
|
67
|
+
(local_date_time + timedelta(seconds=delta))
|
|
68
|
+
.astimezone()
|
|
69
|
+
.replace(microsecond=0)
|
|
70
|
+
.isoformat()
|
|
71
|
+
)
|
|
72
|
+
|
|
62
73
|
|
|
63
74
|
def generate_ports(n_ports):
|
|
64
75
|
protocol = ["/tcp", "/udp"]
|
|
@@ -164,17 +175,9 @@ def generate_result_elem(
|
|
|
164
175
|
e.SubElement(own, "name").text = generate_id()
|
|
165
176
|
|
|
166
177
|
elem = e.Element("modification_time")
|
|
167
|
-
e.SubElement(result_elem, "modification_time").text = (
|
|
168
|
-
time.strftime("%Y-%m-%dT%H:%M:%S%z", time.localtime(time.time()))[:-2]
|
|
169
|
-
+ ":00"
|
|
170
|
-
) # Hell of a Timeformat :D
|
|
178
|
+
e.SubElement(result_elem, "modification_time").text = calculate_timestamp(0)
|
|
171
179
|
e.SubElement(result_elem, "comment").text = ""
|
|
172
|
-
e.SubElement(result_elem, "creation_time").text = (
|
|
173
|
-
time.strftime("%Y-%m-%dT%H:%M:%S%z", time.localtime(time.time() - 20))[
|
|
174
|
-
:-2
|
|
175
|
-
]
|
|
176
|
-
+ ":00"
|
|
177
|
-
)
|
|
180
|
+
e.SubElement(result_elem, "creation_time").text = calculate_timestamp(-20)
|
|
178
181
|
|
|
179
182
|
host_elem = e.Element("host")
|
|
180
183
|
host_elem.text = host_ip
|
|
@@ -260,18 +263,8 @@ def generate_host_elem(
|
|
|
260
263
|
e.SubElement(host_elem, "ip").text = host_ip
|
|
261
264
|
e.SubElement(host_elem, "asset", {"asset_id": host_asset}).text = ""
|
|
262
265
|
|
|
263
|
-
e.SubElement(host_elem, "start").text = (
|
|
264
|
-
|
|
265
|
-
"%Y-%m-%dT%H:%M:%S%z", time.localtime(time.time() - 1000)
|
|
266
|
-
)[:-2]
|
|
267
|
-
+ ":00"
|
|
268
|
-
)
|
|
269
|
-
e.SubElement(host_elem, "end").text = (
|
|
270
|
-
time.strftime("%Y-%m-%dT%H:%M:%S%z", time.localtime(time.time() - 30))[
|
|
271
|
-
:-2
|
|
272
|
-
]
|
|
273
|
-
+ ":00"
|
|
274
|
-
)
|
|
266
|
+
e.SubElement(host_elem, "start").text = calculate_timestamp(-1000)
|
|
267
|
+
e.SubElement(host_elem, "end").text = calculate_timestamp(-30)
|
|
275
268
|
|
|
276
269
|
app = choice(list(data["apps"]))
|
|
277
270
|
os = choice(list(data["oss"]))
|
|
@@ -304,7 +297,7 @@ def generate_host_elem(
|
|
|
304
297
|
host_elem.append(
|
|
305
298
|
generate_host_detail_elem(
|
|
306
299
|
"best_os_txt",
|
|
307
|
-
|
|
300
|
+
os,
|
|
308
301
|
source_name=oid,
|
|
309
302
|
source_description="Host Details",
|
|
310
303
|
source_type="nvt",
|
|
@@ -340,7 +333,7 @@ def generate_host_elem(
|
|
|
340
333
|
return host_elem
|
|
341
334
|
|
|
342
335
|
|
|
343
|
-
def generate_reports(task, n_reports, with_gauss, **kwargs):
|
|
336
|
+
def generate_reports(task, n_reports, n_results, with_gauss, **kwargs):
|
|
344
337
|
reports = []
|
|
345
338
|
|
|
346
339
|
if with_gauss:
|
|
@@ -352,29 +345,65 @@ def generate_reports(task, n_reports, with_gauss, **kwargs):
|
|
|
352
345
|
if with_gauss:
|
|
353
346
|
n_results = abs(int(gauss(n_results, 2)))
|
|
354
347
|
|
|
355
|
-
report_elem = generate_report_elem(task, **kwargs)
|
|
348
|
+
report_elem = generate_report_elem(task, n_results=n_results, **kwargs)
|
|
356
349
|
report_elem = e.tostring(report_elem)
|
|
357
350
|
reports.append(report_elem)
|
|
358
351
|
|
|
359
352
|
return reports
|
|
360
353
|
|
|
361
354
|
|
|
362
|
-
def
|
|
355
|
+
def generate_target():
|
|
356
|
+
target_name = f"Random_Report_Generation_Target_{calculate_timestamp(0)}"
|
|
357
|
+
target_comment = (
|
|
358
|
+
f"Generated by Random Report Generation Script Version {__version__}."
|
|
359
|
+
)
|
|
360
|
+
target_hosts = ["198.18.0.0/24"]
|
|
361
|
+
target_port_list_id = "c7e03b6c-3bbe-11e1-a057-406186ea4fc5"
|
|
362
|
+
|
|
363
|
+
gmp.create_target(
|
|
364
|
+
name=target_name,
|
|
365
|
+
comment=target_comment,
|
|
366
|
+
hosts=target_hosts,
|
|
367
|
+
port_list_id=target_port_list_id,
|
|
368
|
+
)
|
|
369
|
+
|
|
370
|
+
|
|
371
|
+
def generate_data(gmp, n_tasks, task_type, **kwargs):
|
|
372
|
+
if task_type == "scan":
|
|
373
|
+
scanner_id = "08b69003-5fc2-4037-a479-93b440211c73"
|
|
374
|
+
config_id = "085569ce-73ed-11df-83c3-002264764cea"
|
|
375
|
+
generate_target()
|
|
376
|
+
target_id = gmp.get_targets(
|
|
377
|
+
filter_string=f'"Random_Report_Generation_Target_{calculate_timestamp(0)}"'
|
|
378
|
+
).xpath("//@id")[0]
|
|
379
|
+
|
|
363
380
|
for i in range(n_tasks):
|
|
364
381
|
index = f"{{0:0>{len(str(n_tasks))}}}"
|
|
365
|
-
task_name = f"
|
|
382
|
+
task_name = f"Random_Report_Generation_{task_type.capitalize()}_Task_{calculate_timestamp(0)}_{index.format(i + 1)}"
|
|
383
|
+
task_comment = f"Generated by Random Report Generation Script Version {__version__}."
|
|
366
384
|
|
|
367
|
-
gmp.create_container_task(task_name)
|
|
385
|
+
gmp.create_container_task(name=task_name, comment=task_comment)
|
|
368
386
|
|
|
369
387
|
task_id = gmp.get_tasks(filter_string=f"name={task_name}").xpath(
|
|
370
388
|
"//@id"
|
|
371
389
|
)[0]
|
|
372
390
|
|
|
391
|
+
if task_type == "scan":
|
|
392
|
+
gmp.modify_task(task_id=task_id, alterable=1)
|
|
393
|
+
|
|
373
394
|
reports = generate_reports(task=(task_id, task_name), **kwargs)
|
|
374
395
|
|
|
375
396
|
for report in reports[0:]:
|
|
376
397
|
gmp.import_report(report, task_id=task_id, in_assets=True)
|
|
377
398
|
|
|
399
|
+
if task_type == "scan":
|
|
400
|
+
gmp.modify_task(
|
|
401
|
+
task_id=task_id,
|
|
402
|
+
target_id=target_id,
|
|
403
|
+
scanner_id=scanner_id,
|
|
404
|
+
config_id=config_id,
|
|
405
|
+
)
|
|
406
|
+
|
|
378
407
|
|
|
379
408
|
def main(gmp: Gmp, args: Namespace) -> None:
|
|
380
409
|
# pylint: disable=undefined-variable, line-too-long
|
|
@@ -388,8 +417,9 @@ def main(gmp: Gmp, args: Namespace) -> None:
|
|
|
388
417
|
epilog=textwrap.dedent(
|
|
389
418
|
"""
|
|
390
419
|
Example:
|
|
391
|
-
$ gvm-script --gmp-username name --gmp-password pass
|
|
392
|
-
|
|
420
|
+
$ gvm-script --gmp-username name --gmp-password pass \
|
|
421
|
+
ssh --hostname <gsm> scripts/gen-random-reports.gmp.py \
|
|
422
|
+
-T 5 -r 4 -R 3 --hosts 10
|
|
393
423
|
"""
|
|
394
424
|
),
|
|
395
425
|
)
|
|
@@ -473,6 +503,16 @@ def main(gmp: Gmp, args: Namespace) -> None:
|
|
|
473
503
|
"--seed", help="RNG Seed, in case the same data should be generated."
|
|
474
504
|
)
|
|
475
505
|
|
|
506
|
+
parser.add_argument(
|
|
507
|
+
"--task-type",
|
|
508
|
+
dest="task_type",
|
|
509
|
+
type=str,
|
|
510
|
+
choices=["container", "scan"],
|
|
511
|
+
default="container",
|
|
512
|
+
help="Type of Task(s) to store the generated Reports. Can either "
|
|
513
|
+
"be 'container' or 'scan', default: 'container'.",
|
|
514
|
+
)
|
|
515
|
+
|
|
476
516
|
script_args = parser.parse_args(args.script_args)
|
|
477
517
|
|
|
478
518
|
if not script_args.seed:
|
|
@@ -483,7 +523,7 @@ def main(gmp: Gmp, args: Namespace) -> None:
|
|
|
483
523
|
with open(str(script_args.datafile), encoding="utf-8") as file:
|
|
484
524
|
data = json.load(file)
|
|
485
525
|
|
|
486
|
-
print("\n Generating randomized data
|
|
526
|
+
print("\n Generating randomized data...\n")
|
|
487
527
|
|
|
488
528
|
generate_data(
|
|
489
529
|
gmp,
|
|
@@ -496,9 +536,10 @@ def main(gmp: Gmp, args: Namespace) -> None:
|
|
|
496
536
|
data=data,
|
|
497
537
|
with_gauss=script_args.with_gauss,
|
|
498
538
|
with_descriptions=script_args.with_descriptions,
|
|
539
|
+
task_type=script_args.task_type,
|
|
499
540
|
)
|
|
500
541
|
|
|
501
|
-
print("\n Generation
|
|
542
|
+
print("\n Generation completed.\n")
|
|
502
543
|
|
|
503
544
|
|
|
504
545
|
if __name__ == "__gmp__":
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
builtins = ["gmp", "args"]
|
|
@@ -40,7 +40,8 @@ def check_args(args: Namespace) -> None:
|
|
|
40
40
|
reports via email for selected tasks.
|
|
41
41
|
|
|
42
42
|
Example for starting up the routine:
|
|
43
|
-
$ gvm-script --gmp-username name --gmp-password pass ssh
|
|
43
|
+
$ gvm-script --gmp-username name --gmp-password pass ssh \
|
|
44
|
+
--hostname <gsm> scripts/send-delta-emails.gmp.py
|
|
44
45
|
|
|
45
46
|
The routine follows this procedure:
|
|
46
47
|
|
|
@@ -82,7 +83,7 @@ def execute_send_delta_emails(sc: sched.scheduler, **kwargs: dict) -> None:
|
|
|
82
83
|
print(f'Processing task "{task_name}" ({task_id})...')
|
|
83
84
|
|
|
84
85
|
reports = gmp.get_reports(
|
|
85
|
-
filter_string="task_id={task_id} and status=Done "
|
|
86
|
+
filter_string=f"task_id={task_id} and status=Done "
|
|
86
87
|
"sort-reverse=date"
|
|
87
88
|
).xpath("report")
|
|
88
89
|
print(f" Found {str(len(reports))} report(s).")
|
|
@@ -25,7 +25,7 @@ from gvm.protocols.gmp import Gmp
|
|
|
25
25
|
HELP_TEXT = """
|
|
26
26
|
This script makes an E-Mail alert scan.
|
|
27
27
|
|
|
28
|
-
Usage examples:
|
|
28
|
+
Usage examples:
|
|
29
29
|
$ gvm-script --gmp-username name --gmp-password pass ssh --hostname
|
|
30
30
|
... start-alert-scan.gmp.py +h
|
|
31
31
|
... start-alert-scan.gmp.py ++target-name ++hosts ++ports \
|
|
@@ -114,7 +114,7 @@ def get_target(
|
|
|
114
114
|
if port_list_name in existing_port_lists:
|
|
115
115
|
counter = 0
|
|
116
116
|
while True:
|
|
117
|
-
tmp_name = "{port_list_name} ({str(counter)})"
|
|
117
|
+
tmp_name = f"{port_list_name} ({str(counter)})"
|
|
118
118
|
if tmp_name in existing_port_lists:
|
|
119
119
|
counter += 1
|
|
120
120
|
else:
|
|
@@ -177,7 +177,7 @@ should not have received it.
|
|
|
177
177
|
},
|
|
178
178
|
)
|
|
179
179
|
|
|
180
|
-
alert_object = gmp.get_alerts(filter_string="name={recipient_email}")
|
|
180
|
+
alert_object = gmp.get_alerts(filter_string=f"name={recipient_email}")
|
|
181
181
|
alert = alert_object.xpath("alert")
|
|
182
182
|
|
|
183
183
|
alert_id = alert[0].get("id", "no id found")
|
|
@@ -204,7 +204,7 @@ def create_and_start_task(
|
|
|
204
204
|
) -> str:
|
|
205
205
|
# Create the task
|
|
206
206
|
task_name = f"Alert Scan for Alert {alert_name}"
|
|
207
|
-
tasks = gmp.get_tasks(filter_string='name="{task_name}"')
|
|
207
|
+
tasks = gmp.get_tasks(filter_string=f'name="{task_name}"')
|
|
208
208
|
existing_tasks = tasks.findall("task")
|
|
209
209
|
|
|
210
210
|
if existing_tasks:
|
|
@@ -32,10 +32,11 @@ def check_args(args):
|
|
|
32
32
|
|
|
33
33
|
1. <sender_email> -- E-Mail of the sender
|
|
34
34
|
2. <receiver_email> -- E-Mail of the receiver
|
|
35
|
-
|
|
35
|
+
|
|
36
36
|
Example:
|
|
37
37
|
$ gvm-script --gmp-username name --gmp-password pass \
|
|
38
|
-
ssh --hostname <gsm> scripts/start-multiple-alert-scan.gmp.py
|
|
38
|
+
ssh --hostname <gsm> scripts/start-multiple-alert-scan.gmp.py \
|
|
39
|
+
<sender_email> <receiver_email>
|
|
39
40
|
"""
|
|
40
41
|
if len_args != 2:
|
|
41
42
|
print(message)
|
|
@@ -30,7 +30,8 @@ def check_args(args):
|
|
|
30
30
|
This script reads host data from a csv file and sync it with the gsm.
|
|
31
31
|
It needs one parameters after the script name.
|
|
32
32
|
|
|
33
|
-
1. <csv_file> - should contain a table of IP-addresses with an
|
|
33
|
+
1. <csv_file> - should contain a table of IP-addresses with an
|
|
34
|
+
optional a comment
|
|
34
35
|
|
|
35
36
|
Example:
|
|
36
37
|
$ gvm-script --gmp-username name --gmp-password pass \
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
from importlib.util import module_from_spec, spec_from_file_location
|
|
20
20
|
from pathlib import Path
|
|
21
21
|
from typing import Union
|
|
22
|
-
from unittest.mock import MagicMock, create_autospec
|
|
22
|
+
from unittest.mock import MagicMock, create_autospec
|
|
23
23
|
|
|
24
24
|
from gvm.protocols.latest import Gmp
|
|
25
25
|
from lxml import etree
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|