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 |
20
|
|
|
""" |
21
|
|
|
Module for communication with gvmd in Greenbone Management Protocol version 7 |
22
|
|
|
""" |
23
|
|
|
import logging |
24
|
|
|
|
25
|
|
|
from lxml import etree |
26
|
|
|
|
27
|
|
|
from gvm.errors import InvalidArgument, RequiredArgument |
28
|
|
|
from gvm.utils import get_version_string |
29
|
|
|
from gvm.xml import _GmpCommandFactory as GmpCommandFactory, XmlCommand |
30
|
|
|
|
31
|
|
|
from .base import GvmProtocol |
32
|
|
|
|
33
|
|
|
logger = logging.getLogger(__name__) |
34
|
|
|
|
35
|
|
|
PROTOCOL_VERSION = (7,) |
36
|
|
|
|
37
|
|
|
FILTER_TYPES = [ |
38
|
|
|
'agent', |
39
|
|
|
'alert', |
40
|
|
|
'asset', |
41
|
|
|
'config', |
42
|
|
|
'credential', |
43
|
|
|
'filter', |
44
|
|
|
'group', |
45
|
|
|
'note', |
46
|
|
|
'override', |
47
|
|
|
'permission', |
48
|
|
|
'port_list', |
49
|
|
|
'report', |
50
|
|
|
'report_format', |
51
|
|
|
'result', |
52
|
|
|
'role', |
53
|
|
|
'schedule', |
54
|
|
|
'secinfo', |
55
|
|
|
'tag', |
56
|
|
|
'target', |
57
|
|
|
'task', |
58
|
|
|
'user', |
59
|
|
|
] |
60
|
|
|
|
61
|
|
|
TIME_UNITS = [ |
62
|
|
|
'second', |
63
|
|
|
'minute', |
64
|
|
|
'hour', |
65
|
|
|
'day', |
66
|
|
|
'week', |
67
|
|
|
'month', |
68
|
|
|
'year', |
69
|
|
|
'decade', |
70
|
|
|
] |
71
|
|
|
|
72
|
|
|
|
73
|
|
|
def _check_command_status(xml): |
74
|
|
|
"""Check gmp response |
75
|
|
|
|
76
|
|
|
Look into the gmp response and check for the status in the root element |
77
|
|
|
|
78
|
|
|
Arguments: |
79
|
|
|
xml {string} -- XML-Source |
80
|
|
|
|
81
|
|
|
Returns: |
82
|
|
|
bool -- True if valid, otherwise False |
83
|
|
|
""" |
84
|
|
|
|
85
|
|
|
if xml is 0 or xml is None: |
86
|
|
|
logger.error('XML Command is empty') |
87
|
|
|
return False |
88
|
|
|
|
89
|
|
|
try: |
90
|
|
|
parser = etree.XMLParser(encoding='utf-8', recover=True) |
91
|
|
|
|
92
|
|
|
root = etree.XML(xml, parser=parser) |
93
|
|
|
status = root.attrib['status'] |
94
|
|
|
return status is not None and status[0] == '2' |
95
|
|
|
|
96
|
|
|
except etree.Error as e: |
97
|
|
|
logger.error('etree.XML(xml): %s', e) |
98
|
|
|
return False |
99
|
|
|
|
100
|
|
|
|
101
|
|
|
class Gmp(GvmProtocol): |
|
|
|
|
102
|
|
|
"""Python interface for Greenbone Management Protocol |
103
|
|
|
|
104
|
|
|
This class implements the `Greenbone Management Protocol version 7`_ |
105
|
|
|
|
106
|
|
|
Attributes: |
107
|
|
|
connection (:class:`gvm.connections.GvmConnection`): Connection to use |
108
|
|
|
to talk with the gvmd daemon. See :mod:`gvm.connections` for |
109
|
|
|
possible connection types. |
110
|
|
|
transform (`callable`_, optional): Optional transform callable to |
111
|
|
|
convert response data. After each request the callable gets passed |
112
|
|
|
the plain response data which can be used to check the data and/or |
113
|
|
|
conversion into different representaitions like a xml dom. |
114
|
|
|
|
115
|
|
|
See :mod:`gvm.transforms` for existing transforms. |
116
|
|
|
|
117
|
|
|
.. _Greenbone Management Protocol version 7: |
118
|
|
|
https://docs.greenbone.net/API/GMP/gmp-7.0.html |
119
|
|
|
.. _callable: |
120
|
|
|
https://docs.python.org/3.6/library/functions.html#callable |
121
|
|
|
""" |
122
|
|
|
|
123
|
|
|
def __init__(self, connection, transform=None): |
124
|
|
|
super().__init__(connection, transform) |
125
|
|
|
|
126
|
|
|
# Is authenticated on gvmd |
127
|
|
|
self._authenticated = False |
128
|
|
|
|
129
|
|
|
# GMP Message Creator |
130
|
|
|
self._generator = GmpCommandFactory() |
131
|
|
|
|
132
|
|
|
@staticmethod |
133
|
|
|
def get_protocol_version(): |
134
|
|
|
"""Allow to determine the Greenbone Management Protocol version. |
135
|
|
|
|
136
|
|
|
Returns: |
137
|
|
|
str: Implemented version of the Greenbone Management Protocol |
138
|
|
|
""" |
139
|
|
|
return get_version_string(PROTOCOL_VERSION) |
140
|
|
|
|
141
|
|
|
def is_authenticated(self): |
142
|
|
|
"""Checks if the user is authenticated |
143
|
|
|
|
144
|
|
|
If the user is authenticated privilged GMP commands like get_tasks |
145
|
|
|
may be send to gvmd. |
146
|
|
|
|
147
|
|
|
Returns: |
148
|
|
|
bool: True if an authenticated connection to gvmd has been |
149
|
|
|
established. |
150
|
|
|
""" |
151
|
|
|
return self._authenticated |
152
|
|
|
|
153
|
|
|
def authenticate(self, username, password): |
154
|
|
|
"""Authenticate to gvmd. |
155
|
|
|
|
156
|
|
|
The generated authenticate command will be send to server. |
157
|
|
|
Afterwards the response is read, transformed and returned. |
158
|
|
|
|
159
|
|
|
Arguments: |
160
|
|
|
username (str): Username |
161
|
|
|
password (str): Password |
162
|
|
|
|
163
|
|
|
Returns: |
164
|
|
|
any, str by default: Transformed response from server. |
165
|
|
|
""" |
166
|
|
|
cmd = XmlCommand('authenticate') |
167
|
|
|
|
168
|
|
|
if not username: |
169
|
|
|
raise RequiredArgument('authenticate requires username') |
170
|
|
|
|
171
|
|
|
if not password: |
172
|
|
|
raise RequiredArgument('authenticate requires password') |
173
|
|
|
|
174
|
|
|
credentials = cmd.add_element('credentials') |
175
|
|
|
credentials.add_element('username', username) |
176
|
|
|
credentials.add_element('password', password) |
177
|
|
|
|
178
|
|
|
self._send(cmd.to_string()) |
179
|
|
|
response = self._read() |
180
|
|
|
|
181
|
|
|
if _check_command_status(response): |
182
|
|
|
self._authenticated = True |
183
|
|
|
|
184
|
|
|
return self._transform(response) |
185
|
|
|
|
186
|
|
|
def create_agent(self, installer, signature, name, comment=None, |
187
|
|
|
howto_install=None, howto_use=None): |
188
|
|
|
"""Create a new agent |
189
|
|
|
|
190
|
|
|
Arguments: |
191
|
|
|
installer (str): A base64 encoded file that installs the agent on a |
192
|
|
|
target machine |
193
|
|
|
signature: (str): A detached OpenPGP signature of the installer |
194
|
|
|
name (str): A name for the agent |
195
|
|
|
comment (str, optional): A comment for the agent |
196
|
|
|
howto_install (str, optional): A file that describes how to install |
197
|
|
|
the agent |
198
|
|
|
howto_use (str, optional): A file that describes how to use the |
199
|
|
|
agent |
200
|
|
|
|
201
|
|
|
Returns: |
202
|
|
|
The response. See :py:meth:`send_command` for details. |
203
|
|
|
""" |
204
|
|
|
if not name: |
205
|
|
|
raise RequiredArgument('create_agent requires name argument') |
206
|
|
|
|
207
|
|
|
if not installer: |
208
|
|
|
raise RequiredArgument('create_agent requires installer argument') |
209
|
|
|
|
210
|
|
|
if not signature: |
211
|
|
|
raise RequiredArgument('create_agent requires signature argument') |
212
|
|
|
|
213
|
|
|
cmd = XmlCommand('create_agent') |
214
|
|
|
cmd.add_element('installer', installer) |
215
|
|
|
cmd.add_element('signature', signature) |
216
|
|
|
cmd.add_element('name', name) |
217
|
|
|
|
218
|
|
|
if comment: |
219
|
|
|
cmd.add_element('comment', comment) |
220
|
|
|
|
221
|
|
|
if howto_install: |
222
|
|
|
cmd.add_element('howto_install', howto_install) |
223
|
|
|
|
224
|
|
|
if howto_use: |
225
|
|
|
cmd.add_element('howto_use', howto_use) |
226
|
|
|
|
227
|
|
|
return self._send_xml_command(cmd) |
228
|
|
|
|
229
|
|
|
def clone_agent(self, agent_id): |
230
|
|
|
"""Clone an existing agent |
231
|
|
|
|
232
|
|
|
Arguments: |
233
|
|
|
copy (str): UUID of an existing agent to clone from |
234
|
|
|
|
235
|
|
|
Returns: |
236
|
|
|
The response. See :py:meth:`send_command` for details. |
237
|
|
|
""" |
238
|
|
|
cmd = XmlCommand('create_agent') |
239
|
|
|
cmd.add_element('copy', agent_id) |
240
|
|
|
return self._send_xml_command(cmd) |
241
|
|
|
|
242
|
|
|
def create_alert(self, name, condition, event, method, method_data=None, |
|
|
|
|
243
|
|
|
event_data=None, condition_data=None, filter_id=None, |
244
|
|
|
comment=None): |
245
|
|
|
"""Create a new alert |
246
|
|
|
|
247
|
|
|
Arguments: |
248
|
|
|
name (str): Name of the new Alert |
249
|
|
|
condition (str): The condition that must be satisfied for the alert |
250
|
|
|
to occur. |
251
|
|
|
event (str): The event that must happen for the alert to occur |
252
|
|
|
method (str): The method by which the user is alerted |
253
|
|
|
condition_data (dict, optional): Data that defines the condition |
254
|
|
|
event_data (dict, optional): Data that defines the event |
255
|
|
|
method_data (dict, optional): Data that defines the method |
256
|
|
|
filter_id (str, optional): Filter to apply when executing alert |
257
|
|
|
comment (str, optional): Comment for the alert |
258
|
|
|
|
259
|
|
|
Returns: |
260
|
|
|
The response. See :py:meth:`send_command` for details. |
261
|
|
|
""" |
262
|
|
|
if not name: |
263
|
|
|
raise RequiredArgument('create_alert requires name argument') |
264
|
|
|
|
265
|
|
|
if condition is None or len(condition) == 0: |
266
|
|
|
raise RequiredArgument('create_alert requires condition argument') |
267
|
|
|
|
268
|
|
|
if event is None or len(event) == 0: |
269
|
|
|
raise RequiredArgument('create_alert requires event argument') |
270
|
|
|
|
271
|
|
|
cmd = XmlCommand('create_alert') |
272
|
|
|
cmd.add_element('name', name) |
273
|
|
|
|
274
|
|
|
conditions = cmd.add_element('condition', condition) |
275
|
|
|
|
276
|
|
|
if not condition_data is None: |
277
|
|
|
for value, key in condition_data.items(): |
278
|
|
|
_data = conditions.add_element('data', value) |
279
|
|
|
_data.add_element('name', key) |
280
|
|
|
|
281
|
|
|
events = cmd.add_element('event', event) |
282
|
|
|
|
283
|
|
|
if not event_data is None: |
284
|
|
|
for value, key in event_data.items(): |
285
|
|
|
_data = events.add_element('data', value) |
286
|
|
|
_data.add_element('name', key) |
287
|
|
|
|
288
|
|
|
methods = cmd.add_element('method', method) |
289
|
|
|
|
290
|
|
|
if not method_data is None: |
291
|
|
|
for value, key in method_data.items(): |
292
|
|
|
_data = methods.add_element('data', value) |
293
|
|
|
_data.add_element('name', key) |
294
|
|
|
|
295
|
|
|
if filter_id: |
296
|
|
|
cmd.add_element('filter', attrs={'id': filter_id}) |
297
|
|
|
|
298
|
|
|
if comment: |
299
|
|
|
cmd.add_element('comment', comment) |
300
|
|
|
|
301
|
|
|
return self._send_xml_command(cmd) |
302
|
|
|
|
303
|
|
|
def clone_alert(self, alert_id): |
304
|
|
|
"""Clone an existing alert |
305
|
|
|
|
306
|
|
|
Arguments: |
307
|
|
|
copy (str): UUID of an existing alert to clone from |
308
|
|
|
|
309
|
|
|
Returns: |
310
|
|
|
The response. See :py:meth:`send_command` for details. |
311
|
|
|
""" |
312
|
|
|
cmd = XmlCommand('create_alert') |
313
|
|
|
cmd.add_element('copy', alert_id) |
314
|
|
|
return self._send_xml_command(cmd) |
315
|
|
|
|
316
|
|
|
def create_asset(self, name, asset_type, comment=None): |
317
|
|
|
"""Create a new asset |
318
|
|
|
|
319
|
|
|
Arguments: |
320
|
|
|
name (str): Name for the new asset |
321
|
|
|
asset_type (str): Either 'os' or 'host' |
322
|
|
|
comment (str, optional): Comment for the new asset |
323
|
|
|
|
324
|
|
|
Returns: |
325
|
|
|
The response. See :py:meth:`send_command` for details. |
326
|
|
|
""" |
327
|
|
|
if asset_type not in ('host', 'os'): |
328
|
|
|
raise InvalidArgument( |
329
|
|
|
'create_asset requires asset_type to be either host or os') |
330
|
|
|
|
331
|
|
|
if not name: |
332
|
|
|
raise RequiredArgument('create_asset requires name argument') |
333
|
|
|
|
334
|
|
|
cmd = XmlCommand('create_asset') |
335
|
|
|
asset = cmd.add_element('asset') |
336
|
|
|
asset.add_element('type', asset_type) |
337
|
|
|
asset.add_element('name', name) |
338
|
|
|
|
339
|
|
|
if comment: |
340
|
|
|
asset.add_element('comment', comment) |
341
|
|
|
|
342
|
|
|
return self._send_xml_command(cmd) |
343
|
|
|
|
344
|
|
|
def create_config(self, name, copy): |
345
|
|
|
"""Create a new scan config from an existing one |
346
|
|
|
|
347
|
|
|
Arguments: |
348
|
|
|
name (str): Name of the new scan config |
349
|
|
|
copy (str): UUID of the existing scan config |
350
|
|
|
|
351
|
|
|
Returns: |
352
|
|
|
The response. See :py:meth:`send_command` for details. |
353
|
|
|
""" |
354
|
|
|
if not name: |
355
|
|
|
raise RequiredArgument('create_config requires name argument') |
356
|
|
|
|
357
|
|
|
if not copy: |
358
|
|
|
raise RequiredArgument('create_config requires copy argument') |
359
|
|
|
|
360
|
|
|
cmd = XmlCommand('create_config') |
361
|
|
|
cmd.add_element('copy', copy) |
362
|
|
|
cmd.add_element('name', name) |
363
|
|
|
return self._send_xml_command(cmd) |
364
|
|
|
|
365
|
|
|
def create_credential(self, name, comment=None, allow_insecure=False, |
|
|
|
|
366
|
|
|
certificate=None, key_phrase=None, private_key=None, |
367
|
|
|
login=None, password=None, auth_algorithm=None, |
368
|
|
|
community=None, privacy_algorithm=None, |
369
|
|
|
privacy_password=None, credential_type=None): |
370
|
|
|
"""Create a new credential |
371
|
|
|
|
372
|
|
|
Arguments: |
373
|
|
|
name (str): Name of the new credential |
374
|
|
|
comment (str, optional): Comment for the credential |
375
|
|
|
allow_insecure (boolean, optional): Whether to allow insecure use of |
376
|
|
|
the credential |
377
|
|
|
certificate (str, optional): Certificate for the credential |
378
|
|
|
key_phrase (str, optional): Key passphrase for the private key |
379
|
|
|
private_key (str, optional): Private key to use for login |
380
|
|
|
login (str, optional): Username for the credential |
381
|
|
|
password (str, optional): Password for the credential |
382
|
|
|
community (str, optional): The SNMP community |
383
|
|
|
privacy_alogorithm (str, optional): The SNMP privacy algorithm, |
384
|
|
|
either aes or des. |
385
|
|
|
privacy_password (str, optional): The SNMP privacy password |
386
|
|
|
credential_type (str, optional): The credential type. One of 'cc', |
387
|
|
|
'snmp', 'up', 'usk' |
388
|
|
|
|
389
|
|
|
Returns: |
390
|
|
|
The response. See :py:meth:`send_command` for details. |
391
|
|
|
""" |
392
|
|
|
if not name: |
393
|
|
|
raise RequiredArgument('create_credential requires name argument') |
394
|
|
|
|
395
|
|
|
cmd = XmlCommand('create_credential') |
396
|
|
|
cmd.add_element('name', name) |
397
|
|
|
|
398
|
|
|
if comment: |
399
|
|
|
cmd.add_element('comment', comment) |
400
|
|
|
|
401
|
|
|
if allow_insecure: |
402
|
|
|
cmd.add_element('allow_insecure', '1') |
403
|
|
|
|
404
|
|
|
if certificate: |
405
|
|
|
cmd.add_element('certificate', certificate) |
406
|
|
|
|
407
|
|
|
if not key_phrase is None and private_key: |
408
|
|
|
_xmlkey = cmd.add_element('key') |
409
|
|
|
_xmlkey.add_element('phrase', key_phrase) |
410
|
|
|
_xmlkey.add_element('private', private_key) |
411
|
|
|
|
412
|
|
|
if login: |
413
|
|
|
cmd.add_element('login', login) |
414
|
|
|
|
415
|
|
|
if password: |
416
|
|
|
cmd.add_element('password', password) |
417
|
|
|
|
418
|
|
|
if auth_algorithm: |
419
|
|
|
if auth_algorithm not in ('md5', 'sha1'): |
420
|
|
|
raise InvalidArgument( |
421
|
|
|
'create_credential requires auth_algorithm to be either ' |
422
|
|
|
'md5 or sha1') |
423
|
|
|
cmd.add_element('auth_algorithm', auth_algorithm) |
424
|
|
|
|
425
|
|
|
if community: |
426
|
|
|
cmd.add_element('community', community) |
427
|
|
|
|
428
|
|
|
if privacy_algorithm and privacy_password: |
429
|
|
|
if privacy_algorithm not in ('aes', 'des'): |
430
|
|
|
raise InvalidArgument( |
431
|
|
|
'create_credential requires algorithm to be either aes or ' |
432
|
|
|
'des') |
433
|
|
|
_xmlprivacy = cmd.add_element('privacy') |
434
|
|
|
_xmlprivacy.add_element('algorithm', privacy_algorithm) |
435
|
|
|
_xmlprivacy.add_element('password', privacy_password) |
436
|
|
|
|
437
|
|
|
if credential_type: |
438
|
|
|
if credential_type not in ('cc', 'snmp', 'up', 'usk'): |
439
|
|
|
raise InvalidArgument( |
440
|
|
|
'create_credential requires type to be either cc, snmp, up ' |
441
|
|
|
' or usk') |
442
|
|
|
cmd.add_element('type', credential_type) |
443
|
|
|
|
444
|
|
|
return self._send_xml_command(cmd) |
445
|
|
|
|
446
|
|
|
def clone_credential(self, credential_id): |
447
|
|
|
"""Clone an existing credential |
448
|
|
|
|
449
|
|
|
Arguments: |
450
|
|
|
copy (str): UUID of an existing credential to clone from |
451
|
|
|
|
452
|
|
|
Returns: |
453
|
|
|
The response. See :py:meth:`send_command` for details. |
454
|
|
|
""" |
455
|
|
|
cmd = XmlCommand('create_credential') |
456
|
|
|
cmd.add_element('copy', credential_id) |
457
|
|
|
return self._send_xml_command(cmd) |
458
|
|
|
|
459
|
|
|
def create_filter(self, name, make_unique=False, filter_type=None, |
460
|
|
|
comment=None, term=None): |
461
|
|
|
"""Create a new filter |
462
|
|
|
|
463
|
|
|
Arguments: |
464
|
|
|
name (str): Name of the new filter |
465
|
|
|
make_unique (boolean, optional): |
466
|
|
|
filter_type (str, optional): Filter for entity type |
467
|
|
|
comment (str, optional): Comment for the filter |
468
|
|
|
term (str, optional): Filter term e.g. 'name=foo' |
469
|
|
|
|
470
|
|
|
Returns: |
471
|
|
|
The response. See :py:meth:`send_command` for details. |
472
|
|
|
""" |
473
|
|
|
if not name: |
474
|
|
|
raise RequiredArgument('create_filter requires a name argument') |
475
|
|
|
|
476
|
|
|
cmd = XmlCommand('create_filter') |
477
|
|
|
_xmlname = cmd.add_element('name', name) |
478
|
|
|
if make_unique: |
479
|
|
|
_xmlname.add_element('make_unique', '1') |
480
|
|
|
|
481
|
|
|
if comment: |
482
|
|
|
cmd.add_element('comment', comment) |
483
|
|
|
|
484
|
|
|
if term: |
485
|
|
|
cmd.add_element('term', term) |
486
|
|
|
|
487
|
|
|
if filter_type: |
488
|
|
|
filter_type = filter_type.lower() |
489
|
|
|
if filter_type not in FILTER_TYPES: |
490
|
|
|
raise InvalidArgument( |
491
|
|
|
'create_filter requires type to be one of {0} but ' |
492
|
|
|
'was {1}'.format(', '.join(FILTER_TYPES), filter_type)) |
493
|
|
|
cmd.add_element('type', filter_type) |
494
|
|
|
|
495
|
|
|
return self._send_xml_command(cmd) |
496
|
|
|
|
497
|
|
|
def clone_filter(self, filter_id): |
498
|
|
|
"""Clone an existing filter |
499
|
|
|
|
500
|
|
|
Arguments: |
501
|
|
|
copy (str): UUID of an existing filter to clone from |
502
|
|
|
|
503
|
|
|
Returns: |
504
|
|
|
The response. See :py:meth:`send_command` for details. |
505
|
|
|
""" |
506
|
|
|
cmd = XmlCommand('create_filter') |
507
|
|
|
cmd.add_element('copy', filter_id) |
508
|
|
|
return self._send_xml_command(cmd) |
509
|
|
|
|
510
|
|
|
def create_group(self, name, comment=None, special=False, users=None): |
511
|
|
|
"""Create a new group |
512
|
|
|
|
513
|
|
|
Arguments: |
514
|
|
|
name (str): Name of the new group |
515
|
|
|
comment (str, optional): Comment for the group |
516
|
|
|
special (boolean, optional): Create permission giving members full |
517
|
|
|
access to each other's entities |
518
|
|
|
users (list, optional): List of user names to be in the group |
519
|
|
|
|
520
|
|
|
Returns: |
521
|
|
|
The response. See :py:meth:`send_command` for details. |
522
|
|
|
""" |
523
|
|
|
if not name: |
524
|
|
|
raise RequiredArgument('create_group requires a name argument') |
525
|
|
|
|
526
|
|
|
cmd = XmlCommand('create_group') |
527
|
|
|
cmd.add_element('name', name) |
528
|
|
|
|
529
|
|
|
if comment: |
530
|
|
|
cmd.add_element('comment', comment) |
531
|
|
|
|
532
|
|
|
if special: |
533
|
|
|
_xmlspecial = cmd.add_element('specials') |
534
|
|
|
_xmlspecial.add_element('full') |
535
|
|
|
|
536
|
|
|
if users: |
537
|
|
|
cmd.add_element('users', ','.join(users)) |
538
|
|
|
|
539
|
|
|
return self._send_xml_command(cmd) |
540
|
|
|
|
541
|
|
|
def clone_group(self, group_id): |
542
|
|
|
"""Clone an existing group |
543
|
|
|
|
544
|
|
|
Arguments: |
545
|
|
|
copy (str): UUID of an existing group to clone from |
546
|
|
|
|
547
|
|
|
Returns: |
548
|
|
|
The response. See :py:meth:`send_command` for details. |
549
|
|
|
""" |
550
|
|
|
cmd = XmlCommand('create_group') |
551
|
|
|
cmd.add_element('copy', group_id) |
552
|
|
|
return self._send_xml_command(cmd) |
553
|
|
|
|
554
|
|
|
def create_note(self, text, nvt_oid, active=None, comment=None, hosts=None, |
555
|
|
|
result_id=None, severity=None, task_id=None, threat=None, |
556
|
|
|
port=None): |
557
|
|
|
"""Create a new note |
558
|
|
|
|
559
|
|
|
Arguments: |
560
|
|
|
text (str): Text of the new note |
561
|
|
|
nvt_id (str): OID of the nvt to which note applies |
562
|
|
|
active (int, optional): Seconds note will be active. -1 on |
563
|
|
|
always, 0 off |
564
|
|
|
comment (str, optional): Comment for the note |
565
|
|
|
hosts (list, optional): A list of hosts addresses |
566
|
|
|
port (str, optional): Port to which the note applies |
567
|
|
|
result_id (str, optional): UUID of a result to which note applies |
568
|
|
|
severity (decimal, optional): Severity to which note applies |
569
|
|
|
task_id (str, optional): UUID of task to which note applies |
570
|
|
|
threat (str, optional): Threat level to which note applies. Will be |
571
|
|
|
converted to severity |
572
|
|
|
|
573
|
|
|
Returns: |
574
|
|
|
The response. See :py:meth:`send_command` for details. |
575
|
|
|
""" |
576
|
|
|
if not text: |
577
|
|
|
raise RequiredArgument('create_note requires a text argument') |
578
|
|
|
|
579
|
|
|
if not nvt_oid: |
580
|
|
|
raise RequiredArgument('create_note requires a nvt_oid argument') |
581
|
|
|
|
582
|
|
|
cmd = XmlCommand('create_note') |
583
|
|
|
cmd.add_element('text', text) |
584
|
|
|
cmd.add_element('nvt', attrs={"oid": nvt_oid}) |
585
|
|
|
|
586
|
|
|
if not active is None: |
587
|
|
|
cmd.add_element('active', str(active)) |
588
|
|
|
|
589
|
|
|
if comment: |
590
|
|
|
cmd.add_element('comment', comment) |
591
|
|
|
|
592
|
|
|
if hosts: |
593
|
|
|
cmd.add_element('hosts', ', '.join(hosts)) |
594
|
|
|
|
595
|
|
|
if port: |
596
|
|
|
cmd.add_element('port', port) |
597
|
|
|
|
598
|
|
|
if result_id: |
599
|
|
|
cmd.add_element('result', attrs={'id': result_id}) |
600
|
|
|
|
601
|
|
|
if severity: |
602
|
|
|
cmd.add_element('severity', severity) |
603
|
|
|
|
604
|
|
|
if task_id: |
605
|
|
|
cmd.add_element('task', attrs={'id': task_id}) |
606
|
|
|
|
607
|
|
|
if threat: |
608
|
|
|
cmd.add_element('threat', threat) |
609
|
|
|
|
610
|
|
|
return self._send_xml_command(cmd) |
611
|
|
|
|
612
|
|
|
def clone_note(self, note_id): |
613
|
|
|
"""Clone an existing note |
614
|
|
|
|
615
|
|
|
Arguments: |
616
|
|
|
copy (str): UUID of an existing note to clone from |
617
|
|
|
|
618
|
|
|
Returns: |
619
|
|
|
The response. See :py:meth:`send_command` for details. |
620
|
|
|
""" |
621
|
|
|
cmd = XmlCommand('create_note') |
622
|
|
|
cmd.add_element('copy', note_id) |
623
|
|
|
return self._send_xml_command(cmd) |
624
|
|
|
|
625
|
|
|
def create_override(self, text, nvt_oid, active=None, hosts=None, |
626
|
|
|
port=None, result_id=None, severity=None, comment=None, |
627
|
|
|
new_severity=None, task_id=None, threat=None, |
628
|
|
|
new_threat=None): |
629
|
|
|
"""Create a new override |
630
|
|
|
|
631
|
|
|
Arguments: |
632
|
|
|
text (str): Text of the new override |
633
|
|
|
nvt_id (str): OID of the nvt to which override applies |
634
|
|
|
active (int, optional): Seconds override will be active. -1 on |
635
|
|
|
always, 0 off |
636
|
|
|
comment (str, optional): Comment for the override |
637
|
|
|
hosts (list, optional): A list of host addresses |
638
|
|
|
port (str, optional): Port ot which the override applies |
639
|
|
|
result_id (str, optional): UUID of a result to which override |
640
|
|
|
applies |
641
|
|
|
severity (decimal, optional): Severity to which override applies |
642
|
|
|
new_severity (decimal, optional): New severity for result |
643
|
|
|
task_id (str, optional): UUID of task to which override applies |
644
|
|
|
threat (str, optional): Threat level to which override applies. Will |
645
|
|
|
be converted to severity |
646
|
|
|
new_threat (str, optional): New threat level for result, will be |
647
|
|
|
converted to a new_severity |
648
|
|
|
|
649
|
|
|
Returns: |
650
|
|
|
The response. See :py:meth:`send_command` for details. |
651
|
|
|
""" |
652
|
|
|
if not text: |
653
|
|
|
raise RequiredArgument('create_override requires a text argument') |
654
|
|
|
|
655
|
|
|
if not nvt_oid: |
656
|
|
|
raise RequiredArgument('create_override requires a nvt_oid ' |
657
|
|
|
'argument') |
658
|
|
|
|
659
|
|
|
cmd = XmlCommand('create_override') |
660
|
|
|
cmd.add_element('text', text) |
661
|
|
|
cmd.add_element('nvt', attrs={'oid': nvt_oid}) |
662
|
|
|
|
663
|
|
|
if active: |
664
|
|
|
cmd.add_element('active', active) |
665
|
|
|
|
666
|
|
|
if comment: |
667
|
|
|
cmd.add_element('comment', comment) |
668
|
|
|
|
669
|
|
|
if hosts: |
670
|
|
|
cmd.add_element('hosts', ', '.join(hosts)) |
671
|
|
|
|
672
|
|
|
if port: |
673
|
|
|
cmd.add_element('port', port) |
674
|
|
|
|
675
|
|
|
if result_id: |
676
|
|
|
cmd.add_element('result', attrs={'id': result_id}) |
677
|
|
|
|
678
|
|
|
if severity: |
679
|
|
|
cmd.add_element('severity', severity) |
680
|
|
|
|
681
|
|
|
if new_severity: |
682
|
|
|
cmd.add_element('new_severity', new_severity) |
683
|
|
|
|
684
|
|
|
if task_id: |
685
|
|
|
cmd.add_element('task', attrs={'id': task_id}) |
686
|
|
|
|
687
|
|
|
if threat: |
688
|
|
|
cmd.add_element('threat', threat) |
689
|
|
|
|
690
|
|
|
if new_threat: |
691
|
|
|
cmd.add_element('new_threat', new_threat) |
692
|
|
|
|
693
|
|
|
return self._send_xml_command(cmd) |
694
|
|
|
|
695
|
|
|
def clone_override(self, override_id): |
696
|
|
|
"""Clone an existing override |
697
|
|
|
|
698
|
|
|
Arguments: |
699
|
|
|
copy (str): UUID of an existing override to clone from |
700
|
|
|
|
701
|
|
|
Returns: |
702
|
|
|
The response. See :py:meth:`send_command` for details. |
703
|
|
|
""" |
704
|
|
|
cmd = XmlCommand('create_override') |
705
|
|
|
cmd.add_element('copy', override_id) |
706
|
|
|
return self._send_xml_command(cmd) |
707
|
|
|
|
708
|
|
|
def create_permission(self, name, subject_id, subject_type, |
709
|
|
|
resource_id=None, resource_type=None, |
710
|
|
|
comment=None): |
711
|
|
|
"""Create a new permission |
712
|
|
|
|
713
|
|
|
Arguments: |
714
|
|
|
name (str): Name of the new permission |
715
|
|
|
subject_id (str): UUID of subject to whom the permission is granted |
716
|
|
|
subject_type (str): Type of the subject user, group or role |
717
|
|
|
comment (str, optional): Comment for the permission |
718
|
|
|
resource_id (str, optional): UUID of entity to which the permission |
719
|
|
|
applies |
720
|
|
|
resource_type (str, optional): Type of the resource. For Super |
721
|
|
|
permissions user, group or role |
722
|
|
|
|
723
|
|
|
Returns: |
724
|
|
|
The response. See :py:meth:`send_command` for details. |
725
|
|
|
""" |
726
|
|
|
if not name: |
727
|
|
|
raise RequiredArgument('create_permission requires a name argument') |
728
|
|
|
|
729
|
|
|
if not subject_id: |
730
|
|
|
raise RequiredArgument( |
731
|
|
|
'create_permission requires a subject_id argument') |
732
|
|
|
|
733
|
|
|
if subject_type not in ('user', 'group', 'role'): |
734
|
|
|
raise InvalidArgument( |
735
|
|
|
'create_permission requires subject_type to be either user, ' |
736
|
|
|
'group or role') |
737
|
|
|
|
738
|
|
|
cmd = XmlCommand('create_permission') |
739
|
|
|
cmd.add_element('name', name) |
740
|
|
|
|
741
|
|
|
_xmlsubject = cmd.add_element('subject', attrs={'id': subject_id}) |
742
|
|
|
_xmlsubject.add_element('type', type) |
743
|
|
|
|
744
|
|
|
if comment: |
745
|
|
|
cmd.add_element('comment', comment) |
746
|
|
|
|
747
|
|
|
if resource_id and resource_type: |
748
|
|
|
_xmlresource = cmd.add_element('resource', |
749
|
|
|
attrs={'id': resource_id}) |
750
|
|
|
_xmlresource.add_element('type', resource_type) |
751
|
|
|
|
752
|
|
|
|
753
|
|
|
return self._send_xml_command(cmd) |
754
|
|
|
|
755
|
|
|
def clone_permission(self, permission_id): |
756
|
|
|
"""Clone an existing permission |
757
|
|
|
|
758
|
|
|
Arguments: |
759
|
|
|
copy (str): UUID of an existing permission to clone from |
760
|
|
|
|
761
|
|
|
Returns: |
762
|
|
|
The response. See :py:meth:`send_command` for details. |
763
|
|
|
""" |
764
|
|
|
cmd = XmlCommand('create_permission') |
765
|
|
|
cmd.add_element('copy', permission_id) |
766
|
|
|
return self._send_xml_command(cmd) |
767
|
|
|
|
768
|
|
|
def create_port_list(self, name, port_range, comment=None): |
769
|
|
|
"""Create a new port list |
770
|
|
|
|
771
|
|
|
Arguments: |
772
|
|
|
name (str): Name of the new port list |
773
|
|
|
port_range (str): Port list ranges e.g. `"T: 1-1234"` for tcp port |
774
|
|
|
1 - 1234 |
775
|
|
|
comment (str, optional): Comment for the port list |
776
|
|
|
|
777
|
|
|
Returns: |
778
|
|
|
The response. See :py:meth:`send_command` for details. |
779
|
|
|
""" |
780
|
|
|
if not name: |
781
|
|
|
raise RequiredArgument('create_port_list requires a name argument') |
782
|
|
|
|
783
|
|
|
if not port_range: |
784
|
|
|
raise RequiredArgument( |
785
|
|
|
'create_port_list requires a port_range argument') |
786
|
|
|
|
787
|
|
|
cmd = XmlCommand('create_port_list') |
788
|
|
|
cmd.add_element('name', name) |
789
|
|
|
cmd.add_element('port_range', port_range) |
790
|
|
|
|
791
|
|
|
if comment: |
792
|
|
|
cmd.add_element('comment', comment) |
793
|
|
|
|
794
|
|
|
return self._send_xml_command(cmd) |
795
|
|
|
|
796
|
|
|
def clone_port_list(self, port_list_id): |
797
|
|
|
"""Clone an existing port list |
798
|
|
|
|
799
|
|
|
Arguments: |
800
|
|
|
copy (str): UUID of an existing port list to clone from |
801
|
|
|
|
802
|
|
|
Returns: |
803
|
|
|
The response. See :py:meth:`send_command` for details. |
804
|
|
|
""" |
805
|
|
|
cmd = XmlCommand('create_port_list') |
806
|
|
|
cmd.add_element('copy', port_list_id) |
807
|
|
|
return self._send_xml_command(cmd) |
808
|
|
|
|
809
|
|
|
def create_port_range(self, port_list_id, start, end, port_range_type, |
810
|
|
|
comment=None): |
811
|
|
|
"""Create new port range |
812
|
|
|
|
813
|
|
|
Arguments: |
814
|
|
|
port_list_id (str): UUID of the port list to which to add the range |
815
|
|
|
start (int): The first port in the range |
816
|
|
|
end (int): The last port in the range |
817
|
|
|
type (str): The type of the ports: TCP, UDP, ... |
818
|
|
|
comment (str, optional): Comment for the port range |
819
|
|
|
|
820
|
|
|
Returns: |
821
|
|
|
The response. See :py:meth:`send_command` for details. |
822
|
|
|
""" |
823
|
|
|
if not port_list_id: |
824
|
|
|
raise RequiredArgument('create_port_range requires ' |
825
|
|
|
'a port_list_id argument') |
826
|
|
|
|
827
|
|
|
if not port_range_type: |
828
|
|
|
raise RequiredArgument( |
829
|
|
|
'create_port_range requires a port_range_type argument') |
830
|
|
|
|
831
|
|
|
if not start: |
832
|
|
|
raise RequiredArgument( |
833
|
|
|
'create_port_range requires a start argument') |
834
|
|
|
|
835
|
|
|
if not end: |
836
|
|
|
raise RequiredArgument( |
837
|
|
|
'create_port_range requires a end argument') |
838
|
|
|
|
839
|
|
|
cmd = XmlCommand('create_port_range') |
840
|
|
|
cmd.add_element('port_list', attrs={'id': port_list_id}) |
841
|
|
|
cmd.add_element('start', start) |
842
|
|
|
cmd.add_element('end', end) |
843
|
|
|
cmd.add_element('type', port_range_type) |
844
|
|
|
|
845
|
|
|
if comment: |
846
|
|
|
cmd.add_element('comment', comment) |
847
|
|
|
|
848
|
|
|
return self._send_xml_command(cmd) |
849
|
|
|
|
850
|
|
|
def import_report(self, report, task_id=None, task_name=None, |
851
|
|
|
task_comment=None, in_assets=None): |
852
|
|
|
"""Import a Report |
853
|
|
|
|
854
|
|
|
Arguments: |
855
|
|
|
report (str): Report XML as string to import |
856
|
|
|
task_id (str, optional): UUID of task to import report to |
857
|
|
|
task_name (str, optional): Name of task to be createed if task_id is |
858
|
|
|
not present. Either task_id or task_name must be passed |
859
|
|
|
task_comment (str, optional): Comment for task to be created if |
860
|
|
|
task_id is not present |
861
|
|
|
in_asset (boolean, optional): Whether to create or update assets |
862
|
|
|
using the report |
863
|
|
|
|
864
|
|
|
Returns: |
865
|
|
|
The response. See :py:meth:`send_command` for details. |
866
|
|
|
""" |
867
|
|
|
if not report: |
868
|
|
|
raise RequiredArgument('create_report requires a report argument') |
869
|
|
|
|
870
|
|
|
cmd = XmlCommand('create_report') |
871
|
|
|
|
872
|
|
|
if task_id: |
873
|
|
|
cmd.add_element('task', attrs={'id': task_id}) |
874
|
|
|
elif task_name: |
875
|
|
|
_xmltask = cmd.add_element('task') |
876
|
|
|
_xmltask.add_element('name', task_name) |
877
|
|
|
|
878
|
|
|
if task_comment: |
879
|
|
|
_xmltask.add_element('comment', task_comment) |
880
|
|
|
else: |
881
|
|
|
raise RequiredArgument( |
882
|
|
|
'import_report requires a task_id or task_name argument') |
883
|
|
|
|
884
|
|
|
if not in_assets is None: |
885
|
|
|
if in_assets: |
886
|
|
|
cmd.add_element('in_assets', '1') |
887
|
|
|
else: |
888
|
|
|
cmd.add_element('in_assets', '0') |
889
|
|
|
try: |
890
|
|
|
cmd.append_xml_str(report) |
891
|
|
|
except etree.XMLSyntaxError as e: |
892
|
|
|
raise InvalidArgument( |
893
|
|
|
'Invalid xml passed as report to import_report', e) |
894
|
|
|
|
895
|
|
|
return self._send_xml_command(cmd) |
896
|
|
|
|
897
|
|
|
def create_role(self, name, comment=None, users=None): |
898
|
|
|
"""Create a new role |
899
|
|
|
|
900
|
|
|
Arguments: |
901
|
|
|
name (str): Name of the role |
902
|
|
|
comment (str, optional): Comment for the role |
903
|
|
|
users (list, optional): List of user names to add to the role |
904
|
|
|
|
905
|
|
|
Returns: |
906
|
|
|
The response. See :py:meth:`send_command` for details. |
907
|
|
|
""" |
908
|
|
|
|
909
|
|
|
if not name: |
910
|
|
|
raise RequiredArgument('create_role requires a name argument') |
911
|
|
|
|
912
|
|
|
cmd = XmlCommand('create_role') |
913
|
|
|
cmd.add_element('name', name) |
914
|
|
|
|
915
|
|
|
if comment: |
916
|
|
|
cmd.add_element('comment', comment) |
917
|
|
|
|
918
|
|
|
if users: |
919
|
|
|
cmd.add_element('users', ",".join(users)) |
920
|
|
|
|
921
|
|
|
return self._send_xml_command(cmd) |
922
|
|
|
|
923
|
|
|
def clone_role(self, role_id): |
924
|
|
|
"""Clone an existing role |
925
|
|
|
|
926
|
|
|
Arguments: |
927
|
|
|
copy (str): UUID of an existing role to clone from |
928
|
|
|
|
929
|
|
|
Returns: |
930
|
|
|
The response. See :py:meth:`send_command` for details. |
931
|
|
|
""" |
932
|
|
|
cmd = XmlCommand('create_role') |
933
|
|
|
cmd.add_element('copy', role_id) |
934
|
|
|
return self._send_xml_command(cmd) |
935
|
|
|
|
936
|
|
|
def create_scanner(self, name, host, port, scanner_type, ca_pub, |
937
|
|
|
credential_id, comment=None): |
938
|
|
|
"""Create a new scanner |
939
|
|
|
|
940
|
|
|
Arguments: |
941
|
|
|
name (str): Name of the scanner |
942
|
|
|
host (str): The host of the scanner |
943
|
|
|
port (str): The port of the scanner |
944
|
|
|
scanner_type (str): The type of the scanner |
945
|
|
|
ca_pub (str): Certificate of CA to verify scanner certificate |
946
|
|
|
credential_id (str): UUID of client certificate credential for the |
947
|
|
|
scanner |
948
|
|
|
comment (str, optional): Comment for the scanner |
949
|
|
|
|
950
|
|
|
Returns: |
951
|
|
|
The response. See :py:meth:`send_command` for details. |
952
|
|
|
""" |
953
|
|
|
if not name: |
954
|
|
|
raise RequiredArgument('create_scanner requires a name argument') |
955
|
|
|
|
956
|
|
|
if not host: |
957
|
|
|
raise RequiredArgument('create_scanner requires a host argument') |
958
|
|
|
|
959
|
|
|
if not port: |
960
|
|
|
raise RequiredArgument('create_scanner requires a port argument') |
961
|
|
|
|
962
|
|
|
if not type: |
963
|
|
|
raise RequiredArgument('create_scanner requires a scanner_type ' |
964
|
|
|
'argument') |
965
|
|
|
if not ca_pub: |
966
|
|
|
raise RequiredArgument('create_scanner requires a ca_pub argument') |
967
|
|
|
|
968
|
|
|
if not credential_id: |
969
|
|
|
raise RequiredArgument('create_scanner requires a credential_id ' |
970
|
|
|
'argument') |
971
|
|
|
|
972
|
|
|
cmd = XmlCommand('create_scanner') |
973
|
|
|
cmd.add_element('name', name) |
974
|
|
|
cmd.add_element('host', host) |
975
|
|
|
cmd.add_element('port', port) |
976
|
|
|
cmd.add_element('type', scanner_type) |
977
|
|
|
cmd.add_element('ca_pub', ca_pub) |
978
|
|
|
cmd.add_element('credential', attrs={'id': str(credential_id)}) |
979
|
|
|
|
980
|
|
|
if comment: |
981
|
|
|
cmd.add_element('comment', comment) |
982
|
|
|
|
983
|
|
|
return self._send_xml_command(cmd) |
984
|
|
|
|
985
|
|
|
def clone_scanner(self, scanner_id): |
986
|
|
|
"""Clone an existing scanner |
987
|
|
|
|
988
|
|
|
Arguments: |
989
|
|
|
copy (str): UUID of an existing scanner to clone from |
990
|
|
|
|
991
|
|
|
Returns: |
992
|
|
|
The response. See :py:meth:`send_command` for details. |
993
|
|
|
""" |
994
|
|
|
cmd = XmlCommand('create_scanner') |
995
|
|
|
cmd.add_element('copy', scanner_id) |
996
|
|
|
return self._send_xml_command(cmd) |
997
|
|
|
|
998
|
|
|
def create_schedule(self, name, comment=None, first_time_minute=None, |
|
|
|
|
999
|
|
|
first_time_hour=None, first_time_day_of_month=None, |
1000
|
|
|
first_time_month=None, first_time_year=None, |
1001
|
|
|
duration=None, duration_unit=None, period=None, |
1002
|
|
|
period_unit=None, timezone=None): |
1003
|
|
|
"""Create a new schedule |
1004
|
|
|
|
1005
|
|
|
Arguments: |
1006
|
|
|
name (str): Name of the schedule |
1007
|
|
|
comment (str, optional): Comment for the schedule |
1008
|
|
|
first_time_minute (int, optional): First time minute the schedule |
1009
|
|
|
will run |
1010
|
|
|
first_time_hour (int, optional): First time hour the schedule |
1011
|
|
|
will run |
1012
|
|
|
first_time_day_of_month (int, optional): First time day of month the |
1013
|
|
|
schedule will run |
1014
|
|
|
first_time_month (int, optional): First time month the schedule |
1015
|
|
|
will run |
1016
|
|
|
first_time_year (int, optional): First time year the schedule |
1017
|
|
|
will run |
1018
|
|
|
duration (int, optional): How long the Manager will run the |
1019
|
|
|
scheduled task for until it gets paused if not finished yet. |
1020
|
|
|
duration_unit (str, optional): Unit of the duration. One of second, |
1021
|
|
|
minute, hour, day, week, month, year, decade. Required if |
1022
|
|
|
duration is set. |
1023
|
|
|
period (int, optional): How often the Manager will repeat the |
1024
|
|
|
scheduled task |
1025
|
|
|
period_unit (str, optional): Unit of the period. One of second, |
1026
|
|
|
minute, hour, day, week, month, year, decade. Required if |
1027
|
|
|
period is set. |
1028
|
|
|
timezone (str, optional): The timezone the schedule will follow |
1029
|
|
|
|
1030
|
|
|
Returns: |
1031
|
|
|
The response. See :py:meth:`send_command` for details. |
1032
|
|
|
""" |
1033
|
|
|
if not name: |
1034
|
|
|
raise RequiredArgument('create_schedule requires a name argument') |
1035
|
|
|
|
1036
|
|
|
cmd = XmlCommand('create_schedule') |
1037
|
|
|
cmd.add_element('name', name) |
1038
|
|
|
|
1039
|
|
|
if comment: |
1040
|
|
|
cmd.add_element('comment', comment) |
1041
|
|
|
|
1042
|
|
|
if first_time_minute or first_time_hour or first_time_day_of_month or \ |
1043
|
|
|
first_time_month or first_time_year: |
1044
|
|
|
|
1045
|
|
|
if not first_time_minute: |
1046
|
|
|
raise RequiredArgument( |
1047
|
|
|
'Setting first_time requires first_time_minute argument') |
1048
|
|
|
if not first_time_hour: |
1049
|
|
|
raise RequiredArgument( |
1050
|
|
|
'Setting first_time requires first_time_hour argument') |
1051
|
|
|
if not first_time_day_of_month: |
1052
|
|
|
raise RequiredArgument( |
1053
|
|
|
'Setting first_time requires first_time_day_of_month ' |
1054
|
|
|
'argument') |
1055
|
|
|
if not first_time_month: |
1056
|
|
|
raise RequiredArgument( |
1057
|
|
|
'Setting first_time requires first_time_month argument') |
1058
|
|
|
if not first_time_year: |
1059
|
|
|
raise RequiredArgument( |
1060
|
|
|
'Setting first_time requires first_time_year argument') |
1061
|
|
|
|
1062
|
|
|
_xmlftime = cmd.add_element('first_time') |
1063
|
|
|
_xmlftime.add_element('minute', str(first_time_minute)) |
1064
|
|
|
_xmlftime.add_element('hour', str(first_time_hour)) |
1065
|
|
|
_xmlftime.add_element('day_of_month', str(first_time_day_of_month)) |
1066
|
|
|
_xmlftime.add_element('month', str(first_time_month)) |
1067
|
|
|
_xmlftime.add_element('year', str(first_time_year)) |
1068
|
|
|
|
1069
|
|
|
if duration: |
1070
|
|
|
if not duration_unit: |
1071
|
|
|
raise RequiredArgument( |
1072
|
|
|
'Setting duration requires duration_unit argument') |
1073
|
|
|
|
1074
|
|
|
if not duration_unit in TIME_UNITS: |
1075
|
|
|
raise InvalidArgument( |
1076
|
|
|
'duration_unit must be one of {units} but {actual} has ' |
1077
|
|
|
'been passed'.format( |
1078
|
|
|
units=', '.join(TIME_UNITS), actual=duration_unit)) |
1079
|
|
|
|
1080
|
|
|
_xmlduration = cmd.add_element('duration', str(duration)) |
1081
|
|
|
_xmlduration.add_element('unit', duration_unit) |
1082
|
|
|
|
1083
|
|
|
if period: |
1084
|
|
|
if not period_unit: |
1085
|
|
|
raise RequiredArgument( |
1086
|
|
|
'Setting period requires period_unit argument') |
1087
|
|
|
|
1088
|
|
|
if not period_unit in TIME_UNITS: |
1089
|
|
|
raise InvalidArgument( |
1090
|
|
|
'period_unit must be one of {units} but {actual} has ' |
1091
|
|
|
'been passed'.format( |
1092
|
|
|
units=', '.join(TIME_UNITS), actual=period_unit)) |
1093
|
|
|
|
1094
|
|
|
_xmlperiod = cmd.add_element('period', str(period)) |
1095
|
|
|
_xmlperiod.add_element('unit', period_unit) |
1096
|
|
|
|
1097
|
|
|
if timezone: |
1098
|
|
|
cmd.add_element('timezone', timezone) |
1099
|
|
|
|
1100
|
|
|
return self._send_xml_command(cmd) |
1101
|
|
|
|
1102
|
|
|
def clone_schedule(self, schedule_id): |
1103
|
|
|
"""Clone an existing schedule |
1104
|
|
|
|
1105
|
|
|
Arguments: |
1106
|
|
|
copy (str): UUID of an existing schedule to clone from |
1107
|
|
|
|
1108
|
|
|
Returns: |
1109
|
|
|
The response. See :py:meth:`send_command` for details. |
1110
|
|
|
""" |
1111
|
|
|
cmd = XmlCommand('create_schedule') |
1112
|
|
|
cmd.add_element('copy', schedule_id) |
1113
|
|
|
return self._send_xml_command(cmd) |
1114
|
|
|
|
1115
|
|
|
def create_tag(self, name, resource_id, resource_type, value=None, |
1116
|
|
|
comment=None, active=None): |
1117
|
|
|
"""Create a new tag |
1118
|
|
|
|
1119
|
|
|
Arguments: |
1120
|
|
|
name (str): Name of the tag. A full tag name consisting of namespace |
1121
|
|
|
and predicate e.g. `foo:bar`. |
1122
|
|
|
resource_id (str): ID of the resource the tag is to be attached to. |
1123
|
|
|
resource_type (str): Entity type the tag is to be attached to |
1124
|
|
|
value (str, optional): Value associated with the tag |
1125
|
|
|
comment (str, optional): Comment for the tag |
1126
|
|
|
active (boolean, optional): Whether the tag should be active |
1127
|
|
|
|
1128
|
|
|
Returns: |
1129
|
|
|
The response. See :py:meth:`send_command` for details. |
1130
|
|
|
""" |
1131
|
|
|
cmd = XmlCommand('create_tag') |
1132
|
|
|
cmd.add_element('name', name) |
1133
|
|
|
_xmlresource = cmd.add_element('resource', |
1134
|
|
|
attrs={'id': str(resource_id)}) |
1135
|
|
|
_xmlresource.add_element('type', resource_type) |
1136
|
|
|
|
1137
|
|
|
if comment: |
1138
|
|
|
cmd.add_element('comment', comment) |
1139
|
|
|
|
1140
|
|
|
if value: |
1141
|
|
|
cmd.add_element('value', value) |
1142
|
|
|
|
1143
|
|
|
if not active is None: |
1144
|
|
|
if active: |
1145
|
|
|
cmd.add_element('active', '1') |
1146
|
|
|
else: |
1147
|
|
|
cmd.add_element('active', '0') |
1148
|
|
|
|
1149
|
|
|
return self._send_xml_command(cmd) |
1150
|
|
|
|
1151
|
|
|
def clone_tag(self, tag_id): |
1152
|
|
|
"""Clone an existing tag |
1153
|
|
|
|
1154
|
|
|
Arguments: |
1155
|
|
|
copy (str): UUID of an existing tag to clone from |
1156
|
|
|
|
1157
|
|
|
Returns: |
1158
|
|
|
The response. See :py:meth:`send_command` for details. |
1159
|
|
|
""" |
1160
|
|
|
cmd = XmlCommand('create_tag') |
1161
|
|
|
cmd.add_element('copy', tag_id) |
1162
|
|
|
return self._send_xml_command(cmd) |
1163
|
|
|
|
1164
|
|
|
def create_target(self, name, make_unique=False, asset_hosts_filter=None, |
|
|
|
|
1165
|
|
|
hosts=None, comment=None, exclude_hosts=None, |
1166
|
|
|
ssh_credential_id=None, ssh_credential_port=None, |
1167
|
|
|
smb_credential_id=None, esxi_credential_id=None, |
1168
|
|
|
snmp_credential_id=None, alive_tests=None, |
1169
|
|
|
reverse_lookup_only=None, reverse_lookup_unify=None, |
1170
|
|
|
port_range=None, port_list_id=None): |
1171
|
|
|
"""Create a new target |
1172
|
|
|
|
1173
|
|
|
Arguments: |
1174
|
|
|
name (str): Name of the target |
1175
|
|
|
make_unique (boolean, optional): Append a unique suffix if the name |
1176
|
|
|
already exists |
1177
|
|
|
asset_hosts_filter (str, optional): Filter to select target host |
1178
|
|
|
from assets hosts |
1179
|
|
|
hosts (list, optional): List of hosts addresses to scan |
1180
|
|
|
exclude_hosts (list, optional): List of hosts addresses to exclude |
1181
|
|
|
from scan |
1182
|
|
|
comment (str, optional): Comment for the target |
1183
|
|
|
ssh_credential_id (str, optional): UUID of a ssh credential to use |
1184
|
|
|
on target |
1185
|
|
|
ssh_credential_port (str, optional): The port to use for ssh |
1186
|
|
|
credential |
1187
|
|
|
smb_credential_id (str, optional): UUID of a smb credential to use |
1188
|
|
|
on target |
1189
|
|
|
snmp_credential_id (str, optional): UUID of a snmp credential to use |
1190
|
|
|
on target |
1191
|
|
|
esxi_credential_id (str, optional): UUID of a esxi credential to use |
1192
|
|
|
on target |
1193
|
|
|
alive_tests (str, optional): Which alive tests to use |
1194
|
|
|
reverse_lookup_only (boolean, optional): Whether to scan only hosts |
1195
|
|
|
that have names |
1196
|
|
|
reverse_lookup_unify (boolean, optional): Whether to scan only one |
1197
|
|
|
IP when multiple IPs have the same name. |
1198
|
|
|
port_range (str, optional): Port range for the target |
1199
|
|
|
port_list_id (str, optional): UUID of the port list to use on target |
1200
|
|
|
|
1201
|
|
|
Returns: |
1202
|
|
|
The response. See :py:meth:`send_command` for details. |
1203
|
|
|
""" |
1204
|
|
|
if not name: |
1205
|
|
|
raise RequiredArgument('create_target requires a name argument') |
1206
|
|
|
|
1207
|
|
|
cmd = XmlCommand('create_target') |
1208
|
|
|
_xmlname = cmd.add_element('name', name) |
1209
|
|
|
if make_unique: |
1210
|
|
|
_xmlname.add_element('make_unique', '1') |
1211
|
|
|
|
1212
|
|
|
if asset_hosts_filter: |
1213
|
|
|
cmd.add_element('asset_hosts', |
1214
|
|
|
attrs={'filter': str(asset_hosts_filter)}) |
1215
|
|
|
elif hosts: |
1216
|
|
|
cmd.add_element('hosts', ', '.join(hosts)) |
1217
|
|
|
else: |
1218
|
|
|
raise RequiredArgument('create_target requires either a hosts or ' |
1219
|
|
|
'an asset_hosts_filter argument') |
1220
|
|
|
|
1221
|
|
|
if comment: |
1222
|
|
|
cmd.add_element('comment', comment) |
1223
|
|
|
|
1224
|
|
|
if exclude_hosts: |
1225
|
|
|
cmd.add_element('exclude_hosts', ', '.join(exclude_hosts)) |
1226
|
|
|
|
1227
|
|
|
if ssh_credential_id: |
1228
|
|
|
_xmlssh = cmd.add_element('ssh_credential', |
1229
|
|
|
attrs={'id': ssh_credential_id}) |
1230
|
|
|
if ssh_credential_port: |
1231
|
|
|
_xmlssh.add_element('port', ssh_credential_port) |
1232
|
|
|
|
1233
|
|
|
if smb_credential_id: |
1234
|
|
|
cmd.add_element('smb_credential', attrs={'id': smb_credential_id}) |
1235
|
|
|
|
1236
|
|
|
if esxi_credential_id: |
1237
|
|
|
cmd.add_element('esxi_credential', attrs={'id': esxi_credential_id}) |
1238
|
|
|
|
1239
|
|
|
if snmp_credential_id: |
1240
|
|
|
cmd.add_element('snmp_credential', attrs={'id': snmp_credential_id}) |
1241
|
|
|
|
1242
|
|
|
if alive_tests: |
1243
|
|
|
cmd.add_element('alive_tests', alive_tests) |
1244
|
|
|
|
1245
|
|
|
if not reverse_lookup_only is None: |
1246
|
|
|
if reverse_lookup_only: |
1247
|
|
|
cmd.add_element('reverse_lookup_only', '1') |
1248
|
|
|
else: |
1249
|
|
|
cmd.add_element('reverse_lookup_only', '0') |
1250
|
|
|
|
1251
|
|
|
if not reverse_lookup_unify is None: |
1252
|
|
|
if reverse_lookup_unify: |
1253
|
|
|
cmd.add_element('reverse_lookup_unify', '1') |
1254
|
|
|
else: |
1255
|
|
|
cmd.add_element('reverse_lookup_unify', '0') |
1256
|
|
|
|
1257
|
|
|
if port_range: |
1258
|
|
|
cmd.add_element('port_range', port_range) |
1259
|
|
|
|
1260
|
|
|
if port_list_id: |
1261
|
|
|
cmd.add_element('port_list', attrs={'id': port_list_id}) |
1262
|
|
|
|
1263
|
|
|
return self._send_xml_command(cmd) |
1264
|
|
|
|
1265
|
|
|
def clone_target(self, target_id): |
1266
|
|
|
"""Clone an existing target |
1267
|
|
|
|
1268
|
|
|
Arguments: |
1269
|
|
|
copy (str): UUID of an existing target to clone from |
1270
|
|
|
|
1271
|
|
|
Returns: |
1272
|
|
|
The response. See :py:meth:`send_command` for details. |
1273
|
|
|
""" |
1274
|
|
|
cmd = XmlCommand('create_target') |
1275
|
|
|
cmd.add_element('copy', target_id) |
1276
|
|
|
return self._send_xml_command(cmd) |
1277
|
|
|
|
1278
|
|
|
def create_task(self, name, config_id, target_id, scanner_id, |
1279
|
|
|
alterable=None, hosts_ordering=None, schedule_id=None, |
1280
|
|
|
alert_ids=None, comment=None, schedule_periods=None, |
1281
|
|
|
observers=None): |
1282
|
|
|
"""Create a new task |
1283
|
|
|
|
1284
|
|
|
Arguments: |
1285
|
|
|
name (str): Name of the task |
1286
|
|
|
config_id (str): UUID of scan config to use by the task |
1287
|
|
|
target_id (str): UUID of target to be scanned |
1288
|
|
|
scanner_id (str): UUID of scanner to use for scanning the target |
1289
|
|
|
comment (str, optional): Comment for the task |
1290
|
|
|
alterable (boolean, optional): Wether the task should be alterable |
1291
|
|
|
alert_ids (list, optional): List of UUIDs for alerts to be applied |
1292
|
|
|
to the task |
1293
|
|
|
hosts_ordering (str, optional): The order hosts are scanned in |
1294
|
|
|
schedule_id (str, optional): UUID of a schedule when the task should |
1295
|
|
|
be run. |
1296
|
|
|
schedule_periods (int, optional): A limit to the number of times the |
1297
|
|
|
task will be scheduled, or 0 for no limit |
1298
|
|
|
observers (list, optional): List of user names which should be |
1299
|
|
|
allowed to observe this task |
1300
|
|
|
|
1301
|
|
|
Returns: |
1302
|
|
|
The response. See :py:meth:`send_command` for details. |
1303
|
|
|
""" |
1304
|
|
|
if not name: |
1305
|
|
|
raise RequiredArgument('create_task requires a name argument') |
1306
|
|
|
|
1307
|
|
|
if not config_id: |
1308
|
|
|
raise RequiredArgument('create_task requires a config_id argument') |
1309
|
|
|
|
1310
|
|
|
if not target_id: |
1311
|
|
|
raise RequiredArgument('create_task requires a target_id argument') |
1312
|
|
|
|
1313
|
|
|
if not scanner_id: |
1314
|
|
|
raise RequiredArgument('create_task requires a scanner_id argument') |
1315
|
|
|
|
1316
|
|
|
cmd = XmlCommand('create_task') |
1317
|
|
|
cmd.add_element('name', name) |
1318
|
|
|
cmd.add_element('config', attrs={'id': config_id}) |
1319
|
|
|
cmd.add_element('target', attrs={'id': target_id}) |
1320
|
|
|
cmd.add_element('scanner', attrs={'id': scanner_id}) |
1321
|
|
|
|
1322
|
|
|
if comment: |
1323
|
|
|
cmd.add_element('comment', comment) |
1324
|
|
|
|
1325
|
|
|
if not alterable is None: |
1326
|
|
|
if alterable: |
1327
|
|
|
cmd.add_element('alterable', '1') |
1328
|
|
|
else: |
1329
|
|
|
cmd.add_element('alterable', '0') |
1330
|
|
|
|
1331
|
|
|
if hosts_ordering: |
1332
|
|
|
cmd.add_element('hosts_ordering', hosts_ordering) |
1333
|
|
|
|
1334
|
|
|
if alert_ids: |
1335
|
|
|
if isinstance(alert_ids, str): |
1336
|
|
|
logger.warning( |
1337
|
|
|
'Please pass a list as alert_ids parameter to create_task. ' |
1338
|
|
|
'Passing a string is deprecated and will be removed in ' |
1339
|
|
|
'future.') |
1340
|
|
|
|
1341
|
|
|
#if a single id is given as a string wrap it into a list |
1342
|
|
|
alert_ids = [alert_ids] |
1343
|
|
|
if isinstance(alert_ids, list): |
1344
|
|
|
#parse all given alert id's |
1345
|
|
|
for alert in alert_ids: |
1346
|
|
|
cmd.add_element('alert', attrs={'id': str(alert)}) |
1347
|
|
|
|
1348
|
|
|
if schedule_id: |
1349
|
|
|
cmd.add_element('schedule', schedule_id) |
1350
|
|
|
|
1351
|
|
|
if schedule_periods: |
1352
|
|
|
cmd.add_element('schedule_periods', str(schedule_periods)) |
1353
|
|
|
|
1354
|
|
|
if observers: |
1355
|
|
|
cmd.add_element('observers', ' '.join(observers)) |
1356
|
|
|
|
1357
|
|
|
return self._send_xml_command(cmd) |
1358
|
|
|
|
1359
|
|
|
def clone_task(self, task_id): |
1360
|
|
|
"""Clone an existing task |
1361
|
|
|
|
1362
|
|
|
Arguments: |
1363
|
|
|
task_id (str): UUID of existing task to clone from |
1364
|
|
|
|
1365
|
|
|
Returns: |
1366
|
|
|
The response. See :py:meth:`send_command` for details. |
1367
|
|
|
""" |
1368
|
|
|
cmd = XmlCommand('create_task') |
1369
|
|
|
cmd.add_element('copy', task_id) |
1370
|
|
|
return self._send_xml_command(cmd) |
1371
|
|
|
|
1372
|
|
|
def create_user(self, name, password=None, hosts=None, hosts_allow=False, |
1373
|
|
|
ifaces=None, ifaces_allow=False, role_ids=None): |
1374
|
|
|
"""Create a new user |
1375
|
|
|
|
1376
|
|
|
Arguments: |
1377
|
|
|
name (str): Name of the user |
1378
|
|
|
password (str, optional): Password of the user |
1379
|
|
|
hosts (list, optional): A list of host addresses (IPs, DNS names) |
1380
|
|
|
hosts_allow (boolean, optional): If True allow only access to passed |
1381
|
|
|
hosts otherwise deny access. Default is False for deny hosts. |
1382
|
|
|
ifaces (list, optional): A list of interface names |
1383
|
|
|
ifaces_allow (boolean, optional): If True allow only access to |
1384
|
|
|
passed interfaces otherwise deny access. Default is False for |
1385
|
|
|
deny interfaces. |
1386
|
|
|
role_ids (list, optional): A list of role UUIDs for the user |
1387
|
|
|
|
1388
|
|
|
Returns: |
1389
|
|
|
The response. See :py:meth:`send_command` for details. |
1390
|
|
|
""" |
1391
|
|
|
if not name: |
1392
|
|
|
raise RequiredArgument('create_user requires a name argument') |
1393
|
|
|
|
1394
|
|
|
cmd = XmlCommand('create_user') |
1395
|
|
|
cmd.add_element('name', name) |
1396
|
|
|
|
1397
|
|
|
if password: |
1398
|
|
|
cmd.add_element('password', password) |
1399
|
|
|
|
1400
|
|
|
if hosts: |
1401
|
|
|
cmd.add_element('hosts', ', '.join(hosts), |
1402
|
|
|
attrs={'allow': '1' if hosts_allow else '0'}) |
1403
|
|
|
|
1404
|
|
|
if ifaces: |
1405
|
|
|
cmd.add_element('ifaces', ', '.join(ifaces), |
1406
|
|
|
attrs={'allow': '1' if ifaces_allow else '0'}) |
1407
|
|
|
|
1408
|
|
|
if role_ids: |
1409
|
|
|
for role in role_ids: |
1410
|
|
|
cmd.add_element('role', attrs={'id': role}) |
1411
|
|
|
|
1412
|
|
|
return self._send_xml_command(cmd) |
1413
|
|
|
|
1414
|
|
|
def clone_user(self, user_id): |
1415
|
|
|
"""Clone an existing user |
1416
|
|
|
|
1417
|
|
|
Arguments: |
1418
|
|
|
user_id (str): UUID of existing user to clone from |
1419
|
|
|
|
1420
|
|
|
Returns: |
1421
|
|
|
The response. See :py:meth:`send_command` for details. |
1422
|
|
|
""" |
1423
|
|
|
cmd = XmlCommand('create_user') |
1424
|
|
|
cmd.add_element('copy', user_id) |
1425
|
|
|
return self._send_xml_command(cmd) |
1426
|
|
|
|
1427
|
|
|
def delete_agent(self, **kwargs): |
1428
|
|
|
cmd = self._generator.delete_agent_command(kwargs) |
1429
|
|
|
return self.send_command(cmd) |
1430
|
|
|
|
1431
|
|
|
def delete_alert(self, **kwargs): |
1432
|
|
|
cmd = self._generator.delete_alert_command(kwargs) |
1433
|
|
|
return self.send_command(cmd) |
1434
|
|
|
|
1435
|
|
|
def delete_asset(self, asset_id, ultimate=0): |
1436
|
|
|
cmd = self._generator.delete_asset_command(asset_id, ultimate) |
1437
|
|
|
return self.send_command(cmd) |
1438
|
|
|
|
1439
|
|
|
def delete_config(self, config_id, ultimate=0): |
1440
|
|
|
cmd = self._generator.delete_config_command(config_id, ultimate) |
1441
|
|
|
return self.send_command(cmd) |
1442
|
|
|
|
1443
|
|
|
def delete_credential(self, credential_id, ultimate=0): |
1444
|
|
|
cmd = self._generator.delete_credential_command(credential_id, ultimate) |
1445
|
|
|
return self.send_command(cmd) |
1446
|
|
|
|
1447
|
|
|
def delete_filter(self, filter_id, ultimate=0): |
1448
|
|
|
cmd = self._generator.delete_filter_command(filter_id, ultimate) |
1449
|
|
|
return self.send_command(cmd) |
1450
|
|
|
|
1451
|
|
|
def delete_group(self, group_id, ultimate=0): |
1452
|
|
|
cmd = self._generator.delete_group_command(group_id, ultimate) |
1453
|
|
|
return self.send_command(cmd) |
1454
|
|
|
|
1455
|
|
|
def delete_note(self, note_id, ultimate=0): |
1456
|
|
|
cmd = self._generator.delete_note_command(note_id, ultimate) |
1457
|
|
|
return self.send_command(cmd) |
1458
|
|
|
|
1459
|
|
|
def delete_override(self, override_id, ultimate=0): |
1460
|
|
|
cmd = self._generator.delete_override_command(override_id, ultimate) |
1461
|
|
|
return self.send_command(cmd) |
1462
|
|
|
|
1463
|
|
|
def delete_permission(self, permission_id, ultimate=0): |
1464
|
|
|
cmd = self._generator.delete_permission_command(permission_id, ultimate) |
1465
|
|
|
return self.send_command(cmd) |
1466
|
|
|
|
1467
|
|
|
def delete_port_list(self, port_list_id, ultimate=0): |
1468
|
|
|
cmd = self._generator.delete_port_list_command(port_list_id, ultimate) |
1469
|
|
|
return self.send_command(cmd) |
1470
|
|
|
|
1471
|
|
|
def delete_port_range(self, port_range_id): |
1472
|
|
|
cmd = self._generator.delete_port_range_command(port_range_id) |
1473
|
|
|
return self.send_command(cmd) |
1474
|
|
|
|
1475
|
|
|
def delete_report(self, report_id): |
1476
|
|
|
cmd = self._generator.delete_report_command(report_id) |
1477
|
|
|
return self.send_command(cmd) |
1478
|
|
|
|
1479
|
|
|
def delete_report_format(self, report_format_id, ultimate=0): |
1480
|
|
|
cmd = self._generator.delete_report_format_command( |
1481
|
|
|
report_format_id, ultimate) |
1482
|
|
|
return self.send_command(cmd) |
1483
|
|
|
|
1484
|
|
|
def delete_role(self, role_id, ultimate=0): |
1485
|
|
|
cmd = self._generator.delete_role_command(role_id, ultimate) |
1486
|
|
|
return self.send_command(cmd) |
1487
|
|
|
|
1488
|
|
|
def delete_scanner(self, scanner_id, ultimate=0): |
1489
|
|
|
cmd = self._generator.delete_scanner_command(scanner_id, ultimate) |
1490
|
|
|
return self.send_command(cmd) |
1491
|
|
|
|
1492
|
|
|
def delete_schedule(self, schedule_id, ultimate=0): |
1493
|
|
|
cmd = self._generator.delete_schedule_command(schedule_id, ultimate) |
1494
|
|
|
return self.send_command(cmd) |
1495
|
|
|
|
1496
|
|
|
def delete_tag(self, tag_id, ultimate=0): |
1497
|
|
|
cmd = self._generator.delete_tag_command(tag_id, ultimate) |
1498
|
|
|
return self.send_command(cmd) |
1499
|
|
|
|
1500
|
|
|
def delete_target(self, target_id, ultimate=0): |
1501
|
|
|
cmd = self._generator.delete_target_command(target_id, ultimate) |
1502
|
|
|
return self.send_command(cmd) |
1503
|
|
|
|
1504
|
|
|
def delete_task(self, task_id, ultimate=0): |
1505
|
|
|
cmd = self._generator.delete_task_command(task_id, ultimate) |
1506
|
|
|
return self.send_command(cmd) |
1507
|
|
|
|
1508
|
|
|
def delete_user(self, **kwargs): |
1509
|
|
|
cmd = self._generator.delete_user_command(kwargs) |
1510
|
|
|
return self.send_command(cmd) |
1511
|
|
|
|
1512
|
|
|
def describe_auth(self): |
1513
|
|
|
cmd = self._generator.describe_auth_command() |
1514
|
|
|
return self.send_command(cmd) |
1515
|
|
|
|
1516
|
|
|
def empty_trashcan(self): |
1517
|
|
|
cmd = self._generator.empty_trashcan_command() |
1518
|
|
|
return self.send_command(cmd) |
1519
|
|
|
|
1520
|
|
|
def get_agents(self, **kwargs): |
1521
|
|
|
cmd = self._generator.get_agents_command(kwargs) |
1522
|
|
|
return self.send_command(cmd) |
1523
|
|
|
|
1524
|
|
|
def get_aggregates(self, **kwargs): |
1525
|
|
|
cmd = self._generator.get_aggregates_command(kwargs) |
1526
|
|
|
return self.send_command(cmd) |
1527
|
|
|
|
1528
|
|
|
def get_alerts(self, **kwargs): |
1529
|
|
|
cmd = self._generator.get_alerts_command(kwargs) |
1530
|
|
|
return self.send_command(cmd) |
1531
|
|
|
|
1532
|
|
|
def get_assets(self, **kwargs): |
1533
|
|
|
cmd = self._generator.get_assets_command(kwargs) |
1534
|
|
|
return self.send_command(cmd) |
1535
|
|
|
|
1536
|
|
|
def get_credentials(self, **kwargs): |
1537
|
|
|
cmd = self._generator.get_credentials_command(kwargs) |
1538
|
|
|
return self.send_command(cmd) |
1539
|
|
|
|
1540
|
|
|
def get_configs(self, **kwargs): |
1541
|
|
|
cmd = self._generator.get_configs_command(kwargs) |
1542
|
|
|
return self.send_command(cmd) |
1543
|
|
|
|
1544
|
|
|
def get_feeds(self, **kwargs): |
1545
|
|
|
cmd = self._generator.get_feeds_command(kwargs) |
1546
|
|
|
return self.send_command(cmd) |
1547
|
|
|
|
1548
|
|
|
def get_filters(self, **kwargs): |
1549
|
|
|
cmd = self._generator.get_filters_command(kwargs) |
1550
|
|
|
return self.send_command(cmd) |
1551
|
|
|
|
1552
|
|
|
def get_groups(self, **kwargs): |
1553
|
|
|
cmd = self._generator.get_groups_command(kwargs) |
1554
|
|
|
return self.send_command(cmd) |
1555
|
|
|
|
1556
|
|
|
def get_info(self, **kwargs): |
1557
|
|
|
cmd = self._generator.get_info_command(kwargs) |
1558
|
|
|
return self.send_command(cmd) |
1559
|
|
|
|
1560
|
|
|
def get_notes(self, **kwargs): |
1561
|
|
|
cmd = self._generator.get_notes_command(kwargs) |
1562
|
|
|
return self.send_command(cmd) |
1563
|
|
|
|
1564
|
|
|
def get_nvts(self, **kwargs): |
1565
|
|
|
cmd = self._generator.get_nvts_command(kwargs) |
1566
|
|
|
return self.send_command(cmd) |
1567
|
|
|
|
1568
|
|
|
def get_nvt_families(self, **kwargs): |
1569
|
|
|
cmd = self._generator.get_nvt_families_command(kwargs) |
1570
|
|
|
return self.send_command(cmd) |
1571
|
|
|
|
1572
|
|
|
def get_overrides(self, **kwargs): |
1573
|
|
|
cmd = self._generator.get_overrides_command(kwargs) |
1574
|
|
|
return self.send_command(cmd) |
1575
|
|
|
|
1576
|
|
|
def get_permissions(self, **kwargs): |
1577
|
|
|
cmd = self._generator.get_permissions_command(kwargs) |
1578
|
|
|
return self.send_command(cmd) |
1579
|
|
|
|
1580
|
|
|
def get_port_lists(self, **kwargs): |
1581
|
|
|
cmd = self._generator.get_port_lists_command(kwargs) |
1582
|
|
|
return self.send_command(cmd) |
1583
|
|
|
|
1584
|
|
|
def get_preferences(self, **kwargs): |
1585
|
|
|
cmd = self._generator.get_preferences_command(kwargs) |
1586
|
|
|
return self.send_command(cmd) |
1587
|
|
|
|
1588
|
|
|
def get_reports(self, **kwargs): |
1589
|
|
|
cmd = self._generator.get_reports_command(kwargs) |
1590
|
|
|
return self.send_command(cmd) |
1591
|
|
|
|
1592
|
|
|
def get_report_formats(self, **kwargs): |
1593
|
|
|
cmd = self._generator.get_report_formats_command(kwargs) |
1594
|
|
|
return self.send_command(cmd) |
1595
|
|
|
|
1596
|
|
|
def get_results(self, **kwargs): |
1597
|
|
|
cmd = self._generator.get_results_command(kwargs) |
1598
|
|
|
return self.send_command(cmd) |
1599
|
|
|
|
1600
|
|
|
def get_roles(self, **kwargs): |
1601
|
|
|
cmd = self._generator.get_roles_command(kwargs) |
1602
|
|
|
return self.send_command(cmd) |
1603
|
|
|
|
1604
|
|
|
def get_scanners(self, **kwargs): |
1605
|
|
|
cmd = self._generator.get_scanners_command(kwargs) |
1606
|
|
|
return self.send_command(cmd) |
1607
|
|
|
|
1608
|
|
|
def get_schedules(self, **kwargs): |
1609
|
|
|
cmd = self._generator.get_schedules_command(kwargs) |
1610
|
|
|
return self.send_command(cmd) |
1611
|
|
|
|
1612
|
|
|
def get_settings(self, **kwargs): |
1613
|
|
|
cmd = self._generator.get_settings_command(kwargs) |
1614
|
|
|
return self.send_command(cmd) |
1615
|
|
|
|
1616
|
|
|
def get_system_reports(self, **kwargs): |
1617
|
|
|
cmd = self._generator.get_system_reports_command(kwargs) |
1618
|
|
|
return self.send_command(cmd) |
1619
|
|
|
|
1620
|
|
|
def get_tags(self, **kwargs): |
1621
|
|
|
cmd = self._generator.get_tags_command(kwargs) |
1622
|
|
|
return self.send_command(cmd) |
1623
|
|
|
|
1624
|
|
|
def get_targets(self, **kwargs): |
1625
|
|
|
cmd = self._generator.get_targets_command(kwargs) |
1626
|
|
|
return self.send_command(cmd) |
1627
|
|
|
|
1628
|
|
|
def get_tasks(self, **kwargs): |
1629
|
|
|
cmd = self._generator.get_tasks_command(kwargs) |
1630
|
|
|
return self.send_command(cmd) |
1631
|
|
|
|
1632
|
|
|
def get_users(self, **kwargs): |
1633
|
|
|
cmd = self._generator.get_users_command(kwargs) |
1634
|
|
|
return self.send_command(cmd) |
1635
|
|
|
|
1636
|
|
|
def get_version(self): |
1637
|
|
|
cmd = self._generator.get_version_command() |
1638
|
|
|
return self.send_command(cmd) |
1639
|
|
|
|
1640
|
|
|
def help(self, **kwargs): |
1641
|
|
|
cmd = self._generator.help_command(kwargs) |
1642
|
|
|
return self.send_command(cmd) |
1643
|
|
|
|
1644
|
|
|
def modify_agent(self, agent_id, name=None, comment=None): |
1645
|
|
|
"""Generates xml string for modify agent on gvmd |
1646
|
|
|
|
1647
|
|
|
Arguments: |
1648
|
|
|
agent_id (str) UUID of the agent to be modified. |
1649
|
|
|
name (str, optional): Name of the new credential |
1650
|
|
|
comment (str, optional): Comment for the credential |
1651
|
|
|
""" |
1652
|
|
|
if not agent_id: |
1653
|
|
|
raise RequiredArgument('modify_agent requires agent_id argument') |
1654
|
|
|
|
1655
|
|
|
cmd = XmlCommand('modify_agent') |
1656
|
|
|
cmd.set_attribute('agent_id', str(agent_id)) |
1657
|
|
|
if name: |
1658
|
|
|
cmd.add_element('name', name) |
1659
|
|
|
if comment: |
1660
|
|
|
cmd.add_element('comment', comment) |
1661
|
|
|
|
1662
|
|
|
return self._send_xml_command(cmd) |
1663
|
|
|
|
1664
|
|
|
def modify_alert(self, alert_id, name=None, comment=None, |
|
|
|
|
1665
|
|
|
filter_id=None, event= None, event_data=None, |
|
|
|
|
1666
|
|
|
condition=None, condition_data=None, method=None, |
1667
|
|
|
method_data=None): |
1668
|
|
|
"""Generates xml string for modify alert on gvmd. |
1669
|
|
|
|
1670
|
|
|
Arguments: |
1671
|
|
|
alert_id (str) UUID of the alert to be modified. |
1672
|
|
|
name (str, optional): Name of the Alert. |
1673
|
|
|
condition (str): The condition that must be satisfied for the alert |
1674
|
|
|
to occur. |
1675
|
|
|
condition_data (dict, optional): Data that defines the condition |
1676
|
|
|
event (str, optional): The event that must happen for the alert |
1677
|
|
|
to occur. |
1678
|
|
|
event_data (dict, optional): Data that defines the event |
1679
|
|
|
method (str, optional): The method by which the user is alerted |
1680
|
|
|
method_data (dict, optional): Data that defines the method |
1681
|
|
|
filter_id (str, optional): Filter to apply when executing alert |
1682
|
|
|
comment (str, optional): Comment for the alert |
1683
|
|
|
""" |
1684
|
|
|
|
1685
|
|
|
if not alert_id: |
1686
|
|
|
raise RequiredArgument('modify_alert requires an alert_id argument') |
1687
|
|
|
|
1688
|
|
|
cmd = XmlCommand('modify_alert') |
1689
|
|
|
cmd.set_attribute('alert_id', str(alert_id)) |
1690
|
|
|
|
1691
|
|
|
if name: |
1692
|
|
|
cmd.add_element('name', name) |
1693
|
|
|
|
1694
|
|
|
if comment: |
1695
|
|
|
cmd.add_element('comment', comment) |
1696
|
|
|
|
1697
|
|
|
if filter_id: |
1698
|
|
|
cmd.add_element('filter', attrs={'id': filter_id}) |
1699
|
|
|
|
1700
|
|
|
conditions = cmd.add_element('condition', condition) |
1701
|
|
|
|
1702
|
|
|
if not condition_data is None: |
1703
|
|
|
for value, key in condition_data.items(): |
1704
|
|
|
_data = conditions.add_element('data', value) |
1705
|
|
|
_data.add_element('name', key) |
1706
|
|
|
|
1707
|
|
|
events = cmd.add_element('event', event) |
1708
|
|
|
|
1709
|
|
|
if not event_data is None: |
1710
|
|
|
for value, key in event_data.items(): |
1711
|
|
|
_data = events.add_element('data', value) |
1712
|
|
|
_data.add_element('name', key) |
1713
|
|
|
|
1714
|
|
|
methods = cmd.add_element('method', method) |
1715
|
|
|
|
1716
|
|
|
if not method_data is None: |
1717
|
|
|
for value, key in method_data.items(): |
1718
|
|
|
_data = methods.add_element('data', value) |
1719
|
|
|
_data.add_element('name', key) |
1720
|
|
|
|
1721
|
|
|
return self._send_xml_command(cmd) |
1722
|
|
|
|
1723
|
|
|
def modify_asset(self, asset_id, comment): |
1724
|
|
|
"""Generates xml string for modify asset on gvmd |
1725
|
|
|
|
1726
|
|
|
Arguments: |
1727
|
|
|
asset_id (str) UUID of the asset to be modified. |
1728
|
|
|
comment (str, optional): Comment for the asset. |
1729
|
|
|
""" |
1730
|
|
|
if not asset_id: |
1731
|
|
|
raise RequiredArgument('modify_asset requires an asset_id argument') |
1732
|
|
|
|
1733
|
|
|
cmd = XmlCommand('modify_asset') |
1734
|
|
|
cmd.set_attribute('asset_id', asset_id) |
1735
|
|
|
cmd.add_element('comment', comment) |
1736
|
|
|
|
1737
|
|
|
return self._send_xml_command(cmd) |
1738
|
|
|
|
1739
|
|
|
def modify_auth(self, group_name, auth_conf_settings): |
1740
|
|
|
"""Generates xml string for modify auth on gvmd. |
1741
|
|
|
Arguments: |
1742
|
|
|
group_name (str) Name of the group to be modified. |
1743
|
|
|
auth_conf_settings (dict): The new auth config. |
1744
|
|
|
""" |
1745
|
|
|
if not group_name: |
1746
|
|
|
raise RequiredArgument('modify_auth requires a group_name argument') |
1747
|
|
|
if not auth_conf_settings: |
1748
|
|
|
raise RequiredArgument('modify_auth requires an ' |
1749
|
|
|
'auth_conf_settings argument') |
1750
|
|
|
cmd = XmlCommand('modify_auth') |
1751
|
|
|
_xmlgroup = cmd.add_element('group', attrs={'name': str(group_name)}) |
1752
|
|
|
|
1753
|
|
|
for key, value in auth_conf_settings.items(): |
1754
|
|
|
_xmlauthconf = _xmlgroup.add_element('auth_conf_setting') |
1755
|
|
|
_xmlauthconf.add_element('key', key) |
1756
|
|
|
_xmlauthconf.add_element('value', value) |
1757
|
|
|
|
1758
|
|
|
return self._send_xml_command(cmd) |
1759
|
|
|
|
1760
|
|
|
def modify_config(self, selection, config_id=None, nvt_oids=None, name=None, |
1761
|
|
|
value=None, family=None): |
1762
|
|
|
"""Modifies an existing scan config on gvmd. |
1763
|
|
|
|
1764
|
|
|
Arguments: |
1765
|
|
|
selection (str): one of 'nvt_pref', nvt_selection or |
1766
|
|
|
family_selection' |
1767
|
|
|
config_id (str, optional): UUID of scan config to modify. |
1768
|
|
|
name (str, optional): New name for preference. |
1769
|
|
|
value(str, optional): New value for preference. |
1770
|
|
|
nvt_oids (list, optional): List of NVTs associated with preference |
1771
|
|
|
to modify. |
1772
|
|
|
family (str,optional): Name of family to modify. |
1773
|
|
|
""" |
1774
|
|
|
if selection not in ('nvt_pref', 'scan_pref', |
1775
|
|
|
'family_selection', 'nvt_selection'): |
1776
|
|
|
raise InvalidArgument('selection must be one of nvt_pref, ' |
1777
|
|
|
'sca_pref, family_selection or ' |
|
|
|
|
1778
|
|
|
'nvt_selection') |
1779
|
|
|
|
1780
|
|
|
cmd = XmlCommand('modify_config') |
1781
|
|
|
cmd.set_attribute('config_id', str(config_id)) |
1782
|
|
|
|
1783
|
|
|
if selection == 'nvt_pref': |
1784
|
|
|
_xmlpref = cmd.add_element('preference') |
1785
|
|
|
if not nvt_oids: |
1786
|
|
|
raise InvalidArgument('modify_config requires a nvt_oids ' |
1787
|
|
|
'argument') |
1788
|
|
|
_xmlpref.add_element('nvt', attrs={'oid': nvt_oids[0]}) |
1789
|
|
|
_xmlpref.add_element('name', name) |
1790
|
|
|
_xmlpref.add_element('value', value) |
1791
|
|
|
|
1792
|
|
|
elif selection == 'nvt_selection': |
1793
|
|
|
_xmlnvtsel = cmd.add_element('nvt_selection') |
1794
|
|
|
_xmlnvtsel.add_element('family', family) |
1795
|
|
|
|
1796
|
|
|
if nvt_oids: |
1797
|
|
|
for nvt in nvt_oids: |
1798
|
|
|
_xmlnvtsel.add_element('nvt', attrs={'oid': nvt}) |
1799
|
|
|
else: |
1800
|
|
|
raise InvalidArgument('modify_config requires a nvt_oid ' |
1801
|
|
|
'argument') |
1802
|
|
|
|
1803
|
|
|
elif selection == 'family_selection': |
1804
|
|
|
_xmlfamsel = cmd.add_element('family_selection') |
1805
|
|
|
_xmlfamsel.add_element('growing', '1') |
1806
|
|
|
_xmlfamily = _xmlfamsel.add_element('family') |
1807
|
|
|
_xmlfamily.add_element('name', family) |
1808
|
|
|
_xmlfamily.add_element('all', '1') |
1809
|
|
|
_xmlfamily.add_element('growing', '1') |
1810
|
|
|
|
1811
|
|
|
return self._send_xml_command(cmd) |
1812
|
|
|
|
1813
|
|
|
def modify_credential(self, credential_id, name=None, comment=None, |
|
|
|
|
1814
|
|
|
allow_insecure=None, certificate=None, |
1815
|
|
|
key_phrase=None, private_key=None, login=None, |
1816
|
|
|
password=None, auth_algorithm=None, community=None, |
1817
|
|
|
privacy_algorithm=None, privacy_password=None, |
1818
|
|
|
credential_type=None): |
1819
|
|
|
"""Generates xml string for modify credential on gvmd. |
1820
|
|
|
|
1821
|
|
|
Arguments: |
1822
|
|
|
credential_id (str): UUID of the credential |
1823
|
|
|
name (str, optional): Name of the credential |
1824
|
|
|
comment (str, optional): Comment for the credential |
1825
|
|
|
allow_insecure (boolean, optional): Whether to allow insecure use of |
1826
|
|
|
the credential |
1827
|
|
|
certificate (str, optional): Certificate for the credential |
1828
|
|
|
key_phrase (str, optional): Key passphrase for the private key |
1829
|
|
|
private_key (str, optional): Private key to use for login |
1830
|
|
|
login (str, optional): Username for the credential |
1831
|
|
|
password (str, optional): Password for the credential |
1832
|
|
|
auth_algorithm (str, optional): The auth_algorithm, |
1833
|
|
|
either md5 or sha1. |
1834
|
|
|
community (str, optional): The SNMP community |
1835
|
|
|
privacy_algorithm (str, optional): The SNMP privacy algorithm, |
1836
|
|
|
either aes or des. |
1837
|
|
|
privacy_password (str, optional): The SNMP privacy password |
1838
|
|
|
credential_type (str, optional): The credential type. One of 'cc', |
1839
|
|
|
'snmp', 'up', 'usk' |
1840
|
|
|
""" |
1841
|
|
|
if not credential_id: |
1842
|
|
|
raise RequiredArgument('modify_credential requires ' |
1843
|
|
|
'a credential_id attribute') |
1844
|
|
|
|
1845
|
|
|
cmd = XmlCommand('modify_credential') |
1846
|
|
|
cmd.set_attribute('credential_id', credential_id) |
1847
|
|
|
|
1848
|
|
|
if comment: |
1849
|
|
|
cmd.add_element('comment', comment) |
1850
|
|
|
|
1851
|
|
|
if name: |
1852
|
|
|
cmd.add_element('name', name) |
1853
|
|
|
|
1854
|
|
|
if allow_insecure: |
1855
|
|
|
cmd.add_element('allow_insecure', allow_insecure) |
1856
|
|
|
|
1857
|
|
|
if certificate: |
1858
|
|
|
cmd.add_element('certificate', certificate) |
1859
|
|
|
|
1860
|
|
|
if key_phrase or private_key: |
1861
|
|
|
if not key_phrase or not private_key: |
1862
|
|
|
raise RequiredArgument('modify_credential requires ' |
1863
|
|
|
'a key_phrase and private_key arguments') |
1864
|
|
|
_xmlkey = cmd.add_element('key') |
1865
|
|
|
_xmlkey.add_element('phrase', key_phrase) |
1866
|
|
|
_xmlkey.add_element('private', private_key) |
1867
|
|
|
|
1868
|
|
|
if login: |
1869
|
|
|
cmd.add_element('login', login) |
1870
|
|
|
|
1871
|
|
|
if password: |
1872
|
|
|
cmd.add_element('password', password) |
1873
|
|
|
|
1874
|
|
|
if auth_algorithm: |
1875
|
|
|
if auth_algorithm not in ('md5', 'sha1'): |
1876
|
|
|
raise RequiredArgument('modify_credential requires ' |
1877
|
|
|
'auth_algorithm to be either ' |
1878
|
|
|
'md5 or sha1') |
1879
|
|
|
cmd.add_element('auth_algorithm', auth_algorithm) |
1880
|
|
|
|
1881
|
|
|
if community: |
1882
|
|
|
cmd.add_element('community', community) |
1883
|
|
|
|
1884
|
|
|
if privacy_algorithm: |
1885
|
|
|
if privacy_algorithm not in ('aes', 'des'): |
1886
|
|
|
raise RequiredArgument('modify_credential requires ' |
1887
|
|
|
'privacy_algorithm to be either' |
1888
|
|
|
'aes or des') |
1889
|
|
|
_xmlprivacy = cmd.add_element('privacy') |
1890
|
|
|
_xmlprivacy.add_element('algorithm', privacy_algorithm) |
1891
|
|
|
_xmlprivacy.add_element('password', privacy_password) |
1892
|
|
|
|
1893
|
|
|
if cred_type: |
|
|
|
|
1894
|
|
|
if cred_type not in ('cc', 'snmp', 'up', 'usk'): |
|
|
|
|
1895
|
|
|
raise RequiredArgument('modify_credential requires type ' |
1896
|
|
|
'to be either cc, snmp, up or usk') |
|
|
|
|
1897
|
|
|
cmd.add_element('type', credential_type) |
1898
|
|
|
|
1899
|
|
|
return self._send_xml_command(cmd) |
1900
|
|
|
|
1901
|
|
|
def modify_filter(self, filter_id, comment=None, name=None, term=None, |
1902
|
|
|
filter_type=None): |
1903
|
|
|
"""Generates xml string for modify filter on gvmd. |
1904
|
|
|
|
1905
|
|
|
Arguments: |
1906
|
|
|
filter_id (str): UUID of the filter to be modified |
1907
|
|
|
comment (str, optional): Comment on filter. |
1908
|
|
|
name (str, optional): Name of filter. |
1909
|
|
|
term (str, optional): Filter term. |
1910
|
|
|
filter_type (str, optional): Resource type filter applies to. |
1911
|
|
|
""" |
1912
|
|
|
if not filter_id: |
1913
|
|
|
raise RequiredArgument('modify_filter requires a filter_id ' |
1914
|
|
|
'attribute') |
1915
|
|
|
|
1916
|
|
|
cmd = XmlCommand('modify_filter') |
1917
|
|
|
cmd.set_attribute('filter_id', filter_id) |
1918
|
|
|
|
1919
|
|
|
if comment: |
1920
|
|
|
cmd.add_element('comment', comment) |
1921
|
|
|
|
1922
|
|
|
if name: |
1923
|
|
|
cmd.add_element('name', name) |
1924
|
|
|
|
1925
|
|
|
if term: |
1926
|
|
|
cmd.add_element('term', term) |
1927
|
|
|
|
1928
|
|
|
if filter_type: |
1929
|
|
|
filter_type = filter_type.lower() |
1930
|
|
|
if filter_type not in FILTER_TYPES: |
1931
|
|
|
raise InvalidArgument( |
1932
|
|
|
'modify_filter requires type to be one of {0} but ' |
1933
|
|
|
'was {1}'.format(', '.join(FILTER_TYPES), filter_type)) |
1934
|
|
|
cmd.add_element('type', filter_type) |
1935
|
|
|
|
1936
|
|
|
return self._send_xml_command(cmd) |
1937
|
|
|
|
1938
|
|
|
def modify_group(self, group_id, **kwargs): |
1939
|
|
|
cmd = self._generator.modify_group_command(group_id, kwargs) |
1940
|
|
|
return self.send_command(cmd) |
1941
|
|
|
|
1942
|
|
|
def modify_note(self, note_id, text, **kwargs): |
1943
|
|
|
cmd = self._generator.modify_note_command(note_id, text, kwargs) |
1944
|
|
|
return self.send_command(cmd) |
1945
|
|
|
|
1946
|
|
|
def modify_override(self, override_id, text, **kwargs): |
1947
|
|
|
cmd = self._generator.modify_override_command(override_id, text, |
1948
|
|
|
kwargs) |
1949
|
|
|
return self.send_command(cmd) |
1950
|
|
|
|
1951
|
|
|
def modify_permission(self, permission_id, **kwargs): |
1952
|
|
|
cmd = self._generator.modify_permission_command( |
1953
|
|
|
permission_id, kwargs) |
1954
|
|
|
return self.send_command(cmd) |
1955
|
|
|
|
1956
|
|
|
def modify_port_list(self, port_list_id, **kwargs): |
1957
|
|
|
cmd = self._generator.modify_port_list_command(port_list_id, kwargs) |
1958
|
|
|
return self.send_command(cmd) |
1959
|
|
|
|
1960
|
|
|
def modify_report(self, report_id, comment): |
1961
|
|
|
cmd = self._generator.modify_report_format_command(report_id, comment) |
1962
|
|
|
return self.send_command(cmd) |
1963
|
|
|
|
1964
|
|
|
def modify_report_format(self, report_format_id, **kwargs): |
1965
|
|
|
cmd = self._generator.modify_report_format_command(report_format_id, |
1966
|
|
|
kwargs) |
1967
|
|
|
return self.send_command(cmd) |
1968
|
|
|
|
1969
|
|
|
def modify_role(self, role_id, **kwargs): |
1970
|
|
|
cmd = self._generator.modify_role_command(role_id, kwargs) |
1971
|
|
|
return self.send_command(cmd) |
1972
|
|
|
|
1973
|
|
|
def modify_scanner(self, scanner_id, host, port, scanner_type, **kwargs): |
1974
|
|
|
cmd = self._generator.modify_scanner_command(scanner_id, host, port, |
1975
|
|
|
scanner_type, kwargs) |
1976
|
|
|
return self.send_command(cmd) |
1977
|
|
|
|
1978
|
|
|
def modify_schedule(self, schedule_id, **kwargs): |
1979
|
|
|
cmd = self._generator.modify_schedule_command(schedule_id, kwargs) |
1980
|
|
|
return self.send_command(cmd) |
1981
|
|
|
|
1982
|
|
|
def modify_setting(self, setting_id, name, value): |
1983
|
|
|
cmd = self._generator.modify_setting_command(setting_id, name, value) |
1984
|
|
|
return self.send_command(cmd) |
1985
|
|
|
|
1986
|
|
|
def modify_tag(self, tag_id, **kwargs): |
1987
|
|
|
cmd = self._generator.modify_tag_command(tag_id, kwargs) |
1988
|
|
|
return self.send_command(cmd) |
1989
|
|
|
|
1990
|
|
|
def modify_target(self, target_id, **kwargs): |
1991
|
|
|
cmd = self._generator.modify_target_command(target_id, kwargs) |
1992
|
|
|
return self.send_command(cmd) |
1993
|
|
|
|
1994
|
|
|
def modify_task(self, task_id, **kwargs): |
1995
|
|
|
cmd = self._generator.modify_task_command(task_id, kwargs) |
1996
|
|
|
return self.send_command(cmd) |
1997
|
|
|
|
1998
|
|
|
def modify_user(self, **kwargs): |
1999
|
|
|
cmd = self._generator.modify_user_command(kwargs) |
2000
|
|
|
return self.send_command(cmd) |
2001
|
|
|
|
2002
|
|
|
def move_task(self, task_id, slave_id): |
2003
|
|
|
cmd = self._generator.move_task_command(task_id, slave_id) |
2004
|
|
|
return self.send_command(cmd) |
2005
|
|
|
|
2006
|
|
|
def restore(self, entity_id): |
2007
|
|
|
cmd = self._generator.restore_command(entity_id) |
2008
|
|
|
return self.send_command(cmd) |
2009
|
|
|
|
2010
|
|
|
def resume_task(self, task_id): |
2011
|
|
|
cmd = self._generator.resume_task_command(task_id) |
2012
|
|
|
return self.send_command(cmd) |
2013
|
|
|
|
2014
|
|
|
def start_task(self, task_id): |
2015
|
|
|
cmd = self._generator.start_task_command(task_id) |
2016
|
|
|
return self.send_command(cmd) |
2017
|
|
|
|
2018
|
|
|
def stop_task(self, task_id): |
2019
|
|
|
cmd = self._generator.stop_task_command(task_id) |
2020
|
|
|
return self.send_command(cmd) |
2021
|
|
|
|
2022
|
|
|
def sync_cert(self): |
2023
|
|
|
cmd = self._generator.sync_cert_command() |
2024
|
|
|
return self.send_command(cmd) |
2025
|
|
|
|
2026
|
|
|
def sync_config(self): |
2027
|
|
|
cmd = self._generator.sync_config_command() |
2028
|
|
|
return self.send_command(cmd) |
2029
|
|
|
|
2030
|
|
|
def sync_feed(self): |
2031
|
|
|
cmd = self._generator.sync_feed_command() |
2032
|
|
|
return self.send_command(cmd) |
2033
|
|
|
|
2034
|
|
|
def sync_scap(self): |
2035
|
|
|
cmd = self._generator.sync_scap_command() |
2036
|
|
|
return self.send_command(cmd) |
2037
|
|
|
|
2038
|
|
|
def test_alert(self, alert_id): |
2039
|
|
|
cmd = self._generator.test_alert_command(alert_id) |
2040
|
|
|
return self.send_command(cmd) |
2041
|
|
|
|
2042
|
|
|
def verify_agent(self, agent_id): |
2043
|
|
|
cmd = self._generator.verify_agent_command(agent_id) |
2044
|
|
|
return self.send_command(cmd) |
2045
|
|
|
|
2046
|
|
|
def verify_report_format(self, report_format_id): |
2047
|
|
|
cmd = self._generator.verify_report_format_command(report_format_id) |
2048
|
|
|
return self.send_command(cmd) |
2049
|
|
|
|
2050
|
|
|
def verify_scanner(self, scanner_id): |
2051
|
|
|
cmd = self._generator.verify_scanner_command(scanner_id) |
2052
|
|
|
return self.send_command(cmd) |
2053
|
|
|
|