From 48630c41b5dcf7e33b9d1dad3eb6704f7cc9d87e Mon Sep 17 00:00:00 2001 From: jstach Date: Mon, 9 Sep 2019 13:35:29 +0200 Subject: [PATCH 01/31] changed create_report to import_report (as in greenbone/python-gvm) --- scripts/combine-reports.gmp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/combine-reports.gmp b/scripts/combine-reports.gmp index 3e2d5796..fce054ea 100644 --- a/scripts/combine-reports.gmp +++ b/scripts/combine-reports.gmp @@ -93,7 +93,7 @@ def send_report(gmp, args, report): report = e.tostring(report) - gmp.create_report(report, task_id=task_id, task_name=task_name) + gmp.import_report(report, task_id=task_id, task_name=task_name) def main(): From a25a7e700f13e1d015680b1e6a6b4d3cb5fd0adc Mon Sep 17 00:00:00 2001 From: jstach Date: Mon, 9 Sep 2019 13:41:45 +0200 Subject: [PATCH 02/31] removed dropped arg make_unique --- scripts/nvt-scan.gmp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/nvt-scan.gmp b/scripts/nvt-scan.gmp index b779d351..81c3d458 100644 --- a/scripts/nvt-scan.gmp +++ b/scripts/nvt-scan.gmp @@ -72,7 +72,7 @@ def create_config(gmp, nvt_oid): def create_target(gmp, name): try: - res = gmp.create_target(name, make_unique=True, hosts=[name]) + res = gmp.create_target(name, hosts=[name]) target_id = res.xpath('@id')[0] except GvmError: res = gmp.get_targets(filter='name=%s hosts=%s' % (name, name)) From e8b0b061528383b865432f0668deef2921831dda Mon Sep 17 00:00:00 2001 From: jstach Date: Mon, 9 Sep 2019 15:12:50 +0200 Subject: [PATCH 03/31] removed the make_unique arg, corrected port_list to port_list_id, changed alive_tests to alive_test --- scripts/send-targets.gmp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/scripts/send-targets.gmp b/scripts/send-targets.gmp index 28700a72..482c1425 100644 --- a/scripts/send-targets.gmp +++ b/scripts/send-targets.gmp @@ -78,7 +78,7 @@ def parse_send_xml_tree(gmp, xml_tree): counter = 1 for target in xml_tree.xpath('target'): - keywords = {'make_unique': True} + keywords = {}#{'make_unique': True} keywords['name'] = target.find('name').text @@ -118,9 +118,10 @@ def parse_send_xml_tree(gmp, xml_tree): keywords[credential] = temp_dict - alive_tests = target.find('alive_tests').text - if alive_tests is not None: - keywords['alive_tests'] = alive_tests + alive_test = target.find('alive_test') + + if alive_test is not None: + keywords['alive_test'] = alive_test reverse_lookup_only = target.find('reverse_lookup_only').text if reverse_lookup_only == '1': @@ -136,8 +137,10 @@ def parse_send_xml_tree(gmp, xml_tree): if target.xpath('port_list/@id') is not None: port_list = {} - port_list['id'] = target.xpath('port_list/@id')[0] - keywords['port_list'] = port_list + port_list = target.xpath('port_list/@id')[0] + keywords['port_list_id'] = port_list + + print(keywords) gmp.create_target(**keywords) From 783d9c906039a16d0718b4c6d50147d50d0b80aa Mon Sep 17 00:00:00 2001 From: jstach Date: Mon, 9 Sep 2019 15:25:27 +0200 Subject: [PATCH 04/31] schedule_periode is not a required attribute in the xml and NoneType has no attribute text. So a check if this attribute exists should work here --- scripts/send-tasks.gmp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/send-tasks.gmp b/scripts/send-tasks.gmp index a91b2ea5..5a352e4c 100644 --- a/scripts/send-tasks.gmp +++ b/scripts/send-tasks.gmp @@ -145,7 +145,7 @@ def parse_send_xml_tree(gmp, xml_tree): mod_keywords = {'task_id': new_task.xpath('//@id')[0]} - if task.find('schedule_periods').text != 0: + if task.find('schedule_periods') is not None: mod_keywords['schedule_periods'] = int( task.find('schedule_periods').text ) From 8a74a9d322295ac9d9ec18c802426e906b047210 Mon Sep 17 00:00:00 2001 From: jstach Date: Mon, 9 Sep 2019 15:34:05 +0200 Subject: [PATCH 05/31] Added the required positional argument 'credential_type' --- scripts/create-dummy-data.gmp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/scripts/create-dummy-data.gmp b/scripts/create-dummy-data.gmp index f8d4253a..61856a42 100644 --- a/scripts/create-dummy-data.gmp +++ b/scripts/create-dummy-data.gmp @@ -19,6 +19,9 @@ import random import string +from gvm.protocols.gmpv8 import CredentialType + + def id_generator(size=12, chars=string.ascii_uppercase + string.digits): return ''.join(random.choice(chars) for _ in range(size)) @@ -30,7 +33,7 @@ def create_data(gmp, count): for _ in range(0, count): name = id_generator() - gmp.create_credential(name, login=name, password=name) + gmp.create_credential(name, login=name, password=name, credential_type=CredentialType.PASSWORD_ONLY) for _ in range(0, count): name = id_generator() @@ -59,7 +62,7 @@ def create_data(gmp, count): def main(): # pylint: disable=undefined-variable - count = 50 + count = 50 #TODO: Maybe make this an optional argument?! create_data(gmp, count) From c490a5e60364c225a55fd35b8b7b19a0c1015d5a Mon Sep 17 00:00:00 2001 From: jstach Date: Mon, 9 Sep 2019 15:39:26 +0200 Subject: [PATCH 06/31] Used new AssetType ENUM for asset_type --- scripts/monthly-report2.gmp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/monthly-report2.gmp b/scripts/monthly-report2.gmp index 9942a316..29a1e28f 100644 --- a/scripts/monthly-report2.gmp +++ b/scripts/monthly-report2.gmp @@ -18,6 +18,8 @@ from datetime import date, timedelta +from gvm.protocols.gmpv7 import AssetType + from terminaltables import AsciiTable @@ -44,7 +46,7 @@ def print_reports(gmp, from_date, to_date): from_date.isoformat(), to_date.isoformat() ) - assets_xml = gmp.get_assets(asset_type='host', filter=asset_filter) + assets_xml = gmp.get_assets(asset_type=AssetType.HOST, filter=asset_filter) sum_high = 0 sum_medium = 0 From 7cbcc6481a6baff89b15aeff05945c23b453780e Mon Sep 17 00:00:00 2001 From: jstach Date: Mon, 9 Sep 2019 16:33:41 +0200 Subject: [PATCH 07/31] changed for gvm8 ical support --- scripts/send-schedules.gmp | 40 ++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/scripts/send-schedules.gmp b/scripts/send-schedules.gmp index d0d06fd7..66df3346 100644 --- a/scripts/send-schedules.gmp +++ b/scripts/send-schedules.gmp @@ -20,6 +20,12 @@ import sys from lxml import etree as e +from icalendar import Calendar, Event +import pytz +from datetime import (datetime, timedelta) + +from gvm.protocols.gmpv7 import TimeUnit + import dateutil.parser @@ -71,36 +77,28 @@ def parse_send_xml_tree(gmp, xml_tree): if comment is None: comment = '' - first_time = {} f_time = schedule.find('first_time').text f_time = dateutil.parser.parse(f_time) - first_time['day_of_month'] = f_time.day - first_time['hour'] = f_time.hour - first_time['minute'] = f_time.minute - first_time['month'] = f_time.month - first_time['year'] = f_time.year - - duration = schedule.find('simple_duration').text - duration_unit = schedule.find('simple_duration').find('unit').text - period = schedule.find('simple_period').text - period_unit = schedule.find('simple_period').find('unit').text + ical = schedule.find('icalendar').text timezone_abbrev = schedule.find('timezone_abbrev').text + cal = Calendar() + cal.add('prodid', '-//Foo Bar//') + cal.add('version', '2.0') + event = Event() + event.add('dtstamp', datetime.now(tz=pytz.UTC)) + event.add('dtstart', datetime(f_time.year, f_time.month, f_time.day, f_time.hour, f_time.minute, f_time.second, tzinfo=pytz.utc)) + + cal.add_component(event) + + gmp.create_schedule( name=name, - first_time_minute=f_time.minute, - first_time_hour=f_time.hour, - first_time_day_of_month=f_time.day, - first_time_month=f_time.month, - first_time_year=f_time.year, - duration=duration, - duration_unit=duration_unit, - period=period, - period_unit=period_unit, comment=comment, timezone=timezone_abbrev, + icalendar=ical ) @@ -109,7 +107,7 @@ def main(): check_args(args) - xml_doc = args.script[2] + xml_doc = args.script[1] print('\nSending schedules...') From 580681844acc26892bfd75034966c5f2efdb4feb Mon Sep 17 00:00:00 2001 From: jstach Date: Mon, 9 Sep 2019 16:34:18 +0200 Subject: [PATCH 08/31] changed for gvm8 ical support --- scripts/send-schedules.gmp | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/scripts/send-schedules.gmp b/scripts/send-schedules.gmp index 66df3346..d99a70b7 100644 --- a/scripts/send-schedules.gmp +++ b/scripts/send-schedules.gmp @@ -20,12 +20,6 @@ import sys from lxml import etree as e -from icalendar import Calendar, Event -import pytz -from datetime import (datetime, timedelta) - -from gvm.protocols.gmpv7 import TimeUnit - import dateutil.parser @@ -84,16 +78,6 @@ def parse_send_xml_tree(gmp, xml_tree): timezone_abbrev = schedule.find('timezone_abbrev').text - cal = Calendar() - cal.add('prodid', '-//Foo Bar//') - cal.add('version', '2.0') - event = Event() - event.add('dtstamp', datetime.now(tz=pytz.UTC)) - event.add('dtstart', datetime(f_time.year, f_time.month, f_time.day, f_time.hour, f_time.minute, f_time.second, tzinfo=pytz.utc)) - - cal.add_component(event) - - gmp.create_schedule( name=name, comment=comment, From 93b0242b93a4cc3f46cdcdf248271319dad1b57f Mon Sep 17 00:00:00 2001 From: jstach Date: Mon, 9 Sep 2019 16:58:07 +0200 Subject: [PATCH 09/31] WiP: removed make_unique, added AlertCondition, etc. ENUMS --- scripts/start-alert-scan.gmp | 9 +++++---- scripts/start-multiple-alerts-scan.gmp | 10 ++++++---- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/scripts/start-alert-scan.gmp b/scripts/start-alert-scan.gmp index a1e6faeb..31fc3ab8 100644 --- a/scripts/start-alert-scan.gmp +++ b/scripts/start-alert-scan.gmp @@ -16,6 +16,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +from gvm.protocols.gmpv8 import AlertCondition, AlertEvent, AlertMethod def check_args(args): len_args = len(args.script) - 1 @@ -123,7 +124,7 @@ def get_target(gmp, debug=False): # integrate port list id into create_target res = gmp.create_target( - target_name, make_unique=True, hosts=hosts, port_list_id=portlist_id + target_name, hosts=hosts, port_list_id=portlist_id ) return res.xpath('@id')[0] @@ -141,10 +142,10 @@ def get_alert(gmp, sender_email, recipient_email, debug=False): print("creating alert") gmp.create_alert( alert_name, - event="Always", - condition="Task run status changed", + event=AlertEvent.TASK_RUN_STATUS_CHANGED, + condition=AlertCondition.ALWAYS, condition_data={"status": "Done"}, - method="Email", + method=AlertMethod.EMAIL, method_data={ """Task '$n': $e diff --git a/scripts/start-multiple-alerts-scan.gmp b/scripts/start-multiple-alerts-scan.gmp index f581f5dc..2e41c167 100644 --- a/scripts/start-multiple-alerts-scan.gmp +++ b/scripts/start-multiple-alerts-scan.gmp @@ -16,10 +16,12 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +from gvm.protocols.gmpv8 import AlertCondition, AlertEvent, AlertMethod def check_args(args): len_args = len(args.script) - 1 message = """ + TODO? """ if len_args != 2: print(message) @@ -124,7 +126,7 @@ def get_target(gmp, debug=False): # integrate port list id into create_target res = gmp.create_target( - target_name, make_unique=True, hosts=hosts, port_list_id=portlist_id + target_name, hosts=hosts, port_list_id=portlist_id ) return res.xpath('@id')[0] @@ -141,10 +143,10 @@ def get_alerts(gmp, sender_email, recipient_email, debug=False): print("creating alert") gmp.create_alert( alert_name, - event="Always", - condition="Task run status changed", + event=AlertEvent.TASK_RUN_STATUS_CHANGED, + condition=AlertCondition.ALWAYS, condition_data={"status": "Done"}, - method="Email", + method=AlertMethod.EMAIL, method_data={ """Task '$n': $e From 136c86eeda3c8087fda3512f44395e606c54a44c Mon Sep 17 00:00:00 2001 From: jstach Date: Mon, 9 Sep 2019 17:03:34 +0200 Subject: [PATCH 10/31] changed positional argument into named argument --- scripts/clean-sensor.gmp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/scripts/clean-sensor.gmp b/scripts/clean-sensor.gmp index d56533bb..12e48f26 100644 --- a/scripts/clean-sensor.gmp +++ b/scripts/clean-sensor.gmp @@ -25,32 +25,32 @@ def clean_sensor(gmp): ) for tid in tasks.xpath('task/@id'): - print('Removing task %s... ' % tid) - status_text = gmp.delete_task(tid, True).xpath('@status_text')[0] + print('Removing task %s ... ' % tid) + status_text = gmp.delete_task(tid, ultimate=True).xpath('@status_text')[0] print(status_text) targets = gmp.get_targets(filter="rows=-1 not _owner=""") for tid in targets.xpath('target/@id'): - print('Removing target %s... ' % tid) - status_text = gmp.delete_target(tid, True).xpath('@status_text')[0] + print('Removing target %s ... ' % tid) + status_text = gmp.delete_target(tid, ultimate=True).xpath('@status_text')[0] print(status_text) configs = gmp.get_configs(filter="rows=-1 not _owner=""") for cid in configs.xpath('config/@id'): - print('Removing config %s... ' % cid) - status_text = gmp.delete_config(cid, True).xpath('@status_text')[0] + print('Removing config %s ... ' % cid) + status_text = gmp.delete_config(cid, ultimate=True).xpath('@status_text')[0] print(status_text) port_lists = gmp.get_port_lists(filter="rows=-1 not _owner=""") for pid in port_lists.xpath('port_list/@id'): - print('Removing port_list %s... ' % pid) - status_text = gmp.delete_port_list(pid, True).xpath('@status_text')[0] + print('Removing port_list %s ... ' % pid) + status_text = gmp.delete_port_list(pid, ultimate=True).xpath('@status_text')[0] print(status_text) credentials = gmp.get_credentials(filter="rows=-1 not _owner=""") for cid in credentials.xpath('credential/@id'): - print('Removing credential %s... ' % cid) - status_text = gmp.delete_credential(cid, True).xpath('@status_text')[0] + print('Removing credential %s ... ' % cid) + status_text = gmp.delete_credential(cid, ultimate=True).xpath('@status_text')[0] print(status_text) print('Emptying trash... ') From 1be107b0ca85e3c4a84df4447e72ffea1684d601 Mon Sep 17 00:00:00 2001 From: jstach Date: Thu, 12 Sep 2019 09:38:44 +0200 Subject: [PATCH 11/31] removed hardcoded count and replaced with argument, added Output, added check_args and help --- scripts/create-dummy-data.gmp | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/scripts/create-dummy-data.gmp b/scripts/create-dummy-data.gmp index 61856a42..3432f0b4 100644 --- a/scripts/create-dummy-data.gmp +++ b/scripts/create-dummy-data.gmp @@ -21,7 +21,20 @@ import string from gvm.protocols.gmpv8 import CredentialType +def check_args(args): + len_args = len(args.script) - 1 + if len_args is not 1: + message = """ + This script will create random data for the given GVM database + 1. -- Number of datasets to create + + Example: + $ gvm-script gvm-script --gmp-username name --gmp-password pass \ + ssh --hostname scripts/create-dummy-data.gmp + """ + print(message) + quit() def id_generator(size=12, chars=string.ascii_uppercase + string.digits): return ''.join(random.choice(chars) for _ in range(size)) @@ -34,21 +47,25 @@ def create_data(gmp, count): for _ in range(0, count): name = id_generator() gmp.create_credential(name, login=name, password=name, credential_type=CredentialType.PASSWORD_ONLY) + print(str(count) + ' random credentials generated.') for _ in range(0, count): name = id_generator() gmp.create_port_list(name, port_range='T:1-42') + print(str(count) + ' random port lists generated.') for _ in range(0, count): name = id_generator() res = gmp.create_config('085569ce-73ed-11df-83c3-002264764cea', name) config_ids.append(res.xpath('@id')[0]) + print(str(count) + ' random scan configs generated.') for _ in range(0, count): name = id_generator() res = gmp.create_target(name, hosts=['127.0.0.1']) target_ids.append(res.xpath('@id')[0]) + print(str(count) + ' random targets generated.') for _ in range(0, count): name = id_generator() @@ -57,14 +74,15 @@ def create_data(gmp, count): gmp.create_task( name, config_id, target_id, '08b69003-5fc2-4037-a479-93b440211c73' ) + print(str(count) + ' random tasks generated.') def main(): # pylint: disable=undefined-variable - count = 50 #TODO: Maybe make this an optional argument?! + check_args(args) - create_data(gmp, count) + create_data(gmp, int(args.script[1])) if __name__ == '__gmp__': From 900ecb22078b7334101da929b8681551541e8472 Mon Sep 17 00:00:00 2001 From: jstach Date: Thu, 12 Sep 2019 09:39:39 +0200 Subject: [PATCH 12/31] replaced userinput with argument, added check_args and help --- scripts/application-detection.gmp | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/scripts/application-detection.gmp b/scripts/application-detection.gmp index 0063e30f..1491c3cd 100644 --- a/scripts/application-detection.gmp +++ b/scripts/application-detection.gmp @@ -17,6 +17,21 @@ # along with this program. If not, see . +def check_args(args): + len_args = len(args.script) - 1 + if len_args is not 1: + message = """ + This script will display all hosts with the searched applications! + + 1. -- Name of the application + + Example: + $ gvm-script gvm-script --gmp-username name --gmp-password pass \ + ssh --hostname scripts/application-detection.gmp + """ + print(message) + quit() + def print_assets(gmp, appname): res = gmp.get_reports() @@ -43,16 +58,7 @@ def print_assets(gmp, appname): def main(): # pylint: disable=undefined-variable - message = """ - This script will display all hosts with the searched applications! - - Example: - $ gvm-pyshell socket scripts/application-detection.gmp - """ - print(message) - - appname = input('What application are you looking for? ') - print('') + check_args(args) print_assets(gmp, appname) From f46c465b4dd66759247e0252c515f398a8f3dae8 Mon Sep 17 00:00:00 2001 From: jstach Date: Thu, 12 Sep 2019 09:41:38 +0200 Subject: [PATCH 13/31] Updated for gvm8 support, updated help message --- scripts/cfg-gen-for-certs.gmp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/scripts/cfg-gen-for-certs.gmp b/scripts/cfg-gen-for-certs.gmp index e6897cb8..65c0fe3f 100644 --- a/scripts/cfg-gen-for-certs.gmp +++ b/scripts/cfg-gen-for-certs.gmp @@ -17,6 +17,7 @@ # along with this program. If not, see . from gvm.errors import GvmError +from gvm.protocols.gmpv8 import InfoType def check_args(args): @@ -29,14 +30,15 @@ def check_args(args): 1. Name or ID of the CERT-Bund Example: - $ gvm-pyshell socket scripts/cfg-gen-for-certs.gmp CB-K16/0943 + $ gvm-script gvm-script --gmp-username name --gmp-password pass \ + ssh --hostname scripts/cfg-gen-for-certs.gmp CB-K16/0943 """ print(message) quit() def create_config(gmp, cert_bund_name): - cert_bund_details = gmp.get_info(cert_bund_name, 'CERT_BUND_ADV') + cert_bund_details = gmp.get_info(info_id=cert_bund_name, info_type=InfoType.CERT_BUND_ADV) list_cves = cert_bund_details.xpath( 'info/cert_bund_adv/raw_data/Advisory/CVEList/CVE/text()' @@ -47,7 +49,7 @@ def create_config(gmp, cert_bund_name): for cve in list_cves: # Get all nvts of this cve - cve_info = gmp.get_info(cve, 'CVE') + cve_info = gmp.get_info(info_id=cve, info_type=InfoType.CVE) nvts = cve_info.xpath('info/cve/nvts/nvt') for nvt in nvts: @@ -77,8 +79,6 @@ def create_config(gmp, cert_bund_name): for family, nvt_oid in nvt_dict.items(): gmp.modify_config( config_id, - 'nvt_selection', - name=config_name, nvt_oids=nvt_oid, family=family, ) @@ -87,7 +87,7 @@ def create_config(gmp, cert_bund_name): family = 'Port scanners' nvts = ['1.3.6.1.4.1.25623.1.0.14259', '1.3.6.1.4.1.25623.1.0.100315'] gmp.modify_config( - config_id, 'nvt_selection', nvt_oids=nvts, family=family + config_id=config_id, nvt_oids=nvts, family=family ) except GvmError: From 7a40b56e1c8f0bdaf336f65ba068b842dd47ba04 Mon Sep 17 00:00:00 2001 From: jstach Date: Thu, 12 Sep 2019 09:53:28 +0200 Subject: [PATCH 14/31] removed obsolete import, updated help message --- scripts/send-schedules.gmp | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/scripts/send-schedules.gmp b/scripts/send-schedules.gmp index d99a70b7..f0c07cba 100644 --- a/scripts/send-schedules.gmp +++ b/scripts/send-schedules.gmp @@ -20,9 +20,6 @@ import sys from lxml import etree as e -import dateutil.parser - - def check_args(args): len_args = len(args.script) - 1 if len_args is not 1: @@ -34,11 +31,9 @@ def check_args(args): 1. -- .xml file containing schedules Example: - $ gvm-pyshell ssh --hostname=hostname --gmp-username=name \ - --gmp-password=pass scripts/send-schedules.gmp targethost example_file.xml + $ gvm-script gvm-script --gmp-username name --gmp-password pass \ + ssh --hostname scripts/send-schedules.gmp targethost example_file.xml - Note: In order to use this script python-dateutil must first be installed: - $ pip install python-dateutil """ print(message) quit() @@ -71,9 +66,6 @@ def parse_send_xml_tree(gmp, xml_tree): if comment is None: comment = '' - f_time = schedule.find('first_time').text - f_time = dateutil.parser.parse(f_time) - ical = schedule.find('icalendar').text timezone_abbrev = schedule.find('timezone_abbrev').text From 687a83511794fd29ccbd45460b6471e7fb19e9b1 Mon Sep 17 00:00:00 2001 From: jstach Date: Thu, 12 Sep 2019 10:48:25 +0200 Subject: [PATCH 15/31] workarround for a bug see https://github.com/CxAalto/gtfspy/commit/8d05c3c94a6d4ca3ed675d88af93def7d5053bfe --- scripts/check-gmp.gmp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/scripts/check-gmp.gmp b/scripts/check-gmp.gmp index 07c22286..38b1ca64 100644 --- a/scripts/check-gmp.gmp +++ b/scripts/check-gmp.gmp @@ -263,8 +263,9 @@ class InstanceManager: """ logger.debug("Delete entry with ip: %s", ip) self.cursor.execute("DELETE FROM Report WHERE host=?", (ip,)) + self.con_db.isolation_level = None self.cursor.execute("VACUUM") - + self.con_db.isolation_level = '' # see: https://github.com/CxAalto/gtfspy/commit/8d05c3c94a6d4ca3ed675d88af93def7d5053bfe # Save the changes self.con_db.commit() @@ -1185,7 +1186,7 @@ def parse_date(datestring, default_timezone=UTC): raise ParseError(e) -def main(): +def main(gmp, args): tmp_path = "%s/check_gmp/" % tempfile.gettempdir() tmp_path_db = tmp_path + "reports.db" @@ -1202,7 +1203,10 @@ def main(): ) parser.add_argument( - "-H", action="help", help="Show this help message and exit." + "-H", + "--help", + action="help", + help="Show this help message and exit." ) parser.add_argument( @@ -1403,4 +1407,4 @@ def main(): if __name__ == "__gmp__": - main() + main(gmp, args) From d82875f9112188ef23f554e41d4e65cc5a08b273 Mon Sep 17 00:00:00 2001 From: jstach Date: Thu, 12 Sep 2019 12:20:57 +0200 Subject: [PATCH 16/31] edited main(), updated help, other minor fixes --- scripts/application-detection.gmp | 4 +-- scripts/cfg-gen-for-certs.gmp | 4 +-- scripts/check-gmp.gmp | 1 - scripts/clean-sensor.gmp | 4 +-- scripts/combine-reports.gmp | 8 ++--- scripts/create-dummy-data.gmp | 4 +-- scripts/create-targets-from-host-list.gmp | 23 ++++++------- scripts/delete-overrides-by-filter.gmp | 10 +++--- scripts/gen-random-targets.gmp | 12 +++---- scripts/monthly-report.gmp | 14 ++++---- scripts/monthly-report2.gmp | 6 ++-- scripts/nvt-scan.gmp | 4 +-- scripts/pdf-report.gmp | 40 ++++++++++++++++++----- scripts/random-report-gen.gmp | 8 ++--- scripts/send-delta-emails.gmp | 14 ++++---- scripts/send-schedules.gmp | 4 +-- scripts/send-targets.gmp | 8 ++--- scripts/send-tasks.gmp | 10 +++--- scripts/start-alert-scan.gmp | 4 +-- scripts/start-multiple-alerts-scan.gmp | 4 +-- scripts/start-nvt-scan.gmp | 6 ++-- scripts/sync-assets.gmp | 32 +++++++----------- scripts/update-task-target.gmp | 18 +++++----- 23 files changed, 132 insertions(+), 110 deletions(-) diff --git a/scripts/application-detection.gmp b/scripts/application-detection.gmp index 1491c3cd..23272304 100644 --- a/scripts/application-detection.gmp +++ b/scripts/application-detection.gmp @@ -55,7 +55,7 @@ def print_assets(gmp, appname): print('\n') -def main(): +def main(gmp, args): # pylint: disable=undefined-variable check_args(args) @@ -64,4 +64,4 @@ def main(): if __name__ == '__gmp__': - main() + main(gmp, args) diff --git a/scripts/cfg-gen-for-certs.gmp b/scripts/cfg-gen-for-certs.gmp index 65c0fe3f..5b8b38ff 100644 --- a/scripts/cfg-gen-for-certs.gmp +++ b/scripts/cfg-gen-for-certs.gmp @@ -94,7 +94,7 @@ def create_config(gmp, cert_bund_name): print('Config exist') -def main(): +def main(gmp, args): # pylint: disable=undefined-variable check_args(args) @@ -107,4 +107,4 @@ def main(): if __name__ == '__gmp__': - main() + main(gmp, args) diff --git a/scripts/check-gmp.gmp b/scripts/check-gmp.gmp index 38b1ca64..573bc62e 100644 --- a/scripts/check-gmp.gmp +++ b/scripts/check-gmp.gmp @@ -1204,7 +1204,6 @@ def main(gmp, args): parser.add_argument( "-H", - "--help", action="help", help="Show this help message and exit." ) diff --git a/scripts/clean-sensor.gmp b/scripts/clean-sensor.gmp index 12e48f26..5037fb5a 100644 --- a/scripts/clean-sensor.gmp +++ b/scripts/clean-sensor.gmp @@ -58,7 +58,7 @@ def clean_sensor(gmp): print(status_text) -def main(): +def main(gmp, args): # pylint: disable=undefined-variable message = """ @@ -71,4 +71,4 @@ def main(): if __name__ == '__gmp__': - main() + main(gmp, args) diff --git a/scripts/combine-reports.gmp b/scripts/combine-reports.gmp index fce054ea..e6ededfa 100644 --- a/scripts/combine-reports.gmp +++ b/scripts/combine-reports.gmp @@ -39,8 +39,8 @@ def check_args(args): n. --uuid of report to be combined Example for starting up the routine: - $ gvm-pyshell ssh --hostname=hostname --gmp-username=name \ - --gmp-password=pass scripts/gsm-updater.gmp \ + $ gvm-script --gmp-username=namessh --gmp-password=pass ssh --hostname=hostname \ + scripts/gsm-updater.gmp \ "d15a337c-56f3-4208-a462-afeb79eb03b7" \ "303fa0a6-aa9b-43c4-bac0-66ae0b2d1698" 'first_task' @@ -96,7 +96,7 @@ def send_report(gmp, args, report): gmp.import_report(report, task_id=task_id, task_name=task_name) -def main(): +def main(gmp, args): # pylint: disable=undefined-variable check_args(args) @@ -105,4 +105,4 @@ def main(): if __name__ == '__gmp__': - main() + main(gmp, args) diff --git a/scripts/create-dummy-data.gmp b/scripts/create-dummy-data.gmp index 3432f0b4..7cf4c75b 100644 --- a/scripts/create-dummy-data.gmp +++ b/scripts/create-dummy-data.gmp @@ -77,7 +77,7 @@ def create_data(gmp, count): print(str(count) + ' random tasks generated.') -def main(): +def main(gmp, args): # pylint: disable=undefined-variable check_args(args) @@ -86,4 +86,4 @@ def main(): if __name__ == '__gmp__': - main() + main(gmp, args) diff --git a/scripts/create-targets-from-host-list.gmp b/scripts/create-targets-from-host-list.gmp index 2dcefd9e..b53d78d3 100644 --- a/scripts/create-targets-from-host-list.gmp +++ b/scripts/create-targets-from-host-list.gmp @@ -22,18 +22,19 @@ import time def check_args(args): len_args = len(args.script) - 1 - if len_args is not 1: + if len_args is not 2: message = """ This script pulls hostnames from a text file and creates a target \ - for each. +for each. One parameter after the script name is required. - 1. -- text file containing hostnames + 1. -- IP of the GVM host + 2. -- text file containing hostnames Example: - $ gvm-pyshell ssh --hostname=hostname --gmp-username=name \ - --gmp-password=pass scripts/create_targets_from_host_list.gmp \ - example_host_textfile + $ gvm-script gvm-script --gmp-username name --gmp-password pass \ +ssh --hostname scripts/create_targets_from_host_list.gmp \ + """ print(message) quit() @@ -68,17 +69,17 @@ def send_targets(gmp, host_name, host_file, host_list): hosts = [host] gmp.create_target( - name=name, make_unique=True, comment=comment, hosts=hosts + name=name, comment=comment, hosts=hosts ) -def main(): +def main(gmp, args): # pylint: disable=undefined-variable check_args(args) - hostname = args.hostname - hostfile = args.script[1] + hostname = args.script[1] + hostfile = args.script[2] hostlist = load_host_list(hostfile) send_targets(gmp, hostname, hostfile, hostlist) @@ -87,4 +88,4 @@ def main(): if __name__ == '__gmp__': - main() + main(gmp, args) diff --git a/scripts/delete-overrides-by-filter.gmp b/scripts/delete-overrides-by-filter.gmp index d32aa852..26a05b04 100644 --- a/scripts/delete-overrides-by-filter.gmp +++ b/scripts/delete-overrides-by-filter.gmp @@ -26,11 +26,11 @@ def check_args(args): message = """ This script deletes overrides with a specific filter value - It only needs one parameter for the filter. + -- the parameter for the filter. Example: - $ gvm-pyshell ssh --hostname --gmp-username name \ - --gmp-password pass scripts/DeleteOverridesByFilter.gmp + $ gvm-script --gmp-username name --gmp-password pass \ + ssh --hostname scripts/delete-overrides-by-filter.gmp """ print(message) quit() @@ -54,7 +54,7 @@ def delete_overrides(gmp, filter_value): time.sleep(60) -def main(): +def main(gmp, args): # pylint: disable=undefined-variable check_args(args) @@ -65,4 +65,4 @@ def main(): if __name__ == '__gmp__': - main() + main(gmp, args) diff --git a/scripts/gen-random-targets.gmp b/scripts/gen-random-targets.gmp index bc0e109a..62a0af49 100644 --- a/scripts/gen-random-targets.gmp +++ b/scripts/gen-random-targets.gmp @@ -27,15 +27,15 @@ def check_args(args): a desired GSM It needs two parameters after the script name. - 1. --number of dummy hosts to select from - 2. --number of targets to be generated + 1. -- number of dummy hosts to select from + 2. -- number of targets to be generated In addition, if you would like for the number of targets generated to be randomized on a Gaussian distribution, add 'with-gauss' Example: - $ gvm-pyshell ssh --hostname=hostname --gmp-username=name \ - --gmp-password=pass scripts/gen-random-tasks.gmp 3 40 with-gauss + $ gvm-script gvm-script --gmp-username name --gmp-password pass \ + ssh --hostname scripts/gen-random-tasks.gmp 3 40 with-gauss """ print(message) quit() @@ -70,7 +70,7 @@ def generate(gmp, args, n_targets, n_ips): gmp.create_target(name=name, make_unique=True, hosts=[host_ip]) -def main(): +def main(gmp, args): # pylint: disable=undefined-variable check_args(args) @@ -84,4 +84,4 @@ def main(): if __name__ == '__gmp__': - main() + main(gmp, args) diff --git a/scripts/monthly-report.gmp b/scripts/monthly-report.gmp index 4479cdab..74a06d34 100644 --- a/scripts/monthly-report.gmp +++ b/scripts/monthly-report.gmp @@ -27,14 +27,16 @@ def check_args(args): message = """ This script will display all vulnerabilities from the hosts of the reports in a given month! - It needs two parameters and has one optional after the script name. - First one is the month and second one is the year. - Both parameters are plain numbers, so no text. + + 1. -- month of the monthly report + 2. -- year of the monthly report + The third is 'with-tables' parameter to activate a verbose output of hosts. Explicitly made for GOS 3.1. Example: - $ gvm-pyshell scripts/monthly-report.gmp 05 2017 with-tables + $ gvm-script gvm-script --gmp-username name --gmp-password pass \ + ssh --hostname scripts/monthly-report.gmp 05 2017 with-tables """ print(message) quit() @@ -108,7 +110,7 @@ def print_reports(gmp, args, from_date, to_date): ) -def main(): +def main(gmp, args): # pylint: disable=undefined-variable check_args(args) @@ -124,4 +126,4 @@ def main(): if __name__ == '__gmp__': - main() + main(gmp, args) diff --git a/scripts/monthly-report2.gmp b/scripts/monthly-report2.gmp index 29a1e28f..eef6a64c 100644 --- a/scripts/monthly-report2.gmp +++ b/scripts/monthly-report2.gmp @@ -18,7 +18,7 @@ from datetime import date, timedelta -from gvm.protocols.gmpv7 import AssetType +from gvm.protocols.gmpv8 import AssetType from terminaltables import AsciiTable @@ -100,7 +100,7 @@ def print_reports(gmp, from_date, to_date): ) -def main(): +def main(gmp, args): # pylint: disable=undefined-variable check_args(args) @@ -116,4 +116,4 @@ def main(): if __name__ == '__gmp__': - main() + main(gmp, args) diff --git a/scripts/nvt-scan.gmp b/scripts/nvt-scan.gmp index 81c3d458..88221e17 100644 --- a/scripts/nvt-scan.gmp +++ b/scripts/nvt-scan.gmp @@ -99,7 +99,7 @@ def create_and_start_task(gmp, name, nvt_oid, config_id, target_id): print('\nTask %s started' % task_id) -def main(): +def main(gmp, args): # pylint: disable=undefined-variable check_args(args) @@ -114,4 +114,4 @@ def main(): if __name__ == '__gmp__': - main() + main(gmp, args) diff --git a/scripts/pdf-report.gmp b/scripts/pdf-report.gmp index d78119d0..9dbb7a9d 100644 --- a/scripts/pdf-report.gmp +++ b/scripts/pdf-report.gmp @@ -19,36 +19,60 @@ from base64 import b64decode from pathlib import Path +def check_args(args): + len_args = len(args.script) - 1 + if len_args < 1: + message = """ + This script requests the given report and saves it as a pdf file locally + It needs one parameters after the script name. + + 1. -- ID of the report + + Optional a file name to save the pdf in. + + Example: + $ gvm-script --gmp-username name --gmp-password pass \ +ssh --hostname scripts/pdf-report.gmp + """ + print(message) + quit() def main(gmp, args): # check if report id and PDF filename are provided to the script # argv[0] contains the script name - if len(args.argv) <= 2: - print('Please provide report ID and PDF file name as script arguments') - return 1 + check_args(args) report_id = args.argv[1] - pdf_filename = args.argv[2] + if len(args.argv) == 3: + pdf_filename = args.argv[2] + 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 - ) + # response = gmp.get_report_formats(filter_id=pdf_report_format_id) + # print(response[0]) + # response = gmp.get_report( + # report_id=report_id, report_format_id=pdf_report_format_id + # ) report_element = response[0] # get the full content of the report element content = "".join(report_element.itertext()) + print(content) + # convert content to 8-bit ASCII bytes binary_base64_encoded_pdf = content.encode('ascii') + # decode base64 binary_pdf = b64decode(binary_base64_encoded_pdf) # write to file and support ~ in filename path pdf_path = Path(pdf_filename).expanduser() + pdf_path.write_bytes(binary_pdf) - print('Done.') + print('Done. PDF created: ' + str(pdf_path)) if __name__ == '__gmp__': diff --git a/scripts/random-report-gen.gmp b/scripts/random-report-gen.gmp index 8f3f690d..a8063996 100644 --- a/scripts/random-report-gen.gmp +++ b/scripts/random-report-gen.gmp @@ -42,8 +42,8 @@ def check_args(args): 'with-gauss' Example: - $ gvm-pyshell ssh --hostname=hostname --gmp-username=name \ - --gmp-password=pass scripts/gen-random-reports.gmp 10 50 2500 256 with-gauss + $ gvm-script --gmp-username name --gmp-password pass \ + ssh --hostname scripts/gen-random-reports.gmp 10 50 2500 256 with-gauss """ print(message) quit() @@ -902,7 +902,7 @@ TEMPLATE = { } -def main(): +def main(gmp, args): # pylint: disable=undefined-variable check_args(args) @@ -924,4 +924,4 @@ def main(): if __name__ == '__gmp__': - main() + main(gmp, args) diff --git a/scripts/send-delta-emails.gmp b/scripts/send-delta-emails.gmp index 321e654c..b0ac3f8a 100644 --- a/scripts/send-delta-emails.gmp +++ b/scripts/send-delta-emails.gmp @@ -38,8 +38,8 @@ def check_args(args): reports via email for selected tasks. Example for starting up the routine: - $ gvm-pyshell ssh --hostname=hostname --gmp-username=name \ - --gmp-password=pass scripts/projekt.gmp + $ gvm-pyshell --hostname=hostname --gmp-username=name \ + ssh --gmp-password=pass scripts/projekt.gmp The routine follows this procedure: @@ -160,11 +160,13 @@ def execute_send_delta_emails(sc, **kwargs): ) -def main(): +def main(gmp, args): # pylint: disable=undefined-variable check_args(args) + print(args) + interval = 60 # in minutes task_tag = 'send_delta_alert' report_tag_name = 'delta_alert_sent' @@ -177,8 +179,8 @@ def main(): mta_password = 'mysecret' print('send_delta_alerts starting up with following settings:') - print('GSM: %s' % args.hostname) - print('User: %s' % args.gmp_username) + #print('GSM: %s' % args.hostname) # is this even necessary? + print('User: %s' % args.username) print('Interval: %d minutes' % interval) print('Task tag: %s' % task_tag) print('Email subject: %s' % email_subject) @@ -218,4 +220,4 @@ def main(): if __name__ == '__gmp__': - main() + main(gmp, args) diff --git a/scripts/send-schedules.gmp b/scripts/send-schedules.gmp index f0c07cba..18b641a7 100644 --- a/scripts/send-schedules.gmp +++ b/scripts/send-schedules.gmp @@ -78,7 +78,7 @@ def parse_send_xml_tree(gmp, xml_tree): ) -def main(): +def main(gmp, args): # pylint: disable=undefined-variable check_args(args) @@ -94,4 +94,4 @@ def main(): if __name__ == '__gmp__': - main() + main(gmp, args) diff --git a/scripts/send-targets.gmp b/scripts/send-targets.gmp index 482c1425..d5941d28 100644 --- a/scripts/send-targets.gmp +++ b/scripts/send-targets.gmp @@ -32,8 +32,8 @@ def check_args(args): 1. -- .xml file containing targets Example: - $ gvm-pyshell ssh --hostname=hostname --gmp-username=name \ - --gmp-password=pass scripts/send-targets.gmp example_file.xml + $ gvm-script gvm-script --gmp-username name --gmp-password pass \ + ssh --hostname scripts/send-targets.gmp example_file.xml """ print(message) quit() @@ -147,7 +147,7 @@ def parse_send_xml_tree(gmp, xml_tree): counter += 1 -def main(): +def main(gmp, args): # pylint: disable=undefined-variable check_args(args) @@ -163,4 +163,4 @@ def main(): if __name__ == '__gmp__': - main() + main(gmp, args) diff --git a/scripts/send-tasks.gmp b/scripts/send-tasks.gmp index 5a352e4c..9d3714ba 100644 --- a/scripts/send-tasks.gmp +++ b/scripts/send-tasks.gmp @@ -28,11 +28,11 @@ def check_args(args): a desired GSM One parameter after the script name is required. - 1. .xml file containing tasks + 1. -- .xml file containing tasks Example: - $ gvm-pyshell ssh --hostname=hostname --gmp-username=name \ - --gmp-password=pass scripts/send-tasks.gmp example_file.xml + $ gvm-script gvm-script --gmp-username name --gmp-password pass \ + ssh --hostname scripts/send-tasks.gmp example_file.xml """ print(message) @@ -180,7 +180,7 @@ def parse_send_xml_tree(gmp, xml_tree): gmp.modify_task(**mod_keywords) -def main(): +def main(gmp, args): # pylint: disable=undefined-variable check_args(args) xml_doc = args.script[1] @@ -194,4 +194,4 @@ def main(): if __name__ == '__gmp__': - main() + main(gmp, args) diff --git a/scripts/start-alert-scan.gmp b/scripts/start-alert-scan.gmp index 31fc3ab8..12e1a735 100644 --- a/scripts/start-alert-scan.gmp +++ b/scripts/start-alert-scan.gmp @@ -215,7 +215,7 @@ def create_and_start_task( print('Task stopped') -def main(): +def main(gmp, args): # pylint: disable=undefined-variable check_args(args) @@ -234,4 +234,4 @@ def main(): if __name__ == '__gmp__': - main() + main(gmp, args) diff --git a/scripts/start-multiple-alerts-scan.gmp b/scripts/start-multiple-alerts-scan.gmp index 2e41c167..7750ddf5 100644 --- a/scripts/start-multiple-alerts-scan.gmp +++ b/scripts/start-multiple-alerts-scan.gmp @@ -259,7 +259,7 @@ def create_and_start_task( print('Task stopped') -def main(): +def main(gmp, args): # pylint: disable=undefined-variable check_args(args) @@ -278,4 +278,4 @@ def main(): if __name__ == '__gmp__': - main() + main(gmp, args) diff --git a/scripts/start-nvt-scan.gmp b/scripts/start-nvt-scan.gmp index d70758b9..446a9121 100644 --- a/scripts/start-nvt-scan.gmp +++ b/scripts/start-nvt-scan.gmp @@ -125,7 +125,7 @@ def get_target(gmp, hosts): name = input('Name of target: ') res = gmp.create_target( - name, make_unique=True, hosts=hosts.split(',') + name, hosts=hosts.split(',') ) return res.xpath('@id')[0] @@ -168,7 +168,7 @@ def create_and_start_task( print('Task started') -def main(): +def main(gmp, args): # pylint: disable=undefined-variable check_args(args) @@ -189,4 +189,4 @@ def main(): if __name__ == '__gmp__': - main() + main(gmp, args) diff --git a/scripts/sync-assets.gmp b/scripts/sync-assets.gmp index 002925e2..d9067f7a 100644 --- a/scripts/sync-assets.gmp +++ b/scripts/sync-assets.gmp @@ -17,7 +17,7 @@ # along with this program. If not, see . import csv - +from gvm.protocols.gmpv8 import AssetType def check_args(args): len_args = len(args.script) - 1 @@ -26,11 +26,11 @@ def check_args(args): This script reads asset data from a csv file and sync it with the gsm It needs one parameters after the script name. - 1. + 1. - should contain an IP-address and a comment Example: - $ gvm-pyshell ssh --hostname --gmp-username name \ - --gmp-password pass scripts/SyncAssets.gmp + $ gvm-script --gmp-username name --gmp-password pass \ + ssh --hostname scripts/sync-assets.gmp """ print(message) quit() @@ -40,36 +40,28 @@ def sync_assets(gmp, filename): with open(filename, newline='') as f: reader = csv.reader(f, delimiter=',', quotechar='|') for row in reader: - if len(row) == 4: - ip = row[1] - location = row[3] + if len(row) == 2: + ip = row[0] + comment = row[1] # print('%s %s %s %s' % (host, ip, contact, location)) # check if asset is already there - ret = gmp.get_assets(asset_type='host', filter='ip=%s' % ip) + ret = gmp.get_assets(asset_type=AssetType.HOST, filter='ip=%s' % ip) if ret.xpath('asset'): print('\nAsset with IP %s exist' % ip) asset_id = ret.xpath('asset/@id')[0] gmp.delete_asset(asset_id=asset_id) else: print('Asset with ip %s does not exist. Sync...' % ip) - ret = gmp.create_asset( - asset_type='host', name=ip, comment='Delete me' + ret = gmp.create_host( + name=ip, comment=comment ) - if location: - asset_id = ret.xpath('@id')[0] - gmp.create_tag( - location, asset_id, 'host', value=location - ) - - if 'OK' in ret.xpath('@status_text')[0]: - print('Tag created') if 'OK' in ret.xpath('@status_text')[0]: print('Asset synced') -def main(): +def main(gmp, args): # pylint: disable=undefined-variable check_args(args) @@ -80,4 +72,4 @@ def main(): if __name__ == '__gmp__': - main() + main(gmp, args) diff --git a/scripts/update-task-target.gmp b/scripts/update-task-target.gmp index ac457a2f..f5af2abf 100644 --- a/scripts/update-task-target.gmp +++ b/scripts/update-task-target.gmp @@ -27,12 +27,12 @@ def check_args(args): This script will update target hosts information for a desired task. Two parameters after the script name are required. - 1. --.csv file containing desired target hosts - 2. --uuid of task to be modified + 1. -- .csv file containing desired target hosts seperated by ',' + 2. -- uuid of task to be modified Example for starting up the routine: - $ gvm-pyshell ssh --hostname=hostname --gmp-username=name \ - --gmp-password=pass scripts/update-task-target-hosts.gmp hosts_file.csv \ + $ gvm-script gvm-script --gmp-username name --gmp-password pass \ + ssh --hostname scripts/update-task-target-hosts.gmp hosts_file.csv \ "303fa0a6-aa9b-43c4-bac0-66ae0b2d1698" """ @@ -70,7 +70,7 @@ def load_host_file(filename): def copy_send_target(gmp, hosts_file, old_target_id): hosts_string = load_host_file(hosts_file) - keywords = {'make_unique': True, 'hosts': hosts_string} + keywords = {'hosts': hosts_string} keywords['comment'] = 'This target was automatically modified: {}'.format( time.strftime("%Y/%m/%d-%H:%M:%S") @@ -85,7 +85,9 @@ def copy_send_target(gmp, hosts_file, old_target_id): var = '' keywords['{}'.format(obj)] = var - keywords['port_list'] = {'id': old_target.xpath('port_list/@id')[0]} + port_list = {} + port_list = old_target.xpath('port_list/@id')[0] + keywords['port_list_id'] = port_list new_target_id = gmp.create_target(**keywords).xpath('@id')[0] @@ -110,7 +112,7 @@ def check_to_delete(gmp, target_id): gmp.delete_target(target_id=target_id) -def main(): +def main(gmp, args): # pylint: disable=undefined-variable check_args(args) @@ -126,4 +128,4 @@ def main(): if __name__ == '__gmp__': - main() + main(gmp, args) From 5aeae415579e3bb354ea2d6fc508af027548701b Mon Sep 17 00:00:00 2001 From: jstach Date: Mon, 16 Sep 2019 15:28:47 +0200 Subject: [PATCH 17/31] Added message, replaced the Alert-Strings with the enums, exchanged event and condition so this can work correctly --- scripts/start-alert-scan.gmp | 11 ++++++++++- scripts/start-multiple-alerts-scan.gmp | 22 ++++++++++++++-------- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/scripts/start-alert-scan.gmp b/scripts/start-alert-scan.gmp index 12e1a735..fda42330 100644 --- a/scripts/start-alert-scan.gmp +++ b/scripts/start-alert-scan.gmp @@ -21,6 +21,15 @@ from gvm.protocols.gmpv8 import AlertCondition, AlertEvent, AlertMethod def check_args(args): len_args = len(args.script) - 1 message = """ + This script makes an alert scan + It needs two parameters after the script name. + + 1. -- E-Mail of the sender + 2. -- E-Mail of the receiver + + Example: + $ gvm-script --gmp-username name --gmp-password pass \ +ssh --hostname scripts/start-alert-scan.gmp """ if len_args != 2: print(message) @@ -143,8 +152,8 @@ def get_alert(gmp, sender_email, recipient_email, debug=False): gmp.create_alert( alert_name, event=AlertEvent.TASK_RUN_STATUS_CHANGED, + event_data={"status": "Done"}, condition=AlertCondition.ALWAYS, - condition_data={"status": "Done"}, method=AlertMethod.EMAIL, method_data={ """Task '$n': $e diff --git a/scripts/start-multiple-alerts-scan.gmp b/scripts/start-multiple-alerts-scan.gmp index 7750ddf5..2eeaf0e4 100644 --- a/scripts/start-multiple-alerts-scan.gmp +++ b/scripts/start-multiple-alerts-scan.gmp @@ -21,13 +21,20 @@ from gvm.protocols.gmpv8 import AlertCondition, AlertEvent, AlertMethod def check_args(args): len_args = len(args.script) - 1 message = """ - TODO? + This script makes an alert scan + It needs two parameters after the script name. + + 1. -- E-Mail of the sender + 2. -- E-Mail of the receiver + + Example: + $ gvm-script --gmp-username name --gmp-password pass \ +ssh --hostname scripts/start-multiple-alert-scan.gmp """ if len_args != 2: print(message) quit() - # returns a list containing all port_list names def get_port_list_names(gmp): res = gmp.get_port_lists() @@ -140,12 +147,11 @@ def get_alerts(gmp, sender_email, recipient_email, debug=False): alert_id = None alert = alert_object.xpath('alert') if len(alert) == 0: - print("creating alert") gmp.create_alert( alert_name, event=AlertEvent.TASK_RUN_STATUS_CHANGED, + event_data={'status': 'Done'}, condition=AlertCondition.ALWAYS, - condition_data={"status": "Done"}, method=AlertMethod.EMAIL, method_data={ """Task '$n': $e @@ -189,10 +195,10 @@ should not have received it. print("creating alert") gmp.create_alert( alert_name2, - event="Always", - condition="Task run status changed", - condition_data={"status": "Done"}, - method="Email", + event=AlertEvent.TASK_RUN_STATUS_CHANGED, + event_data={'status': 'Done'}, + condition=AlertCondition.ALWAYS, + method=AlertMethod.EMAIL, method_data={ """Task '$n': $e From 4d7cb89d5656d0bb4fa3897ac50bb8a882f674b2 Mon Sep 17 00:00:00 2001 From: jstach Date: Mon, 16 Sep 2019 15:34:29 +0200 Subject: [PATCH 18/31] Updated requirements.txt --- scripts/requirements.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/scripts/requirements.txt b/scripts/requirements.txt index d37823d4..aefd9dd5 100644 --- a/scripts/requirements.txt +++ b/scripts/requirements.txt @@ -1,4 +1,2 @@ -# required for send-schedule.gmp -python-dateutil # required for monthly-report and monthly-report2 terminaltables From deec81581caec37d0ffb09ecd85abef6a84abc63 Mon Sep 17 00:00:00 2001 From: jstach Date: Mon, 16 Sep 2019 15:45:28 +0200 Subject: [PATCH 19/31] Added message --- scripts/scan-new-system.gmp | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/scripts/scan-new-system.gmp b/scripts/scan-new-system.gmp index dc06ae91..1684ffe2 100644 --- a/scripts/scan-new-system.gmp +++ b/scripts/scan-new-system.gmp @@ -16,6 +16,21 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +def check_args(args): + len_args = len(args.script) - 1 + message = """ + This script starts a new scan on the given host + It needs one parameters after the script name. + + 1. -- IP Address of the host system + + Example: + $ gvm-script --gmp-username name --gmp-password pass \ +ssh --hostname scripts/scan -net-system.gmp + """ + if len_args != 1: + print(message) + quit() def create_target(gmp, ipaddress): import datetime @@ -45,11 +60,9 @@ def start_task(gmp, task_id): def main(gmp, args): - # check if IP address is provided to the script - # argv[0] contains the script name - if len(args.argv) <= 1: - print('Missing IP address argument') - return 1 + # pylint: disable=undefined-variable + + check_args(args) ipaddress = args.argv[1] From be4ba5f83b4f8e89dcfba6b79694aab1e624628c Mon Sep 17 00:00:00 2001 From: jstach Date: Mon, 16 Sep 2019 17:18:12 +0200 Subject: [PATCH 20/31] Markdown summarized the different scripts --- scripts/scripts.md | 391 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 391 insertions(+) create mode 100644 scripts/scripts.md diff --git a/scripts/scripts.md b/scripts/scripts.md new file mode 100644 index 00000000..51f2d1ff --- /dev/null +++ b/scripts/scripts.md @@ -0,0 +1,391 @@ +![Greenbone Logo](https://www.greenbone.net/wp-content/uploads/gb_logo_resilience_horizontal.png) + +# GVM Example Scripts + +## `application-detection.gmp` + +This script will search the reports and display all hosts with the requested applications! + +### Arguments + +* ``: Name of the application + +### Example + + `$ gvm-script --gmp-username name --gmp-password pass ssh --hostname scripts/application-detection.gmp ` + +--- + +## `cfg-gen-for-certs.gmp` + +This script creates a new scan config with nvts from a given CERT-Bund! + +### Arguments + +* ``: Name or ID of the CERT-Bund + +### Example + +`$ gvm-script --gmp-username name --gmp-password pass ssh --hostname scripts/cfg-gen-for-certs.gmp CB-K16/0943` + +--- + +## `check-gmp.gmp` + +This script can test different methods of the gmp API. + +| Optional argument | Description | +| --- | --- | +|`-H`: | Show this help message and exit +|`-V`, `--version`: | Show program's version number and exit +|`--cache [CACHE]`: | Path to cache file. Default: `/var/folders/mk/ dfxkj16j4779x98r26n21qnr0000gn/ T/check_gmp/reports.db` +| `--clean` | Activate to clean the database +| `-u GMP_USERNAME`, `--gmp-username GMP_USERNAME` | GMP username +| `-w GMP_PASSWORD`, `--gmp-password GMP_PASSWORD` | GMP password +|`-F HOSTADDRESS`, `--hostaddress HOSTADDRESS` | Report last report status of host ``. +|`-T TASK`, `--task TASK` | Report status of task ``. +|`--apply-overrides` | Apply overrides. +|`--overrides` | Include overrides. +|`-d`, `--details` | Include connection details in output. +|`-l`, `--report-link` | Include URL of report in output. +|`--dfn` | Include DFN-CERT IDs on vulnerabilities in output. +|`--oid` | Include OIDs of NVTs finding vulnerabilities in output. +|`--descr` | Include descriptions of NVTs finding vulnerabilities in output. +|`--showlog` | Include log messages in output. +| `--show-ports` | Include port of given vulnerable nvt in output. +| `--scanend` | Include timestamp of scan end in output. +| `--autofp {0,1,2}` | Trust vendor security updates for automatic false positive filtering (`0=No`, `1=full match`, `2=partial`). +| `-e`, `--empty-as-unknown` | Respond with `UNKNOWN` on empty results. +| `-I MAX_RUNNING_INSTANCES`, `--max-running-instances MAX_RUNNING_INSTANCES` | Set the maximum simultaneous processes of check-gmp +| `--hostname [HOSTNAME]` +| `--ping` | Ping the gsm appliance. +| `--status` | Report status of task. +| `--days DAYS` | Delete database entries that are older than given days. +| `--ip IP` | Delete database entry for given ip. +| `--trend` | Report status by trend. +| `--last-report` | Report status by last report. + +### Example + +`$ gvm-script --gmp-username name --gmp-password pass ssh --hostname scripts/check-gmp.gmp --ip 127.0.0.1 --ping` + +--- + +## `clean-sensor.gmp` + +This script removes all resources from a sensor, except active tasks. + +### Example + +`$ gvm-script --gmp-username name --gmp-password pass ssh --hostname scripts/clean-sensor.gmp` + +--- + +## `combine-reports.gmp` + +This script will combine desired reports into a single report. The combined report will then be sent to a desired container task. This script will create a container task for the combined report to be sent to, however, if you would like the report to be sent to an existing task, place the report of the desired task first and add the argument 'first_task'. + +### Arguments + +* `, ..., `: UUIDs of the reports to be combined + +### Example + +`$ gvm-script --gmp-username=namessh --gmp-password=pass ssh --hostname=hostname scripts/gsm-updater.gmp "d15a337c-56f3-4208-a462-afeb79eb03b7" "303fa0a6-aa9b-43c4-bac0-66ae0b2d1698" 'first_task'` + +--- + +## `create-dummy-data.gmp` + +This script will create random data in the given GVM database. + +### Arguments + +* ``: Number of datasets to create + +### Example + +`$ gvm-script --gmp-username name --gmp-password pass ssh --hostname scripts/create-dummy-data.gmp ` + +--- + +## `create-targets-from-host-list.gmp` + +This script pulls hostnames from a text file and creates a target for each. + +### Arguments + +* ``: IP of the GVM host +* ``: text file containing hostnames + +### Example + +`$ gvm-script --gmp-username name --gmp-password pass ssh --hostname scripts/create_targets_from_host_list.gmp ` + +--- + +## `delete-overrides-by-filter.gmp` + +This script deletes overrides with a specific filter value. + +### Arguments + +* ``: the parameter for the filter. + +### Example + +`$ gvm-script --gmp-username name --gmp-password pass ssh --hostname scripts/delete-overrides-by-filter.gmp ` + +--- + +## `gen-random-targets.gmp` + +This script generates random task data and feeds it to a desired GSM database. + +### Arguments + +* ``: number of dummy hosts to select from +* ``: number of targets to be generated +* `'with-gauss'`: (optional), if you would like for the number of targets generated + to be randomized on a Gaussian distribution + +### Example + +`$ gvm-script --gmp-username name --gmp-password pass ssh --hostname scripts/gen-random-tasks.gmp 3 40 with-gauss` + +--- + +## `list-tasks.gmp` + +Lists the tasks stored in an GSM Database + +### Example + +`$ gvm-script --gmp-username name --gmp-password pass ssh --hostname scripts/list-tasks.gmp` + +--- + +## `monthly-report.gmp` + +This script will display all vulnerabilities from the hosts of the reports in a given month! + +### Arguments + +* ``: month of the monthly report +* ``: year of the monthly report +* `'with-tables'`: (optional), parameter to activate a verbose output of hosts. + +### Example + +`$ gvm-script --gmp-username name --gmp-password pass ssh --hostname scripts/monthly-report.gmp 05 2019 with-tables` + +--- + +## `monthly-report2.gmp` + +This script will display all vulnerabilities from the hosts of the reports in a given month! + +### Arguments + +* ``: month of the monthly report +* ``: year of the monthly report + +### Example + +`$ gvm-script --gmp-username name --gmp-password pass ssh --hostname scripts/monthly-report2.gmp 05 2019` + +--- + +## `nvt-scan.gmp` + +This script creates a new task with specific host and nvt! + +### Arguments +* ``: oid of the nvt +* ``: scan target. + +### Example + +`$ gvm-script --gmp-username name --gmp-password pass ssh --hostname 1.3.6.1.4.1.25623.1.0.106223 localhost` + +--- + +## `pdf-report.gmp` + +This script requests the given report and saves it as a pdf file locally. + +### Arguments + +* ``: ID of the report +* ``: (optional), pdf file name + +### Example + +`$ gvm-script --gmp-username name --gmp-password pass ssh --hostname scripts/pdf-report.gmp ` + +--- + +## `random-report-gen.gmp` + +This script generates randomized report data. + +### Arguments + +* ``: number of tasks to be generated +* ``: number of reports per task +* ``: number of results per report +* ``: number of randomized hosts to select from +* `'with-gauss'`: if you would like for the number of reports/task and results/report to be randomized along a Gaussian distribution + +### Example + +`$ gvm-script --gmp-username name --gmp-password pass ssh --hostname scripts/gen-random-reports.gmp 10 50 2500 256 with-gauss` + +--- + +## `scan-new-system.gmp` + +This script starts a new scan on the given host. + +### Arguments + +* `` IP Address of the host system + +### Example + +`$ gvm-script --gmp-username name --gmp-password pass ssh --hostname scripts/scan -net-system.gmp ` + +--- + +## `send-delta-emails.gmp` + +This script, once started, will continuously send delta reports via email for selected tasks. The routine follows this procedure: + +Every `` minutes do: +* Get all tasks where the tag `` is attached. +* For each of these tasks get the finished reports: + * If less than 2 reports, continue with next task + * If latest report has tag "delta_alert_sent", continue with next task + * Create a CSV report from the delta of latest vs. previous report where filtered for only the new results. + * Send the CSV as an attachment to the configured email address. + +> You may edit the scripts hardcoded variables like `from_address`, `to_address`, etc. + +### Example + +`$ gvm-script --gmp-username name --gmp-password pass ssh --hostname scripts/send-delta-emails.gmp` + +--- + +## `send-schedules.gmp` + +This script pulls schedule data from an xml document and feeds it to a desired GSM. + +### Arguments + +* ``: .xml file containing schedules + +### Example + +`$ gvm-script --gmp-username name --gmp-password pass ssh --hostname scripts/send-schedules.gmp targethost example_file.xml` + +--- + +## `send-targets.gmp` + +This script pulls target data from an xml document and feeds it to a desired GSM. + +### Arguments + +* ``: .xml file containing schedules + +### Example + +`$ gvm-script --gmp-username name --gmp-password pass ssh --hostname scripts/send-targets.gmp example_file.xml` + +--- + +## `send-tasks.gmp` + +This script pulls tasks data from an xml document and feeds it to a desired GSM. + +### Arguments + +* ``: .xml file containing schedules + +### Example + +`$ gvm-script --gmp-username name --gmp-password pass ssh --hostname scripts/send-tasks.gmp example_file.xml` + +--- + +## `start-alert-scan.gmp` + +This script makes an alert scan and sends the report via email. + +### Arguments + +* ``: E-Mail of the sender +* ``: E-Mail of the receiver + +### Example + +`$ gvm-script --gmp-username name --gmp-password pass ssh --hostname scripts/start-alert-scan.gmp ` + +--- + +## `start-multiple-alerts-scan.gmp` + +This script makes an alert scan and sends the report via email. + +### Arguments + +* ``: E-Mail of the sender +* ``: E-Mail of the receiver + +### Example + +`$ gvm-script --gmp-username name --gmp-password pass ssh --hostname scripts/start-multiple-alerts-scan.gmp ` + +--- + +## `start-nvt-scan.gmp` + +This script creates a new task (if the target is not existing) with specific host and nvt! + +### Arguments +* ``: oid of the nvt +* ``: scan target. + +### Example + +`$ gvm-script --gmp-username name --gmp-password pass ssh --hostname scripts/start-nvt-scan.gmp 1.3.6.1.4.1.25623.1.0.106223 localhost` + +--- + +## `sync-assets.gmp` + +This script reads asset data from a csv file and sync it with the gsm. + +### Arguments + +* ``: should contain a table of IP-addresses with an optional a comment + +### Example + +`$ gvm-script --gmp-username name --gmp-password pass ssh --hostname scripts/sync-assets.gmp ` + +--- + +## `update-task-target.gmp` + +This script will update target hosts information for a desired task. + +### Arguments + +* ``: .csv file containing desired target hosts seperated by ',' +* ``: uuid of task to be modified + +### Example + +`$ gvm-script --gmp-username name --gmp-password pass ssh --hostname scripts/update-task-target-hosts.gmp hosts_file.csv "303fa0a6-aa9b-43c4-bac0-66ae0b2d1698"` \ No newline at end of file From cddf11d6b6c453d90c513dc1687ed95190729277 Mon Sep 17 00:00:00 2001 From: jstach Date: Mon, 16 Sep 2019 17:22:20 +0200 Subject: [PATCH 21/31] Minor changes in comments, corrected the help message --- scripts/cfg-gen-for-certs.gmp | 4 ++-- scripts/create-dummy-data.gmp | 4 ++-- scripts/create-targets-from-host-list.gmp | 2 +- scripts/gen-random-targets.gmp | 2 +- scripts/list-tasks.gmp | 1 - scripts/monthly-report.gmp | 2 +- scripts/monthly-report2.gmp | 6 +++++- scripts/nvt-scan.gmp | 9 +++++---- scripts/pdf-report.gmp | 2 +- scripts/scan-new-system.gmp | 2 +- scripts/send-delta-emails.gmp | 7 ++----- scripts/send-schedules.gmp | 2 +- scripts/send-targets.gmp | 2 +- scripts/send-tasks.gmp | 2 +- scripts/start-alert-scan.gmp | 4 ++-- scripts/start-nvt-scan.gmp | 3 ++- scripts/sync-assets.gmp | 4 ++-- scripts/update-task-target.gmp | 2 +- 18 files changed, 31 insertions(+), 29 deletions(-) diff --git a/scripts/cfg-gen-for-certs.gmp b/scripts/cfg-gen-for-certs.gmp index 5b8b38ff..d0b0bb22 100644 --- a/scripts/cfg-gen-for-certs.gmp +++ b/scripts/cfg-gen-for-certs.gmp @@ -27,10 +27,10 @@ def check_args(args): This script creates a new scan config with nvts from a given CERT-Bund! It needs one parameter after the script name. - 1. Name or ID of the CERT-Bund + 1. -- Name or ID of the CERT-Bund Example: - $ gvm-script gvm-script --gmp-username name --gmp-password pass \ + $ gvm-script --gmp-username name --gmp-password pass \ ssh --hostname scripts/cfg-gen-for-certs.gmp CB-K16/0943 """ print(message) diff --git a/scripts/create-dummy-data.gmp b/scripts/create-dummy-data.gmp index 7cf4c75b..7e6785ae 100644 --- a/scripts/create-dummy-data.gmp +++ b/scripts/create-dummy-data.gmp @@ -25,12 +25,12 @@ def check_args(args): len_args = len(args.script) - 1 if len_args is not 1: message = """ - This script will create random data for the given GVM database + This script will create random data in the given GVM database 1. -- Number of datasets to create Example: - $ gvm-script gvm-script --gmp-username name --gmp-password pass \ + $ gvm-script --gmp-username name --gmp-password pass \ ssh --hostname scripts/create-dummy-data.gmp """ print(message) diff --git a/scripts/create-targets-from-host-list.gmp b/scripts/create-targets-from-host-list.gmp index b53d78d3..552ffee2 100644 --- a/scripts/create-targets-from-host-list.gmp +++ b/scripts/create-targets-from-host-list.gmp @@ -32,7 +32,7 @@ for each. 2. -- text file containing hostnames Example: - $ gvm-script gvm-script --gmp-username name --gmp-password pass \ + $ gvm-script --gmp-username name --gmp-password pass \ ssh --hostname scripts/create_targets_from_host_list.gmp \ """ diff --git a/scripts/gen-random-targets.gmp b/scripts/gen-random-targets.gmp index 62a0af49..233332c8 100644 --- a/scripts/gen-random-targets.gmp +++ b/scripts/gen-random-targets.gmp @@ -34,7 +34,7 @@ def check_args(args): to be randomized on a Gaussian distribution, add 'with-gauss' Example: - $ gvm-script gvm-script --gmp-username name --gmp-password pass \ + $ gvm-script --gmp-username name --gmp-password pass \ ssh --hostname scripts/gen-random-tasks.gmp 3 40 with-gauss """ print(message) diff --git a/scripts/list-tasks.gmp b/scripts/list-tasks.gmp index f2f75fb1..cdd89e90 100644 --- a/scripts/list-tasks.gmp +++ b/scripts/list-tasks.gmp @@ -18,7 +18,6 @@ from gvmtools.helper import Table - def main(gmp, args): response_xml = gmp.get_tasks() tasks_xml = response_xml.xpath('task') diff --git a/scripts/monthly-report.gmp b/scripts/monthly-report.gmp index 74a06d34..aa942392 100644 --- a/scripts/monthly-report.gmp +++ b/scripts/monthly-report.gmp @@ -35,7 +35,7 @@ def check_args(args): hosts. Explicitly made for GOS 3.1. Example: - $ gvm-script gvm-script --gmp-username name --gmp-password pass \ + $ gvm-script --gmp-username name --gmp-password pass \ ssh --hostname scripts/monthly-report.gmp 05 2017 with-tables """ print(message) diff --git a/scripts/monthly-report2.gmp b/scripts/monthly-report2.gmp index eef6a64c..24cff6b2 100644 --- a/scripts/monthly-report2.gmp +++ b/scripts/monthly-report2.gmp @@ -34,8 +34,12 @@ def check_args(args): Both parameters are plain numbers, so no text. Explicitly made for GOS 4.X. + 1. -- month of the monthly report + 2. -- year of the monthly report + Example: - $ gvm-pyshell scripts/monthly-report2.gmp 05 2017 + $ gvm-script --gmp-username name --gmp-password pass \ + ssh --hostname scripts/monthly-report2.gmp 05 2019 """ print(message) quit() diff --git a/scripts/nvt-scan.gmp b/scripts/nvt-scan.gmp index 88221e17..4d64c339 100644 --- a/scripts/nvt-scan.gmp +++ b/scripts/nvt-scan.gmp @@ -27,12 +27,13 @@ def check_args(args): message = """ This script creates a new task with specific host and nvt! It needs two parameters after the script name. - First one is the oid of the nvt and the second one is the - chosen scan target. + + -- oid of the nvt + -- scan target Example: - $ gvm-pyshell socket scripts/nvt-scan.gmp \ - 1.3.6.1.4.1.25623.1.0.106223 localhost + $ gvm-script --gmp-username name --gmp-password pass \ + ssh --hostname 1.3.6.1.4.1.25623.1.0.106223 localhost """ print(message) quit() diff --git a/scripts/pdf-report.gmp b/scripts/pdf-report.gmp index 9dbb7a9d..d7d18f69 100644 --- a/scripts/pdf-report.gmp +++ b/scripts/pdf-report.gmp @@ -23,7 +23,7 @@ def check_args(args): len_args = len(args.script) - 1 if len_args < 1: message = """ - This script requests the given report and saves it as a pdf file locally + This script requests the given report and saves it as a pdf file locally. It needs one parameters after the script name. 1. -- ID of the report diff --git a/scripts/scan-new-system.gmp b/scripts/scan-new-system.gmp index 1684ffe2..69e51a10 100644 --- a/scripts/scan-new-system.gmp +++ b/scripts/scan-new-system.gmp @@ -19,7 +19,7 @@ def check_args(args): len_args = len(args.script) - 1 message = """ - This script starts a new scan on the given host + This script starts a new scan on the given host. It needs one parameters after the script name. 1. -- IP Address of the host system diff --git a/scripts/send-delta-emails.gmp b/scripts/send-delta-emails.gmp index b0ac3f8a..a177e554 100644 --- a/scripts/send-delta-emails.gmp +++ b/scripts/send-delta-emails.gmp @@ -38,8 +38,7 @@ def check_args(args): reports via email for selected tasks. Example for starting up the routine: - $ gvm-pyshell --hostname=hostname --gmp-username=name \ - ssh --gmp-password=pass scripts/projekt.gmp + $ gvm-script --gmp-username name --gmp-password pass ssh --hostname scripts/send-delta-emails.gmp The routine follows this procedure: @@ -165,9 +164,7 @@ def main(gmp, args): check_args(args) - print(args) - - interval = 60 # in minutes + interval = 1 # in minutes task_tag = 'send_delta_alert' report_tag_name = 'delta_alert_sent' email_subject = 'Delta Report' diff --git a/scripts/send-schedules.gmp b/scripts/send-schedules.gmp index 18b641a7..918c6015 100644 --- a/scripts/send-schedules.gmp +++ b/scripts/send-schedules.gmp @@ -31,7 +31,7 @@ def check_args(args): 1. -- .xml file containing schedules Example: - $ gvm-script gvm-script --gmp-username name --gmp-password pass \ + $ gvm-script --gmp-username name --gmp-password pass \ ssh --hostname scripts/send-schedules.gmp targethost example_file.xml """ diff --git a/scripts/send-targets.gmp b/scripts/send-targets.gmp index d5941d28..247a009a 100644 --- a/scripts/send-targets.gmp +++ b/scripts/send-targets.gmp @@ -32,7 +32,7 @@ def check_args(args): 1. -- .xml file containing targets Example: - $ gvm-script gvm-script --gmp-username name --gmp-password pass \ + $ gvm-script --gmp-username name --gmp-password pass \ ssh --hostname scripts/send-targets.gmp example_file.xml """ print(message) diff --git a/scripts/send-tasks.gmp b/scripts/send-tasks.gmp index 9d3714ba..37ee58b5 100644 --- a/scripts/send-tasks.gmp +++ b/scripts/send-tasks.gmp @@ -31,7 +31,7 @@ def check_args(args): 1. -- .xml file containing tasks Example: - $ gvm-script gvm-script --gmp-username name --gmp-password pass \ + $ gvm-script --gmp-username name --gmp-password pass \ ssh --hostname scripts/send-tasks.gmp example_file.xml """ diff --git a/scripts/start-alert-scan.gmp b/scripts/start-alert-scan.gmp index fda42330..f4366e70 100644 --- a/scripts/start-alert-scan.gmp +++ b/scripts/start-alert-scan.gmp @@ -21,13 +21,13 @@ from gvm.protocols.gmpv8 import AlertCondition, AlertEvent, AlertMethod def check_args(args): len_args = len(args.script) - 1 message = """ - This script makes an alert scan + This script makes an alert scan. It needs two parameters after the script name. 1. -- E-Mail of the sender 2. -- E-Mail of the receiver - Example: + Example: $ gvm-script --gmp-username name --gmp-password pass \ ssh --hostname scripts/start-alert-scan.gmp """ diff --git a/scripts/start-nvt-scan.gmp b/scripts/start-nvt-scan.gmp index 446a9121..268d773e 100644 --- a/scripts/start-nvt-scan.gmp +++ b/scripts/start-nvt-scan.gmp @@ -27,7 +27,8 @@ def check_args(args): chosen scan target. Example: - $ gvm-pyshell socket scripts/start-nvt-scan.gmp \ + $ gvm-script --gmp-username name --gmp-password pass \ +ssh --hostname scripts/start-nvt-scan.gmp \ 1.3.6.1.4.1.25623.1.0.106223 localhost """ print(message) diff --git a/scripts/sync-assets.gmp b/scripts/sync-assets.gmp index d9067f7a..38be98a6 100644 --- a/scripts/sync-assets.gmp +++ b/scripts/sync-assets.gmp @@ -23,10 +23,10 @@ def check_args(args): len_args = len(args.script) - 1 if len_args is not 1: message = """ - This script reads asset data from a csv file and sync it with the gsm + This script reads asset data from a csv file and sync it with the gsm. It needs one parameters after the script name. - 1. - should contain an IP-address and a comment + 1. - should contain a table of IP-addresses with an optional a comment Example: $ gvm-script --gmp-username name --gmp-password pass \ diff --git a/scripts/update-task-target.gmp b/scripts/update-task-target.gmp index f5af2abf..9546231a 100644 --- a/scripts/update-task-target.gmp +++ b/scripts/update-task-target.gmp @@ -31,7 +31,7 @@ def check_args(args): 2. -- uuid of task to be modified Example for starting up the routine: - $ gvm-script gvm-script --gmp-username name --gmp-password pass \ + $ gvm-script --gmp-username name --gmp-password pass \ ssh --hostname scripts/update-task-target-hosts.gmp hosts_file.csv \ "303fa0a6-aa9b-43c4-bac0-66ae0b2d1698" From c9e49be19389e16dfdae7beb35b6cdd5420ff5a9 Mon Sep 17 00:00:00 2001 From: jstach Date: Mon, 16 Sep 2019 17:22:35 +0200 Subject: [PATCH 22/31] Little fix with the argument --- scripts/application-detection.gmp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/application-detection.gmp b/scripts/application-detection.gmp index 23272304..1bd5c7c9 100644 --- a/scripts/application-detection.gmp +++ b/scripts/application-detection.gmp @@ -26,7 +26,7 @@ def check_args(args): 1. -- Name of the application Example: - $ gvm-script gvm-script --gmp-username name --gmp-password pass \ + $ gvm-script --gmp-username name --gmp-password pass \ ssh --hostname scripts/application-detection.gmp """ print(message) @@ -60,7 +60,7 @@ def main(gmp, args): check_args(args) - print_assets(gmp, appname) + print_assets(gmp, args.script[1]) if __name__ == '__gmp__': From 43db4e193cd83df9c85bbcd4f303a69a6d17b33f Mon Sep 17 00:00:00 2001 From: jstach Date: Mon, 16 Sep 2019 17:27:38 +0200 Subject: [PATCH 23/31] Formatted ... --- scripts/application-detection.gmp | 1 + scripts/cfg-gen-for-certs.gmp | 14 +++------ scripts/check-gmp.gmp | 13 ++++---- scripts/clean-sensor.gmp | 20 +++++++++--- scripts/create-dummy-data.gmp | 9 +++++- scripts/create-tags.gmp | 37 +++++++++++++++++++++++ scripts/create-targets-from-host-list.gmp | 4 +-- scripts/list-tasks.gmp | 1 + scripts/pdf-report.gmp | 2 ++ scripts/scan-new-system.gmp | 2 ++ scripts/send-delta-emails.gmp | 2 +- scripts/send-schedules.gmp | 6 ++-- scripts/send-targets.gmp | 2 +- scripts/start-alert-scan.gmp | 5 ++- scripts/start-multiple-alerts-scan.gmp | 6 ++-- scripts/start-nvt-scan.gmp | 4 +-- scripts/sync-assets.gmp | 9 +++--- 17 files changed, 94 insertions(+), 43 deletions(-) create mode 100644 scripts/create-tags.gmp diff --git a/scripts/application-detection.gmp b/scripts/application-detection.gmp index 1bd5c7c9..d2bd7f82 100644 --- a/scripts/application-detection.gmp +++ b/scripts/application-detection.gmp @@ -32,6 +32,7 @@ def check_args(args): print(message) quit() + def print_assets(gmp, appname): res = gmp.get_reports() diff --git a/scripts/cfg-gen-for-certs.gmp b/scripts/cfg-gen-for-certs.gmp index d0b0bb22..ee7f4a9d 100644 --- a/scripts/cfg-gen-for-certs.gmp +++ b/scripts/cfg-gen-for-certs.gmp @@ -38,7 +38,9 @@ def check_args(args): def create_config(gmp, cert_bund_name): - cert_bund_details = gmp.get_info(info_id=cert_bund_name, info_type=InfoType.CERT_BUND_ADV) + cert_bund_details = gmp.get_info( + info_id=cert_bund_name, info_type=InfoType.CERT_BUND_ADV + ) list_cves = cert_bund_details.xpath( 'info/cert_bund_adv/raw_data/Advisory/CVEList/CVE/text()' @@ -77,18 +79,12 @@ def create_config(gmp, cert_bund_name): # Modify the config with the nvts oid for family, nvt_oid in nvt_dict.items(): - gmp.modify_config( - config_id, - nvt_oids=nvt_oid, - family=family, - ) + gmp.modify_config(config_id, nvt_oids=nvt_oid, family=family) # This nvts must be present to work family = 'Port scanners' nvts = ['1.3.6.1.4.1.25623.1.0.14259', '1.3.6.1.4.1.25623.1.0.100315'] - gmp.modify_config( - config_id=config_id, nvt_oids=nvts, family=family - ) + gmp.modify_config(config_id=config_id, nvt_oids=nvts, family=family) except GvmError: print('Config exist') diff --git a/scripts/check-gmp.gmp b/scripts/check-gmp.gmp index 573bc62e..f8d4dfe8 100644 --- a/scripts/check-gmp.gmp +++ b/scripts/check-gmp.gmp @@ -265,7 +265,9 @@ class InstanceManager: self.cursor.execute("DELETE FROM Report WHERE host=?", (ip,)) self.con_db.isolation_level = None self.cursor.execute("VACUUM") - self.con_db.isolation_level = '' # see: https://github.com/CxAalto/gtfspy/commit/8d05c3c94a6d4ca3ed675d88af93def7d5053bfe + self.con_db.isolation_level = ( + '' + ) # see: https://github.com/CxAalto/gtfspy/commit/8d05c3c94a6d4ca3ed675d88af93def7d5053bfe # Save the changes self.con_db.commit() @@ -1203,9 +1205,7 @@ def main(gmp, args): ) parser.add_argument( - "-H", - action="help", - help="Show this help message and exit." + "-H", action="help", help="Show this help message and exit." ) parser.add_argument( @@ -1358,8 +1358,9 @@ def main(gmp, args): script_args = parser.parse_args(args.script_args) - aux_parser = ArgumentParser(prefix_chars="-", - formatter_class=RawTextHelpFormatter) + aux_parser = ArgumentParser( + prefix_chars="-", formatter_class=RawTextHelpFormatter + ) aux_parser.add_argument("--hostname", nargs="?", required=False) gvm_tool_args, _ = aux_parser.parse_known_args(sys.argv) if "hostname" in gvm_tool_args: diff --git a/scripts/clean-sensor.gmp b/scripts/clean-sensor.gmp index 5037fb5a..7553e63a 100644 --- a/scripts/clean-sensor.gmp +++ b/scripts/clean-sensor.gmp @@ -26,31 +26,41 @@ def clean_sensor(gmp): for tid in tasks.xpath('task/@id'): print('Removing task %s ... ' % tid) - status_text = gmp.delete_task(tid, ultimate=True).xpath('@status_text')[0] + status_text = gmp.delete_task(tid, ultimate=True).xpath('@status_text')[ + 0 + ] print(status_text) targets = gmp.get_targets(filter="rows=-1 not _owner=""") for tid in targets.xpath('target/@id'): print('Removing target %s ... ' % tid) - status_text = gmp.delete_target(tid, ultimate=True).xpath('@status_text')[0] + status_text = gmp.delete_target(tid, ultimate=True).xpath( + '@status_text' + )[0] print(status_text) configs = gmp.get_configs(filter="rows=-1 not _owner=""") for cid in configs.xpath('config/@id'): print('Removing config %s ... ' % cid) - status_text = gmp.delete_config(cid, ultimate=True).xpath('@status_text')[0] + status_text = gmp.delete_config(cid, ultimate=True).xpath( + '@status_text' + )[0] print(status_text) port_lists = gmp.get_port_lists(filter="rows=-1 not _owner=""") for pid in port_lists.xpath('port_list/@id'): print('Removing port_list %s ... ' % pid) - status_text = gmp.delete_port_list(pid, ultimate=True).xpath('@status_text')[0] + status_text = gmp.delete_port_list(pid, ultimate=True).xpath( + '@status_text' + )[0] print(status_text) credentials = gmp.get_credentials(filter="rows=-1 not _owner=""") for cid in credentials.xpath('credential/@id'): print('Removing credential %s ... ' % cid) - status_text = gmp.delete_credential(cid, ultimate=True).xpath('@status_text')[0] + status_text = gmp.delete_credential(cid, ultimate=True).xpath( + '@status_text' + )[0] print(status_text) print('Emptying trash... ') diff --git a/scripts/create-dummy-data.gmp b/scripts/create-dummy-data.gmp index 7e6785ae..2fd856b6 100644 --- a/scripts/create-dummy-data.gmp +++ b/scripts/create-dummy-data.gmp @@ -21,6 +21,7 @@ import string from gvm.protocols.gmpv8 import CredentialType + def check_args(args): len_args = len(args.script) - 1 if len_args is not 1: @@ -36,6 +37,7 @@ def check_args(args): print(message) quit() + def id_generator(size=12, chars=string.ascii_uppercase + string.digits): return ''.join(random.choice(chars) for _ in range(size)) @@ -46,7 +48,12 @@ def create_data(gmp, count): for _ in range(0, count): name = id_generator() - gmp.create_credential(name, login=name, password=name, credential_type=CredentialType.PASSWORD_ONLY) + gmp.create_credential( + name, + login=name, + password=name, + credential_type=CredentialType.PASSWORD_ONLY, + ) print(str(count) + ' random credentials generated.') for _ in range(0, count): diff --git a/scripts/create-tags.gmp b/scripts/create-tags.gmp new file mode 100644 index 00000000..e50cdc13 --- /dev/null +++ b/scripts/create-tags.gmp @@ -0,0 +1,37 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 2019 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 . + +from gvm.protocols.gmpv8 import EntityType +import datetime + + +def main(gmp, args): + + # gmp.create_tag( + # name="test", + # resource_type=EntityType.ALERT, + # ) + + gmp.modify_tag( + tag_id="242d5791-3cef-429a-b078-33e4badb6366", + resource_type=EntityType.HOST, + ) + + +if __name__ == '__gmp__': + main(gmp, args) diff --git a/scripts/create-targets-from-host-list.gmp b/scripts/create-targets-from-host-list.gmp index 552ffee2..da34db0f 100644 --- a/scripts/create-targets-from-host-list.gmp +++ b/scripts/create-targets-from-host-list.gmp @@ -68,9 +68,7 @@ def send_targets(gmp, host_name, host_file, host_list): comment = "Created: {}".format(time.strftime("%Y/%m/%d-%H:%M:%S")) hosts = [host] - gmp.create_target( - name=name, comment=comment, hosts=hosts - ) + gmp.create_target(name=name, comment=comment, hosts=hosts) def main(gmp, args): diff --git a/scripts/list-tasks.gmp b/scripts/list-tasks.gmp index cdd89e90..f2f75fb1 100644 --- a/scripts/list-tasks.gmp +++ b/scripts/list-tasks.gmp @@ -18,6 +18,7 @@ from gvmtools.helper import Table + def main(gmp, args): response_xml = gmp.get_tasks() tasks_xml = response_xml.xpath('task') diff --git a/scripts/pdf-report.gmp b/scripts/pdf-report.gmp index d7d18f69..b380de84 100644 --- a/scripts/pdf-report.gmp +++ b/scripts/pdf-report.gmp @@ -19,6 +19,7 @@ from base64 import b64decode from pathlib import Path + def check_args(args): len_args = len(args.script) - 1 if len_args < 1: @@ -37,6 +38,7 @@ ssh --hostname scripts/pdf-report.gmp print(message) quit() + def main(gmp, args): # check if report id and PDF filename are provided to the script # argv[0] contains the script name diff --git a/scripts/scan-new-system.gmp b/scripts/scan-new-system.gmp index 69e51a10..53e42d74 100644 --- a/scripts/scan-new-system.gmp +++ b/scripts/scan-new-system.gmp @@ -16,6 +16,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . + def check_args(args): len_args = len(args.script) - 1 message = """ @@ -32,6 +33,7 @@ ssh --hostname scripts/scan -net-system.gmp print(message) quit() + def create_target(gmp, ipaddress): import datetime diff --git a/scripts/send-delta-emails.gmp b/scripts/send-delta-emails.gmp index a177e554..125b3580 100644 --- a/scripts/send-delta-emails.gmp +++ b/scripts/send-delta-emails.gmp @@ -176,7 +176,7 @@ def main(gmp, args): mta_password = 'mysecret' print('send_delta_alerts starting up with following settings:') - #print('GSM: %s' % args.hostname) # is this even necessary? + # print('GSM: %s' % args.hostname) # is this even necessary? print('User: %s' % args.username) print('Interval: %d minutes' % interval) print('Task tag: %s' % task_tag) diff --git a/scripts/send-schedules.gmp b/scripts/send-schedules.gmp index 918c6015..8e9278a1 100644 --- a/scripts/send-schedules.gmp +++ b/scripts/send-schedules.gmp @@ -20,6 +20,7 @@ import sys from lxml import etree as e + def check_args(args): len_args = len(args.script) - 1 if len_args is not 1: @@ -71,10 +72,7 @@ def parse_send_xml_tree(gmp, xml_tree): timezone_abbrev = schedule.find('timezone_abbrev').text gmp.create_schedule( - name=name, - comment=comment, - timezone=timezone_abbrev, - icalendar=ical + name=name, comment=comment, timezone=timezone_abbrev, icalendar=ical ) diff --git a/scripts/send-targets.gmp b/scripts/send-targets.gmp index 247a009a..5b2e6bca 100644 --- a/scripts/send-targets.gmp +++ b/scripts/send-targets.gmp @@ -78,7 +78,7 @@ def parse_send_xml_tree(gmp, xml_tree): counter = 1 for target in xml_tree.xpath('target'): - keywords = {}#{'make_unique': True} + keywords = {} # {'make_unique': True} keywords['name'] = target.find('name').text diff --git a/scripts/start-alert-scan.gmp b/scripts/start-alert-scan.gmp index f4366e70..6f48d03c 100644 --- a/scripts/start-alert-scan.gmp +++ b/scripts/start-alert-scan.gmp @@ -18,6 +18,7 @@ from gvm.protocols.gmpv8 import AlertCondition, AlertEvent, AlertMethod + def check_args(args): len_args = len(args.script) - 1 message = """ @@ -132,9 +133,7 @@ def get_target(gmp, debug=False): hosts = ["localhost"] # integrate port list id into create_target - res = gmp.create_target( - target_name, hosts=hosts, port_list_id=portlist_id - ) + res = gmp.create_target(target_name, hosts=hosts, port_list_id=portlist_id) return res.xpath('@id')[0] diff --git a/scripts/start-multiple-alerts-scan.gmp b/scripts/start-multiple-alerts-scan.gmp index 2eeaf0e4..b5b9b6eb 100644 --- a/scripts/start-multiple-alerts-scan.gmp +++ b/scripts/start-multiple-alerts-scan.gmp @@ -18,6 +18,7 @@ from gvm.protocols.gmpv8 import AlertCondition, AlertEvent, AlertMethod + def check_args(args): len_args = len(args.script) - 1 message = """ @@ -35,6 +36,7 @@ ssh --hostname scripts/start-multiple-alert-scan.gmp Date: Tue, 17 Sep 2019 10:03:37 +0200 Subject: [PATCH 24/31] Accidently commited this file --- scripts/create-tags.gmp | 37 ------------------------------------- 1 file changed, 37 deletions(-) delete mode 100644 scripts/create-tags.gmp diff --git a/scripts/create-tags.gmp b/scripts/create-tags.gmp deleted file mode 100644 index e50cdc13..00000000 --- a/scripts/create-tags.gmp +++ /dev/null @@ -1,37 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright (C) 2019 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 . - -from gvm.protocols.gmpv8 import EntityType -import datetime - - -def main(gmp, args): - - # gmp.create_tag( - # name="test", - # resource_type=EntityType.ALERT, - # ) - - gmp.modify_tag( - tag_id="242d5791-3cef-429a-b078-33e4badb6366", - resource_type=EntityType.HOST, - ) - - -if __name__ == '__gmp__': - main(gmp, args) From 1036762be8f480dbb7745d95adc6b032b41e04d9 Mon Sep 17 00:00:00 2001 From: jstach Date: Tue, 17 Sep 2019 19:21:20 +0200 Subject: [PATCH 25/31] fixed this skript --- scripts/pdf-report.gmp | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/scripts/pdf-report.gmp b/scripts/pdf-report.gmp index b380de84..2efdb7f4 100644 --- a/scripts/pdf-report.gmp +++ b/scripts/pdf-report.gmp @@ -51,18 +51,15 @@ def main(gmp, args): pdf_filename = args.argv[1] + ".pdf" pdf_report_format_id = "c402cc3e-b531-11e1-9163-406186ea4fc5" - # response = gmp.get_report_formats(filter_id=pdf_report_format_id) - # print(response[0]) - # response = gmp.get_report( - # report_id=report_id, report_format_id=pdf_report_format_id - # ) + + response = gmp.get_report( + report_id=report_id, report_format_id=pdf_report_format_id + ) report_element = response[0] # get the full content of the report element content = "".join(report_element.itertext()) - print(content) - # convert content to 8-bit ASCII bytes binary_base64_encoded_pdf = content.encode('ascii') From 73bdc1a2731464bdc48b3af9ead845052cbcbc44 Mon Sep 17 00:00:00 2001 From: jstach Date: Tue, 17 Sep 2019 19:21:37 +0200 Subject: [PATCH 26/31] removed print --- scripts/start-multiple-alerts-scan.gmp | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/start-multiple-alerts-scan.gmp b/scripts/start-multiple-alerts-scan.gmp index b5b9b6eb..0c52d576 100644 --- a/scripts/start-multiple-alerts-scan.gmp +++ b/scripts/start-multiple-alerts-scan.gmp @@ -192,7 +192,6 @@ should not have received it. alert_id2 = None alert2 = alert_object2.xpath('alert') if len(alert2) == 0: - print("creating alert") gmp.create_alert( alert_name2, event=AlertEvent.TASK_RUN_STATUS_CHANGED, From a790091115161e99fbc9c63350c9f18f247ce899 Mon Sep 17 00:00:00 2001 From: jstach Date: Wed, 18 Sep 2019 13:28:18 +0200 Subject: [PATCH 27/31] renamed the markdown --- scripts/{scripts.md => README.md} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename scripts/{scripts.md => README.md} (100%) diff --git a/scripts/scripts.md b/scripts/README.md similarity index 100% rename from scripts/scripts.md rename to scripts/README.md From 7368555b6f18a498d76e266f84738d8bad10bc4b Mon Sep 17 00:00:00 2001 From: jstach Date: Wed, 18 Sep 2019 13:30:45 +0200 Subject: [PATCH 28/31] removed unnessesary import --- scripts/cfg-gen-for-certs.gmp | 5 ++--- scripts/create-dummy-data.gmp | 5 +---- scripts/monthly-report2.gmp | 5 +---- scripts/start-alert-scan.gmp | 8 +++----- scripts/start-multiple-alerts-scan.gmp | 14 ++++++-------- scripts/sync-assets.gmp | 4 +--- 6 files changed, 14 insertions(+), 27 deletions(-) diff --git a/scripts/cfg-gen-for-certs.gmp b/scripts/cfg-gen-for-certs.gmp index ee7f4a9d..095f7550 100644 --- a/scripts/cfg-gen-for-certs.gmp +++ b/scripts/cfg-gen-for-certs.gmp @@ -17,7 +17,6 @@ # along with this program. If not, see . from gvm.errors import GvmError -from gvm.protocols.gmpv8 import InfoType def check_args(args): @@ -39,7 +38,7 @@ def check_args(args): def create_config(gmp, cert_bund_name): cert_bund_details = gmp.get_info( - info_id=cert_bund_name, info_type=InfoType.CERT_BUND_ADV + info_id=cert_bund_name, info_type=gmp.types.InfoType.CERT_BUND_ADV ) list_cves = cert_bund_details.xpath( @@ -51,7 +50,7 @@ def create_config(gmp, cert_bund_name): for cve in list_cves: # Get all nvts of this cve - cve_info = gmp.get_info(info_id=cve, info_type=InfoType.CVE) + cve_info = gmp.get_info(info_id=cve, info_type=gmp.types.InfoType.CVE) nvts = cve_info.xpath('info/cve/nvts/nvt') for nvt in nvts: diff --git a/scripts/create-dummy-data.gmp b/scripts/create-dummy-data.gmp index 2fd856b6..e5e58f64 100644 --- a/scripts/create-dummy-data.gmp +++ b/scripts/create-dummy-data.gmp @@ -19,9 +19,6 @@ import random import string -from gvm.protocols.gmpv8 import CredentialType - - def check_args(args): len_args = len(args.script) - 1 if len_args is not 1: @@ -52,7 +49,7 @@ def create_data(gmp, count): name, login=name, password=name, - credential_type=CredentialType.PASSWORD_ONLY, + credential_type=gmp.types.CredentialType.PASSWORD_ONLY, ) print(str(count) + ' random credentials generated.') diff --git a/scripts/monthly-report2.gmp b/scripts/monthly-report2.gmp index 24cff6b2..8d5de089 100644 --- a/scripts/monthly-report2.gmp +++ b/scripts/monthly-report2.gmp @@ -17,9 +17,6 @@ # along with this program. If not, see . from datetime import date, timedelta - -from gvm.protocols.gmpv8 import AssetType - from terminaltables import AsciiTable @@ -50,7 +47,7 @@ def print_reports(gmp, from_date, to_date): from_date.isoformat(), to_date.isoformat() ) - assets_xml = gmp.get_assets(asset_type=AssetType.HOST, filter=asset_filter) + assets_xml = gmp.get_assets(asset_type=gmp.types.AssetType.HOST, filter=asset_filter) sum_high = 0 sum_medium = 0 diff --git a/scripts/start-alert-scan.gmp b/scripts/start-alert-scan.gmp index 6f48d03c..1dd338e6 100644 --- a/scripts/start-alert-scan.gmp +++ b/scripts/start-alert-scan.gmp @@ -16,8 +16,6 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -from gvm.protocols.gmpv8 import AlertCondition, AlertEvent, AlertMethod - def check_args(args): len_args = len(args.script) - 1 @@ -150,10 +148,10 @@ def get_alert(gmp, sender_email, recipient_email, debug=False): print("creating alert") gmp.create_alert( alert_name, - event=AlertEvent.TASK_RUN_STATUS_CHANGED, + event=gmp.types.AlertEvent.TASK_RUN_STATUS_CHANGED, event_data={"status": "Done"}, - condition=AlertCondition.ALWAYS, - method=AlertMethod.EMAIL, + condition=gmp.types.AlertCondition.ALWAYS, + method=gmp.types.AlertMethod.EMAIL, method_data={ """Task '$n': $e diff --git a/scripts/start-multiple-alerts-scan.gmp b/scripts/start-multiple-alerts-scan.gmp index 0c52d576..61bba49c 100644 --- a/scripts/start-multiple-alerts-scan.gmp +++ b/scripts/start-multiple-alerts-scan.gmp @@ -16,8 +16,6 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -from gvm.protocols.gmpv8 import AlertCondition, AlertEvent, AlertMethod - def check_args(args): len_args = len(args.script) - 1 @@ -149,10 +147,10 @@ def get_alerts(gmp, sender_email, recipient_email, debug=False): if len(alert) == 0: gmp.create_alert( alert_name, - event=AlertEvent.TASK_RUN_STATUS_CHANGED, + event=gmp.types.AlertEvent.TASK_RUN_STATUS_CHANGED, event_data={'status': 'Done'}, - condition=AlertCondition.ALWAYS, - method=AlertMethod.EMAIL, + condition=gmp.types.AlertCondition.ALWAYS, + method=gmp.types.AlertMethod.EMAIL, method_data={ """Task '$n': $e @@ -194,10 +192,10 @@ should not have received it. if len(alert2) == 0: gmp.create_alert( alert_name2, - event=AlertEvent.TASK_RUN_STATUS_CHANGED, + event=gmp.types.AlertEvent.TASK_RUN_STATUS_CHANGED, event_data={'status': 'Done'}, - condition=AlertCondition.ALWAYS, - method=AlertMethod.EMAIL, + condition=gmp.types.AlertCondition.ALWAYS, + method=gmp.types.AlertMethod.EMAIL, method_data={ """Task '$n': $e diff --git a/scripts/sync-assets.gmp b/scripts/sync-assets.gmp index 6a0f9edc..7a336854 100644 --- a/scripts/sync-assets.gmp +++ b/scripts/sync-assets.gmp @@ -17,8 +17,6 @@ # along with this program. If not, see . import csv -from gvm.protocols.gmpv8 import AssetType - def check_args(args): len_args = len(args.script) - 1 @@ -48,7 +46,7 @@ def sync_assets(gmp, filename): # check if asset is already there ret = gmp.get_assets( - asset_type=AssetType.HOST, filter='ip=%s' % ip + asset_type=gmp.types.AssetType.HOST, filter='ip=%s' % ip ) if ret.xpath('asset'): print('\nAsset with IP %s exist' % ip) From 0a1059904ae2d7d39d8a9134b33a2816fb70db1a Mon Sep 17 00:00:00 2001 From: jstach Date: Wed, 18 Sep 2019 13:59:36 +0200 Subject: [PATCH 29/31] Added versioncheck to this script, because it can only be executed with gmp8 (or higher) --- scripts/send-schedules.gmp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scripts/send-schedules.gmp b/scripts/send-schedules.gmp index 8e9278a1..d34ee9e1 100644 --- a/scripts/send-schedules.gmp +++ b/scripts/send-schedules.gmp @@ -38,6 +38,9 @@ def check_args(args): """ print(message) quit() + if int(gmp.get_protocol_version()[0]) < 8: + print("This script requires GMP version 8") + quit() def error_and_exit(msg): From 9beb0977594d86e822f0ab45964879c73237e33f Mon Sep 17 00:00:00 2001 From: jstach Date: Wed, 18 Sep 2019 14:05:52 +0200 Subject: [PATCH 30/31] Removed outdated print --- scripts/send-delta-emails.gmp | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/send-delta-emails.gmp b/scripts/send-delta-emails.gmp index 125b3580..d471622b 100644 --- a/scripts/send-delta-emails.gmp +++ b/scripts/send-delta-emails.gmp @@ -176,7 +176,6 @@ def main(gmp, args): mta_password = 'mysecret' print('send_delta_alerts starting up with following settings:') - # print('GSM: %s' % args.hostname) # is this even necessary? print('User: %s' % args.username) print('Interval: %d minutes' % interval) print('Task tag: %s' % task_tag) From a527110a362f71416b965d85abfe6a83bb8494eb Mon Sep 17 00:00:00 2001 From: jstach Date: Wed, 18 Sep 2019 14:21:23 +0200 Subject: [PATCH 31/31] formatting --- scripts/create-dummy-data.gmp | 1 + scripts/monthly-report2.gmp | 4 +++- scripts/sync-assets.gmp | 1 + 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/scripts/create-dummy-data.gmp b/scripts/create-dummy-data.gmp index e5e58f64..c4a6e223 100644 --- a/scripts/create-dummy-data.gmp +++ b/scripts/create-dummy-data.gmp @@ -19,6 +19,7 @@ import random import string + def check_args(args): len_args = len(args.script) - 1 if len_args is not 1: diff --git a/scripts/monthly-report2.gmp b/scripts/monthly-report2.gmp index 8d5de089..a6e735b1 100644 --- a/scripts/monthly-report2.gmp +++ b/scripts/monthly-report2.gmp @@ -47,7 +47,9 @@ def print_reports(gmp, from_date, to_date): from_date.isoformat(), to_date.isoformat() ) - assets_xml = gmp.get_assets(asset_type=gmp.types.AssetType.HOST, filter=asset_filter) + assets_xml = gmp.get_assets( + asset_type=gmp.types.AssetType.HOST, filter=asset_filter + ) sum_high = 0 sum_medium = 0 diff --git a/scripts/sync-assets.gmp b/scripts/sync-assets.gmp index 7a336854..c6d0c079 100644 --- a/scripts/sync-assets.gmp +++ b/scripts/sync-assets.gmp @@ -18,6 +18,7 @@ import csv + def check_args(args): len_args = len(args.script) - 1 if len_args is not 1: