1
|
|
|
# -*- coding: utf-8 -*- |
2
|
|
|
# Copyright (C) 2018 Greenbone Networks GmbH |
3
|
|
|
# |
4
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later |
5
|
|
|
# |
6
|
|
|
# This program is free software: you can redistribute it and/or modify |
7
|
|
|
# it under the terms of the GNU General Public License as published by |
8
|
|
|
# the Free Software Foundation, either version 3 of the License, or |
9
|
|
|
# (at your option) any later version. |
10
|
|
|
# |
11
|
|
|
# This program is distributed in the hope that it will be useful, |
12
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
13
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14
|
|
|
# GNU General Public License for more details. |
15
|
|
|
# |
16
|
|
|
# You should have received a copy of the GNU General Public License |
17
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
18
|
|
|
|
19
|
|
|
# pylint: disable=too-many-lines,redefined-builtin |
20
|
|
|
""" |
21
|
|
|
Module for communication with gvmd in `Greenbone Management Protocol version 7`_ |
22
|
|
|
|
23
|
|
|
.. _Greenbone Management Protocol version 7: |
24
|
|
|
https://docs.greenbone.net/API/GMP/gmp-7.0.html |
25
|
|
|
""" |
26
|
|
|
import logging |
27
|
|
|
|
28
|
|
|
from lxml import etree |
29
|
|
|
|
30
|
|
|
from gvm.errors import InvalidArgument, RequiredArgument |
31
|
|
|
from gvm.utils import get_version_string |
32
|
|
|
from gvm.xml import XmlCommand |
33
|
|
|
|
34
|
|
|
from .base import GvmProtocol |
35
|
|
|
|
36
|
|
|
logger = logging.getLogger(__name__) |
37
|
|
|
|
38
|
|
|
PROTOCOL_VERSION = (7,) |
39
|
|
|
|
40
|
|
|
FILTER_TYPES = ( |
41
|
|
|
'agent', |
42
|
|
|
'alert', |
43
|
|
|
'asset', |
44
|
|
|
'config', |
45
|
|
|
'credential', |
46
|
|
|
'filter', |
47
|
|
|
'group', |
48
|
|
|
'note', |
49
|
|
|
'override', |
50
|
|
|
'permission', |
51
|
|
|
'port_list', |
52
|
|
|
'report', |
53
|
|
|
'report_format', |
54
|
|
|
'result', |
55
|
|
|
'role', |
56
|
|
|
'schedule', |
57
|
|
|
'secinfo', |
58
|
|
|
'tag', |
59
|
|
|
'target', |
60
|
|
|
'task', |
61
|
|
|
'user', |
62
|
|
|
) |
63
|
|
|
|
64
|
|
|
TIME_UNITS = ( |
65
|
|
|
'second', |
66
|
|
|
'minute', |
67
|
|
|
'hour', |
68
|
|
|
'day', |
69
|
|
|
'week', |
70
|
|
|
'month', |
71
|
|
|
'year', |
72
|
|
|
'decade', |
73
|
|
|
) |
74
|
|
|
|
75
|
|
|
ALIVE_TESTS = ( |
76
|
|
|
'ICMP, TCP Service & ARP Ping', |
77
|
|
|
'TCP Service & ARP Ping', |
78
|
|
|
'ICMP & ARP Ping', |
79
|
|
|
'ICMP & TCP Service Ping', |
80
|
|
|
'ARP Ping', |
81
|
|
|
'TCP Service Ping', |
82
|
|
|
'ICMP Ping', |
83
|
|
|
'Scan Config Default', |
84
|
|
|
) |
85
|
|
|
|
86
|
|
|
CREDENTIAL_TYPES = ( |
87
|
|
|
'cc', |
88
|
|
|
'snmp', |
89
|
|
|
'up', |
90
|
|
|
'usk', |
91
|
|
|
) |
92
|
|
|
|
93
|
|
|
SCANNER_TYPES = ( |
94
|
|
|
'1', |
95
|
|
|
'2', |
96
|
|
|
) |
97
|
|
|
|
98
|
|
|
def _check_command_status(xml): |
99
|
|
|
"""Check gmp response |
100
|
|
|
|
101
|
|
|
Look into the gmp response and check for the status in the root element |
102
|
|
|
|
103
|
|
|
Arguments: |
104
|
|
|
xml {string} -- XML-Source |
105
|
|
|
|
106
|
|
|
Returns: |
107
|
|
|
bool -- True if valid, otherwise False |
108
|
|
|
""" |
109
|
|
|
|
110
|
|
|
if xml is 0 or xml is None: |
|
|
|
|
111
|
|
|
logger.error('XML Command is empty') |
112
|
|
|
return False |
113
|
|
|
|
114
|
|
|
try: |
115
|
|
|
parser = etree.XMLParser(encoding='utf-8', recover=True) |
116
|
|
|
|
117
|
|
|
root = etree.XML(xml, parser=parser) |
118
|
|
|
status = root.attrib['status'] |
119
|
|
|
return status is not None and status[0] == '2' |
120
|
|
|
|
121
|
|
|
except etree.Error as e: |
122
|
|
|
logger.error('etree.XML(xml): %s', e) |
123
|
|
|
return False |
124
|
|
|
|
125
|
|
|
|
126
|
|
|
def _to_bool(value): |
127
|
|
|
return '1' if value else '0' |
128
|
|
|
|
129
|
|
|
|
130
|
|
|
def _add_filter(cmd, filter, filter_id): |
131
|
|
|
if filter: |
132
|
|
|
cmd.set_attribute('filter', filter) |
133
|
|
|
|
134
|
|
|
if filter_id: |
135
|
|
|
cmd.set_attribute('filt_id', filter_id) |
136
|
|
|
|
137
|
|
|
|
138
|
|
|
class Gmp(GvmProtocol): |
|
|
|
|
139
|
|
|
"""Python interface for Greenbone Management Protocol |
140
|
|
|
|
141
|
|
|
This class implements the `Greenbone Management Protocol version 7`_ |
142
|
|
|
|
143
|
|
|
Attributes: |
144
|
|
|
connection (:class:`gvm.connections.GvmConnection`): Connection to use |
145
|
|
|
to talk with the gvmd daemon. See :mod:`gvm.connections` for |
146
|
|
|
possible connection types. |
147
|
|
|
transform (`callable`_, optional): Optional transform callable to |
148
|
|
|
convert response data. After each request the callable gets passed |
149
|
|
|
the plain response data which can be used to check the data and/or |
150
|
|
|
conversion into different representations like a xml dom. |
151
|
|
|
|
152
|
|
|
See :mod:`gvm.transforms` for existing transforms. |
153
|
|
|
|
154
|
|
|
.. _Greenbone Management Protocol version 7: |
155
|
|
|
https://docs.greenbone.net/API/GMP/gmp-7.0.html |
156
|
|
|
.. _callable: |
157
|
|
|
https://docs.python.org/3/library/functions.html#callable |
158
|
|
|
""" |
159
|
|
|
|
160
|
|
|
def __init__(self, connection, *, transform=None): |
161
|
|
|
super().__init__(connection, transform=transform) |
162
|
|
|
|
163
|
|
|
# Is authenticated on gvmd |
164
|
|
|
self._authenticated = False |
165
|
|
|
|
166
|
|
|
@staticmethod |
167
|
|
|
def get_protocol_version(): |
168
|
|
|
"""Allow to determine the Greenbone Management Protocol version. |
169
|
|
|
|
170
|
|
|
Returns: |
171
|
|
|
str: Implemented version of the Greenbone Management Protocol |
172
|
|
|
""" |
173
|
|
|
return get_version_string(PROTOCOL_VERSION) |
174
|
|
|
|
175
|
|
|
def is_authenticated(self): |
176
|
|
|
"""Checks if the user is authenticated |
177
|
|
|
|
178
|
|
|
If the user is authenticated privileged GMP commands like get_tasks |
179
|
|
|
may be send to gvmd. |
180
|
|
|
|
181
|
|
|
Returns: |
182
|
|
|
bool: True if an authenticated connection to gvmd has been |
183
|
|
|
established. |
184
|
|
|
""" |
185
|
|
|
return self._authenticated |
186
|
|
|
|
187
|
|
|
def authenticate(self, username, password): |
188
|
|
|
"""Authenticate to gvmd. |
189
|
|
|
|
190
|
|
|
The generated authenticate command will be send to server. |
191
|
|
|
Afterwards the response is read, transformed and returned. |
192
|
|
|
|
193
|
|
|
Arguments: |
194
|
|
|
username (str): Username |
195
|
|
|
password (str): Password |
196
|
|
|
|
197
|
|
|
Returns: |
198
|
|
|
any, str by default: Transformed response from server. |
199
|
|
|
""" |
200
|
|
|
cmd = XmlCommand('authenticate') |
201
|
|
|
|
202
|
|
|
if not username: |
203
|
|
|
raise RequiredArgument('authenticate requires username') |
204
|
|
|
|
205
|
|
|
if not password: |
206
|
|
|
raise RequiredArgument('authenticate requires password') |
207
|
|
|
|
208
|
|
|
credentials = cmd.add_element('credentials') |
209
|
|
|
credentials.add_element('username', username) |
210
|
|
|
credentials.add_element('password', password) |
211
|
|
|
|
212
|
|
|
self._send(cmd.to_string()) |
213
|
|
|
response = self._read() |
214
|
|
|
|
215
|
|
|
if _check_command_status(response): |
216
|
|
|
self._authenticated = True |
217
|
|
|
|
218
|
|
|
return self._transform(response) |
219
|
|
|
|
220
|
|
|
def create_agent(self, installer, signature, name, *, comment=None, |
221
|
|
|
howto_install=None, howto_use=None): |
222
|
|
|
"""Create a new agent |
223
|
|
|
|
224
|
|
|
Arguments: |
225
|
|
|
installer (str): A base64 encoded file that installs the agent on a |
226
|
|
|
target machine |
227
|
|
|
signature: (str): A detached OpenPGP signature of the installer |
228
|
|
|
name (str): A name for the agent |
229
|
|
|
comment (str, optional): A comment for the agent |
230
|
|
|
howto_install (str, optional): A file that describes how to install |
231
|
|
|
the agent |
232
|
|
|
howto_use (str, optional): A file that describes how to use the |
233
|
|
|
agent |
234
|
|
|
|
235
|
|
|
Returns: |
236
|
|
|
The response. See :py:meth:`send_command` for details. |
237
|
|
|
""" |
238
|
|
|
if not name: |
239
|
|
|
raise RequiredArgument('create_agent requires name argument') |
240
|
|
|
|
241
|
|
|
if not installer: |
242
|
|
|
raise RequiredArgument('create_agent requires installer argument') |
243
|
|
|
|
244
|
|
|
if not signature: |
245
|
|
|
raise RequiredArgument('create_agent requires signature argument') |
246
|
|
|
|
247
|
|
|
cmd = XmlCommand('create_agent') |
248
|
|
|
cmd.add_element('installer', installer) |
249
|
|
|
cmd.add_element('signature', signature) |
250
|
|
|
cmd.add_element('name', name) |
251
|
|
|
|
252
|
|
|
if comment: |
253
|
|
|
cmd.add_element('comment', comment) |
254
|
|
|
|
255
|
|
|
if howto_install: |
256
|
|
|
cmd.add_element('howto_install', howto_install) |
257
|
|
|
|
258
|
|
|
if howto_use: |
259
|
|
|
cmd.add_element('howto_use', howto_use) |
260
|
|
|
|
261
|
|
|
return self._send_xml_command(cmd) |
262
|
|
|
|
263
|
|
|
def clone_agent(self, agent_id): |
264
|
|
|
"""Clone an existing agent |
265
|
|
|
|
266
|
|
|
Arguments: |
267
|
|
|
copy (str): UUID of an existing agent to clone from |
268
|
|
|
|
269
|
|
|
Returns: |
270
|
|
|
The response. See :py:meth:`send_command` for details. |
271
|
|
|
""" |
272
|
|
|
if not agent_id: |
273
|
|
|
raise RequiredArgument('clone_agent requires a agent_id argument') |
274
|
|
|
|
275
|
|
|
cmd = XmlCommand('create_agent') |
276
|
|
|
cmd.add_element('copy', agent_id) |
277
|
|
|
return self._send_xml_command(cmd) |
278
|
|
|
|
279
|
|
|
def create_alert(self, name, condition, event, method, *, method_data=None, |
|
|
|
|
280
|
|
|
event_data=None, condition_data=None, filter_id=None, |
281
|
|
|
comment=None): |
282
|
|
|
"""Create a new alert |
283
|
|
|
|
284
|
|
|
Arguments: |
285
|
|
|
name (str): Name of the new Alert |
286
|
|
|
condition (str): The condition that must be satisfied for the alert |
287
|
|
|
to occur. |
288
|
|
|
event (str): The event that must happen for the alert to occur |
289
|
|
|
method (str): The method by which the user is alerted |
290
|
|
|
condition_data (dict, optional): Data that defines the condition |
291
|
|
|
event_data (dict, optional): Data that defines the event |
292
|
|
|
method_data (dict, optional): Data that defines the method |
293
|
|
|
filter_id (str, optional): Filter to apply when executing alert |
294
|
|
|
comment (str, optional): Comment for the alert |
295
|
|
|
|
296
|
|
|
Returns: |
297
|
|
|
The response. See :py:meth:`send_command` for details. |
298
|
|
|
""" |
299
|
|
|
if not name: |
300
|
|
|
raise RequiredArgument('create_alert requires name argument') |
301
|
|
|
|
302
|
|
|
if not condition: |
303
|
|
|
raise RequiredArgument('create_alert requires condition argument') |
304
|
|
|
|
305
|
|
|
if not event: |
306
|
|
|
raise RequiredArgument('create_alert requires event argument') |
307
|
|
|
|
308
|
|
|
if not method: |
309
|
|
|
raise RequiredArgument('create_alert requires method argument') |
310
|
|
|
|
311
|
|
|
cmd = XmlCommand('create_alert') |
312
|
|
|
cmd.add_element('name', name) |
313
|
|
|
|
314
|
|
|
conditions = cmd.add_element('condition', condition) |
315
|
|
|
|
316
|
|
|
if not condition_data is None: |
317
|
|
|
for key, value in condition_data.items(): |
318
|
|
|
_data = conditions.add_element('data', value) |
319
|
|
|
_data.add_element('name', key) |
320
|
|
|
|
321
|
|
|
events = cmd.add_element('event', event) |
322
|
|
|
|
323
|
|
|
if not event_data is None: |
324
|
|
|
for key, value in event_data.items(): |
325
|
|
|
_data = events.add_element('data', value) |
326
|
|
|
_data.add_element('name', key) |
327
|
|
|
|
328
|
|
|
methods = cmd.add_element('method', method) |
329
|
|
|
|
330
|
|
|
if not method_data is None: |
331
|
|
|
for key, value in method_data.items(): |
332
|
|
|
_data = methods.add_element('data', value) |
333
|
|
|
_data.add_element('name', key) |
334
|
|
|
|
335
|
|
|
if filter_id: |
336
|
|
|
cmd.add_element('filter', attrs={'id': filter_id}) |
337
|
|
|
|
338
|
|
|
if comment: |
339
|
|
|
cmd.add_element('comment', comment) |
340
|
|
|
|
341
|
|
|
return self._send_xml_command(cmd) |
342
|
|
|
|
343
|
|
|
def clone_alert(self, alert_id): |
344
|
|
|
"""Clone an existing alert |
345
|
|
|
|
346
|
|
|
Arguments: |
347
|
|
|
copy (str): UUID of an existing alert to clone from |
348
|
|
|
|
349
|
|
|
Returns: |
350
|
|
|
The response. See :py:meth:`send_command` for details. |
351
|
|
|
""" |
352
|
|
|
if not alert_id: |
353
|
|
|
raise RequiredArgument('clone_alert requires a alert_id argument') |
354
|
|
|
|
355
|
|
|
cmd = XmlCommand('create_alert') |
356
|
|
|
cmd.add_element('copy', alert_id) |
357
|
|
|
return self._send_xml_command(cmd) |
358
|
|
|
|
359
|
|
|
def create_asset(self, name, asset_type, *, comment=None): |
360
|
|
|
"""Create a new asset |
361
|
|
|
|
362
|
|
|
Arguments: |
363
|
|
|
name (str): Name for the new asset |
364
|
|
|
asset_type (str): Either 'os' or 'host' |
365
|
|
|
comment (str, optional): Comment for the new asset |
366
|
|
|
|
367
|
|
|
Returns: |
368
|
|
|
The response. See :py:meth:`send_command` for details. |
369
|
|
|
""" |
370
|
|
|
if asset_type not in ('host', 'os'): |
371
|
|
|
raise InvalidArgument( |
372
|
|
|
'create_asset requires asset_type to be either host or os') |
373
|
|
|
|
374
|
|
|
if not name: |
375
|
|
|
raise RequiredArgument('create_asset requires name argument') |
376
|
|
|
|
377
|
|
|
cmd = XmlCommand('create_asset') |
378
|
|
|
asset = cmd.add_element('asset') |
379
|
|
|
asset.add_element('type', asset_type) |
380
|
|
|
asset.add_element('name', name) |
381
|
|
|
|
382
|
|
|
if comment: |
383
|
|
|
asset.add_element('comment', comment) |
384
|
|
|
|
385
|
|
|
return self._send_xml_command(cmd) |
386
|
|
|
|
387
|
|
|
def create_config(self, config_id, name): |
388
|
|
|
"""Create a new scan config from an existing one |
389
|
|
|
|
390
|
|
|
Arguments: |
391
|
|
|
config_id (str): UUID of the existing scan config |
392
|
|
|
name (str): Name of the new scan config |
393
|
|
|
|
394
|
|
|
Returns: |
395
|
|
|
The response. See :py:meth:`send_command` for details. |
396
|
|
|
""" |
397
|
|
|
if not name: |
398
|
|
|
raise RequiredArgument('create_config requires name argument') |
399
|
|
|
|
400
|
|
|
if not config_id: |
401
|
|
|
raise RequiredArgument('create_config requires config_id argument') |
402
|
|
|
|
403
|
|
|
cmd = XmlCommand('create_config') |
404
|
|
|
cmd.add_element('copy', config_id) |
405
|
|
|
cmd.add_element('name', name) |
406
|
|
|
return self._send_xml_command(cmd) |
407
|
|
|
|
408
|
|
|
def clone_config(self, config_id): |
409
|
|
|
"""Clone a scan config from an existing one |
410
|
|
|
|
411
|
|
|
Arguments: |
412
|
|
|
config_id (str): UUID of the existing scan config |
413
|
|
|
|
414
|
|
|
Returns: |
415
|
|
|
The response. See :py:meth:`send_command` for details. |
416
|
|
|
""" |
417
|
|
|
if not config_id: |
418
|
|
|
raise RequiredArgument('clone_config requires config_id argument') |
419
|
|
|
|
420
|
|
|
cmd = XmlCommand('create_config') |
421
|
|
|
cmd.add_element('copy', config_id) |
422
|
|
|
return self._send_xml_command(cmd) |
423
|
|
|
|
424
|
|
|
def create_credential(self, name, credential_type, *, comment=None, |
|
|
|
|
425
|
|
|
allow_insecure=False, certificate=None, |
426
|
|
|
key_phrase=None, private_key=None, |
427
|
|
|
login=None, password=None, auth_algorithm=None, |
428
|
|
|
community=None, privacy_algorithm=None, |
429
|
|
|
privacy_password=None): |
430
|
|
|
"""Create a new credential |
431
|
|
|
|
432
|
|
|
Arguments: |
433
|
|
|
name (str): Name of the new credential |
434
|
|
|
credential_type (str): The credential type. One of 'cc', 'snmp', |
435
|
|
|
'up', 'usk' |
436
|
|
|
comment (str, optional): Comment for the credential |
437
|
|
|
allow_insecure (boolean, optional): Whether to allow insecure use of |
438
|
|
|
the credential |
439
|
|
|
certificate (str, optional): Certificate for the credential |
440
|
|
|
key_phrase (str, optional): Key passphrase for the private key |
441
|
|
|
private_key (str, optional): Private key to use for login |
442
|
|
|
login (str, optional): Username for the credential |
443
|
|
|
password (str, optional): Password for the credential |
444
|
|
|
community (str, optional): The SNMP community |
445
|
|
|
privacy_algorithm (str, optional): The SNMP privacy algorithm, |
446
|
|
|
either aes or des. |
447
|
|
|
privacy_password (str, optional): The SNMP privacy password |
448
|
|
|
|
449
|
|
|
Returns: |
450
|
|
|
The response. See :py:meth:`send_command` for details. |
451
|
|
|
""" |
452
|
|
|
if not name: |
453
|
|
|
raise RequiredArgument('create_credential requires name argument') |
454
|
|
|
|
455
|
|
|
if credential_type not in CREDENTIAL_TYPES: |
456
|
|
|
raise InvalidArgument( |
457
|
|
|
'create_credential requires type to be either cc, snmp, up ' |
458
|
|
|
' or usk') |
459
|
|
|
|
460
|
|
|
cmd = XmlCommand('create_credential') |
461
|
|
|
cmd.add_element('name', name) |
462
|
|
|
|
463
|
|
|
cmd.add_element('type', credential_type) |
464
|
|
|
|
465
|
|
|
if comment: |
466
|
|
|
cmd.add_element('comment', comment) |
467
|
|
|
|
468
|
|
|
if allow_insecure: |
469
|
|
|
cmd.add_element('allow_insecure', '1') |
470
|
|
|
|
471
|
|
|
if credential_type == 'cc': |
472
|
|
|
if not certificate: |
473
|
|
|
raise RequiredArgument( |
474
|
|
|
'create_credential requires certificate argument for ' |
475
|
|
|
'credential_type {0}'.format(credential_type)) |
476
|
|
|
|
477
|
|
|
cmd.add_element('certificate', certificate) |
478
|
|
|
|
479
|
|
|
if (credential_type == 'up' or credential_type == 'usk' or \ |
|
|
|
|
480
|
|
|
credential_type == 'snmp'): |
481
|
|
|
if not login: |
482
|
|
|
raise RequiredArgument( |
483
|
|
|
'create_credential requires login argument for ' |
484
|
|
|
'credential_type {0}'.format(credential_type)) |
485
|
|
|
|
486
|
|
|
cmd.add_element('login', login) |
487
|
|
|
|
488
|
|
|
if (credential_type == 'up' or credential_type == 'snmp') and password: |
|
|
|
|
489
|
|
|
cmd.add_element('password', password) |
490
|
|
|
|
491
|
|
View Code Duplication |
if credential_type == 'usk': |
|
|
|
|
492
|
|
|
if not private_key: |
493
|
|
|
raise RequiredArgument( |
494
|
|
|
'create_credential requires certificate argument for ' |
495
|
|
|
'credential_type usk') |
496
|
|
|
|
497
|
|
|
_xmlkey = cmd.add_element('key') |
498
|
|
|
_xmlkey.add_element('private', private_key) |
499
|
|
|
|
500
|
|
|
if key_phrase: |
501
|
|
|
_xmlkey.add_element('phrase', key_phrase) |
502
|
|
|
|
503
|
|
|
if credential_type == 'cc' and private_key: |
504
|
|
|
_xmlkey = cmd.add_element('key') |
505
|
|
|
_xmlkey.add_element('private', private_key) |
506
|
|
|
|
507
|
|
View Code Duplication |
if credential_type == 'snmp': |
|
|
|
|
508
|
|
|
if auth_algorithm not in ('md5', 'sha1'): |
509
|
|
|
raise InvalidArgument( |
510
|
|
|
'create_credential requires auth_algorithm to be either ' |
511
|
|
|
'md5 or sha1') |
512
|
|
|
|
513
|
|
|
cmd.add_element('auth_algorithm', auth_algorithm) |
514
|
|
|
|
515
|
|
|
if community: |
516
|
|
|
cmd.add_element('community', community) |
517
|
|
|
|
518
|
|
|
if privacy_algorithm is not None or privacy_password: |
519
|
|
|
_xmlprivacy = cmd.add_element('privacy') |
520
|
|
|
|
521
|
|
|
if privacy_algorithm is not None: |
522
|
|
|
if privacy_algorithm not in ('aes', 'des'): |
523
|
|
|
raise InvalidArgument( |
524
|
|
|
'create_credential requires algorithm to be either ' |
525
|
|
|
'aes or des') |
526
|
|
|
|
527
|
|
|
_xmlprivacy.add_element('algorithm', privacy_algorithm) |
528
|
|
|
|
529
|
|
|
if privacy_password: |
530
|
|
|
_xmlprivacy.add_element('password', privacy_password) |
531
|
|
|
|
532
|
|
|
return self._send_xml_command(cmd) |
533
|
|
|
|
534
|
|
|
def clone_credential(self, credential_id): |
535
|
|
|
"""Clone an existing credential |
536
|
|
|
|
537
|
|
|
Arguments: |
538
|
|
|
copy (str): UUID of an existing credential to clone from |
539
|
|
|
|
540
|
|
|
Returns: |
541
|
|
|
The response. See :py:meth:`send_command` for details. |
542
|
|
|
""" |
543
|
|
|
if not credential_id: |
544
|
|
|
raise RequiredArgument( |
545
|
|
|
'clone_credential requires a credential_id argument') |
546
|
|
|
|
547
|
|
|
cmd = XmlCommand('create_credential') |
548
|
|
|
cmd.add_element('copy', credential_id) |
549
|
|
|
return self._send_xml_command(cmd) |
550
|
|
|
|
551
|
|
|
def create_filter(self, name, *, make_unique=False, filter_type=None, |
552
|
|
|
comment=None, term=None): |
553
|
|
|
"""Create a new filter |
554
|
|
|
|
555
|
|
|
Arguments: |
556
|
|
|
name (str): Name of the new filter |
557
|
|
|
make_unique (boolean, optional): |
558
|
|
|
filter_type (str, optional): Filter for entity type |
559
|
|
|
comment (str, optional): Comment for the filter |
560
|
|
|
term (str, optional): Filter term e.g. 'name=foo' |
561
|
|
|
|
562
|
|
|
Returns: |
563
|
|
|
The response. See :py:meth:`send_command` for details. |
564
|
|
|
""" |
565
|
|
|
if not name: |
566
|
|
|
raise RequiredArgument('create_filter requires a name argument') |
567
|
|
|
|
568
|
|
|
cmd = XmlCommand('create_filter') |
569
|
|
|
_xmlname = cmd.add_element('name', name) |
570
|
|
|
if make_unique: |
571
|
|
|
_xmlname.add_element('make_unique', '1') |
572
|
|
|
|
573
|
|
|
if comment: |
574
|
|
|
cmd.add_element('comment', comment) |
575
|
|
|
|
576
|
|
|
if term: |
577
|
|
|
cmd.add_element('term', term) |
578
|
|
|
|
579
|
|
|
if filter_type: |
580
|
|
|
filter_type = filter_type.lower() |
581
|
|
|
if filter_type not in FILTER_TYPES: |
582
|
|
|
raise InvalidArgument( |
583
|
|
|
'create_filter requires type to be one of {0} but ' |
584
|
|
|
'was {1}'.format(', '.join(FILTER_TYPES), filter_type)) |
585
|
|
|
cmd.add_element('type', filter_type) |
586
|
|
|
|
587
|
|
|
return self._send_xml_command(cmd) |
588
|
|
|
|
589
|
|
|
def clone_filter(self, filter_id): |
590
|
|
|
"""Clone an existing filter |
591
|
|
|
|
592
|
|
|
Arguments: |
593
|
|
|
copy (str): UUID of an existing filter to clone from |
594
|
|
|
|
595
|
|
|
Returns: |
596
|
|
|
The response. See :py:meth:`send_command` for details. |
597
|
|
|
""" |
598
|
|
|
if not filter_id: |
599
|
|
|
raise RequiredArgument('clone_filter requires a filter_id argument') |
600
|
|
|
|
601
|
|
|
cmd = XmlCommand('create_filter') |
602
|
|
|
cmd.add_element('copy', filter_id) |
603
|
|
|
return self._send_xml_command(cmd) |
604
|
|
|
|
605
|
|
|
def create_group(self, name, *, comment=None, special=False, users=None): |
606
|
|
|
"""Create a new group |
607
|
|
|
|
608
|
|
|
Arguments: |
609
|
|
|
name (str): Name of the new group |
610
|
|
|
comment (str, optional): Comment for the group |
611
|
|
|
special (boolean, optional): Create permission giving members full |
612
|
|
|
access to each other's entities |
613
|
|
|
users (list, optional): List of user names to be in the group |
614
|
|
|
|
615
|
|
|
Returns: |
616
|
|
|
The response. See :py:meth:`send_command` for details. |
617
|
|
|
""" |
618
|
|
|
if not name: |
619
|
|
|
raise RequiredArgument('create_group requires a name argument') |
620
|
|
|
|
621
|
|
|
cmd = XmlCommand('create_group') |
622
|
|
|
cmd.add_element('name', name) |
623
|
|
|
|
624
|
|
|
if comment: |
625
|
|
|
cmd.add_element('comment', comment) |
626
|
|
|
|
627
|
|
|
if special: |
628
|
|
|
_xmlspecial = cmd.add_element('specials') |
629
|
|
|
_xmlspecial.add_element('full') |
630
|
|
|
|
631
|
|
|
if users: |
632
|
|
|
cmd.add_element('users', ','.join(users)) |
633
|
|
|
|
634
|
|
|
return self._send_xml_command(cmd) |
635
|
|
|
|
636
|
|
|
def clone_group(self, group_id): |
637
|
|
|
"""Clone an existing group |
638
|
|
|
|
639
|
|
|
Arguments: |
640
|
|
|
copy (str): UUID of an existing group to clone from |
641
|
|
|
|
642
|
|
|
Returns: |
643
|
|
|
The response. See :py:meth:`send_command` for details. |
644
|
|
|
""" |
645
|
|
|
if not group_id: |
646
|
|
|
raise RequiredArgument('clone_group requires a group_id argument') |
647
|
|
|
|
648
|
|
|
cmd = XmlCommand('create_group') |
649
|
|
|
cmd.add_element('copy', group_id) |
650
|
|
|
return self._send_xml_command(cmd) |
651
|
|
|
|
652
|
|
|
def create_note(self, text, nvt_oid, *, seconds_active=None, comment=None, |
653
|
|
|
hosts=None, result_id=None, severity=None, task_id=None, |
654
|
|
|
threat=None, port=None): |
655
|
|
|
"""Create a new note |
656
|
|
|
|
657
|
|
|
Arguments: |
658
|
|
|
text (str): Text of the new note |
659
|
|
|
nvt_id (str): OID of the nvt to which note applies |
660
|
|
|
seconds_active (int, optional): Seconds note will be active. -1 on |
661
|
|
|
always, 0 off |
662
|
|
|
comment (str, optional): Comment for the note |
663
|
|
|
hosts (list, optional): A list of hosts addresses |
664
|
|
|
port (str, optional): Port to which the note applies |
665
|
|
|
result_id (str, optional): UUID of a result to which note applies |
666
|
|
|
severity (decimal, optional): Severity to which note applies |
667
|
|
|
task_id (str, optional): UUID of task to which note applies |
668
|
|
|
threat (str, optional): Threat level to which note applies. Will be |
669
|
|
|
converted to severity |
670
|
|
|
|
671
|
|
|
Returns: |
672
|
|
|
The response. See :py:meth:`send_command` for details. |
673
|
|
|
""" |
674
|
|
|
if not text: |
675
|
|
|
raise RequiredArgument('create_note requires a text argument') |
676
|
|
|
|
677
|
|
|
if not nvt_oid: |
678
|
|
|
raise RequiredArgument('create_note requires a nvt_oid argument') |
679
|
|
|
|
680
|
|
|
cmd = XmlCommand('create_note') |
681
|
|
|
cmd.add_element('text', text) |
682
|
|
|
cmd.add_element('nvt', attrs={"oid": nvt_oid}) |
683
|
|
|
|
684
|
|
|
if not seconds_active is None: |
685
|
|
|
cmd.add_element('active', str(seconds_active)) |
686
|
|
|
|
687
|
|
|
if comment: |
688
|
|
|
cmd.add_element('comment', comment) |
689
|
|
|
|
690
|
|
|
if hosts: |
691
|
|
|
cmd.add_element('hosts', ', '.join(hosts)) |
692
|
|
|
|
693
|
|
|
if port: |
694
|
|
|
cmd.add_element('port', port) |
695
|
|
|
|
696
|
|
|
if result_id: |
697
|
|
|
cmd.add_element('result', attrs={'id': result_id}) |
698
|
|
|
|
699
|
|
|
if severity: |
700
|
|
|
cmd.add_element('severity', severity) |
701
|
|
|
|
702
|
|
|
if task_id: |
703
|
|
|
cmd.add_element('task', attrs={'id': task_id}) |
704
|
|
|
|
705
|
|
|
if threat: |
706
|
|
|
cmd.add_element('threat', threat) |
707
|
|
|
|
708
|
|
|
return self._send_xml_command(cmd) |
709
|
|
|
|
710
|
|
|
def clone_note(self, note_id): |
711
|
|
|
"""Clone an existing note |
712
|
|
|
|
713
|
|
|
Arguments: |
714
|
|
|
copy (str): UUID of an existing note to clone from |
715
|
|
|
|
716
|
|
|
Returns: |
717
|
|
|
The response. See :py:meth:`send_command` for details. |
718
|
|
|
""" |
719
|
|
|
if not note_id: |
720
|
|
|
raise RequiredArgument('clone_note requires a note_id argument') |
721
|
|
|
|
722
|
|
|
cmd = XmlCommand('create_note') |
723
|
|
|
cmd.add_element('copy', note_id) |
724
|
|
|
return self._send_xml_command(cmd) |
725
|
|
|
|
726
|
|
View Code Duplication |
def create_override(self, text, nvt_oid, *, seconds_active=None, hosts=None, |
|
|
|
|
727
|
|
|
port=None, result_id=None, severity=None, comment=None, |
728
|
|
|
new_severity=None, task_id=None, threat=None, |
729
|
|
|
new_threat=None): |
730
|
|
|
"""Create a new override |
731
|
|
|
|
732
|
|
|
Arguments: |
733
|
|
|
text (str): Text of the new override |
734
|
|
|
nvt_id (str): OID of the nvt to which override applies |
735
|
|
|
seconds_active (int, optional): Seconds override will be active. |
736
|
|
|
-1 on always, 0 off |
737
|
|
|
comment (str, optional): Comment for the override |
738
|
|
|
hosts (list, optional): A list of host addresses |
739
|
|
|
port (str, optional): Port to which the override applies |
740
|
|
|
result_id (str, optional): UUID of a result to which override |
741
|
|
|
applies |
742
|
|
|
severity (decimal, optional): Severity to which override applies |
743
|
|
|
new_severity (decimal, optional): New severity for result |
744
|
|
|
task_id (str, optional): UUID of task to which override applies |
745
|
|
|
threat (str, optional): Threat level to which override applies. Will |
746
|
|
|
be converted to severity |
747
|
|
|
new_threat (str, optional): New threat level for result, will be |
748
|
|
|
converted to a new_severity |
749
|
|
|
|
750
|
|
|
Returns: |
751
|
|
|
The response. See :py:meth:`send_command` for details. |
752
|
|
|
""" |
753
|
|
|
if not text: |
754
|
|
|
raise RequiredArgument('create_override requires a text argument') |
755
|
|
|
|
756
|
|
|
if not nvt_oid: |
757
|
|
|
raise RequiredArgument('create_override requires a nvt_oid ' |
758
|
|
|
'argument') |
759
|
|
|
|
760
|
|
|
cmd = XmlCommand('create_override') |
761
|
|
|
cmd.add_element('text', text) |
762
|
|
|
cmd.add_element('nvt', attrs={'oid': nvt_oid}) |
763
|
|
|
|
764
|
|
|
if not seconds_active is None: |
765
|
|
|
cmd.add_element('active', str(seconds_active)) |
766
|
|
|
|
767
|
|
|
if comment: |
768
|
|
|
cmd.add_element('comment', comment) |
769
|
|
|
|
770
|
|
|
if hosts: |
771
|
|
|
cmd.add_element('hosts', ', '.join(hosts)) |
772
|
|
|
|
773
|
|
|
if port: |
774
|
|
|
cmd.add_element('port', port) |
775
|
|
|
|
776
|
|
|
if result_id: |
777
|
|
|
cmd.add_element('result', attrs={'id': result_id}) |
778
|
|
|
|
779
|
|
|
if severity: |
780
|
|
|
cmd.add_element('severity', severity) |
781
|
|
|
|
782
|
|
|
if new_severity: |
783
|
|
|
cmd.add_element('new_severity', new_severity) |
784
|
|
|
|
785
|
|
|
if task_id: |
786
|
|
|
cmd.add_element('task', attrs={'id': task_id}) |
787
|
|
|
|
788
|
|
|
if threat: |
789
|
|
|
cmd.add_element('threat', threat) |
790
|
|
|
|
791
|
|
|
if new_threat: |
792
|
|
|
cmd.add_element('new_threat', new_threat) |
793
|
|
|
|
794
|
|
|
return self._send_xml_command(cmd) |
795
|
|
|
|
796
|
|
|
def clone_override(self, override_id): |
797
|
|
|
"""Clone an existing override |
798
|
|
|
|
799
|
|
|
Arguments: |
800
|
|
|
copy (str): UUID of an existing override to clone from |
801
|
|
|
|
802
|
|
|
Returns: |
803
|
|
|
The response. See :py:meth:`send_command` for details. |
804
|
|
|
""" |
805
|
|
|
if not override_id: |
806
|
|
|
raise RequiredArgument( |
807
|
|
|
'clone_override requires a override_id argument') |
808
|
|
|
|
809
|
|
|
cmd = XmlCommand('create_override') |
810
|
|
|
cmd.add_element('copy', override_id) |
811
|
|
|
return self._send_xml_command(cmd) |
812
|
|
|
|
813
|
|
|
def create_permission(self, name, subject_id, subject_type, *, |
814
|
|
|
resource_id=None, resource_type=None, |
815
|
|
|
comment=None): |
816
|
|
|
"""Create a new permission |
817
|
|
|
|
818
|
|
|
Arguments: |
819
|
|
|
name (str): Name of the new permission |
820
|
|
|
subject_id (str): UUID of subject to whom the permission is granted |
821
|
|
|
subject_type (str): Type of the subject user, group or role |
822
|
|
|
comment (str, optional): Comment for the permission |
823
|
|
|
resource_id (str, optional): UUID of entity to which the permission |
824
|
|
|
applies |
825
|
|
|
resource_type (str, optional): Type of the resource. For Super |
826
|
|
|
permissions user, group or role |
827
|
|
|
|
828
|
|
|
Returns: |
829
|
|
|
The response. See :py:meth:`send_command` for details. |
830
|
|
|
""" |
831
|
|
|
if not name: |
832
|
|
|
raise RequiredArgument('create_permission requires a name argument') |
833
|
|
|
|
834
|
|
|
if not subject_id: |
835
|
|
|
raise RequiredArgument( |
836
|
|
|
'create_permission requires a subject_id argument') |
837
|
|
|
|
838
|
|
|
if subject_type not in ('user', 'group', 'role'): |
839
|
|
|
raise InvalidArgument( |
840
|
|
|
'create_permission requires subject_type to be either user, ' |
841
|
|
|
'group or role') |
842
|
|
|
|
843
|
|
|
cmd = XmlCommand('create_permission') |
844
|
|
|
cmd.add_element('name', name) |
845
|
|
|
|
846
|
|
|
_xmlsubject = cmd.add_element('subject', attrs={'id': subject_id}) |
847
|
|
|
_xmlsubject.add_element('type', subject_type) |
848
|
|
|
|
849
|
|
|
if comment: |
850
|
|
|
cmd.add_element('comment', comment) |
851
|
|
|
|
852
|
|
|
if resource_id or resource_type: |
853
|
|
|
if not resource_id: |
854
|
|
|
raise RequiredArgument( |
855
|
|
|
'create_permission requires resource_id for resource_type') |
856
|
|
|
|
857
|
|
|
if not resource_type: |
858
|
|
|
raise RequiredArgument( |
859
|
|
|
'create_permission requires resource_type for resource_id') |
860
|
|
|
|
861
|
|
|
_xmlresource = cmd.add_element('resource', |
862
|
|
|
attrs={'id': resource_id}) |
863
|
|
|
_xmlresource.add_element('type', resource_type) |
864
|
|
|
|
865
|
|
|
|
866
|
|
|
return self._send_xml_command(cmd) |
867
|
|
|
|
868
|
|
|
def clone_permission(self, permission_id): |
869
|
|
|
"""Clone an existing permission |
870
|
|
|
|
871
|
|
|
Arguments: |
872
|
|
|
copy (str): UUID of an existing permission to clone from |
873
|
|
|
|
874
|
|
|
Returns: |
875
|
|
|
The response. See :py:meth:`send_command` for details. |
876
|
|
|
""" |
877
|
|
|
if not permission_id: |
878
|
|
|
raise RequiredArgument( |
879
|
|
|
'clone_permission requires a permission_id argument') |
880
|
|
|
|
881
|
|
|
cmd = XmlCommand('create_permission') |
882
|
|
|
cmd.add_element('copy', permission_id) |
883
|
|
|
return self._send_xml_command(cmd) |
884
|
|
|
|
885
|
|
|
def create_port_list(self, name, port_range, *, comment=None): |
886
|
|
|
"""Create a new port list |
887
|
|
|
|
888
|
|
|
Arguments: |
889
|
|
|
name (str): Name of the new port list |
890
|
|
|
port_range (str): Port list ranges e.g. `"T: 1-1234"` for tcp port |
891
|
|
|
1 - 1234 |
892
|
|
|
comment (str, optional): Comment for the port list |
893
|
|
|
|
894
|
|
|
Returns: |
895
|
|
|
The response. See :py:meth:`send_command` for details. |
896
|
|
|
""" |
897
|
|
|
if not name: |
898
|
|
|
raise RequiredArgument('create_port_list requires a name argument') |
899
|
|
|
|
900
|
|
|
if not port_range: |
901
|
|
|
raise RequiredArgument( |
902
|
|
|
'create_port_list requires a port_range argument') |
903
|
|
|
|
904
|
|
|
cmd = XmlCommand('create_port_list') |
905
|
|
|
cmd.add_element('name', name) |
906
|
|
|
cmd.add_element('port_range', port_range) |
907
|
|
|
|
908
|
|
|
if comment: |
909
|
|
|
cmd.add_element('comment', comment) |
910
|
|
|
|
911
|
|
|
return self._send_xml_command(cmd) |
912
|
|
|
|
913
|
|
|
def clone_port_list(self, port_list_id): |
914
|
|
|
"""Clone an existing port list |
915
|
|
|
|
916
|
|
|
Arguments: |
917
|
|
|
copy (str): UUID of an existing port list to clone from |
918
|
|
|
|
919
|
|
|
Returns: |
920
|
|
|
The response. See :py:meth:`send_command` for details. |
921
|
|
|
""" |
922
|
|
|
if not port_list_id: |
923
|
|
|
raise RequiredArgument( |
924
|
|
|
'clone_port_list requires a port_list_id argument') |
925
|
|
|
|
926
|
|
|
cmd = XmlCommand('create_port_list') |
927
|
|
|
cmd.add_element('copy', port_list_id) |
928
|
|
|
return self._send_xml_command(cmd) |
929
|
|
|
|
930
|
|
|
def create_port_range(self, port_list_id, start, end, port_range_type, |
931
|
|
|
*, comment=None): |
932
|
|
|
"""Create new port range |
933
|
|
|
|
934
|
|
|
Arguments: |
935
|
|
|
port_list_id (str): UUID of the port list to which to add the range |
936
|
|
|
start (int): The first port in the range |
937
|
|
|
end (int): The last port in the range |
938
|
|
|
port_range_type (str): The type of the ports: TCP, UDP, ... |
939
|
|
|
comment (str, optional): Comment for the port range |
940
|
|
|
|
941
|
|
|
Returns: |
942
|
|
|
The response. See :py:meth:`send_command` for details. |
943
|
|
|
""" |
944
|
|
|
if not port_list_id: |
945
|
|
|
raise RequiredArgument('create_port_range requires ' |
946
|
|
|
'a port_list_id argument') |
947
|
|
|
|
948
|
|
|
if not port_range_type: |
949
|
|
|
raise RequiredArgument( |
950
|
|
|
'create_port_range requires a port_range_type argument') |
951
|
|
|
|
952
|
|
|
if not start: |
953
|
|
|
raise RequiredArgument( |
954
|
|
|
'create_port_range requires a start argument') |
955
|
|
|
|
956
|
|
|
if not end: |
957
|
|
|
raise RequiredArgument( |
958
|
|
|
'create_port_range requires a end argument') |
959
|
|
|
|
960
|
|
|
cmd = XmlCommand('create_port_range') |
961
|
|
|
cmd.add_element('port_list', attrs={'id': port_list_id}) |
962
|
|
|
cmd.add_element('start', start) |
963
|
|
|
cmd.add_element('end', end) |
964
|
|
|
cmd.add_element('type', port_range_type) |
965
|
|
|
|
966
|
|
|
if comment: |
967
|
|
|
cmd.add_element('comment', comment) |
968
|
|
|
|
969
|
|
|
return self._send_xml_command(cmd) |
970
|
|
|
|
971
|
|
|
def import_report(self, report, *, task_id=None, task_name=None, |
972
|
|
|
task_comment=None, in_assets=None): |
973
|
|
|
"""Import a Report |
974
|
|
|
|
975
|
|
|
Arguments: |
976
|
|
|
report (str): Report XML as string to import |
977
|
|
|
task_id (str, optional): UUID of task to import report to |
978
|
|
|
task_name (str, optional): Name of task to be created if task_id is |
979
|
|
|
not present. Either task_id or task_name must be passed |
980
|
|
|
task_comment (str, optional): Comment for task to be created if |
981
|
|
|
task_id is not present |
982
|
|
|
in_asset (boolean, optional): Whether to create or update assets |
983
|
|
|
using the report |
984
|
|
|
|
985
|
|
|
Returns: |
986
|
|
|
The response. See :py:meth:`send_command` for details. |
987
|
|
|
""" |
988
|
|
|
if not report: |
989
|
|
|
raise RequiredArgument('create_report requires a report argument') |
990
|
|
|
|
991
|
|
|
cmd = XmlCommand('create_report') |
992
|
|
|
|
993
|
|
|
if task_id: |
994
|
|
|
cmd.add_element('task', attrs={'id': task_id}) |
995
|
|
|
elif task_name: |
996
|
|
|
_xmltask = cmd.add_element('task') |
997
|
|
|
_xmltask.add_element('name', task_name) |
998
|
|
|
|
999
|
|
|
if task_comment: |
1000
|
|
|
_xmltask.add_element('comment', task_comment) |
1001
|
|
|
else: |
1002
|
|
|
raise RequiredArgument( |
1003
|
|
|
'import_report requires a task_id or task_name argument') |
1004
|
|
|
|
1005
|
|
|
if not in_assets is None: |
1006
|
|
|
cmd.add_element('in_assets', _to_bool(in_assets)) |
1007
|
|
|
|
1008
|
|
|
try: |
1009
|
|
|
cmd.append_xml_str(report) |
1010
|
|
|
except etree.XMLSyntaxError as e: |
1011
|
|
|
raise InvalidArgument( |
1012
|
|
|
'Invalid xml passed as report to import_report', e) |
1013
|
|
|
|
1014
|
|
|
return self._send_xml_command(cmd) |
1015
|
|
|
|
1016
|
|
|
def create_role(self, name, *, comment=None, users=None): |
1017
|
|
|
"""Create a new role |
1018
|
|
|
|
1019
|
|
|
Arguments: |
1020
|
|
|
name (str): Name of the role |
1021
|
|
|
comment (str, optional): Comment for the role |
1022
|
|
|
users (list, optional): List of user names to add to the role |
1023
|
|
|
|
1024
|
|
|
Returns: |
1025
|
|
|
The response. See :py:meth:`send_command` for details. |
1026
|
|
|
""" |
1027
|
|
|
|
1028
|
|
|
if not name: |
1029
|
|
|
raise RequiredArgument('create_role requires a name argument') |
1030
|
|
|
|
1031
|
|
|
cmd = XmlCommand('create_role') |
1032
|
|
|
cmd.add_element('name', name) |
1033
|
|
|
|
1034
|
|
|
if comment: |
1035
|
|
|
cmd.add_element('comment', comment) |
1036
|
|
|
|
1037
|
|
|
if users: |
1038
|
|
|
cmd.add_element('users', ",".join(users)) |
1039
|
|
|
|
1040
|
|
|
return self._send_xml_command(cmd) |
1041
|
|
|
|
1042
|
|
|
def clone_role(self, role_id): |
1043
|
|
|
"""Clone an existing role |
1044
|
|
|
|
1045
|
|
|
Arguments: |
1046
|
|
|
copy (str): UUID of an existing role to clone from |
1047
|
|
|
|
1048
|
|
|
Returns: |
1049
|
|
|
The response. See :py:meth:`send_command` for details. |
1050
|
|
|
""" |
1051
|
|
|
if not role_id: |
1052
|
|
|
raise RequiredArgument('clone_role requires a role_id argument') |
1053
|
|
|
|
1054
|
|
|
cmd = XmlCommand('create_role') |
1055
|
|
|
cmd.add_element('copy', role_id) |
1056
|
|
|
return self._send_xml_command(cmd) |
1057
|
|
|
|
1058
|
|
View Code Duplication |
def create_scanner(self, name, host, port, scanner_type, ca_pub, |
|
|
|
|
1059
|
|
|
credential_id, *, comment=None): |
1060
|
|
|
"""Create a new scanner |
1061
|
|
|
|
1062
|
|
|
Arguments: |
1063
|
|
|
name (str): Name of the scanner |
1064
|
|
|
host (str): The host of the scanner |
1065
|
|
|
port (str): The port of the scanner |
1066
|
|
|
scanner_type (str): Type of the scanner. |
1067
|
|
|
'1' for OSP, '2' for OpenVAS (classic) Scanner. |
1068
|
|
|
ca_pub (str): Certificate of CA to verify scanner certificate |
1069
|
|
|
credential_id (str): UUID of client certificate credential for the |
1070
|
|
|
scanner |
1071
|
|
|
comment (str, optional): Comment for the scanner |
1072
|
|
|
|
1073
|
|
|
Returns: |
1074
|
|
|
The response. See :py:meth:`send_command` for details. |
1075
|
|
|
""" |
1076
|
|
|
if not name: |
1077
|
|
|
raise RequiredArgument('create_scanner requires a name argument') |
1078
|
|
|
|
1079
|
|
|
if not host: |
1080
|
|
|
raise RequiredArgument('create_scanner requires a host argument') |
1081
|
|
|
|
1082
|
|
|
if not port: |
1083
|
|
|
raise RequiredArgument('create_scanner requires a port argument') |
1084
|
|
|
|
1085
|
|
|
if not scanner_type: |
1086
|
|
|
raise RequiredArgument('create_scanner requires a scanner_type ' |
1087
|
|
|
'argument') |
1088
|
|
|
if not ca_pub: |
1089
|
|
|
raise RequiredArgument('create_scanner requires a ca_pub argument') |
1090
|
|
|
|
1091
|
|
|
if not credential_id: |
1092
|
|
|
raise RequiredArgument('create_scanner requires a credential_id ' |
1093
|
|
|
'argument') |
1094
|
|
|
|
1095
|
|
|
if scanner_type not in SCANNER_TYPES: |
1096
|
|
|
raise InvalidArgument('create_scanner requires a scanner_type ' |
1097
|
|
|
'argument which must be either "1" for OSP ' |
1098
|
|
|
'or "2" OpenVAS (Classic).') |
1099
|
|
|
|
1100
|
|
|
cmd = XmlCommand('create_scanner') |
1101
|
|
|
cmd.add_element('name', name) |
1102
|
|
|
cmd.add_element('host', host) |
1103
|
|
|
cmd.add_element('port', port) |
1104
|
|
|
cmd.add_element('type', scanner_type) |
1105
|
|
|
cmd.add_element('ca_pub', ca_pub) |
1106
|
|
|
cmd.add_element('credential', attrs={'id': str(credential_id)}) |
1107
|
|
|
|
1108
|
|
|
if comment: |
1109
|
|
|
cmd.add_element('comment', comment) |
1110
|
|
|
|
1111
|
|
|
return self._send_xml_command(cmd) |
1112
|
|
|
|
1113
|
|
|
def clone_scanner(self, scanner_id): |
1114
|
|
|
"""Clone an existing scanner |
1115
|
|
|
|
1116
|
|
|
Arguments: |
1117
|
|
|
copy (str): UUID of an existing scanner to clone from |
1118
|
|
|
|
1119
|
|
|
Returns: |
1120
|
|
|
The response. See :py:meth:`send_command` for details. |
1121
|
|
|
""" |
1122
|
|
|
if not scanner_id: |
1123
|
|
|
raise RequiredArgument( |
1124
|
|
|
'clone_scanner requires a scanner_id argument') |
1125
|
|
|
|
1126
|
|
|
cmd = XmlCommand('create_scanner') |
1127
|
|
|
cmd.add_element('copy', scanner_id) |
1128
|
|
|
return self._send_xml_command(cmd) |
1129
|
|
|
|
1130
|
|
|
def create_schedule(self, name, *, comment=None, first_time_minute=None, |
|
|
|
|
1131
|
|
|
first_time_hour=None, first_time_day_of_month=None, |
1132
|
|
|
first_time_month=None, first_time_year=None, |
1133
|
|
|
duration=None, duration_unit=None, period=None, |
1134
|
|
|
period_unit=None, timezone=None): |
1135
|
|
|
"""Create a new schedule |
1136
|
|
|
|
1137
|
|
|
Arguments: |
1138
|
|
|
name (str): Name of the schedule |
1139
|
|
|
comment (str, optional): Comment for the schedule |
1140
|
|
|
first_time_minute (int, optional): First time minute the schedule |
1141
|
|
|
will run |
1142
|
|
|
first_time_hour (int, optional): First time hour the schedule |
1143
|
|
|
will run |
1144
|
|
|
first_time_day_of_month (int, optional): First time day of month the |
1145
|
|
|
schedule will run |
1146
|
|
|
first_time_month (int, optional): First time month the schedule |
1147
|
|
|
will run |
1148
|
|
|
first_time_year (int, optional): First time year the schedule |
1149
|
|
|
will run |
1150
|
|
|
duration (int, optional): How long the Manager will run the |
1151
|
|
|
scheduled task for until it gets paused if not finished yet. |
1152
|
|
|
duration_unit (str, optional): Unit of the duration. One of second, |
1153
|
|
|
minute, hour, day, week, month, year, decade. Required if |
1154
|
|
|
duration is set. |
1155
|
|
|
period (int, optional): How often the Manager will repeat the |
1156
|
|
|
scheduled task |
1157
|
|
|
period_unit (str, optional): Unit of the period. One of second, |
1158
|
|
|
minute, hour, day, week, month, year, decade. Required if |
1159
|
|
|
period is set. |
1160
|
|
|
timezone (str, optional): The timezone the schedule will follow |
1161
|
|
|
|
1162
|
|
|
Returns: |
1163
|
|
|
The response. See :py:meth:`send_command` for details. |
1164
|
|
|
""" |
1165
|
|
|
if not name: |
1166
|
|
|
raise RequiredArgument('create_schedule requires a name argument') |
1167
|
|
|
|
1168
|
|
|
cmd = XmlCommand('create_schedule') |
1169
|
|
|
cmd.add_element('name', name) |
1170
|
|
|
|
1171
|
|
|
if comment: |
1172
|
|
|
cmd.add_element('comment', comment) |
1173
|
|
|
|
1174
|
|
View Code Duplication |
if first_time_minute or first_time_hour or first_time_day_of_month or \ |
|
|
|
|
1175
|
|
|
first_time_month or first_time_year: |
1176
|
|
|
|
1177
|
|
|
if not first_time_minute: |
1178
|
|
|
raise RequiredArgument( |
1179
|
|
|
'Setting first_time requires first_time_minute argument') |
1180
|
|
|
if not first_time_hour: |
1181
|
|
|
raise RequiredArgument( |
1182
|
|
|
'Setting first_time requires first_time_hour argument') |
1183
|
|
|
if not first_time_day_of_month: |
1184
|
|
|
raise RequiredArgument( |
1185
|
|
|
'Setting first_time requires first_time_day_of_month ' |
1186
|
|
|
'argument') |
1187
|
|
|
if not first_time_month: |
1188
|
|
|
raise RequiredArgument( |
1189
|
|
|
'Setting first_time requires first_time_month argument') |
1190
|
|
|
if not first_time_year: |
1191
|
|
|
raise RequiredArgument( |
1192
|
|
|
'Setting first_time requires first_time_year argument') |
1193
|
|
|
|
1194
|
|
|
_xmlftime = cmd.add_element('first_time') |
1195
|
|
|
_xmlftime.add_element('minute', str(first_time_minute)) |
1196
|
|
|
_xmlftime.add_element('hour', str(first_time_hour)) |
1197
|
|
|
_xmlftime.add_element('day_of_month', str(first_time_day_of_month)) |
1198
|
|
|
_xmlftime.add_element('month', str(first_time_month)) |
1199
|
|
|
_xmlftime.add_element('year', str(first_time_year)) |
1200
|
|
|
|
1201
|
|
View Code Duplication |
if duration: |
|
|
|
|
1202
|
|
|
if not duration_unit: |
1203
|
|
|
raise RequiredArgument( |
1204
|
|
|
'Setting duration requires duration_unit argument') |
1205
|
|
|
|
1206
|
|
|
if not duration_unit in TIME_UNITS: |
1207
|
|
|
raise InvalidArgument( |
1208
|
|
|
'duration_unit must be one of {units} but {actual} has ' |
1209
|
|
|
'been passed'.format( |
1210
|
|
|
units=', '.join(TIME_UNITS), actual=duration_unit)) |
1211
|
|
|
|
1212
|
|
|
_xmlduration = cmd.add_element('duration', str(duration)) |
1213
|
|
|
_xmlduration.add_element('unit', duration_unit) |
1214
|
|
|
|
1215
|
|
View Code Duplication |
if period: |
|
|
|
|
1216
|
|
|
if not period_unit: |
1217
|
|
|
raise RequiredArgument( |
1218
|
|
|
'Setting period requires period_unit argument') |
1219
|
|
|
|
1220
|
|
|
if not period_unit in TIME_UNITS: |
1221
|
|
|
raise InvalidArgument( |
1222
|
|
|
'period_unit must be one of {units} but {actual} has ' |
1223
|
|
|
'been passed'.format( |
1224
|
|
|
units=', '.join(TIME_UNITS), actual=period_unit)) |
1225
|
|
|
|
1226
|
|
|
_xmlperiod = cmd.add_element('period', str(period)) |
1227
|
|
|
_xmlperiod.add_element('unit', period_unit) |
1228
|
|
|
|
1229
|
|
|
if timezone: |
1230
|
|
|
cmd.add_element('timezone', timezone) |
1231
|
|
|
|
1232
|
|
|
return self._send_xml_command(cmd) |
1233
|
|
|
|
1234
|
|
|
def clone_schedule(self, schedule_id): |
1235
|
|
|
"""Clone an existing schedule |
1236
|
|
|
|
1237
|
|
|
Arguments: |
1238
|
|
|
copy (str): UUID of an existing schedule to clone from |
1239
|
|
|
|
1240
|
|
|
Returns: |
1241
|
|
|
The response. See :py:meth:`send_command` for details. |
1242
|
|
|
""" |
1243
|
|
|
if not schedule_id: |
1244
|
|
|
raise RequiredArgument( |
1245
|
|
|
'clone_schedule requires a schedule_id argument') |
1246
|
|
|
|
1247
|
|
|
cmd = XmlCommand('create_schedule') |
1248
|
|
|
cmd.add_element('copy', schedule_id) |
1249
|
|
|
return self._send_xml_command(cmd) |
1250
|
|
|
|
1251
|
|
|
def create_tag(self, name, resource_id, resource_type, *, value=None, |
1252
|
|
|
comment=None, active=None): |
1253
|
|
|
"""Create a new tag |
1254
|
|
|
|
1255
|
|
|
Arguments: |
1256
|
|
|
name (str): Name of the tag. A full tag name consisting of namespace |
1257
|
|
|
and predicate e.g. `foo:bar`. |
1258
|
|
|
resource_id (str): ID of the resource the tag is to be attached to. |
1259
|
|
|
resource_type (str): Entity type the tag is to be attached to |
1260
|
|
|
value (str, optional): Value associated with the tag |
1261
|
|
|
comment (str, optional): Comment for the tag |
1262
|
|
|
active (boolean, optional): Whether the tag should be active |
1263
|
|
|
|
1264
|
|
|
Returns: |
1265
|
|
|
The response. See :py:meth:`send_command` for details. |
1266
|
|
|
""" |
1267
|
|
|
cmd = XmlCommand('create_tag') |
1268
|
|
|
cmd.add_element('name', name) |
1269
|
|
|
_xmlresource = cmd.add_element('resource', |
1270
|
|
|
attrs={'id': str(resource_id)}) |
1271
|
|
|
_xmlresource.add_element('type', resource_type) |
1272
|
|
|
|
1273
|
|
|
if comment: |
1274
|
|
|
cmd.add_element('comment', comment) |
1275
|
|
|
|
1276
|
|
|
if value: |
1277
|
|
|
cmd.add_element('value', value) |
1278
|
|
|
|
1279
|
|
|
if not active is None: |
1280
|
|
|
if active: |
1281
|
|
|
cmd.add_element('active', '1') |
1282
|
|
|
else: |
1283
|
|
|
cmd.add_element('active', '0') |
1284
|
|
|
|
1285
|
|
|
return self._send_xml_command(cmd) |
1286
|
|
|
|
1287
|
|
|
def clone_tag(self, tag_id): |
1288
|
|
|
"""Clone an existing tag |
1289
|
|
|
|
1290
|
|
|
Arguments: |
1291
|
|
|
copy (str): UUID of an existing tag to clone from |
1292
|
|
|
|
1293
|
|
|
Returns: |
1294
|
|
|
The response. See :py:meth:`send_command` for details. |
1295
|
|
|
""" |
1296
|
|
|
if not tag_id: |
1297
|
|
|
raise RequiredArgument('clone_tag requires a tag_id argument') |
1298
|
|
|
|
1299
|
|
|
cmd = XmlCommand('create_tag') |
1300
|
|
|
cmd.add_element('copy', tag_id) |
1301
|
|
|
return self._send_xml_command(cmd) |
1302
|
|
|
|
1303
|
|
|
def create_target(self, name, *, make_unique=False, asset_hosts_filter=None, |
|
|
|
|
1304
|
|
|
hosts=None, comment=None, exclude_hosts=None, |
1305
|
|
|
ssh_credential_id=None, ssh_credential_port=None, |
1306
|
|
|
smb_credential_id=None, esxi_credential_id=None, |
1307
|
|
|
snmp_credential_id=None, alive_tests=None, |
1308
|
|
|
reverse_lookup_only=None, reverse_lookup_unify=None, |
1309
|
|
|
port_range=None, port_list_id=None): |
1310
|
|
|
"""Create a new target |
1311
|
|
|
|
1312
|
|
|
Arguments: |
1313
|
|
|
name (str): Name of the target |
1314
|
|
|
make_unique (boolean, optional): Append a unique suffix if the name |
1315
|
|
|
already exists |
1316
|
|
|
asset_hosts_filter (str, optional): Filter to select target host |
1317
|
|
|
from assets hosts |
1318
|
|
|
hosts (list, optional): List of hosts addresses to scan |
1319
|
|
|
exclude_hosts (list, optional): List of hosts addresses to exclude |
1320
|
|
|
from scan |
1321
|
|
|
comment (str, optional): Comment for the target |
1322
|
|
|
ssh_credential_id (str, optional): UUID of a ssh credential to use |
1323
|
|
|
on target |
1324
|
|
|
ssh_credential_port (str, optional): The port to use for ssh |
1325
|
|
|
credential |
1326
|
|
|
smb_credential_id (str, optional): UUID of a smb credential to use |
1327
|
|
|
on target |
1328
|
|
|
snmp_credential_id (str, optional): UUID of a snmp credential to use |
1329
|
|
|
on target |
1330
|
|
|
esxi_credential_id (str, optional): UUID of a esxi credential to use |
1331
|
|
|
on target |
1332
|
|
|
alive_tests (str, optional): Which alive tests to use |
1333
|
|
|
reverse_lookup_only (boolean, optional): Whether to scan only hosts |
1334
|
|
|
that have names |
1335
|
|
|
reverse_lookup_unify (boolean, optional): Whether to scan only one |
1336
|
|
|
IP when multiple IPs have the same name. |
1337
|
|
|
port_range (str, optional): Port range for the target |
1338
|
|
|
port_list_id (str, optional): UUID of the port list to use on target |
1339
|
|
|
|
1340
|
|
|
Returns: |
1341
|
|
|
The response. See :py:meth:`send_command` for details. |
1342
|
|
|
""" |
1343
|
|
|
if not name: |
1344
|
|
|
raise RequiredArgument('create_target requires a name argument') |
1345
|
|
|
|
1346
|
|
|
cmd = XmlCommand('create_target') |
1347
|
|
|
_xmlname = cmd.add_element('name', name) |
1348
|
|
|
if make_unique: |
1349
|
|
|
_xmlname.add_element('make_unique', '1') |
1350
|
|
|
|
1351
|
|
|
if asset_hosts_filter: |
1352
|
|
|
cmd.add_element('asset_hosts', |
1353
|
|
|
attrs={'filter': str(asset_hosts_filter)}) |
1354
|
|
|
elif hosts: |
1355
|
|
|
cmd.add_element('hosts', ', '.join(hosts)) |
1356
|
|
|
else: |
1357
|
|
|
raise RequiredArgument('create_target requires either a hosts or ' |
1358
|
|
|
'an asset_hosts_filter argument') |
1359
|
|
|
|
1360
|
|
|
if comment: |
1361
|
|
|
cmd.add_element('comment', comment) |
1362
|
|
|
|
1363
|
|
|
if exclude_hosts: |
1364
|
|
|
cmd.add_element('exclude_hosts', ', '.join(exclude_hosts)) |
1365
|
|
|
|
1366
|
|
|
if ssh_credential_id: |
1367
|
|
|
_xmlssh = cmd.add_element('ssh_credential', |
1368
|
|
|
attrs={'id': ssh_credential_id}) |
1369
|
|
|
if ssh_credential_port: |
1370
|
|
|
_xmlssh.add_element('port', ssh_credential_port) |
1371
|
|
|
|
1372
|
|
|
if smb_credential_id: |
1373
|
|
|
cmd.add_element('smb_credential', attrs={'id': smb_credential_id}) |
1374
|
|
|
|
1375
|
|
|
if esxi_credential_id: |
1376
|
|
|
cmd.add_element('esxi_credential', attrs={'id': esxi_credential_id}) |
1377
|
|
|
|
1378
|
|
|
if snmp_credential_id: |
1379
|
|
|
cmd.add_element('snmp_credential', attrs={'id': snmp_credential_id}) |
1380
|
|
|
|
1381
|
|
|
if alive_tests: |
1382
|
|
|
cmd.add_element('alive_tests', alive_tests) |
1383
|
|
|
|
1384
|
|
|
if not reverse_lookup_only is None: |
1385
|
|
|
if reverse_lookup_only: |
1386
|
|
|
cmd.add_element('reverse_lookup_only', '1') |
1387
|
|
|
else: |
1388
|
|
|
cmd.add_element('reverse_lookup_only', '0') |
1389
|
|
|
|
1390
|
|
|
if not reverse_lookup_unify is None: |
1391
|
|
|
if reverse_lookup_unify: |
1392
|
|
|
cmd.add_element('reverse_lookup_unify', '1') |
1393
|
|
|
else: |
1394
|
|
|
cmd.add_element('reverse_lookup_unify', '0') |
1395
|
|
|
|
1396
|
|
|
if port_range: |
1397
|
|
|
cmd.add_element('port_range', port_range) |
1398
|
|
|
|
1399
|
|
|
if port_list_id: |
1400
|
|
|
cmd.add_element('port_list', attrs={'id': port_list_id}) |
1401
|
|
|
|
1402
|
|
|
return self._send_xml_command(cmd) |
1403
|
|
|
|
1404
|
|
|
def clone_target(self, target_id): |
1405
|
|
|
"""Clone an existing target |
1406
|
|
|
|
1407
|
|
|
Arguments: |
1408
|
|
|
copy (str): UUID of an existing target to clone from |
1409
|
|
|
|
1410
|
|
|
Returns: |
1411
|
|
|
The response. See :py:meth:`send_command` for details. |
1412
|
|
|
""" |
1413
|
|
|
if not target_id: |
1414
|
|
|
raise RequiredArgument('clone_target requires a target_id argument') |
1415
|
|
|
|
1416
|
|
|
cmd = XmlCommand('create_target') |
1417
|
|
|
cmd.add_element('copy', target_id) |
1418
|
|
|
return self._send_xml_command(cmd) |
1419
|
|
|
|
1420
|
|
|
def create_task(self, name, config_id, target_id, scanner_id, *, |
1421
|
|
|
alterable=None, hosts_ordering=None, schedule_id=None, |
1422
|
|
|
alert_ids=None, comment=None, schedule_periods=None, |
1423
|
|
|
observers=None): |
1424
|
|
|
"""Create a new task |
1425
|
|
|
|
1426
|
|
|
Arguments: |
1427
|
|
|
name (str): Name of the task |
1428
|
|
|
config_id (str): UUID of scan config to use by the task |
1429
|
|
|
target_id (str): UUID of target to be scanned |
1430
|
|
|
scanner_id (str): UUID of scanner to use for scanning the target |
1431
|
|
|
comment (str, optional): Comment for the task |
1432
|
|
|
alterable (boolean, optional): Whether the task should be alterable |
1433
|
|
|
alert_ids (list, optional): List of UUIDs for alerts to be applied |
1434
|
|
|
to the task |
1435
|
|
|
hosts_ordering (str, optional): The order hosts are scanned in |
1436
|
|
|
schedule_id (str, optional): UUID of a schedule when the task should |
1437
|
|
|
be run. |
1438
|
|
|
schedule_periods (int, optional): A limit to the number of times the |
1439
|
|
|
task will be scheduled, or 0 for no limit |
1440
|
|
|
observers (list, optional): List of user names which should be |
1441
|
|
|
allowed to observe this task |
1442
|
|
|
|
1443
|
|
|
Returns: |
1444
|
|
|
The response. See :py:meth:`send_command` for details. |
1445
|
|
|
""" |
1446
|
|
|
if not name: |
1447
|
|
|
raise RequiredArgument('create_task requires a name argument') |
1448
|
|
|
|
1449
|
|
|
if not config_id: |
1450
|
|
|
raise RequiredArgument('create_task requires a config_id argument') |
1451
|
|
|
|
1452
|
|
|
if not target_id: |
1453
|
|
|
raise RequiredArgument('create_task requires a target_id argument') |
1454
|
|
|
|
1455
|
|
|
if not scanner_id: |
1456
|
|
|
raise RequiredArgument('create_task requires a scanner_id argument') |
1457
|
|
|
|
1458
|
|
|
cmd = XmlCommand('create_task') |
1459
|
|
|
cmd.add_element('name', name) |
1460
|
|
|
cmd.add_element('config', attrs={'id': config_id}) |
1461
|
|
|
cmd.add_element('target', attrs={'id': target_id}) |
1462
|
|
|
cmd.add_element('scanner', attrs={'id': scanner_id}) |
1463
|
|
|
|
1464
|
|
|
if comment: |
1465
|
|
|
cmd.add_element('comment', comment) |
1466
|
|
|
|
1467
|
|
|
if not alterable is None: |
1468
|
|
|
if alterable: |
1469
|
|
|
cmd.add_element('alterable', '1') |
1470
|
|
|
else: |
1471
|
|
|
cmd.add_element('alterable', '0') |
1472
|
|
|
|
1473
|
|
|
if hosts_ordering: |
1474
|
|
|
cmd.add_element('hosts_ordering', hosts_ordering) |
1475
|
|
|
|
1476
|
|
|
if alert_ids: |
1477
|
|
|
if isinstance(alert_ids, str): |
1478
|
|
|
logger.warning( |
1479
|
|
|
'Please pass a list as alert_ids parameter to create_task. ' |
1480
|
|
|
'Passing a string is deprecated and will be removed in ' |
1481
|
|
|
'future.') |
1482
|
|
|
|
1483
|
|
|
#if a single id is given as a string wrap it into a list |
1484
|
|
|
alert_ids = [alert_ids] |
1485
|
|
|
if isinstance(alert_ids, list): |
1486
|
|
|
#parse all given alert id's |
1487
|
|
|
for alert in alert_ids: |
1488
|
|
|
cmd.add_element('alert', attrs={'id': str(alert)}) |
1489
|
|
|
|
1490
|
|
|
if schedule_id: |
1491
|
|
|
cmd.add_element('schedule', schedule_id) |
1492
|
|
|
|
1493
|
|
|
if schedule_periods: |
1494
|
|
|
cmd.add_element('schedule_periods', str(schedule_periods)) |
1495
|
|
|
|
1496
|
|
|
if observers: |
1497
|
|
|
cmd.add_element('observers', ' '.join(observers)) |
1498
|
|
|
|
1499
|
|
|
return self._send_xml_command(cmd) |
1500
|
|
|
|
1501
|
|
|
def clone_task(self, task_id): |
1502
|
|
|
"""Clone an existing task |
1503
|
|
|
|
1504
|
|
|
Arguments: |
1505
|
|
|
task_id (str): UUID of existing task to clone from |
1506
|
|
|
|
1507
|
|
|
Returns: |
1508
|
|
|
The response. See :py:meth:`send_command` for details. |
1509
|
|
|
""" |
1510
|
|
|
if not task_id: |
1511
|
|
|
raise RequiredArgument('clone_task requires a task_id argument') |
1512
|
|
|
|
1513
|
|
|
cmd = XmlCommand('create_task') |
1514
|
|
|
cmd.add_element('copy', task_id) |
1515
|
|
|
return self._send_xml_command(cmd) |
1516
|
|
|
|
1517
|
|
|
def create_user(self, name, *, password=None, hosts=None, hosts_allow=False, |
1518
|
|
|
ifaces=None, ifaces_allow=False, role_ids=None): |
1519
|
|
|
"""Create a new user |
1520
|
|
|
|
1521
|
|
|
Arguments: |
1522
|
|
|
name (str): Name of the user |
1523
|
|
|
password (str, optional): Password of the user |
1524
|
|
|
hosts (list, optional): A list of host addresses (IPs, DNS names) |
1525
|
|
|
hosts_allow (boolean, optional): If True allow only access to passed |
1526
|
|
|
hosts otherwise deny access. Default is False for deny hosts. |
1527
|
|
|
ifaces (list, optional): A list of interface names |
1528
|
|
|
ifaces_allow (boolean, optional): If True allow only access to |
1529
|
|
|
passed interfaces otherwise deny access. Default is False for |
1530
|
|
|
deny interfaces. |
1531
|
|
|
role_ids (list, optional): A list of role UUIDs for the user |
1532
|
|
|
|
1533
|
|
|
Returns: |
1534
|
|
|
The response. See :py:meth:`send_command` for details. |
1535
|
|
|
""" |
1536
|
|
|
if not name: |
1537
|
|
|
raise RequiredArgument('create_user requires a name argument') |
1538
|
|
|
|
1539
|
|
|
cmd = XmlCommand('create_user') |
1540
|
|
|
cmd.add_element('name', name) |
1541
|
|
|
|
1542
|
|
|
if password: |
1543
|
|
|
cmd.add_element('password', password) |
1544
|
|
|
|
1545
|
|
|
if hosts: |
1546
|
|
|
cmd.add_element('hosts', ', '.join(hosts), |
1547
|
|
|
attrs={'allow': '1' if hosts_allow else '0'}) |
1548
|
|
|
|
1549
|
|
|
if ifaces: |
1550
|
|
|
cmd.add_element('ifaces', ', '.join(ifaces), |
1551
|
|
|
attrs={'allow': '1' if ifaces_allow else '0'}) |
1552
|
|
|
|
1553
|
|
|
if role_ids: |
1554
|
|
|
for role in role_ids: |
1555
|
|
|
cmd.add_element('role', attrs={'id': role}) |
1556
|
|
|
|
1557
|
|
|
return self._send_xml_command(cmd) |
1558
|
|
|
|
1559
|
|
|
def clone_user(self, user_id): |
1560
|
|
|
"""Clone an existing user |
1561
|
|
|
|
1562
|
|
|
Arguments: |
1563
|
|
|
user_id (str): UUID of existing user to clone from |
1564
|
|
|
|
1565
|
|
|
Returns: |
1566
|
|
|
The response. See :py:meth:`send_command` for details. |
1567
|
|
|
""" |
1568
|
|
|
if not user_id: |
1569
|
|
|
raise RequiredArgument('clone_user requires a user_id argument') |
1570
|
|
|
|
1571
|
|
|
cmd = XmlCommand('create_user') |
1572
|
|
|
cmd.add_element('copy', user_id) |
1573
|
|
|
return self._send_xml_command(cmd) |
1574
|
|
|
|
1575
|
|
|
def delete_agent(self, agent_id, *, ultimate=False): |
1576
|
|
|
"""Deletes an existing agent |
1577
|
|
|
|
1578
|
|
|
Arguments: |
1579
|
|
|
agent_id (str) UUID of the agent to be deleted. |
1580
|
|
|
ultimate (boolean, optional): Whether to remove entirely, |
1581
|
|
|
or to the trashcan. |
1582
|
|
|
""" |
1583
|
|
|
if not agent_id: |
1584
|
|
|
raise RequiredArgument('delete_agent requires an agent_id argument') |
1585
|
|
|
|
1586
|
|
|
cmd = XmlCommand('delete_agent') |
1587
|
|
|
cmd.set_attribute('agent_id', agent_id) |
1588
|
|
|
cmd.set_attribute('ultimate', _to_bool(ultimate)) |
1589
|
|
|
|
1590
|
|
|
return self._send_xml_command(cmd) |
1591
|
|
|
|
1592
|
|
|
def delete_alert(self, alert_id, *, ultimate=False): |
1593
|
|
|
"""Deletes an existing alert |
1594
|
|
|
|
1595
|
|
|
Arguments: |
1596
|
|
|
alert_id (str) UUID of the alert to be deleted. |
1597
|
|
|
ultimate (boolean, optional): Whether to remove entirely, |
1598
|
|
|
or to the trashcan. |
1599
|
|
|
""" |
1600
|
|
|
if not alert_id: |
1601
|
|
|
raise RequiredArgument('delete_alert requires an alert_id argument') |
1602
|
|
|
|
1603
|
|
|
cmd = XmlCommand('delete_alert') |
1604
|
|
|
cmd.set_attribute('alert_id', alert_id) |
1605
|
|
|
cmd.set_attribute('ultimate', _to_bool(ultimate)) |
1606
|
|
|
|
1607
|
|
|
return self._send_xml_command(cmd) |
1608
|
|
|
|
1609
|
|
|
def delete_asset(self, *, asset_id=None, report_id=None): |
1610
|
|
|
"""Deletes an existing asset |
1611
|
|
|
|
1612
|
|
|
Arguments: |
1613
|
|
|
asset_id (str, optional): UUID of the single asset to delete. |
1614
|
|
|
report_id (str,optional): UUID of report from which to get all |
1615
|
|
|
assets to delete. |
1616
|
|
|
""" |
1617
|
|
|
if not asset_id and not report_id: |
1618
|
|
|
raise RequiredArgument('delete_asset requires an asset_id or ' |
1619
|
|
|
'a report_id argument') |
1620
|
|
|
|
1621
|
|
|
cmd = XmlCommand('delete_asset') |
1622
|
|
|
if asset_id: |
1623
|
|
|
cmd.set_attribute('asset_id', asset_id) |
1624
|
|
|
else: |
1625
|
|
|
cmd.set_attribute('report_id', report_id) |
1626
|
|
|
|
1627
|
|
|
return self._send_xml_command(cmd) |
1628
|
|
|
|
1629
|
|
|
def delete_config(self, config_id, *, ultimate=False): |
1630
|
|
|
"""Deletes an existing config |
1631
|
|
|
|
1632
|
|
|
Arguments: |
1633
|
|
|
config_id (str) UUID of the config to be deleted. |
1634
|
|
|
ultimate (boolean, optional): Whether to remove entirely, |
1635
|
|
|
or to the trashcan. |
1636
|
|
|
""" |
1637
|
|
|
if not config_id: |
1638
|
|
|
raise RequiredArgument('delete_config requires a ' |
1639
|
|
|
'config_id argument') |
1640
|
|
|
|
1641
|
|
|
cmd = XmlCommand('delete_config') |
1642
|
|
|
cmd.set_attribute('config_id', config_id) |
1643
|
|
|
cmd.set_attribute('ultimate', _to_bool(ultimate)) |
1644
|
|
|
|
1645
|
|
|
return self._send_xml_command(cmd) |
1646
|
|
|
|
1647
|
|
|
def delete_credential(self, credential_id, *, ultimate=False): |
1648
|
|
|
"""Deletes an existing credential |
1649
|
|
|
|
1650
|
|
|
Arguments: |
1651
|
|
|
credential_id (str) UUID of the credential to be deleted. |
1652
|
|
|
ultimate (boolean, optional): Whether to remove entirely, |
1653
|
|
|
or to the trashcan. |
1654
|
|
|
""" |
1655
|
|
|
if not credential_id: |
1656
|
|
|
raise RequiredArgument('delete_credential requires a ' |
1657
|
|
|
'credential_id argument') |
1658
|
|
|
|
1659
|
|
|
cmd = XmlCommand('delete_credential') |
1660
|
|
|
cmd.set_attribute('credential_id', credential_id) |
1661
|
|
|
cmd.set_attribute('ultimate', _to_bool(ultimate)) |
1662
|
|
|
|
1663
|
|
|
return self._send_xml_command(cmd) |
1664
|
|
|
|
1665
|
|
|
def delete_filter(self, filter_id, *, ultimate=False): |
1666
|
|
|
"""Deletes an existing filter |
1667
|
|
|
|
1668
|
|
|
Arguments: |
1669
|
|
|
filter_id (str) UUID of the filter to be deleted. |
1670
|
|
|
ultimate (boolean, optional): Whether to remove entirely, |
1671
|
|
|
or to the trashcan. |
1672
|
|
|
""" |
1673
|
|
|
if not filter_id: |
1674
|
|
|
raise RequiredArgument('delete_filter requires a ' |
1675
|
|
|
'filter_id argument') |
1676
|
|
|
|
1677
|
|
|
cmd = XmlCommand('delete_filter') |
1678
|
|
|
cmd.set_attribute('filter_id', filter_id) |
1679
|
|
|
cmd.set_attribute('ultimate', _to_bool(ultimate)) |
1680
|
|
|
|
1681
|
|
|
return self._send_xml_command(cmd) |
1682
|
|
|
|
1683
|
|
|
def delete_group(self, group_id, *, ultimate=False): |
1684
|
|
|
"""Deletes an existing group |
1685
|
|
|
|
1686
|
|
|
Arguments: |
1687
|
|
|
group_id (str) UUID of the group to be deleted. |
1688
|
|
|
ultimate (boolean, optional): Whether to remove entirely, |
1689
|
|
|
or to the trashcan. |
1690
|
|
|
""" |
1691
|
|
|
if not group_id: |
1692
|
|
|
raise RequiredArgument('delete_group requires a ' |
1693
|
|
|
'group_id argument') |
1694
|
|
|
|
1695
|
|
|
cmd = XmlCommand('delete_group') |
1696
|
|
|
cmd.set_attribute('group_id', group_id) |
1697
|
|
|
cmd.set_attribute('ultimate', _to_bool(ultimate)) |
1698
|
|
|
|
1699
|
|
|
return self._send_xml_command(cmd) |
1700
|
|
|
|
1701
|
|
|
def delete_note(self, note_id, *, ultimate=False): |
1702
|
|
|
"""Deletes an existing note |
1703
|
|
|
|
1704
|
|
|
Arguments: |
1705
|
|
|
note_id (str) UUID of the note to be deleted. |
1706
|
|
|
ultimate (boolean, optional): Whether to remove entirely, |
1707
|
|
|
or to the trashcan. |
1708
|
|
|
""" |
1709
|
|
|
if not note_id: |
1710
|
|
|
raise RequiredArgument('delete_note requires a ' |
1711
|
|
|
'note_id argument') |
1712
|
|
|
|
1713
|
|
|
cmd = XmlCommand('delete_note') |
1714
|
|
|
cmd.set_attribute('note_id', note_id) |
1715
|
|
|
cmd.set_attribute('ultimate', _to_bool(ultimate)) |
1716
|
|
|
|
1717
|
|
|
return self._send_xml_command(cmd) |
1718
|
|
|
|
1719
|
|
|
def delete_override(self, override_id, *, ultimate=False): |
1720
|
|
|
"""Deletes an existing override |
1721
|
|
|
|
1722
|
|
|
Arguments: |
1723
|
|
|
override_id (str) UUID of the override to be deleted. |
1724
|
|
|
ultimate (boolean, optional): Whether to remove entirely, |
1725
|
|
|
or to the trashcan. |
1726
|
|
|
""" |
1727
|
|
|
if not override_id: |
1728
|
|
|
raise RequiredArgument('delete_override requires a ' |
1729
|
|
|
'override_id argument') |
1730
|
|
|
|
1731
|
|
|
cmd = XmlCommand('delete_override') |
1732
|
|
|
cmd.set_attribute('override_id', override_id) |
1733
|
|
|
cmd.set_attribute('ultimate', _to_bool(ultimate)) |
1734
|
|
|
|
1735
|
|
|
return self._send_xml_command(cmd) |
1736
|
|
|
|
1737
|
|
|
def delete_permission(self, permission_id, *, ultimate=False): |
1738
|
|
|
"""Deletes an existing permission |
1739
|
|
|
|
1740
|
|
|
Arguments: |
1741
|
|
|
permission_id (str) UUID of the permission to be deleted. |
1742
|
|
|
ultimate (boolean, optional): Whether to remove entirely, |
1743
|
|
|
or to the trashcan. |
1744
|
|
|
""" |
1745
|
|
|
if not permission_id: |
1746
|
|
|
raise RequiredArgument('delete_permission requires a ' |
1747
|
|
|
'permission_id argument') |
1748
|
|
|
|
1749
|
|
|
cmd = XmlCommand('delete_permission') |
1750
|
|
|
cmd.set_attribute('permission_id', permission_id) |
1751
|
|
|
cmd.set_attribute('ultimate', _to_bool(ultimate)) |
1752
|
|
|
|
1753
|
|
|
return self._send_xml_command(cmd) |
1754
|
|
|
|
1755
|
|
|
def delete_port_list(self, port_list_id, *, ultimate=False): |
1756
|
|
|
"""Deletes an existing port list |
1757
|
|
|
|
1758
|
|
|
Arguments: |
1759
|
|
|
port_list_id (str) UUID of the port list to be deleted. |
1760
|
|
|
ultimate (boolean, optional): Whether to remove entirely, |
1761
|
|
|
or to the trashcan. |
1762
|
|
|
""" |
1763
|
|
|
if not port_list_id: |
1764
|
|
|
raise RequiredArgument('delete_port_list requires a ' |
1765
|
|
|
'port_list_id argument') |
1766
|
|
|
|
1767
|
|
|
cmd = XmlCommand('delete_port_list') |
1768
|
|
|
cmd.set_attribute('port_list_id', port_list_id) |
1769
|
|
|
cmd.set_attribute('ultimate', _to_bool(ultimate)) |
1770
|
|
|
|
1771
|
|
|
return self._send_xml_command(cmd) |
1772
|
|
|
|
1773
|
|
|
def delete_port_range(self, port_range_id): |
1774
|
|
|
"""Deletes an existing port range |
1775
|
|
|
|
1776
|
|
|
Arguments: |
1777
|
|
|
port_range_id (str) UUID of the port range to be deleted. |
1778
|
|
|
""" |
1779
|
|
|
if not port_range_id: |
1780
|
|
|
raise RequiredArgument('delete_port_range requires a ' |
1781
|
|
|
'port_range_id argument') |
1782
|
|
|
|
1783
|
|
|
cmd = XmlCommand('delete_port_range') |
1784
|
|
|
cmd.set_attribute('port_range_id', port_range_id) |
1785
|
|
|
|
1786
|
|
|
return self._send_xml_command(cmd) |
1787
|
|
|
|
1788
|
|
|
def delete_report(self, report_id): |
1789
|
|
|
"""Deletes an existing report |
1790
|
|
|
|
1791
|
|
|
Arguments: |
1792
|
|
|
report_id (str) UUID of the report to be deleted. |
1793
|
|
|
""" |
1794
|
|
|
if not report_id: |
1795
|
|
|
raise RequiredArgument('delete_report requires a ' |
1796
|
|
|
'report_id argument') |
1797
|
|
|
|
1798
|
|
|
cmd = XmlCommand('delete_report') |
1799
|
|
|
cmd.set_attribute('report_id', report_id) |
1800
|
|
|
|
1801
|
|
|
return self._send_xml_command(cmd) |
1802
|
|
|
|
1803
|
|
|
|
1804
|
|
|
def delete_report_format(self, report_format_id, *, ultimate=False): |
1805
|
|
|
"""Deletes an existing report format |
1806
|
|
|
|
1807
|
|
|
Arguments: |
1808
|
|
|
report_format_id (str) UUID of the report format to be deleted. |
1809
|
|
|
ultimate (boolean, optional): Whether to remove entirely, |
1810
|
|
|
or to the trashcan. |
1811
|
|
|
""" |
1812
|
|
|
if not report_format_id: |
1813
|
|
|
raise RequiredArgument('delete_report_format requires a ' |
1814
|
|
|
'report_format_id argument') |
1815
|
|
|
|
1816
|
|
|
cmd = XmlCommand('delete_report_format') |
1817
|
|
|
cmd.set_attribute('report_format_id', report_format_id) |
1818
|
|
|
cmd.set_attribute('ultimate', _to_bool(ultimate)) |
1819
|
|
|
|
1820
|
|
|
return self._send_xml_command(cmd) |
1821
|
|
|
|
1822
|
|
|
|
1823
|
|
|
def delete_role(self, role_id, *, ultimate=False): |
1824
|
|
|
"""Deletes an existing role |
1825
|
|
|
|
1826
|
|
|
Arguments: |
1827
|
|
|
role_id (str) UUID of the role to be deleted. |
1828
|
|
|
ultimate (boolean, optional): Whether to remove entirely, |
1829
|
|
|
or to the trashcan. |
1830
|
|
|
""" |
1831
|
|
|
if not role_id: |
1832
|
|
|
raise RequiredArgument('delete_role requires a ' |
1833
|
|
|
'role_id argument') |
1834
|
|
|
|
1835
|
|
|
cmd = XmlCommand('delete_role') |
1836
|
|
|
cmd.set_attribute('role_id', role_id) |
1837
|
|
|
cmd.set_attribute('ultimate', _to_bool(ultimate)) |
1838
|
|
|
|
1839
|
|
|
return self._send_xml_command(cmd) |
1840
|
|
|
|
1841
|
|
|
def delete_scanner(self, scanner_id, *, ultimate=False): |
1842
|
|
|
"""Deletes an existing scanner |
1843
|
|
|
|
1844
|
|
|
Arguments: |
1845
|
|
|
scanner_id (str) UUID of the scanner to be deleted. |
1846
|
|
|
ultimate (boolean, optional): Whether to remove entirely, |
1847
|
|
|
or to the trashcan. |
1848
|
|
|
""" |
1849
|
|
|
if not scanner_id: |
1850
|
|
|
raise RequiredArgument('delete_scanner requires a ' |
1851
|
|
|
'scanner_id argument') |
1852
|
|
|
|
1853
|
|
|
cmd = XmlCommand('delete_scanner') |
1854
|
|
|
cmd.set_attribute('scanner_id', scanner_id) |
1855
|
|
|
cmd.set_attribute('ultimate', _to_bool(ultimate)) |
1856
|
|
|
|
1857
|
|
|
return self._send_xml_command(cmd) |
1858
|
|
|
|
1859
|
|
|
def delete_schedule(self, schedule_id, *, ultimate=False): |
1860
|
|
|
"""Deletes an existing schedule |
1861
|
|
|
|
1862
|
|
|
Arguments: |
1863
|
|
|
schedule_id (str) UUID of the schedule to be deleted. |
1864
|
|
|
ultimate (boolean, optional): Whether to remove entirely, |
1865
|
|
|
or to the trashcan. |
1866
|
|
|
""" |
1867
|
|
|
if not schedule_id: |
1868
|
|
|
raise RequiredArgument('delete_schedule requires a ' |
1869
|
|
|
'schedule_id argument') |
1870
|
|
|
|
1871
|
|
|
cmd = XmlCommand('delete_schedule') |
1872
|
|
|
cmd.set_attribute('schedule_id', schedule_id) |
1873
|
|
|
cmd.set_attribute('ultimate', _to_bool(ultimate)) |
1874
|
|
|
|
1875
|
|
|
return self._send_xml_command(cmd) |
1876
|
|
|
|
1877
|
|
|
def delete_tag(self, tag_id, *, ultimate=False): |
1878
|
|
|
"""Deletes an existing tag |
1879
|
|
|
|
1880
|
|
|
Arguments: |
1881
|
|
|
tag_id (str) UUID of the tag to be deleted. |
1882
|
|
|
ultimate (boolean, optional): Whether to remove entirely, |
1883
|
|
|
or to the trashcan. |
1884
|
|
|
""" |
1885
|
|
|
if not tag_id: |
1886
|
|
|
raise RequiredArgument('delete_tag requires a ' |
1887
|
|
|
'tag_id argument') |
1888
|
|
|
|
1889
|
|
|
cmd = XmlCommand('delete_tag') |
1890
|
|
|
cmd.set_attribute('tag_id', tag_id) |
1891
|
|
|
cmd.set_attribute('ultimate', _to_bool(ultimate)) |
1892
|
|
|
|
1893
|
|
|
return self._send_xml_command(cmd) |
1894
|
|
|
|
1895
|
|
|
def delete_target(self, target_id, *, ultimate=False): |
1896
|
|
|
"""Deletes an existing target |
1897
|
|
|
|
1898
|
|
|
Arguments: |
1899
|
|
|
target_id (str) UUID of the target to be deleted. |
1900
|
|
|
ultimate (boolean, optional): Whether to remove entirely, |
1901
|
|
|
or to the trashcan. |
1902
|
|
|
""" |
1903
|
|
|
if not target_id: |
1904
|
|
|
raise RequiredArgument('delete_target requires a ' |
1905
|
|
|
'target_id argument') |
1906
|
|
|
|
1907
|
|
|
cmd = XmlCommand('delete_target') |
1908
|
|
|
cmd.set_attribute('target_id', target_id) |
1909
|
|
|
cmd.set_attribute('ultimate', _to_bool(ultimate)) |
1910
|
|
|
|
1911
|
|
|
return self._send_xml_command(cmd) |
1912
|
|
|
|
1913
|
|
|
def delete_task(self, task_id, *, ultimate=False): |
1914
|
|
|
"""Deletes an existing task |
1915
|
|
|
|
1916
|
|
|
Arguments: |
1917
|
|
|
task_id (str) UUID of the task to be deleted. |
1918
|
|
|
ultimate (boolean, optional): Whether to remove entirely, |
1919
|
|
|
or to the trashcan. |
1920
|
|
|
""" |
1921
|
|
|
if not task_id: |
1922
|
|
|
raise RequiredArgument('delete_task requires a ' |
1923
|
|
|
'task_id argument') |
1924
|
|
|
|
1925
|
|
|
cmd = XmlCommand('delete_task') |
1926
|
|
|
cmd.set_attribute('task_id', task_id) |
1927
|
|
|
cmd.set_attribute('ultimate', _to_bool(ultimate)) |
1928
|
|
|
|
1929
|
|
|
return self._send_xml_command(cmd) |
1930
|
|
|
|
1931
|
|
|
def delete_user(self, user_id, *, name=None, inheritor_id=None, |
1932
|
|
|
inheritor_name=None): |
1933
|
|
|
"""Deletes an existing user |
1934
|
|
|
|
1935
|
|
|
Arguments: |
1936
|
|
|
user_id (str): UUID of the task to be deleted. |
1937
|
|
|
name (str, optional): The name of the user to be deleted. |
1938
|
|
|
inheritor_id (str, optional): The ID of the inheriting user |
1939
|
|
|
or "self". Overrides inheritor_name. |
1940
|
|
|
inheritor_name (str, optional): The name of the inheriting user. |
1941
|
|
|
|
1942
|
|
|
""" |
1943
|
|
|
if not user_id: |
1944
|
|
|
raise RequiredArgument('delete_user requires a ' |
1945
|
|
|
'user_id argument') |
1946
|
|
|
|
1947
|
|
|
cmd = XmlCommand('delete_user') |
1948
|
|
|
cmd.set_attribute('user_id', user_id) |
1949
|
|
|
|
1950
|
|
|
if name: |
1951
|
|
|
cmd.set_attribute('name', name) |
1952
|
|
|
|
1953
|
|
|
if not inheritor_id and not inheritor_name: |
1954
|
|
|
raise RequiredArgument('delete_user requires a ' |
1955
|
|
|
'inheritor_id or inheritor_name argument') |
1956
|
|
|
if inheritor_id: |
1957
|
|
|
cmd.set_attribute('inheritor_id', inheritor_id) |
1958
|
|
|
|
1959
|
|
|
if inheritor_name: |
1960
|
|
|
cmd.set_attribute('inheritor_name', inheritor_name) |
1961
|
|
|
|
1962
|
|
|
return self._send_xml_command(cmd) |
1963
|
|
|
|
1964
|
|
|
def describe_auth(self): |
1965
|
|
|
"""Describe authentication methods |
1966
|
|
|
|
1967
|
|
|
Returns a list of all used authentication methods if such a list is |
1968
|
|
|
available. |
1969
|
|
|
|
1970
|
|
|
Returns: |
1971
|
|
|
The response. See :py:meth:`send_command` for details. |
1972
|
|
|
""" |
1973
|
|
|
return self._send_xml_command(XmlCommand('describe_auth')) |
1974
|
|
|
|
1975
|
|
|
def empty_trashcan(self): |
1976
|
|
|
"""Empty the trashcan |
1977
|
|
|
|
1978
|
|
|
Remove all entities from the trashcan. **Attention:** this command can |
1979
|
|
|
not be reverted |
1980
|
|
|
|
1981
|
|
|
Returns: |
1982
|
|
|
The response. See :py:meth:`send_command` for details. |
1983
|
|
|
""" |
1984
|
|
|
return self._send_xml_command(XmlCommand('empty_trashcan')) |
1985
|
|
|
|
1986
|
|
|
def get_agents(self, *, filter=None, filter_id=None, trash=None, |
1987
|
|
|
details=None, format=None): |
1988
|
|
|
"""Request a list of agents |
1989
|
|
|
|
1990
|
|
|
Arguments: |
1991
|
|
|
filter (str, optional): Filter term to use for the query |
1992
|
|
|
filter_id (str, optional): UUID of an existing filter to use for |
1993
|
|
|
the query |
1994
|
|
|
trash (boolean, optional): True to request the agents in the |
1995
|
|
|
trashcan |
1996
|
|
|
details (boolean, optional): Whether to include agents package |
1997
|
|
|
information when no format was provided |
1998
|
|
|
format (str, optional): One of "installer", "howto_install" or |
1999
|
|
|
"howto_use" |
2000
|
|
|
|
2001
|
|
|
Returns: |
2002
|
|
|
The response. See :py:meth:`send_command` for details. |
2003
|
|
|
""" |
2004
|
|
|
cmd = XmlCommand('get_agents') |
2005
|
|
|
|
2006
|
|
|
_add_filter(cmd, filter, filter_id) |
2007
|
|
|
|
2008
|
|
|
if not trash is None: |
2009
|
|
|
cmd.set_attribute('trash', _to_bool(trash)) |
2010
|
|
|
|
2011
|
|
|
if not details is None: |
2012
|
|
|
cmd.set_attribute('details', _to_bool(details)) |
2013
|
|
|
|
2014
|
|
|
if format: |
2015
|
|
|
if not format in ('installer', 'howto_install', 'howto_use'): |
2016
|
|
|
raise InvalidArgument( |
2017
|
|
|
'installer argument needs to be one of installer, ' |
2018
|
|
|
'howto_install or howto_use') |
2019
|
|
|
|
2020
|
|
|
cmd.set_attribute('format', format) |
2021
|
|
|
|
2022
|
|
|
return self._send_xml_command(cmd) |
2023
|
|
|
|
2024
|
|
|
def get_agent(self, agent_id): |
2025
|
|
|
"""Request a single agent |
2026
|
|
|
|
2027
|
|
|
Arguments: |
2028
|
|
|
agent_id (str): UUID of an existing agent |
2029
|
|
|
|
2030
|
|
|
Returns: |
2031
|
|
|
The response. See :py:meth:`send_command` for details. |
2032
|
|
|
""" |
2033
|
|
|
cmd = XmlCommand('get_agents') |
2034
|
|
|
cmd.set_attribute('agent_id', agent_id) |
2035
|
|
|
|
2036
|
|
|
# for single entity always request all details |
2037
|
|
|
cmd.set_attribute('details', '1') |
2038
|
|
|
return self._send_xml_command(cmd) |
2039
|
|
|
|
2040
|
|
|
def get_aggregates(self, **kwargs): |
2041
|
|
|
cmd = XmlCommand('get_aggregates') |
2042
|
|
|
cmd.set_attributes(kwargs) |
2043
|
|
|
return self._send_xml_command(cmd) |
2044
|
|
|
|
2045
|
|
View Code Duplication |
def get_alerts(self, *, filter=None, filter_id=None, trash=None, |
|
|
|
|
2046
|
|
|
tasks=None): |
2047
|
|
|
"""Request a list of alerts |
2048
|
|
|
|
2049
|
|
|
Arguments: |
2050
|
|
|
filter (str, optional): Filter term to use for the query |
2051
|
|
|
filter_id (str, optional): UUID of an existing filter to use for |
2052
|
|
|
the query |
2053
|
|
|
trash (boolean, optional): True to request the alerts in the |
2054
|
|
|
trashcan |
2055
|
|
|
tasks (boolean, optional): Whether to include the tasks using the |
2056
|
|
|
alerts |
2057
|
|
|
Returns: |
2058
|
|
|
The response. See :py:meth:`send_command` for details. |
2059
|
|
|
""" |
2060
|
|
|
cmd = XmlCommand('get_alerts') |
2061
|
|
|
|
2062
|
|
|
_add_filter(cmd, filter, filter_id) |
2063
|
|
|
|
2064
|
|
|
if not trash is None: |
2065
|
|
|
cmd.set_attribute('trash', _to_bool(trash)) |
2066
|
|
|
|
2067
|
|
|
if not tasks is None: |
2068
|
|
|
cmd.set_attribute('tasks', _to_bool(tasks)) |
2069
|
|
|
|
2070
|
|
|
return self._send_xml_command(cmd) |
2071
|
|
|
|
2072
|
|
|
def get_alert(self, alert_id): |
2073
|
|
|
"""Request a single alert |
2074
|
|
|
|
2075
|
|
|
Arguments: |
2076
|
|
|
alert_id (str): UUID of an existing alert |
2077
|
|
|
|
2078
|
|
|
Returns: |
2079
|
|
|
The response. See :py:meth:`send_command` for details. |
2080
|
|
|
""" |
2081
|
|
|
cmd = XmlCommand('get_alerts') |
2082
|
|
|
cmd.set_attribute('alert_id', alert_id) |
2083
|
|
|
return self._send_xml_command(cmd) |
2084
|
|
|
|
2085
|
|
|
def get_assets(self, asset_type, *, filter=None, filter_id=None): |
2086
|
|
|
"""Request a list of assets |
2087
|
|
|
|
2088
|
|
|
Arguments: |
2089
|
|
|
asset_type (str): Either 'os' or 'host' |
2090
|
|
|
filter (str, optional): Filter term to use for the query |
2091
|
|
|
filter_id (str, optional): UUID of an existing filter to use for |
2092
|
|
|
the query |
2093
|
|
|
|
2094
|
|
|
Returns: |
2095
|
|
|
The response. See :py:meth:`send_command` for details. |
2096
|
|
|
""" |
2097
|
|
|
if not asset_type in ('os', 'host'): |
2098
|
|
|
raise InvalidArgument('asset_type must be either os or host') |
2099
|
|
|
|
2100
|
|
|
cmd = XmlCommand('get_assets') |
2101
|
|
|
|
2102
|
|
|
_add_filter(cmd, filter, filter_id) |
2103
|
|
|
|
2104
|
|
|
cmd.set_attribute('type', asset_type) |
2105
|
|
|
|
2106
|
|
|
return self._send_xml_command(cmd) |
2107
|
|
|
|
2108
|
|
|
def get_asset(self, asset_id, asset_type): |
2109
|
|
|
"""Request a single asset |
2110
|
|
|
|
2111
|
|
|
Arguments: |
2112
|
|
|
asset_type (str): Either 'os' or 'host' |
2113
|
|
|
asset_id (str): UUID of an existing asset |
2114
|
|
|
|
2115
|
|
|
Returns: |
2116
|
|
|
The response. See :py:meth:`send_command` for details. |
2117
|
|
|
""" |
2118
|
|
|
if not asset_type in ('os', 'host'): |
2119
|
|
|
raise InvalidArgument('asset_type must be either os or host') |
2120
|
|
|
|
2121
|
|
|
cmd = XmlCommand('get_assets') |
2122
|
|
|
cmd.set_attribute('asset_id', asset_id) |
2123
|
|
|
cmd.set_attribute('type', asset_type) |
2124
|
|
|
|
2125
|
|
|
return self._send_xml_command(cmd) |
2126
|
|
|
|
2127
|
|
|
def get_credentials(self, *, filter=None, filter_id=None, scanners=None, |
2128
|
|
|
trash=None, targets=None, format=None): |
2129
|
|
|
"""Request a list of credentials |
2130
|
|
|
|
2131
|
|
|
Arguments: |
2132
|
|
|
filter (str, optional): Filter term to use for the query |
2133
|
|
|
filter_id (str, optional): UUID of an existing filter to use for |
2134
|
|
|
the query |
2135
|
|
|
scanners (boolean, optional): Whether to include a list of scanners |
2136
|
|
|
using the credentials |
2137
|
|
|
trash (boolean, optional): Whether to get the trashcan credentials |
2138
|
|
|
instead |
2139
|
|
|
targets (boolean, optional): Whether to include a list of targets |
2140
|
|
|
using the credentials |
2141
|
|
|
format (str, optional): One of "key", "rpm", "deb" or "exe" |
2142
|
|
|
|
2143
|
|
|
Returns: |
2144
|
|
|
The response. See :py:meth:`send_command` for details. |
2145
|
|
|
""" |
2146
|
|
|
cmd = XmlCommand('get_credentials') |
2147
|
|
|
|
2148
|
|
|
_add_filter(cmd, filter, filter_id) |
2149
|
|
|
|
2150
|
|
|
if not scanners is None: |
2151
|
|
|
cmd.set_attribute('scanners', _to_bool(scanners)) |
2152
|
|
|
|
2153
|
|
|
if not trash is None: |
2154
|
|
|
cmd.set_attribute('trash', _to_bool(trash)) |
2155
|
|
|
|
2156
|
|
|
if not targets is None: |
2157
|
|
|
cmd.set_attribute('targets', _to_bool(targets)) |
2158
|
|
|
|
2159
|
|
|
if format: |
2160
|
|
|
if not format in ('key', 'rpm', 'deb', 'exe'): |
2161
|
|
|
raise InvalidArgument( |
2162
|
|
|
'format argument needs to one of key, rpm, deb or exe') |
2163
|
|
|
|
2164
|
|
|
cmd.set_attribute('format', format) |
2165
|
|
|
|
2166
|
|
|
return self.send_command(cmd) |
2167
|
|
|
|
2168
|
|
|
def get_credential(self, credential_id): |
2169
|
|
|
"""Request a single credential |
2170
|
|
|
|
2171
|
|
|
Arguments: |
2172
|
|
|
credential_id (str): UUID of an existing credential |
2173
|
|
|
|
2174
|
|
|
Returns: |
2175
|
|
|
The response. See :py:meth:`send_command` for details. |
2176
|
|
|
""" |
2177
|
|
|
cmd = XmlCommand('get_credentials') |
2178
|
|
|
cmd.set_attribute('credential_id', credential_id) |
2179
|
|
|
return self._send_xml_command(cmd) |
2180
|
|
|
|
2181
|
|
|
def get_configs(self, *, filter=None, filter_id=None, trash=None, |
2182
|
|
|
details=None, families=None, preferences=None, tasks=None): |
2183
|
|
|
"""Request a list of scan configs |
2184
|
|
|
|
2185
|
|
|
Arguments: |
2186
|
|
|
filter (str, optional): Filter term to use for the query |
2187
|
|
|
filter_id (str, optional): UUID of an existing filter to use for |
2188
|
|
|
the query |
2189
|
|
|
trash (boolean, optional): Whether to get the trashcan scan configs |
2190
|
|
|
instead |
2191
|
|
|
details (boolean, optional): Whether to get config families, |
2192
|
|
|
preferences, nvt selectors and tasks. |
2193
|
|
|
families (boolean, optional): Whether to include the families if no |
2194
|
|
|
details are requested |
2195
|
|
|
preferences (boolean, optional): Whether to include the preferences |
2196
|
|
|
if no details are requested |
2197
|
|
|
tasks (boolean, optional): Whether to get tasks using this config |
2198
|
|
|
|
2199
|
|
|
Returns: |
2200
|
|
|
The response. See :py:meth:`send_command` for details. |
2201
|
|
|
""" |
2202
|
|
|
cmd = XmlCommand('get_configs') |
2203
|
|
|
|
2204
|
|
|
_add_filter(cmd, filter, filter_id) |
2205
|
|
|
|
2206
|
|
|
if not trash is None: |
2207
|
|
|
cmd.set_attribute('trash', _to_bool(trash)) |
2208
|
|
|
|
2209
|
|
|
if not details is None: |
2210
|
|
|
cmd.set_attribute('details', _to_bool(details)) |
2211
|
|
|
|
2212
|
|
|
if not families is None: |
2213
|
|
|
cmd.set_attribute('families', _to_bool(families)) |
2214
|
|
|
|
2215
|
|
|
if not preferences is None: |
2216
|
|
|
cmd.set_attribute('preferences', _to_bool(preferences)) |
2217
|
|
|
|
2218
|
|
|
if not tasks is None: |
2219
|
|
|
cmd.set_attribute('tasks', _to_bool(tasks)) |
2220
|
|
|
|
2221
|
|
|
return self._send_xml_command(cmd) |
2222
|
|
|
|
2223
|
|
|
def get_config(self, config_id): |
2224
|
|
|
"""Request a single scan config |
2225
|
|
|
|
2226
|
|
|
Arguments: |
2227
|
|
|
config_id (str): UUID of an existing scan config |
2228
|
|
|
|
2229
|
|
|
Returns: |
2230
|
|
|
The response. See :py:meth:`send_command` for details. |
2231
|
|
|
""" |
2232
|
|
|
cmd = XmlCommand('get_configs') |
2233
|
|
|
cmd.set_attribute('config_id', config_id) |
2234
|
|
|
|
2235
|
|
|
# for single entity always request all details |
2236
|
|
|
cmd.set_attribute('details', '1') |
2237
|
|
|
return self._send_xml_command(cmd) |
2238
|
|
|
|
2239
|
|
|
def get_feeds(self): |
2240
|
|
|
"""Request the list of feeds |
2241
|
|
|
|
2242
|
|
|
Returns: |
2243
|
|
|
The response. See :py:meth:`send_command` for details. |
2244
|
|
|
""" |
2245
|
|
|
return self._send_xml_command(XmlCommand('get_feeds')) |
2246
|
|
|
|
2247
|
|
|
def get_feed(self, feed_type): |
2248
|
|
|
"""Request a single feed |
2249
|
|
|
|
2250
|
|
|
Arguments: |
2251
|
|
|
feed_type (str): Type of single feed to get: NVT, CERT or SCAP |
2252
|
|
|
|
2253
|
|
|
Returns: |
2254
|
|
|
The response. See :py:meth:`send_command` for details. |
2255
|
|
|
""" |
2256
|
|
|
feed_type = feed_type.upper() |
2257
|
|
|
|
2258
|
|
|
if not feed_type in ('NVT', 'CERT', 'SCAP'): |
2259
|
|
|
raise InvalidArgument( |
2260
|
|
|
'get_feed type arguments must be one of NVT, CERT or SCAP') |
2261
|
|
|
|
2262
|
|
|
cmd = XmlCommand('get_feeds') |
2263
|
|
|
cmd.set_attribute('type', feed_type) |
2264
|
|
|
|
2265
|
|
|
return self._send_xml_command(cmd) |
2266
|
|
|
|
2267
|
|
|
def get_filters(self, *, filter=None, filter_id=None, trash=None, |
2268
|
|
|
alerts=None): |
2269
|
|
|
"""Request a list of filters |
2270
|
|
|
|
2271
|
|
|
Arguments: |
2272
|
|
|
filter (str, optional): Filter term to use for the query |
2273
|
|
|
filter_id (str, optional): UUID of an existing filter to use for |
2274
|
|
|
the query |
2275
|
|
|
trash (boolean, optional): Whether to get the trashcan filters |
2276
|
|
|
instead |
2277
|
|
|
alerts (boolean, optional): Whether to include list of alerts that |
2278
|
|
|
use the filter. |
2279
|
|
|
|
2280
|
|
|
Returns: |
2281
|
|
|
The response. See :py:meth:`send_command` for details. |
2282
|
|
|
""" |
2283
|
|
|
cmd = XmlCommand('get_filters') |
2284
|
|
|
|
2285
|
|
|
_add_filter(cmd, filter, filter_id) |
2286
|
|
|
|
2287
|
|
|
if not trash is None: |
2288
|
|
|
cmd.set_attribute('trash', _to_bool(trash)) |
2289
|
|
|
|
2290
|
|
|
if not alerts is None: |
2291
|
|
|
cmd.set_attribute('alerts', _to_bool(alerts)) |
2292
|
|
|
|
2293
|
|
|
return self._send_xml_command(cmd) |
2294
|
|
|
|
2295
|
|
|
def get_filter(self, filter_id): |
2296
|
|
|
"""Request a single filter |
2297
|
|
|
|
2298
|
|
|
Arguments: |
2299
|
|
|
filter_id (str): UUID of an existing filter |
2300
|
|
|
|
2301
|
|
|
Returns: |
2302
|
|
|
The response. See :py:meth:`send_command` for details. |
2303
|
|
|
""" |
2304
|
|
|
cmd = XmlCommand('get_filters') |
2305
|
|
|
cmd.set_attribute('filter_id', filter_id) |
2306
|
|
|
return self._send_xml_command(cmd) |
2307
|
|
|
|
2308
|
|
|
def get_groups(self, *, filter=None, filter_id=None, trash=None): |
2309
|
|
|
"""Request a list of groups |
2310
|
|
|
|
2311
|
|
|
Arguments: |
2312
|
|
|
filter (str, optional): Filter term to use for the query |
2313
|
|
|
filter_id (str, optional): UUID of an existing filter to use for |
2314
|
|
|
the query |
2315
|
|
|
trash (boolean, optional): Whether to get the trashcan groups |
2316
|
|
|
instead |
2317
|
|
|
|
2318
|
|
|
Returns: |
2319
|
|
|
The response. See :py:meth:`send_command` for details. |
2320
|
|
|
""" |
2321
|
|
|
cmd = XmlCommand('get_groups') |
2322
|
|
|
|
2323
|
|
|
_add_filter(cmd, filter, filter_id) |
2324
|
|
|
|
2325
|
|
|
if not trash is None: |
2326
|
|
|
cmd.set_attribute('trash', _to_bool(trash)) |
2327
|
|
|
|
2328
|
|
|
return self._send_xml_command(cmd) |
2329
|
|
|
|
2330
|
|
|
def get_group(self, group_id): |
2331
|
|
|
"""Request a single group |
2332
|
|
|
|
2333
|
|
|
Arguments: |
2334
|
|
|
group_id (str): UUID of an existing group |
2335
|
|
|
|
2336
|
|
|
Returns: |
2337
|
|
|
The response. See :py:meth:`send_command` for details. |
2338
|
|
|
""" |
2339
|
|
|
cmd = XmlCommand('get_groups') |
2340
|
|
|
cmd.set_attribute('group_id', group_id) |
2341
|
|
|
return self._send_xml_command(cmd) |
2342
|
|
|
|
2343
|
|
|
def get_info_list(self, info_type, *, filter=None, filter_id=None, |
2344
|
|
|
name=None, details=None): |
2345
|
|
|
"""Request a list of security information |
2346
|
|
|
|
2347
|
|
|
Arguments: |
2348
|
|
|
info_type (str): Type must be either CERT_BUND_ADV, CPE, CVE, |
2349
|
|
|
DFN_CERT_ADV, OVALDEF, NVT or ALLINFO |
2350
|
|
|
filter (str, optional): Filter term to use for the query |
2351
|
|
|
filter_id (str, optional): UUID of an existing filter to use for |
2352
|
|
|
the query |
2353
|
|
|
name (str, optional): Name or identifier of the requested |
2354
|
|
|
information |
2355
|
|
|
details (boolean, optional): Whether to include information about |
2356
|
|
|
references to this information |
2357
|
|
|
|
2358
|
|
|
Returns: |
2359
|
|
|
The response. See :py:meth:`send_command` for details. |
2360
|
|
|
""" |
2361
|
|
|
info_type = info_type.upper() |
2362
|
|
|
|
2363
|
|
|
if not info_type in ( |
2364
|
|
|
'CERT_BUND_ADV', 'CPE', 'CVE', 'DFN_CERT_ADV', 'OVALDEF', 'NVT', |
2365
|
|
|
'ALLINFO'): |
2366
|
|
|
raise InvalidArgument( |
2367
|
|
|
'get_info_list info_type argument must be one of CERT_BUND_ADV' |
2368
|
|
|
', CPE, CVE, DFN_CERT_ADV, OVALDEF, NVT or ALLINFO') |
2369
|
|
|
|
2370
|
|
|
cmd = XmlCommand('get_info') |
2371
|
|
|
|
2372
|
|
|
_add_filter(cmd, filter, filter_id) |
2373
|
|
|
|
2374
|
|
|
cmd.set_attribute('type', info_type) |
2375
|
|
|
|
2376
|
|
|
if name: |
2377
|
|
|
cmd.set_attribute('name', name) |
2378
|
|
|
|
2379
|
|
|
if not details is None: |
2380
|
|
|
cmd.set_attribute('details', _to_bool(details)) |
2381
|
|
|
|
2382
|
|
|
return self._send_xml_command(cmd) |
2383
|
|
|
|
2384
|
|
|
def get_info(self, info_id, info_type): |
2385
|
|
|
"""Request a single secinfo |
2386
|
|
|
|
2387
|
|
|
Arguments: |
2388
|
|
|
info_id (str): UUID of an existing secinfo |
2389
|
|
|
info_type (str): Type must be either CERT_BUND_ADV, CPE, CVE, |
2390
|
|
|
DFN_CERT_ADV, OVALDEF, NVT or ALLINFO |
2391
|
|
|
|
2392
|
|
|
Returns: |
2393
|
|
|
The response. See :py:meth:`send_command` for details. |
2394
|
|
|
""" |
2395
|
|
|
if not info_type in ( |
2396
|
|
|
'CERT_BUND_ADV', 'CPE', 'CVE', 'DFN_CERT_ADV', 'OVALDEF', 'NVT', |
2397
|
|
|
'ALLINFO'): |
2398
|
|
|
raise InvalidArgument( |
2399
|
|
|
'get_info_list info_type argument must be one of CERT_BUND_ADV' |
2400
|
|
|
', CPE, CVE, DFN_CERT_ADV, OVALDEF, NVT or ALLINFO') |
2401
|
|
|
|
2402
|
|
|
cmd = XmlCommand('get_info') |
2403
|
|
|
cmd.set_attribute('info_id', info_id) |
2404
|
|
|
|
2405
|
|
|
cmd.set_attribute('type', info_type) |
2406
|
|
|
|
2407
|
|
|
# for single entity always request all details |
2408
|
|
|
cmd.set_attribute('details', '1') |
2409
|
|
|
return self._send_xml_command(cmd) |
2410
|
|
|
|
2411
|
|
View Code Duplication |
def get_notes(self, *, filter=None, filter_id=None, nvt_oid=None, |
|
|
|
|
2412
|
|
|
task_id=None, details=None, result=None): |
2413
|
|
|
"""Request a list of notes |
2414
|
|
|
|
2415
|
|
|
Arguments: |
2416
|
|
|
filter (str, optional): Filter term to use for the query |
2417
|
|
|
filter_id (str, optional): UUID of an existing filter to use for |
2418
|
|
|
the query |
2419
|
|
|
nvt_oid (str, optional): OID of a nvt |
2420
|
|
|
task_id (str, optional): UUID of a task |
2421
|
|
|
details (boolean, optional): |
2422
|
|
|
result (boolean, optional): |
2423
|
|
|
|
2424
|
|
|
Returns: |
2425
|
|
|
The response. See :py:meth:`send_command` for details. |
2426
|
|
|
""" |
2427
|
|
|
cmd = XmlCommand('get_notes') |
2428
|
|
|
|
2429
|
|
|
_add_filter(cmd, filter, filter_id) |
2430
|
|
|
|
2431
|
|
|
if nvt_oid: |
2432
|
|
|
cmd.set_attribute('nvt_oid', nvt_oid) |
2433
|
|
|
|
2434
|
|
|
if task_id: |
2435
|
|
|
cmd.set_attribute('task_id', task_id) |
2436
|
|
|
|
2437
|
|
|
if not details is None: |
2438
|
|
|
cmd.set_attribute('details', _to_bool(details)) |
2439
|
|
|
|
2440
|
|
|
if not result is None: |
2441
|
|
|
cmd.set_attribute('result', _to_bool(result)) |
2442
|
|
|
|
2443
|
|
|
return self._send_xml_command(cmd) |
2444
|
|
|
|
2445
|
|
|
def get_note(self, note_id): |
2446
|
|
|
"""Request a single note |
2447
|
|
|
|
2448
|
|
|
Arguments: |
2449
|
|
|
note_id (str): UUID of an existing note |
2450
|
|
|
|
2451
|
|
|
Returns: |
2452
|
|
|
The response. See :py:meth:`send_command` for details. |
2453
|
|
|
""" |
2454
|
|
|
cmd = XmlCommand('get_notes') |
2455
|
|
|
cmd.set_attribute('note_id', note_id) |
2456
|
|
|
|
2457
|
|
|
# for single entity always request all details |
2458
|
|
|
cmd.set_attribute('details', '1') |
2459
|
|
|
return self._send_xml_command(cmd) |
2460
|
|
|
|
2461
|
|
|
def get_nvts(self, *, details=None, preferences=None, preference_count=None, |
2462
|
|
|
timeout=None, config_id=None, preferences_config_id=None, |
2463
|
|
|
family=None, sort_order=None, sort_field=None): |
2464
|
|
|
"""Request a list of nvts |
2465
|
|
|
|
2466
|
|
|
Arguments: |
2467
|
|
|
details (boolean, optional): Whether to include full details |
2468
|
|
|
preferences (boolean, optional): Whether to include nvt preferences |
2469
|
|
|
preference_count (boolean, optional): Whether to include preference |
2470
|
|
|
count |
2471
|
|
|
timeout (boolean, optional): Whether to include the special timeout |
2472
|
|
|
preference |
2473
|
|
|
config_id (str, optional): UUID of scan config to which to limit the |
2474
|
|
|
NVT listing |
2475
|
|
|
preferences_config_id (str, optional): UUID of scan config to use |
2476
|
|
|
for preference values |
2477
|
|
|
family (str, optional): Family to which to limit NVT listing |
2478
|
|
|
sort_order (str, optional): Sort order |
2479
|
|
|
sort_field (str, optional): Sort field |
2480
|
|
|
|
2481
|
|
|
Returns: |
2482
|
|
|
The response. See :py:meth:`send_command` for details. |
2483
|
|
|
""" |
2484
|
|
|
cmd = XmlCommand('get_notes') |
2485
|
|
|
|
2486
|
|
|
if not details is None: |
2487
|
|
|
cmd.set_attribute('details', _to_bool(details)) |
2488
|
|
|
|
2489
|
|
|
if not preferences is None: |
2490
|
|
|
cmd.set_attribute('preferences', _to_bool(preferences)) |
2491
|
|
|
|
2492
|
|
|
if not preference_count is None: |
2493
|
|
|
cmd.set_attribute('preference_count', _to_bool(preference_count)) |
2494
|
|
|
|
2495
|
|
|
if not timeout is None: |
2496
|
|
|
cmd.set_attribute('timeout', _to_bool(timeout)) |
2497
|
|
|
|
2498
|
|
|
if config_id: |
2499
|
|
|
cmd.set_attribute('config_id', config_id) |
2500
|
|
|
|
2501
|
|
|
if preferences_config_id: |
2502
|
|
|
cmd.set_attribute('preferences_config_id', preferences_config_id) |
2503
|
|
|
|
2504
|
|
|
if family: |
2505
|
|
|
cmd.set_attribute('family', family) |
2506
|
|
|
|
2507
|
|
|
if sort_order: |
2508
|
|
|
cmd.set_attribute('sort_order', sort_order) |
2509
|
|
|
|
2510
|
|
|
if sort_field: |
2511
|
|
|
cmd.set_attribute('sort_field', sort_field) |
2512
|
|
|
|
2513
|
|
|
return self._send_xml_command(cmd) |
2514
|
|
|
|
2515
|
|
|
def get_nvt(self, nvt_oid): |
2516
|
|
|
"""Request a single nvt |
2517
|
|
|
|
2518
|
|
|
Arguments: |
2519
|
|
|
nvt_oid (str): OID of an existing nvt |
2520
|
|
|
|
2521
|
|
|
Returns: |
2522
|
|
|
The response. See :py:meth:`send_command` for details. |
2523
|
|
|
""" |
2524
|
|
|
cmd = XmlCommand('get_nvts') |
2525
|
|
|
cmd.set_attribute('nvt_oid', nvt_oid) |
2526
|
|
|
|
2527
|
|
|
# for single entity always request all details |
2528
|
|
|
cmd.set_attribute('details', '1') |
2529
|
|
|
return self._send_xml_command(cmd) |
2530
|
|
|
|
2531
|
|
|
def get_nvt_families(self, *, sort_order=None): |
2532
|
|
|
"""Request a list of nvt families |
2533
|
|
|
|
2534
|
|
|
Arguments: |
2535
|
|
|
sort_order (str, optional): Sort order |
2536
|
|
|
|
2537
|
|
|
Returns: |
2538
|
|
|
The response. See :py:meth:`send_command` for details. |
2539
|
|
|
""" |
2540
|
|
|
cmd = XmlCommand('get_nvt_families') |
2541
|
|
|
|
2542
|
|
|
if sort_order: |
2543
|
|
|
cmd.set_attribute('sort_order', sort_order) |
2544
|
|
|
|
2545
|
|
|
return self._send_xml_command(cmd) |
2546
|
|
|
|
2547
|
|
View Code Duplication |
def get_overrides(self, *, filter=None, filter_id=None, nvt_oid=None, |
|
|
|
|
2548
|
|
|
task_id=None, details=None, result=None): |
2549
|
|
|
"""Request a list of overrides |
2550
|
|
|
|
2551
|
|
|
Arguments: |
2552
|
|
|
filter (str, optional): Filter term to use for the query |
2553
|
|
|
filter_id (str, optional): UUID of an existing filter to use for |
2554
|
|
|
the query |
2555
|
|
|
nvt_oid (str, optional): OID of a nvt |
2556
|
|
|
task_id (str, optional): UUID of a task |
2557
|
|
|
details (boolean, optional): |
2558
|
|
|
result (boolean, optional): |
2559
|
|
|
|
2560
|
|
|
Returns: |
2561
|
|
|
The response. See :py:meth:`send_command` for details. |
2562
|
|
|
""" |
2563
|
|
|
cmd = XmlCommand('get_overrides') |
2564
|
|
|
|
2565
|
|
|
_add_filter(cmd, filter, filter_id) |
2566
|
|
|
|
2567
|
|
|
if nvt_oid: |
2568
|
|
|
cmd.set_attribute('nvt_oid', nvt_oid) |
2569
|
|
|
|
2570
|
|
|
if task_id: |
2571
|
|
|
cmd.set_attribute('task_id', task_id) |
2572
|
|
|
|
2573
|
|
|
if not details is None: |
2574
|
|
|
cmd.set_attribute('details', _to_bool(details)) |
2575
|
|
|
|
2576
|
|
|
if not result is None: |
2577
|
|
|
cmd.set_attribute('result', _to_bool(result)) |
2578
|
|
|
|
2579
|
|
|
return self._send_xml_command(cmd) |
2580
|
|
|
|
2581
|
|
|
def get_override(self, override_id): |
2582
|
|
|
"""Request a single override |
2583
|
|
|
|
2584
|
|
|
Arguments: |
2585
|
|
|
override_id (str): UUID of an existing override |
2586
|
|
|
|
2587
|
|
|
Returns: |
2588
|
|
|
The response. See :py:meth:`send_command` for details. |
2589
|
|
|
""" |
2590
|
|
|
cmd = XmlCommand('get_overrides') |
2591
|
|
|
cmd.set_attribute('override_id', override_id) |
2592
|
|
|
|
2593
|
|
|
# for single entity always request all details |
2594
|
|
|
cmd.set_attribute('details', '1') |
2595
|
|
|
return self._send_xml_command(cmd) |
2596
|
|
|
|
2597
|
|
|
def get_permissions(self, *, filter=None, filter_id=None, trash=None): |
2598
|
|
|
"""Request a list of permissions |
2599
|
|
|
|
2600
|
|
|
Arguments: |
2601
|
|
|
filter (str, optional): Filter term to use for the query |
2602
|
|
|
filter_id (str, optional): UUID of an existing filter to use for |
2603
|
|
|
the query |
2604
|
|
|
trash (boolean, optional): Whether to get permissions in the |
2605
|
|
|
trashcan instead |
2606
|
|
|
|
2607
|
|
|
Returns: |
2608
|
|
|
The response. See :py:meth:`send_command` for details. |
2609
|
|
|
""" |
2610
|
|
|
cmd = XmlCommand('get_permissions') |
2611
|
|
|
|
2612
|
|
|
_add_filter(cmd, filter, filter_id) |
2613
|
|
|
|
2614
|
|
|
if not trash is None: |
2615
|
|
|
cmd.set_attribute('trash', _to_bool(trash)) |
2616
|
|
|
|
2617
|
|
|
return self._send_xml_command(cmd) |
2618
|
|
|
|
2619
|
|
|
def get_permission(self, permission_id): |
2620
|
|
|
"""Request a single permission |
2621
|
|
|
|
2622
|
|
|
Arguments: |
2623
|
|
|
permission_id (str): UUID of an existing permission |
2624
|
|
|
|
2625
|
|
|
Returns: |
2626
|
|
|
The response. See :py:meth:`send_command` for details. |
2627
|
|
|
""" |
2628
|
|
|
cmd = XmlCommand('get_permissions') |
2629
|
|
|
cmd.set_attribute('permission_id', permission_id) |
2630
|
|
|
return self._send_xml_command(cmd) |
2631
|
|
|
|
2632
|
|
View Code Duplication |
def get_port_lists(self, *, filter=None, filter_id=None, details=None, |
|
|
|
|
2633
|
|
|
targets=None, trash=None): |
2634
|
|
|
"""Request a list of port lists |
2635
|
|
|
|
2636
|
|
|
Arguments: |
2637
|
|
|
filter (str, optional): Filter term to use for the query |
2638
|
|
|
filter_id (str, optional): UUID of an existing filter to use for |
2639
|
|
|
the query |
2640
|
|
|
details (boolean, optional): Whether to include full port list |
2641
|
|
|
details |
2642
|
|
|
targets (boolean, optional): Whether to include targets using this |
2643
|
|
|
port list |
2644
|
|
|
trash (boolean, optional): Whether to get port lists in the |
2645
|
|
|
trashcan instead |
2646
|
|
|
|
2647
|
|
|
Returns: |
2648
|
|
|
The response. See :py:meth:`send_command` for details. |
2649
|
|
|
""" |
2650
|
|
|
cmd = XmlCommand('get_port_lists') |
2651
|
|
|
|
2652
|
|
|
_add_filter(cmd, filter, filter_id) |
2653
|
|
|
|
2654
|
|
|
if not details is None: |
2655
|
|
|
cmd.set_attribute('details', _to_bool(details)) |
2656
|
|
|
|
2657
|
|
|
if not targets is None: |
2658
|
|
|
cmd.set_attribute('targets', _to_bool(targets)) |
2659
|
|
|
|
2660
|
|
|
if not trash is None: |
2661
|
|
|
cmd.set_attribute('trash', _to_bool(trash)) |
2662
|
|
|
|
2663
|
|
|
return self._send_xml_command(cmd) |
2664
|
|
|
|
2665
|
|
|
def get_port_list(self, port_list_id): |
2666
|
|
|
"""Request a single port list |
2667
|
|
|
|
2668
|
|
|
Arguments: |
2669
|
|
|
port_list_id (str): UUID of an existing port list |
2670
|
|
|
|
2671
|
|
|
Returns: |
2672
|
|
|
The response. See :py:meth:`send_command` for details. |
2673
|
|
|
""" |
2674
|
|
|
cmd = XmlCommand('get_port_lists') |
2675
|
|
|
cmd.set_attribute('port_list_id', port_list_id) |
2676
|
|
|
|
2677
|
|
|
# for single entity always request all details |
2678
|
|
|
cmd.set_attribute('details', '1') |
2679
|
|
|
return self._send_xml_command(cmd) |
2680
|
|
|
|
2681
|
|
|
def get_preferences(self, *, nvt_oid=None, config_id=None, preference=None): |
2682
|
|
|
"""Request a list of preferences |
2683
|
|
|
|
2684
|
|
|
When the command includes a config_id attribute, the preference element |
2685
|
|
|
includes the preference name, type and value, and the NVT to which the |
2686
|
|
|
preference applies. Otherwise, the preference element includes just the |
2687
|
|
|
name and value, with the NVT and type built into the name. |
2688
|
|
|
|
2689
|
|
|
Arguments: |
2690
|
|
|
nvt_oid (str, optional): OID of nvt |
2691
|
|
|
config_id (str, optional): UUID of scan config of which to show |
2692
|
|
|
preference values |
2693
|
|
|
preference (str, optional): name of a particular preference to get |
2694
|
|
|
|
2695
|
|
|
Returns: |
2696
|
|
|
The response. See :py:meth:`send_command` for details. |
2697
|
|
|
""" |
2698
|
|
|
cmd = XmlCommand('get_preferences') |
2699
|
|
|
|
2700
|
|
|
if nvt_oid: |
2701
|
|
|
cmd.set_attribute('nvt_oid', nvt_oid) |
2702
|
|
|
|
2703
|
|
|
if config_id: |
2704
|
|
|
cmd.set_attribute('config_id', config_id) |
2705
|
|
|
|
2706
|
|
|
if preference: |
2707
|
|
|
cmd.set_attribute('preference', preference) |
2708
|
|
|
|
2709
|
|
|
return self._send_xml_command(cmd) |
2710
|
|
|
|
2711
|
|
|
def get_reports(self, *, filter=None, filter_id=None, note_details=None, |
2712
|
|
|
override_details=None): |
2713
|
|
|
"""Request a list of reports |
2714
|
|
|
|
2715
|
|
|
Arguments: |
2716
|
|
|
filter (str, optional): Filter term to use for the query |
2717
|
|
|
filter_id (str, optional): UUID of an existing filter to use for |
2718
|
|
|
the query |
2719
|
|
|
note_details (boolean, optional): If notes are included, whether to |
2720
|
|
|
include note details |
2721
|
|
|
override_details (boolean, optional): If overrides are included, |
2722
|
|
|
whether to include override details |
2723
|
|
|
|
2724
|
|
|
Returns: |
2725
|
|
|
The response. See :py:meth:`send_command` for details. |
2726
|
|
|
""" |
2727
|
|
|
cmd = XmlCommand('get_reports') |
2728
|
|
|
|
2729
|
|
|
if filter: |
2730
|
|
|
cmd.set_attribute('report_filter', filter) |
2731
|
|
|
|
2732
|
|
|
if filter_id: |
2733
|
|
|
cmd.set_attribute('report_filt_id', filter_id) |
2734
|
|
|
|
2735
|
|
|
if not note_details is None: |
2736
|
|
|
cmd.set_attribute('note_details', _to_bool(note_details)) |
2737
|
|
|
|
2738
|
|
|
if not override_details is None: |
2739
|
|
|
cmd.set_attribute('override_details', _to_bool(override_details)) |
2740
|
|
|
|
2741
|
|
|
cmd.set_attribute('ignore_pagination', '1') |
2742
|
|
|
|
2743
|
|
|
return self._send_xml_command(cmd) |
2744
|
|
|
|
2745
|
|
|
def get_report(self, report_id, *, filter=None, filter_id=None, |
2746
|
|
|
delta_report_id=None, report_format_id=None): |
2747
|
|
|
"""Request a single report |
2748
|
|
|
|
2749
|
|
|
Arguments: |
2750
|
|
|
report_id (str): UUID of an existing report |
2751
|
|
|
filter (str, optional): Filter term to use to filter results in the |
2752
|
|
|
report |
2753
|
|
|
filter_id (str, optional): UUID of filter to use to filter results |
2754
|
|
|
in the report |
2755
|
|
|
delta_report_id (str, optional): UUID of an existing report to |
2756
|
|
|
compare report to. |
2757
|
|
|
report_format_id (str, optional): UUID of report format to use |
2758
|
|
|
|
2759
|
|
|
Returns: |
2760
|
|
|
The response. See :py:meth:`send_command` for details. |
2761
|
|
|
""" |
2762
|
|
|
if not report_id: |
2763
|
|
|
raise RequiredArgument('get_report requires a report_id argument') |
2764
|
|
|
|
2765
|
|
|
cmd = XmlCommand('get_reports') |
2766
|
|
|
cmd.set_attribute('report_id', report_id) |
2767
|
|
|
|
2768
|
|
|
_add_filter(cmd, filter, filter_id) |
2769
|
|
|
|
2770
|
|
|
if delta_report_id: |
2771
|
|
|
cmd.set_attribute('delta_report_id', delta_report_id) |
2772
|
|
|
|
2773
|
|
|
if report_format_id: |
2774
|
|
|
cmd.set_attribute('format_id', report_format_id) |
2775
|
|
|
|
2776
|
|
|
return self._send_xml_command(cmd) |
2777
|
|
|
|
2778
|
|
|
def get_report_formats(self, *, filter=None, filter_id=None, trash=None, |
2779
|
|
|
alerts=None, params=None, details=None): |
2780
|
|
|
"""Request a list of report formats |
2781
|
|
|
|
2782
|
|
|
Arguments: |
2783
|
|
|
filter (str, optional): Filter term to use for the query |
2784
|
|
|
filter_id (str, optional): UUID of an existing filter to use for |
2785
|
|
|
the query |
2786
|
|
|
trash (boolean, optional): Whether to get the trashcan report |
2787
|
|
|
formats instead |
2788
|
|
|
alerts (boolean, optional): Whether to include alerts that use the |
2789
|
|
|
report format |
2790
|
|
|
params (boolean, optional): Whether to include report format |
2791
|
|
|
parameters |
2792
|
|
|
details (boolean, optional): Include report format file, signature |
2793
|
|
|
and parameters |
2794
|
|
|
|
2795
|
|
|
Returns: |
2796
|
|
|
The response. See :py:meth:`send_command` for details. |
2797
|
|
|
""" |
2798
|
|
|
cmd = XmlCommand('get_report_formats') |
2799
|
|
|
|
2800
|
|
|
_add_filter(cmd, filter, filter_id) |
2801
|
|
|
|
2802
|
|
|
if not details is None: |
2803
|
|
|
cmd.set_attribute('details', _to_bool(details)) |
2804
|
|
|
|
2805
|
|
|
if not alerts is None: |
2806
|
|
|
cmd.set_attribute('alerts', _to_bool(alerts)) |
2807
|
|
|
|
2808
|
|
|
if not params is None: |
2809
|
|
|
cmd.set_attribute('params', _to_bool(params)) |
2810
|
|
|
|
2811
|
|
|
if not trash is None: |
2812
|
|
|
cmd.set_attribute('trash', _to_bool(trash)) |
2813
|
|
|
|
2814
|
|
|
return self._send_xml_command(cmd) |
2815
|
|
|
|
2816
|
|
|
def get_report_format(self, report_format_id): |
2817
|
|
|
"""Request a single report format |
2818
|
|
|
|
2819
|
|
|
Arguments: |
2820
|
|
|
report_format_id (str): UUID of an existing report format |
2821
|
|
|
|
2822
|
|
|
Returns: |
2823
|
|
|
The response. See :py:meth:`send_command` for details. |
2824
|
|
|
""" |
2825
|
|
|
cmd = XmlCommand('get_report_formats') |
2826
|
|
|
cmd.set_attribute('report_format_id', report_format_id) |
2827
|
|
|
|
2828
|
|
|
# for single entity always request all details |
2829
|
|
|
cmd.set_attribute('details', '1') |
2830
|
|
|
return self._send_xml_command(cmd) |
2831
|
|
|
|
2832
|
|
|
def get_results(self, *, filter=None, filter_id=None, task_id=None, |
2833
|
|
|
note_details=None, override_details=None, details=None): |
2834
|
|
|
"""Request a list of results |
2835
|
|
|
|
2836
|
|
|
Arguments: |
2837
|
|
|
filter (str, optional): Filter term to use for the query |
2838
|
|
|
filter_id (str, optional): UUID of an existing filter to use for |
2839
|
|
|
the query |
2840
|
|
|
task_id (str, optional): UUID of task for note and override handling |
2841
|
|
|
note_details (boolean, optional): If notes are included, whether to |
2842
|
|
|
include note details |
2843
|
|
|
override_details (boolean, optional): If overrides are included, |
2844
|
|
|
whether to include override details |
2845
|
|
|
details (boolean, optional): Whether to include additional details |
2846
|
|
|
of the results |
2847
|
|
|
|
2848
|
|
|
Returns: |
2849
|
|
|
The response. See :py:meth:`send_command` for details. |
2850
|
|
|
""" |
2851
|
|
|
cmd = XmlCommand('get_results') |
2852
|
|
|
|
2853
|
|
|
_add_filter(cmd, filter, filter_id) |
2854
|
|
|
|
2855
|
|
|
if task_id: |
2856
|
|
|
cmd.set_attribute('task_id', task_id) |
2857
|
|
|
|
2858
|
|
|
if not details is None: |
2859
|
|
|
cmd.set_attribute('details', _to_bool(details)) |
2860
|
|
|
|
2861
|
|
|
if not note_details is None: |
2862
|
|
|
cmd.set_attribute('note_details', _to_bool(note_details)) |
2863
|
|
|
|
2864
|
|
|
if not override_details is None: |
2865
|
|
|
cmd.set_attribute('override_details', _to_bool(override_details)) |
2866
|
|
|
|
2867
|
|
|
return self._send_xml_command(cmd) |
2868
|
|
|
|
2869
|
|
|
def get_result(self, result_id): |
2870
|
|
|
"""Request a single result |
2871
|
|
|
|
2872
|
|
|
Arguments: |
2873
|
|
|
result_id (str): UUID of an existing result |
2874
|
|
|
|
2875
|
|
|
Returns: |
2876
|
|
|
The response. See :py:meth:`send_command` for details. |
2877
|
|
|
""" |
2878
|
|
|
cmd = XmlCommand('get_results') |
2879
|
|
|
cmd.set_attribute('result_id', result_id) |
2880
|
|
|
|
2881
|
|
|
# for single entity always request all details |
2882
|
|
|
cmd.set_attribute('details', '1') |
2883
|
|
|
return self._send_xml_command(cmd) |
2884
|
|
|
|
2885
|
|
|
def get_roles(self, *, filter=None, filter_id=None, trash=None): |
2886
|
|
|
"""Request a list of roles |
2887
|
|
|
|
2888
|
|
|
Arguments: |
2889
|
|
|
filter (str, optional): Filter term to use for the query |
2890
|
|
|
filter_id (str, optional): UUID of an existing filter to use for |
2891
|
|
|
the query |
2892
|
|
|
trash (boolean, optional): Whether to get the trashcan roles instead |
2893
|
|
|
|
2894
|
|
|
Returns: |
2895
|
|
|
The response. See :py:meth:`send_command` for details. |
2896
|
|
|
""" |
2897
|
|
|
cmd = XmlCommand('get_roles') |
2898
|
|
|
|
2899
|
|
|
_add_filter(cmd, filter, filter_id) |
2900
|
|
|
|
2901
|
|
|
if not trash is None: |
2902
|
|
|
cmd.set_attribute('trash', _to_bool(trash)) |
2903
|
|
|
|
2904
|
|
|
return self._send_xml_command(cmd) |
2905
|
|
|
|
2906
|
|
|
def get_role(self, role_id): |
2907
|
|
|
"""Request a single role |
2908
|
|
|
|
2909
|
|
|
Arguments: |
2910
|
|
|
role_id (str): UUID of an existing role |
2911
|
|
|
|
2912
|
|
|
Returns: |
2913
|
|
|
The response. See :py:meth:`send_command` for details. |
2914
|
|
|
""" |
2915
|
|
|
cmd = XmlCommand('get_roles') |
2916
|
|
|
cmd.set_attribute('role_id', role_id) |
2917
|
|
|
return self._send_xml_command(cmd) |
2918
|
|
|
|
2919
|
|
|
def get_scanners(self, *, filter=None, filter_id=None, trash=None, |
2920
|
|
|
details=None): |
2921
|
|
|
"""Request a list of scanners |
2922
|
|
|
|
2923
|
|
|
Arguments: |
2924
|
|
|
filter (str, optional): Filter term to use for the query |
2925
|
|
|
filter_id (str, optional): UUID of an existing filter to use for |
2926
|
|
|
the query |
2927
|
|
|
trash (boolean, optional): Whether to get the trashcan scanners |
2928
|
|
|
instead |
2929
|
|
|
details (boolean, optional): Whether to include extra details like |
2930
|
|
|
tasks using this scanner |
2931
|
|
|
|
2932
|
|
|
Returns: |
2933
|
|
|
The response. See :py:meth:`send_command` for details. |
2934
|
|
|
""" |
2935
|
|
|
cmd = XmlCommand('get_scanners') |
2936
|
|
|
|
2937
|
|
|
_add_filter(cmd, filter, filter_id) |
2938
|
|
|
|
2939
|
|
|
if not trash is None: |
2940
|
|
|
cmd.set_attribute('trash', _to_bool(trash)) |
2941
|
|
|
|
2942
|
|
|
if not details is None: |
2943
|
|
|
cmd.set_attribute('details', _to_bool(details)) |
2944
|
|
|
|
2945
|
|
|
return self._send_xml_command(cmd) |
2946
|
|
|
|
2947
|
|
|
def get_scanner(self, scanner_id): |
2948
|
|
|
"""Request a single scanner |
2949
|
|
|
|
2950
|
|
|
Arguments: |
2951
|
|
|
scanner_id (str): UUID of an existing scanner |
2952
|
|
|
|
2953
|
|
|
Returns: |
2954
|
|
|
The response. See :py:meth:`send_command` for details. |
2955
|
|
|
""" |
2956
|
|
|
cmd = XmlCommand('get_scanners') |
2957
|
|
|
cmd.set_attribute('scanner_id', scanner_id) |
2958
|
|
|
|
2959
|
|
|
# for single entity always request all details |
2960
|
|
|
cmd.set_attribute('details', '1') |
2961
|
|
|
return self._send_xml_command(cmd) |
2962
|
|
|
|
2963
|
|
View Code Duplication |
def get_schedules(self, *, filter=None, filter_id=None, trash=None, |
|
|
|
|
2964
|
|
|
tasks=None): |
2965
|
|
|
"""Request a list of schedules |
2966
|
|
|
|
2967
|
|
|
Arguments: |
2968
|
|
|
filter (str, optional): Filter term to use for the query |
2969
|
|
|
filter_id (str, optional): UUID of an existing filter to use for |
2970
|
|
|
the query |
2971
|
|
|
trash (boolean, optional): Whether to get the trashcan schedules |
2972
|
|
|
instead |
2973
|
|
|
tasks (boolean, optional): Whether to include tasks using the |
2974
|
|
|
schedules |
2975
|
|
|
|
2976
|
|
|
Returns: |
2977
|
|
|
The response. See :py:meth:`send_command` for details. |
2978
|
|
|
""" |
2979
|
|
|
cmd = XmlCommand('get_schedules') |
2980
|
|
|
|
2981
|
|
|
_add_filter(cmd, filter, filter_id) |
2982
|
|
|
|
2983
|
|
|
if not trash is None: |
2984
|
|
|
cmd.set_attribute('trash', _to_bool(trash)) |
2985
|
|
|
|
2986
|
|
|
if not tasks is None: |
2987
|
|
|
cmd.set_attribute('tasks', _to_bool(tasks)) |
2988
|
|
|
|
2989
|
|
|
return self._send_xml_command(cmd) |
2990
|
|
|
|
2991
|
|
|
def get_schedule(self, schedule_id): |
2992
|
|
|
"""Request a single schedule |
2993
|
|
|
|
2994
|
|
|
Arguments: |
2995
|
|
|
schedule_id (str): UUID of an existing schedule |
2996
|
|
|
|
2997
|
|
|
Returns: |
2998
|
|
|
The response. See :py:meth:`send_command` for details. |
2999
|
|
|
""" |
3000
|
|
|
cmd = XmlCommand('get_schedules') |
3001
|
|
|
cmd.set_attribute('schedule_id', schedule_id) |
3002
|
|
|
return self._send_xml_command(cmd) |
3003
|
|
|
|
3004
|
|
|
def get_settings(self, *, filter=None): |
3005
|
|
|
"""Request a list of user settings |
3006
|
|
|
|
3007
|
|
|
Arguments: |
3008
|
|
|
filter (str, optional): Filter term to use for the query |
3009
|
|
|
|
3010
|
|
|
Returns: |
3011
|
|
|
The response. See :py:meth:`send_command` for details. |
3012
|
|
|
""" |
3013
|
|
|
cmd = XmlCommand('get_schedules') |
3014
|
|
|
|
3015
|
|
|
if filter: |
3016
|
|
|
cmd.set_attribute('filter', filter) |
3017
|
|
|
|
3018
|
|
|
return self._send_xml_command(cmd) |
3019
|
|
|
|
3020
|
|
|
def get_setting(self, setting_id): |
3021
|
|
|
"""Request a single setting |
3022
|
|
|
|
3023
|
|
|
Arguments: |
3024
|
|
|
setting_id (str): UUID of an existing setting |
3025
|
|
|
|
3026
|
|
|
Returns: |
3027
|
|
|
The response. See :py:meth:`send_command` for details. |
3028
|
|
|
""" |
3029
|
|
|
cmd = XmlCommand('get_settings') |
3030
|
|
|
cmd.set_attribute('setting_id', setting_id) |
3031
|
|
|
return self._send_xml_command(cmd) |
3032
|
|
|
|
3033
|
|
|
def get_system_reports(self, *, name=None, duration=None, start_time=None, |
3034
|
|
|
end_time=None, brief=None, slave_id=None): |
3035
|
|
|
"""Request a list of system reports |
3036
|
|
|
|
3037
|
|
|
Arguments: |
3038
|
|
|
name (str, optional): A string describing the required system report |
3039
|
|
|
duration (int, optional): The number of seconds into the past that |
3040
|
|
|
the system report should include |
3041
|
|
|
start_time (str, optional): The start of the time interval the |
3042
|
|
|
system report should include in ISO time format |
3043
|
|
|
end_time (str, optional): The end of the time interval the system |
3044
|
|
|
report should include in ISO time format |
3045
|
|
|
brief (boolean, optional): Whether to include the actual system |
3046
|
|
|
reports |
3047
|
|
|
slave_id (str, optional): UUID of GMP scanner from which to get the |
3048
|
|
|
system reports |
3049
|
|
|
|
3050
|
|
|
Returns: |
3051
|
|
|
The response. See :py:meth:`send_command` for details. |
3052
|
|
|
""" |
3053
|
|
|
cmd = XmlCommand('get_system_reports') |
3054
|
|
|
|
3055
|
|
|
if name: |
3056
|
|
|
cmd.set_attribute('name', name) |
3057
|
|
|
|
3058
|
|
|
if not duration is None: |
3059
|
|
|
cmd.set_attribute('duration', str(duration)) |
3060
|
|
|
|
3061
|
|
|
if start_time: |
3062
|
|
|
cmd.set_attribute('start_time', str(start_time)) |
3063
|
|
|
|
3064
|
|
|
if end_time: |
3065
|
|
|
cmd.set_attribute('end_time', str(end_time)) |
3066
|
|
|
|
3067
|
|
|
if not brief is None: |
3068
|
|
|
cmd.set_attribute('brief', _to_bool(brief)) |
3069
|
|
|
|
3070
|
|
|
if slave_id: |
3071
|
|
|
cmd.set_attribute('slave_id', slave_id) |
3072
|
|
|
|
3073
|
|
|
return self._send_xml_command(cmd) |
3074
|
|
|
|
3075
|
|
|
def get_tags(self, *, filter=None, filter_id=None, trash=None, |
3076
|
|
|
names_only=None): |
3077
|
|
|
"""Request a list of tags |
3078
|
|
|
|
3079
|
|
|
Arguments: |
3080
|
|
|
filter (str, optional): Filter term to use for the query |
3081
|
|
|
filter_id (str, optional): UUID of an existing filter to use for |
3082
|
|
|
the query |
3083
|
|
|
trash (boolean, optional): Whether to get tags from the trashcan |
3084
|
|
|
instead |
3085
|
|
|
names_only (boolean, optional): Whether to get only distinct tag |
3086
|
|
|
names |
3087
|
|
|
|
3088
|
|
|
Returns: |
3089
|
|
|
The response. See :py:meth:`send_command` for details. |
3090
|
|
|
""" |
3091
|
|
|
cmd = XmlCommand('get_tags') |
3092
|
|
|
|
3093
|
|
|
_add_filter(cmd, filter, filter_id) |
3094
|
|
|
|
3095
|
|
|
if not trash is None: |
3096
|
|
|
cmd.set_attribute('trash', _to_bool(trash)) |
3097
|
|
|
|
3098
|
|
|
if not names_only is None: |
3099
|
|
|
cmd.set_attribute('names_only', _to_bool(names_only)) |
3100
|
|
|
|
3101
|
|
|
return self._send_xml_command(cmd) |
3102
|
|
|
|
3103
|
|
|
def get_tag(self, tag_id): |
3104
|
|
|
"""Request a single tag |
3105
|
|
|
|
3106
|
|
|
Arguments: |
3107
|
|
|
tag_id (str): UUID of an existing tag |
3108
|
|
|
|
3109
|
|
|
Returns: |
3110
|
|
|
The response. See :py:meth:`send_command` for details. |
3111
|
|
|
""" |
3112
|
|
|
cmd = XmlCommand('get_tags') |
3113
|
|
|
cmd.set_attribute('tag_id', tag_id) |
3114
|
|
|
return self._send_xml_command(cmd) |
3115
|
|
|
|
3116
|
|
View Code Duplication |
def get_targets(self, *, filter=None, filter_id=None, trash=None, |
|
|
|
|
3117
|
|
|
tasks=None): |
3118
|
|
|
"""Request a list of targets |
3119
|
|
|
|
3120
|
|
|
Arguments: |
3121
|
|
|
filter (str, optional): Filter term to use for the query |
3122
|
|
|
filter_id (str, optional): UUID of an existing filter to use for |
3123
|
|
|
the query |
3124
|
|
|
trash (boolean, optional): Whether to get the trashcan targets |
3125
|
|
|
instead |
3126
|
|
|
tasks (boolean, optional): Whether to include list of tasks that |
3127
|
|
|
use the target |
3128
|
|
|
|
3129
|
|
|
Returns: |
3130
|
|
|
The response. See :py:meth:`send_command` for details. |
3131
|
|
|
""" |
3132
|
|
|
cmd = XmlCommand('get_targets') |
3133
|
|
|
|
3134
|
|
|
_add_filter(cmd, filter, filter_id) |
3135
|
|
|
|
3136
|
|
|
if not trash is None: |
3137
|
|
|
cmd.set_attribute('trash', _to_bool(trash)) |
3138
|
|
|
|
3139
|
|
|
if not tasks is None: |
3140
|
|
|
cmd.set_attribute('tasks', _to_bool(tasks)) |
3141
|
|
|
|
3142
|
|
|
return self._send_xml_command(cmd) |
3143
|
|
|
|
3144
|
|
|
def get_target(self, target_id): |
3145
|
|
|
"""Request a single target |
3146
|
|
|
|
3147
|
|
|
Arguments: |
3148
|
|
|
target_id (str): UUID of an existing target |
3149
|
|
|
|
3150
|
|
|
Returns: |
3151
|
|
|
The response. See :py:meth:`send_command` for details. |
3152
|
|
|
""" |
3153
|
|
|
cmd = XmlCommand('get_targets') |
3154
|
|
|
cmd.set_attribute('target_id', target_id) |
3155
|
|
|
return self._send_xml_command(cmd) |
3156
|
|
|
|
3157
|
|
View Code Duplication |
def get_tasks(self, *, filter=None, filter_id=None, trash=None, |
|
|
|
|
3158
|
|
|
details=None, schedules_only=None): |
3159
|
|
|
"""Request a list of tasks |
3160
|
|
|
|
3161
|
|
|
Arguments: |
3162
|
|
|
filter (str, optional): Filter term to use for the query |
3163
|
|
|
filter_id (str, optional): UUID of an existing filter to use for |
3164
|
|
|
the query |
3165
|
|
|
trash (boolean, optional): Whether to get the trashcan tasks instead |
3166
|
|
|
details (boolean, optional): Whether to include full task details |
3167
|
|
|
schedules_only (boolean, optional): Whether to only include id, name |
3168
|
|
|
and schedule details |
3169
|
|
|
|
3170
|
|
|
Returns: |
3171
|
|
|
The response. See :py:meth:`send_command` for details. |
3172
|
|
|
""" |
3173
|
|
|
cmd = XmlCommand('get_tasks') |
3174
|
|
|
|
3175
|
|
|
_add_filter(cmd, filter, filter_id) |
3176
|
|
|
|
3177
|
|
|
if not trash is None: |
3178
|
|
|
cmd.set_attribute('trash', _to_bool(trash)) |
3179
|
|
|
|
3180
|
|
|
if not details is None: |
3181
|
|
|
cmd.set_attribute('details', _to_bool(details)) |
3182
|
|
|
|
3183
|
|
|
if not schedules_only is None: |
3184
|
|
|
cmd.set_attribute('schedules_only', _to_bool(schedules_only)) |
3185
|
|
|
|
3186
|
|
|
return self._send_xml_command(cmd) |
3187
|
|
|
|
3188
|
|
|
def get_task(self, task_id): |
3189
|
|
|
"""Request a single task |
3190
|
|
|
|
3191
|
|
|
Arguments: |
3192
|
|
|
task_id (str): UUID of an existing task |
3193
|
|
|
|
3194
|
|
|
Returns: |
3195
|
|
|
The response. See :py:meth:`send_command` for details. |
3196
|
|
|
""" |
3197
|
|
|
if not task_id: |
3198
|
|
|
raise RequiredArgument('get_task requires task_id argument') |
3199
|
|
|
|
3200
|
|
|
cmd = XmlCommand('get_tasks') |
3201
|
|
|
cmd.set_attribute('task_id', task_id) |
3202
|
|
|
|
3203
|
|
|
# for single entity always request all details |
3204
|
|
|
cmd.set_attribute('details', '1') |
3205
|
|
|
return self._send_xml_command(cmd) |
3206
|
|
|
|
3207
|
|
|
def get_users(self, *, filter=None, filter_id=None): |
3208
|
|
|
"""Request a list of users |
3209
|
|
|
|
3210
|
|
|
Arguments: |
3211
|
|
|
filter (str, optional): Filter term to use for the query |
3212
|
|
|
filter_id (str, optional): UUID of an existing filter to use for |
3213
|
|
|
the query |
3214
|
|
|
|
3215
|
|
|
Returns: |
3216
|
|
|
The response. See :py:meth:`send_command` for details. |
3217
|
|
|
""" |
3218
|
|
|
cmd = XmlCommand('get_users') |
3219
|
|
|
|
3220
|
|
|
_add_filter(cmd, filter, filter_id) |
3221
|
|
|
|
3222
|
|
|
return self._send_xml_command(cmd) |
3223
|
|
|
|
3224
|
|
|
def get_user(self, user_id): |
3225
|
|
|
"""Request a single user |
3226
|
|
|
|
3227
|
|
|
Arguments: |
3228
|
|
|
user_id (str): UUID of an existing user |
3229
|
|
|
|
3230
|
|
|
Returns: |
3231
|
|
|
The response. See :py:meth:`send_command` for details. |
3232
|
|
|
""" |
3233
|
|
|
cmd = XmlCommand('get_users') |
3234
|
|
|
cmd.set_attribute('user_id', user_id) |
3235
|
|
|
return self._send_xml_command(cmd) |
3236
|
|
|
|
3237
|
|
|
def get_version(self): |
3238
|
|
|
"""Get the Greenbone Manager Protocol version used by the remote gvmd |
3239
|
|
|
|
3240
|
|
|
Returns: |
3241
|
|
|
The response. See :py:meth:`send_command` for details. |
3242
|
|
|
""" |
3243
|
|
|
return self._send_xml_command(XmlCommand('get_version')) |
3244
|
|
|
|
3245
|
|
|
def help(self, *, format=None, help_type=''): |
3246
|
|
|
"""Get the help text |
3247
|
|
|
|
3248
|
|
|
Arguments: |
3249
|
|
|
format (str, optional): One of "html", "rnc", "text" or "xml |
3250
|
|
|
type (str, optional): One of "brief" or "". Default "" |
3251
|
|
|
|
3252
|
|
|
Returns: |
3253
|
|
|
The response. See :py:meth:`send_command` for details. |
3254
|
|
|
""" |
3255
|
|
|
cmd = XmlCommand('help') |
3256
|
|
|
|
3257
|
|
|
if help_type not in ('', 'brief'): |
3258
|
|
|
raise InvalidArgument( |
3259
|
|
|
'help_type argument must be an empty string or "brief"') |
3260
|
|
|
|
3261
|
|
|
cmd.set_attribute('type', help_type) |
3262
|
|
|
|
3263
|
|
|
if format: |
3264
|
|
|
if not format.lower() in ('html', 'rnc', 'text', 'xml'): |
3265
|
|
|
raise InvalidArgument( |
3266
|
|
|
'help format Argument must be one of html, rnc, text or ' |
3267
|
|
|
'xml') |
3268
|
|
|
|
3269
|
|
|
cmd.set_attribute('format', format) |
3270
|
|
|
|
3271
|
|
|
return self._send_xml_command(cmd) |
3272
|
|
|
|
3273
|
|
|
def modify_agent(self, agent_id, *, name=None, comment=None): |
3274
|
|
|
"""Modifies an existing agent |
3275
|
|
|
|
3276
|
|
|
Arguments: |
3277
|
|
|
agent_id (str) UUID of the agent to be modified. |
3278
|
|
|
name (str, optional): Name of the new credential |
3279
|
|
|
comment (str, optional): Comment for the credential |
3280
|
|
|
|
3281
|
|
|
Returns: |
3282
|
|
|
The response. See :py:meth:`send_command` for details. |
3283
|
|
|
""" |
3284
|
|
|
if not agent_id: |
3285
|
|
|
raise RequiredArgument('modify_agent requires agent_id argument') |
3286
|
|
|
|
3287
|
|
|
cmd = XmlCommand('modify_agent') |
3288
|
|
|
cmd.set_attribute('agent_id', str(agent_id)) |
3289
|
|
|
if name: |
3290
|
|
|
cmd.add_element('name', name) |
3291
|
|
|
if comment: |
3292
|
|
|
cmd.add_element('comment', comment) |
3293
|
|
|
|
3294
|
|
|
return self._send_xml_command(cmd) |
3295
|
|
|
|
3296
|
|
|
def modify_alert(self, alert_id, *, name=None, comment=None, |
|
|
|
|
3297
|
|
|
filter_id=None, event=None, event_data=None, |
3298
|
|
|
condition=None, condition_data=None, method=None, |
3299
|
|
|
method_data=None): |
3300
|
|
|
"""Modifies an existing alert. |
3301
|
|
|
|
3302
|
|
|
Arguments: |
3303
|
|
|
alert_id (str) UUID of the alert to be modified. |
3304
|
|
|
name (str, optional): Name of the Alert. |
3305
|
|
|
condition (str, optional): The condition that must be satisfied |
3306
|
|
|
for the alert to occur. |
3307
|
|
|
condition_data (dict, optional): Data that defines the condition |
3308
|
|
|
event (str, optional): The event that must happen for the alert |
3309
|
|
|
to occur. |
3310
|
|
|
event_data (dict, optional): Data that defines the event |
3311
|
|
|
method (str, optional): The method by which the user is alerted |
3312
|
|
|
method_data (dict, optional): Data that defines the method |
3313
|
|
|
filter_id (str, optional): Filter to apply when executing alert |
3314
|
|
|
comment (str, optional): Comment for the alert |
3315
|
|
|
|
3316
|
|
|
Returns: |
3317
|
|
|
The response. See :py:meth:`send_command` for details. |
3318
|
|
|
""" |
3319
|
|
|
|
3320
|
|
|
if not alert_id: |
3321
|
|
|
raise RequiredArgument('modify_alert requires an alert_id argument') |
3322
|
|
|
|
3323
|
|
|
cmd = XmlCommand('modify_alert') |
3324
|
|
|
cmd.set_attribute('alert_id', str(alert_id)) |
3325
|
|
|
|
3326
|
|
|
if name: |
3327
|
|
|
cmd.add_element('name', name) |
3328
|
|
|
|
3329
|
|
|
if comment: |
3330
|
|
|
cmd.add_element('comment', comment) |
3331
|
|
|
|
3332
|
|
|
if filter_id: |
3333
|
|
|
cmd.add_element('filter', attrs={'id': filter_id}) |
3334
|
|
|
|
3335
|
|
|
conditions = cmd.add_element('condition', condition) |
3336
|
|
|
|
3337
|
|
|
if not condition_data is None: |
3338
|
|
|
for value, key in condition_data.items(): |
3339
|
|
|
_data = conditions.add_element('data', value) |
3340
|
|
|
_data.add_element('name', key) |
3341
|
|
|
|
3342
|
|
|
events = cmd.add_element('event', event) |
3343
|
|
|
|
3344
|
|
|
if not event_data is None: |
3345
|
|
|
for value, key in event_data.items(): |
3346
|
|
|
_data = events.add_element('data', value) |
3347
|
|
|
_data.add_element('name', key) |
3348
|
|
|
|
3349
|
|
|
methods = cmd.add_element('method', method) |
3350
|
|
|
|
3351
|
|
|
if not method_data is None: |
3352
|
|
|
for value, key in method_data.items(): |
3353
|
|
|
_data = methods.add_element('data', value) |
3354
|
|
|
_data.add_element('name', key) |
3355
|
|
|
|
3356
|
|
|
return self._send_xml_command(cmd) |
3357
|
|
|
|
3358
|
|
|
def modify_asset(self, asset_id, comment): |
3359
|
|
|
"""Modifies an existing asset. |
3360
|
|
|
|
3361
|
|
|
Arguments: |
3362
|
|
|
asset_id (str) UUID of the asset to be modified. |
3363
|
|
|
comment (str, optional): Comment for the asset. |
3364
|
|
|
|
3365
|
|
|
Returns: |
3366
|
|
|
The response. See :py:meth:`send_command` for details. |
3367
|
|
|
""" |
3368
|
|
|
if not asset_id: |
3369
|
|
|
raise RequiredArgument('modify_asset requires an asset_id argument') |
3370
|
|
|
|
3371
|
|
|
cmd = XmlCommand('modify_asset') |
3372
|
|
|
cmd.set_attribute('asset_id', asset_id) |
3373
|
|
|
cmd.add_element('comment', comment) |
3374
|
|
|
|
3375
|
|
|
return self._send_xml_command(cmd) |
3376
|
|
|
|
3377
|
|
|
def modify_auth(self, group_name, auth_conf_settings): |
3378
|
|
|
"""Modifies an existing auth. |
3379
|
|
|
|
3380
|
|
|
Arguments: |
3381
|
|
|
group_name (str) Name of the group to be modified. |
3382
|
|
|
auth_conf_settings (dict): The new auth config. |
3383
|
|
|
|
3384
|
|
|
Returns: |
3385
|
|
|
The response. See :py:meth:`send_command` for details. |
3386
|
|
|
""" |
3387
|
|
|
if not group_name: |
3388
|
|
|
raise RequiredArgument('modify_auth requires a group_name argument') |
3389
|
|
|
if not auth_conf_settings: |
3390
|
|
|
raise RequiredArgument('modify_auth requires an ' |
3391
|
|
|
'auth_conf_settings argument') |
3392
|
|
|
cmd = XmlCommand('modify_auth') |
3393
|
|
|
_xmlgroup = cmd.add_element('group', attrs={'name': str(group_name)}) |
3394
|
|
|
|
3395
|
|
|
for key, value in auth_conf_settings.items(): |
3396
|
|
|
_xmlauthconf = _xmlgroup.add_element('auth_conf_setting') |
3397
|
|
|
_xmlauthconf.add_element('key', key) |
3398
|
|
|
_xmlauthconf.add_element('value', value) |
3399
|
|
|
|
3400
|
|
|
return self._send_xml_command(cmd) |
3401
|
|
|
|
3402
|
|
|
def modify_config(self, config_id, selection, *, nvt_oids=None, name=None, |
3403
|
|
|
value=None, family=None): |
3404
|
|
|
"""Modifies an existing scan config. |
3405
|
|
|
|
3406
|
|
|
Arguments: |
3407
|
|
|
config_id (str): UUID of scan config to modify. |
3408
|
|
|
selection (str): one of 'nvt_pref', nvt_selection or |
3409
|
|
|
family_selection' |
3410
|
|
|
name (str, optional): New name for preference. |
3411
|
|
|
value(str, optional): New value for preference. |
3412
|
|
|
nvt_oids (list, optional): List of NVTs associated with preference |
3413
|
|
|
to modify. |
3414
|
|
|
family (str,optional): Name of family to modify. |
3415
|
|
|
|
3416
|
|
|
Returns: |
3417
|
|
|
The response. See :py:meth:`send_command` for details. |
3418
|
|
|
""" |
3419
|
|
|
if not config_id: |
3420
|
|
|
raise RequiredArgument('modify_config required config_id argument') |
3421
|
|
|
|
3422
|
|
|
if selection not in ('nvt_pref', 'scan_pref', |
3423
|
|
|
'family_selection', 'nvt_selection'): |
3424
|
|
|
raise InvalidArgument('selection must be one of nvt_pref, ' |
3425
|
|
|
'scan_pref, family_selection or ' |
3426
|
|
|
'nvt_selection') |
3427
|
|
|
|
3428
|
|
|
cmd = XmlCommand('modify_config') |
3429
|
|
|
cmd.set_attribute('config_id', str(config_id)) |
3430
|
|
|
|
3431
|
|
|
if selection == 'nvt_pref': |
3432
|
|
|
_xmlpref = cmd.add_element('preference') |
3433
|
|
|
if not nvt_oids: |
3434
|
|
|
raise InvalidArgument('modify_config requires a nvt_oids ' |
3435
|
|
|
'argument') |
3436
|
|
|
_xmlpref.add_element('nvt', attrs={'oid': nvt_oids[0]}) |
3437
|
|
|
_xmlpref.add_element('name', name) |
3438
|
|
|
_xmlpref.add_element('value', value) |
3439
|
|
|
|
3440
|
|
|
elif selection == 'nvt_selection': |
3441
|
|
|
_xmlnvtsel = cmd.add_element('nvt_selection') |
3442
|
|
|
_xmlnvtsel.add_element('family', family) |
3443
|
|
|
|
3444
|
|
|
if nvt_oids: |
3445
|
|
|
for nvt in nvt_oids: |
3446
|
|
|
_xmlnvtsel.add_element('nvt', attrs={'oid': nvt}) |
3447
|
|
|
else: |
3448
|
|
|
raise InvalidArgument('modify_config requires a nvt_oid ' |
3449
|
|
|
'argument') |
3450
|
|
|
|
3451
|
|
|
elif selection == 'family_selection': |
3452
|
|
|
_xmlfamsel = cmd.add_element('family_selection') |
3453
|
|
|
_xmlfamsel.add_element('growing', '1') |
3454
|
|
|
_xmlfamily = _xmlfamsel.add_element('family') |
3455
|
|
|
_xmlfamily.add_element('name', family) |
3456
|
|
|
_xmlfamily.add_element('all', '1') |
3457
|
|
|
_xmlfamily.add_element('growing', '1') |
3458
|
|
|
|
3459
|
|
|
return self._send_xml_command(cmd) |
3460
|
|
|
|
3461
|
|
|
def modify_credential(self, credential_id, credential_type=None, *, |
|
|
|
|
3462
|
|
|
name=None, comment=None, allow_insecure=None, |
3463
|
|
|
certificate=None, key_phrase=None, private_key=None, |
3464
|
|
|
login=None, password=None, auth_algorithm=None, |
3465
|
|
|
community=None, privacy_algorithm=None, |
3466
|
|
|
privacy_password=None): |
3467
|
|
|
"""Modifies an existing credential. |
3468
|
|
|
|
3469
|
|
|
Arguments: |
3470
|
|
|
credential_id (str): UUID of the credential |
3471
|
|
|
credential_type (str, optional): The credential type. One of 'cc', |
3472
|
|
|
'snmp', 'up', 'usk' |
3473
|
|
|
name (str, optional): Name of the credential |
3474
|
|
|
comment (str, optional): Comment for the credential |
3475
|
|
|
allow_insecure (boolean, optional): Whether to allow insecure use of |
3476
|
|
|
the credential |
3477
|
|
|
certificate (str, optional): Certificate for the credential |
3478
|
|
|
key_phrase (str, optional): Key passphrase for the private key |
3479
|
|
|
private_key (str, optional): Private key to use for login |
3480
|
|
|
login (str, optional): Username for the credential |
3481
|
|
|
password (str, optional): Password for the credential |
3482
|
|
|
auth_algorithm (str, optional): The auth_algorithm, |
3483
|
|
|
either md5 or sha1. |
3484
|
|
|
community (str, optional): The SNMP community |
3485
|
|
|
privacy_algorithm (str, optional): The SNMP privacy algorithm, |
3486
|
|
|
either aes or des. |
3487
|
|
|
privacy_password (str, optional): The SNMP privacy password |
3488
|
|
|
|
3489
|
|
|
Returns: |
3490
|
|
|
The response. See :py:meth:`send_command` for details. |
3491
|
|
|
""" |
3492
|
|
|
if not credential_id: |
3493
|
|
|
raise RequiredArgument('modify_credential requires ' |
3494
|
|
|
'a credential_id attribute') |
3495
|
|
|
|
3496
|
|
|
cmd = XmlCommand('modify_credential') |
3497
|
|
|
cmd.set_attribute('credential_id', credential_id) |
3498
|
|
|
|
3499
|
|
|
if credential_type: |
3500
|
|
|
if credential_type not in ('cc', 'snmp', 'up', 'usk'): |
3501
|
|
|
raise RequiredArgument('modify_credential requires type ' |
3502
|
|
|
'to be either cc, snmp, up or usk') |
3503
|
|
|
|
3504
|
|
|
cmd.add_element('type', credential_type) |
3505
|
|
|
|
3506
|
|
|
if comment: |
3507
|
|
|
cmd.add_element('comment', comment) |
3508
|
|
|
|
3509
|
|
|
if name: |
3510
|
|
|
cmd.add_element('name', name) |
3511
|
|
|
|
3512
|
|
|
if allow_insecure: |
3513
|
|
|
cmd.add_element('allow_insecure', allow_insecure) |
3514
|
|
|
|
3515
|
|
|
if certificate: |
3516
|
|
|
cmd.add_element('certificate', certificate) |
3517
|
|
|
|
3518
|
|
|
if key_phrase or private_key: |
3519
|
|
|
if not key_phrase or not private_key: |
3520
|
|
|
raise RequiredArgument('modify_credential requires ' |
3521
|
|
|
'a key_phrase and private_key arguments') |
3522
|
|
|
_xmlkey = cmd.add_element('key') |
3523
|
|
|
_xmlkey.add_element('phrase', key_phrase) |
3524
|
|
|
_xmlkey.add_element('private', private_key) |
3525
|
|
|
|
3526
|
|
|
if login: |
3527
|
|
|
cmd.add_element('login', login) |
3528
|
|
|
|
3529
|
|
|
if password: |
3530
|
|
|
cmd.add_element('password', password) |
3531
|
|
|
|
3532
|
|
|
if auth_algorithm: |
3533
|
|
|
if auth_algorithm not in ('md5', 'sha1'): |
3534
|
|
|
raise RequiredArgument('modify_credential requires ' |
3535
|
|
|
'auth_algorithm to be either ' |
3536
|
|
|
'md5 or sha1') |
3537
|
|
|
cmd.add_element('auth_algorithm', auth_algorithm) |
3538
|
|
|
|
3539
|
|
|
if community: |
3540
|
|
|
cmd.add_element('community', community) |
3541
|
|
|
|
3542
|
|
|
if privacy_algorithm: |
3543
|
|
|
if privacy_algorithm not in ('aes', 'des'): |
3544
|
|
|
raise RequiredArgument('modify_credential requires ' |
3545
|
|
|
'privacy_algorithm to be either' |
3546
|
|
|
'aes or des') |
3547
|
|
|
_xmlprivacy = cmd.add_element('privacy') |
3548
|
|
|
_xmlprivacy.add_element('algorithm', privacy_algorithm) |
3549
|
|
|
_xmlprivacy.add_element('password', privacy_password) |
3550
|
|
|
|
3551
|
|
|
return self._send_xml_command(cmd) |
3552
|
|
|
|
3553
|
|
|
def modify_filter(self, filter_id, *, comment=None, name=None, term=None, |
3554
|
|
|
filter_type=None): |
3555
|
|
|
"""Modifies an existing filter. |
3556
|
|
|
|
3557
|
|
|
Arguments: |
3558
|
|
|
filter_id (str): UUID of the filter to be modified |
3559
|
|
|
comment (str, optional): Comment on filter. |
3560
|
|
|
name (str, optional): Name of filter. |
3561
|
|
|
term (str, optional): Filter term. |
3562
|
|
|
filter_type (str, optional): Resource type filter applies to. |
3563
|
|
|
|
3564
|
|
|
Returns: |
3565
|
|
|
The response. See :py:meth:`send_command` for details. |
3566
|
|
|
""" |
3567
|
|
|
if not filter_id: |
3568
|
|
|
raise RequiredArgument('modify_filter requires a filter_id ' |
3569
|
|
|
'attribute') |
3570
|
|
|
|
3571
|
|
|
cmd = XmlCommand('modify_filter') |
3572
|
|
|
cmd.set_attribute('filter_id', filter_id) |
3573
|
|
|
|
3574
|
|
|
if comment: |
3575
|
|
|
cmd.add_element('comment', comment) |
3576
|
|
|
|
3577
|
|
|
if name: |
3578
|
|
|
cmd.add_element('name', name) |
3579
|
|
|
|
3580
|
|
|
if term: |
3581
|
|
|
cmd.add_element('term', term) |
3582
|
|
|
|
3583
|
|
|
if filter_type: |
3584
|
|
|
filter_type = filter_type.lower() |
3585
|
|
|
if filter_type not in FILTER_TYPES: |
3586
|
|
|
raise InvalidArgument( |
3587
|
|
|
'modify_filter requires type to be one of {0} but ' |
3588
|
|
|
'was {1}'.format(', '.join(FILTER_TYPES), filter_type)) |
3589
|
|
|
cmd.add_element('type', filter_type) |
3590
|
|
|
|
3591
|
|
|
return self._send_xml_command(cmd) |
3592
|
|
|
|
3593
|
|
|
def modify_group(self, group_id, *, comment=None, name=None, |
3594
|
|
|
users=None): |
3595
|
|
|
"""Modifies an existing group. |
3596
|
|
|
|
3597
|
|
|
Arguments: |
3598
|
|
|
group_id (str): UUID of group to modify. |
3599
|
|
|
comment (str, optional): Comment on group. |
3600
|
|
|
name (str, optional): Name of group. |
3601
|
|
|
users (list, optional): List of user names to be in the group |
3602
|
|
|
|
3603
|
|
|
Returns: |
3604
|
|
|
The response. See :py:meth:`send_command` for details. |
3605
|
|
|
""" |
3606
|
|
|
if not group_id: |
3607
|
|
|
raise RequiredArgument('modify_group requires a group_id argument') |
3608
|
|
|
|
3609
|
|
|
cmd = XmlCommand('modify_group') |
3610
|
|
|
cmd.set_attribute('group_id', group_id) |
3611
|
|
|
|
3612
|
|
|
if comment: |
3613
|
|
|
cmd.add_element('comment', comment) |
3614
|
|
|
|
3615
|
|
|
if name: |
3616
|
|
|
cmd.add_element('name', name) |
3617
|
|
|
|
3618
|
|
|
if users: |
3619
|
|
|
cmd.add_element('users', ','.join(users)) |
3620
|
|
|
|
3621
|
|
|
return self._send_xml_command(cmd) |
3622
|
|
|
|
3623
|
|
|
def modify_note(self, note_id, text, *, seconds_active=None, hosts=None, |
3624
|
|
|
port=None, result_id=None, severity=None, task_id=None, |
3625
|
|
|
threat=None): |
3626
|
|
|
"""Modifies an existing note. |
3627
|
|
|
|
3628
|
|
|
Arguments: |
3629
|
|
|
note_id (str): UUID of note to modify. |
3630
|
|
|
text (str): The text of the note. |
3631
|
|
|
seconds_active (int, optional): Seconds note will be active. |
3632
|
|
|
-1 on always, 0 off. |
3633
|
|
|
hosts (list, optional): A list of hosts addresses |
3634
|
|
|
port (str, optional): Port to which note applies. |
3635
|
|
|
result_id (str, optional): Result to which note applies. |
3636
|
|
|
severity (str, optional): Severity to which note applies. |
3637
|
|
|
task_id (str, optional): Task to which note applies. |
3638
|
|
|
threat (str, optional): Threat level to which note applies. |
3639
|
|
|
|
3640
|
|
|
Returns: |
3641
|
|
|
The response. See :py:meth:`send_command` for details. |
3642
|
|
|
""" |
3643
|
|
|
if not note_id: |
3644
|
|
|
raise RequiredArgument('modify_note requires a note_id attribute') |
3645
|
|
|
if not text: |
3646
|
|
|
raise RequiredArgument('modify_note requires a text element') |
3647
|
|
|
|
3648
|
|
|
cmd = XmlCommand('modify_note') |
3649
|
|
|
cmd.set_attribute('note_id', note_id) |
3650
|
|
|
cmd.add_element('text', text) |
3651
|
|
|
|
3652
|
|
|
if not seconds_active is None: |
3653
|
|
|
cmd.add_element('active', str(seconds_active)) |
3654
|
|
|
|
3655
|
|
|
if hosts: |
3656
|
|
|
cmd.add_element('hosts', ', '.join(hosts)) |
3657
|
|
|
|
3658
|
|
|
if port: |
3659
|
|
|
cmd.add_element('port', port) |
3660
|
|
|
|
3661
|
|
|
if result_id: |
3662
|
|
|
cmd.add_element('result', attrs={'id': result_id}) |
3663
|
|
|
|
3664
|
|
|
if severity: |
3665
|
|
|
cmd.add_element('severity', severity) |
3666
|
|
|
|
3667
|
|
|
if task_id: |
3668
|
|
|
cmd.add_element('task', attrs={'id': task_id}) |
3669
|
|
|
|
3670
|
|
|
if threat: |
3671
|
|
|
cmd.add_element('threat', threat) |
3672
|
|
|
|
3673
|
|
|
return self._send_xml_command(cmd) |
3674
|
|
|
|
3675
|
|
View Code Duplication |
def modify_override(self, override_id, text, *, seconds_active=None, |
|
|
|
|
3676
|
|
|
hosts=None, port=None, result_id=None, severity=None, |
3677
|
|
|
new_severity=None, task_id=None, threat=None, |
3678
|
|
|
new_threat=None): |
3679
|
|
|
"""Modifies an existing override. |
3680
|
|
|
|
3681
|
|
|
Arguments: |
3682
|
|
|
override_id (str): UUID of override to modify. |
3683
|
|
|
text (str): The text of the override. |
3684
|
|
|
seconds_active (int, optional): Seconds override will be active. |
3685
|
|
|
-1 on always, 0 off. |
3686
|
|
|
hosts (list, optional): A list of host addresses |
3687
|
|
|
port (str, optional): Port to which override applies. |
3688
|
|
|
result_id (str, optional): Result to which override applies. |
3689
|
|
|
severity (str, optional): Severity to which override applies. |
3690
|
|
|
new_severity (str, optional): New severity score for result. |
3691
|
|
|
task_id (str, optional): Task to which override applies. |
3692
|
|
|
threat (str, optional): Threat level to which override applies. |
3693
|
|
|
new_threat (str, optional): New threat level for results. |
3694
|
|
|
|
3695
|
|
|
Returns: |
3696
|
|
|
The response. See :py:meth:`send_command` for details. |
3697
|
|
|
""" |
3698
|
|
|
if not override_id: |
3699
|
|
|
raise RequiredArgument('modify_override requires a override_id ' |
3700
|
|
|
'argument') |
3701
|
|
|
if not text: |
3702
|
|
|
raise RequiredArgument('modify_override requires a text argument') |
3703
|
|
|
|
3704
|
|
|
cmd = XmlCommand('modify_override') |
3705
|
|
|
cmd.set_attribute('override_id', override_id) |
3706
|
|
|
cmd.add_element('text', text) |
3707
|
|
|
|
3708
|
|
|
if not seconds_active is None: |
3709
|
|
|
cmd.add_element('active', str(seconds_active)) |
3710
|
|
|
|
3711
|
|
|
if hosts: |
3712
|
|
|
cmd.add_element('hosts', ', '.join(hosts)) |
3713
|
|
|
|
3714
|
|
|
if port: |
3715
|
|
|
cmd.add_element('port', port) |
3716
|
|
|
|
3717
|
|
|
if result_id: |
3718
|
|
|
cmd.add_element('result', attrs={'id': result_id}) |
3719
|
|
|
|
3720
|
|
|
if severity: |
3721
|
|
|
cmd.add_element('severity', severity) |
3722
|
|
|
|
3723
|
|
|
if new_severity: |
3724
|
|
|
cmd.add_element('new_severity', new_severity) |
3725
|
|
|
|
3726
|
|
|
if task_id: |
3727
|
|
|
cmd.add_element('task', attrs={'id': task_id}) |
3728
|
|
|
|
3729
|
|
|
if threat: |
3730
|
|
|
cmd.add_element('threat', threat) |
3731
|
|
|
|
3732
|
|
|
if new_threat: |
3733
|
|
|
cmd.add_element('new_threat', new_threat) |
3734
|
|
|
|
3735
|
|
|
return self._send_xml_command(cmd) |
3736
|
|
|
|
3737
|
|
|
def modify_permission(self, permission_id, *, comment=None, name=None, |
3738
|
|
|
resource_id=None, resource_type=None, |
3739
|
|
|
subject_id=None, subject_type=None): |
3740
|
|
|
"""Modifies an existing permission. |
3741
|
|
|
|
3742
|
|
|
Arguments: |
3743
|
|
|
permission_id (str): UUID of permission to be modified. |
3744
|
|
|
comment (str, optional): The comment on the permission. |
3745
|
|
|
name (str, optional): Permission name, currently the name of |
3746
|
|
|
a command. |
3747
|
|
|
subject_id (str, optional): UUID of subject to whom the permission |
3748
|
|
|
is granted |
3749
|
|
|
subject_type (str, optional): Type of the subject user, group or |
3750
|
|
|
role |
3751
|
|
|
resource_id (str, optional): UUID of entity to which the permission |
3752
|
|
|
applies |
3753
|
|
|
resource_type (str, optional): Type of the resource. For Super |
3754
|
|
|
permissions user, group or role |
3755
|
|
|
|
3756
|
|
|
Returns: |
3757
|
|
|
The response. See :py:meth:`send_command` for details. |
3758
|
|
|
""" |
3759
|
|
|
if not permission_id: |
3760
|
|
|
raise RequiredArgument('modify_permission requires ' |
3761
|
|
|
'a permission_id element') |
3762
|
|
|
|
3763
|
|
|
cmd = XmlCommand('modify_permission') |
3764
|
|
|
cmd.set_attribute('permission_id', permission_id) |
3765
|
|
|
|
3766
|
|
|
if comment: |
3767
|
|
|
cmd.add_element('comment', comment) |
3768
|
|
|
|
3769
|
|
|
if name: |
3770
|
|
|
cmd.add_element('name', name) |
3771
|
|
|
|
3772
|
|
|
if resource_id and resource_type: |
3773
|
|
|
_xmlresource = cmd.add_element('resource', |
3774
|
|
|
attrs={'id': resource_id}) |
3775
|
|
|
_xmlresource.add_element('type', resource_type) |
3776
|
|
|
|
3777
|
|
|
if subject_id and subject_type: |
3778
|
|
|
_xmlsubject = cmd.add_element('subject', |
3779
|
|
|
attrs={'id': subject_id}) |
3780
|
|
|
_xmlsubject.add_element('type', subject_type) |
3781
|
|
|
|
3782
|
|
|
return self._send_xml_command(cmd) |
3783
|
|
|
|
3784
|
|
|
def modify_port_list(self, port_list_id, *, comment=None, name=None): |
3785
|
|
|
"""Modifies an existing port list. |
3786
|
|
|
|
3787
|
|
|
Arguments: |
3788
|
|
|
port_list_id (str): UUID of port list to modify. |
3789
|
|
|
name (str, optional): Name of port list. |
3790
|
|
|
comment (str, optional): Comment on port list. |
3791
|
|
|
|
3792
|
|
|
Returns: |
3793
|
|
|
The response. See :py:meth:`send_command` for details. |
3794
|
|
|
""" |
3795
|
|
|
if not port_list_id: |
3796
|
|
|
raise RequiredArgument('modify_port_list requires ' |
3797
|
|
|
'a port_list_id attribute') |
3798
|
|
|
cmd = XmlCommand('modify_port_list') |
3799
|
|
|
cmd.set_attribute('port_list_id', port_list_id) |
3800
|
|
|
|
3801
|
|
|
if comment: |
3802
|
|
|
cmd.add_element('comment', comment) |
3803
|
|
|
|
3804
|
|
|
if name: |
3805
|
|
|
cmd.add_element('name', name) |
3806
|
|
|
|
3807
|
|
|
return self._send_xml_command(cmd) |
3808
|
|
|
|
3809
|
|
|
def modify_report(self, report_id, comment): |
3810
|
|
|
"""Modifies an existing report. |
3811
|
|
|
|
3812
|
|
|
Arguments: |
3813
|
|
|
report_id (str): UUID of report to modify. |
3814
|
|
|
comment (str): The comment on the report. |
3815
|
|
|
|
3816
|
|
|
Returns: |
3817
|
|
|
The response. See :py:meth:`send_command` for details. |
3818
|
|
|
""" |
3819
|
|
|
if not report_id: |
3820
|
|
|
raise RequiredArgument('modify_report requires ' |
3821
|
|
|
'a report_id attribute') |
3822
|
|
|
if not comment: |
3823
|
|
|
raise RequiredArgument('modify_report requires ' |
3824
|
|
|
'a comment attribute') |
3825
|
|
|
cmd = XmlCommand('modify_report') |
3826
|
|
|
cmd.set_attribute('report_id', report_id) |
3827
|
|
|
cmd.add_element('comment', comment) |
3828
|
|
|
|
3829
|
|
|
return self._send_xml_command(cmd) |
3830
|
|
|
|
3831
|
|
|
def modify_report_format(self, report_format_id, *, active=None, name=None, |
3832
|
|
|
summary=None, param_name=None, param_value=None): |
3833
|
|
|
"""Modifies an existing report format. |
3834
|
|
|
|
3835
|
|
|
Arguments: |
3836
|
|
|
report_format_id (str) UUID of report format to modify. |
3837
|
|
|
active (boolean, optional): Whether the report format is active. |
3838
|
|
|
name (str, optional): The name of the report format. |
3839
|
|
|
summary (str, optional): A summary of the report format. |
3840
|
|
|
param_name (str, optional): The name of the param. |
3841
|
|
|
param_value (str, optional): The value of the param. |
3842
|
|
|
|
3843
|
|
|
Returns: |
3844
|
|
|
The response. See :py:meth:`send_command` for details. |
3845
|
|
|
""" |
3846
|
|
|
if not report_format_id: |
3847
|
|
|
raise RequiredArgument('modify_report requires ' |
3848
|
|
|
'a report_format_id attribute') |
3849
|
|
|
cmd = XmlCommand('modify_report_format') |
3850
|
|
|
cmd.set_attribute('report_format_id', report_format_id) |
3851
|
|
|
|
3852
|
|
|
if not active is None: |
3853
|
|
|
cmd.add_element('active', '1' if active else '0') |
3854
|
|
|
|
3855
|
|
|
if name: |
3856
|
|
|
cmd.add_element('name', name) |
3857
|
|
|
|
3858
|
|
|
if summary: |
3859
|
|
|
cmd.add_element('summary', summary) |
3860
|
|
|
|
3861
|
|
|
if param_name and param_value: |
3862
|
|
|
_xmlparam = cmd.add_element('param') |
3863
|
|
|
_xmlparam.add_element('name', param_name) |
3864
|
|
|
_xmlparam.add_element('value', param_value) |
3865
|
|
|
|
3866
|
|
|
return self._send_xml_command(cmd) |
3867
|
|
|
|
3868
|
|
|
def modify_role(self, role_id, *, comment=None, name=None, users=None): |
3869
|
|
|
"""Modifies an existing role. |
3870
|
|
|
|
3871
|
|
|
Arguments: |
3872
|
|
|
role_id (str): UUID of role to modify. |
3873
|
|
|
comment (str, optional): Name of role. |
3874
|
|
|
name (str, optional): Comment on role. |
3875
|
|
|
users (list, optional): List of user names. |
3876
|
|
|
|
3877
|
|
|
Returns: |
3878
|
|
|
The response. See :py:meth:`send_command` for details. |
3879
|
|
|
""" |
3880
|
|
|
if not role_id: |
3881
|
|
|
raise RequiredArgument('modify_role requires a role_id argument') |
3882
|
|
|
|
3883
|
|
|
cmd = XmlCommand('modify_role') |
3884
|
|
|
cmd.set_attribute('role_id', role_id) |
3885
|
|
|
|
3886
|
|
|
if comment: |
3887
|
|
|
cmd.add_element('comment', comment) |
3888
|
|
|
|
3889
|
|
|
if name: |
3890
|
|
|
cmd.add_element('name', name) |
3891
|
|
|
|
3892
|
|
|
if users: |
3893
|
|
|
cmd.add_element('users', ",".join(users)) |
3894
|
|
|
|
3895
|
|
|
return self._send_xml_command(cmd) |
3896
|
|
|
|
3897
|
|
View Code Duplication |
def modify_scanner(self, scanner_id, host, port, scanner_type, *, |
|
|
|
|
3898
|
|
|
comment=None, name=None, ca_pub=None, |
3899
|
|
|
credential_id=None): |
3900
|
|
|
"""Modifies an existing scanner. |
3901
|
|
|
|
3902
|
|
|
Arguments: |
3903
|
|
|
scanner_id (str): UUID of scanner to modify. |
3904
|
|
|
host (str): Host of the scanner. |
3905
|
|
|
port (str): Port of the scanner. |
3906
|
|
|
scanner_type (str): Type of the scanner. |
3907
|
|
|
'1' for OSP, '2' for OpenVAS (classic) Scanner. |
3908
|
|
|
comment (str, optional): Comment on scanner. |
3909
|
|
|
name (str, optional): Name of scanner. |
3910
|
|
|
ca_pub (str, optional): Certificate of CA to verify scanner's |
3911
|
|
|
certificate. |
3912
|
|
|
credential_id (str, optional): UUID of the client certificate |
3913
|
|
|
credential for the Scanner. |
3914
|
|
|
|
3915
|
|
|
Returns: |
3916
|
|
|
The response. See :py:meth:`send_command` for details. |
3917
|
|
|
""" |
3918
|
|
|
if not scanner_id: |
3919
|
|
|
raise RequiredArgument( |
3920
|
|
|
'modify_scanner requires a scanner_id argument') |
3921
|
|
|
if not host: |
3922
|
|
|
raise RequiredArgument('modify_scanner requires a host argument') |
3923
|
|
|
if not port: |
3924
|
|
|
raise RequiredArgument('modify_scanner requires a port argument') |
3925
|
|
|
if not scanner_type: |
3926
|
|
|
raise RequiredArgument('modify_scanner requires a scanner_type ' |
3927
|
|
|
'argument') |
3928
|
|
|
|
3929
|
|
|
cmd = XmlCommand('modify_scanner') |
3930
|
|
|
cmd.set_attribute('scanner_id', scanner_id) |
3931
|
|
|
cmd.add_element('host', host) |
3932
|
|
|
cmd.add_element('port', port) |
3933
|
|
|
|
3934
|
|
|
if scanner_type not in SCANNER_TYPES: |
3935
|
|
|
raise InvalidArgument('modify_scanner requires a scanner_type ' |
3936
|
|
|
'argument which must be either "1" for OSP ' |
3937
|
|
|
'or "2" OpenVAS (Classic).') |
3938
|
|
|
|
3939
|
|
|
cmd.add_element('type', scanner_type) |
3940
|
|
|
|
3941
|
|
|
if comment: |
3942
|
|
|
cmd.add_element('comment', comment) |
3943
|
|
|
|
3944
|
|
|
if name: |
3945
|
|
|
cmd.add_element('name', name) |
3946
|
|
|
|
3947
|
|
|
if ca_pub: |
3948
|
|
|
cmd.add_element('ca_pub', ca_pub) |
3949
|
|
|
|
3950
|
|
|
if credential_id: |
3951
|
|
|
cmd.add_element('credential', attrs={'id': str(credential_id)}) |
3952
|
|
|
|
3953
|
|
|
return self._send_xml_command(cmd) |
3954
|
|
|
|
3955
|
|
|
def modify_schedule(self, schedule_id, *, comment=None, name=None, |
|
|
|
|
3956
|
|
|
first_time_minute=None, first_time_hour=None, |
3957
|
|
|
first_time_day_of_month=None, first_time_month=None, |
3958
|
|
|
first_time_year=None, duration=None, duration_unit=None, |
3959
|
|
|
period=None, period_unit=None, timezone=None): |
3960
|
|
|
"""Modifies an existing schedule. |
3961
|
|
|
|
3962
|
|
|
Arguments: |
3963
|
|
|
schedule_id (str): UUID of schedule to modify. |
3964
|
|
|
name (str, optional): Name of the schedule |
3965
|
|
|
comment (str, optional): Comment for the schedule |
3966
|
|
|
first_time_minute (int, optional): First time minute the schedule |
3967
|
|
|
will run |
3968
|
|
|
first_time_hour (int, optional): First time hour the schedule |
3969
|
|
|
will run |
3970
|
|
|
first_time_day_of_month (int, optional): First time day of month the |
3971
|
|
|
schedule will run |
3972
|
|
|
first_time_month (int, optional): First time month the schedule |
3973
|
|
|
will run |
3974
|
|
|
first_time_year (int, optional): First time year the schedule |
3975
|
|
|
will run |
3976
|
|
|
duration (int, optional): How long the Manager will run the |
3977
|
|
|
scheduled task for until it gets paused if not finished yet. |
3978
|
|
|
duration_unit (str, optional): Unit of the duration. One of second, |
3979
|
|
|
minute, hour, day, week, month, year, decade. Required if |
3980
|
|
|
duration is set. |
3981
|
|
|
period (int, optional): How often the Manager will repeat the |
3982
|
|
|
scheduled task |
3983
|
|
|
period_unit (str, optional): Unit of the period. One of second, |
3984
|
|
|
minute, hour, day, week, month, year, decade. Required if |
3985
|
|
|
period is set. |
3986
|
|
|
timezone (str, optional): The timezone the schedule will follow |
3987
|
|
|
|
3988
|
|
|
Returns: |
3989
|
|
|
The response. See :py:meth:`send_command` for details. |
3990
|
|
|
""" |
3991
|
|
|
if not schedule_id: |
3992
|
|
|
raise RequiredArgument('modify_schedule requires a schedule_id' |
3993
|
|
|
'argument') |
3994
|
|
|
|
3995
|
|
|
cmd = XmlCommand('modify_schedule') |
3996
|
|
|
cmd.set_attribute('schedule_id', schedule_id) |
3997
|
|
|
|
3998
|
|
|
if comment: |
3999
|
|
|
cmd.add_element('comment', comment) |
4000
|
|
|
|
4001
|
|
|
if name: |
4002
|
|
|
cmd.add_element('name', name) |
4003
|
|
|
|
4004
|
|
View Code Duplication |
if first_time_minute or first_time_hour or first_time_day_of_month or \ |
|
|
|
|
4005
|
|
|
first_time_month or first_time_year: |
4006
|
|
|
|
4007
|
|
|
if not first_time_minute: |
4008
|
|
|
raise RequiredArgument( |
4009
|
|
|
'Setting first_time requires first_time_minute argument') |
4010
|
|
|
if not first_time_hour: |
4011
|
|
|
raise RequiredArgument( |
4012
|
|
|
'Setting first_time requires first_time_hour argument') |
4013
|
|
|
if not first_time_day_of_month: |
4014
|
|
|
raise RequiredArgument( |
4015
|
|
|
'Setting first_time requires first_time_day_of_month ' |
4016
|
|
|
'argument') |
4017
|
|
|
if not first_time_month: |
4018
|
|
|
raise RequiredArgument( |
4019
|
|
|
'Setting first_time requires first_time_month argument') |
4020
|
|
|
if not first_time_year: |
4021
|
|
|
raise RequiredArgument( |
4022
|
|
|
'Setting first_time requires first_time_year argument') |
4023
|
|
|
|
4024
|
|
|
_xmlftime = cmd.add_element('first_time') |
4025
|
|
|
_xmlftime.add_element('minute', str(first_time_minute)) |
4026
|
|
|
_xmlftime.add_element('hour', str(first_time_hour)) |
4027
|
|
|
_xmlftime.add_element('day_of_month', str(first_time_day_of_month)) |
4028
|
|
|
_xmlftime.add_element('month', str(first_time_month)) |
4029
|
|
|
_xmlftime.add_element('year', str(first_time_year)) |
4030
|
|
|
|
4031
|
|
View Code Duplication |
if duration: |
|
|
|
|
4032
|
|
|
if not duration_unit: |
4033
|
|
|
raise RequiredArgument( |
4034
|
|
|
'Setting duration requires duration_unit argument') |
4035
|
|
|
|
4036
|
|
|
if not duration_unit in TIME_UNITS: |
4037
|
|
|
raise InvalidArgument( |
4038
|
|
|
'duration_unit must be one of {units} but {actual} has ' |
4039
|
|
|
'been passed'.format( |
4040
|
|
|
units=', '.join(TIME_UNITS), actual=duration_unit)) |
4041
|
|
|
|
4042
|
|
|
_xmlduration = cmd.add_element('duration', str(duration)) |
4043
|
|
|
_xmlduration.add_element('unit', duration_unit) |
4044
|
|
|
|
4045
|
|
View Code Duplication |
if period: |
|
|
|
|
4046
|
|
|
if not period_unit: |
4047
|
|
|
raise RequiredArgument( |
4048
|
|
|
'Setting period requires period_unit argument') |
4049
|
|
|
|
4050
|
|
|
if not period_unit in TIME_UNITS: |
4051
|
|
|
raise InvalidArgument( |
4052
|
|
|
'period_unit must be one of {units} but {actual} has ' |
4053
|
|
|
'been passed'.format( |
4054
|
|
|
units=', '.join(TIME_UNITS), actual=period_unit)) |
4055
|
|
|
|
4056
|
|
|
_xmlperiod = cmd.add_element('period', str(period)) |
4057
|
|
|
_xmlperiod.add_element('unit', period_unit) |
4058
|
|
|
|
4059
|
|
|
if timezone: |
4060
|
|
|
cmd.add_element('timezone', str(timezone)) |
4061
|
|
|
|
4062
|
|
|
return self._send_xml_command(cmd) |
4063
|
|
|
|
4064
|
|
|
def modify_setting(self, setting_id, name, value): |
4065
|
|
|
"""Modifies an existing setting. |
4066
|
|
|
|
4067
|
|
|
Arguments: |
4068
|
|
|
setting_id (str): UUID of the setting to be changed. |
4069
|
|
|
name (str): The name of the setting. |
4070
|
|
|
value (str): The value of the setting. |
4071
|
|
|
|
4072
|
|
|
Returns: |
4073
|
|
|
The response. See :py:meth:`send_command` for details. |
4074
|
|
|
""" |
4075
|
|
|
if not setting_id: |
4076
|
|
|
raise RequiredArgument('modify_setting requires a setting_id' |
4077
|
|
|
'argument') |
4078
|
|
|
if not name: |
4079
|
|
|
raise RequiredArgument('modify_setting requires a name argument') |
4080
|
|
|
|
4081
|
|
|
if not value: |
4082
|
|
|
raise RequiredArgument('modify_setting requires a value argument') |
4083
|
|
|
|
4084
|
|
|
cmd = XmlCommand('modify_setting') |
4085
|
|
|
cmd.set_attribute('setting_id', setting_id) |
4086
|
|
|
cmd.add_element('name', name) |
4087
|
|
|
cmd.add_element('value', value) |
4088
|
|
|
|
4089
|
|
|
return self._send_xml_command(cmd) |
4090
|
|
|
|
4091
|
|
|
def modify_tag(self, tag_id, *, comment=None, name=None, value=None, |
4092
|
|
|
active=None, resource_id=None, resource_type=None): |
4093
|
|
|
"""Modifies an existing tag. |
4094
|
|
|
|
4095
|
|
|
Arguments: |
4096
|
|
|
tag_id (str): UUID of the tag. |
4097
|
|
|
comment (str, optional): Comment to add to the tag. |
4098
|
|
|
name (str, optional): Name of the tag. |
4099
|
|
|
value (str, optional): Value of the tag. |
4100
|
|
|
active (boolean, optional): Whether the tag is active. |
4101
|
|
|
resource_id (str, optional): IDs of the resource to which to |
4102
|
|
|
attach the tag. |
4103
|
|
|
resource_type (str, optional): Type of the resource to which to |
4104
|
|
|
attach the tag. |
4105
|
|
|
|
4106
|
|
|
Returns: |
4107
|
|
|
The response. See :py:meth:`send_command` for details. |
4108
|
|
|
""" |
4109
|
|
|
if not tag_id: |
4110
|
|
|
raise RequiredArgument('modify_tag requires a tag_id element') |
4111
|
|
|
|
4112
|
|
|
cmd = XmlCommand('modify_tag') |
4113
|
|
|
cmd.set_attribute('tag_id', str(tag_id)) |
4114
|
|
|
|
4115
|
|
|
if comment: |
4116
|
|
|
cmd.add_element('comment', comment) |
4117
|
|
|
|
4118
|
|
|
if name: |
4119
|
|
|
cmd.add_element('name', name) |
4120
|
|
|
|
4121
|
|
|
if value: |
4122
|
|
|
cmd.add_element('value', value) |
4123
|
|
|
|
4124
|
|
|
if not active is None: |
4125
|
|
|
if active: |
4126
|
|
|
cmd.add_element('active', '1') |
4127
|
|
|
else: |
4128
|
|
|
cmd.add_element('active', '0') |
4129
|
|
|
|
4130
|
|
|
if resource_id and resource_type: |
4131
|
|
|
_xmlresource = cmd.add_element('resource', |
4132
|
|
|
attrs={'resource_id': resource_id}) |
4133
|
|
|
_xmlresource.add_element('type', resource_type) |
4134
|
|
|
|
4135
|
|
|
return self._send_xml_command(cmd) |
4136
|
|
|
|
4137
|
|
|
def modify_target(self, target_id, *, name=None, comment=None, |
|
|
|
|
4138
|
|
|
hosts=None, hosts_ordering=None, |
4139
|
|
|
exclude_hosts=None, ssh_credential_id=None, |
4140
|
|
|
smb_credential_id=None, esxi_credential_id=None, |
4141
|
|
|
snmp_credential_id=None, alive_tests=None, |
4142
|
|
|
reverse_lookup_only=None, reverse_lookup_unify=None, |
4143
|
|
|
port_list_id=None): |
4144
|
|
|
"""Modifies an existing target. |
4145
|
|
|
|
4146
|
|
|
Arguments: |
4147
|
|
|
target_id (uuid) ID of target to modify. |
4148
|
|
|
comment (str, optional): Comment on target. |
4149
|
|
|
name (str, optional): Name of target. |
4150
|
|
|
hosts (list, optional): List of target hosts. |
4151
|
|
|
hosts_ordering (str, optional): The order hosts are scanned in. |
4152
|
|
|
exclude_hosts (list, optional): A list of hosts to exclude. |
4153
|
|
|
ssh_credential (str, optional): UUID of SSH credential to |
4154
|
|
|
use on target. |
4155
|
|
|
smb_credential (str, optional): UUID of SMB credential to use |
4156
|
|
|
on target. |
4157
|
|
|
esxi_credential (str, optional): UUID of ESXi credential to use |
4158
|
|
|
on target. |
4159
|
|
|
snmp_credential (str, optional): UUID of SNMP credential to use |
4160
|
|
|
on target. |
4161
|
|
|
port_list (str, optional): UUID of port list describing ports to |
4162
|
|
|
scan. |
4163
|
|
|
alive_tests (str, optional): Which alive tests to use. |
4164
|
|
|
reverse_lookup_only (boolean, optional): Whether to scan only hosts |
4165
|
|
|
that have names. |
4166
|
|
|
reverse_lookup_unify (boolean, optional): Whether to scan only one |
4167
|
|
|
IP when multiple IPs have the same name. |
4168
|
|
|
|
4169
|
|
|
Returns: |
4170
|
|
|
The response. See :py:meth:`send_command` for details. |
4171
|
|
|
""" |
4172
|
|
|
if not target_id: |
4173
|
|
|
raise RequiredArgument('modify_target requires a ' |
4174
|
|
|
'target_id argument') |
4175
|
|
|
|
4176
|
|
|
cmd = XmlCommand('modify_target') |
4177
|
|
|
cmd.set_attribute('target_id', target_id) |
4178
|
|
|
|
4179
|
|
|
if comment: |
4180
|
|
|
cmd.add_element('comment', comment) |
4181
|
|
|
|
4182
|
|
|
if name: |
4183
|
|
|
cmd.add_element('name', name) |
4184
|
|
|
|
4185
|
|
|
if hosts: |
4186
|
|
|
cmd.add_element('hosts', ', '.join(hosts)) |
4187
|
|
|
|
4188
|
|
|
if hosts_ordering: |
4189
|
|
|
cmd.add_element('hosts_ordering', ', '.join(hosts_ordering)) |
4190
|
|
|
|
4191
|
|
|
if exclude_hosts: |
4192
|
|
|
cmd.add_element('exclude_hosts', ', '.join(exclude_hosts)) |
4193
|
|
|
|
4194
|
|
|
if alive_tests: |
4195
|
|
|
if not alive_tests in ALIVE_TESTS: |
4196
|
|
|
raise InvalidArgument( |
4197
|
|
|
'alive_tests must be one of {tests} but ' |
4198
|
|
|
'{actual} has been passed'.format( |
4199
|
|
|
tests='|'.join(ALIVE_TESTS), actual=alive_tests)) |
4200
|
|
|
cmd.add_element('alive_tests', alive_tests) |
4201
|
|
|
|
4202
|
|
|
if ssh_credential_id: |
4203
|
|
|
cmd.add_element('ssh_credential', attrs={'id': ssh_credential_id}) |
4204
|
|
|
|
4205
|
|
|
if smb_credential_id: |
4206
|
|
|
cmd.add_element('smb_credential', attrs={'id': smb_credential_id}) |
4207
|
|
|
|
4208
|
|
|
if esxi_credential_id: |
4209
|
|
|
cmd.add_element('esxi_credential', attrs={'id': esxi_credential_id}) |
4210
|
|
|
|
4211
|
|
|
if snmp_credential_id: |
4212
|
|
|
cmd.add_element('snmp_credential', attrs={'id': snmp_credential_id}) |
4213
|
|
|
|
4214
|
|
|
if not reverse_lookup_only is None: |
4215
|
|
|
if reverse_lookup_only: |
4216
|
|
|
cmd.add_element('reverse_lookup_only', '1') |
4217
|
|
|
else: |
4218
|
|
|
cmd.add_element('reverse_lookup_only', '0') |
4219
|
|
|
|
4220
|
|
|
if not reverse_lookup_unify is None: |
4221
|
|
|
if reverse_lookup_unify: |
4222
|
|
|
cmd.add_element('reverse_lookup_unify', '1') |
4223
|
|
|
else: |
4224
|
|
|
cmd.add_element('reverse_lookup_unify', '0') |
4225
|
|
|
|
4226
|
|
|
if port_list_id: |
4227
|
|
|
cmd.add_element('port_list', attrs={'id': port_list_id}) |
4228
|
|
|
|
4229
|
|
|
return self._send_xml_command(cmd) |
4230
|
|
|
|
4231
|
|
|
def modify_task(self, task_id, *, name=None, comment=None, alert=None, |
|
|
|
|
4232
|
|
|
observers=None, preferences=None, schedule=None, |
4233
|
|
|
schedule_periods=None, scanner=None, file_name=None, |
4234
|
|
|
file_action=None): |
4235
|
|
|
"""Modifies an existing task. |
4236
|
|
|
|
4237
|
|
|
Arguments: |
4238
|
|
|
task_id (str) UUID of task to modify. |
4239
|
|
|
comment (str, optional):The comment on the task. |
4240
|
|
|
alert (str, optional): UUID of Task alert. |
4241
|
|
|
name (str, optional): The name of the task. |
4242
|
|
|
observers (list, optional): Users allowed to observe this task. |
4243
|
|
|
preferences (dict, optional): Compact name of preference, from |
4244
|
|
|
scanner and its value |
4245
|
|
|
schedule (str, optional): UUID of Task schedule. |
4246
|
|
|
schedule_periods (int, optional): A limit to the number of times |
4247
|
|
|
the task will be scheduled, or 0 for no limit. |
4248
|
|
|
scanner (str, optional): UUID of Task scanner. |
4249
|
|
|
file_name (str, optional): File to attach to task. |
4250
|
|
|
file_action (str, optional): Action for the file: |
4251
|
|
|
one of "update" or "remove" |
4252
|
|
|
|
4253
|
|
|
Returns: |
4254
|
|
|
The response. See :py:meth:`send_command` for details. |
4255
|
|
|
""" |
4256
|
|
|
if not task_id: |
4257
|
|
|
raise RequiredArgument('modify_task requires a task_id argument') |
4258
|
|
|
|
4259
|
|
|
cmd = XmlCommand('modify_task') |
4260
|
|
|
cmd.set_attribute('task_id', task_id) |
4261
|
|
|
|
4262
|
|
|
if name: |
4263
|
|
|
cmd.add_element('name', name) |
4264
|
|
|
|
4265
|
|
|
if comment: |
4266
|
|
|
cmd.add_element('comment', comment) |
4267
|
|
|
|
4268
|
|
|
if scanner: |
4269
|
|
|
cmd.add_element('scanner', attrs={'id': scanner}) |
4270
|
|
|
|
4271
|
|
|
if schedule_periods: |
4272
|
|
|
cmd.add_element('schedule_periods', str(schedule_periods)) |
4273
|
|
|
|
4274
|
|
|
if schedule: |
4275
|
|
|
cmd.add_element('schedule', attrs={'id': schedule}) |
4276
|
|
|
|
4277
|
|
|
if alert: |
4278
|
|
|
cmd.add_element('alert', attrs={'id': alert}) |
4279
|
|
|
|
4280
|
|
|
if observers: |
4281
|
|
|
cmd.add_element('observers', ', '.join(observers)) |
4282
|
|
|
|
4283
|
|
|
if preferences: |
4284
|
|
|
_xmlprefs = cmd.add_element('preferences') |
4285
|
|
|
for pref_name, pref_value in preferences.items(): |
4286
|
|
|
_xmlpref = _xmlprefs.add_element('preference') |
4287
|
|
|
_xmlpref.add_element('scanner_name', pref_name) |
4288
|
|
|
_xmlpref.add_element('value', pref_value) |
4289
|
|
|
|
4290
|
|
|
if file_name and file_action: |
4291
|
|
|
if file_action not in ('update', 'remove'): |
4292
|
|
|
raise InvalidArgument('action can only be ' |
4293
|
|
|
'"update" or "remove"!') |
4294
|
|
|
cmd.add_element('file', attrs={'name': file_name, |
4295
|
|
|
'action': file_action}) |
4296
|
|
|
|
4297
|
|
|
return self._send_xml_command(cmd) |
4298
|
|
|
|
4299
|
|
|
def modify_user(self, user_id, name, *, new_name=None, password=None, |
4300
|
|
|
role_ids=None, hosts=None, hosts_allow=None, |
4301
|
|
|
ifaces=None, ifaces_allow=None, sources=None): |
4302
|
|
|
"""Modifies an existing user. |
4303
|
|
|
|
4304
|
|
|
Arguments: |
4305
|
|
|
user_id (str): UUID of the user to be modified. Overrides |
4306
|
|
|
NAME element. |
4307
|
|
|
name (str): The name of the user to be modified. |
4308
|
|
|
new_name (str, optional): The new name for the user. |
4309
|
|
|
password (str, optional): The password for the user. |
4310
|
|
|
roles_id (list, optional): List of roles UUIDs for the user. |
4311
|
|
|
hosts (list, optional): User access rules: List of hosts. |
4312
|
|
|
hosts_allow (boolean,optional): If True, allow only listed, |
4313
|
|
|
otherwise forbid listed. |
4314
|
|
|
ifaces (list, optional): User access rules: List |
4315
|
|
|
of ifaces. |
4316
|
|
|
ifaces_allow (boolean, optional): If True, allow only listed, |
4317
|
|
|
otherwise forbid listed. |
4318
|
|
|
sources (list, optional): List of authentication sources for |
4319
|
|
|
this user. |
4320
|
|
|
|
4321
|
|
|
Returns: |
4322
|
|
|
The response. See :py:meth:`send_command` for details. |
4323
|
|
|
""" |
4324
|
|
|
if not user_id: |
4325
|
|
|
raise RequiredArgument('modify_user requires a user_id argument') |
4326
|
|
|
|
4327
|
|
|
if not name: |
4328
|
|
|
raise RequiredArgument('modify_user requires a name argument') |
4329
|
|
|
|
4330
|
|
|
cmd = XmlCommand('modify_user') |
4331
|
|
|
cmd.set_attribute('user_id', user_id) |
4332
|
|
|
|
4333
|
|
|
if new_name: |
4334
|
|
|
cmd.add_element('new_name', new_name) |
4335
|
|
|
|
4336
|
|
|
if password: |
4337
|
|
|
cmd.add_element('password', password) |
4338
|
|
|
|
4339
|
|
|
if role_ids: |
4340
|
|
|
for role in role_ids: |
4341
|
|
|
cmd.add_element('role', attrs={'id': role}) |
4342
|
|
|
|
4343
|
|
|
if hosts or hosts_allow: |
4344
|
|
|
cmd.add_element('hosts', ', '.join(hosts), |
4345
|
|
|
attrs={'allow': '1' if hosts_allow else '0'}) |
4346
|
|
|
|
4347
|
|
|
if ifaces or ifaces_allow: |
4348
|
|
|
cmd.add_element('ifaces', ', '.join(ifaces), |
4349
|
|
|
attrs={'allow': '1' if ifaces_allow else '0'}) |
4350
|
|
|
|
4351
|
|
|
if sources: |
4352
|
|
|
cmd.add_element('sources', ', '.join(sources)) |
4353
|
|
|
|
4354
|
|
|
return self._send_xml_command(cmd) |
4355
|
|
|
|
4356
|
|
|
def move_task(self, task_id, *, slave_id=None): |
4357
|
|
|
"""Move an existing task to another GMP slave scanner or the master |
4358
|
|
|
|
4359
|
|
|
Arguments: |
4360
|
|
|
task_id (str): UUID of the task to be moved |
4361
|
|
|
slave_id (str, optional): UUID of slave to reassign the task to, |
4362
|
|
|
empty for master. |
4363
|
|
|
|
4364
|
|
|
Returns: |
4365
|
|
|
The response. See :py:meth:`send_command` for details. |
4366
|
|
|
""" |
4367
|
|
|
if not task_id: |
4368
|
|
|
raise InvalidArgument('move_task requires an task_id argument') |
4369
|
|
|
|
4370
|
|
|
cmd = XmlCommand('move_task') |
4371
|
|
|
cmd.set_attribute('task_id', task_id) |
4372
|
|
|
|
4373
|
|
|
if not slave_id is None: |
4374
|
|
|
cmd.set_attribute('slave_id', slave_id) |
4375
|
|
|
|
4376
|
|
|
return self._send_xml_command(cmd) |
4377
|
|
|
|
4378
|
|
|
def restore(self, entity_id): |
4379
|
|
|
"""Restore an entity from the trashcan |
4380
|
|
|
|
4381
|
|
|
Arguments: |
4382
|
|
|
entity_id (str): ID of the entity to be restored from the trashcan |
4383
|
|
|
|
4384
|
|
|
Returns: |
4385
|
|
|
The response. See :py:meth:`send_command` for details. |
4386
|
|
|
""" |
4387
|
|
|
if not entity_id: |
4388
|
|
|
raise InvalidArgument('restore requires an entity_id argument') |
4389
|
|
|
|
4390
|
|
|
cmd = XmlCommand('restore') |
4391
|
|
|
cmd.set_attribute('id', entity_id) |
4392
|
|
|
|
4393
|
|
|
return self._send_xml_command(cmd) |
4394
|
|
|
|
4395
|
|
|
def resume_task(self, task_id): |
4396
|
|
|
"""Resume an existing stopped task |
4397
|
|
|
|
4398
|
|
|
Arguments: |
4399
|
|
|
task_id (str): UUID of the task to be resumed |
4400
|
|
|
|
4401
|
|
|
Returns: |
4402
|
|
|
The response. See :py:meth:`send_command` for details. |
4403
|
|
|
""" |
4404
|
|
|
if not task_id: |
4405
|
|
|
raise InvalidArgument('resume_task requires an task_id argument') |
4406
|
|
|
|
4407
|
|
|
cmd = XmlCommand('resume_task') |
4408
|
|
|
cmd.set_attribute('task_id', task_id) |
4409
|
|
|
|
4410
|
|
|
return self._send_xml_command(cmd) |
4411
|
|
|
|
4412
|
|
|
def start_task(self, task_id): |
4413
|
|
|
"""Start an existing task |
4414
|
|
|
|
4415
|
|
|
Arguments: |
4416
|
|
|
task_id (str): UUID of the task to be started |
4417
|
|
|
|
4418
|
|
|
Returns: |
4419
|
|
|
The response. See :py:meth:`send_command` for details. |
4420
|
|
|
""" |
4421
|
|
|
if not task_id: |
4422
|
|
|
raise InvalidArgument('start_task requires an task_id argument') |
4423
|
|
|
|
4424
|
|
|
cmd = XmlCommand('start_task') |
4425
|
|
|
cmd.set_attribute('task_id', task_id) |
4426
|
|
|
|
4427
|
|
|
return self._send_xml_command(cmd) |
4428
|
|
|
|
4429
|
|
|
def stop_task(self, task_id): |
4430
|
|
|
"""Stop an existing running task |
4431
|
|
|
|
4432
|
|
|
Arguments: |
4433
|
|
|
task_id (str): UUID of the task to be stopped |
4434
|
|
|
|
4435
|
|
|
Returns: |
4436
|
|
|
The response. See :py:meth:`send_command` for details. |
4437
|
|
|
""" |
4438
|
|
|
if not task_id: |
4439
|
|
|
raise InvalidArgument('stop_task requires an task_id argument') |
4440
|
|
|
|
4441
|
|
|
cmd = XmlCommand('stop_task') |
4442
|
|
|
cmd.set_attribute('task_id', task_id) |
4443
|
|
|
|
4444
|
|
|
return self._send_xml_command(cmd) |
4445
|
|
|
|
4446
|
|
|
def sync_cert(self): |
4447
|
|
|
"""Request a synchronization with the CERT feed service |
4448
|
|
|
|
4449
|
|
|
Returns: |
4450
|
|
|
The response. See :py:meth:`send_command` for details. |
4451
|
|
|
""" |
4452
|
|
|
return self._send_xml_command(XmlCommand('sync_cert')) |
4453
|
|
|
|
4454
|
|
|
def sync_config(self): |
4455
|
|
|
"""Request an OSP config synchronization with scanner |
4456
|
|
|
|
4457
|
|
|
Returns: |
4458
|
|
|
The response. See :py:meth:`send_command` for details. |
4459
|
|
|
""" |
4460
|
|
|
return self._send_xml_command(XmlCommand('sync_config')) |
4461
|
|
|
|
4462
|
|
|
def sync_feed(self): |
4463
|
|
|
"""Request a synchronization with the NVT feed service |
4464
|
|
|
|
4465
|
|
|
Returns: |
4466
|
|
|
The response. See :py:meth:`send_command` for details. |
4467
|
|
|
""" |
4468
|
|
|
return self._send_xml_command(XmlCommand('sync_feed')) |
4469
|
|
|
|
4470
|
|
|
def sync_scap(self): |
4471
|
|
|
"""Request a synchronization with the SCAP feed service |
4472
|
|
|
|
4473
|
|
|
Returns: |
4474
|
|
|
The response. See :py:meth:`send_command` for details. |
4475
|
|
|
""" |
4476
|
|
|
return self._send_xml_command(XmlCommand('sync_scap')) |
4477
|
|
|
|
4478
|
|
|
def test_alert(self, alert_id): |
4479
|
|
|
"""Run an alert |
4480
|
|
|
|
4481
|
|
|
Invoke a test run of an alert |
4482
|
|
|
|
4483
|
|
|
Arguments: |
4484
|
|
|
alert_id (str): UUID of the alert to be tested |
4485
|
|
|
|
4486
|
|
|
Returns: |
4487
|
|
|
The response. See :py:meth:`send_command` for details. |
4488
|
|
|
""" |
4489
|
|
|
if not alert_id: |
4490
|
|
|
raise InvalidArgument('test_alert requires an alert_id argument') |
4491
|
|
|
|
4492
|
|
|
cmd = XmlCommand('test_alert') |
4493
|
|
|
cmd.set_attribute('alert_id', alert_id) |
4494
|
|
|
|
4495
|
|
|
return self._send_xml_command(cmd) |
4496
|
|
|
|
4497
|
|
|
def trigger_alert(self, alert_id, report_id, *, filter=None, filter_id=None, |
4498
|
|
|
report_format_id=None, delta_report_id=None): |
4499
|
|
|
"""Run an alert by ignoring its event and conditions |
4500
|
|
|
|
4501
|
|
|
The alert is triggered to run immediately with the provided filtered |
4502
|
|
|
report by ignoring the even and condition settings. |
4503
|
|
|
|
4504
|
|
|
Arguments: |
4505
|
|
|
alert_id (str): UUID of the alert to be run |
4506
|
|
|
report_id (str): UUID of the report to be provided to the alert |
4507
|
|
|
filter (str, optional): Filter term to use to filter results in the |
4508
|
|
|
report |
4509
|
|
|
filter_id (str, optional): UUID of filter to use to filter results |
4510
|
|
|
in the report |
4511
|
|
|
report_format_id (str, optional): UUID of report format to use |
4512
|
|
|
delta_report_id (str, optional): UUID of an existing report to |
4513
|
|
|
compare report to. |
4514
|
|
|
|
4515
|
|
|
Returns: |
4516
|
|
|
The response. See :py:meth:`send_command` for details. |
4517
|
|
|
""" |
4518
|
|
|
if not alert_id: |
4519
|
|
|
raise RequiredArgument('run_alert requires a alert_id argument') |
4520
|
|
|
|
4521
|
|
|
if not report_id: |
4522
|
|
|
raise RequiredArgument('run_alert requires a report_id argument') |
4523
|
|
|
|
4524
|
|
|
cmd = XmlCommand('get_reports') |
4525
|
|
|
cmd.set_attribute('report_id', report_id) |
4526
|
|
|
cmd.set_attribute('alert_id', alert_id) |
4527
|
|
|
|
4528
|
|
|
if filter: |
4529
|
|
|
cmd.set_attribute('filter', filter) |
4530
|
|
|
|
4531
|
|
|
if filter_id: |
4532
|
|
|
cmd.set_attribute('filt_id', filter_id) |
4533
|
|
|
|
4534
|
|
|
if report_format_id: |
4535
|
|
|
cmd.set_attribute('format_id', report_format_id) |
4536
|
|
|
|
4537
|
|
|
if delta_report_id: |
4538
|
|
|
cmd.set_attribute('delta_report_id', delta_report_id) |
4539
|
|
|
|
4540
|
|
|
return self._send_xml_command(cmd) |
4541
|
|
|
|
4542
|
|
|
def verify_agent(self, agent_id): |
4543
|
|
|
"""Verify an existing agent |
4544
|
|
|
|
4545
|
|
|
Verifies the trust level of an existing agent. It will be checked |
4546
|
|
|
whether signature of the agent currently matches the agent. This |
4547
|
|
|
includes the agent installer file. It is *not* verified if the agent |
4548
|
|
|
works as expected by the user. |
4549
|
|
|
|
4550
|
|
|
Arguments: |
4551
|
|
|
agent_id (str): UUID of the agent to be verified |
4552
|
|
|
|
4553
|
|
|
Returns: |
4554
|
|
|
The response. See :py:meth:`send_command` for details. |
4555
|
|
|
""" |
4556
|
|
|
if not agent_id: |
4557
|
|
|
raise InvalidArgument('verify_agent requires an agent_id argument') |
4558
|
|
|
|
4559
|
|
|
cmd = XmlCommand('verify_agent') |
4560
|
|
|
cmd.set_attribute('agent_id', agent_id) |
4561
|
|
|
|
4562
|
|
|
return self._send_xml_command(cmd) |
4563
|
|
|
|
4564
|
|
|
def verify_report_format(self, report_format_id): |
4565
|
|
|
"""Verify an existing report format |
4566
|
|
|
|
4567
|
|
|
Verifies the trust level of an existing report format. It will be |
4568
|
|
|
checked whether the signature of the report format currently matches the |
4569
|
|
|
report format. This includes the script and files used to generate |
4570
|
|
|
reports of this format. It is *not* verified if the report format works |
4571
|
|
|
as expected by the user. |
4572
|
|
|
|
4573
|
|
|
Arguments: |
4574
|
|
|
report_format_id (str): UUID of the report format to be verified |
4575
|
|
|
|
4576
|
|
|
Returns: |
4577
|
|
|
The response. See :py:meth:`send_command` for details. |
4578
|
|
|
""" |
4579
|
|
|
if not report_format_id: |
4580
|
|
|
raise InvalidArgument( |
4581
|
|
|
'verify_report_format requires a report_format_id argument') |
4582
|
|
|
|
4583
|
|
|
cmd = XmlCommand('verify_report_format') |
4584
|
|
|
cmd.set_attribute('report_format_id', report_format_id) |
4585
|
|
|
|
4586
|
|
|
return self._send_xml_command(cmd) |
4587
|
|
|
|
4588
|
|
|
def verify_scanner(self, scanner_id): |
4589
|
|
|
"""Verify an existing scanner |
4590
|
|
|
|
4591
|
|
|
Verifies if it is possible to connect to an existing scanner. It is |
4592
|
|
|
*not* verified if the scanner works as expected by the user. |
4593
|
|
|
|
4594
|
|
|
Arguments: |
4595
|
|
|
scanner_id (str): UUID of the scanner to be verified |
4596
|
|
|
|
4597
|
|
|
Returns: |
4598
|
|
|
The response. See :py:meth:`send_command` for details. |
4599
|
|
|
""" |
4600
|
|
|
if not scanner_id: |
4601
|
|
|
raise InvalidArgument( |
4602
|
|
|
'verify_scanner requires a scanner_id argument') |
4603
|
|
|
|
4604
|
|
|
cmd = XmlCommand('verify_scanner') |
4605
|
|
|
cmd.set_attribute('scanner_id', scanner_id) |
4606
|
|
|
|
4607
|
|
|
return self._send_xml_command(cmd) |
4608
|
|
|
|