Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
187 changes: 187 additions & 0 deletions gvm/protocols/gmp/_gmpnext.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
AgentInstallerInstructionLanguageType,
AgentInstallerInstructions,
Agents,
AliveTest,
Credentials,
CredentialStoreCredentialType,
CredentialStores,
Expand All @@ -29,9 +30,11 @@
ReportPorts,
ReportTlsCertificates,
ReportVulnerabilities,
Targets,
Tasks,
WebApplicationTargets,
)
from .requests.v224 import AliveTest as AliveTestV224
from .requests.v224 import HostsOrdering


Expand Down Expand Up @@ -1382,3 +1385,187 @@ def get_web_application_targets(
tasks=tasks,
)
)

def create_target(
self,
name: str,
*,
asset_hosts_filter: str | None = None,
hosts: list[str] | None = None,
comment: str | None = None,
exclude_hosts: list[str] | None = None,
ssh_credential_id: EntityID | None = None,
ssh_credential_port: int | str | None = None,
smb_credential_id: EntityID | None = None,
esxi_credential_id: EntityID | None = None,
snmp_credential_id: EntityID | None = None,
alive_test: str | AliveTest | AliveTestV224 | None = None,
allow_simultaneous_ips: bool | None = None,
reverse_lookup_only: bool | None = None,
reverse_lookup_unify: bool | None = None,
port_range: str | None = None,
port_list_id: EntityID | None = None,
) -> T:
"""Create a new target

Args:
name: Name of the target
asset_hosts_filter: Filter to select target host from assets hosts
hosts: List of hosts addresses to scan
exclude_hosts: List of hosts addresses to exclude from scan
comment: Comment for the target
ssh_credential_id: UUID of a ssh credential to use on target
ssh_credential_port: The port to use for ssh credential
smb_credential_id: UUID of a smb credential to use on target
snmp_credential_id: UUID of a snmp credential to use on target
esxi_credential_id: UUID of a esxi credential to use on target
alive_test: Which alive test to use
allow_simultaneous_ips: Whether to scan multiple IPs of the
same host simultaneously
reverse_lookup_only: Whether to scan only hosts that have names
reverse_lookup_unify: Whether to scan only one IP when multiple IPs
have the same name.
port_range: Port range for the target
port_list_id: UUID of the port list to use on target
"""
return self._send_request_and_transform_response(
Targets.create_target(
name,
asset_hosts_filter=asset_hosts_filter,
hosts=hosts,
comment=comment,
exclude_hosts=exclude_hosts,
ssh_credential_id=ssh_credential_id,
ssh_credential_port=ssh_credential_port,
smb_credential_id=smb_credential_id,
esxi_credential_id=esxi_credential_id,
snmp_credential_id=snmp_credential_id,
alive_test=alive_test,
allow_simultaneous_ips=allow_simultaneous_ips,
reverse_lookup_only=reverse_lookup_only,
reverse_lookup_unify=reverse_lookup_unify,
port_range=port_range,
port_list_id=port_list_id,
)
)

def modify_target(
self,
target_id: EntityID,
*,
name: str | None = None,
comment: str | None = None,
hosts: list[str] | None = None,
exclude_hosts: list[str] | None = None,
ssh_credential_id: EntityID | None = None,
ssh_credential_port: str | int | None = None,
smb_credential_id: EntityID | None = None,
esxi_credential_id: EntityID | None = None,
snmp_credential_id: EntityID | None = None,
alive_test: str | AliveTest | AliveTestV224 | None = None,
allow_simultaneous_ips: bool | None = None,
reverse_lookup_only: bool | None = None,
reverse_lookup_unify: bool | None = None,
port_list_id: EntityID | None = None,
) -> T:
"""Modify an existing target.

Args:
target_id: UUID of target to modify.
comment: Comment on target.
name: Name of target.
hosts: List of target hosts.
exclude_hosts: A list of hosts to exclude.
ssh_credential_id: UUID of SSH credential to use on target.
ssh_credential_port: The port to use for ssh credential
smb_credential_id: UUID of SMB credential to use on target.
esxi_credential_id: UUID of ESXi credential to use on target.
snmp_credential_id: UUID of SNMP credential to use on target.
port_list_id: UUID of port list describing ports to scan.
alive_test: Which alive tests to use.
allow_simultaneous_ips: Whether to scan multiple IPs of the
same host simultaneously
reverse_lookup_only: Whether to scan only hosts that have names.
reverse_lookup_unify: Whether to scan only one IP when multiple IPs
have the same name.
"""
return self._send_request_and_transform_response(
Targets.modify_target(
target_id,
name=name,
comment=comment,
hosts=hosts,
exclude_hosts=exclude_hosts,
ssh_credential_id=ssh_credential_id,
ssh_credential_port=ssh_credential_port,
smb_credential_id=smb_credential_id,
esxi_credential_id=esxi_credential_id,
snmp_credential_id=snmp_credential_id,
alive_test=alive_test,
allow_simultaneous_ips=allow_simultaneous_ips,
reverse_lookup_only=reverse_lookup_only,
reverse_lookup_unify=reverse_lookup_unify,
port_list_id=port_list_id,
)
)

def clone_target(self, target_id: EntityID) -> T:
"""Clone an existing target.

Args:
target_id: UUID of an existing target to clone.
"""
return self._send_request_and_transform_response(
Targets.clone_target(target_id)
)

def delete_target(
self, target_id: EntityID, *, ultimate: bool | None = False
) -> T:
"""Delete an existing target.

Args:
target_id: UUID of an existing target to delete.
ultimate: Whether to remove entirely or to the trashcan.
"""
return self._send_request_and_transform_response(
Targets.delete_target(target_id, ultimate=ultimate)
)

def get_target(
self, target_id: EntityID, *, tasks: bool | None = None
) -> T:
"""Request a single target.

Args:
target_id: UUID of the target to request.
tasks: Whether to include list of tasks that use the target
"""
return self._send_request_and_transform_response(
Targets.get_target(target_id, tasks=tasks)
)

def get_targets(
self,
*,
filter_string: str | None = None,
filter_id: EntityID | None = None,
trash: bool | None = None,
tasks: bool | None = None,
) -> T:
"""Request a list of 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.
"""
return self._send_request_and_transform_response(
Targets.get_targets(
filter_string=filter_string,
filter_id=filter_id,
trash=trash,
tasks=tasks,
)
)
3 changes: 1 addition & 2 deletions gvm/protocols/gmp/requests/next/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
from gvm.protocols.gmp.requests.next._report_vulnerabilities import (
ReportVulnerabilities,
)
from gvm.protocols.gmp.requests.next._targets import AliveTest, Targets
from gvm.protocols.gmp.requests.next._tasks import Tasks
from gvm.protocols.gmp.requests.next._web_application_targets import (
WebApplicationTargets,
Expand All @@ -58,7 +59,6 @@
AlertEvent,
AlertMethod,
Alerts,
AliveTest,
AuditReports,
Audits,
Authentication,
Expand Down Expand Up @@ -108,7 +108,6 @@
SortOrder,
SystemReports,
Tags,
Targets,
Tickets,
TicketStatus,
TLSCertificates,
Expand Down
Loading
Loading