The create_override API throws exception when non-default port provided

GVM versions

gsad: (‘gsad --version’): Greenbone Security Assistant 21.4.3
gvmd: (‘gvmd --version’): Greenbone Vulnerability Manager 21.4.5
openvas-scanner: (‘openvas --version’, in older GVM versions < 11: ‘openvassd --version’): OpenVAS 21.4.4

gvm-libs:: gvm-libs 21.4.4

Environment

Operating system:: Ubuntu 18.04 server
Kernel: (‘uname -a’): Linux nsentinel-100144 4.15.0-128-generic #131-Ubuntu SMP Wed Dec 9 06:57:35 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
Installation method / source:. Downloaded from GitHub and built by hand using online guides

I’m trying to create an override programmatically using the API. As you can see from the code snippet below, it fails when I specify the optional “port” argument as an int. But it succeeds if I use the default value for port. Is this a bug? Not sure how to debug this any further… Any help resolving this would be much appreciated.

>>> scanner.gmp.create_override('test override 1', nvt_oid='1.3.6.1.4.1.25623.1.0.113736', hosts=['127.0.0.1'], port=22, new_severity='-1.0', task_id=task_id)
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
>   File "/usr/local/lib/python3.8/dist-packages/gvm/protocols/gmpv214/gmpv214.py", line 227, in create_override
>     return self._send_xml_command(cmd)
>   File "/usr/local/lib/python3.8/dist-packages/gvm/protocols/base.py", line 86, in _send_xml_command
>     return self.send_command(xmlcmd.to_string())
>   File "/usr/local/lib/python3.8/dist-packages/gvm/protocols/base.py", line 142, in send_command
>     return self._transform(response)
>   File "/usr/local/lib/python3.8/dist-packages/gvm/protocols/base.py", line 78, in _transform
>     return transform(data)
>   File "/usr/local/lib/python3.8/dist-packages/gvm/transforms.py", line 81, in __call__
>     _check_command_status(root)
>   File "/usr/local/lib/python3.8/dist-packages/gvm/transforms.py", line 49, in _check_command_status
>     raise GvmResponseError(status=status, message=root.get("status_text"))
> gvm.errors.GvmResponseError: Response Error 400. Error in port specification

>>> scanner.gmp.create_override('test override 1', nvt_oid='1.3.6.1.4.1.25623.1.0.113736', hosts=['127.0.0.1'], port=None, new_severity='-1.0', task_id=task_id)
> <Element create_override_response at 0x7f0adfd01080>
1 Like

Actually the description of the Python API is not correct. The problem here is, that you can not specify a port by an integer. You actually need to use the following “syntax” for port-specification to work:
port="123/tcp" or port="1234/udp" - actually you can type anything like <number>/<number/string>

In case of the gvm-pyshell:

res = gmp.create_override(text="moh", nvt_oid="1.3.6.1.4.1.25623.1.0.65564", new_severity="1", port="1/tcp")

We will update the description and checks in the python-gvm API asap! Thank you for finding this issue!

2 Likes

Fixed with PR #755 in release 22.6.0.

1 Like