|
1
|
|
|
# -*- coding: utf-8 -*- |
|
2
|
|
|
# Copyright (C) 2014-2021 Greenbone Networks GmbH |
|
3
|
|
|
# |
|
4
|
|
|
# SPDX-License-Identifier: AGPL-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 Affero General Public License as |
|
8
|
|
|
# published by the Free Software Foundation, either version 3 of the |
|
9
|
|
|
# License, or (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 Affero General Public License for more details. |
|
15
|
|
|
# |
|
16
|
|
|
# You should have received a copy of the GNU Affero General Public License |
|
17
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
18
|
|
|
|
|
19
|
|
|
|
|
20
|
|
|
from unittest.mock import patch, MagicMock |
|
21
|
|
|
|
|
22
|
|
|
from xml.etree import ElementTree as et |
|
23
|
|
|
|
|
24
|
|
|
from ospd_openvas.daemon import OSPDopenvas |
|
25
|
|
|
|
|
26
|
|
|
|
|
27
|
|
|
class FakeDataManager: |
|
28
|
|
|
def __init__(self): |
|
29
|
|
|
pass |
|
30
|
|
|
|
|
31
|
|
|
def dict(self): |
|
32
|
|
|
return dict() |
|
33
|
|
|
|
|
34
|
|
|
|
|
35
|
|
|
class DummyDaemon(OSPDopenvas): |
|
36
|
|
|
VTS = { |
|
37
|
|
|
'1.3.6.1.4.1.25623.1.0.100061': { |
|
38
|
|
|
'creation_time': '1237458156', |
|
39
|
|
|
'custom': { |
|
40
|
|
|
'category': '3', |
|
41
|
|
|
'excluded_keys': 'Settings/disable_cgi_scanning', |
|
42
|
|
|
'family': 'Product detection', |
|
43
|
|
|
'filename': 'mantis_detect.nasl', |
|
44
|
|
|
'required_ports': 'Services/www, 80', |
|
45
|
|
|
'timeout': '0', |
|
46
|
|
|
}, |
|
47
|
|
|
'modification_time': ('1533906565'), |
|
48
|
|
|
'name': 'Mantis Detection', |
|
49
|
|
|
'qod_type': 'remote_banner', |
|
50
|
|
|
'insight': 'some insight', |
|
51
|
|
|
'severities': { |
|
52
|
|
|
'severity_base_vector': 'AV:N/AC:L/Au:N/C:N/I:N/A:N', |
|
53
|
|
|
'severity_type': 'cvss_base_v2', |
|
54
|
|
|
'severity_date': '1237458156', |
|
55
|
|
|
'severity_origin': 'Greenbone', |
|
56
|
|
|
}, |
|
57
|
|
|
'solution': 'some solution', |
|
58
|
|
|
'solution_type': 'WillNotFix', |
|
59
|
|
|
'solution_method': 'DebianAPTUpgrade', |
|
60
|
|
|
'impact': 'some impact', |
|
61
|
|
|
'summary': 'some summary', |
|
62
|
|
|
'affected': 'some affection', |
|
63
|
|
|
'vt_dependencies': [], |
|
64
|
|
|
'vt_params': { |
|
65
|
|
|
'1': { |
|
66
|
|
|
'id': '1', |
|
67
|
|
|
'default': '', |
|
68
|
|
|
'description': 'Description', |
|
69
|
|
|
'name': 'Data length :', |
|
70
|
|
|
'type': 'entry', |
|
71
|
|
|
}, |
|
72
|
|
|
'2': { |
|
73
|
|
|
'id': '2', |
|
74
|
|
|
'default': 'no', |
|
75
|
|
|
'description': 'Description', |
|
76
|
|
|
'name': 'Do not randomize the order in which ports are scanned', # pylint: disable=line-too-long |
|
77
|
|
|
'type': 'checkbox', |
|
78
|
|
|
}, |
|
79
|
|
|
}, |
|
80
|
|
|
'vt_refs': { |
|
81
|
|
|
'bid': [''], |
|
82
|
|
|
'cve': [''], |
|
83
|
|
|
'xref': ['URL:http://www.mantisbt.org/'], |
|
84
|
|
|
}, |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
@patch('ospd_openvas.daemon.NVTICache') |
|
89
|
|
|
@patch('ospd_openvas.daemon.MainDB') |
|
90
|
|
|
def __init__( |
|
91
|
|
|
self, _MainDBClass: MagicMock = None, NvtiClass: MagicMock = None |
|
92
|
|
|
): |
|
93
|
|
|
assert _MainDBClass |
|
94
|
|
|
assert NvtiClass |
|
95
|
|
|
nvti = NvtiClass.return_value |
|
96
|
|
|
oids = [['mantis_detect.nasl', '1.3.6.1.4.1.25623.1.0.100061']] |
|
97
|
|
|
nvti.get_oids.return_value = oids |
|
98
|
|
|
nvti.get_nvt_params.return_value = { |
|
99
|
|
|
'1': { |
|
100
|
|
|
'id': '1', |
|
101
|
|
|
'default': '', |
|
102
|
|
|
'description': 'Description', |
|
103
|
|
|
'name': 'Data length :', |
|
104
|
|
|
'type': 'entry', |
|
105
|
|
|
}, |
|
106
|
|
|
'2': { |
|
107
|
|
|
'id': '2', |
|
108
|
|
|
'default': 'no', |
|
109
|
|
|
'description': 'Description', |
|
110
|
|
|
'name': 'Do not randomize the order in which ports are scanned', # pylint: disable=line-too-long |
|
111
|
|
|
'type': 'checkbox', |
|
112
|
|
|
}, |
|
113
|
|
|
} |
|
114
|
|
|
nvti.get_nvt_refs.return_value = { |
|
115
|
|
|
'bid': [''], |
|
116
|
|
|
'cve': [''], |
|
117
|
|
|
'xref': ['URL:http://www.mantisbt.org/'], |
|
118
|
|
|
} |
|
119
|
|
|
nvti.get_nvt_metadata.return_value = { |
|
120
|
|
|
'category': '3', |
|
121
|
|
|
'creation_date': '1237458156', |
|
122
|
|
|
'cvss_base_vector': 'AV:N/AC:L/Au:N/C:N/I:N/A:N', |
|
123
|
|
|
'excluded_keys': 'Settings/disable_cgi_scanning', |
|
124
|
|
|
'family': 'Product detection', |
|
125
|
|
|
'filename': 'mantis_detect.nasl', |
|
126
|
|
|
'last_modification': ('1533906565'), |
|
127
|
|
|
'name': 'Mantis Detection', |
|
128
|
|
|
'qod_type': 'remote_banner', |
|
129
|
|
|
'required_ports': 'Services/www, 80', |
|
130
|
|
|
'solution': 'some solution', |
|
131
|
|
|
'solution_type': 'WillNotFix', |
|
132
|
|
|
'solution_method': 'DebianAPTUpgrade', |
|
133
|
|
|
'impact': 'some impact', |
|
134
|
|
|
'insight': 'some insight', |
|
135
|
|
|
'summary': ('some summary'), |
|
136
|
|
|
'affected': 'some affection', |
|
137
|
|
|
'timeout': '0', |
|
138
|
|
|
'vt_params': { |
|
139
|
|
|
'1': { |
|
140
|
|
|
'id': '1', |
|
141
|
|
|
'default': '', |
|
142
|
|
|
'description': 'Description', |
|
143
|
|
|
'name': 'Data length :', |
|
144
|
|
|
'type': 'entry', |
|
145
|
|
|
}, |
|
146
|
|
|
'2': { |
|
147
|
|
|
'id': '2', |
|
148
|
|
|
'default': 'no', |
|
149
|
|
|
'description': 'Description', |
|
150
|
|
|
'name': 'Do not randomize the order in which ports are scanned', # pylint: disable=line-too-long |
|
151
|
|
|
'type': 'checkbox', |
|
152
|
|
|
}, |
|
153
|
|
|
}, |
|
154
|
|
|
'refs': { |
|
155
|
|
|
'bid': [''], |
|
156
|
|
|
'cve': [''], |
|
157
|
|
|
'xref': ['URL:http://www.mantisbt.org/'], |
|
158
|
|
|
}, |
|
159
|
|
|
} |
|
160
|
|
|
nvti.get_feed_version.return_value = '123' |
|
161
|
|
|
|
|
162
|
|
|
super().__init__(niceness=10, lock_file_dir='/tmp') |
|
163
|
|
|
|
|
164
|
|
|
self.scan_collection.data_manager = FakeDataManager() |
|
165
|
|
|
|
|
166
|
|
|
def create_xml_target(self) -> et.Element: |
|
167
|
|
|
target = et.fromstring( |
|
168
|
|
|
"<target>" |
|
169
|
|
|
"<hosts>192.168.0.1</hosts>" |
|
170
|
|
|
"<ports>80,443</ports>" |
|
171
|
|
|
"</target>" |
|
172
|
|
|
) |
|
173
|
|
|
return target |
|
174
|
|
|
|