greenbone / python-gvm

Greenbone Vulnerability Management Python Library
https://greenbone.github.io/python-gvm/
GNU General Public License v3.0
106 stars 60 forks source link

[gvm.connections.TLSConnection] ConnectionRefusedError: [Errno 111] Connection refused #554

Closed v1c5anchez closed 3 years ago

v1c5anchez commented 3 years ago

Description

Hello everybody,

I am currently using a dockerized version of GVM. gvmd is running in the container.

I am trying to connect to gvmd using python-gvm via a TLSConnection object with the following script:

demo.py

from gvm.connections import DebugConnection, TLSConnection
from gvm.protocols.gmp import Gmp
from gvm.transforms import EtreeTransform
from gvm.xml import pretty_print

tls_connection = TLSConnection()
connection = DebugConnection(tls_connection)
transform = EtreeTransform()

with Gmp(connection, transform=transform) as gmp:
    version = gmp.get_version()
    pretty_print(version)

Given that TLSConnection object is using the following default parameters:

class gvm.connections.TLSConnection(*, certfile=None, cafile=None, keyfile=None, hostname='127.0.0.1', port=9390, password=None, timeout=60)

The command I am using to run the container is:

docker run --detach --publish 8080:9390 (.......) --name <CONTAINER_NAME> <IMAGE_NAME>

Expected behavior

I should get the version:

# python3 demo.py
<get_version_response status="200" status_text="OK">
  <version>21.4</version>
</get_version_response>

Current behavior

Instead, I get an error:

# python3 demo.py
Traceback (most recent call last):
  File "/root/res/demo.py", line 19, in <module>
    with Gmp(connection, transform=transform) as gmp:
  File "/root/res/env/lib/python3.9/site-packages/gvm/protocols/gmp.py", line 113, in __enter__
    gmp = self.determine_supported_gmp()
  File "/root/res/env/lib/python3.9/site-packages/gvm/protocols/gmp.py", line 98, in determine_supported_gmp
    version = self.determine_remote_gmp_version()
  File "/root/res/env/lib/python3.9/site-packages/gvm/protocols/gmp.py", line 81, in determine_remote_gmp_version
    self.connect()
  File "/root/res/env/lib/python3.9/site-packages/gvm/protocols/base.py", line 107, in connect
    self._connection.connect()
  File "/root/res/env/lib/python3.9/site-packages/gvm/connections.py", line 557, in connect
    return self._connection.connect()
  File "/root/res/env/lib/python3.9/site-packages/gvm/connections.py", line 467, in connect
    self._socket.connect((self.hostname, int(self.port)))
  File "/usr/lib/python3.9/ssl.py", line 1342, in connect
    self._real_connect(addr, False)
  File "/usr/lib/python3.9/ssl.py", line 1329, in _real_connect
    super().connect(addr)
ConnectionRefusedError: [Errno 111] Connection refused

Steps to reproduce

  1. Activate the python virtual environment (with python-gvm)
  2. python3 demo.py
Traceback (most recent call last):
  File "/root/res/demo.py", line 19, in <module>
    with Gmp(connection, transform=transform) as gmp:
  File "/root/res/env/lib/python3.9/site-packages/gvm/protocols/gmp.py", line 113, in __enter__
    gmp = self.determine_supported_gmp()
  File "/root/res/env/lib/python3.9/site-packages/gvm/protocols/gmp.py", line 98, in determine_supported_gmp
    version = self.determine_remote_gmp_version()
  File "/root/res/env/lib/python3.9/site-packages/gvm/protocols/gmp.py", line 81, in determine_remote_gmp_version
    self.connect()
  File "/root/res/env/lib/python3.9/site-packages/gvm/protocols/base.py", line 107, in connect
    self._connection.connect()
  File "/root/res/env/lib/python3.9/site-packages/gvm/connections.py", line 557, in connect
    return self._connection.connect()
  File "/root/res/env/lib/python3.9/site-packages/gvm/connections.py", line 467, in connect
    self._socket.connect((self.hostname, int(self.port)))
  File "/usr/lib/python3.9/ssl.py", line 1342, in connect
    self._real_connect(addr, False)
  File "/usr/lib/python3.9/ssl.py", line 1329, in _real_connect
    super().connect(addr)
ConnectionRefusedError: [Errno 111] Connection refused

GVM versions

gsa: Greenbone Security Assistant 21.4.2

gvm: Greenbone Vulnerability Manager 21.4.3

openvas-scanner: ?

gvm-libs: ?

gvm-tools: ?

Environment

Operating system: Arch Linux 5.12.12-arch1-1 x86_64 GNU/Linux

Installation method / source: Docker

bjoernricks commented 3 years ago

--publish 8080:9390 indicates that you are trying to map the web interface port to the local port. This wont work. GMP is not a HTTP based protocol. You need to change the gvmd service to provide access via GMP over TLS.