python-gvm 27.10.0__py3-none-any.whl → 27.11.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
gvm/__version__.py CHANGED
@@ -2,4 +2,4 @@
2
2
 
3
3
  # THIS IS AN AUTOGENERATED FILE. DO NOT TOUCH!
4
4
 
5
- __version__ = "27.10.0"
5
+ __version__ = "27.11.0"
@@ -4,6 +4,7 @@
4
4
 
5
5
  import logging
6
6
  import socket as socketlib
7
+ import ssl
7
8
  from abc import ABC, abstractmethod
8
9
  from time import time
9
10
  from typing import Protocol, runtime_checkable
@@ -16,6 +17,14 @@ DEFAULT_TIMEOUT = 60 # in seconds
16
17
 
17
18
  logger = logging.getLogger(__name__)
18
19
 
20
+ # Errors raised by a socket if the remote server has closed the connection.
21
+ # The SSL errors are raised by TLS sockets and aren't ConnectionErrors.
22
+ REMOTE_CLOSED_ERRORS = (
23
+ ConnectionError,
24
+ ssl.SSLEOFError,
25
+ ssl.SSLZeroReturnError,
26
+ )
27
+
19
28
 
20
29
  @runtime_checkable
21
30
  class GvmConnection(Protocol):
@@ -82,11 +91,22 @@ class AbstractGvmConnection(ABC):
82
91
 
83
92
  Args:
84
93
  data: Data to be send to the server as bytes.
94
+
95
+ Raises:
96
+ GvmError: If the socket is not connected or the remote server
97
+ has closed the connection. In the latter case the connection
98
+ needs to be re-established via :py:meth:`connect`.
85
99
  """
86
100
  if self._socket is None:
87
101
  raise GvmError("Socket is not connected")
88
102
 
89
- self._socket.sendall(data)
103
+ try:
104
+ self._socket.sendall(data)
105
+ except REMOTE_CLOSED_ERRORS as e:
106
+ # Connection was closed by server, e.g. after an error response
107
+ raise GvmError(
108
+ f"Remote closed the connection. Error was {e}"
109
+ ) from e
90
110
 
91
111
  def read(self) -> bytes:
92
112
  """Read data from the remote server
@@ -98,7 +118,13 @@ class AbstractGvmConnection(ABC):
98
118
  time() + self._timeout if self._timeout is not None else None
99
119
  )
100
120
 
101
- data = self._read()
121
+ try:
122
+ data = self._read()
123
+ except REMOTE_CLOSED_ERRORS as e:
124
+ # Connection was reset by server
125
+ raise GvmError(
126
+ f"Remote closed the connection. Error was {e}"
127
+ ) from e
102
128
 
103
129
  if not data:
104
130
  # Connection was closed by server
@@ -3925,14 +3925,13 @@ class GMPv224(GvmProtocol[T]):
3925
3925
  )
3926
3926
  )
3927
3927
 
3928
- def move_task(
3929
- self, task_id: EntityID, *, slave_id: EntityID | None = None
3930
- ) -> T:
3928
+ def move_task(self, task_id: EntityID, *, slave_id: EntityID = "") -> T:
3931
3929
  """Move an existing task to another GMP slave scanner or the master
3932
3930
 
3933
3931
  Args:
3934
3932
  task_id: UUID of the task to be moved
3935
- slave_id: UUID of the sensor to reassign the task to, empty for master.
3933
+ slave_id: UUID of the sensor to reassign the task to. Defaults to
3934
+ an empty string, which selects the master.
3936
3935
  """
3937
3936
  return self._send_request_and_transform_response(
3938
3937
  Tasks.move_task(task_id, slave_id=slave_id)
@@ -11,6 +11,10 @@ from ...utils import SupportsStr
11
11
  from .._protocol import T
12
12
  from ._gmp227 import GMPv227
13
13
  from .requests.next import (
14
+ ActiveDirectory,
15
+ ActiveDirectoryObjectType,
16
+ ActiveDirectorySearchScope,
17
+ ActiveDirectoryTlsMode,
14
18
  AgentGroups,
15
19
  AgentInstallerInstructionLanguageType,
16
20
  AgentInstallerInstructions,
@@ -35,6 +39,7 @@ from .requests.next import (
35
39
  ReportVulnerabilities,
36
40
  ScanReports,
37
41
  Targets,
42
+ TargetSource,
38
43
  Tasks,
39
44
  Timezones,
40
45
  WebApplicationTargets,
@@ -128,6 +133,9 @@ class GMPNext(GMPv227[T]):
128
133
  authorized: Whether the agent is authorized.
129
134
  update_to_latest: Whether the agent is allowed to update to latest automatically.
130
135
  config: Nested config for Agent Controller.
136
+ Optional file_search.excluded_paths contains a sequence of
137
+ path strings. Use an empty sequence to clear excluded paths.
138
+ Paths are sent as provided.
131
139
  comment: Optional comment for the change.
132
140
  """
133
141
  return self._send_request_and_transform_response(
@@ -161,6 +169,9 @@ class GMPNext(GMPv227[T]):
161
169
  Args:
162
170
  agent_control_id: The agent control UUID.
163
171
  config: Nested config for Agent Controller.
172
+ Optional agent_defaults.file_search.excluded_paths contains
173
+ a sequence of path strings. Use an empty sequence to clear
174
+ excluded paths. Paths are sent as provided.
164
175
  """
165
176
  return self._send_request_and_transform_response(
166
177
  Agents.modify_agent_control_scan_config(
@@ -218,6 +229,7 @@ class GMPNext(GMPv227[T]):
218
229
  agent_ids: list[str],
219
230
  scheduler_cron_time: str,
220
231
  *,
232
+ max_delay_seconds: int | None = None,
221
233
  comment: str | None = None,
222
234
  ) -> T:
223
235
  """Create a new agent group.
@@ -226,6 +238,7 @@ class GMPNext(GMPv227[T]):
226
238
  name: Name of the new agent group.
227
239
  agent_ids: List of agent UUIDs to include in the group (required).
228
240
  scheduler_cron_time: Scheduler cron to use.
241
+ max_delay_seconds: Max delay seconds to use.
229
242
  comment: Optional comment for the group.
230
243
 
231
244
  Raises:
@@ -237,6 +250,7 @@ class GMPNext(GMPv227[T]):
237
250
  comment=comment,
238
251
  agent_ids=agent_ids,
239
252
  scheduler_cron_time=scheduler_cron_time,
253
+ max_delay_seconds=max_delay_seconds,
240
254
  )
241
255
  )
242
256
 
@@ -248,6 +262,7 @@ class GMPNext(GMPv227[T]):
248
262
  name: str | None = None,
249
263
  comment: str | None = None,
250
264
  agent_ids: list[str] | None = None,
265
+ max_delay_seconds: int | None = None,
251
266
  ) -> T:
252
267
  """Modify an existing agent group.
253
268
 
@@ -257,6 +272,7 @@ class GMPNext(GMPv227[T]):
257
272
  scheduler_cron_time: Scheduler cron to use.
258
273
  comment: Optional comment for the group.
259
274
  agent_ids: Optional list of agent UUIDs to set for the group.
275
+ max_delay_seconds: Optional maximum delay for agent groups.
260
276
 
261
277
  Raises:
262
278
  RequiredArgument: If agent_group_id is not provided.
@@ -268,6 +284,7 @@ class GMPNext(GMPv227[T]):
268
284
  comment=comment,
269
285
  agent_ids=agent_ids,
270
286
  scheduler_cron_time=scheduler_cron_time,
287
+ max_delay_seconds=max_delay_seconds,
271
288
  )
272
289
  )
273
290
 
@@ -317,6 +334,7 @@ class GMPNext(GMPv227[T]):
317
334
  agent_id: EntityID,
318
335
  days: int = 0,
319
336
  encryption: bool = True,
337
+ anonymized: bool = False,
320
338
  ) -> T:
321
339
  """Request a support bundle for an agent.
322
340
 
@@ -325,6 +343,7 @@ class GMPNext(GMPv227[T]):
325
343
  days: Number of days of logs to include. If None, zero is sent so the
326
344
  Agent Controller uses its configured default.
327
345
  encryption: Whether an encrypted or plain support bundle is requested.
346
+ anonymized: Whether an anonymized support bundle is requested.
328
347
 
329
348
  Raises:
330
349
  RequiredArgument: If agent_id is missing.
@@ -335,6 +354,212 @@ class GMPNext(GMPv227[T]):
335
354
  agent_id,
336
355
  days=days,
337
356
  encryption=encryption,
357
+ anonymized=anonymized,
358
+ )
359
+ )
360
+
361
+ def get_agent_inventory_token(self) -> T:
362
+ """Request a short-lived agent inventory token.
363
+
364
+ The token is used to authenticate requests to the agent-control API
365
+ using Authorization: Bearer <token>.
366
+
367
+ The authenticated user must have the get_agents permission.
368
+ """
369
+ return self._send_request_and_transform_response(
370
+ Agents.get_agent_inventory_token()
371
+ )
372
+
373
+ def create_active_directory_credential(
374
+ self,
375
+ name: str,
376
+ *,
377
+ host: str,
378
+ bind_dn: str,
379
+ base_dn: str,
380
+ bind_password: str,
381
+ tls_mode: ActiveDirectoryTlsMode | str,
382
+ comment: str | None = None,
383
+ port: int | None = None,
384
+ ca_certificate: str | None = None,
385
+ ) -> T:
386
+ """Create an Active Directory credential.
387
+
388
+ Requires AD integration to be enabled in gvmd.
389
+
390
+ Args:
391
+ name: Name of the credential.
392
+ host: Active Directory server hostname or IP address.
393
+ bind_dn: Distinguished name used to bind to the directory.
394
+ base_dn: Base distinguished name for directory searches.
395
+ bind_password: Password used to bind to the directory.
396
+ tls_mode: TLS mode, either "ldaps" or "starttls".
397
+ comment: Optional comment for the credential.
398
+ port: Server port (1 to 65535). Omit to use the connector default.
399
+ ca_certificate: Optional CA certificate in PEM format.
400
+ """
401
+ return self._send_request_and_transform_response(
402
+ Credentials.create_active_directory_credential(
403
+ name=name,
404
+ host=host,
405
+ bind_dn=bind_dn,
406
+ base_dn=base_dn,
407
+ bind_password=bind_password,
408
+ tls_mode=tls_mode,
409
+ comment=comment,
410
+ port=port,
411
+ ca_certificate=ca_certificate,
412
+ )
413
+ )
414
+
415
+ def modify_active_directory_credential(
416
+ self,
417
+ credential_id: EntityID,
418
+ *,
419
+ name: str | None = None,
420
+ comment: str | None = None,
421
+ host: str | None = None,
422
+ bind_dn: str | None = None,
423
+ base_dn: str | None = None,
424
+ bind_password: str | None = None,
425
+ tls_mode: ActiveDirectoryTlsMode | str | None = None,
426
+ port: int | str | None = None,
427
+ ca_certificate: str | None = None,
428
+ ) -> T:
429
+ """Modify an Active Directory credential.
430
+
431
+ Requires AD integration to be enabled in gvmd. Fields set to None
432
+ are left unchanged.
433
+
434
+ Args:
435
+ credential_id: UUID of the credential to modify.
436
+ name: New name of the credential.
437
+ comment: New comment. An empty string clears the comment.
438
+ host: Active Directory server hostname or IP address.
439
+ bind_dn: Distinguished name used to bind to the directory.
440
+ base_dn: Base distinguished name for directory searches.
441
+ bind_password: Password used to bind to the directory.
442
+ tls_mode: TLS mode, either "ldaps" or "starttls".
443
+ port: Server port (1 to 65535), or an empty string to restore
444
+ the connector default. Nonempty strings are not accepted.
445
+ ca_certificate: CA certificate in PEM format. An empty string
446
+ clears the certificate.
447
+ """
448
+ return self._send_request_and_transform_response(
449
+ Credentials.modify_active_directory_credential(
450
+ credential_id=credential_id,
451
+ name=name,
452
+ comment=comment,
453
+ host=host,
454
+ bind_dn=bind_dn,
455
+ base_dn=base_dn,
456
+ bind_password=bind_password,
457
+ tls_mode=tls_mode,
458
+ port=port,
459
+ ca_certificate=ca_certificate,
460
+ )
461
+ )
462
+
463
+ def verify_active_directory_credential(
464
+ self,
465
+ *,
466
+ credential_id: EntityID | None = None,
467
+ host: str | None = None,
468
+ bind_dn: str | None = None,
469
+ bind_password: str | None = None,
470
+ base_dn: str | None = None,
471
+ tls_mode: ActiveDirectoryTlsMode | str | None = None,
472
+ port: int | None = None,
473
+ ca_certificate: str | None = None,
474
+ ) -> T:
475
+ """Verify a saved AD credential or supplied AD connection settings.
476
+
477
+ Requires AD integration to be enabled in gvmd. Provide either
478
+ credential_id alone or the required inline connection fields.
479
+
480
+ Args:
481
+ credential_id: UUID of a saved AD credential.
482
+ host: AD server hostname or IP address.
483
+ bind_dn: Distinguished name used to bind to the directory.
484
+ bind_password: Password used for the bind.
485
+ base_dn: Base distinguished name for directory searches.
486
+ tls_mode: TLS mode, either "ldaps" or "starttls".
487
+ port: Optional server port, from 1 to 65535.
488
+ ca_certificate: Optional CA certificate in PEM format.
489
+ """
490
+ return self._send_request_and_transform_response(
491
+ Credentials.verify_active_directory_credential(
492
+ credential_id=credential_id,
493
+ host=host,
494
+ bind_dn=bind_dn,
495
+ bind_password=bind_password,
496
+ base_dn=base_dn,
497
+ tls_mode=tls_mode,
498
+ port=port,
499
+ ca_certificate=ca_certificate,
500
+ )
501
+ )
502
+
503
+ def get_active_directory_objects(
504
+ self,
505
+ credential_id: EntityID,
506
+ *,
507
+ base_dn: str | None = None,
508
+ group_dn: str | None = None,
509
+ scope: ActiveDirectorySearchScope | str | None = None,
510
+ object_types: Sequence[ActiveDirectoryObjectType | str] | None = None,
511
+ max_results: int | None = None,
512
+ include_disabled_computers: bool | None = None,
513
+ targets: bool | None = None,
514
+ tasks: bool | None = None,
515
+ details: bool | None = None,
516
+ ) -> T:
517
+ """Search Active Directory using a saved AD credential.
518
+
519
+ Requires AD integration to be enabled in gvmd and a saved AD
520
+ credential. Options set to None are omitted from the request so that
521
+ gvmd applies its defaults.
522
+
523
+ The response includes per-type counts for the fetched subset and an
524
+ objects truncated attribute indicating whether more objects were
525
+ available.
526
+
527
+ Args:
528
+ credential_id: UUID of a saved AD credential.
529
+ base_dn: Nonempty search base within the credential's base DN.
530
+ Defaults to the credential's base DN.
531
+ group_dn: Nonempty DN selecting explicit direct group members
532
+ within the search base and scope. Must be within the
533
+ credential's base DN.
534
+ scope: Search scope, either "base", "onelevel", or "subtree".
535
+ Defaults to "onelevel", searching immediately below base_dn. Use
536
+ "subtree" to search at all directory depths.
537
+ object_types: Nonempty selection of "ou", "container", "computer",
538
+ or "group". Defaults to "ou", "computer", and "group".
539
+ Duplicates are ignored, preserving first-occurrence order.
540
+ max_results: Maximum number of objects to fetch after LDAP
541
+ filtering. Must be a positive integer within the server's
542
+ configured limit. Omit to use that limit.
543
+ include_disabled_computers: Include disabled computers. Defaults
544
+ to True.
545
+ targets: Include matching targets for computers. Defaults to False.
546
+ tasks: Include tasks and readable configurations for matching
547
+ targets. Requires targets=True. Defaults to False.
548
+ details: Include computer OS version and service principal names.
549
+ Defaults to False.
550
+ """
551
+ return self._send_request_and_transform_response(
552
+ ActiveDirectory.get_active_directory_objects(
553
+ credential_id=credential_id,
554
+ base_dn=base_dn,
555
+ group_dn=group_dn,
556
+ scope=scope,
557
+ object_types=object_types,
558
+ max_results=max_results,
559
+ include_disabled_computers=include_disabled_computers,
560
+ targets=targets,
561
+ tasks=tasks,
562
+ details=details,
338
563
  )
339
564
  )
340
565
 
@@ -957,14 +1182,13 @@ class GMPNext(GMPv227[T]):
957
1182
  )
958
1183
  )
959
1184
 
960
- def move_task(
961
- self, task_id: EntityID, *, slave_id: EntityID | None = None
962
- ) -> T:
1185
+ def move_task(self, task_id: EntityID, *, slave_id: EntityID = "") -> T:
963
1186
  """Move an existing task to another GMP slave scanner or the master
964
1187
 
965
1188
  Args:
966
1189
  task_id: UUID of the task to be moved
967
- slave_id: UUID of the sensor to reassign the task to, empty for master.
1190
+ slave_id: UUID of the sensor to reassign the task to. Defaults to
1191
+ an empty string, which selects the master.
968
1192
  """
969
1193
  return self._send_request_and_transform_response(
970
1194
  Tasks.move_task(
@@ -1504,6 +1728,7 @@ class GMPNext(GMPv227[T]):
1504
1728
  *,
1505
1729
  asset_hosts_filter: str | None = None,
1506
1730
  hosts: list[str] | None = None,
1731
+ source: TargetSource | str | None = None,
1507
1732
  comment: str | None = None,
1508
1733
  exclude_hosts: list[str] | None = None,
1509
1734
  ssh_credential_id: EntityID | None = None,
@@ -1524,6 +1749,7 @@ class GMPNext(GMPv227[T]):
1524
1749
  name: Name of the target
1525
1750
  asset_hosts_filter: Filter to select target host from assets hosts
1526
1751
  hosts: List of hosts addresses to scan
1752
+ source: Target source. Omit to default to manual.
1527
1753
  exclude_hosts: List of hosts addresses to exclude from scan
1528
1754
  comment: Comment for the target
1529
1755
  ssh_credential_id: UUID of a ssh credential to use on target
@@ -1545,6 +1771,7 @@ class GMPNext(GMPv227[T]):
1545
1771
  name,
1546
1772
  asset_hosts_filter=asset_hosts_filter,
1547
1773
  hosts=hosts,
1774
+ source=source,
1548
1775
  comment=comment,
1549
1776
  exclude_hosts=exclude_hosts,
1550
1777
  ssh_credential_id=ssh_credential_id,
@@ -1568,6 +1795,7 @@ class GMPNext(GMPv227[T]):
1568
1795
  name: str | None = None,
1569
1796
  comment: str | None = None,
1570
1797
  hosts: list[str] | None = None,
1798
+ source: TargetSource | str | None = None,
1571
1799
  exclude_hosts: list[str] | None = None,
1572
1800
  ssh_credential_id: EntityID | None = None,
1573
1801
  ssh_credential_port: str | int | None = None,
@@ -1587,6 +1815,7 @@ class GMPNext(GMPv227[T]):
1587
1815
  comment: Comment on target.
1588
1816
  name: Name of target.
1589
1817
  hosts: List of target hosts.
1818
+ source: Target source. Omit to keep the current source.
1590
1819
  exclude_hosts: A list of hosts to exclude.
1591
1820
  ssh_credential_id: UUID of SSH credential to use on target.
1592
1821
  ssh_credential_port: The port to use for ssh credential
@@ -1607,6 +1836,7 @@ class GMPNext(GMPv227[T]):
1607
1836
  name=name,
1608
1837
  comment=comment,
1609
1838
  hosts=hosts,
1839
+ source=source,
1610
1840
  exclude_hosts=exclude_hosts,
1611
1841
  ssh_credential_id=ssh_credential_id,
1612
1842
  ssh_credential_port=ssh_credential_port,
@@ -2,6 +2,11 @@
2
2
  #
3
3
  # SPDX-License-Identifier: GPL-3.0-or-later
4
4
 
5
+ from gvm.protocols.gmp.requests.next._active_directory import (
6
+ ActiveDirectory,
7
+ ActiveDirectoryObjectType,
8
+ ActiveDirectorySearchScope,
9
+ )
5
10
  from gvm.protocols.gmp.requests.next._agent_groups import AgentGroups
6
11
  from gvm.protocols.gmp.requests.next._agent_installer_instructions import (
7
12
  AgentInstallerInstructionLanguageType,
@@ -11,8 +16,10 @@ from gvm.protocols.gmp.requests.next._agents import Agents
11
16
  from gvm.protocols.gmp.requests.next._audit_report import AuditReport
12
17
  from gvm.protocols.gmp.requests.next._credential_stores import CredentialStores
13
18
  from gvm.protocols.gmp.requests.next._credentials import (
19
+ ActiveDirectoryTlsMode,
14
20
  Credentials,
15
21
  CredentialStoreCredentialType,
22
+ CredentialType,
16
23
  )
17
24
  from gvm.protocols.gmp.requests.next._features import (
18
25
  Features,
@@ -52,7 +59,11 @@ from gvm.protocols.gmp.requests.next._report_vulnerabilities import (
52
59
  ReportVulnerabilities,
53
60
  )
54
61
  from gvm.protocols.gmp.requests.next._scan_report import ScanReports
55
- from gvm.protocols.gmp.requests.next._targets import AliveTest, Targets
62
+ from gvm.protocols.gmp.requests.next._targets import (
63
+ AliveTest,
64
+ Targets,
65
+ TargetSource,
66
+ )
56
67
  from gvm.protocols.gmp.requests.next._tasks import Tasks
57
68
  from gvm.protocols.gmp.requests.next._timezones import (
58
69
  Timezones,
@@ -76,7 +87,6 @@ from ..v227 import (
76
87
  CertBundAdvisories,
77
88
  Cpes,
78
89
  CredentialFormat,
79
- CredentialType,
80
90
  Cves,
81
91
  DfnCertAdvisories,
82
92
  EntityType,
@@ -130,6 +140,10 @@ from ..v227 import (
130
140
  )
131
141
 
132
142
  __all__ = (
143
+ "ActiveDirectory",
144
+ "ActiveDirectoryObjectType",
145
+ "ActiveDirectorySearchScope",
146
+ "ActiveDirectoryTlsMode",
133
147
  "AgentGroups",
134
148
  "AgentInstallerInstructionLanguageType",
135
149
  "AgentInstallerInstructions",
@@ -210,6 +224,7 @@ __all__ = (
210
224
  "SystemReports",
211
225
  "TLSCertificates",
212
226
  "Tags",
227
+ "TargetSource",
213
228
  "Targets",
214
229
  "Tasks",
215
230
  "TicketStatus",