|
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
|
|
|
Module for communication with gvmd in Greenbone Management Protocol version 7 |
|
20
|
|
|
""" |
|
21
|
|
|
|
|
22
|
|
|
import logging |
|
23
|
|
|
|
|
24
|
|
|
from lxml import etree |
|
25
|
|
|
|
|
26
|
|
|
from gmp.errors import GmpError |
|
27
|
|
|
from gmp.xml import _GmpCommandFactory as GmpCommandFactory |
|
28
|
|
|
|
|
29
|
|
|
logger = logging.getLogger(__name__) |
|
|
|
|
|
|
30
|
|
|
|
|
31
|
|
|
PROTOCOL_VERSION = (7,) |
|
32
|
|
|
|
|
33
|
|
|
def arguments_to_string(kwargs): |
|
34
|
|
|
"""Convert arguments |
|
35
|
|
|
|
|
36
|
|
|
Converts dictionaries into gmp arguments string |
|
37
|
|
|
|
|
38
|
|
|
Arguments: |
|
39
|
|
|
kwargs {dict} -- Arguments |
|
40
|
|
|
|
|
41
|
|
|
Returns: |
|
42
|
|
|
string -- Arguments as string |
|
43
|
|
|
""" |
|
44
|
|
|
msg = '' |
|
45
|
|
|
for key, value in kwargs.items(): |
|
46
|
|
|
msg += str(key) + '=\'' + str(value) + '\' ' |
|
47
|
|
|
|
|
48
|
|
|
return msg |
|
49
|
|
|
|
|
50
|
|
|
def _check_command_status(xml): |
|
51
|
|
|
"""Check gmp response |
|
52
|
|
|
|
|
53
|
|
|
Look into the gmp response and check for the status in the root element |
|
54
|
|
|
|
|
55
|
|
|
Arguments: |
|
56
|
|
|
xml {string} -- XML-Source |
|
57
|
|
|
|
|
58
|
|
|
Returns: |
|
59
|
|
|
bool -- True if valid, otherwise False |
|
60
|
|
|
""" |
|
61
|
|
|
|
|
62
|
|
|
if xml is 0 or xml is None: |
|
63
|
|
|
logger.error('XML Command is empty') |
|
64
|
|
|
return False |
|
65
|
|
|
|
|
66
|
|
|
try: |
|
67
|
|
|
parser = etree.XMLParser(encoding='utf-8', recover=True) |
|
|
|
|
|
|
68
|
|
|
|
|
69
|
|
|
root = etree.XML(xml, parser=parser) |
|
|
|
|
|
|
70
|
|
|
status = root.attrib['status'] |
|
71
|
|
|
return status is not None and status[0] == '2' |
|
72
|
|
|
|
|
73
|
|
|
except etree.Error as e: |
|
|
|
|
|
|
74
|
|
|
logger.error('etree.XML(xml): %s', e) |
|
75
|
|
|
return False |
|
76
|
|
|
|
|
77
|
|
|
|
|
78
|
|
|
class Gmp: |
|
|
|
|
|
|
79
|
|
|
"""Python interface for Greenbone Management Protocol |
|
80
|
|
|
|
|
81
|
|
|
This class implements the `Greenbone Management Protocol version 7`_ |
|
82
|
|
|
|
|
83
|
|
|
Attributes: |
|
84
|
|
|
connection (:class:`gmp.connection.GmpConnection`): Connection to use to |
|
85
|
|
|
talk with the gvmd daemon. See :mod:`gmp.connection` for possible |
|
86
|
|
|
connection types. |
|
87
|
|
|
transform (`callable`_, optional): Optional transform callable to |
|
88
|
|
|
convert response data. After each request the callable gets passed |
|
89
|
|
|
the plain response data which can be used to check the data and/or |
|
90
|
|
|
conversion into different representaitions like a xml dom. |
|
91
|
|
|
|
|
92
|
|
|
See :mod:`gmp.transform` for existing transforms. |
|
93
|
|
|
|
|
94
|
|
|
.. _Greenbone Management Protocol version 7: |
|
95
|
|
|
https://docs.greenbone.net/API/GMP/gmp-7.0.html |
|
96
|
|
|
.. _callable: |
|
97
|
|
|
https://docs.python.org/3.6/library/functions.html#callable |
|
98
|
|
|
""" |
|
99
|
|
|
|
|
100
|
|
|
def __init__(self, connection, transform=None): |
|
101
|
|
|
# GMP Message Creator |
|
102
|
|
|
self._generator = GmpCommandFactory() |
|
103
|
|
|
self._connection = connection |
|
104
|
|
|
|
|
105
|
|
|
self._connected = False |
|
106
|
|
|
|
|
107
|
|
|
# Is authenticated on gvm |
|
108
|
|
|
self._authenticated = False |
|
109
|
|
|
|
|
110
|
|
|
self._transform_callable = transform |
|
111
|
|
|
|
|
112
|
|
|
@staticmethod |
|
113
|
|
|
def get_protocol_version(): |
|
114
|
|
|
"""Allow to determine the Greenbone Management Protocol version. |
|
115
|
|
|
|
|
116
|
|
|
Returns: |
|
117
|
|
|
str: Implemented version of the Greenbone Management Protocol |
|
118
|
|
|
""" |
|
119
|
|
|
return '.'.join(str(x) for x in PROTOCOL_VERSION) |
|
120
|
|
|
|
|
121
|
|
|
def _read(self): |
|
122
|
|
|
"""Read a command response from gvmd |
|
123
|
|
|
|
|
124
|
|
|
Returns: |
|
125
|
|
|
str: Response from server. |
|
126
|
|
|
""" |
|
127
|
|
|
response = self._connection.read() |
|
128
|
|
|
|
|
129
|
|
|
logger.debug('read() %i Bytes response: %s', len(response), response) |
|
130
|
|
|
|
|
131
|
|
|
if response is None or len(str(response)) == 0: |
|
|
|
|
|
|
132
|
|
|
raise GmpError('Connection was closed by remote server') |
|
133
|
|
|
|
|
134
|
|
|
return response |
|
135
|
|
|
|
|
136
|
|
|
def _send(self, data): |
|
137
|
|
|
"""Send a command to gvmd |
|
138
|
|
|
|
|
139
|
|
|
Args: |
|
140
|
|
|
data (str): Data to be send over the connection to gvmd |
|
141
|
|
|
""" |
|
142
|
|
|
self._connect() |
|
143
|
|
|
self._connection.send(data) |
|
144
|
|
|
|
|
145
|
|
|
def _connect(self): |
|
146
|
|
|
if not self.is_connected(): |
|
147
|
|
|
self._connection.connect() |
|
148
|
|
|
self._connected = True |
|
149
|
|
|
|
|
150
|
|
|
def _transform(self, data): |
|
151
|
|
|
transform = self._transform_callable |
|
152
|
|
|
if transform is None: |
|
153
|
|
|
return data |
|
154
|
|
|
return transform(data) |
|
155
|
|
|
|
|
156
|
|
|
def is_connected(self): |
|
157
|
|
|
"""Status of the current connection to gvmd |
|
158
|
|
|
|
|
159
|
|
|
Returns: |
|
160
|
|
|
bool: True if a connection to gvmd has been established. |
|
161
|
|
|
""" |
|
162
|
|
|
return self._connected |
|
163
|
|
|
|
|
164
|
|
|
def is_authenticated(self): |
|
165
|
|
|
"""Checks if the user is authenticated |
|
166
|
|
|
|
|
167
|
|
|
If the user is authenticated privilged GMP commands like get_tasks |
|
168
|
|
|
may be send to gvmd. |
|
169
|
|
|
|
|
170
|
|
|
Returns: |
|
171
|
|
|
bool: True if an authenticated connection to gvmd has been |
|
172
|
|
|
established. |
|
173
|
|
|
""" |
|
174
|
|
|
return self._authenticated |
|
175
|
|
|
|
|
176
|
|
|
def disconnect(self): |
|
177
|
|
|
"""Disconnect the connection to gvmd. |
|
178
|
|
|
|
|
179
|
|
|
Ends and closes the connection to gvmd. |
|
180
|
|
|
""" |
|
181
|
|
|
if self.is_connected(): |
|
182
|
|
|
self._connection.disconnect() |
|
183
|
|
|
self._connected = False |
|
184
|
|
|
|
|
185
|
|
|
def send_command(self, cmd): |
|
186
|
|
|
"""Send a GMP command to gsad |
|
187
|
|
|
|
|
188
|
|
|
If the class isn't connected to gvmd yet the connection will be |
|
189
|
|
|
established automatically. |
|
190
|
|
|
|
|
191
|
|
|
Arguments: |
|
192
|
|
|
cmd (str): GMP command as string to be send over the connection to |
|
193
|
|
|
gvmd. |
|
194
|
|
|
|
|
195
|
|
|
Returns: |
|
196
|
|
|
any: The actual returned type depends on the set transform. |
|
197
|
|
|
|
|
198
|
|
|
Per default - if no transform is set explicitly - the response is |
|
199
|
|
|
returned as string. |
|
200
|
|
|
""" |
|
201
|
|
|
self._send(cmd) |
|
202
|
|
|
response = self._read() |
|
203
|
|
|
return self._transform(response) |
|
204
|
|
|
|
|
205
|
|
|
def authenticate(self, username, password): |
|
206
|
|
|
"""Authenticate to gvmd. |
|
207
|
|
|
|
|
208
|
|
|
The generated authenticate command will be send to server. |
|
209
|
|
|
Afterwards the response is read, tranformed and returned. |
|
210
|
|
|
|
|
211
|
|
|
Arguments: |
|
212
|
|
|
username (str): Username |
|
213
|
|
|
password (str): Password |
|
214
|
|
|
|
|
215
|
|
|
Returns: |
|
216
|
|
|
any, str by default: Transformed response from server. |
|
217
|
|
|
""" |
|
218
|
|
|
cmd = self._generator.create_authenticate_command( |
|
219
|
|
|
username=username, password=password) |
|
220
|
|
|
|
|
221
|
|
|
self._send(cmd) |
|
222
|
|
|
response = self._read() |
|
223
|
|
|
|
|
224
|
|
|
if _check_command_status(response): |
|
225
|
|
|
self._authenticated = True |
|
226
|
|
|
|
|
227
|
|
|
return self._transform(response) |
|
228
|
|
|
|
|
229
|
|
|
def create_agent(self, installer, signature, name, comment='', copy='', |
|
|
|
|
|
|
230
|
|
|
howto_install='', howto_use=''): |
|
231
|
|
|
cmd = self._generator.create_agent_command( |
|
232
|
|
|
installer, signature, name, comment, copy, howto_install, |
|
233
|
|
|
howto_use) |
|
234
|
|
|
return self.send_command(cmd) |
|
235
|
|
|
|
|
236
|
|
|
def create_alert(self, name, condition, event, method, filter_id='', |
|
|
|
|
|
|
237
|
|
|
copy='', comment=''): |
|
238
|
|
|
cmd = self._generator.create_alert_command(name, condition, event, |
|
239
|
|
|
method, filter_id, copy, |
|
240
|
|
|
comment) |
|
241
|
|
|
return self.send_command(cmd) |
|
242
|
|
|
|
|
243
|
|
|
def create_asset(self, name, asset_type, comment=''): |
|
|
|
|
|
|
244
|
|
|
# TODO: Add the missing second method. Also the docs are not complete! |
|
|
|
|
|
|
245
|
|
|
cmd = self._generator.create_asset_command(name, asset_type, comment) |
|
246
|
|
|
return self.send_command(cmd) |
|
247
|
|
|
|
|
248
|
|
|
def create_config(self, copy_id, name): |
|
|
|
|
|
|
249
|
|
|
cmd = self._generator.create_config_command(copy_id, name) |
|
250
|
|
|
return self.send_command(cmd) |
|
251
|
|
|
|
|
252
|
|
|
def create_credential(self, name, **kwargs): |
|
|
|
|
|
|
253
|
|
|
cmd = self._generator.create_credential_command(name, kwargs) |
|
254
|
|
|
return self.send_command(cmd) |
|
255
|
|
|
|
|
256
|
|
|
def create_filter(self, name, make_unique, **kwargs): |
|
|
|
|
|
|
257
|
|
|
cmd = self._generator.create_filter_command(name, make_unique, |
|
258
|
|
|
kwargs) |
|
259
|
|
|
return self.send_command(cmd) |
|
260
|
|
|
|
|
261
|
|
|
def create_group(self, name, **kwargs): |
|
|
|
|
|
|
262
|
|
|
cmd = self._generator.create_group_command(name, kwargs) |
|
263
|
|
|
return self.send_command(cmd) |
|
264
|
|
|
|
|
265
|
|
|
# TODO: Create notes with comment returns bogus element. Research |
|
|
|
|
|
|
266
|
|
|
def create_note(self, text, nvt_oid, **kwargs): |
|
|
|
|
|
|
267
|
|
|
cmd = self._generator.create_note_command(text, nvt_oid, kwargs) |
|
268
|
|
|
return self.send_command(cmd) |
|
269
|
|
|
|
|
270
|
|
|
def create_override(self, text, nvt_oid, **kwargs): |
|
|
|
|
|
|
271
|
|
|
cmd = self._generator.create_override_command(text, nvt_oid, kwargs) |
|
272
|
|
|
return self.send_command(cmd) |
|
273
|
|
|
|
|
274
|
|
|
def create_permission(self, name, subject_id, permission_type, **kwargs): |
|
|
|
|
|
|
275
|
|
|
cmd = self._generator.create_permission_command( |
|
276
|
|
|
name, subject_id, permission_type, kwargs) |
|
277
|
|
|
return self.send_command(cmd) |
|
278
|
|
|
|
|
279
|
|
|
def create_port_list(self, name, port_range, **kwargs): |
|
|
|
|
|
|
280
|
|
|
cmd = self._generator.create_port_list_command(name, port_range, kwargs) |
|
281
|
|
|
return self.send_command(cmd) |
|
282
|
|
|
|
|
283
|
|
|
def create_port_range(self, port_list_id, start, end, port_range_type, |
|
|
|
|
|
|
284
|
|
|
comment=''): |
|
285
|
|
|
cmd = self._generator.create_port_range_command( |
|
286
|
|
|
port_list_id, start, end, port_range_type, comment) |
|
287
|
|
|
return self.send_command(cmd) |
|
288
|
|
|
|
|
289
|
|
|
def create_report(self, report_xml_string, **kwargs): |
|
|
|
|
|
|
290
|
|
|
cmd = self._generator.create_report_command(report_xml_string, kwargs) |
|
291
|
|
|
return self.send_command(cmd) |
|
292
|
|
|
|
|
293
|
|
|
def create_role(self, name, **kwargs): |
|
|
|
|
|
|
294
|
|
|
cmd = self._generator.create_role_command(name, kwargs) |
|
295
|
|
|
return self.send_command(cmd) |
|
296
|
|
|
|
|
297
|
|
|
def create_scanner(self, name, host, port, scanner_type, ca_pub, |
|
|
|
|
|
|
298
|
|
|
credential_id, **kwargs): |
|
299
|
|
|
cmd = self._generator.create_scanner_command(name, host, port, |
|
300
|
|
|
scanner_type, ca_pub, |
|
301
|
|
|
credential_id, kwargs) |
|
302
|
|
|
return self.send_command(cmd) |
|
303
|
|
|
|
|
304
|
|
|
def create_schedule(self, name, **kwargs): |
|
|
|
|
|
|
305
|
|
|
cmd = self._generator.create_schedule_command(name, kwargs) |
|
306
|
|
|
return self.send_command(cmd) |
|
307
|
|
|
|
|
308
|
|
|
def create_tag(self, name, resource_id, resource_type, **kwargs): |
|
|
|
|
|
|
309
|
|
|
cmd = self._generator.create_tag_command(name, resource_id, |
|
310
|
|
|
resource_type, kwargs) |
|
311
|
|
|
return self.send_command(cmd) |
|
312
|
|
|
|
|
313
|
|
|
def create_target(self, name, make_unique, **kwargs): |
|
|
|
|
|
|
314
|
|
|
# TODO: Missing variables |
|
|
|
|
|
|
315
|
|
|
cmd = self._generator.create_target_command(name, make_unique, kwargs) |
|
316
|
|
|
return self.send_command(cmd) |
|
317
|
|
|
|
|
318
|
|
|
def create_task(self, name, config_id, target_id, scanner_id, |
|
|
|
|
|
|
319
|
|
|
alert_ids=None, comment=''): |
|
320
|
|
|
if alert_ids is None: |
|
321
|
|
|
alert_ids = [] |
|
322
|
|
|
cmd = self._generator.create_task_command( |
|
323
|
|
|
name, config_id, target_id, scanner_id, alert_ids, comment) |
|
324
|
|
|
return self.send_command(cmd) |
|
325
|
|
|
|
|
326
|
|
|
def create_user(self, name, password, copy='', hosts_allow='0', |
|
|
|
|
|
|
327
|
|
|
ifaces_allow='0', role_ids=(), hosts=None, ifaces=None): |
|
328
|
|
|
cmd = self._generator.create_user_command( |
|
329
|
|
|
name, password, copy, hosts_allow, ifaces_allow, role_ids, hosts, |
|
330
|
|
|
ifaces) |
|
331
|
|
|
return self.send_command(cmd) |
|
332
|
|
|
|
|
333
|
|
|
def delete_agent(self, **kwargs): |
|
|
|
|
|
|
334
|
|
|
cmd = '<delete_agent {0}/>'.format(arguments_to_string(kwargs)) |
|
335
|
|
|
return self.send_command(cmd) |
|
336
|
|
|
|
|
337
|
|
|
def delete_alert(self, **kwargs): |
|
|
|
|
|
|
338
|
|
|
cmd = '<delete_alert {0}/>'.format(arguments_to_string(kwargs)) |
|
339
|
|
|
return self.send_command(cmd) |
|
340
|
|
|
|
|
341
|
|
|
def delete_asset(self, asset_id, ultimate=0): |
|
|
|
|
|
|
342
|
|
|
cmd = '<delete_asset asset_id="{0}" ultimate="{1}"/>'.format( |
|
343
|
|
|
asset_id, ultimate) |
|
344
|
|
|
return self.send_command(cmd) |
|
345
|
|
|
|
|
346
|
|
|
def delete_config(self, config_id, ultimate=0): |
|
|
|
|
|
|
347
|
|
|
cmd = '<delete_config config_id="{0}" ultimate="{1}"/>'.format( |
|
348
|
|
|
config_id, ultimate) |
|
349
|
|
|
return self.send_command(cmd) |
|
350
|
|
|
|
|
351
|
|
|
def delete_credential(self, credential_id, ultimate=0): |
|
|
|
|
|
|
352
|
|
|
cmd = '<delete_credential credential_id="{0}" ultimate="{1}"/>'.format( |
|
353
|
|
|
credential_id, ultimate) |
|
354
|
|
|
return self.send_command(cmd) |
|
355
|
|
|
|
|
356
|
|
|
def delete_filter(self, filter_id, ultimate=0): |
|
|
|
|
|
|
357
|
|
|
cmd = '<delete_filter filter_id="{0}" ultimate="{1}"/>'.format( |
|
358
|
|
|
filter_id, ultimate) |
|
359
|
|
|
return self.send_command(cmd) |
|
360
|
|
|
|
|
361
|
|
|
def delete_group(self, group_id, ultimate=0): |
|
|
|
|
|
|
362
|
|
|
cmd = '<delete_group group_id="{0}" ultimate="{1}"/>'.format( |
|
363
|
|
|
group_id, ultimate) |
|
364
|
|
|
return self.send_command(cmd) |
|
365
|
|
|
|
|
366
|
|
|
def delete_note(self, note_id, ultimate=0): |
|
|
|
|
|
|
367
|
|
|
cmd = '<delete_note note_id="{0}" ultimate="{1}"/>'.format( |
|
368
|
|
|
note_id, ultimate) |
|
369
|
|
|
return self.send_command(cmd) |
|
370
|
|
|
|
|
371
|
|
|
def delete_override(self, override_id, ultimate=0): |
|
|
|
|
|
|
372
|
|
|
cmd = '<delete_override override_id="{0}" ultimate="{1}"/>'.format( |
|
373
|
|
|
override_id, ultimate) |
|
374
|
|
|
return self.send_command(cmd) |
|
375
|
|
|
|
|
376
|
|
|
def delete_permission(self, permission_id, ultimate=0): |
|
|
|
|
|
|
377
|
|
|
cmd = '<delete_permission permission_id="{0}" ultimate="{1}"/>'.format( |
|
378
|
|
|
permission_id, ultimate) |
|
379
|
|
|
return self.send_command(cmd) |
|
380
|
|
|
|
|
381
|
|
|
def delete_port_list(self, port_list_id, ultimate=0): |
|
|
|
|
|
|
382
|
|
|
cmd = '<delete_port_list port_list_id="{0}" ultimate="{1}"/>'.format( |
|
383
|
|
|
port_list_id, ultimate) |
|
384
|
|
|
return self.send_command(cmd) |
|
385
|
|
|
|
|
386
|
|
|
def delete_port_range(self, port_range_id): |
|
|
|
|
|
|
387
|
|
|
cmd = '<delete_port_range port_range_id="{0}"/>'.format(port_range_id) |
|
388
|
|
|
return self.send_command(cmd) |
|
389
|
|
|
|
|
390
|
|
|
def delete_report(self, report_id): |
|
|
|
|
|
|
391
|
|
|
cmd = '<delete_report report_id="{0}"/>'.format(report_id) |
|
392
|
|
|
return self.send_command(cmd) |
|
393
|
|
|
|
|
394
|
|
|
def delete_report_format(self, report_format_id, ultimate=0): |
|
|
|
|
|
|
395
|
|
|
cmd = '<delete_report_format report_format_id="{0}" ' \ |
|
396
|
|
|
'ultimate="{1}"/>'.format(report_format_id, ultimate) |
|
397
|
|
|
return self.send_command(cmd) |
|
398
|
|
|
|
|
399
|
|
|
def delete_role(self, role_id, ultimate=0): |
|
|
|
|
|
|
400
|
|
|
cmd = '<delete_role role_id="{0}" ultimate="{1}"/>'.format( |
|
401
|
|
|
role_id, ultimate) |
|
402
|
|
|
return self.send_command(cmd) |
|
403
|
|
|
|
|
404
|
|
|
def delete_scanner(self, scanner_id, ultimate=0): |
|
|
|
|
|
|
405
|
|
|
cmd = '<delete_scanner scanner_id="{0}" ultimate="{1}"/>'.format( |
|
406
|
|
|
scanner_id, ultimate) |
|
407
|
|
|
return self.send_command(cmd) |
|
408
|
|
|
|
|
409
|
|
|
def delete_schedule(self, schedule_id, ultimate=0): |
|
|
|
|
|
|
410
|
|
|
# if self.ask_yes_or_no('Are you sure to delete this schedule? '): |
|
411
|
|
|
cmd = '<delete_schedule schedule_id="{0}" ultimate="{1}"/>'.format( |
|
412
|
|
|
schedule_id, ultimate) |
|
413
|
|
|
return self.send_command(cmd) |
|
414
|
|
|
|
|
415
|
|
|
def delete_tag(self, tag_id, ultimate=0): |
|
|
|
|
|
|
416
|
|
|
cmd = '<delete_tag tag_id="{0}" ultimate="{1}"/>'.format( |
|
417
|
|
|
tag_id, ultimate) |
|
418
|
|
|
return self.send_command(cmd) |
|
419
|
|
|
|
|
420
|
|
|
def delete_target(self, target_id, ultimate=0): |
|
|
|
|
|
|
421
|
|
|
cmd = '<delete_target target_id="{0}" ultimate="{1}"/>'.format( |
|
422
|
|
|
target_id, ultimate) |
|
423
|
|
|
return self.send_command(cmd) |
|
424
|
|
|
|
|
425
|
|
|
def delete_task(self, task_id, ultimate=0): |
|
|
|
|
|
|
426
|
|
|
cmd = '<delete_task task_id="{0}" ultimate="{1}"/>'.format( |
|
427
|
|
|
task_id, ultimate) |
|
428
|
|
|
return self.send_command(cmd) |
|
429
|
|
|
|
|
430
|
|
|
def delete_user(self, **kwargs): |
|
|
|
|
|
|
431
|
|
|
user_id = kwargs.get('user_id', '') |
|
432
|
|
|
if user_id: |
|
433
|
|
|
user_id = ' user_id="%s"' % user_id |
|
434
|
|
|
|
|
435
|
|
|
name = kwargs.get('name', '') |
|
436
|
|
|
if name: |
|
437
|
|
|
name = ' name="%s"' % name |
|
438
|
|
|
|
|
439
|
|
|
inheritor_id = kwargs.get('inheritor_id', '') |
|
440
|
|
|
if inheritor_id: |
|
441
|
|
|
inheritor_id = ' inheritor_id="%s"' % inheritor_id |
|
442
|
|
|
|
|
443
|
|
|
inheritor_name = kwargs.get('inheritor_name', '') |
|
444
|
|
|
if inheritor_name: |
|
445
|
|
|
inheritor_name = ' inheritor_name="%s"' % inheritor_name |
|
446
|
|
|
|
|
447
|
|
|
cmd = '<delete_user{0}{1}{2}{3}/>'.format( |
|
448
|
|
|
user_id, name, inheritor_id, inheritor_name) |
|
449
|
|
|
return self.send_command(cmd) |
|
450
|
|
|
|
|
451
|
|
|
def describe_auth(self): |
|
|
|
|
|
|
452
|
|
|
return self.send_command('<describe_auth/>') |
|
453
|
|
|
|
|
454
|
|
|
def empty_trashcan(self): |
|
|
|
|
|
|
455
|
|
|
return self.send_command('<empty_trashcan/>') |
|
456
|
|
|
|
|
457
|
|
|
def get_agents(self, **kwargs): |
|
|
|
|
|
|
458
|
|
|
cmd = '<get_agents {0}/>'.format(arguments_to_string(kwargs)) |
|
459
|
|
|
return self.send_command(cmd) |
|
460
|
|
|
|
|
461
|
|
|
def get_aggregates(self, **kwargs): |
|
|
|
|
|
|
462
|
|
|
cmd = '<get_aggregates {0}/>'.format(arguments_to_string(kwargs)) |
|
463
|
|
|
return self.send_command(cmd) |
|
464
|
|
|
|
|
465
|
|
|
def get_alerts(self, **kwargs): |
|
|
|
|
|
|
466
|
|
|
cmd = '<get_alerts {0}/>'.format(arguments_to_string(kwargs)) |
|
467
|
|
|
return self.send_command(cmd) |
|
468
|
|
|
|
|
469
|
|
|
def get_assets(self, **kwargs): |
|
|
|
|
|
|
470
|
|
|
cmd = '<get_assets {0}/>'.format(arguments_to_string(kwargs)) |
|
471
|
|
|
return self.send_command(cmd) |
|
472
|
|
|
|
|
473
|
|
|
def get_credentials(self, **kwargs): |
|
|
|
|
|
|
474
|
|
|
cmd = '<get_credentials {0}/>'.format(arguments_to_string(kwargs)) |
|
475
|
|
|
return self.send_command(cmd) |
|
476
|
|
|
|
|
477
|
|
|
def get_configs(self, **kwargs): |
|
|
|
|
|
|
478
|
|
|
cmd = '<get_configs {0}/>'.format(arguments_to_string(kwargs)) |
|
479
|
|
|
return self.send_command(cmd) |
|
480
|
|
|
|
|
481
|
|
|
def get_feeds(self, **kwargs): |
|
|
|
|
|
|
482
|
|
|
cmd = '<get_feeds {0}/>'.format(arguments_to_string(kwargs)) |
|
483
|
|
|
return self.send_command(cmd) |
|
484
|
|
|
|
|
485
|
|
|
def get_filters(self, **kwargs): |
|
|
|
|
|
|
486
|
|
|
cmd = '<get_filters {0}/>'.format(arguments_to_string(kwargs)) |
|
487
|
|
|
return self.send_command(cmd) |
|
488
|
|
|
|
|
489
|
|
|
def get_groups(self, **kwargs): |
|
|
|
|
|
|
490
|
|
|
cmd = '<get_groups {0}/>'.format(arguments_to_string(kwargs)) |
|
491
|
|
|
return self.send_command(cmd) |
|
492
|
|
|
|
|
493
|
|
|
def get_info(self, **kwargs): |
|
|
|
|
|
|
494
|
|
|
cmd = '<get_info {0}/>'.format(arguments_to_string(kwargs)) |
|
495
|
|
|
return self.send_command(cmd) |
|
496
|
|
|
|
|
497
|
|
|
def get_notes(self, **kwargs): |
|
|
|
|
|
|
498
|
|
|
cmd = '<get_notes {0}/>'.format(arguments_to_string(kwargs)) |
|
499
|
|
|
return self.send_command(cmd) |
|
500
|
|
|
|
|
501
|
|
|
def get_nvts(self, **kwargs): |
|
|
|
|
|
|
502
|
|
|
cmd = '<get_nvts {0}/>'.format(arguments_to_string(kwargs)) |
|
503
|
|
|
return self.send_command(cmd) |
|
504
|
|
|
|
|
505
|
|
|
def get_nvt_families(self, **kwargs): |
|
|
|
|
|
|
506
|
|
|
cmd = '<get_nvt_families {0}/>'.format(arguments_to_string(kwargs)) |
|
507
|
|
|
return self.send_command(cmd) |
|
508
|
|
|
|
|
509
|
|
|
def get_overrides(self, **kwargs): |
|
|
|
|
|
|
510
|
|
|
cmd = '<get_overrides {0}/>'.format(arguments_to_string(kwargs)) |
|
511
|
|
|
return self.send_command(cmd) |
|
512
|
|
|
|
|
513
|
|
|
def get_permissions(self, **kwargs): |
|
|
|
|
|
|
514
|
|
|
cmd = '<get_permissions {0}/>'.format(arguments_to_string(kwargs)) |
|
515
|
|
|
return self.send_command(cmd) |
|
516
|
|
|
|
|
517
|
|
|
def get_port_lists(self, **kwargs): |
|
|
|
|
|
|
518
|
|
|
cmd = '<get_port_lists {0}/>'.format(arguments_to_string(kwargs)) |
|
519
|
|
|
return self.send_command(cmd) |
|
520
|
|
|
|
|
521
|
|
|
def get_preferences(self, **kwargs): |
|
|
|
|
|
|
522
|
|
|
cmd = '<get_preferences {0}/>'.format(arguments_to_string(kwargs)) |
|
523
|
|
|
return self.send_command(cmd) |
|
524
|
|
|
|
|
525
|
|
|
def get_reports(self, **kwargs): |
|
|
|
|
|
|
526
|
|
|
cmd = '<get_reports {0}/>'.format(arguments_to_string(kwargs)) |
|
527
|
|
|
return self.send_command(cmd) |
|
528
|
|
|
|
|
529
|
|
|
def get_report_formats(self, **kwargs): |
|
|
|
|
|
|
530
|
|
|
cmd = '<get_report_formats {0}/>'.format(arguments_to_string(kwargs)) |
|
531
|
|
|
return self.send_command(cmd) |
|
532
|
|
|
|
|
533
|
|
|
def get_results(self, **kwargs): |
|
|
|
|
|
|
534
|
|
|
cmd = '<get_results {0}/>'.format(arguments_to_string(kwargs)) |
|
535
|
|
|
return self.send_command(cmd) |
|
536
|
|
|
|
|
537
|
|
|
def get_roles(self, **kwargs): |
|
|
|
|
|
|
538
|
|
|
cmd = '<get_roles {0}/>'.format(arguments_to_string(kwargs)) |
|
539
|
|
|
return self.send_command(cmd) |
|
540
|
|
|
|
|
541
|
|
|
def get_scanners(self, **kwargs): |
|
|
|
|
|
|
542
|
|
|
cmd = '<get_scanners {0}/>'.format(arguments_to_string(kwargs)) |
|
543
|
|
|
return self.send_command(cmd) |
|
544
|
|
|
|
|
545
|
|
|
def get_schedules(self, **kwargs): |
|
|
|
|
|
|
546
|
|
|
cmd = '<get_schedules {0}/>'.format(arguments_to_string(kwargs)) |
|
547
|
|
|
return self.send_command(cmd) |
|
548
|
|
|
|
|
549
|
|
|
def get_settings(self, **kwargs): |
|
|
|
|
|
|
550
|
|
|
cmd = '<get_settings {0}/>'.format(arguments_to_string(kwargs)) |
|
551
|
|
|
return self.send_command(cmd) |
|
552
|
|
|
|
|
553
|
|
|
def get_system_reports(self, **kwargs): |
|
|
|
|
|
|
554
|
|
|
cmd = '<get_system_reports {0}/>'.format(arguments_to_string(kwargs)) |
|
555
|
|
|
return self.send_command(cmd) |
|
556
|
|
|
|
|
557
|
|
|
def get_tags(self, **kwargs): |
|
|
|
|
|
|
558
|
|
|
cmd = '<get_tags {0}/>'.format(arguments_to_string(kwargs)) |
|
559
|
|
|
return self.send_command(cmd) |
|
560
|
|
|
|
|
561
|
|
|
def get_targets(self, **kwargs): |
|
|
|
|
|
|
562
|
|
|
cmd = '<get_targets {0}/>'.format(arguments_to_string(kwargs)) |
|
563
|
|
|
return self.send_command(cmd) |
|
564
|
|
|
|
|
565
|
|
|
def get_tasks(self, **kwargs): |
|
|
|
|
|
|
566
|
|
|
cmd = '<get_tasks {0}/>'.format(arguments_to_string(kwargs)) |
|
567
|
|
|
return self.send_command(cmd) |
|
568
|
|
|
|
|
569
|
|
|
def get_users(self, **kwargs): |
|
|
|
|
|
|
570
|
|
|
cmd = '<get_users {0}/>'.format(arguments_to_string(kwargs)) |
|
571
|
|
|
return self.send_command(cmd) |
|
572
|
|
|
|
|
573
|
|
|
def get_version(self): |
|
|
|
|
|
|
574
|
|
|
return self.send_command('<get_version/>') |
|
575
|
|
|
|
|
576
|
|
|
def help(self, **kwargs): |
|
|
|
|
|
|
577
|
|
|
cmd = '<help {0} />'.format(arguments_to_string(kwargs)) |
|
578
|
|
|
return self.send_command(cmd) |
|
579
|
|
|
|
|
580
|
|
|
def modify_agent(self, agent_id, name='', comment=''): |
|
|
|
|
|
|
581
|
|
|
cmd = self._generator.modify_agent_command(agent_id, name, comment) |
|
582
|
|
|
return self.send_command(cmd) |
|
583
|
|
|
|
|
584
|
|
|
def modify_alert(self, alert_id, **kwargs): |
|
|
|
|
|
|
585
|
|
|
cmd = self._generator.modify_alert_command(alert_id, kwargs) |
|
586
|
|
|
return self.send_command(cmd) |
|
587
|
|
|
|
|
588
|
|
|
def modify_asset(self, asset_id, comment): |
|
|
|
|
|
|
589
|
|
|
cmd = '<modify_asset asset_id="%s"><comment>%s</comment>' \ |
|
590
|
|
|
'</modify_asset>' % (asset_id, comment) |
|
591
|
|
|
return self.send_command(cmd) |
|
592
|
|
|
|
|
593
|
|
|
def modify_auth(self, group_name, auth_conf_settings): |
|
|
|
|
|
|
594
|
|
|
cmd = self._generator.modify_auth_command(group_name, |
|
595
|
|
|
auth_conf_settings) |
|
596
|
|
|
return self.send_command(cmd) |
|
597
|
|
|
|
|
598
|
|
|
def modify_config(self, selection, **kwargs): |
|
|
|
|
|
|
599
|
|
|
cmd = self._generator.modify_config_command(selection, kwargs) |
|
600
|
|
|
return self.send_command(cmd) |
|
601
|
|
|
|
|
602
|
|
|
def modify_credential(self, credential_id, **kwargs): |
|
|
|
|
|
|
603
|
|
|
cmd = self._generator.modify_credential_command( |
|
604
|
|
|
credential_id, kwargs) |
|
605
|
|
|
return self.send_command(cmd) |
|
606
|
|
|
|
|
607
|
|
|
def modify_filter(self, filter_id, **kwargs): |
|
|
|
|
|
|
608
|
|
|
cmd = self._generator.modify_filter_command(filter_id, kwargs) |
|
609
|
|
|
return self.send_command(cmd) |
|
610
|
|
|
|
|
611
|
|
|
def modify_group(self, group_id, **kwargs): |
|
|
|
|
|
|
612
|
|
|
cmd = self._generator.modify_group_command(group_id, kwargs) |
|
613
|
|
|
return self.send_command(cmd) |
|
614
|
|
|
|
|
615
|
|
|
def modify_note(self, note_id, text, **kwargs): |
|
|
|
|
|
|
616
|
|
|
cmd = self._generator.modify_note_command(note_id, text, kwargs) |
|
617
|
|
|
return self.send_command(cmd) |
|
618
|
|
|
|
|
619
|
|
|
def modify_override(self, override_id, text, **kwargs): |
|
|
|
|
|
|
620
|
|
|
cmd = self._generator.modify_override_command(override_id, text, |
|
621
|
|
|
kwargs) |
|
622
|
|
|
return self.send_command(cmd) |
|
623
|
|
|
|
|
624
|
|
|
def modify_permission(self, permission_id, **kwargs): |
|
|
|
|
|
|
625
|
|
|
cmd = self._generator.modify_permission_command( |
|
626
|
|
|
permission_id, kwargs) |
|
627
|
|
|
return self.send_command(cmd) |
|
628
|
|
|
|
|
629
|
|
|
def modify_port_list(self, port_list_id, **kwargs): |
|
|
|
|
|
|
630
|
|
|
cmd = self._generator.modify_port_list_command(port_list_id, kwargs) |
|
631
|
|
|
return self.send_command(cmd) |
|
632
|
|
|
|
|
633
|
|
|
def modify_report(self, report_id, comment): |
|
|
|
|
|
|
634
|
|
|
cmd = '<modify_report report_id="{0}"><comment>{1}</comment>' \ |
|
635
|
|
|
'</modify_report>'.format(report_id, comment) |
|
636
|
|
|
return self.send_command(cmd) |
|
637
|
|
|
|
|
638
|
|
|
def modify_report_format(self, report_format_id, **kwargs): |
|
|
|
|
|
|
639
|
|
|
cmd = self._generator.modify_report_format_command(report_format_id, |
|
640
|
|
|
kwargs) |
|
641
|
|
|
return self.send_command(cmd) |
|
642
|
|
|
|
|
643
|
|
|
def modify_role(self, role_id, **kwargs): |
|
|
|
|
|
|
644
|
|
|
cmd = self._generator.modify_role_command(role_id, kwargs) |
|
645
|
|
|
return self.send_command(cmd) |
|
646
|
|
|
|
|
647
|
|
|
def modify_scanner(self, scanner_id, host, port, scanner_type, **kwargs): |
|
|
|
|
|
|
648
|
|
|
cmd = self._generator.modify_scanner_command(scanner_id, host, port, |
|
649
|
|
|
scanner_type, kwargs) |
|
650
|
|
|
return self.send_command(cmd) |
|
651
|
|
|
|
|
652
|
|
|
def modify_schedule(self, schedule_id, **kwargs): |
|
|
|
|
|
|
653
|
|
|
cmd = self._generator.modify_schedule_command(schedule_id, kwargs) |
|
654
|
|
|
return self.send_command(cmd) |
|
655
|
|
|
|
|
656
|
|
|
def modify_setting(self, setting_id, name, value): |
|
|
|
|
|
|
657
|
|
|
cmd = '<modify_setting setting_id="{0}"><name>{1}</name>' \ |
|
658
|
|
|
'<value>{2}</value></modify_setting>' \ |
|
659
|
|
|
''.format(setting_id, name, value) |
|
660
|
|
|
return self.send_command(cmd) |
|
661
|
|
|
|
|
662
|
|
|
def modify_tag(self, tag_id, **kwargs): |
|
|
|
|
|
|
663
|
|
|
cmd = self._generator.modify_tag_command(tag_id, kwargs) |
|
664
|
|
|
return self.send_command(cmd) |
|
665
|
|
|
|
|
666
|
|
|
def modify_target(self, target_id, **kwargs): |
|
|
|
|
|
|
667
|
|
|
cmd = self._generator.modify_target_command(target_id, kwargs) |
|
668
|
|
|
return self.send_command(cmd) |
|
669
|
|
|
|
|
670
|
|
|
def modify_task(self, task_id, **kwargs): |
|
|
|
|
|
|
671
|
|
|
cmd = self._generator.modify_task_command(task_id, kwargs) |
|
672
|
|
|
return self.send_command(cmd) |
|
673
|
|
|
|
|
674
|
|
|
def modify_user(self, **kwargs): |
|
|
|
|
|
|
675
|
|
|
cmd = self._generator.modify_user_command(kwargs) |
|
676
|
|
|
return self.send_command(cmd) |
|
677
|
|
|
|
|
678
|
|
|
def move_task(self, task_id, slave_id): |
|
|
|
|
|
|
679
|
|
|
cmd = '<move_task task_id="{0}" slave_id="{1}"/>'.format( |
|
680
|
|
|
task_id, slave_id) |
|
681
|
|
|
return self.send_command(cmd) |
|
682
|
|
|
|
|
683
|
|
|
def restore(self, entity_id): |
|
|
|
|
|
|
684
|
|
|
cmd = '<restore id="{0}"/>'.format(entity_id) |
|
685
|
|
|
return self.send_command(cmd) |
|
686
|
|
|
|
|
687
|
|
|
def resume_task(self, task_id): |
|
|
|
|
|
|
688
|
|
|
cmd = '<resume_task task_id="{0}"/>'.format(task_id) |
|
689
|
|
|
return self.send_command(cmd) |
|
690
|
|
|
|
|
691
|
|
|
def start_task(self, task_id): |
|
|
|
|
|
|
692
|
|
|
cmd = '<start_task task_id="{0}"/>'.format(task_id) |
|
693
|
|
|
return self.send_command(cmd) |
|
694
|
|
|
|
|
695
|
|
|
def stop_task(self, task_id): |
|
|
|
|
|
|
696
|
|
|
cmd = '<stop_task task_id="{0}"/>'.format(task_id) |
|
697
|
|
|
return self.send_command(cmd) |
|
698
|
|
|
|
|
699
|
|
|
def sync_cert(self): |
|
|
|
|
|
|
700
|
|
|
cmd = '<sync_cert/>' |
|
701
|
|
|
return self.send_command(cmd) |
|
702
|
|
|
|
|
703
|
|
|
def sync_config(self): |
|
|
|
|
|
|
704
|
|
|
cmd = '<sync_config/>' |
|
705
|
|
|
return self.send_command(cmd) |
|
706
|
|
|
|
|
707
|
|
|
def sync_feed(self): |
|
|
|
|
|
|
708
|
|
|
cmd = '<sync_feed/>' |
|
709
|
|
|
return self.send_command(cmd) |
|
710
|
|
|
|
|
711
|
|
|
def sync_scap(self): |
|
|
|
|
|
|
712
|
|
|
cmd = '<sync_scap/>' |
|
713
|
|
|
return self.send_command(cmd) |
|
714
|
|
|
|
|
715
|
|
|
def test_alert(self, alert_id): |
|
|
|
|
|
|
716
|
|
|
cmd = '<test_alert alert_id="{0}"/>'.format(alert_id) |
|
717
|
|
|
return self.send_command(cmd) |
|
718
|
|
|
|
|
719
|
|
|
def verify_agent(self, agent_id): |
|
|
|
|
|
|
720
|
|
|
cmd = '<verify_agent agent_id="{0}"/>'.format(agent_id) |
|
721
|
|
|
return self.send_command(cmd) |
|
722
|
|
|
|
|
723
|
|
|
def verify_report_format(self, report_format_id): |
|
|
|
|
|
|
724
|
|
|
cmd = '<verify_report_format report_format_id="{0}"/>'.format( |
|
725
|
|
|
report_format_id) |
|
726
|
|
|
return self.send_command(cmd) |
|
727
|
|
|
|
|
728
|
|
|
def verify_scanner(self, scanner_id): |
|
|
|
|
|
|
729
|
|
|
cmd = '<verify_scanner scanner_id="{0}"/>'.format(scanner_id) |
|
730
|
|
|
return self.send_command(cmd) |
|
731
|
|
|
|
This check looks for invalid names for a range of different identifiers.
You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.
If your project includes a Pylint configuration file, the settings contained in that file take precedence.
To find out more about Pylint, please refer to their site.