Python connection to Greenbone (GMP) on VMware fails with TLSConnection

I’m trying to connect to a Greenbone VM via Python using the gvm library (TLSConnection + Gmp) from another VM (VMware). Connection fails with a ConnectionRefusedError.

Environment:

  • Greenbone VM IP: 192.xxx.xxx.xxx

  • GMP port: 9390

  • Python 3.14 (Windows 11, running in PyCharm virtual environment)

  • gvm library installed in venv

Python code (main.py):

from gvm.connections import TLSConnection
from gvm.protocols.gmp import Gmp
import yaml

def load_config(path="config/config.yaml"):
    with open(path, "r") as f:
        return yaml.safe_load(f)

def main():
    cfg = load_config()
    gmp_cfg = cfg["gmp"]

    connection = TLSConnection(hostname=gmp_cfg["host"], port=gmp_cfg["port"])
    try:
        connection.connect()
        with Gmp(connection=connection) as gmp:
            gmp.authenticate(username=gmp_cfg["username"], password=gmp_cfg["password"])
            print("✅ Connected and authenticated!")
            tasks_xml = gmp.get_tasks(filter_string="rows=5")
    finally:
        connection.disconnect()

if __name__ == "__main__":
    main()

Config (config/config.yaml):

gmp:
  host: "192.xxx.xxx.xxx"
  port: 9390
  username: "xxx"
  password: "xxx"

Error message:

ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it
...
ValueError: No SSL wrapper around <ssl.SSLSocket ...>

What I’ve checked:

  • Greenbone VM is reachable via ping

  • GMP port 9390 is open

  • Both VMs are in the same network (VMware)

Question:
Why does TLSConnection.connect() fail with ConnectionRefusedError? Is there something wrong with TLS, firewall, or GMP configuration? Any guidance on connecting via Python would be appreciated.

Hi, did you setup gvmd to listening on the TLS socket at port 9390 and provided the certs for you client code? Additionally to should not call connect on the connection. It’s done internally in the Gmp class when using the context manager.

1 Like

Thanks for your answer!

Currently my gvmd is listening on 127.0.0.1:9390 (as shown with ss -tuln), so it’s the unencrypted GMP socket, not TLS. I haven’t set up any TLS certificates yet, and I also read that the Greenbone OS trial version doesn’t provide root access at all.

I usually access the system through the Support Shell to run commands, but without root privileges I can’t modify the gvmd configuration or enable a TLS listener.

That’s why I switched my Python code to use SocketConnection instead of TLSConnection, and I also removed the manual connection.connect() call as you suggested.

Now the connection and authentication work fine when I connect locally or through an SSH tunnel from my host machine.

That VM was and is never intended to be used in that way.

1 Like