1
|
|
|
# -*- coding: utf-8 -*- |
2
|
|
|
# Copyright (C) 2021 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
|
|
|
from typing import Any, Optional |
20
|
|
|
|
21
|
|
|
from gvm.errors import RequiredArgument |
22
|
|
|
from gvm.utils import add_filter |
23
|
|
|
from gvm.xml import XmlCommand |
24
|
|
|
|
25
|
|
|
|
26
|
|
|
class VulnerabilitiesMixin: |
27
|
|
|
def get_vulnerabilities( |
28
|
|
|
self, |
29
|
|
|
*, |
30
|
|
|
filter_string: Optional[str] = None, |
31
|
|
|
filter_id: Optional[str] = None, |
32
|
|
|
) -> Any: |
33
|
|
|
"""Request a list of vulnerabilities |
34
|
|
|
|
35
|
|
|
Arguments: |
36
|
|
|
filter_string: Filter term to use for the query |
37
|
|
|
filter_id: UUID of an existing filter to use for the query |
38
|
|
|
Returns: |
39
|
|
|
The response. See :py:meth:`send_command` for details. |
40
|
|
|
""" |
41
|
|
|
cmd = XmlCommand("get_vulns") |
42
|
|
|
|
43
|
|
|
add_filter(cmd, filter_string, filter_id) |
44
|
|
|
|
45
|
|
|
return self._send_xml_command(cmd) |
46
|
|
|
|
47
|
|
|
def get_vulnerability(self, vulnerability_id: str) -> Any: |
48
|
|
|
"""Request a single vulnerability |
49
|
|
|
|
50
|
|
|
Arguments: |
51
|
|
|
vulnerability_id: ID of an existing vulnerability |
52
|
|
|
|
53
|
|
|
Returns: |
54
|
|
|
The response. See :py:meth:`send_command` for details. |
55
|
|
|
""" |
56
|
|
|
if not vulnerability_id: |
57
|
|
|
raise RequiredArgument( |
58
|
|
|
function=self.get_vulnerability.__name__, |
59
|
|
|
argument='vulnerability_id', |
60
|
|
|
) |
61
|
|
|
|
62
|
|
|
cmd = XmlCommand("get_vulns") |
63
|
|
|
cmd.set_attribute("vuln_id", vulnerability_id) |
64
|
|
|
return self._send_xml_command(cmd) |
65
|
|
|
|