GSM-Appliance Connection with python-gvm in the Network

Dear Greenbone-Community,

I have searched for the answer, but I was not able to retrieve the information how to use a GSM-Appliance with python-gvm.

What is the problem?
I have some expirience with GSM in the OpenSource edition and I was able to use the API with a connection established via UnixSocketConnection. When I try to use the Module SSHConnection or TLSConnection, our GSM Deca Appliance will respond with an error-message.

My try with TLSConnection:
Code:
from gvm.connections import SSHConnection, TLSConnection, UnixSocketConnection
from gvm.protocols.gmpv208 import Gmp

gmp_obj = TLSConnection(hostname=“10.10.20.150”)
with Gmp(connection=gmp_obj) as gmpReady_obj:
gmpReady_obj.authenticate(username=“webadmin”, password=“webadminpassword”)
print(gmpReady_obj.get_version())

Error:
TimeoutError: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed
to respond

My try with SSH:
Code:
from gvm.connections import SSHConnection, TLSConnection, UnixSocketConnection
from gvm.protocols.gmpv208 import Gmp

gmp_obj = SSHConnection(hostname=“10.10.20.150”, port=22, username=“admin”, password=“admin”)
with Gmp(connection=gmp_obj) as gmpReady_obj:
gmpReady_obj.authenticate(username=“webadmin”, password=“webadmin”)
print(gmpReady_obj.get_version())

Error:
File “C:\Users\User\AppData\Roaming\Python\Python38\site-packages\paramiko\channel.py”, line 801, in send
return self._send(s, m)
File “C:\Users\User\AppData\Roaming\Python\Python38\site-packages\paramiko\channel.py”, line 1198, in _send
raise socket.error(“Socket is closed”)
OSError: Socket is closed

(Error message shortened)

GMP is activated on the Deca-Appliance:
2021-03-10 15_41_36-Window

Deca-Version:
20.08.7

Python-gvm version:
Name: python-gvm
Version: 21.1.3

I would be happy if you could help me with this!

Best Regards,

Florian

Hi first of all maybe it is easier to write a gmp script then a full application. You should definitely take a look at our gvm-tools. Besides that just create an ssh connection instance without username, password and port. python-gvm uses the necessary defaults for a GSM. TLS is not possible. Since GOS 4 you need to use SSH. Please also don’t forget to activate the remote gmp access in the GOS admin menu.

3 Likes

Hi Bricks,

thank you for the answer!

Now the following Code is working:
image

Maybe it’s would be good to mention that you don’t need to authenticate at the GSM-Appliance in the SSHConnection-Documentation:
https://python-gvm.readthedocs.io/en/latest/api/connections.html?highlight=connections#module-gvm.connections

Or alternatively creating a new part in " Using the Greenbone Management Protocol" for python-gvm.
https://docs.greenbone.net/GSM-Manual/gos-20.08/en/gmp.html#using-the-greenbone-management-protocol

Thank you again for your help!

Best Regards,

Florian

1 Like