Create targets from CLI

Hello,

I am trying to experiment a bit with the tools provided in your GitHub https://github.com/greenbone/gvm-tools/tree/main/scripts. I wanted to try out the create-targets-from-host-list.gmp.py but I get an error that says gvm.errors.GvmResponseError: Response Error 400. One of PORT_LIST and PORT_RANGE are required, even though the documentation says, that there is just an IP of the GVM host name and a text-file containing hostnames needed. Can someone please tell me where I’m wrong or if I’m wrong?

Thanks ins advance

I figured out, that the source code didn’t provide a port_list_id in the create_target function, so I just added it and it worked :slight_smile:

1 Like

Hi, We are facing this same problem. Could you show me what you added in the create-targets-from-host-list.gmp.py to specify the port_list_id ?

Thanks this was helpful. FYI for anyone else using this. You have to get the port_list_id UID from the web console (we got ours from doing an export) and then put in the code block where Don specified.

Kinda stinks that you have to modify the script from git, but hey - it works!

1 Like

@rootbeard42 please share the working script, so it can be fixed reused by others…

Eero

I will update the mentioned script!

1 Like

I have fixed the script.

After merging can add a port_range (will result in creating a new port_list with that range) or a port_list_id (by giving a UUID) to the script.

The default behavior of the script has not been changed

 gvm-script --gmp-username xyz --gmp-password abc ssh --hostname <host> scripts/create-targets-from-host-list.gmp.py <host> <file>

will default to create targets with the standard port_list_id of All IANA assigned TCP and UDP ("4a4717fe-57d2-11e1-9a26-406186ea4fc5")

You can use +pl/++port_list_id to add your own ID or +pr/++port_range to create a new port list (T: 1-1234 or U: 3-4, …) See documentation.

If you have any further problem, please let me know.

3 Likes

I am playing with gvm-cli and am wrestling with how to describe a scan. Since the change from version 9 to version 21 (my example is using version 22.4) , there was a change in that defining a scan necessitated defining/declaring what ports to declare.
Example:

gvm@d5af8536329d:/gvm-tools$ gvm-cli --gmp-username XXXXX --gmp-password XXXXX socket --xml "\
<create_target> \
<name>Gigs Network2</name> \
<hosts>172.16.48.0/24</hosts> \
</create_target>"

and output

ERROR:gvmtools.cli:Response Error 400. One of PORT_LIST and PORT_RANGE are required

I tried to reference the defined scan All IANA assigned TCP and UDP <port_list_id=“4a4717fe-57d2-11e1-9a26-406186ea4fc5"> but I don’t completely understand the proper syntax in making this match.

gvm@d5af8536329d:/gvm-tools$ gvm-cli --gmp-username XXXXX --gmp-password XXXXX socket --xml "\
<create_target> \
<name>Gigs Network2</name> \
<hosts>172.16.48.0/24</hosts> \
<port_list_id=\"4a4717fe-57d2-11e1-9a26-406186ea4fc5\"/> \
</create_target>"

Returns a

Invalid XML error message.

Please advise on the proper syntax on specifying a port list.

Replying to myself. Answer is the following:

Replace

<port_list_id=\"4a4717fe-57d2-11e1-9a26-406186ea4fc5\"/> \

with

<port_list id=\"4a4717fe-57d2-11e1-9a26-406186ea4fc5\"/> \

(Remove the second underscore between list and id).

1 Like