diff --git a/scripts/README.md b/scripts/README.md new file mode 100644 index 00000000..51f2d1ff --- /dev/null +++ b/scripts/README.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 diff --git a/scripts/application-detection.gmp b/scripts/application-detection.gmp index 0063e30f..d2bd7f82 100644 --- a/scripts/application-detection.gmp +++ b/scripts/application-detection.gmp @@ -17,6 +17,22 @@ # 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 --gmp-username name --gmp-password pass \ + ssh --hostname scripts/application-detection.gmp + """ + print(message) + quit() + + def print_assets(gmp, appname): res = gmp.get_reports() @@ -40,22 +56,13 @@ def print_assets(gmp, appname): print('\n') -def main(): +def main(gmp, args): # 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) + print_assets(gmp, args.script[1]) if __name__ == '__gmp__': - main() + main(gmp, args) diff --git a/scripts/cfg-gen-for-certs.gmp b/scripts/cfg-gen-for-certs.gmp index e6897cb8..095f7550 100644 --- a/scripts/cfg-gen-for-certs.gmp +++ b/scripts/cfg-gen-for-certs.gmp @@ -26,17 +26,20 @@ 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-pyshell socket scripts/cfg-gen-for-certs.gmp CB-K16/0943 + $ 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=gmp.types.InfoType.CERT_BUND_ADV + ) list_cves = cert_bund_details.xpath( 'info/cert_bund_adv/raw_data/Advisory/CVEList/CVE/text()' @@ -47,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(cve, '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: @@ -75,26 +78,18 @@ 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_selection', - name=config_name, - 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, 'nvt_selection', nvt_oids=nvts, family=family - ) + gmp.modify_config(config_id=config_id, nvt_oids=nvts, family=family) except GvmError: print('Config exist') -def main(): +def main(gmp, args): # pylint: disable=undefined-variable check_args(args) @@ -107,4 +102,4 @@ def main(): if __name__ == '__gmp__': - main() + main(gmp, args) diff --git a/scripts/check-gmp.gmp b/scripts/check-gmp.gmp index 07c22286..f8d4dfe8 100644 --- a/scripts/check-gmp.gmp +++ b/scripts/check-gmp.gmp @@ -263,8 +263,11 @@ 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 +1188,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" @@ -1355,8 +1358,9 @@ def main(): 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: @@ -1403,4 +1407,4 @@ def main(): if __name__ == "__gmp__": - main() + main(gmp, args) diff --git a/scripts/clean-sensor.gmp b/scripts/clean-sensor.gmp index d56533bb..7553e63a 100644 --- a/scripts/clean-sensor.gmp +++ b/scripts/clean-sensor.gmp @@ -25,32 +25,42 @@ 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... ') @@ -58,7 +68,7 @@ def clean_sensor(gmp): print(status_text) -def main(): +def main(gmp, args): # pylint: disable=undefined-variable message = """ @@ -71,4 +81,4 @@ def main(): if __name__ == '__gmp__': - main() + main(gmp, args) diff --git a/scripts/combine-reports.gmp b/scripts/combine-reports.gmp index 3e2d5796..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' @@ -93,10 +93,10 @@ 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(): +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 f8d4253a..c4a6e223 100644 --- a/scripts/create-dummy-data.gmp +++ b/scripts/create-dummy-data.gmp @@ -20,6 +20,22 @@ import random import string +def check_args(args): + len_args = len(args.script) - 1 + if len_args is not 1: + message = """ + This script will create random data in the given GVM database + + 1. -- Number of datasets to create + + Example: + $ 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)) @@ -30,22 +46,31 @@ 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=gmp.types.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() @@ -54,15 +79,16 @@ 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(): +def main(gmp, args): # pylint: disable=undefined-variable - count = 50 + check_args(args) - create_data(gmp, count) + create_data(gmp, int(args.script[1])) 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..da34db0f 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 --gmp-username name --gmp-password pass \ +ssh --hostname scripts/create_targets_from_host_list.gmp \ + """ print(message) quit() @@ -67,18 +68,16 @@ 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, make_unique=True, comment=comment, hosts=hosts - ) + gmp.create_target(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 +86,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..233332c8 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 --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..aa942392 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 --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 9942a316..a6e735b1 100644 --- a/scripts/monthly-report2.gmp +++ b/scripts/monthly-report2.gmp @@ -17,7 +17,6 @@ # along with this program. If not, see . from datetime import date, timedelta - from terminaltables import AsciiTable @@ -32,8 +31,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() @@ -44,7 +47,9 @@ 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=gmp.types.AssetType.HOST, filter=asset_filter + ) sum_high = 0 sum_medium = 0 @@ -98,7 +103,7 @@ def print_reports(gmp, from_date, to_date): ) -def main(): +def main(gmp, args): # pylint: disable=undefined-variable check_args(args) @@ -114,4 +119,4 @@ def main(): if __name__ == '__gmp__': - main() + main(gmp, args) diff --git a/scripts/nvt-scan.gmp b/scripts/nvt-scan.gmp index b779d351..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() @@ -72,7 +73,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)) @@ -99,7 +100,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 +115,4 @@ def main(): if __name__ == '__gmp__': - main() + main(gmp, args) diff --git a/scripts/pdf-report.gmp b/scripts/pdf-report.gmp index d78119d0..2efdb7f4 100644 --- a/scripts/pdf-report.gmp +++ b/scripts/pdf-report.gmp @@ -20,17 +20,38 @@ 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 ) @@ -41,14 +62,16 @@ def main(gmp, args): # 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/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 diff --git a/scripts/scan-new-system.gmp b/scripts/scan-new-system.gmp index dc06ae91..53e42d74 100644 --- a/scripts/scan-new-system.gmp +++ b/scripts/scan-new-system.gmp @@ -17,6 +17,23 @@ # 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 +62,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] diff --git a/scripts/send-delta-emails.gmp b/scripts/send-delta-emails.gmp index 321e654c..d471622b 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 ssh --hostname=hostname --gmp-username=name \ - --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: @@ -160,12 +159,12 @@ def execute_send_delta_emails(sc, **kwargs): ) -def main(): +def main(gmp, args): # pylint: disable=undefined-variable check_args(args) - interval = 60 # in minutes + interval = 1 # in minutes task_tag = 'send_delta_alert' report_tag_name = 'delta_alert_sent' email_subject = 'Delta Report' @@ -177,8 +176,7 @@ 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('User: %s' % args.username) print('Interval: %d minutes' % interval) print('Task tag: %s' % task_tag) print('Email subject: %s' % email_subject) @@ -218,4 +216,4 @@ def main(): if __name__ == '__gmp__': - main() + main(gmp, args) diff --git a/scripts/send-schedules.gmp b/scripts/send-schedules.gmp index d0d06fd7..d34ee9e1 100644 --- a/scripts/send-schedules.gmp +++ b/scripts/send-schedules.gmp @@ -20,8 +20,6 @@ import sys from lxml import etree as e -import dateutil.parser - def check_args(args): len_args = len(args.script) - 1 @@ -34,14 +32,15 @@ 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 --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() + if int(gmp.get_protocol_version()[0]) < 8: + print("This script requires GMP version 8") + quit() def error_and_exit(msg): @@ -71,45 +70,21 @@ 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 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, + name=name, comment=comment, timezone=timezone_abbrev, icalendar=ical ) -def main(): +def main(gmp, args): # pylint: disable=undefined-variable check_args(args) - xml_doc = args.script[2] + xml_doc = args.script[1] print('\nSending schedules...') @@ -120,4 +95,4 @@ def main(): if __name__ == '__gmp__': - main() + main(gmp, args) diff --git a/scripts/send-targets.gmp b/scripts/send-targets.gmp index 28700a72..5b2e6bca 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 --gmp-username name --gmp-password pass \ + ssh --hostname scripts/send-targets.gmp example_file.xml """ print(message) quit() @@ -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,15 +137,17 @@ 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) counter += 1 -def main(): +def main(gmp, args): # pylint: disable=undefined-variable check_args(args) @@ -160,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 a91b2ea5..37ee58b5 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 --gmp-username name --gmp-password pass \ + ssh --hostname scripts/send-tasks.gmp example_file.xml """ print(message) @@ -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 ) @@ -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 a1e6faeb..1dd338e6 100644 --- a/scripts/start-alert-scan.gmp +++ b/scripts/start-alert-scan.gmp @@ -20,6 +20,15 @@ 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) @@ -122,9 +131,7 @@ def get_target(gmp, debug=False): hosts = ["localhost"] # integrate port list id into create_target - res = gmp.create_target( - target_name, make_unique=True, 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] @@ -141,10 +148,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", - condition_data={"status": "Done"}, - method="Email", + event=gmp.types.AlertEvent.TASK_RUN_STATUS_CHANGED, + event_data={"status": "Done"}, + condition=gmp.types.AlertCondition.ALWAYS, + method=gmp.types.AlertMethod.EMAIL, method_data={ """Task '$n': $e @@ -214,7 +221,7 @@ def create_and_start_task( print('Task stopped') -def main(): +def main(gmp, args): # pylint: disable=undefined-variable check_args(args) @@ -233,4 +240,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 f581f5dc..61bba49c 100644 --- a/scripts/start-multiple-alerts-scan.gmp +++ b/scripts/start-multiple-alerts-scan.gmp @@ -20,6 +20,15 @@ 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-multiple-alert-scan.gmp """ if len_args != 2: print(message) @@ -123,9 +132,7 @@ def get_target(gmp, debug=False): hosts = ["localhost"] # integrate port list id into create_target - res = gmp.create_target( - target_name, make_unique=True, 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] @@ -138,13 +145,12 @@ 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="Always", - condition="Task run status changed", - condition_data={"status": "Done"}, - method="Email", + event=gmp.types.AlertEvent.TASK_RUN_STATUS_CHANGED, + event_data={'status': 'Done'}, + condition=gmp.types.AlertCondition.ALWAYS, + method=gmp.types.AlertMethod.EMAIL, method_data={ """Task '$n': $e @@ -184,13 +190,12 @@ 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="Always", - condition="Task run status changed", - condition_data={"status": "Done"}, - method="Email", + event=gmp.types.AlertEvent.TASK_RUN_STATUS_CHANGED, + event_data={'status': 'Done'}, + condition=gmp.types.AlertCondition.ALWAYS, + method=gmp.types.AlertMethod.EMAIL, method_data={ """Task '$n': $e @@ -257,7 +262,7 @@ def create_and_start_task( print('Task stopped') -def main(): +def main(gmp, args): # pylint: disable=undefined-variable check_args(args) @@ -276,4 +281,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..4c19d0da 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) @@ -124,9 +125,7 @@ def get_target(gmp, hosts): name = input('Name of target: ') - res = gmp.create_target( - name, make_unique=True, hosts=hosts.split(',') - ) + res = gmp.create_target(name, hosts=hosts.split(',')) return res.xpath('@id')[0] if 0 <= int(chosen_target) < len(target_ids): @@ -168,7 +167,7 @@ def create_and_start_task( print('Task started') -def main(): +def main(gmp, args): # pylint: disable=undefined-variable check_args(args) @@ -189,4 +188,4 @@ def main(): if __name__ == '__gmp__': - main() + main(gmp, args) diff --git a/scripts/sync-assets.gmp b/scripts/sync-assets.gmp index 002925e2..c6d0c079 100644 --- a/scripts/sync-assets.gmp +++ b/scripts/sync-assets.gmp @@ -23,14 +23,14 @@ 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. + 1. - should contain a table of IP-addresses with an optional 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=gmp.types.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' - ) - 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') + ret = gmp.create_host(name=ip, comment=comment) 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..9546231a 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 --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)