|
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
|
|
|
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
|
|
|
def _to_bool(value): |
|
102
|
|
|
return '1' if value else '0' |
|
103
|
|
|
|
|
104
|
|
|
|
|
105
|
|
|
def _add_filter(cmd, filter, filter_id): |
|
106
|
|
|
if filter: |
|
107
|
|
|
cmd.set_attribute('filter', filter) |
|
108
|
|
|
|
|
109
|
|
|
if filter_id: |
|
110
|
|
|
cmd.set_attribute('filt_id', filter_id) |
|
111
|
|
|
|
|
112
|
|
|
|
|
113
|
|
|
class Gmp(GvmProtocol): |
|
|
|
|
|
|
114
|
|
|
"""Python interface for Greenbone Management Protocol |
|
115
|
|
|
|
|
116
|
|
|
This class implements the `Greenbone Management Protocol version 7`_ |
|
117
|
|
|
|
|
118
|
|
|
Attributes: |
|
119
|
|
|
connection (:class:`gvm.connections.GvmConnection`): Connection to use |
|
120
|
|
|
to talk with the gvmd daemon. See :mod:`gvm.connections` for |
|
121
|
|
|
possible connection types. |
|
122
|
|
|
transform (`callable`_, optional): Optional transform callable to |
|
123
|
|
|
convert response data. After each request the callable gets passed |
|
124
|
|
|
the plain response data which can be used to check the data and/or |
|
125
|
|
|
conversion into different representaitions like a xml dom. |
|
126
|
|
|
|
|
127
|
|
|
See :mod:`gvm.transforms` for existing transforms. |
|
128
|
|
|
|
|
129
|
|
|
.. _Greenbone Management Protocol version 7: |
|
130
|
|
|
https://docs.greenbone.net/API/GMP/gmp-7.0.html |
|
131
|
|
|
.. _callable: |
|
132
|
|
|
https://docs.python.org/3.6/library/functions.html#callable |
|
133
|
|
|
""" |
|
134
|
|
|
|
|
135
|
|
|
def __init__(self, connection, transform=None): |
|
136
|
|
|
super().__init__(connection, transform) |
|
137
|
|
|
|
|
138
|
|
|
# Is authenticated on gvmd |
|
139
|
|
|
self._authenticated = False |
|
140
|
|
|
|
|
141
|
|
|
# GMP Message Creator |
|
142
|
|
|
self._generator = GmpCommandFactory() |
|
143
|
|
|
|
|
144
|
|
|
@staticmethod |
|
145
|
|
|
def get_protocol_version(): |
|
146
|
|
|
"""Allow to determine the Greenbone Management Protocol version. |
|
147
|
|
|
|
|
148
|
|
|
Returns: |
|
149
|
|
|
str: Implemented version of the Greenbone Management Protocol |
|
150
|
|
|
""" |
|
151
|
|
|
return get_version_string(PROTOCOL_VERSION) |
|
152
|
|
|
|
|
153
|
|
|
def is_authenticated(self): |
|
154
|
|
|
"""Checks if the user is authenticated |
|
155
|
|
|
|
|
156
|
|
|
If the user is authenticated privilged GMP commands like get_tasks |
|
157
|
|
|
may be send to gvmd. |
|
158
|
|
|
|
|
159
|
|
|
Returns: |
|
160
|
|
|
bool: True if an authenticated connection to gvmd has been |
|
161
|
|
|
established. |
|
162
|
|
|
""" |
|
163
|
|
|
return self._authenticated |
|
164
|
|
|
|
|
165
|
|
|
def authenticate(self, username, password): |
|
166
|
|
|
"""Authenticate to gvmd. |
|
167
|
|
|
|
|
168
|
|
|
The generated authenticate command will be send to server. |
|
169
|
|
|
Afterwards the response is read, transformed and returned. |
|
170
|
|
|
|
|
171
|
|
|
Arguments: |
|
172
|
|
|
username (str): Username |
|
173
|
|
|
password (str): Password |
|
174
|
|
|
|
|
175
|
|
|
Returns: |
|
176
|
|
|
any, str by default: Transformed response from server. |
|
177
|
|
|
""" |
|
178
|
|
|
cmd = XmlCommand('authenticate') |
|
179
|
|
|
|
|
180
|
|
|
if not username: |
|
181
|
|
|
raise RequiredArgument('authenticate requires username') |
|
182
|
|
|
|
|
183
|
|
|
if not password: |
|
184
|
|
|
raise RequiredArgument('authenticate requires password') |
|
185
|
|
|
|
|
186
|
|
|
credentials = cmd.add_element('credentials') |
|
187
|
|
|
credentials.add_element('username', username) |
|
188
|
|
|
credentials.add_element('password', password) |
|
189
|
|
|
|
|
190
|
|
|
self._send(cmd.to_string()) |
|
191
|
|
|
response = self._read() |
|
192
|
|
|
|
|
193
|
|
|
if _check_command_status(response): |
|
194
|
|
|
self._authenticated = True |
|
195
|
|
|
|
|
196
|
|
|
return self._transform(response) |
|
197
|
|
|
|
|
198
|
|
|
def create_agent(self, installer, signature, name, comment=None, |
|
199
|
|
|
howto_install=None, howto_use=None): |
|
200
|
|
|
"""Create a new agent |
|
201
|
|
|
|
|
202
|
|
|
Arguments: |
|
203
|
|
|
installer (str): A base64 encoded file that installs the agent on a |
|
204
|
|
|
target machine |
|
205
|
|
|
signature: (str): A detached OpenPGP signature of the installer |
|
206
|
|
|
name (str): A name for the agent |
|
207
|
|
|
comment (str, optional): A comment for the agent |
|
208
|
|
|
howto_install (str, optional): A file that describes how to install |
|
209
|
|
|
the agent |
|
210
|
|
|
howto_use (str, optional): A file that describes how to use the |
|
211
|
|
|
agent |
|
212
|
|
|
|
|
213
|
|
|
Returns: |
|
214
|
|
|
The response. See :py:meth:`send_command` for details. |
|
215
|
|
|
""" |
|
216
|
|
|
if not name: |
|
217
|
|
|
raise RequiredArgument('create_agent requires name argument') |
|
218
|
|
|
|
|
219
|
|
|
if not installer: |
|
220
|
|
|
raise RequiredArgument('create_agent requires installer argument') |
|
221
|
|
|
|
|
222
|
|
|
if not signature: |
|
223
|
|
|
raise RequiredArgument('create_agent requires signature argument') |
|
224
|
|
|
|
|
225
|
|
|
cmd = XmlCommand('create_agent') |
|
226
|
|
|
cmd.add_element('installer', installer) |
|
227
|
|
|
cmd.add_element('signature', signature) |
|
228
|
|
|
cmd.add_element('name', name) |
|
229
|
|
|
|
|
230
|
|
|
if comment: |
|
231
|
|
|
cmd.add_element('comment', comment) |
|
232
|
|
|
|
|
233
|
|
|
if howto_install: |
|
234
|
|
|
cmd.add_element('howto_install', howto_install) |
|
235
|
|
|
|
|
236
|
|
|
if howto_use: |
|
237
|
|
|
cmd.add_element('howto_use', howto_use) |
|
238
|
|
|
|
|
239
|
|
|
return self._send_xml_command(cmd) |
|
240
|
|
|
|
|
241
|
|
|
def clone_agent(self, agent_id): |
|
242
|
|
|
"""Clone an existing agent |
|
243
|
|
|
|
|
244
|
|
|
Arguments: |
|
245
|
|
|
copy (str): UUID of an existing agent to clone from |
|
246
|
|
|
|
|
247
|
|
|
Returns: |
|
248
|
|
|
The response. See :py:meth:`send_command` for details. |
|
249
|
|
|
""" |
|
250
|
|
|
cmd = XmlCommand('create_agent') |
|
251
|
|
|
cmd.add_element('copy', agent_id) |
|
252
|
|
|
return self._send_xml_command(cmd) |
|
253
|
|
|
|
|
254
|
|
|
def create_alert(self, name, condition, event, method, method_data=None, |
|
|
|
|
|
|
255
|
|
|
event_data=None, condition_data=None, filter_id=None, |
|
256
|
|
|
comment=None): |
|
257
|
|
|
"""Create a new alert |
|
258
|
|
|
|
|
259
|
|
|
Arguments: |
|
260
|
|
|
name (str): Name of the new Alert |
|
261
|
|
|
condition (str): The condition that must be satisfied for the alert |
|
262
|
|
|
to occur. |
|
263
|
|
|
event (str): The event that must happen for the alert to occur |
|
264
|
|
|
method (str): The method by which the user is alerted |
|
265
|
|
|
condition_data (dict, optional): Data that defines the condition |
|
266
|
|
|
event_data (dict, optional): Data that defines the event |
|
267
|
|
|
method_data (dict, optional): Data that defines the method |
|
268
|
|
|
filter_id (str, optional): Filter to apply when executing alert |
|
269
|
|
|
comment (str, optional): Comment for the alert |
|
270
|
|
|
|
|
271
|
|
|
Returns: |
|
272
|
|
|
The response. See :py:meth:`send_command` for details. |
|
273
|
|
|
""" |
|
274
|
|
|
if not name: |
|
275
|
|
|
raise RequiredArgument('create_alert requires name argument') |
|
276
|
|
|
|
|
277
|
|
|
if condition is None or len(condition) == 0: |
|
278
|
|
|
raise RequiredArgument('create_alert requires condition argument') |
|
279
|
|
|
|
|
280
|
|
|
if event is None or len(event) == 0: |
|
281
|
|
|
raise RequiredArgument('create_alert requires event argument') |
|
282
|
|
|
|
|
283
|
|
|
cmd = XmlCommand('create_alert') |
|
284
|
|
|
cmd.add_element('name', name) |
|
285
|
|
|
|
|
286
|
|
|
conditions = cmd.add_element('condition', condition) |
|
287
|
|
|
|
|
288
|
|
|
if not condition_data is None: |
|
289
|
|
|
for value, key in condition_data.items(): |
|
290
|
|
|
_data = conditions.add_element('data', value) |
|
291
|
|
|
_data.add_element('name', key) |
|
292
|
|
|
|
|
293
|
|
|
events = cmd.add_element('event', event) |
|
294
|
|
|
|
|
295
|
|
|
if not event_data is None: |
|
296
|
|
|
for value, key in event_data.items(): |
|
297
|
|
|
_data = events.add_element('data', value) |
|
298
|
|
|
_data.add_element('name', key) |
|
299
|
|
|
|
|
300
|
|
|
methods = cmd.add_element('method', method) |
|
301
|
|
|
|
|
302
|
|
|
if not method_data is None: |
|
303
|
|
|
for value, key in method_data.items(): |
|
304
|
|
|
_data = methods.add_element('data', value) |
|
305
|
|
|
_data.add_element('name', key) |
|
306
|
|
|
|
|
307
|
|
|
if filter_id: |
|
308
|
|
|
cmd.add_element('filter', attrs={'id': filter_id}) |
|
309
|
|
|
|
|
310
|
|
|
if comment: |
|
311
|
|
|
cmd.add_element('comment', comment) |
|
312
|
|
|
|
|
313
|
|
|
return self._send_xml_command(cmd) |
|
314
|
|
|
|
|
315
|
|
|
def clone_alert(self, alert_id): |
|
316
|
|
|
"""Clone an existing alert |
|
317
|
|
|
|
|
318
|
|
|
Arguments: |
|
319
|
|
|
copy (str): UUID of an existing alert to clone from |
|
320
|
|
|
|
|
321
|
|
|
Returns: |
|
322
|
|
|
The response. See :py:meth:`send_command` for details. |
|
323
|
|
|
""" |
|
324
|
|
|
cmd = XmlCommand('create_alert') |
|
325
|
|
|
cmd.add_element('copy', alert_id) |
|
326
|
|
|
return self._send_xml_command(cmd) |
|
327
|
|
|
|
|
328
|
|
|
def create_asset(self, name, asset_type, comment=None): |
|
329
|
|
|
"""Create a new asset |
|
330
|
|
|
|
|
331
|
|
|
Arguments: |
|
332
|
|
|
name (str): Name for the new asset |
|
333
|
|
|
asset_type (str): Either 'os' or 'host' |
|
334
|
|
|
comment (str, optional): Comment for the new asset |
|
335
|
|
|
|
|
336
|
|
|
Returns: |
|
337
|
|
|
The response. See :py:meth:`send_command` for details. |
|
338
|
|
|
""" |
|
339
|
|
|
if asset_type not in ('host', 'os'): |
|
340
|
|
|
raise InvalidArgument( |
|
341
|
|
|
'create_asset requires asset_type to be either host or os') |
|
342
|
|
|
|
|
343
|
|
|
if not name: |
|
344
|
|
|
raise RequiredArgument('create_asset requires name argument') |
|
345
|
|
|
|
|
346
|
|
|
cmd = XmlCommand('create_asset') |
|
347
|
|
|
asset = cmd.add_element('asset') |
|
348
|
|
|
asset.add_element('type', asset_type) |
|
349
|
|
|
asset.add_element('name', name) |
|
350
|
|
|
|
|
351
|
|
|
if comment: |
|
352
|
|
|
asset.add_element('comment', comment) |
|
353
|
|
|
|
|
354
|
|
|
return self._send_xml_command(cmd) |
|
355
|
|
|
|
|
356
|
|
|
def create_config(self, name, copy): |
|
357
|
|
|
"""Create a new scan config from an existing one |
|
358
|
|
|
|
|
359
|
|
|
Arguments: |
|
360
|
|
|
name (str): Name of the new scan config |
|
361
|
|
|
copy (str): UUID of the existing scan config |
|
362
|
|
|
|
|
363
|
|
|
Returns: |
|
364
|
|
|
The response. See :py:meth:`send_command` for details. |
|
365
|
|
|
""" |
|
366
|
|
|
if not name: |
|
367
|
|
|
raise RequiredArgument('create_config requires name argument') |
|
368
|
|
|
|
|
369
|
|
|
if not copy: |
|
370
|
|
|
raise RequiredArgument('create_config requires copy argument') |
|
371
|
|
|
|
|
372
|
|
|
cmd = XmlCommand('create_config') |
|
373
|
|
|
cmd.add_element('copy', copy) |
|
374
|
|
|
cmd.add_element('name', name) |
|
375
|
|
|
return self._send_xml_command(cmd) |
|
376
|
|
|
|
|
377
|
|
|
def create_credential(self, name, comment=None, allow_insecure=False, |
|
|
|
|
|
|
378
|
|
|
certificate=None, key_phrase=None, private_key=None, |
|
379
|
|
|
login=None, password=None, auth_algorithm=None, |
|
380
|
|
|
community=None, privacy_algorithm=None, |
|
381
|
|
|
privacy_password=None, credential_type=None): |
|
382
|
|
|
"""Create a new credential |
|
383
|
|
|
|
|
384
|
|
|
Arguments: |
|
385
|
|
|
name (str): Name of the new credential |
|
386
|
|
|
comment (str, optional): Comment for the credential |
|
387
|
|
|
allow_insecure (boolean, optional): Whether to allow insecure use of |
|
388
|
|
|
the credential |
|
389
|
|
|
certificate (str, optional): Certificate for the credential |
|
390
|
|
|
key_phrase (str, optional): Key passphrase for the private key |
|
391
|
|
|
private_key (str, optional): Private key to use for login |
|
392
|
|
|
login (str, optional): Username for the credential |
|
393
|
|
|
password (str, optional): Password for the credential |
|
394
|
|
|
community (str, optional): The SNMP community |
|
395
|
|
|
privacy_alogorithm (str, optional): The SNMP privacy algorithm, |
|
396
|
|
|
either aes or des. |
|
397
|
|
|
privacy_password (str, optional): The SNMP privacy password |
|
398
|
|
|
credential_type (str, optional): The credential type. One of 'cc', |
|
399
|
|
|
'snmp', 'up', 'usk' |
|
400
|
|
|
|
|
401
|
|
|
Returns: |
|
402
|
|
|
The response. See :py:meth:`send_command` for details. |
|
403
|
|
|
""" |
|
404
|
|
|
if not name: |
|
405
|
|
|
raise RequiredArgument('create_credential requires name argument') |
|
406
|
|
|
|
|
407
|
|
|
cmd = XmlCommand('create_credential') |
|
408
|
|
|
cmd.add_element('name', name) |
|
409
|
|
|
|
|
410
|
|
|
if comment: |
|
411
|
|
|
cmd.add_element('comment', comment) |
|
412
|
|
|
|
|
413
|
|
|
if allow_insecure: |
|
414
|
|
|
cmd.add_element('allow_insecure', '1') |
|
415
|
|
|
|
|
416
|
|
|
if certificate: |
|
417
|
|
|
cmd.add_element('certificate', certificate) |
|
418
|
|
|
|
|
419
|
|
|
if not key_phrase is None and private_key: |
|
420
|
|
|
_xmlkey = cmd.add_element('key') |
|
421
|
|
|
_xmlkey.add_element('phrase', key_phrase) |
|
422
|
|
|
_xmlkey.add_element('private', private_key) |
|
423
|
|
|
|
|
424
|
|
|
if login: |
|
425
|
|
|
cmd.add_element('login', login) |
|
426
|
|
|
|
|
427
|
|
|
if password: |
|
428
|
|
|
cmd.add_element('password', password) |
|
429
|
|
|
|
|
430
|
|
|
if auth_algorithm: |
|
431
|
|
|
if auth_algorithm not in ('md5', 'sha1'): |
|
432
|
|
|
raise InvalidArgument( |
|
433
|
|
|
'create_credential requires auth_algorithm to be either ' |
|
434
|
|
|
'md5 or sha1') |
|
435
|
|
|
cmd.add_element('auth_algorithm', auth_algorithm) |
|
436
|
|
|
|
|
437
|
|
|
if community: |
|
438
|
|
|
cmd.add_element('community', community) |
|
439
|
|
|
|
|
440
|
|
|
if privacy_algorithm and privacy_password: |
|
441
|
|
|
if privacy_algorithm not in ('aes', 'des'): |
|
442
|
|
|
raise InvalidArgument( |
|
443
|
|
|
'create_credential requires algorithm to be either aes or ' |
|
444
|
|
|
'des') |
|
445
|
|
|
_xmlprivacy = cmd.add_element('privacy') |
|
446
|
|
|
_xmlprivacy.add_element('algorithm', privacy_algorithm) |
|
447
|
|
|
_xmlprivacy.add_element('password', privacy_password) |
|
448
|
|
|
|
|
449
|
|
|
if credential_type: |
|
450
|
|
|
if credential_type not in ('cc', 'snmp', 'up', 'usk'): |
|
451
|
|
|
raise InvalidArgument( |
|
452
|
|
|
'create_credential requires type to be either cc, snmp, up ' |
|
453
|
|
|
' or usk') |
|
454
|
|
|
cmd.add_element('type', credential_type) |
|
455
|
|
|
|
|
456
|
|
|
return self._send_xml_command(cmd) |
|
457
|
|
|
|
|
458
|
|
|
def clone_credential(self, credential_id): |
|
459
|
|
|
"""Clone an existing credential |
|
460
|
|
|
|
|
461
|
|
|
Arguments: |
|
462
|
|
|
copy (str): UUID of an existing credential to clone from |
|
463
|
|
|
|
|
464
|
|
|
Returns: |
|
465
|
|
|
The response. See :py:meth:`send_command` for details. |
|
466
|
|
|
""" |
|
467
|
|
|
cmd = XmlCommand('create_credential') |
|
468
|
|
|
cmd.add_element('copy', credential_id) |
|
469
|
|
|
return self._send_xml_command(cmd) |
|
470
|
|
|
|
|
471
|
|
|
def create_filter(self, name, make_unique=False, filter_type=None, |
|
472
|
|
|
comment=None, term=None): |
|
473
|
|
|
"""Create a new filter |
|
474
|
|
|
|
|
475
|
|
|
Arguments: |
|
476
|
|
|
name (str): Name of the new filter |
|
477
|
|
|
make_unique (boolean, optional): |
|
478
|
|
|
filter_type (str, optional): Filter for entity type |
|
479
|
|
|
comment (str, optional): Comment for the filter |
|
480
|
|
|
term (str, optional): Filter term e.g. 'name=foo' |
|
481
|
|
|
|
|
482
|
|
|
Returns: |
|
483
|
|
|
The response. See :py:meth:`send_command` for details. |
|
484
|
|
|
""" |
|
485
|
|
|
if not name: |
|
486
|
|
|
raise RequiredArgument('create_filter requires a name argument') |
|
487
|
|
|
|
|
488
|
|
|
cmd = XmlCommand('create_filter') |
|
489
|
|
|
_xmlname = cmd.add_element('name', name) |
|
490
|
|
|
if make_unique: |
|
491
|
|
|
_xmlname.add_element('make_unique', '1') |
|
492
|
|
|
|
|
493
|
|
|
if comment: |
|
494
|
|
|
cmd.add_element('comment', comment) |
|
495
|
|
|
|
|
496
|
|
|
if term: |
|
497
|
|
|
cmd.add_element('term', term) |
|
498
|
|
|
|
|
499
|
|
|
if filter_type: |
|
500
|
|
|
filter_type = filter_type.lower() |
|
501
|
|
|
if filter_type not in FILTER_TYPES: |
|
502
|
|
|
raise InvalidArgument( |
|
503
|
|
|
'create_filter requires type to be one of {0} but ' |
|
504
|
|
|
'was {1}'.format(', '.join(FILTER_TYPES), filter_type)) |
|
505
|
|
|
cmd.add_element('type', filter_type) |
|
506
|
|
|
|
|
507
|
|
|
return self._send_xml_command(cmd) |
|
508
|
|
|
|
|
509
|
|
|
def clone_filter(self, filter_id): |
|
510
|
|
|
"""Clone an existing filter |
|
511
|
|
|
|
|
512
|
|
|
Arguments: |
|
513
|
|
|
copy (str): UUID of an existing filter to clone from |
|
514
|
|
|
|
|
515
|
|
|
Returns: |
|
516
|
|
|
The response. See :py:meth:`send_command` for details. |
|
517
|
|
|
""" |
|
518
|
|
|
cmd = XmlCommand('create_filter') |
|
519
|
|
|
cmd.add_element('copy', filter_id) |
|
520
|
|
|
return self._send_xml_command(cmd) |
|
521
|
|
|
|
|
522
|
|
|
def create_group(self, name, comment=None, special=False, users=None): |
|
523
|
|
|
"""Create a new group |
|
524
|
|
|
|
|
525
|
|
|
Arguments: |
|
526
|
|
|
name (str): Name of the new group |
|
527
|
|
|
comment (str, optional): Comment for the group |
|
528
|
|
|
special (boolean, optional): Create permission giving members full |
|
529
|
|
|
access to each other's entities |
|
530
|
|
|
users (list, optional): List of user names to be in the group |
|
531
|
|
|
|
|
532
|
|
|
Returns: |
|
533
|
|
|
The response. See :py:meth:`send_command` for details. |
|
534
|
|
|
""" |
|
535
|
|
|
if not name: |
|
536
|
|
|
raise RequiredArgument('create_group requires a name argument') |
|
537
|
|
|
|
|
538
|
|
|
cmd = XmlCommand('create_group') |
|
539
|
|
|
cmd.add_element('name', name) |
|
540
|
|
|
|
|
541
|
|
|
if comment: |
|
542
|
|
|
cmd.add_element('comment', comment) |
|
543
|
|
|
|
|
544
|
|
|
if special: |
|
545
|
|
|
_xmlspecial = cmd.add_element('specials') |
|
546
|
|
|
_xmlspecial.add_element('full') |
|
547
|
|
|
|
|
548
|
|
|
if users: |
|
549
|
|
|
cmd.add_element('users', ','.join(users)) |
|
550
|
|
|
|
|
551
|
|
|
return self._send_xml_command(cmd) |
|
552
|
|
|
|
|
553
|
|
|
def clone_group(self, group_id): |
|
554
|
|
|
"""Clone an existing group |
|
555
|
|
|
|
|
556
|
|
|
Arguments: |
|
557
|
|
|
copy (str): UUID of an existing group to clone from |
|
558
|
|
|
|
|
559
|
|
|
Returns: |
|
560
|
|
|
The response. See :py:meth:`send_command` for details. |
|
561
|
|
|
""" |
|
562
|
|
|
cmd = XmlCommand('create_group') |
|
563
|
|
|
cmd.add_element('copy', group_id) |
|
564
|
|
|
return self._send_xml_command(cmd) |
|
565
|
|
|
|
|
566
|
|
|
def create_note(self, text, nvt_oid, seconds_active=None, comment=None, |
|
567
|
|
|
hosts=None, result_id=None, severity=None, task_id=None, |
|
568
|
|
|
threat=None, port=None): |
|
569
|
|
|
"""Create a new note |
|
570
|
|
|
|
|
571
|
|
|
Arguments: |
|
572
|
|
|
text (str): Text of the new note |
|
573
|
|
|
nvt_id (str): OID of the nvt to which note applies |
|
574
|
|
|
seconds_active (int, optional): Seconds note will be active. -1 on |
|
575
|
|
|
always, 0 off |
|
576
|
|
|
comment (str, optional): Comment for the note |
|
577
|
|
|
hosts (list, optional): A list of hosts addresses |
|
578
|
|
|
port (str, optional): Port to which the note applies |
|
579
|
|
|
result_id (str, optional): UUID of a result to which note applies |
|
580
|
|
|
severity (decimal, optional): Severity to which note applies |
|
581
|
|
|
task_id (str, optional): UUID of task to which note applies |
|
582
|
|
|
threat (str, optional): Threat level to which note applies. Will be |
|
583
|
|
|
converted to severity |
|
584
|
|
|
|
|
585
|
|
|
Returns: |
|
586
|
|
|
The response. See :py:meth:`send_command` for details. |
|
587
|
|
|
""" |
|
588
|
|
|
if not text: |
|
589
|
|
|
raise RequiredArgument('create_note requires a text argument') |
|
590
|
|
|
|
|
591
|
|
|
if not nvt_oid: |
|
592
|
|
|
raise RequiredArgument('create_note requires a nvt_oid argument') |
|
593
|
|
|
|
|
594
|
|
|
cmd = XmlCommand('create_note') |
|
595
|
|
|
cmd.add_element('text', text) |
|
596
|
|
|
cmd.add_element('nvt', attrs={"oid": nvt_oid}) |
|
597
|
|
|
|
|
598
|
|
|
if not seconds_active is None: |
|
599
|
|
|
cmd.add_element('active', str(seconds_active)) |
|
600
|
|
|
|
|
601
|
|
|
if comment: |
|
602
|
|
|
cmd.add_element('comment', comment) |
|
603
|
|
|
|
|
604
|
|
|
if hosts: |
|
605
|
|
|
cmd.add_element('hosts', ', '.join(hosts)) |
|
606
|
|
|
|
|
607
|
|
|
if port: |
|
608
|
|
|
cmd.add_element('port', port) |
|
609
|
|
|
|
|
610
|
|
|
if result_id: |
|
611
|
|
|
cmd.add_element('result', attrs={'id': result_id}) |
|
612
|
|
|
|
|
613
|
|
|
if severity: |
|
614
|
|
|
cmd.add_element('severity', severity) |
|
615
|
|
|
|
|
616
|
|
|
if task_id: |
|
617
|
|
|
cmd.add_element('task', attrs={'id': task_id}) |
|
618
|
|
|
|
|
619
|
|
|
if threat: |
|
620
|
|
|
cmd.add_element('threat', threat) |
|
621
|
|
|
|
|
622
|
|
|
return self._send_xml_command(cmd) |
|
623
|
|
|
|
|
624
|
|
|
def clone_note(self, note_id): |
|
625
|
|
|
"""Clone an existing note |
|
626
|
|
|
|
|
627
|
|
|
Arguments: |
|
628
|
|
|
copy (str): UUID of an existing note to clone from |
|
629
|
|
|
|
|
630
|
|
|
Returns: |
|
631
|
|
|
The response. See :py:meth:`send_command` for details. |
|
632
|
|
|
""" |
|
633
|
|
|
cmd = XmlCommand('create_note') |
|
634
|
|
|
cmd.add_element('copy', note_id) |
|
635
|
|
|
return self._send_xml_command(cmd) |
|
636
|
|
|
|
|
637
|
|
View Code Duplication |
def create_override(self, text, nvt_oid, seconds_active=None, hosts=None, |
|
|
|
|
|
|
638
|
|
|
port=None, result_id=None, severity=None, comment=None, |
|
639
|
|
|
new_severity=None, task_id=None, threat=None, |
|
640
|
|
|
new_threat=None): |
|
641
|
|
|
"""Create a new override |
|
642
|
|
|
|
|
643
|
|
|
Arguments: |
|
644
|
|
|
text (str): Text of the new override |
|
645
|
|
|
nvt_id (str): OID of the nvt to which override applies |
|
646
|
|
|
seconds_active (int, optional): Seconds override will be active. |
|
647
|
|
|
-1 on always, 0 off |
|
648
|
|
|
comment (str, optional): Comment for the override |
|
649
|
|
|
hosts (list, optional): A list of host addresses |
|
650
|
|
|
port (str, optional): Port ot which the override applies |
|
651
|
|
|
result_id (str, optional): UUID of a result to which override |
|
652
|
|
|
applies |
|
653
|
|
|
severity (decimal, optional): Severity to which override applies |
|
654
|
|
|
new_severity (decimal, optional): New severity for result |
|
655
|
|
|
task_id (str, optional): UUID of task to which override applies |
|
656
|
|
|
threat (str, optional): Threat level to which override applies. Will |
|
657
|
|
|
be converted to severity |
|
658
|
|
|
new_threat (str, optional): New threat level for result, will be |
|
659
|
|
|
converted to a new_severity |
|
660
|
|
|
|
|
661
|
|
|
Returns: |
|
662
|
|
|
The response. See :py:meth:`send_command` for details. |
|
663
|
|
|
""" |
|
664
|
|
|
if not text: |
|
665
|
|
|
raise RequiredArgument('create_override requires a text argument') |
|
666
|
|
|
|
|
667
|
|
|
if not nvt_oid: |
|
668
|
|
|
raise RequiredArgument('create_override requires a nvt_oid ' |
|
669
|
|
|
'argument') |
|
670
|
|
|
|
|
671
|
|
|
cmd = XmlCommand('create_override') |
|
672
|
|
|
cmd.add_element('text', text) |
|
673
|
|
|
cmd.add_element('nvt', attrs={'oid': nvt_oid}) |
|
674
|
|
|
|
|
675
|
|
|
if not seconds_active is None: |
|
676
|
|
|
cmd.add_element('active', str(seconds_active)) |
|
677
|
|
|
|
|
678
|
|
|
if comment: |
|
679
|
|
|
cmd.add_element('comment', comment) |
|
680
|
|
|
|
|
681
|
|
|
if hosts: |
|
682
|
|
|
cmd.add_element('hosts', ', '.join(hosts)) |
|
683
|
|
|
|
|
684
|
|
|
if port: |
|
685
|
|
|
cmd.add_element('port', port) |
|
686
|
|
|
|
|
687
|
|
|
if result_id: |
|
688
|
|
|
cmd.add_element('result', attrs={'id': result_id}) |
|
689
|
|
|
|
|
690
|
|
|
if severity: |
|
691
|
|
|
cmd.add_element('severity', severity) |
|
692
|
|
|
|
|
693
|
|
|
if new_severity: |
|
694
|
|
|
cmd.add_element('new_severity', new_severity) |
|
695
|
|
|
|
|
696
|
|
|
if task_id: |
|
697
|
|
|
cmd.add_element('task', attrs={'id': task_id}) |
|
698
|
|
|
|
|
699
|
|
|
if threat: |
|
700
|
|
|
cmd.add_element('threat', threat) |
|
701
|
|
|
|
|
702
|
|
|
if new_threat: |
|
703
|
|
|
cmd.add_element('new_threat', new_threat) |
|
704
|
|
|
|
|
705
|
|
|
return self._send_xml_command(cmd) |
|
706
|
|
|
|
|
707
|
|
|
def clone_override(self, override_id): |
|
708
|
|
|
"""Clone an existing override |
|
709
|
|
|
|
|
710
|
|
|
Arguments: |
|
711
|
|
|
copy (str): UUID of an existing override to clone from |
|
712
|
|
|
|
|
713
|
|
|
Returns: |
|
714
|
|
|
The response. See :py:meth:`send_command` for details. |
|
715
|
|
|
""" |
|
716
|
|
|
cmd = XmlCommand('create_override') |
|
717
|
|
|
cmd.add_element('copy', override_id) |
|
718
|
|
|
return self._send_xml_command(cmd) |
|
719
|
|
|
|
|
720
|
|
View Code Duplication |
def create_permission(self, name, subject_id, subject_type, |
|
|
|
|
|
|
721
|
|
|
resource_id=None, resource_type=None, |
|
722
|
|
|
comment=None): |
|
723
|
|
|
"""Create a new permission |
|
724
|
|
|
|
|
725
|
|
|
Arguments: |
|
726
|
|
|
name (str): Name of the new permission |
|
727
|
|
|
subject_id (str): UUID of subject to whom the permission is granted |
|
728
|
|
|
subject_type (str): Type of the subject user, group or role |
|
729
|
|
|
comment (str, optional): Comment for the permission |
|
730
|
|
|
resource_id (str, optional): UUID of entity to which the permission |
|
731
|
|
|
applies |
|
732
|
|
|
resource_type (str, optional): Type of the resource. For Super |
|
733
|
|
|
permissions user, group or role |
|
734
|
|
|
|
|
735
|
|
|
Returns: |
|
736
|
|
|
The response. See :py:meth:`send_command` for details. |
|
737
|
|
|
""" |
|
738
|
|
|
if not name: |
|
739
|
|
|
raise RequiredArgument('create_permission requires a name argument') |
|
740
|
|
|
|
|
741
|
|
|
if not subject_id: |
|
742
|
|
|
raise RequiredArgument( |
|
743
|
|
|
'create_permission requires a subject_id argument') |
|
744
|
|
|
|
|
745
|
|
|
if subject_type not in ('user', 'group', 'role'): |
|
746
|
|
|
raise InvalidArgument( |
|
747
|
|
|
'create_permission requires subject_type to be either user, ' |
|
748
|
|
|
'group or role') |
|
749
|
|
|
|
|
750
|
|
|
cmd = XmlCommand('create_permission') |
|
751
|
|
|
cmd.add_element('name', name) |
|
752
|
|
|
|
|
753
|
|
|
_xmlsubject = cmd.add_element('subject', attrs={'id': subject_id}) |
|
754
|
|
|
_xmlsubject.add_element('type', type) |
|
755
|
|
|
|
|
756
|
|
|
if comment: |
|
757
|
|
|
cmd.add_element('comment', comment) |
|
758
|
|
|
|
|
759
|
|
|
if resource_id and resource_type: |
|
760
|
|
|
_xmlresource = cmd.add_element('resource', |
|
761
|
|
|
attrs={'id': resource_id}) |
|
762
|
|
|
_xmlresource.add_element('type', resource_type) |
|
763
|
|
|
|
|
764
|
|
|
|
|
765
|
|
|
return self._send_xml_command(cmd) |
|
766
|
|
|
|
|
767
|
|
|
def clone_permission(self, permission_id): |
|
768
|
|
|
"""Clone an existing permission |
|
769
|
|
|
|
|
770
|
|
|
Arguments: |
|
771
|
|
|
copy (str): UUID of an existing permission to clone from |
|
772
|
|
|
|
|
773
|
|
|
Returns: |
|
774
|
|
|
The response. See :py:meth:`send_command` for details. |
|
775
|
|
|
""" |
|
776
|
|
|
cmd = XmlCommand('create_permission') |
|
777
|
|
|
cmd.add_element('copy', permission_id) |
|
778
|
|
|
return self._send_xml_command(cmd) |
|
779
|
|
|
|
|
780
|
|
|
def create_port_list(self, name, port_range, comment=None): |
|
781
|
|
|
"""Create a new port list |
|
782
|
|
|
|
|
783
|
|
|
Arguments: |
|
784
|
|
|
name (str): Name of the new port list |
|
785
|
|
|
port_range (str): Port list ranges e.g. `"T: 1-1234"` for tcp port |
|
786
|
|
|
1 - 1234 |
|
787
|
|
|
comment (str, optional): Comment for the port list |
|
788
|
|
|
|
|
789
|
|
|
Returns: |
|
790
|
|
|
The response. See :py:meth:`send_command` for details. |
|
791
|
|
|
""" |
|
792
|
|
|
if not name: |
|
793
|
|
|
raise RequiredArgument('create_port_list requires a name argument') |
|
794
|
|
|
|
|
795
|
|
|
if not port_range: |
|
796
|
|
|
raise RequiredArgument( |
|
797
|
|
|
'create_port_list requires a port_range argument') |
|
798
|
|
|
|
|
799
|
|
|
cmd = XmlCommand('create_port_list') |
|
800
|
|
|
cmd.add_element('name', name) |
|
801
|
|
|
cmd.add_element('port_range', port_range) |
|
802
|
|
|
|
|
803
|
|
|
if comment: |
|
804
|
|
|
cmd.add_element('comment', comment) |
|
805
|
|
|
|
|
806
|
|
|
return self._send_xml_command(cmd) |
|
807
|
|
|
|
|
808
|
|
|
def clone_port_list(self, port_list_id): |
|
809
|
|
|
"""Clone an existing port list |
|
810
|
|
|
|
|
811
|
|
|
Arguments: |
|
812
|
|
|
copy (str): UUID of an existing port list to clone from |
|
813
|
|
|
|
|
814
|
|
|
Returns: |
|
815
|
|
|
The response. See :py:meth:`send_command` for details. |
|
816
|
|
|
""" |
|
817
|
|
|
cmd = XmlCommand('create_port_list') |
|
818
|
|
|
cmd.add_element('copy', port_list_id) |
|
819
|
|
|
return self._send_xml_command(cmd) |
|
820
|
|
|
|
|
821
|
|
|
def create_port_range(self, port_list_id, start, end, port_range_type, |
|
822
|
|
|
comment=None): |
|
823
|
|
|
"""Create new port range |
|
824
|
|
|
|
|
825
|
|
|
Arguments: |
|
826
|
|
|
port_list_id (str): UUID of the port list to which to add the range |
|
827
|
|
|
start (int): The first port in the range |
|
828
|
|
|
end (int): The last port in the range |
|
829
|
|
|
type (str): The type of the ports: TCP, UDP, ... |
|
830
|
|
|
comment (str, optional): Comment for the port range |
|
831
|
|
|
|
|
832
|
|
|
Returns: |
|
833
|
|
|
The response. See :py:meth:`send_command` for details. |
|
834
|
|
|
""" |
|
835
|
|
|
if not port_list_id: |
|
836
|
|
|
raise RequiredArgument('create_port_range requires ' |
|
837
|
|
|
'a port_list_id argument') |
|
838
|
|
|
|
|
839
|
|
|
if not port_range_type: |
|
840
|
|
|
raise RequiredArgument( |
|
841
|
|
|
'create_port_range requires a port_range_type argument') |
|
842
|
|
|
|
|
843
|
|
|
if not start: |
|
844
|
|
|
raise RequiredArgument( |
|
845
|
|
|
'create_port_range requires a start argument') |
|
846
|
|
|
|
|
847
|
|
|
if not end: |
|
848
|
|
|
raise RequiredArgument( |
|
849
|
|
|
'create_port_range requires a end argument') |
|
850
|
|
|
|
|
851
|
|
|
cmd = XmlCommand('create_port_range') |
|
852
|
|
|
cmd.add_element('port_list', attrs={'id': port_list_id}) |
|
853
|
|
|
cmd.add_element('start', start) |
|
854
|
|
|
cmd.add_element('end', end) |
|
855
|
|
|
cmd.add_element('type', port_range_type) |
|
856
|
|
|
|
|
857
|
|
|
if comment: |
|
858
|
|
|
cmd.add_element('comment', comment) |
|
859
|
|
|
|
|
860
|
|
|
return self._send_xml_command(cmd) |
|
861
|
|
|
|
|
862
|
|
|
def import_report(self, report, task_id=None, task_name=None, |
|
863
|
|
|
task_comment=None, in_assets=None): |
|
864
|
|
|
"""Import a Report |
|
865
|
|
|
|
|
866
|
|
|
Arguments: |
|
867
|
|
|
report (str): Report XML as string to import |
|
868
|
|
|
task_id (str, optional): UUID of task to import report to |
|
869
|
|
|
task_name (str, optional): Name of task to be createed if task_id is |
|
870
|
|
|
not present. Either task_id or task_name must be passed |
|
871
|
|
|
task_comment (str, optional): Comment for task to be created if |
|
872
|
|
|
task_id is not present |
|
873
|
|
|
in_asset (boolean, optional): Whether to create or update assets |
|
874
|
|
|
using the report |
|
875
|
|
|
|
|
876
|
|
|
Returns: |
|
877
|
|
|
The response. See :py:meth:`send_command` for details. |
|
878
|
|
|
""" |
|
879
|
|
|
if not report: |
|
880
|
|
|
raise RequiredArgument('create_report requires a report argument') |
|
881
|
|
|
|
|
882
|
|
|
cmd = XmlCommand('create_report') |
|
883
|
|
|
|
|
884
|
|
|
if task_id: |
|
885
|
|
|
cmd.add_element('task', attrs={'id': task_id}) |
|
886
|
|
|
elif task_name: |
|
887
|
|
|
_xmltask = cmd.add_element('task') |
|
888
|
|
|
_xmltask.add_element('name', task_name) |
|
889
|
|
|
|
|
890
|
|
|
if task_comment: |
|
891
|
|
|
_xmltask.add_element('comment', task_comment) |
|
892
|
|
|
else: |
|
893
|
|
|
raise RequiredArgument( |
|
894
|
|
|
'import_report requires a task_id or task_name argument') |
|
895
|
|
|
|
|
896
|
|
|
if not in_assets is None: |
|
897
|
|
|
if in_assets: |
|
898
|
|
|
cmd.add_element('in_assets', '1') |
|
899
|
|
|
else: |
|
900
|
|
|
cmd.add_element('in_assets', '0') |
|
901
|
|
|
try: |
|
902
|
|
|
cmd.append_xml_str(report) |
|
903
|
|
|
except etree.XMLSyntaxError as e: |
|
904
|
|
|
raise InvalidArgument( |
|
905
|
|
|
'Invalid xml passed as report to import_report', e) |
|
906
|
|
|
|
|
907
|
|
|
return self._send_xml_command(cmd) |
|
908
|
|
|
|
|
909
|
|
|
def create_role(self, name, comment=None, users=None): |
|
910
|
|
|
"""Create a new role |
|
911
|
|
|
|
|
912
|
|
|
Arguments: |
|
913
|
|
|
name (str): Name of the role |
|
914
|
|
|
comment (str, optional): Comment for the role |
|
915
|
|
|
users (list, optional): List of user names to add to the role |
|
916
|
|
|
|
|
917
|
|
|
Returns: |
|
918
|
|
|
The response. See :py:meth:`send_command` for details. |
|
919
|
|
|
""" |
|
920
|
|
|
|
|
921
|
|
|
if not name: |
|
922
|
|
|
raise RequiredArgument('create_role requires a name argument') |
|
923
|
|
|
|
|
924
|
|
|
cmd = XmlCommand('create_role') |
|
925
|
|
|
cmd.add_element('name', name) |
|
926
|
|
|
|
|
927
|
|
|
if comment: |
|
928
|
|
|
cmd.add_element('comment', comment) |
|
929
|
|
|
|
|
930
|
|
|
if users: |
|
931
|
|
|
cmd.add_element('users', ",".join(users)) |
|
932
|
|
|
|
|
933
|
|
|
return self._send_xml_command(cmd) |
|
934
|
|
|
|
|
935
|
|
|
def clone_role(self, role_id): |
|
936
|
|
|
"""Clone an existing role |
|
937
|
|
|
|
|
938
|
|
|
Arguments: |
|
939
|
|
|
copy (str): UUID of an existing role to clone from |
|
940
|
|
|
|
|
941
|
|
|
Returns: |
|
942
|
|
|
The response. See :py:meth:`send_command` for details. |
|
943
|
|
|
""" |
|
944
|
|
|
cmd = XmlCommand('create_role') |
|
945
|
|
|
cmd.add_element('copy', role_id) |
|
946
|
|
|
return self._send_xml_command(cmd) |
|
947
|
|
|
|
|
948
|
|
|
def create_scanner(self, name, host, port, scanner_type, ca_pub, |
|
949
|
|
|
credential_id, comment=None): |
|
950
|
|
|
"""Create a new scanner |
|
951
|
|
|
|
|
952
|
|
|
Arguments: |
|
953
|
|
|
name (str): Name of the scanner |
|
954
|
|
|
host (str): The host of the scanner |
|
955
|
|
|
port (str): The port of the scanner |
|
956
|
|
|
scanner_type (str): The type of the scanner |
|
957
|
|
|
ca_pub (str): Certificate of CA to verify scanner certificate |
|
958
|
|
|
credential_id (str): UUID of client certificate credential for the |
|
959
|
|
|
scanner |
|
960
|
|
|
comment (str, optional): Comment for the scanner |
|
961
|
|
|
|
|
962
|
|
|
Returns: |
|
963
|
|
|
The response. See :py:meth:`send_command` for details. |
|
964
|
|
|
""" |
|
965
|
|
|
if not name: |
|
966
|
|
|
raise RequiredArgument('create_scanner requires a name argument') |
|
967
|
|
|
|
|
968
|
|
|
if not host: |
|
969
|
|
|
raise RequiredArgument('create_scanner requires a host argument') |
|
970
|
|
|
|
|
971
|
|
|
if not port: |
|
972
|
|
|
raise RequiredArgument('create_scanner requires a port argument') |
|
973
|
|
|
|
|
974
|
|
|
if not type: |
|
975
|
|
|
raise RequiredArgument('create_scanner requires a scanner_type ' |
|
976
|
|
|
'argument') |
|
977
|
|
|
if not ca_pub: |
|
978
|
|
|
raise RequiredArgument('create_scanner requires a ca_pub argument') |
|
979
|
|
|
|
|
980
|
|
|
if not credential_id: |
|
981
|
|
|
raise RequiredArgument('create_scanner requires a credential_id ' |
|
982
|
|
|
'argument') |
|
983
|
|
|
|
|
984
|
|
|
cmd = XmlCommand('create_scanner') |
|
985
|
|
|
cmd.add_element('name', name) |
|
986
|
|
|
cmd.add_element('host', host) |
|
987
|
|
|
cmd.add_element('port', port) |
|
988
|
|
|
cmd.add_element('type', scanner_type) |
|
989
|
|
|
cmd.add_element('ca_pub', ca_pub) |
|
990
|
|
|
cmd.add_element('credential', attrs={'id': str(credential_id)}) |
|
991
|
|
|
|
|
992
|
|
|
if comment: |
|
993
|
|
|
cmd.add_element('comment', comment) |
|
994
|
|
|
|
|
995
|
|
|
return self._send_xml_command(cmd) |
|
996
|
|
|
|
|
997
|
|
|
def clone_scanner(self, scanner_id): |
|
998
|
|
|
"""Clone an existing scanner |
|
999
|
|
|
|
|
1000
|
|
|
Arguments: |
|
1001
|
|
|
copy (str): UUID of an existing scanner to clone from |
|
1002
|
|
|
|
|
1003
|
|
|
Returns: |
|
1004
|
|
|
The response. See :py:meth:`send_command` for details. |
|
1005
|
|
|
""" |
|
1006
|
|
|
cmd = XmlCommand('create_scanner') |
|
1007
|
|
|
cmd.add_element('copy', scanner_id) |
|
1008
|
|
|
return self._send_xml_command(cmd) |
|
1009
|
|
|
|
|
1010
|
|
|
def create_schedule(self, name, comment=None, first_time_minute=None, |
|
|
|
|
|
|
1011
|
|
|
first_time_hour=None, first_time_day_of_month=None, |
|
1012
|
|
|
first_time_month=None, first_time_year=None, |
|
1013
|
|
|
duration=None, duration_unit=None, period=None, |
|
1014
|
|
|
period_unit=None, timezone=None): |
|
1015
|
|
|
"""Create a new schedule |
|
1016
|
|
|
|
|
1017
|
|
|
Arguments: |
|
1018
|
|
|
name (str): Name of the schedule |
|
1019
|
|
|
comment (str, optional): Comment for the schedule |
|
1020
|
|
|
first_time_minute (int, optional): First time minute the schedule |
|
1021
|
|
|
will run |
|
1022
|
|
|
first_time_hour (int, optional): First time hour the schedule |
|
1023
|
|
|
will run |
|
1024
|
|
|
first_time_day_of_month (int, optional): First time day of month the |
|
1025
|
|
|
schedule will run |
|
1026
|
|
|
first_time_month (int, optional): First time month the schedule |
|
1027
|
|
|
will run |
|
1028
|
|
|
first_time_year (int, optional): First time year the schedule |
|
1029
|
|
|
will run |
|
1030
|
|
|
duration (int, optional): How long the Manager will run the |
|
1031
|
|
|
scheduled task for until it gets paused if not finished yet. |
|
1032
|
|
|
duration_unit (str, optional): Unit of the duration. One of second, |
|
1033
|
|
|
minute, hour, day, week, month, year, decade. Required if |
|
1034
|
|
|
duration is set. |
|
1035
|
|
|
period (int, optional): How often the Manager will repeat the |
|
1036
|
|
|
scheduled task |
|
1037
|
|
|
period_unit (str, optional): Unit of the period. One of second, |
|
1038
|
|
|
minute, hour, day, week, month, year, decade. Required if |
|
1039
|
|
|
period is set. |
|
1040
|
|
|
timezone (str, optional): The timezone the schedule will follow |
|
1041
|
|
|
|
|
1042
|
|
|
Returns: |
|
1043
|
|
|
The response. See :py:meth:`send_command` for details. |
|
1044
|
|
|
""" |
|
1045
|
|
|
if not name: |
|
1046
|
|
|
raise RequiredArgument('create_schedule requires a name argument') |
|
1047
|
|
|
|
|
1048
|
|
|
cmd = XmlCommand('create_schedule') |
|
1049
|
|
|
cmd.add_element('name', name) |
|
1050
|
|
|
|
|
1051
|
|
|
if comment: |
|
1052
|
|
|
cmd.add_element('comment', comment) |
|
1053
|
|
|
|
|
1054
|
|
|
if first_time_minute or first_time_hour or first_time_day_of_month or \ |
|
1055
|
|
|
first_time_month or first_time_year: |
|
1056
|
|
|
|
|
1057
|
|
|
if not first_time_minute: |
|
1058
|
|
|
raise RequiredArgument( |
|
1059
|
|
|
'Setting first_time requires first_time_minute argument') |
|
1060
|
|
|
if not first_time_hour: |
|
1061
|
|
|
raise RequiredArgument( |
|
1062
|
|
|
'Setting first_time requires first_time_hour argument') |
|
1063
|
|
|
if not first_time_day_of_month: |
|
1064
|
|
|
raise RequiredArgument( |
|
1065
|
|
|
'Setting first_time requires first_time_day_of_month ' |
|
1066
|
|
|
'argument') |
|
1067
|
|
|
if not first_time_month: |
|
1068
|
|
|
raise RequiredArgument( |
|
1069
|
|
|
'Setting first_time requires first_time_month argument') |
|
1070
|
|
|
if not first_time_year: |
|
1071
|
|
|
raise RequiredArgument( |
|
1072
|
|
|
'Setting first_time requires first_time_year argument') |
|
1073
|
|
|
|
|
1074
|
|
|
_xmlftime = cmd.add_element('first_time') |
|
1075
|
|
|
_xmlftime.add_element('minute', str(first_time_minute)) |
|
1076
|
|
|
_xmlftime.add_element('hour', str(first_time_hour)) |
|
1077
|
|
|
_xmlftime.add_element('day_of_month', str(first_time_day_of_month)) |
|
1078
|
|
|
_xmlftime.add_element('month', str(first_time_month)) |
|
1079
|
|
|
_xmlftime.add_element('year', str(first_time_year)) |
|
1080
|
|
|
|
|
1081
|
|
|
if duration: |
|
1082
|
|
|
if not duration_unit: |
|
1083
|
|
|
raise RequiredArgument( |
|
1084
|
|
|
'Setting duration requires duration_unit argument') |
|
1085
|
|
|
|
|
1086
|
|
|
if not duration_unit in TIME_UNITS: |
|
1087
|
|
|
raise InvalidArgument( |
|
1088
|
|
|
'duration_unit must be one of {units} but {actual} has ' |
|
1089
|
|
|
'been passed'.format( |
|
1090
|
|
|
units=', '.join(TIME_UNITS), actual=duration_unit)) |
|
1091
|
|
|
|
|
1092
|
|
|
_xmlduration = cmd.add_element('duration', str(duration)) |
|
1093
|
|
|
_xmlduration.add_element('unit', duration_unit) |
|
1094
|
|
|
|
|
1095
|
|
|
if period: |
|
1096
|
|
|
if not period_unit: |
|
1097
|
|
|
raise RequiredArgument( |
|
1098
|
|
|
'Setting period requires period_unit argument') |
|
1099
|
|
|
|
|
1100
|
|
|
if not period_unit in TIME_UNITS: |
|
1101
|
|
|
raise InvalidArgument( |
|
1102
|
|
|
'period_unit must be one of {units} but {actual} has ' |
|
1103
|
|
|
'been passed'.format( |
|
1104
|
|
|
units=', '.join(TIME_UNITS), actual=period_unit)) |
|
1105
|
|
|
|
|
1106
|
|
|
_xmlperiod = cmd.add_element('period', str(period)) |
|
1107
|
|
|
_xmlperiod.add_element('unit', period_unit) |
|
1108
|
|
|
|
|
1109
|
|
|
if timezone: |
|
1110
|
|
|
cmd.add_element('timezone', timezone) |
|
1111
|
|
|
|
|
1112
|
|
|
return self._send_xml_command(cmd) |
|
1113
|
|
|
|
|
1114
|
|
|
def clone_schedule(self, schedule_id): |
|
1115
|
|
|
"""Clone an existing schedule |
|
1116
|
|
|
|
|
1117
|
|
|
Arguments: |
|
1118
|
|
|
copy (str): UUID of an existing schedule to clone from |
|
1119
|
|
|
|
|
1120
|
|
|
Returns: |
|
1121
|
|
|
The response. See :py:meth:`send_command` for details. |
|
1122
|
|
|
""" |
|
1123
|
|
|
cmd = XmlCommand('create_schedule') |
|
1124
|
|
|
cmd.add_element('copy', schedule_id) |
|
1125
|
|
|
return self._send_xml_command(cmd) |
|
1126
|
|
|
|
|
1127
|
|
|
def create_tag(self, name, resource_id, resource_type, value=None, |
|
1128
|
|
|
comment=None, active=None): |
|
1129
|
|
|
"""Create a new tag |
|
1130
|
|
|
|
|
1131
|
|
|
Arguments: |
|
1132
|
|
|
name (str): Name of the tag. A full tag name consisting of namespace |
|
1133
|
|
|
and predicate e.g. `foo:bar`. |
|
1134
|
|
|
resource_id (str): ID of the resource the tag is to be attached to. |
|
1135
|
|
|
resource_type (str): Entity type the tag is to be attached to |
|
1136
|
|
|
value (str, optional): Value associated with the tag |
|
1137
|
|
|
comment (str, optional): Comment for the tag |
|
1138
|
|
|
active (boolean, optional): Whether the tag should be active |
|
1139
|
|
|
|
|
1140
|
|
|
Returns: |
|
1141
|
|
|
The response. See :py:meth:`send_command` for details. |
|
1142
|
|
|
""" |
|
1143
|
|
|
cmd = XmlCommand('create_tag') |
|
1144
|
|
|
cmd.add_element('name', name) |
|
1145
|
|
|
_xmlresource = cmd.add_element('resource', |
|
1146
|
|
|
attrs={'id': str(resource_id)}) |
|
1147
|
|
|
_xmlresource.add_element('type', resource_type) |
|
1148
|
|
|
|
|
1149
|
|
|
if comment: |
|
1150
|
|
|
cmd.add_element('comment', comment) |
|
1151
|
|
|
|
|
1152
|
|
|
if value: |
|
1153
|
|
|
cmd.add_element('value', value) |
|
1154
|
|
|
|
|
1155
|
|
|
if not active is None: |
|
1156
|
|
|
if active: |
|
1157
|
|
|
cmd.add_element('active', '1') |
|
1158
|
|
|
else: |
|
1159
|
|
|
cmd.add_element('active', '0') |
|
1160
|
|
|
|
|
1161
|
|
|
return self._send_xml_command(cmd) |
|
1162
|
|
|
|
|
1163
|
|
|
def clone_tag(self, tag_id): |
|
1164
|
|
|
"""Clone an existing tag |
|
1165
|
|
|
|
|
1166
|
|
|
Arguments: |
|
1167
|
|
|
copy (str): UUID of an existing tag to clone from |
|
1168
|
|
|
|
|
1169
|
|
|
Returns: |
|
1170
|
|
|
The response. See :py:meth:`send_command` for details. |
|
1171
|
|
|
""" |
|
1172
|
|
|
cmd = XmlCommand('create_tag') |
|
1173
|
|
|
cmd.add_element('copy', tag_id) |
|
1174
|
|
|
return self._send_xml_command(cmd) |
|
1175
|
|
|
|
|
1176
|
|
|
def create_target(self, name, make_unique=False, asset_hosts_filter=None, |
|
|
|
|
|
|
1177
|
|
|
hosts=None, comment=None, exclude_hosts=None, |
|
1178
|
|
|
ssh_credential_id=None, ssh_credential_port=None, |
|
1179
|
|
|
smb_credential_id=None, esxi_credential_id=None, |
|
1180
|
|
|
snmp_credential_id=None, alive_tests=None, |
|
1181
|
|
|
reverse_lookup_only=None, reverse_lookup_unify=None, |
|
1182
|
|
|
port_range=None, port_list_id=None): |
|
1183
|
|
|
"""Create a new target |
|
1184
|
|
|
|
|
1185
|
|
|
Arguments: |
|
1186
|
|
|
name (str): Name of the target |
|
1187
|
|
|
make_unique (boolean, optional): Append a unique suffix if the name |
|
1188
|
|
|
already exists |
|
1189
|
|
|
asset_hosts_filter (str, optional): Filter to select target host |
|
1190
|
|
|
from assets hosts |
|
1191
|
|
|
hosts (list, optional): List of hosts addresses to scan |
|
1192
|
|
|
exclude_hosts (list, optional): List of hosts addresses to exclude |
|
1193
|
|
|
from scan |
|
1194
|
|
|
comment (str, optional): Comment for the target |
|
1195
|
|
|
ssh_credential_id (str, optional): UUID of a ssh credential to use |
|
1196
|
|
|
on target |
|
1197
|
|
|
ssh_credential_port (str, optional): The port to use for ssh |
|
1198
|
|
|
credential |
|
1199
|
|
|
smb_credential_id (str, optional): UUID of a smb credential to use |
|
1200
|
|
|
on target |
|
1201
|
|
|
snmp_credential_id (str, optional): UUID of a snmp credential to use |
|
1202
|
|
|
on target |
|
1203
|
|
|
esxi_credential_id (str, optional): UUID of a esxi credential to use |
|
1204
|
|
|
on target |
|
1205
|
|
|
alive_tests (str, optional): Which alive tests to use |
|
1206
|
|
|
reverse_lookup_only (boolean, optional): Whether to scan only hosts |
|
1207
|
|
|
that have names |
|
1208
|
|
|
reverse_lookup_unify (boolean, optional): Whether to scan only one |
|
1209
|
|
|
IP when multiple IPs have the same name. |
|
1210
|
|
|
port_range (str, optional): Port range for the target |
|
1211
|
|
|
port_list_id (str, optional): UUID of the port list to use on target |
|
1212
|
|
|
|
|
1213
|
|
|
Returns: |
|
1214
|
|
|
The response. See :py:meth:`send_command` for details. |
|
1215
|
|
|
""" |
|
1216
|
|
|
if not name: |
|
1217
|
|
|
raise RequiredArgument('create_target requires a name argument') |
|
1218
|
|
|
|
|
1219
|
|
|
cmd = XmlCommand('create_target') |
|
1220
|
|
|
_xmlname = cmd.add_element('name', name) |
|
1221
|
|
|
if make_unique: |
|
1222
|
|
|
_xmlname.add_element('make_unique', '1') |
|
1223
|
|
|
|
|
1224
|
|
|
if asset_hosts_filter: |
|
1225
|
|
|
cmd.add_element('asset_hosts', |
|
1226
|
|
|
attrs={'filter': str(asset_hosts_filter)}) |
|
1227
|
|
|
elif hosts: |
|
1228
|
|
|
cmd.add_element('hosts', ', '.join(hosts)) |
|
1229
|
|
|
else: |
|
1230
|
|
|
raise RequiredArgument('create_target requires either a hosts or ' |
|
1231
|
|
|
'an asset_hosts_filter argument') |
|
1232
|
|
|
|
|
1233
|
|
|
if comment: |
|
1234
|
|
|
cmd.add_element('comment', comment) |
|
1235
|
|
|
|
|
1236
|
|
|
if exclude_hosts: |
|
1237
|
|
|
cmd.add_element('exclude_hosts', ', '.join(exclude_hosts)) |
|
1238
|
|
|
|
|
1239
|
|
|
if ssh_credential_id: |
|
1240
|
|
|
_xmlssh = cmd.add_element('ssh_credential', |
|
1241
|
|
|
attrs={'id': ssh_credential_id}) |
|
1242
|
|
|
if ssh_credential_port: |
|
1243
|
|
|
_xmlssh.add_element('port', ssh_credential_port) |
|
1244
|
|
|
|
|
1245
|
|
|
if smb_credential_id: |
|
1246
|
|
|
cmd.add_element('smb_credential', attrs={'id': smb_credential_id}) |
|
1247
|
|
|
|
|
1248
|
|
|
if esxi_credential_id: |
|
1249
|
|
|
cmd.add_element('esxi_credential', attrs={'id': esxi_credential_id}) |
|
1250
|
|
|
|
|
1251
|
|
|
if snmp_credential_id: |
|
1252
|
|
|
cmd.add_element('snmp_credential', attrs={'id': snmp_credential_id}) |
|
1253
|
|
|
|
|
1254
|
|
|
if alive_tests: |
|
1255
|
|
|
cmd.add_element('alive_tests', alive_tests) |
|
1256
|
|
|
|
|
1257
|
|
|
if not reverse_lookup_only is None: |
|
1258
|
|
|
if reverse_lookup_only: |
|
1259
|
|
|
cmd.add_element('reverse_lookup_only', '1') |
|
1260
|
|
|
else: |
|
1261
|
|
|
cmd.add_element('reverse_lookup_only', '0') |
|
1262
|
|
|
|
|
1263
|
|
|
if not reverse_lookup_unify is None: |
|
1264
|
|
|
if reverse_lookup_unify: |
|
1265
|
|
|
cmd.add_element('reverse_lookup_unify', '1') |
|
1266
|
|
|
else: |
|
1267
|
|
|
cmd.add_element('reverse_lookup_unify', '0') |
|
1268
|
|
|
|
|
1269
|
|
|
if port_range: |
|
1270
|
|
|
cmd.add_element('port_range', port_range) |
|
1271
|
|
|
|
|
1272
|
|
|
if port_list_id: |
|
1273
|
|
|
cmd.add_element('port_list', attrs={'id': port_list_id}) |
|
1274
|
|
|
|
|
1275
|
|
|
return self._send_xml_command(cmd) |
|
1276
|
|
|
|
|
1277
|
|
|
def clone_target(self, target_id): |
|
1278
|
|
|
"""Clone an existing target |
|
1279
|
|
|
|
|
1280
|
|
|
Arguments: |
|
1281
|
|
|
copy (str): UUID of an existing target to clone from |
|
1282
|
|
|
|
|
1283
|
|
|
Returns: |
|
1284
|
|
|
The response. See :py:meth:`send_command` for details. |
|
1285
|
|
|
""" |
|
1286
|
|
|
cmd = XmlCommand('create_target') |
|
1287
|
|
|
cmd.add_element('copy', target_id) |
|
1288
|
|
|
return self._send_xml_command(cmd) |
|
1289
|
|
|
|
|
1290
|
|
|
def create_task(self, name, config_id, target_id, scanner_id, |
|
1291
|
|
|
alterable=None, hosts_ordering=None, schedule_id=None, |
|
1292
|
|
|
alert_ids=None, comment=None, schedule_periods=None, |
|
1293
|
|
|
observers=None): |
|
1294
|
|
|
"""Create a new task |
|
1295
|
|
|
|
|
1296
|
|
|
Arguments: |
|
1297
|
|
|
name (str): Name of the task |
|
1298
|
|
|
config_id (str): UUID of scan config to use by the task |
|
1299
|
|
|
target_id (str): UUID of target to be scanned |
|
1300
|
|
|
scanner_id (str): UUID of scanner to use for scanning the target |
|
1301
|
|
|
comment (str, optional): Comment for the task |
|
1302
|
|
|
alterable (boolean, optional): Wether the task should be alterable |
|
1303
|
|
|
alert_ids (list, optional): List of UUIDs for alerts to be applied |
|
1304
|
|
|
to the task |
|
1305
|
|
|
hosts_ordering (str, optional): The order hosts are scanned in |
|
1306
|
|
|
schedule_id (str, optional): UUID of a schedule when the task should |
|
1307
|
|
|
be run. |
|
1308
|
|
|
schedule_periods (int, optional): A limit to the number of times the |
|
1309
|
|
|
task will be scheduled, or 0 for no limit |
|
1310
|
|
|
observers (list, optional): List of user names which should be |
|
1311
|
|
|
allowed to observe this task |
|
1312
|
|
|
|
|
1313
|
|
|
Returns: |
|
1314
|
|
|
The response. See :py:meth:`send_command` for details. |
|
1315
|
|
|
""" |
|
1316
|
|
|
if not name: |
|
1317
|
|
|
raise RequiredArgument('create_task requires a name argument') |
|
1318
|
|
|
|
|
1319
|
|
|
if not config_id: |
|
1320
|
|
|
raise RequiredArgument('create_task requires a config_id argument') |
|
1321
|
|
|
|
|
1322
|
|
|
if not target_id: |
|
1323
|
|
|
raise RequiredArgument('create_task requires a target_id argument') |
|
1324
|
|
|
|
|
1325
|
|
|
if not scanner_id: |
|
1326
|
|
|
raise RequiredArgument('create_task requires a scanner_id argument') |
|
1327
|
|
|
|
|
1328
|
|
|
cmd = XmlCommand('create_task') |
|
1329
|
|
|
cmd.add_element('name', name) |
|
1330
|
|
|
cmd.add_element('config', attrs={'id': config_id}) |
|
1331
|
|
|
cmd.add_element('target', attrs={'id': target_id}) |
|
1332
|
|
|
cmd.add_element('scanner', attrs={'id': scanner_id}) |
|
1333
|
|
|
|
|
1334
|
|
|
if comment: |
|
1335
|
|
|
cmd.add_element('comment', comment) |
|
1336
|
|
|
|
|
1337
|
|
|
if not alterable is None: |
|
1338
|
|
|
if alterable: |
|
1339
|
|
|
cmd.add_element('alterable', '1') |
|
1340
|
|
|
else: |
|
1341
|
|
|
cmd.add_element('alterable', '0') |
|
1342
|
|
|
|
|
1343
|
|
|
if hosts_ordering: |
|
1344
|
|
|
cmd.add_element('hosts_ordering', hosts_ordering) |
|
1345
|
|
|
|
|
1346
|
|
|
if alert_ids: |
|
1347
|
|
|
if isinstance(alert_ids, str): |
|
1348
|
|
|
logger.warning( |
|
1349
|
|
|
'Please pass a list as alert_ids parameter to create_task. ' |
|
1350
|
|
|
'Passing a string is deprecated and will be removed in ' |
|
1351
|
|
|
'future.') |
|
1352
|
|
|
|
|
1353
|
|
|
#if a single id is given as a string wrap it into a list |
|
1354
|
|
|
alert_ids = [alert_ids] |
|
1355
|
|
|
if isinstance(alert_ids, list): |
|
1356
|
|
|
#parse all given alert id's |
|
1357
|
|
|
for alert in alert_ids: |
|
1358
|
|
|
cmd.add_element('alert', attrs={'id': str(alert)}) |
|
1359
|
|
|
|
|
1360
|
|
|
if schedule_id: |
|
1361
|
|
|
cmd.add_element('schedule', schedule_id) |
|
1362
|
|
|
|
|
1363
|
|
|
if schedule_periods: |
|
1364
|
|
|
cmd.add_element('schedule_periods', str(schedule_periods)) |
|
1365
|
|
|
|
|
1366
|
|
|
if observers: |
|
1367
|
|
|
cmd.add_element('observers', ' '.join(observers)) |
|
1368
|
|
|
|
|
1369
|
|
|
return self._send_xml_command(cmd) |
|
1370
|
|
|
|
|
1371
|
|
|
def clone_task(self, task_id): |
|
1372
|
|
|
"""Clone an existing task |
|
1373
|
|
|
|
|
1374
|
|
|
Arguments: |
|
1375
|
|
|
task_id (str): UUID of existing task to clone from |
|
1376
|
|
|
|
|
1377
|
|
|
Returns: |
|
1378
|
|
|
The response. See :py:meth:`send_command` for details. |
|
1379
|
|
|
""" |
|
1380
|
|
|
cmd = XmlCommand('create_task') |
|
1381
|
|
|
cmd.add_element('copy', task_id) |
|
1382
|
|
|
return self._send_xml_command(cmd) |
|
1383
|
|
|
|
|
1384
|
|
|
def create_user(self, name, password=None, hosts=None, hosts_allow=False, |
|
1385
|
|
|
ifaces=None, ifaces_allow=False, role_ids=None): |
|
1386
|
|
|
"""Create a new user |
|
1387
|
|
|
|
|
1388
|
|
|
Arguments: |
|
1389
|
|
|
name (str): Name of the user |
|
1390
|
|
|
password (str, optional): Password of the user |
|
1391
|
|
|
hosts (list, optional): A list of host addresses (IPs, DNS names) |
|
1392
|
|
|
hosts_allow (boolean, optional): If True allow only access to passed |
|
1393
|
|
|
hosts otherwise deny access. Default is False for deny hosts. |
|
1394
|
|
|
ifaces (list, optional): A list of interface names |
|
1395
|
|
|
ifaces_allow (boolean, optional): If True allow only access to |
|
1396
|
|
|
passed interfaces otherwise deny access. Default is False for |
|
1397
|
|
|
deny interfaces. |
|
1398
|
|
|
role_ids (list, optional): A list of role UUIDs for the user |
|
1399
|
|
|
|
|
1400
|
|
|
Returns: |
|
1401
|
|
|
The response. See :py:meth:`send_command` for details. |
|
1402
|
|
|
""" |
|
1403
|
|
|
if not name: |
|
1404
|
|
|
raise RequiredArgument('create_user requires a name argument') |
|
1405
|
|
|
|
|
1406
|
|
|
cmd = XmlCommand('create_user') |
|
1407
|
|
|
cmd.add_element('name', name) |
|
1408
|
|
|
|
|
1409
|
|
|
if password: |
|
1410
|
|
|
cmd.add_element('password', password) |
|
1411
|
|
|
|
|
1412
|
|
|
if hosts: |
|
1413
|
|
|
cmd.add_element('hosts', ', '.join(hosts), |
|
1414
|
|
|
attrs={'allow': '1' if hosts_allow else '0'}) |
|
1415
|
|
|
|
|
1416
|
|
|
if ifaces: |
|
1417
|
|
|
cmd.add_element('ifaces', ', '.join(ifaces), |
|
1418
|
|
|
attrs={'allow': '1' if ifaces_allow else '0'}) |
|
1419
|
|
|
|
|
1420
|
|
|
if role_ids: |
|
1421
|
|
|
for role in role_ids: |
|
1422
|
|
|
cmd.add_element('role', attrs={'id': role}) |
|
1423
|
|
|
|
|
1424
|
|
|
return self._send_xml_command(cmd) |
|
1425
|
|
|
|
|
1426
|
|
|
def clone_user(self, user_id): |
|
1427
|
|
|
"""Clone an existing user |
|
1428
|
|
|
|
|
1429
|
|
|
Arguments: |
|
1430
|
|
|
user_id (str): UUID of existing user to clone from |
|
1431
|
|
|
|
|
1432
|
|
|
Returns: |
|
1433
|
|
|
The response. See :py:meth:`send_command` for details. |
|
1434
|
|
|
""" |
|
1435
|
|
|
cmd = XmlCommand('create_user') |
|
1436
|
|
|
cmd.add_element('copy', user_id) |
|
1437
|
|
|
return self._send_xml_command(cmd) |
|
1438
|
|
|
|
|
1439
|
|
|
def delete_agent(self, **kwargs): |
|
1440
|
|
|
cmd = self._generator.delete_agent_command(kwargs) |
|
1441
|
|
|
return self.send_command(cmd) |
|
1442
|
|
|
|
|
1443
|
|
|
def delete_alert(self, **kwargs): |
|
1444
|
|
|
cmd = self._generator.delete_alert_command(kwargs) |
|
1445
|
|
|
return self.send_command(cmd) |
|
1446
|
|
|
|
|
1447
|
|
|
def delete_asset(self, asset_id, ultimate=0): |
|
1448
|
|
|
cmd = self._generator.delete_asset_command(asset_id, ultimate) |
|
1449
|
|
|
return self.send_command(cmd) |
|
1450
|
|
|
|
|
1451
|
|
|
def delete_config(self, config_id, ultimate=0): |
|
1452
|
|
|
cmd = self._generator.delete_config_command(config_id, ultimate) |
|
1453
|
|
|
return self.send_command(cmd) |
|
1454
|
|
|
|
|
1455
|
|
|
def delete_credential(self, credential_id, ultimate=0): |
|
1456
|
|
|
cmd = self._generator.delete_credential_command(credential_id, ultimate) |
|
1457
|
|
|
return self.send_command(cmd) |
|
1458
|
|
|
|
|
1459
|
|
|
def delete_filter(self, filter_id, ultimate=0): |
|
1460
|
|
|
cmd = self._generator.delete_filter_command(filter_id, ultimate) |
|
1461
|
|
|
return self.send_command(cmd) |
|
1462
|
|
|
|
|
1463
|
|
|
def delete_group(self, group_id, ultimate=0): |
|
1464
|
|
|
cmd = self._generator.delete_group_command(group_id, ultimate) |
|
1465
|
|
|
return self.send_command(cmd) |
|
1466
|
|
|
|
|
1467
|
|
|
def delete_note(self, note_id, ultimate=0): |
|
1468
|
|
|
cmd = self._generator.delete_note_command(note_id, ultimate) |
|
1469
|
|
|
return self.send_command(cmd) |
|
1470
|
|
|
|
|
1471
|
|
|
def delete_override(self, override_id, ultimate=0): |
|
1472
|
|
|
cmd = self._generator.delete_override_command(override_id, ultimate) |
|
1473
|
|
|
return self.send_command(cmd) |
|
1474
|
|
|
|
|
1475
|
|
|
def delete_permission(self, permission_id, ultimate=0): |
|
1476
|
|
|
cmd = self._generator.delete_permission_command(permission_id, ultimate) |
|
1477
|
|
|
return self.send_command(cmd) |
|
1478
|
|
|
|
|
1479
|
|
|
def delete_port_list(self, port_list_id, ultimate=0): |
|
1480
|
|
|
cmd = self._generator.delete_port_list_command(port_list_id, ultimate) |
|
1481
|
|
|
return self.send_command(cmd) |
|
1482
|
|
|
|
|
1483
|
|
|
def delete_port_range(self, port_range_id): |
|
1484
|
|
|
cmd = self._generator.delete_port_range_command(port_range_id) |
|
1485
|
|
|
return self.send_command(cmd) |
|
1486
|
|
|
|
|
1487
|
|
|
def delete_report(self, report_id): |
|
1488
|
|
|
cmd = self._generator.delete_report_command(report_id) |
|
1489
|
|
|
return self.send_command(cmd) |
|
1490
|
|
|
|
|
1491
|
|
|
def delete_report_format(self, report_format_id, ultimate=0): |
|
1492
|
|
|
cmd = self._generator.delete_report_format_command( |
|
1493
|
|
|
report_format_id, ultimate) |
|
1494
|
|
|
return self.send_command(cmd) |
|
1495
|
|
|
|
|
1496
|
|
|
def delete_role(self, role_id, ultimate=0): |
|
1497
|
|
|
cmd = self._generator.delete_role_command(role_id, ultimate) |
|
1498
|
|
|
return self.send_command(cmd) |
|
1499
|
|
|
|
|
1500
|
|
|
def delete_scanner(self, scanner_id, ultimate=0): |
|
1501
|
|
|
cmd = self._generator.delete_scanner_command(scanner_id, ultimate) |
|
1502
|
|
|
return self.send_command(cmd) |
|
1503
|
|
|
|
|
1504
|
|
|
def delete_schedule(self, schedule_id, ultimate=0): |
|
1505
|
|
|
cmd = self._generator.delete_schedule_command(schedule_id, ultimate) |
|
1506
|
|
|
return self.send_command(cmd) |
|
1507
|
|
|
|
|
1508
|
|
|
def delete_tag(self, tag_id, ultimate=0): |
|
1509
|
|
|
cmd = self._generator.delete_tag_command(tag_id, ultimate) |
|
1510
|
|
|
return self.send_command(cmd) |
|
1511
|
|
|
|
|
1512
|
|
|
def delete_target(self, target_id, ultimate=0): |
|
1513
|
|
|
cmd = self._generator.delete_target_command(target_id, ultimate) |
|
1514
|
|
|
return self.send_command(cmd) |
|
1515
|
|
|
|
|
1516
|
|
|
def delete_task(self, task_id, ultimate=0): |
|
1517
|
|
|
cmd = self._generator.delete_task_command(task_id, ultimate) |
|
1518
|
|
|
return self.send_command(cmd) |
|
1519
|
|
|
|
|
1520
|
|
|
def delete_user(self, **kwargs): |
|
1521
|
|
|
cmd = self._generator.delete_user_command(kwargs) |
|
1522
|
|
|
return self.send_command(cmd) |
|
1523
|
|
|
|
|
1524
|
|
|
def describe_auth(self): |
|
1525
|
|
|
"""Describe authentication methods |
|
1526
|
|
|
|
|
1527
|
|
|
Returns a list of all used authentication methods if such a list is |
|
1528
|
|
|
available. |
|
1529
|
|
|
|
|
1530
|
|
|
Returns: |
|
1531
|
|
|
The response. See :py:meth:`send_command` for details. |
|
1532
|
|
|
""" |
|
1533
|
|
|
return self._send_xml_command(XmlCommand('describe_auth')) |
|
1534
|
|
|
|
|
1535
|
|
|
def empty_trashcan(self): |
|
1536
|
|
|
"""Empty the trashcan |
|
1537
|
|
|
|
|
1538
|
|
|
Remove all entities from the trashcan. **Attention:** this command can |
|
1539
|
|
|
not be reverted |
|
1540
|
|
|
|
|
1541
|
|
|
Returns: |
|
1542
|
|
|
The response. See :py:meth:`send_command` for details. |
|
1543
|
|
|
""" |
|
1544
|
|
|
return self._send_xml_command(XmlCommand('empty_trashcan')) |
|
1545
|
|
|
|
|
1546
|
|
|
def get_agents(self, filter=None, filter_id=None, trash=None, details=None, |
|
1547
|
|
|
format=None): |
|
1548
|
|
|
"""Request a list of agents |
|
1549
|
|
|
|
|
1550
|
|
|
Arguments: |
|
1551
|
|
|
filter (str, optional): Filter term to use for the query |
|
1552
|
|
|
filter_id (str, optional): UUID of an existing filter to use for |
|
1553
|
|
|
the query |
|
1554
|
|
|
trash (boolean, optional): True to request the filters in the |
|
1555
|
|
|
trashcan |
|
1556
|
|
|
details (boolean, optional): Whether to include agents package |
|
1557
|
|
|
information when no format was provided |
|
1558
|
|
|
format (str, optional): One of "installer", "howto_install" or |
|
1559
|
|
|
"howto_use" |
|
1560
|
|
|
|
|
1561
|
|
|
Returns: |
|
1562
|
|
|
The response. See :py:meth:`send_command` for details. |
|
1563
|
|
|
""" |
|
1564
|
|
|
cmd = XmlCommand('get_agents') |
|
1565
|
|
|
|
|
1566
|
|
|
_add_filter(cmd, filter, filter_id) |
|
1567
|
|
|
|
|
1568
|
|
|
if not trash is None: |
|
1569
|
|
|
cmd.set_attribute('trash', _to_bool(trash)) |
|
1570
|
|
|
|
|
1571
|
|
|
if not details is None: |
|
1572
|
|
|
cmd.set_attribute('details', _to_bool(details)) |
|
1573
|
|
|
|
|
1574
|
|
|
if format: |
|
1575
|
|
|
if not format in ('installer', 'howto_install', 'howto_use'): |
|
1576
|
|
|
raise InvalidArgument( |
|
1577
|
|
|
'installer argument needs to be one of installer, ' |
|
1578
|
|
|
'howto_install or howto_use') |
|
1579
|
|
|
|
|
1580
|
|
|
cmd.set_attribute('format', format) |
|
1581
|
|
|
|
|
1582
|
|
|
return self._send_xml_command(cmd) |
|
1583
|
|
|
|
|
1584
|
|
|
def get_agent(self, agent_id): |
|
1585
|
|
|
"""Request a single agent |
|
1586
|
|
|
|
|
1587
|
|
|
Arguments: |
|
1588
|
|
|
agent_id (str): UUID of an existing agent |
|
1589
|
|
|
|
|
1590
|
|
|
Returns: |
|
1591
|
|
|
The response. See :py:meth:`send_command` for details. |
|
1592
|
|
|
""" |
|
1593
|
|
|
cmd = XmlCommand('get_agents') |
|
1594
|
|
|
cmd.set_attribute('agent_id', agent_id) |
|
1595
|
|
|
return self._send_xml_command(cmd) |
|
1596
|
|
|
|
|
1597
|
|
|
def get_aggregates(self, **kwargs): |
|
1598
|
|
|
cmd = XmlCommand('get_aggregates') |
|
1599
|
|
|
cmd.set_attributes(kwargs) |
|
1600
|
|
|
return self._send_xml_command(cmd) |
|
1601
|
|
|
|
|
1602
|
|
|
def get_alerts(self, filter=None, filter_id=None, trash=None, tasks=None): |
|
1603
|
|
|
"""Request a list of alerts |
|
1604
|
|
|
|
|
1605
|
|
|
Arguments: |
|
1606
|
|
|
filter (str, optional): Filter term to use for the query |
|
1607
|
|
|
filter_id (str, optional): UUID of an existing filter to use for |
|
1608
|
|
|
the query |
|
1609
|
|
|
trash (boolean, optional): True to request the alerts in the |
|
1610
|
|
|
trashcan |
|
1611
|
|
|
tasks (boolean, optional): Whether to include the tasks using the |
|
1612
|
|
|
alerts |
|
1613
|
|
|
Returns: |
|
1614
|
|
|
The response. See :py:meth:`send_command` for details. |
|
1615
|
|
|
""" |
|
1616
|
|
|
cmd = XmlCommand('get_alerts') |
|
1617
|
|
|
|
|
1618
|
|
|
_add_filter(cmd, filter, filter_id) |
|
1619
|
|
|
|
|
1620
|
|
|
if not trash is None: |
|
1621
|
|
|
cmd.set_attribute('trash', _to_bool(trash)) |
|
1622
|
|
|
|
|
1623
|
|
|
if not tasks is None: |
|
1624
|
|
|
cmd.set_attribute('tasks', _to_bool(tasks)) |
|
1625
|
|
|
|
|
1626
|
|
|
return self._send_xml_command(cmd) |
|
1627
|
|
|
|
|
1628
|
|
|
def get_alert(self, alert_id): |
|
1629
|
|
|
"""Request a single alert |
|
1630
|
|
|
|
|
1631
|
|
|
Arguments: |
|
1632
|
|
|
alert_id (str): UUID of an existing alert |
|
1633
|
|
|
|
|
1634
|
|
|
Returns: |
|
1635
|
|
|
The response. See :py:meth:`send_command` for details. |
|
1636
|
|
|
""" |
|
1637
|
|
|
cmd = XmlCommand('get_alerts') |
|
1638
|
|
|
cmd.set_attribute('alert_id', alert_id) |
|
1639
|
|
|
return self._send_xml_command(cmd) |
|
1640
|
|
|
|
|
1641
|
|
|
def get_assets(self, filter=None, filter_id=None): |
|
1642
|
|
|
"""Request a list of assets |
|
1643
|
|
|
|
|
1644
|
|
|
Arguments: |
|
1645
|
|
|
filter (str, optional): Filter term to use for the query |
|
1646
|
|
|
filter_id (str, optional): UUID of an existing filter to use for |
|
1647
|
|
|
the query |
|
1648
|
|
|
|
|
1649
|
|
|
Returns: |
|
1650
|
|
|
The response. See :py:meth:`send_command` for details. |
|
1651
|
|
|
""" |
|
1652
|
|
|
cmd = XmlCommand('get_assets') |
|
1653
|
|
|
|
|
1654
|
|
|
_add_filter(cmd, filter, filter_id) |
|
1655
|
|
|
|
|
1656
|
|
|
return self._send_xml_command(cmd) |
|
1657
|
|
|
|
|
1658
|
|
|
def get_asset(self, asset_id): |
|
1659
|
|
|
"""Request a single asset |
|
1660
|
|
|
|
|
1661
|
|
|
Arguments: |
|
1662
|
|
|
asset_id (str): UUID of an existing asset |
|
1663
|
|
|
|
|
1664
|
|
|
Returns: |
|
1665
|
|
|
The response. See :py:meth:`send_command` for details. |
|
1666
|
|
|
""" |
|
1667
|
|
|
cmd = XmlCommand('get_assets') |
|
1668
|
|
|
cmd.set_attribute('asset_id', asset_id) |
|
1669
|
|
|
return self._send_xml_command(cmd) |
|
1670
|
|
|
|
|
1671
|
|
|
def get_credentials(self, filter=None, filter_id=None, scanners=None, |
|
1672
|
|
|
trash=None, targets=None, format=None): |
|
1673
|
|
|
"""Request a list of credentials |
|
1674
|
|
|
|
|
1675
|
|
|
Arguments: |
|
1676
|
|
|
filter (str, optional): Filter term to use for the query |
|
1677
|
|
|
filter_id (str, optional): UUID of an existing filter to use for |
|
1678
|
|
|
the query |
|
1679
|
|
|
scanners (boolean, optional): Whether to include a list of scanners |
|
1680
|
|
|
using the credentials |
|
1681
|
|
|
trash (boolean, optional): Whether to get the trashcan credentials |
|
1682
|
|
|
instead |
|
1683
|
|
|
targets (boolean, optional): Whether to include a list of targets |
|
1684
|
|
|
using the credentials |
|
1685
|
|
|
format (str, optional): One of "key", "rpm", "deb" or "exe" |
|
1686
|
|
|
|
|
1687
|
|
|
Returns: |
|
1688
|
|
|
The response. See :py:meth:`send_command` for details. |
|
1689
|
|
|
""" |
|
1690
|
|
|
cmd = XmlCommand('get_credentials') |
|
1691
|
|
|
|
|
1692
|
|
|
_add_filter(cmd, filter, filter_id) |
|
1693
|
|
|
|
|
1694
|
|
|
if not scanners is None: |
|
1695
|
|
|
cmd.set_attribute('scanners', _to_bool(scanners)) |
|
1696
|
|
|
|
|
1697
|
|
|
if not trash is None: |
|
1698
|
|
|
cmd.set_attribute('trash', _to_bool(trash)) |
|
1699
|
|
|
|
|
1700
|
|
|
if not targets is None: |
|
1701
|
|
|
cmd.set_attribute('targets', _to_bool(targets)) |
|
1702
|
|
|
|
|
1703
|
|
|
if format: |
|
1704
|
|
|
if not format in ('key', 'rpm', 'deb', 'exe'): |
|
1705
|
|
|
raise InvalidArgument( |
|
1706
|
|
|
'format argument needs to one of key, rpm, deb or exe') |
|
1707
|
|
|
|
|
1708
|
|
|
cmd.set_attribute('format', format) |
|
1709
|
|
|
|
|
1710
|
|
|
return self.send_command(cmd) |
|
1711
|
|
|
|
|
1712
|
|
|
def get_credential(self, credential_id): |
|
1713
|
|
|
"""Request a single credential |
|
1714
|
|
|
|
|
1715
|
|
|
Arguments: |
|
1716
|
|
|
credential_id (str): UUID of an existing credential |
|
1717
|
|
|
|
|
1718
|
|
|
Returns: |
|
1719
|
|
|
The response. See :py:meth:`send_command` for details. |
|
1720
|
|
|
""" |
|
1721
|
|
|
cmd = XmlCommand('get_credentials') |
|
1722
|
|
|
cmd.set_attribute('credential_id', credential_id) |
|
1723
|
|
|
return self._send_xml_command(cmd) |
|
1724
|
|
|
|
|
1725
|
|
|
def get_configs(self, filter=None, filter_id=None, trash=None, details=None, |
|
1726
|
|
|
families=None, preferences=None, tasks=None): |
|
1727
|
|
|
"""Request a list of scan configs |
|
1728
|
|
|
|
|
1729
|
|
|
Arguments: |
|
1730
|
|
|
filter (str, optional): Filter term to use for the query |
|
1731
|
|
|
filter_id (str, optional): UUID of an existing filter to use for |
|
1732
|
|
|
the query |
|
1733
|
|
|
trash (boolean, optional): Whether to get the trashcan scan configs |
|
1734
|
|
|
instead |
|
1735
|
|
|
details (boolean, optional): Whether to get config families, |
|
1736
|
|
|
preferences, nvt selectors and tasks. |
|
1737
|
|
|
families (boolean, optional): Whether to include the families if no |
|
1738
|
|
|
details are requested |
|
1739
|
|
|
preferences (boolean, optional): Whether to include the preferences |
|
1740
|
|
|
if no details are requested |
|
1741
|
|
|
tasks (boolean, optional): Whether to get tasks using this config |
|
1742
|
|
|
|
|
1743
|
|
|
Returns: |
|
1744
|
|
|
The response. See :py:meth:`send_command` for details. |
|
1745
|
|
|
""" |
|
1746
|
|
|
cmd = XmlCommand('get_credentials') |
|
1747
|
|
|
|
|
1748
|
|
|
_add_filter(cmd, filter, filter_id) |
|
1749
|
|
|
|
|
1750
|
|
|
if not trash is None: |
|
1751
|
|
|
cmd.set_attribute('trash', _to_bool(trash)) |
|
1752
|
|
|
|
|
1753
|
|
|
if not details is None: |
|
1754
|
|
|
cmd.set_attribute('details', _to_bool(details)) |
|
1755
|
|
|
|
|
1756
|
|
|
if not families is None: |
|
1757
|
|
|
cmd.set_attribute('families', _to_bool(families)) |
|
1758
|
|
|
|
|
1759
|
|
|
if not preferences is None: |
|
1760
|
|
|
cmd.set_attribute('preferences', _to_bool(preferences)) |
|
1761
|
|
|
|
|
1762
|
|
|
if not tasks is None: |
|
1763
|
|
|
cmd.set_attribute('tasks', _to_bool(tasks)) |
|
1764
|
|
|
|
|
1765
|
|
|
return self._send_xml_command(cmd) |
|
1766
|
|
|
|
|
1767
|
|
|
def get_config(self, config_id): |
|
1768
|
|
|
"""Request a single scan config |
|
1769
|
|
|
|
|
1770
|
|
|
Arguments: |
|
1771
|
|
|
config_id (str): UUID of an existing scan config |
|
1772
|
|
|
|
|
1773
|
|
|
Returns: |
|
1774
|
|
|
The response. See :py:meth:`send_command` for details. |
|
1775
|
|
|
""" |
|
1776
|
|
|
cmd = XmlCommand('get_configs') |
|
1777
|
|
|
cmd.set_attribute('config_id', config_id) |
|
1778
|
|
|
return self._send_xml_command(cmd) |
|
1779
|
|
|
|
|
1780
|
|
|
def get_feeds(self): |
|
1781
|
|
|
"""Request the list of feeds |
|
1782
|
|
|
|
|
1783
|
|
|
Returns: |
|
1784
|
|
|
The response. See :py:meth:`send_command` for details. |
|
1785
|
|
|
""" |
|
1786
|
|
|
return self._send_xml_command(XmlCommand('get_feeds')) |
|
1787
|
|
|
|
|
1788
|
|
|
def get_feed(self, feed_type): |
|
1789
|
|
|
"""Request a single feed |
|
1790
|
|
|
|
|
1791
|
|
|
Arguments: |
|
1792
|
|
|
feed_type (str): Type of single feed to get: NVT, CERT or SCAP |
|
1793
|
|
|
|
|
1794
|
|
|
Returns: |
|
1795
|
|
|
The response. See :py:meth:`send_command` for details. |
|
1796
|
|
|
""" |
|
1797
|
|
|
feed_type = feed_type.upper() |
|
1798
|
|
|
|
|
1799
|
|
|
if not feed_type in ('NVT', 'CERT', 'SCAP'): |
|
1800
|
|
|
raise InvalidArgument( |
|
1801
|
|
|
'get_feed type arguments must be one of NVT, CERT or SCAP') |
|
1802
|
|
|
|
|
1803
|
|
|
cmd = XmlCommand('get_feeds') |
|
1804
|
|
|
cmd.set_attribute('type', feed_type) |
|
1805
|
|
|
|
|
1806
|
|
|
return self._send_xml_command(cmd) |
|
1807
|
|
|
|
|
1808
|
|
|
def get_filters(self, filter=None, filter_id=None, trash=None, alerts=None): |
|
1809
|
|
|
"""Request a list of filters |
|
1810
|
|
|
|
|
1811
|
|
|
Arguments: |
|
1812
|
|
|
filter (str, optional): Filter term to use for the query |
|
1813
|
|
|
filter_id (str, optional): UUID of an existing filter to use for |
|
1814
|
|
|
the query |
|
1815
|
|
|
trash (boolean, optional): Whether to get the trashcan filters |
|
1816
|
|
|
instead |
|
1817
|
|
|
alerts (boolean, optional): Whether to include list of alerts that |
|
1818
|
|
|
use the filter. |
|
1819
|
|
|
|
|
1820
|
|
|
Returns: |
|
1821
|
|
|
The response. See :py:meth:`send_command` for details. |
|
1822
|
|
|
""" |
|
1823
|
|
|
cmd = XmlCommand('get_filters') |
|
1824
|
|
|
|
|
1825
|
|
|
_add_filter(cmd, filter, filter_id) |
|
1826
|
|
|
|
|
1827
|
|
|
if not trash is None: |
|
1828
|
|
|
cmd.set_attribute('trash', _to_bool(trash)) |
|
1829
|
|
|
|
|
1830
|
|
|
if not alerts is None: |
|
1831
|
|
|
cmd.set_attribute('alerts', _to_bool(alerts)) |
|
1832
|
|
|
|
|
1833
|
|
|
return self._send_xml_command(cmd) |
|
1834
|
|
|
|
|
1835
|
|
|
def get_filter(self, filter_id): |
|
1836
|
|
|
"""Request a single filter |
|
1837
|
|
|
|
|
1838
|
|
|
Arguments: |
|
1839
|
|
|
filter_id (str): UUID of an existing filter |
|
1840
|
|
|
|
|
1841
|
|
|
Returns: |
|
1842
|
|
|
The response. See :py:meth:`send_command` for details. |
|
1843
|
|
|
""" |
|
1844
|
|
|
cmd = XmlCommand('get_filters') |
|
1845
|
|
|
cmd.set_attribute('filter_id', filter_id) |
|
1846
|
|
|
return self._send_xml_command(cmd) |
|
1847
|
|
|
|
|
1848
|
|
|
def get_groups(self, filter=None, filter_id=None, trash=None): |
|
1849
|
|
|
"""Request a list of groups |
|
1850
|
|
|
|
|
1851
|
|
|
Arguments: |
|
1852
|
|
|
filter (str, optional): Filter term to use for the query |
|
1853
|
|
|
filter_id (str, optional): UUID of an existing filter to use for |
|
1854
|
|
|
the query |
|
1855
|
|
|
trash (boolean, optional): Whether to get the trashcan groups |
|
1856
|
|
|
instead |
|
1857
|
|
|
Returns: |
|
1858
|
|
|
The response. See :py:meth:`send_command` for details. |
|
1859
|
|
|
""" |
|
1860
|
|
|
cmd = XmlCommand('get_groups') |
|
1861
|
|
|
|
|
1862
|
|
|
_add_filter(cmd, filter, filter_id) |
|
1863
|
|
|
|
|
1864
|
|
|
if not trash is None: |
|
1865
|
|
|
cmd.set_attribute('trash', _to_bool(trash)) |
|
1866
|
|
|
|
|
1867
|
|
|
return self._send_xml_command(cmd) |
|
1868
|
|
|
|
|
1869
|
|
|
def get_group(self, group_id): |
|
1870
|
|
|
"""Request a single group |
|
1871
|
|
|
|
|
1872
|
|
|
Arguments: |
|
1873
|
|
|
group_id (str): UUID of an existing group |
|
1874
|
|
|
|
|
1875
|
|
|
Returns: |
|
1876
|
|
|
The response. See :py:meth:`send_command` for details. |
|
1877
|
|
|
""" |
|
1878
|
|
|
cmd = XmlCommand('get_groups') |
|
1879
|
|
|
cmd.set_attribute('group_id', group_id) |
|
1880
|
|
|
return self._send_xml_command(cmd) |
|
1881
|
|
|
|
|
1882
|
|
|
def get_info_list(self, info_type, filter=None, filter_id=None, |
|
1883
|
|
|
name=None, details=None): |
|
1884
|
|
|
"""Request a list of security information |
|
1885
|
|
|
|
|
1886
|
|
|
Arguments: |
|
1887
|
|
|
info_type (str): Type must be either CERT_BUND_ADV, CPE, CVE, |
|
1888
|
|
|
DFN_CERT_ADV, OVALDEF, NVT or ALLINFO |
|
1889
|
|
|
filter (str, optional): Filter term to use for the query |
|
1890
|
|
|
filter_id (str, optional): UUID of an existing filter to use for |
|
1891
|
|
|
the query |
|
1892
|
|
|
name (str, optional): Name or identifier of the requested |
|
1893
|
|
|
information |
|
1894
|
|
|
details (boolean, optional): Whether to include information about |
|
1895
|
|
|
references to this information |
|
1896
|
|
|
|
|
1897
|
|
|
Returns: |
|
1898
|
|
|
The response. See :py:meth:`send_command` for details. |
|
1899
|
|
|
""" |
|
1900
|
|
|
info_type = info_type.upper() |
|
1901
|
|
|
|
|
1902
|
|
|
if not info_type in ( |
|
1903
|
|
|
'CERT_BUND_ADV', 'CPE', 'CVE', 'DFN_CERT_ADV', 'OVALDEF', 'NVT', |
|
1904
|
|
|
'ALLINFO'): |
|
1905
|
|
|
raise InvalidArgument( |
|
1906
|
|
|
'get_info_list info_type argument must be one of CERT_BUND_ADV' |
|
1907
|
|
|
', CPE, CVE, DFN_CERT_ADV, OVALDEF, NVT or ALLINFO') |
|
1908
|
|
|
|
|
1909
|
|
|
cmd = XmlCommand('get_groups') |
|
1910
|
|
|
|
|
1911
|
|
|
_add_filter(cmd, filter, filter_id) |
|
1912
|
|
|
|
|
1913
|
|
|
if name: |
|
1914
|
|
|
cmd.set_attribute('name', name) |
|
1915
|
|
|
|
|
1916
|
|
|
if not details is None: |
|
1917
|
|
|
cmd.set_attribute('details', _to_bool(details)) |
|
1918
|
|
|
|
|
1919
|
|
|
return self._send_xml_command(cmd) |
|
1920
|
|
|
|
|
1921
|
|
|
def get_info(self, info_id): |
|
1922
|
|
|
"""Request a single secinfo |
|
1923
|
|
|
|
|
1924
|
|
|
Arguments: |
|
1925
|
|
|
info_id (str): UUID of an existing secinfo |
|
1926
|
|
|
|
|
1927
|
|
|
Returns: |
|
1928
|
|
|
The response. See :py:meth:`send_command` for details. |
|
1929
|
|
|
""" |
|
1930
|
|
|
cmd = XmlCommand('get_infos') |
|
1931
|
|
|
cmd.set_attribute('info_id', info_id) |
|
1932
|
|
|
return self._send_xml_command(cmd) |
|
1933
|
|
|
|
|
1934
|
|
|
def get_notes(self, filter=None, filter_id=None, nvt_oid=None, |
|
1935
|
|
|
task_id=None, details=None, result=None): |
|
1936
|
|
|
"""Request a list of notes |
|
1937
|
|
|
|
|
1938
|
|
|
Arguments: |
|
1939
|
|
|
filter (str, optional): Filter term to use for the query |
|
1940
|
|
|
filter_id (str, optional): UUID of an existing filter to use for |
|
1941
|
|
|
the query |
|
1942
|
|
|
nvt_oid (str, optional): OID of a nvt |
|
1943
|
|
|
task_id (str, optional): UUID of a task |
|
1944
|
|
|
details (boolean, optional): |
|
1945
|
|
|
result (boolean, optional): |
|
1946
|
|
|
|
|
1947
|
|
|
Returns: |
|
1948
|
|
|
The response. See :py:meth:`send_command` for details. |
|
1949
|
|
|
""" |
|
1950
|
|
|
cmd = XmlCommand('get_notes') |
|
1951
|
|
|
|
|
1952
|
|
|
_add_filter(cmd, filter, filter_id) |
|
1953
|
|
|
|
|
1954
|
|
|
if nvt_oid: |
|
1955
|
|
|
cmd.set_attribute('nvt_oid', nvt_oid) |
|
1956
|
|
|
|
|
1957
|
|
|
if task_id: |
|
1958
|
|
|
cmd.set_attribute('task_id', task_id) |
|
1959
|
|
|
|
|
1960
|
|
|
if not details is None: |
|
1961
|
|
|
cmd.set_attribute('details', _to_bool(details)) |
|
1962
|
|
|
|
|
1963
|
|
|
if not result is None: |
|
1964
|
|
|
cmd.set_attribute('result', _to_bool(result)) |
|
1965
|
|
|
|
|
1966
|
|
|
return self._send_xml_command(cmd) |
|
1967
|
|
|
|
|
1968
|
|
|
def get_note(self, note_id): |
|
1969
|
|
|
"""Request a single note |
|
1970
|
|
|
|
|
1971
|
|
|
Arguments: |
|
1972
|
|
|
note_id (str): UUID of an existing note |
|
1973
|
|
|
|
|
1974
|
|
|
Returns: |
|
1975
|
|
|
The response. See :py:meth:`send_command` for details. |
|
1976
|
|
|
""" |
|
1977
|
|
|
cmd = XmlCommand('get_notes') |
|
1978
|
|
|
cmd.set_attribute('note_id', note_id) |
|
1979
|
|
|
return self._send_xml_command(cmd) |
|
1980
|
|
|
|
|
1981
|
|
|
def get_nvts(self, details=None, preferences=None, preference_count=None, |
|
1982
|
|
|
timeout=None, config_id=None, preferences_config_id=None, |
|
1983
|
|
|
family=None, sort_order=None, sort_field=None): |
|
1984
|
|
|
"""Request a list of nvts |
|
1985
|
|
|
|
|
1986
|
|
|
Arguments: |
|
1987
|
|
|
details (boolean, optional): Whether to include full details |
|
1988
|
|
|
preferences (boolean, optional): Whether to include nvt preferences |
|
1989
|
|
|
preference_count (boolean, optional): Whether to include preference |
|
1990
|
|
|
count |
|
1991
|
|
|
timeout (boolean, optional): Whether to include the special timeout |
|
1992
|
|
|
preference |
|
1993
|
|
|
config_id (str, optional): UUID of scan config to which to limit the |
|
1994
|
|
|
NVT listing |
|
1995
|
|
|
preferences_config_id (str, optional): UUID of scan config to use |
|
1996
|
|
|
for preference values |
|
1997
|
|
|
family (str, optional): Family to which to limit NVT listing |
|
1998
|
|
|
sort_order (str, optional): Sort order |
|
1999
|
|
|
sort_field (str, optional): Sort field |
|
2000
|
|
|
|
|
2001
|
|
|
Returns: |
|
2002
|
|
|
The response. See :py:meth:`send_command` for details. |
|
2003
|
|
|
""" |
|
2004
|
|
|
cmd = XmlCommand('get_notes') |
|
2005
|
|
|
|
|
2006
|
|
|
if not details is None: |
|
2007
|
|
|
cmd.set_attribute('details', _to_bool(details)) |
|
2008
|
|
|
|
|
2009
|
|
|
if not preferences is None: |
|
2010
|
|
|
cmd.set_attribute('preferences', _to_bool(preferences)) |
|
2011
|
|
|
|
|
2012
|
|
|
if not preference_count is None: |
|
2013
|
|
|
cmd.set_attribute('preference_count', _to_bool(preference_count)) |
|
2014
|
|
|
|
|
2015
|
|
|
if not timeout is None: |
|
2016
|
|
|
cmd.set_attribute('timeout', _to_bool(timeout)) |
|
2017
|
|
|
|
|
2018
|
|
|
if config_id: |
|
2019
|
|
|
cmd.set_attribute('config_id', config_id) |
|
2020
|
|
|
|
|
2021
|
|
|
if preferences_config_id: |
|
2022
|
|
|
cmd.set_attribute('preferences_config_id', preferences_config_id) |
|
2023
|
|
|
|
|
2024
|
|
|
if family: |
|
2025
|
|
|
cmd.set_attribute('family', family) |
|
2026
|
|
|
|
|
2027
|
|
|
if sort_order: |
|
2028
|
|
|
cmd.set_attribute('sort_order', sort_order) |
|
2029
|
|
|
|
|
2030
|
|
|
if sort_field: |
|
2031
|
|
|
cmd.set_attribute('sort_field', sort_field) |
|
2032
|
|
|
|
|
2033
|
|
|
return self._send_xml_command(cmd) |
|
2034
|
|
|
|
|
2035
|
|
|
def get_nvt(self, nvt_id): |
|
2036
|
|
|
"""Request a single nvt |
|
2037
|
|
|
|
|
2038
|
|
|
Arguments: |
|
2039
|
|
|
nvt_id (str): OID of an existing nvt |
|
2040
|
|
|
|
|
2041
|
|
|
Returns: |
|
2042
|
|
|
The response. See :py:meth:`send_command` for details. |
|
2043
|
|
|
""" |
|
2044
|
|
|
cmd = XmlCommand('get_nvts') |
|
2045
|
|
|
cmd.set_attribute('nvt_id', nvt_id) |
|
2046
|
|
|
return self._send_xml_command(cmd) |
|
2047
|
|
|
|
|
2048
|
|
|
def get_nvt_families(self, **kwargs): |
|
2049
|
|
|
cmd = self._generator.get_nvt_families_command(kwargs) |
|
2050
|
|
|
return self.send_command(cmd) |
|
2051
|
|
|
|
|
2052
|
|
|
def get_overrides(self, **kwargs): |
|
2053
|
|
|
cmd = self._generator.get_overrides_command(kwargs) |
|
2054
|
|
|
return self.send_command(cmd) |
|
2055
|
|
|
|
|
2056
|
|
|
def get_override(self, override_id): |
|
2057
|
|
|
"""Request a single override |
|
2058
|
|
|
|
|
2059
|
|
|
Arguments: |
|
2060
|
|
|
override_id (str): UUID of an existing override |
|
2061
|
|
|
|
|
2062
|
|
|
Returns: |
|
2063
|
|
|
The response. See :py:meth:`send_command` for details. |
|
2064
|
|
|
""" |
|
2065
|
|
|
cmd = XmlCommand('get_overrides') |
|
2066
|
|
|
cmd.set_attribute('override_id', override_id) |
|
2067
|
|
|
return self._send_xml_command(cmd) |
|
2068
|
|
|
|
|
2069
|
|
|
def get_permissions(self, **kwargs): |
|
2070
|
|
|
cmd = self._generator.get_permissions_command(kwargs) |
|
2071
|
|
|
return self.send_command(cmd) |
|
2072
|
|
|
|
|
2073
|
|
|
def get_permission(self, permission_id): |
|
2074
|
|
|
"""Request a single permission |
|
2075
|
|
|
|
|
2076
|
|
|
Arguments: |
|
2077
|
|
|
permission_id (str): UUID of an existing permission |
|
2078
|
|
|
|
|
2079
|
|
|
Returns: |
|
2080
|
|
|
The response. See :py:meth:`send_command` for details. |
|
2081
|
|
|
""" |
|
2082
|
|
|
cmd = XmlCommand('get_permissions') |
|
2083
|
|
|
cmd.set_attribute('permission_id', permission_id) |
|
2084
|
|
|
return self._send_xml_command(cmd) |
|
2085
|
|
|
|
|
2086
|
|
|
def get_port_lists(self, **kwargs): |
|
2087
|
|
|
cmd = self._generator.get_port_lists_command(kwargs) |
|
2088
|
|
|
return self.send_command(cmd) |
|
2089
|
|
|
|
|
2090
|
|
|
def get_port_list(self, port_list_id): |
|
2091
|
|
|
"""Request a single port list |
|
2092
|
|
|
|
|
2093
|
|
|
Arguments: |
|
2094
|
|
|
port_list_id (str): UUID of an existing port list |
|
2095
|
|
|
|
|
2096
|
|
|
Returns: |
|
2097
|
|
|
The response. See :py:meth:`send_command` for details. |
|
2098
|
|
|
""" |
|
2099
|
|
|
cmd = XmlCommand('get_port_lists') |
|
2100
|
|
|
cmd.set_attribute('port_list_id', port_list_id) |
|
2101
|
|
|
return self._send_xml_command(cmd) |
|
2102
|
|
|
|
|
2103
|
|
|
def get_preferences(self, **kwargs): |
|
2104
|
|
|
cmd = self._generator.get_preferences_command(kwargs) |
|
2105
|
|
|
return self.send_command(cmd) |
|
2106
|
|
|
|
|
2107
|
|
|
def get_reports(self, **kwargs): |
|
2108
|
|
|
cmd = self._generator.get_reports_command(kwargs) |
|
2109
|
|
|
return self.send_command(cmd) |
|
2110
|
|
|
|
|
2111
|
|
|
def get_report(self, report_id): |
|
2112
|
|
|
"""Request a single report |
|
2113
|
|
|
|
|
2114
|
|
|
Arguments: |
|
2115
|
|
|
report_id (str): UUID of an existing report |
|
2116
|
|
|
|
|
2117
|
|
|
Returns: |
|
2118
|
|
|
The response. See :py:meth:`send_command` for details. |
|
2119
|
|
|
""" |
|
2120
|
|
|
cmd = XmlCommand('get_reports') |
|
2121
|
|
|
cmd.set_attribute('report_id', report_id) |
|
2122
|
|
|
return self._send_xml_command(cmd) |
|
2123
|
|
|
|
|
2124
|
|
|
def get_report_formats(self, **kwargs): |
|
2125
|
|
|
cmd = self._generator.get_report_formats_command(kwargs) |
|
2126
|
|
|
return self.send_command(cmd) |
|
2127
|
|
|
|
|
2128
|
|
|
def get_report_format(self, report_format_id): |
|
2129
|
|
|
"""Request a single report format |
|
2130
|
|
|
|
|
2131
|
|
|
Arguments: |
|
2132
|
|
|
report_format_id (str): UUID of an existing report format |
|
2133
|
|
|
|
|
2134
|
|
|
Returns: |
|
2135
|
|
|
The response. See :py:meth:`send_command` for details. |
|
2136
|
|
|
""" |
|
2137
|
|
|
cmd = XmlCommand('get_report_formats') |
|
2138
|
|
|
cmd.set_attribute('report_format_id', report_format_id) |
|
2139
|
|
|
return self._send_xml_command(cmd) |
|
2140
|
|
|
|
|
2141
|
|
|
def get_results(self, **kwargs): |
|
2142
|
|
|
cmd = self._generator.get_results_command(kwargs) |
|
2143
|
|
|
return self.send_command(cmd) |
|
2144
|
|
|
|
|
2145
|
|
|
def get_result(self, result_id): |
|
2146
|
|
|
"""Request a single result |
|
2147
|
|
|
|
|
2148
|
|
|
Arguments: |
|
2149
|
|
|
result_id (str): UUID of an existing result |
|
2150
|
|
|
|
|
2151
|
|
|
Returns: |
|
2152
|
|
|
The response. See :py:meth:`send_command` for details. |
|
2153
|
|
|
""" |
|
2154
|
|
|
cmd = XmlCommand('get_results') |
|
2155
|
|
|
cmd.set_attribute('result_id', result_id) |
|
2156
|
|
|
return self._send_xml_command(cmd) |
|
2157
|
|
|
|
|
2158
|
|
|
def get_roles(self, **kwargs): |
|
2159
|
|
|
cmd = self._generator.get_roles_command(kwargs) |
|
2160
|
|
|
return self.send_command(cmd) |
|
2161
|
|
|
|
|
2162
|
|
|
def get_role(self, role_id): |
|
2163
|
|
|
"""Request a single role |
|
2164
|
|
|
|
|
2165
|
|
|
Arguments: |
|
2166
|
|
|
role_id (str): UUID of an existing role |
|
2167
|
|
|
|
|
2168
|
|
|
Returns: |
|
2169
|
|
|
The response. See :py:meth:`send_command` for details. |
|
2170
|
|
|
""" |
|
2171
|
|
|
cmd = XmlCommand('get_roles') |
|
2172
|
|
|
cmd.set_attribute('role_id', role_id) |
|
2173
|
|
|
return self._send_xml_command(cmd) |
|
2174
|
|
|
|
|
2175
|
|
|
def get_scanners(self, **kwargs): |
|
2176
|
|
|
cmd = self._generator.get_scanners_command(kwargs) |
|
2177
|
|
|
return self.send_command(cmd) |
|
2178
|
|
|
|
|
2179
|
|
|
def get_scanner(self, scanner_id): |
|
2180
|
|
|
"""Request a single scanner |
|
2181
|
|
|
|
|
2182
|
|
|
Arguments: |
|
2183
|
|
|
scanner_id (str): UUID of an existing scanner |
|
2184
|
|
|
|
|
2185
|
|
|
Returns: |
|
2186
|
|
|
The response. See :py:meth:`send_command` for details. |
|
2187
|
|
|
""" |
|
2188
|
|
|
cmd = XmlCommand('get_scanners') |
|
2189
|
|
|
cmd.set_attribute('scanner_id', scanner_id) |
|
2190
|
|
|
return self._send_xml_command(cmd) |
|
2191
|
|
|
|
|
2192
|
|
|
def get_schedules(self, **kwargs): |
|
2193
|
|
|
cmd = self._generator.get_schedules_command(kwargs) |
|
2194
|
|
|
return self.send_command(cmd) |
|
2195
|
|
|
|
|
2196
|
|
|
def get_schedule(self, schedule_id): |
|
2197
|
|
|
"""Request a single schedule |
|
2198
|
|
|
|
|
2199
|
|
|
Arguments: |
|
2200
|
|
|
schedule_id (str): UUID of an existing schedule |
|
2201
|
|
|
|
|
2202
|
|
|
Returns: |
|
2203
|
|
|
The response. See :py:meth:`send_command` for details. |
|
2204
|
|
|
""" |
|
2205
|
|
|
cmd = XmlCommand('get_schedules') |
|
2206
|
|
|
cmd.set_attribute('schedule_id', schedule_id) |
|
2207
|
|
|
return self._send_xml_command(cmd) |
|
2208
|
|
|
|
|
2209
|
|
|
def get_settings(self, **kwargs): |
|
2210
|
|
|
cmd = self._generator.get_settings_command(kwargs) |
|
2211
|
|
|
return self.send_command(cmd) |
|
2212
|
|
|
|
|
2213
|
|
|
def get_setting(self, setting_id): |
|
2214
|
|
|
"""Request a single setting |
|
2215
|
|
|
|
|
2216
|
|
|
Arguments: |
|
2217
|
|
|
setting_id (str): UUID of an existing setting |
|
2218
|
|
|
|
|
2219
|
|
|
Returns: |
|
2220
|
|
|
The response. See :py:meth:`send_command` for details. |
|
2221
|
|
|
""" |
|
2222
|
|
|
cmd = XmlCommand('get_settings') |
|
2223
|
|
|
cmd.set_attribute('setting_id', setting_id) |
|
2224
|
|
|
return self._send_xml_command(cmd) |
|
2225
|
|
|
|
|
2226
|
|
|
def get_system_reports(self, **kwargs): |
|
2227
|
|
|
cmd = self._generator.get_system_reports_command(kwargs) |
|
2228
|
|
|
return self.send_command(cmd) |
|
2229
|
|
|
|
|
2230
|
|
|
def get_tags(self, **kwargs): |
|
2231
|
|
|
cmd = self._generator.get_tags_command(kwargs) |
|
2232
|
|
|
return self.send_command(cmd) |
|
2233
|
|
|
|
|
2234
|
|
|
def get_tag(self, tag_id): |
|
2235
|
|
|
"""Request a single tag |
|
2236
|
|
|
|
|
2237
|
|
|
Arguments: |
|
2238
|
|
|
tag_id (str): UUID of an existing tag |
|
2239
|
|
|
|
|
2240
|
|
|
Returns: |
|
2241
|
|
|
The response. See :py:meth:`send_command` for details. |
|
2242
|
|
|
""" |
|
2243
|
|
|
cmd = XmlCommand('get_tags') |
|
2244
|
|
|
cmd.set_attribute('tag_id', tag_id) |
|
2245
|
|
|
return self._send_xml_command(cmd) |
|
2246
|
|
|
|
|
2247
|
|
|
def get_targets(self, **kwargs): |
|
2248
|
|
|
cmd = self._generator.get_targets_command(kwargs) |
|
2249
|
|
|
return self.send_command(cmd) |
|
2250
|
|
|
|
|
2251
|
|
|
def get_target(self, target_id): |
|
2252
|
|
|
"""Request a single target |
|
2253
|
|
|
|
|
2254
|
|
|
Arguments: |
|
2255
|
|
|
target_id (str): UUID of an existing target |
|
2256
|
|
|
|
|
2257
|
|
|
Returns: |
|
2258
|
|
|
The response. See :py:meth:`send_command` for details. |
|
2259
|
|
|
""" |
|
2260
|
|
|
cmd = XmlCommand('get_targets') |
|
2261
|
|
|
cmd.set_attribute('target_id', target_id) |
|
2262
|
|
|
return self._send_xml_command(cmd) |
|
2263
|
|
|
|
|
2264
|
|
|
def get_tasks(self, **kwargs): |
|
2265
|
|
|
cmd = self._generator.get_tasks_command(kwargs) |
|
2266
|
|
|
return self.send_command(cmd) |
|
2267
|
|
|
|
|
2268
|
|
|
def get_task(self, task_id): |
|
2269
|
|
|
"""Request a single task |
|
2270
|
|
|
|
|
2271
|
|
|
Arguments: |
|
2272
|
|
|
task_id (str): UUID of an existing task |
|
2273
|
|
|
|
|
2274
|
|
|
Returns: |
|
2275
|
|
|
The response. See :py:meth:`send_command` for details. |
|
2276
|
|
|
""" |
|
2277
|
|
|
cmd = XmlCommand('get_tasks') |
|
2278
|
|
|
cmd.set_attribute('task_id', task_id) |
|
2279
|
|
|
return self._send_xml_command(cmd) |
|
2280
|
|
|
|
|
2281
|
|
|
def get_users(self, **kwargs): |
|
2282
|
|
|
cmd = self._generator.get_users_command(kwargs) |
|
2283
|
|
|
return self.send_command(cmd) |
|
2284
|
|
|
|
|
2285
|
|
|
def get_user(self, user_id): |
|
2286
|
|
|
"""Request a single user |
|
2287
|
|
|
|
|
2288
|
|
|
Arguments: |
|
2289
|
|
|
user_id (str): UUID of an existing user |
|
2290
|
|
|
|
|
2291
|
|
|
Returns: |
|
2292
|
|
|
The response. See :py:meth:`send_command` for details. |
|
2293
|
|
|
""" |
|
2294
|
|
|
cmd = XmlCommand('get_users') |
|
2295
|
|
|
cmd.set_attribute('user_id', user_id) |
|
2296
|
|
|
return self._send_xml_command(cmd) |
|
2297
|
|
|
|
|
2298
|
|
|
def get_version(self): |
|
2299
|
|
|
"""Get the Greenbone Manager Protocol version used by the remote gvmd |
|
2300
|
|
|
|
|
2301
|
|
|
Returns: |
|
2302
|
|
|
The response. See :py:meth:`send_command` for details. |
|
2303
|
|
|
""" |
|
2304
|
|
|
return self._send_xml_command(XmlCommand('get_version')) |
|
2305
|
|
|
|
|
2306
|
|
|
def help(self, format=None, type=''): |
|
2307
|
|
|
"""Get the help text |
|
2308
|
|
|
|
|
2309
|
|
|
Arguments: |
|
2310
|
|
|
format (str, optional): One of "html", "rnc", "text" or "xml |
|
2311
|
|
|
type (str, optional): One of "brief" or "". Default "" |
|
2312
|
|
|
|
|
2313
|
|
|
Returns: |
|
2314
|
|
|
The response. See :py:meth:`send_command` for details. |
|
2315
|
|
|
""" |
|
2316
|
|
|
cmd = XmlCommand('help') |
|
2317
|
|
|
|
|
2318
|
|
|
cmd.set_attribute('type', type) |
|
2319
|
|
|
|
|
2320
|
|
|
if format: |
|
2321
|
|
|
if not format.lower() in ('html', 'rnc', 'text', 'xml'): |
|
2322
|
|
|
raise InvalidArgument( |
|
2323
|
|
|
'help format Argument must be one of html, rnc, text or ' |
|
2324
|
|
|
'xml') |
|
2325
|
|
|
|
|
2326
|
|
|
cmd.set_attribute('format', format) |
|
2327
|
|
|
|
|
2328
|
|
|
return self.send_command(cmd) |
|
2329
|
|
|
|
|
2330
|
|
|
def modify_agent(self, agent_id, name=None, comment=None): |
|
2331
|
|
|
"""Modifies an existing agent |
|
2332
|
|
|
|
|
2333
|
|
|
Arguments: |
|
2334
|
|
|
agent_id (str) UUID of the agent to be modified. |
|
2335
|
|
|
name (str, optional): Name of the new credential |
|
2336
|
|
|
comment (str, optional): Comment for the credential |
|
2337
|
|
|
""" |
|
2338
|
|
|
if not agent_id: |
|
2339
|
|
|
raise RequiredArgument('modify_agent requires agent_id argument') |
|
2340
|
|
|
|
|
2341
|
|
|
cmd = XmlCommand('modify_agent') |
|
2342
|
|
|
cmd.set_attribute('agent_id', str(agent_id)) |
|
2343
|
|
|
if name: |
|
2344
|
|
|
cmd.add_element('name', name) |
|
2345
|
|
|
if comment: |
|
2346
|
|
|
cmd.add_element('comment', comment) |
|
2347
|
|
|
|
|
2348
|
|
|
return self._send_xml_command(cmd) |
|
2349
|
|
|
|
|
2350
|
|
|
def modify_alert(self, alert_id, name=None, comment=None, |
|
|
|
|
|
|
2351
|
|
|
filter_id=None, event=None, event_data=None, |
|
2352
|
|
|
condition=None, condition_data=None, method=None, |
|
2353
|
|
|
method_data=None): |
|
2354
|
|
|
"""Modifies an existing alert. |
|
2355
|
|
|
|
|
2356
|
|
|
Arguments: |
|
2357
|
|
|
alert_id (str) UUID of the alert to be modified. |
|
2358
|
|
|
name (str, optional): Name of the Alert. |
|
2359
|
|
|
condition (str, optional): The condition that must be satisfied |
|
2360
|
|
|
for the alert to occur. |
|
2361
|
|
|
condition_data (dict, optional): Data that defines the condition |
|
2362
|
|
|
event (str, optional): The event that must happen for the alert |
|
2363
|
|
|
to occur. |
|
2364
|
|
|
event_data (dict, optional): Data that defines the event |
|
2365
|
|
|
method (str, optional): The method by which the user is alerted |
|
2366
|
|
|
method_data (dict, optional): Data that defines the method |
|
2367
|
|
|
filter_id (str, optional): Filter to apply when executing alert |
|
2368
|
|
|
comment (str, optional): Comment for the alert |
|
2369
|
|
|
""" |
|
2370
|
|
|
|
|
2371
|
|
|
if not alert_id: |
|
2372
|
|
|
raise RequiredArgument('modify_alert requires an alert_id argument') |
|
2373
|
|
|
|
|
2374
|
|
|
cmd = XmlCommand('modify_alert') |
|
2375
|
|
|
cmd.set_attribute('alert_id', str(alert_id)) |
|
2376
|
|
|
|
|
2377
|
|
|
if name: |
|
2378
|
|
|
cmd.add_element('name', name) |
|
2379
|
|
|
|
|
2380
|
|
|
if comment: |
|
2381
|
|
|
cmd.add_element('comment', comment) |
|
2382
|
|
|
|
|
2383
|
|
|
if filter_id: |
|
2384
|
|
|
cmd.add_element('filter', attrs={'id': filter_id}) |
|
2385
|
|
|
|
|
2386
|
|
|
conditions = cmd.add_element('condition', condition) |
|
2387
|
|
|
|
|
2388
|
|
|
if not condition_data is None: |
|
2389
|
|
|
for value, key in condition_data.items(): |
|
2390
|
|
|
_data = conditions.add_element('data', value) |
|
2391
|
|
|
_data.add_element('name', key) |
|
2392
|
|
|
|
|
2393
|
|
|
events = cmd.add_element('event', event) |
|
2394
|
|
|
|
|
2395
|
|
|
if not event_data is None: |
|
2396
|
|
|
for value, key in event_data.items(): |
|
2397
|
|
|
_data = events.add_element('data', value) |
|
2398
|
|
|
_data.add_element('name', key) |
|
2399
|
|
|
|
|
2400
|
|
|
methods = cmd.add_element('method', method) |
|
2401
|
|
|
|
|
2402
|
|
|
if not method_data is None: |
|
2403
|
|
|
for value, key in method_data.items(): |
|
2404
|
|
|
_data = methods.add_element('data', value) |
|
2405
|
|
|
_data.add_element('name', key) |
|
2406
|
|
|
|
|
2407
|
|
|
return self._send_xml_command(cmd) |
|
2408
|
|
|
|
|
2409
|
|
|
def modify_asset(self, asset_id, comment): |
|
2410
|
|
|
"""Modifies an existing asset. |
|
2411
|
|
|
|
|
2412
|
|
|
Arguments: |
|
2413
|
|
|
asset_id (str) UUID of the asset to be modified. |
|
2414
|
|
|
comment (str, optional): Comment for the asset. |
|
2415
|
|
|
""" |
|
2416
|
|
|
if not asset_id: |
|
2417
|
|
|
raise RequiredArgument('modify_asset requires an asset_id argument') |
|
2418
|
|
|
|
|
2419
|
|
|
cmd = XmlCommand('modify_asset') |
|
2420
|
|
|
cmd.set_attribute('asset_id', asset_id) |
|
2421
|
|
|
cmd.add_element('comment', comment) |
|
2422
|
|
|
|
|
2423
|
|
|
return self._send_xml_command(cmd) |
|
2424
|
|
|
|
|
2425
|
|
|
def modify_auth(self, group_name, auth_conf_settings): |
|
2426
|
|
|
"""Modifies an existing auth. |
|
2427
|
|
|
Arguments: |
|
2428
|
|
|
group_name (str) Name of the group to be modified. |
|
2429
|
|
|
auth_conf_settings (dict): The new auth config. |
|
2430
|
|
|
""" |
|
2431
|
|
|
if not group_name: |
|
2432
|
|
|
raise RequiredArgument('modify_auth requires a group_name argument') |
|
2433
|
|
|
if not auth_conf_settings: |
|
2434
|
|
|
raise RequiredArgument('modify_auth requires an ' |
|
2435
|
|
|
'auth_conf_settings argument') |
|
2436
|
|
|
cmd = XmlCommand('modify_auth') |
|
2437
|
|
|
_xmlgroup = cmd.add_element('group', attrs={'name': str(group_name)}) |
|
2438
|
|
|
|
|
2439
|
|
|
for key, value in auth_conf_settings.items(): |
|
2440
|
|
|
_xmlauthconf = _xmlgroup.add_element('auth_conf_setting') |
|
2441
|
|
|
_xmlauthconf.add_element('key', key) |
|
2442
|
|
|
_xmlauthconf.add_element('value', value) |
|
2443
|
|
|
|
|
2444
|
|
|
return self._send_xml_command(cmd) |
|
2445
|
|
|
|
|
2446
|
|
|
def modify_config(self, selection, config_id=None, nvt_oids=None, name=None, |
|
2447
|
|
|
value=None, family=None): |
|
2448
|
|
|
"""Modifies an existing existing scan config. |
|
2449
|
|
|
|
|
2450
|
|
|
Arguments: |
|
2451
|
|
|
selection (str): one of 'nvt_pref', nvt_selection or |
|
2452
|
|
|
family_selection' |
|
2453
|
|
|
config_id (str, optional): UUID of scan config to modify. |
|
2454
|
|
|
name (str, optional): New name for preference. |
|
2455
|
|
|
value(str, optional): New value for preference. |
|
2456
|
|
|
nvt_oids (list, optional): List of NVTs associated with preference |
|
2457
|
|
|
to modify. |
|
2458
|
|
|
family (str,optional): Name of family to modify. |
|
2459
|
|
|
""" |
|
2460
|
|
|
if selection not in ('nvt_pref', 'scan_pref', |
|
2461
|
|
|
'family_selection', 'nvt_selection'): |
|
2462
|
|
|
raise InvalidArgument('selection must be one of nvt_pref, ' |
|
2463
|
|
|
'scan_pref, family_selection or ' |
|
2464
|
|
|
'nvt_selection') |
|
2465
|
|
|
|
|
2466
|
|
|
cmd = XmlCommand('modify_config') |
|
2467
|
|
|
cmd.set_attribute('config_id', str(config_id)) |
|
2468
|
|
|
|
|
2469
|
|
|
if selection == 'nvt_pref': |
|
2470
|
|
|
_xmlpref = cmd.add_element('preference') |
|
2471
|
|
|
if not nvt_oids: |
|
2472
|
|
|
raise InvalidArgument('modify_config requires a nvt_oids ' |
|
2473
|
|
|
'argument') |
|
2474
|
|
|
_xmlpref.add_element('nvt', attrs={'oid': nvt_oids[0]}) |
|
2475
|
|
|
_xmlpref.add_element('name', name) |
|
2476
|
|
|
_xmlpref.add_element('value', value) |
|
2477
|
|
|
|
|
2478
|
|
|
elif selection == 'nvt_selection': |
|
2479
|
|
|
_xmlnvtsel = cmd.add_element('nvt_selection') |
|
2480
|
|
|
_xmlnvtsel.add_element('family', family) |
|
2481
|
|
|
|
|
2482
|
|
|
if nvt_oids: |
|
2483
|
|
|
for nvt in nvt_oids: |
|
2484
|
|
|
_xmlnvtsel.add_element('nvt', attrs={'oid': nvt}) |
|
2485
|
|
|
else: |
|
2486
|
|
|
raise InvalidArgument('modify_config requires a nvt_oid ' |
|
2487
|
|
|
'argument') |
|
2488
|
|
|
|
|
2489
|
|
|
elif selection == 'family_selection': |
|
2490
|
|
|
_xmlfamsel = cmd.add_element('family_selection') |
|
2491
|
|
|
_xmlfamsel.add_element('growing', '1') |
|
2492
|
|
|
_xmlfamily = _xmlfamsel.add_element('family') |
|
2493
|
|
|
_xmlfamily.add_element('name', family) |
|
2494
|
|
|
_xmlfamily.add_element('all', '1') |
|
2495
|
|
|
_xmlfamily.add_element('growing', '1') |
|
2496
|
|
|
|
|
2497
|
|
|
return self._send_xml_command(cmd) |
|
2498
|
|
|
|
|
2499
|
|
|
def modify_credential(self, credential_id, name=None, comment=None, |
|
|
|
|
|
|
2500
|
|
|
allow_insecure=None, certificate=None, |
|
2501
|
|
|
key_phrase=None, private_key=None, login=None, |
|
2502
|
|
|
password=None, auth_algorithm=None, community=None, |
|
2503
|
|
|
privacy_algorithm=None, privacy_password=None, |
|
2504
|
|
|
credential_type=None): |
|
2505
|
|
|
"""Modifies an existing credential. |
|
2506
|
|
|
|
|
2507
|
|
|
Arguments: |
|
2508
|
|
|
credential_id (str): UUID of the credential |
|
2509
|
|
|
name (str, optional): Name of the credential |
|
2510
|
|
|
comment (str, optional): Comment for the credential |
|
2511
|
|
|
allow_insecure (boolean, optional): Whether to allow insecure use of |
|
2512
|
|
|
the credential |
|
2513
|
|
|
certificate (str, optional): Certificate for the credential |
|
2514
|
|
|
key_phrase (str, optional): Key passphrase for the private key |
|
2515
|
|
|
private_key (str, optional): Private key to use for login |
|
2516
|
|
|
login (str, optional): Username for the credential |
|
2517
|
|
|
password (str, optional): Password for the credential |
|
2518
|
|
|
auth_algorithm (str, optional): The auth_algorithm, |
|
2519
|
|
|
either md5 or sha1. |
|
2520
|
|
|
community (str, optional): The SNMP community |
|
2521
|
|
|
privacy_algorithm (str, optional): The SNMP privacy algorithm, |
|
2522
|
|
|
either aes or des. |
|
2523
|
|
|
privacy_password (str, optional): The SNMP privacy password |
|
2524
|
|
|
credential_type (str, optional): The credential type. One of 'cc', |
|
2525
|
|
|
'snmp', 'up', 'usk' |
|
2526
|
|
|
""" |
|
2527
|
|
|
if not credential_id: |
|
2528
|
|
|
raise RequiredArgument('modify_credential requires ' |
|
2529
|
|
|
'a credential_id attribute') |
|
2530
|
|
|
|
|
2531
|
|
|
cmd = XmlCommand('modify_credential') |
|
2532
|
|
|
cmd.set_attribute('credential_id', credential_id) |
|
2533
|
|
|
|
|
2534
|
|
|
if comment: |
|
2535
|
|
|
cmd.add_element('comment', comment) |
|
2536
|
|
|
|
|
2537
|
|
|
if name: |
|
2538
|
|
|
cmd.add_element('name', name) |
|
2539
|
|
|
|
|
2540
|
|
|
if allow_insecure: |
|
2541
|
|
|
cmd.add_element('allow_insecure', allow_insecure) |
|
2542
|
|
|
|
|
2543
|
|
|
if certificate: |
|
2544
|
|
|
cmd.add_element('certificate', certificate) |
|
2545
|
|
|
|
|
2546
|
|
|
if key_phrase or private_key: |
|
2547
|
|
|
if not key_phrase or not private_key: |
|
2548
|
|
|
raise RequiredArgument('modify_credential requires ' |
|
2549
|
|
|
'a key_phrase and private_key arguments') |
|
2550
|
|
|
_xmlkey = cmd.add_element('key') |
|
2551
|
|
|
_xmlkey.add_element('phrase', key_phrase) |
|
2552
|
|
|
_xmlkey.add_element('private', private_key) |
|
2553
|
|
|
|
|
2554
|
|
|
if login: |
|
2555
|
|
|
cmd.add_element('login', login) |
|
2556
|
|
|
|
|
2557
|
|
|
if password: |
|
2558
|
|
|
cmd.add_element('password', password) |
|
2559
|
|
|
|
|
2560
|
|
|
if auth_algorithm: |
|
2561
|
|
|
if auth_algorithm not in ('md5', 'sha1'): |
|
2562
|
|
|
raise RequiredArgument('modify_credential requires ' |
|
2563
|
|
|
'auth_algorithm to be either ' |
|
2564
|
|
|
'md5 or sha1') |
|
2565
|
|
|
cmd.add_element('auth_algorithm', auth_algorithm) |
|
2566
|
|
|
|
|
2567
|
|
|
if community: |
|
2568
|
|
|
cmd.add_element('community', community) |
|
2569
|
|
|
|
|
2570
|
|
|
if privacy_algorithm: |
|
2571
|
|
|
if privacy_algorithm not in ('aes', 'des'): |
|
2572
|
|
|
raise RequiredArgument('modify_credential requires ' |
|
2573
|
|
|
'privacy_algorithm to be either' |
|
2574
|
|
|
'aes or des') |
|
2575
|
|
|
_xmlprivacy = cmd.add_element('privacy') |
|
2576
|
|
|
_xmlprivacy.add_element('algorithm', privacy_algorithm) |
|
2577
|
|
|
_xmlprivacy.add_element('password', privacy_password) |
|
2578
|
|
|
|
|
2579
|
|
|
if credential_type: |
|
2580
|
|
|
if credential_type not in ('cc', 'snmp', 'up', 'usk'): |
|
2581
|
|
|
raise RequiredArgument('modify_credential requires type ' |
|
2582
|
|
|
'to be either cc, snmp, up or usk') |
|
2583
|
|
|
cmd.add_element('type', credential_type) |
|
2584
|
|
|
|
|
2585
|
|
|
return self._send_xml_command(cmd) |
|
2586
|
|
|
|
|
2587
|
|
|
def modify_filter(self, filter_id, comment=None, name=None, term=None, |
|
2588
|
|
|
filter_type=None): |
|
2589
|
|
|
"""Modifies an existing filter. |
|
2590
|
|
|
|
|
2591
|
|
|
Arguments: |
|
2592
|
|
|
filter_id (str): UUID of the filter to be modified |
|
2593
|
|
|
comment (str, optional): Comment on filter. |
|
2594
|
|
|
name (str, optional): Name of filter. |
|
2595
|
|
|
term (str, optional): Filter term. |
|
2596
|
|
|
filter_type (str, optional): Resource type filter applies to. |
|
2597
|
|
|
""" |
|
2598
|
|
|
if not filter_id: |
|
2599
|
|
|
raise RequiredArgument('modify_filter requires a filter_id ' |
|
2600
|
|
|
'attribute') |
|
2601
|
|
|
|
|
2602
|
|
|
cmd = XmlCommand('modify_filter') |
|
2603
|
|
|
cmd.set_attribute('filter_id', filter_id) |
|
2604
|
|
|
|
|
2605
|
|
|
if comment: |
|
2606
|
|
|
cmd.add_element('comment', comment) |
|
2607
|
|
|
|
|
2608
|
|
|
if name: |
|
2609
|
|
|
cmd.add_element('name', name) |
|
2610
|
|
|
|
|
2611
|
|
|
if term: |
|
2612
|
|
|
cmd.add_element('term', term) |
|
2613
|
|
|
|
|
2614
|
|
|
if filter_type: |
|
2615
|
|
|
filter_type = filter_type.lower() |
|
2616
|
|
|
if filter_type not in FILTER_TYPES: |
|
2617
|
|
|
raise InvalidArgument( |
|
2618
|
|
|
'modify_filter requires type to be one of {0} but ' |
|
2619
|
|
|
'was {1}'.format(', '.join(FILTER_TYPES), filter_type)) |
|
2620
|
|
|
cmd.add_element('type', filter_type) |
|
2621
|
|
|
|
|
2622
|
|
|
return self._send_xml_command(cmd) |
|
2623
|
|
|
|
|
2624
|
|
|
def modify_group(self, group_id, comment=None, name=None, |
|
2625
|
|
|
users=None): |
|
2626
|
|
|
"""Modifies an existing group. |
|
2627
|
|
|
|
|
2628
|
|
|
Arguments: |
|
2629
|
|
|
group_id (str): UUID of group to modify. |
|
2630
|
|
|
comment (str, optional): Comment on group. |
|
2631
|
|
|
name (str, optional): Name of group. |
|
2632
|
|
|
users (list, optional): List of user names to be in the group |
|
2633
|
|
|
""" |
|
2634
|
|
|
if not group_id: |
|
2635
|
|
|
raise RequiredArgument('modify_group requires a group_id argument') |
|
2636
|
|
|
|
|
2637
|
|
|
cmd = XmlCommand('modify_group') |
|
2638
|
|
|
cmd.set_attribute('group_id', group_id) |
|
2639
|
|
|
|
|
2640
|
|
|
if comment: |
|
2641
|
|
|
cmd.add_element('comment', comment) |
|
2642
|
|
|
|
|
2643
|
|
|
if name: |
|
2644
|
|
|
cmd.add_element('name', name) |
|
2645
|
|
|
|
|
2646
|
|
|
if users: |
|
2647
|
|
|
cmd.add_element('users', ','.join(users)) |
|
2648
|
|
|
|
|
2649
|
|
|
return self._send_xml_command(cmd) |
|
2650
|
|
|
|
|
2651
|
|
|
def modify_note(self, note_id, text, seconds_active=None, hosts=None, |
|
2652
|
|
|
port=None, result_id=None, severity=None, task_id=None, |
|
2653
|
|
|
threat=None): |
|
2654
|
|
|
"""Modifies an existing note. |
|
2655
|
|
|
|
|
2656
|
|
|
Arguments: |
|
2657
|
|
|
note_id (str): UUID of note to modify. |
|
2658
|
|
|
text (str): The text of the note. |
|
2659
|
|
|
seconds_active (int, optional): Seconds note will be active. |
|
2660
|
|
|
-1 on always, 0 off. |
|
2661
|
|
|
hosts (list, optional): A list of hosts addresses |
|
2662
|
|
|
port (str, optional): Port to which note applies. |
|
2663
|
|
|
result_id (str, optional): Result to which note applies. |
|
2664
|
|
|
severity (str, optional): Severity to which note applies. |
|
2665
|
|
|
task_id (str, optional): Task to which note applies. |
|
2666
|
|
|
threat (str, optional): Threat level to which note applies. |
|
2667
|
|
|
""" |
|
2668
|
|
|
if not note_id: |
|
2669
|
|
|
raise RequiredArgument('modify_note requires a note_id attribute') |
|
2670
|
|
|
if not text: |
|
2671
|
|
|
raise RequiredArgument('modify_note requires a text element') |
|
2672
|
|
|
|
|
2673
|
|
|
cmd = XmlCommand('modify_note') |
|
2674
|
|
|
cmd.set_attribute('note_id', note_id) |
|
2675
|
|
|
cmd.add_element('text', text) |
|
2676
|
|
|
|
|
2677
|
|
|
if not seconds_active is None: |
|
2678
|
|
|
cmd.add_element('active', str(seconds_active)) |
|
2679
|
|
|
|
|
2680
|
|
|
if hosts: |
|
2681
|
|
|
cmd.add_element('hosts', ', '.join(hosts)) |
|
2682
|
|
|
|
|
2683
|
|
|
if port: |
|
2684
|
|
|
cmd.add_element('port', port) |
|
2685
|
|
|
|
|
2686
|
|
|
if result_id: |
|
2687
|
|
|
cmd.add_element('result', attrs={'id': result_id}) |
|
2688
|
|
|
|
|
2689
|
|
|
if severity: |
|
2690
|
|
|
cmd.add_element('severity', severity) |
|
2691
|
|
|
|
|
2692
|
|
|
if task_id: |
|
2693
|
|
|
cmd.add_element('task', attrs={'id': task_id}) |
|
2694
|
|
|
|
|
2695
|
|
|
if threat: |
|
2696
|
|
|
cmd.add_element('threat', threat) |
|
2697
|
|
|
|
|
2698
|
|
|
return self._send_xml_command(cmd) |
|
2699
|
|
|
|
|
2700
|
|
View Code Duplication |
def modify_override(self, override_id, text, seconds_active=None, |
|
|
|
|
|
|
2701
|
|
|
hosts=None, port=None, result_id=None, severity=None, |
|
2702
|
|
|
new_severity=None, task_id=None, threat=None, |
|
2703
|
|
|
new_threat=None): |
|
2704
|
|
|
"""Modifies an existing override. |
|
2705
|
|
|
|
|
2706
|
|
|
Arguments: |
|
2707
|
|
|
override_id (str): UUID of override to modify. |
|
2708
|
|
|
text (str): The text of the override. |
|
2709
|
|
|
seconds_active (int, optional): Seconds override will be active. |
|
2710
|
|
|
-1 on always, 0 off. |
|
2711
|
|
|
hosts (list, optional): A list of host addresses |
|
2712
|
|
|
port (str, optional): Port to which override applies. |
|
2713
|
|
|
result_id (str, optional): Result to which override applies. |
|
2714
|
|
|
severity (str, optional): Severity to which override applies. |
|
2715
|
|
|
new_severity (str, optional): New severity score for result. |
|
2716
|
|
|
task_id (str, optional): Task to which override applies. |
|
2717
|
|
|
threat (str, optional): Threat level to which override applies. |
|
2718
|
|
|
new_threat (str, optional): New threat level for results. |
|
2719
|
|
|
""" |
|
2720
|
|
|
if not override_id: |
|
2721
|
|
|
raise RequiredArgument('modify_override requires a override_id ' |
|
2722
|
|
|
'argument') |
|
2723
|
|
|
if not text: |
|
2724
|
|
|
raise RequiredArgument('modify_override requires a text argument') |
|
2725
|
|
|
|
|
2726
|
|
|
cmd = XmlCommand('modify_override') |
|
2727
|
|
|
cmd.set_attribute('override_id', override_id) |
|
2728
|
|
|
cmd.add_element('text', text) |
|
2729
|
|
|
|
|
2730
|
|
|
if not seconds_active is None: |
|
2731
|
|
|
cmd.add_element('active', str(seconds_active)) |
|
2732
|
|
|
|
|
2733
|
|
|
if hosts: |
|
2734
|
|
|
cmd.add_element('hosts', ', '.join(hosts)) |
|
2735
|
|
|
|
|
2736
|
|
|
if port: |
|
2737
|
|
|
cmd.add_element('port', port) |
|
2738
|
|
|
|
|
2739
|
|
|
if result_id: |
|
2740
|
|
|
cmd.add_element('result', attrs={'id': result_id}) |
|
2741
|
|
|
|
|
2742
|
|
|
if severity: |
|
2743
|
|
|
cmd.add_element('severity', severity) |
|
2744
|
|
|
|
|
2745
|
|
|
if new_severity: |
|
2746
|
|
|
cmd.add_element('new_severity', new_severity) |
|
2747
|
|
|
|
|
2748
|
|
|
if task_id: |
|
2749
|
|
|
cmd.add_element('task', attrs={'id': task_id}) |
|
2750
|
|
|
|
|
2751
|
|
|
if threat: |
|
2752
|
|
|
cmd.add_element('threat', threat) |
|
2753
|
|
|
|
|
2754
|
|
|
if new_threat: |
|
2755
|
|
|
cmd.add_element('new_threat', new_threat) |
|
2756
|
|
|
|
|
2757
|
|
|
return self._send_xml_command(cmd) |
|
2758
|
|
|
|
|
2759
|
|
View Code Duplication |
def modify_permission(self, permission_id, comment=None, name=None, |
|
|
|
|
|
|
2760
|
|
|
resource_id=None, resource_type=None, |
|
2761
|
|
|
subject_id=None, subject_type=None): |
|
2762
|
|
|
"""Modifies an existing permission. |
|
2763
|
|
|
|
|
2764
|
|
|
Arguments: |
|
2765
|
|
|
permission_id (str): UUID of permission to be modified. |
|
2766
|
|
|
comment (str, optional): The comment on the permission. |
|
2767
|
|
|
name (str, optional): Permission name, currently the name of |
|
2768
|
|
|
a command. |
|
2769
|
|
|
subject_id (str, optional): UUID of subject to whom the permission |
|
2770
|
|
|
is granted |
|
2771
|
|
|
subject_type (str, optional): Type of the subject user, group or |
|
2772
|
|
|
role |
|
2773
|
|
|
resource_id (str, optional): UUID of entity to which the permission |
|
2774
|
|
|
applies |
|
2775
|
|
|
resource_type (str, optional): Type of the resource. For Super |
|
2776
|
|
|
permissions user, group or role |
|
2777
|
|
|
""" |
|
2778
|
|
|
if not permission_id: |
|
2779
|
|
|
raise RequiredArgument('modify_permission requires ' |
|
2780
|
|
|
'a permission_id element') |
|
2781
|
|
|
|
|
2782
|
|
|
cmd = XmlCommand('modify_permission') |
|
2783
|
|
|
cmd.set_attribute('permission_id', permission_id) |
|
2784
|
|
|
|
|
2785
|
|
|
if comment: |
|
2786
|
|
|
cmd.add_element('comment', comment) |
|
2787
|
|
|
|
|
2788
|
|
|
if name: |
|
2789
|
|
|
cmd.add_element('name', name) |
|
2790
|
|
|
|
|
2791
|
|
|
if resource_id and resource_type: |
|
2792
|
|
|
_xmlresource = cmd.add_element('resource', |
|
2793
|
|
|
attrs={'id': resource_id}) |
|
2794
|
|
|
_xmlresource.add_element('type', resource_type) |
|
2795
|
|
|
|
|
2796
|
|
|
if subject_id and subject_type: |
|
2797
|
|
|
_xmlsubject = cmd.add_element('subject', |
|
2798
|
|
|
attrs={'id': subject_id}) |
|
|
|
|
|
|
2799
|
|
|
_xmlsubject.add_element('type', subject_type) |
|
2800
|
|
|
|
|
2801
|
|
|
return self._send_xml_command(cmd) |
|
2802
|
|
|
|
|
2803
|
|
|
def modify_port_list(self, port_list_id, comment=None, name=None, ): |
|
2804
|
|
|
"""Modifies an existing port list. |
|
2805
|
|
|
|
|
2806
|
|
|
Arguments: |
|
2807
|
|
|
port_list_id (str): UUID of port list to modify. |
|
2808
|
|
|
name (str, optional): Name of port list. |
|
2809
|
|
|
comment (str, optional): Comment on port list. |
|
2810
|
|
|
""" |
|
2811
|
|
|
if not port_list_id: |
|
2812
|
|
|
raise RequiredArgument('modify_port_list requires ' |
|
2813
|
|
|
'a port_list_id attribute') |
|
2814
|
|
|
cmd = XmlCommand('modify_port_list') |
|
2815
|
|
|
cmd.set_attribute('port_list_id', port_list_id) |
|
2816
|
|
|
|
|
2817
|
|
|
if comment: |
|
2818
|
|
|
cmd.add_element('comment', comment) |
|
2819
|
|
|
|
|
2820
|
|
|
if name: |
|
2821
|
|
|
cmd.add_element('name', name) |
|
2822
|
|
|
|
|
2823
|
|
|
return self._send_xml_command(cmd) |
|
2824
|
|
|
|
|
2825
|
|
|
def modify_report(self, report_id, comment): |
|
2826
|
|
|
"""Modifies an existing report. |
|
2827
|
|
|
|
|
2828
|
|
|
Arguments: |
|
2829
|
|
|
report_id (str): UUID of report to modify. |
|
2830
|
|
|
comment (str): The comment on the report. |
|
2831
|
|
|
""" |
|
2832
|
|
|
if not report_id: |
|
2833
|
|
|
raise RequiredArgument('modify_report requires ' |
|
2834
|
|
|
'a report_id attribute') |
|
2835
|
|
|
if not comment: |
|
2836
|
|
|
raise RequiredArgument('modify_report requires ' |
|
2837
|
|
|
'a comment attribute') |
|
2838
|
|
|
cmd = XmlCommand('modify_report') |
|
2839
|
|
|
cmd.set_attribute('report_id', report_id) |
|
2840
|
|
|
cmd.add_element('comment', comment) |
|
2841
|
|
|
|
|
2842
|
|
|
return self._send_xml_command(cmd) |
|
2843
|
|
|
|
|
2844
|
|
|
def modify_report_format(self, report_format_id, active=None, name=None, |
|
2845
|
|
|
summary=None, param_name=None, param_value=None): |
|
2846
|
|
|
"""Modifies an existing report format on gvmd. |
|
2847
|
|
|
|
|
2848
|
|
|
Arguments: |
|
2849
|
|
|
report_format_id (str) UUID of report format to modify. |
|
2850
|
|
|
active (boolean, optional): Whether the report format is active. |
|
2851
|
|
|
name (str, optional): The name of the report format. |
|
2852
|
|
|
summary (str, optional): A summary of the report format. |
|
2853
|
|
|
param_name (str, optional): The name of the param. |
|
2854
|
|
|
param_value (str, optional): The value of the param. |
|
2855
|
|
|
""" |
|
2856
|
|
|
if not report_format_id: |
|
2857
|
|
|
raise RequiredArgument('modify_report requires ' |
|
2858
|
|
|
'a report_format_id attribute') |
|
2859
|
|
|
cmd = XmlCommand('modify_report_format') |
|
2860
|
|
|
cmd.set_attribute('report_format_id', report_format_id) |
|
2861
|
|
|
|
|
2862
|
|
|
if not active is None: |
|
2863
|
|
|
cmd.add_element('active', '1' if active else '0') |
|
2864
|
|
|
|
|
2865
|
|
|
if name: |
|
2866
|
|
|
cmd.add_element('name', name) |
|
2867
|
|
|
|
|
2868
|
|
|
if summary: |
|
2869
|
|
|
cmd.add_element('summary', summary) |
|
2870
|
|
|
|
|
2871
|
|
|
if param_name and param_value: |
|
2872
|
|
|
_xmlparam = cmd.add_element('param') |
|
2873
|
|
|
_xmlparam.add_element('name', param_name) |
|
2874
|
|
|
_xmlparam.add_element('value', param_value) |
|
2875
|
|
|
|
|
2876
|
|
|
return self._send_xml_command(cmd) |
|
2877
|
|
|
|
|
2878
|
|
|
def modify_role(self, role_id, comment=None, name=None, users=None): |
|
2879
|
|
|
"""Modifies an existing role. |
|
2880
|
|
|
|
|
2881
|
|
|
Arguments: |
|
2882
|
|
|
role_id (str): UUID of role to modify. |
|
2883
|
|
|
comment (str, optional): Name of role. |
|
2884
|
|
|
name (str, optional): Comment on role. |
|
2885
|
|
|
users (list, optional): List of user names. |
|
2886
|
|
|
""" |
|
2887
|
|
|
if not role_id: |
|
2888
|
|
|
raise RequiredArgument('modify_role requires a role_id argument') |
|
2889
|
|
|
|
|
2890
|
|
|
cmd = XmlCommand('modify_role') |
|
2891
|
|
|
cmd.set_attribute('role_id', role_id) |
|
2892
|
|
|
|
|
2893
|
|
|
if comment: |
|
2894
|
|
|
cmd.add_element('comment', comment) |
|
2895
|
|
|
|
|
2896
|
|
|
if name: |
|
2897
|
|
|
cmd.add_element('name', name) |
|
2898
|
|
|
|
|
2899
|
|
|
if users: |
|
2900
|
|
|
cmd.add_element('users', ",".join(users)) |
|
2901
|
|
|
|
|
2902
|
|
|
return self._send_xml_command(cmd) |
|
2903
|
|
|
|
|
2904
|
|
|
def modify_scanner(self, scanner_id, host, port, scanner_type, **kwargs): |
|
2905
|
|
|
cmd = self._generator.modify_scanner_command(scanner_id, host, port, |
|
2906
|
|
|
scanner_type, kwargs) |
|
2907
|
|
|
return self.send_command(cmd) |
|
2908
|
|
|
|
|
2909
|
|
|
def modify_schedule(self, schedule_id, **kwargs): |
|
2910
|
|
|
cmd = self._generator.modify_schedule_command(schedule_id, kwargs) |
|
2911
|
|
|
return self.send_command(cmd) |
|
2912
|
|
|
|
|
2913
|
|
|
def modify_setting(self, setting_id, name, value): |
|
2914
|
|
|
cmd = self._generator.modify_setting_command(setting_id, name, value) |
|
2915
|
|
|
return self.send_command(cmd) |
|
2916
|
|
|
|
|
2917
|
|
|
def modify_tag(self, tag_id, **kwargs): |
|
2918
|
|
|
cmd = self._generator.modify_tag_command(tag_id, kwargs) |
|
2919
|
|
|
return self.send_command(cmd) |
|
2920
|
|
|
|
|
2921
|
|
|
def modify_target(self, target_id, **kwargs): |
|
2922
|
|
|
cmd = self._generator.modify_target_command(target_id, kwargs) |
|
2923
|
|
|
return self.send_command(cmd) |
|
2924
|
|
|
|
|
2925
|
|
|
def modify_task(self, task_id, **kwargs): |
|
2926
|
|
|
cmd = self._generator.modify_task_command(task_id, kwargs) |
|
2927
|
|
|
return self.send_command(cmd) |
|
2928
|
|
|
|
|
2929
|
|
|
def modify_user(self, **kwargs): |
|
2930
|
|
|
cmd = self._generator.modify_user_command(kwargs) |
|
2931
|
|
|
return self.send_command(cmd) |
|
2932
|
|
|
|
|
2933
|
|
|
def move_task(self, task_id, slave_id): |
|
2934
|
|
|
cmd = self._generator.move_task_command(task_id, slave_id) |
|
2935
|
|
|
return self.send_command(cmd) |
|
2936
|
|
|
|
|
2937
|
|
|
def restore(self, entity_id): |
|
2938
|
|
|
cmd = self._generator.restore_command(entity_id) |
|
2939
|
|
|
return self.send_command(cmd) |
|
2940
|
|
|
|
|
2941
|
|
|
def resume_task(self, task_id): |
|
2942
|
|
|
cmd = self._generator.resume_task_command(task_id) |
|
2943
|
|
|
return self.send_command(cmd) |
|
2944
|
|
|
|
|
2945
|
|
|
def start_task(self, task_id): |
|
2946
|
|
|
cmd = self._generator.start_task_command(task_id) |
|
2947
|
|
|
return self.send_command(cmd) |
|
2948
|
|
|
|
|
2949
|
|
|
def stop_task(self, task_id): |
|
2950
|
|
|
cmd = self._generator.stop_task_command(task_id) |
|
2951
|
|
|
return self.send_command(cmd) |
|
2952
|
|
|
|
|
2953
|
|
|
def sync_cert(self): |
|
2954
|
|
|
"""Request a synchronization with the CERT feed service |
|
2955
|
|
|
|
|
2956
|
|
|
Returns: |
|
2957
|
|
|
The response. See :py:meth:`send_command` for details. |
|
2958
|
|
|
""" |
|
2959
|
|
|
return self._send_xml_command(XmlCommand('sync_cert')) |
|
2960
|
|
|
|
|
2961
|
|
|
def sync_config(self): |
|
2962
|
|
|
"""Request an OSP config synchronization with scanner |
|
2963
|
|
|
|
|
2964
|
|
|
Returns: |
|
2965
|
|
|
The response. See :py:meth:`send_command` for details. |
|
2966
|
|
|
""" |
|
2967
|
|
|
return self._send_xml_command(XmlCommand('sync_config')) |
|
2968
|
|
|
|
|
2969
|
|
|
def sync_feed(self): |
|
2970
|
|
|
"""Request a synchronization with the NVT feed service |
|
2971
|
|
|
|
|
2972
|
|
|
Returns: |
|
2973
|
|
|
The response. See :py:meth:`send_command` for details. |
|
2974
|
|
|
""" |
|
2975
|
|
|
return self._send_xml_command(XmlCommand('sync_feed')) |
|
2976
|
|
|
|
|
2977
|
|
|
def sync_scap(self): |
|
2978
|
|
|
"""Request a synchronization with the SCAP feed service |
|
2979
|
|
|
|
|
2980
|
|
|
Returns: |
|
2981
|
|
|
The response. See :py:meth:`send_command` for details. |
|
2982
|
|
|
""" |
|
2983
|
|
|
return self._send_xml_command(XmlCommand('sync_scap')) |
|
2984
|
|
|
|
|
2985
|
|
|
def test_alert(self, alert_id): |
|
2986
|
|
|
cmd = self._generator.test_alert_command(alert_id) |
|
2987
|
|
|
return self.send_command(cmd) |
|
2988
|
|
|
|
|
2989
|
|
|
def verify_agent(self, agent_id): |
|
2990
|
|
|
cmd = self._generator.verify_agent_command(agent_id) |
|
2991
|
|
|
return self.send_command(cmd) |
|
2992
|
|
|
|
|
2993
|
|
|
def verify_report_format(self, report_format_id): |
|
2994
|
|
|
cmd = self._generator.verify_report_format_command(report_format_id) |
|
2995
|
|
|
return self.send_command(cmd) |
|
2996
|
|
|
|
|
2997
|
|
|
def verify_scanner(self, scanner_id): |
|
2998
|
|
|
cmd = self._generator.verify_scanner_command(scanner_id) |
|
2999
|
|
|
return self.send_command(cmd) |
|
3000
|
|
|
|