greenbone / ospd-openvas

ospd-openvas is an OSP server implementation to allow GVM to remotely control an OpenVAS Scanner
GNU Affero General Public License v3.0
67 stars 58 forks source link

failure when starting a remote scan, KeyError: 'end_time' #361

Closed Akrugerus closed 3 years ago

Akrugerus commented 3 years ago

I'm attempting to set up a distributed scan environment with gvmd and gsa running on a central system and ospd-openvas instances spread around to execute the tasks and send them back to the central system. I found a super convenient docker implementation of this environment that handles the setup and connection of these instance here https://github.com/Secure-Compliance-Solutions-LLC/GVM-Docker. I'm able to get both an instance of the gvm controller and an instance of the ospd-openvas scanner running and connected. My problem comes when I try to initiate my first remote scan. When I queue the scan to start, it is sent to the remote scanner and immediately prints out the stack error pasted below in openvas.log.

OSPD[50] 2020-12-10 16:49:28,867: INFO: (ospd.command.command) Scan 37dda0d5-cb26-4f33-a238-88216a587923 added to the queue in position 1.

Traceback (most recent call last): File "/usr/local/bin/ospd-openvas", line 11, in load_entry_point('ospd-openvas==20.8.0', 'console_scripts', 'ospd-openvas')() File "/usr/local/lib/python3.8/dist-packages/ospd_openvas-20.8.0-py3.8.egg/ospd_openvas/daemon.py", line 1383, in main File "/usr/local/lib/python3.8/dist-packages/ospd-20.8.1-py3.8.egg/ospd/main.py", line 160, in main File "/usr/local/lib/python3.8/dist-packages/ospd-20.8.1-py3.8.egg/ospd/ospd.py", line 1255, in run File "/usr/local/lib/python3.8/dist-packages/ospd-20.8.1-py3.8.egg/ospd/ospd.py", line 1398, in clean_forgotten_scans File "/usr/local/lib/python3.8/dist-packages/ospd-20.8.1-py3.8.egg/ospd/ospd.py", line 1487, in get_scan_end_time File "/usr/local/lib/python3.8/dist-packages/ospd-20.8.1-py3.8.egg/ospd/scan.py", line 424, in get_end_time File "", line 2, in getitem File "/usr/lib/python3.8/multiprocessing/managers.py", line 850, in _callmethod raise convert_to_error(kind, result) KeyError: 'end_time' Error in atexit._run_exitfuncs: Traceback (most recent call last): File "/usr/lib/python3.8/multiprocessing/managers.py", line 827, in _callmethod conn = self._tls.connection AttributeError: 'ForkAwareLocal' object has no attribute 'connection'

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/usr/local/lib/python3.8/dist-packages/ospd-20.8.1-py3.8.egg/ospd/main.py", line 81, in exit_cleanup File "/usr/local/lib/python3.8/dist-packages/ospd-20.8.1-py3.8.egg/ospd/ospd.py", line 438, in daemon_exit_cleanup File "/usr/local/lib/python3.8/dist-packages/ospd-20.8.1-py3.8.egg/ospd/scan.py", line 242, in clean_up_pickled_scan_info File "/usr/local/lib/python3.8/dist-packages/ospd-20.8.1-py3.8.egg/ospd/scan.py", line 340, in get_status File "", line 2, in get File "/usr/lib/python3.8/multiprocessing/managers.py", line 831, in _callmethod self._connect() File "/usr/lib/python3.8/multiprocessing/managers.py", line 818, in _connect conn = self._Client(self._token.address, authkey=self._authkey) File "/usr/lib/python3.8/multiprocessing/connection.py", line 502, in Client c = SocketClient(address) File "/usr/lib/python3.8/multiprocessing/connection.py", line 629, in SocketClient s.connect(address) FileNotFoundError: [Errno 2] No such file or directory connect to /data/ospd.sock port -2 failed: Connection refused connect to /data/ospd.sock port -2 failed: Connection refused

I'm unsure if the docker environment I'm using could be causing this, but it seems to just be an error when starting a remotely initiated scan. Any help would be appreciated.

ktosiek commented 3 years ago

This is a bug in ospd - it creates a scan with no 'end_time' (https://github.com/greenbone/ospd/blob/532169f28f65051eb0afa64dd4bf8eef6057c09f/ospd/scan.py#L282), and then assumes 'end_time' is always available (https://github.com/greenbone/ospd/blob/532169f28f65051eb0afa64dd4bf8eef6057c09f/ospd/scan.py#L421). I'm not sure if there's a good workaround for this.

jjnicola commented 3 years ago

Hello @Akrugerus Thanks for reporting the bug. I was able to reproduce it, setting the config option scaninfo_store_time, so I assume this is your case. PR greenbone/ospd#354 fix this issue