Creating a target with Gmp (python) and adding SSH Credentials

Hi,

I’m having trouble understanding the argument to pass into gmp.create_target() that will add the ssh credentials for creating a target. I’ve tried ssh and ssh_credential. According to the documentation, it should be ssh_credential (I think) and I’m unable to dir or help within gvm-pyshell. Here is my code:

def create_target(gmp, ipaddress, ssh_credential, port_list_id):
    name = "Target {}".format(ipaddress)
    response = gmp.create_target(
        name=name,
        hosts=[ipaddress],
        ssh_credential=ssh_credential,
        port_list_id=port_list_id)
    return response.get('id')

Command

  • <name>

A name for the target.

  • <comment> ?

A comment on the target.

  • <copy> ?

The UUID of an existing target.

  • One of
    • <asset_hosts>

Hosts from which to create the target.

* @**filter** (text) Filter term that defines the list of hosts.
  • <hosts>

A comma-separated list of hosts, which may be empty.

  • <exclude_hosts> ?

A list of hosts to exclude.

  • <ssh_credential> ?

SSH login credentials for target.

  • @id (uuid)
  • <port> ?

The port the LSCs will use.

  • <ssh_elevate_credential> ?

SSH elevate credentials for target.

Never mind - I figured it out. I used ssh_credential_id instead. I guess I’m confused at the documentation :confused:

When using the Python API you should better look at python-gvm: Python API for the Greenbone Vulnerability Manager — python-gvm 21.11.1.dev1 documentation instead of the protocol doc. The API has a better documentation. See GMP v21.4 — python-gvm 21.11.1.dev1 documentation for the create_target doc.

2 Likes

Awesome links - Thank you!

So, the docs are not there anymore (404 error). I have similar problem: don`t know how to run an authenticated scan from cli (gvm-python).

The docs just moved to another place https://greenbone.github.io/python-gvm/

2 Likes