-
Notifications
You must be signed in to change notification settings - Fork 67
Expand file tree
/
Copy path_web_application_targets.py
More file actions
209 lines (174 loc) · 6.41 KB
/
Copy path_web_application_targets.py
File metadata and controls
209 lines (174 loc) · 6.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
# SPDX-FileCopyrightText: 2026 Greenbone AG
#
# SPDX-License-Identifier: GPL-3.0-or-later
#
from gvm.errors import RequiredArgument
from gvm.protocols.core import Request
from gvm.protocols.gmp.requests._entity_id import EntityID
from gvm.utils import to_bool, to_comma_list
from gvm.xml import XmlCommand
class WebApplicationTargets:
@classmethod
def create_web_application_target(
cls,
name: str,
urls: list[str],
*,
comment: str | None = None,
exclude_urls: list[str] | None = None,
credential_id: EntityID | None = None,
) -> Request:
"""Create a new web application target.
Args:
name: Name of the target.
urls: List of URLs to scan.
comment: Comment for the target.
exclude_urls: List of URLs to exclude from the scan.
credential_id: UUID of a credential to use on target.
"""
if not name:
raise RequiredArgument(
function=cls.create_web_application_target.__name__,
argument="name",
)
if not urls:
raise RequiredArgument(
function=cls.create_web_application_target.__name__,
argument="urls",
)
cmd = XmlCommand("create_web_application_target")
cmd.add_element("name", name)
cmd.add_element("urls", to_comma_list(urls))
if comment:
cmd.add_element("comment", comment)
if exclude_urls:
cmd.add_element("exclude_urls", to_comma_list(exclude_urls))
if credential_id:
cmd.add_element("credential", attrs={"id": str(credential_id)})
return cmd
@classmethod
def modify_web_application_target(
cls,
web_application_target_id: EntityID,
*,
name: str | None = None,
comment: str | None = None,
urls: list[str] | None = None,
exclude_urls: list[str] | None = None,
credential_id: EntityID | None = None,
) -> Request:
"""Modify an existing web application target.
Args:
web_application_target_id: UUID of target to modify.
name: Name of target.
comment: Comment on target.
urls: List of URLs to scan.
exclude_urls: List of URLs to exclude from the scan.
credential_id: UUID of credential to use on target.
"""
if not web_application_target_id:
raise RequiredArgument(
function=cls.modify_web_application_target.__name__,
argument="web_application_target_id",
)
cmd = XmlCommand("modify_web_application_target")
cmd.set_attribute(
"web_application_target_id", str(web_application_target_id)
)
if comment:
cmd.add_element("comment", comment)
if name:
cmd.add_element("name", name)
if urls:
cmd.add_element("urls", to_comma_list(urls))
if exclude_urls:
cmd.add_element("exclude_urls", to_comma_list(exclude_urls))
if credential_id:
cmd.add_element("credential", attrs={"id": str(credential_id)})
return cmd
@classmethod
def clone_web_application_target(
cls, web_application_target_id: EntityID
) -> Request:
"""Clone an existing web application target.
Args:
web_application_target_id: UUID of an existing target to clone.
"""
if not web_application_target_id:
raise RequiredArgument(
function=cls.clone_web_application_target.__name__,
argument="web_application_target_id",
)
cmd = XmlCommand("create_web_application_target")
cmd.add_element("copy", str(web_application_target_id))
return cmd
@classmethod
def delete_web_application_target(
cls,
web_application_target_id: EntityID,
*,
ultimate: bool | None = False,
) -> Request:
"""Delete an existing web application target.
Args:
web_application_target_id: UUID of an existing target to delete.
ultimate: Whether to remove entirely or move to the trashcan.
"""
if not web_application_target_id:
raise RequiredArgument(
function=cls.delete_web_application_target.__name__,
argument="web_application_target_id",
)
cmd = XmlCommand("delete_web_application_target")
cmd.set_attribute(
"web_application_target_id", str(web_application_target_id)
)
cmd.set_attribute("ultimate", to_bool(ultimate))
return cmd
@classmethod
def get_web_application_target(
cls,
web_application_target_id: EntityID,
*,
tasks: bool | None = None,
) -> Request:
"""Request a single web application target.
Args:
web_application_target_id: UUID of the target to request.
tasks: Whether to include list of tasks that use the target.
"""
if not web_application_target_id:
raise RequiredArgument(
function=cls.get_web_application_target.__name__,
argument="web_application_target_id",
)
cmd = XmlCommand("get_web_application_targets")
cmd.set_attribute(
"web_application_target_id", str(web_application_target_id)
)
if tasks is not None:
cmd.set_attribute("tasks", to_bool(tasks))
return cmd
@classmethod
def get_web_application_targets(
cls,
*,
filter_string: str | None = None,
filter_id: EntityID | None = None,
trash: bool | None = None,
tasks: bool | None = None,
) -> Request:
"""Request a list of web application targets.
Args:
filter_string: Filter term to use for the query.
filter_id: UUID of an existing filter to use for the query.
trash: Whether to include targets in the trashcan.
tasks: Whether to include list of tasks that use the target.
"""
cmd = XmlCommand("get_web_application_targets")
cmd.add_filter(filter_string, filter_id)
if trash is not None:
cmd.set_attribute("trash", to_bool(trash))
if tasks is not None:
cmd.set_attribute("tasks", to_bool(tasks))
return cmd