I have project: "Network device scanning system with detection of potential threats and email reporting". I need to use python and Openvas scanner to write a code for scanning given addresses for example. The finished solution should be encapsulated into a virtualisation container (e.g. Docker).
I was trying to use `Dockerfile`:
FROM python:3.9
RUN pip install python-gvm
RUN python -c "import gvm; print('SUCCESS')"
COPY main.py /app/main.py
CMD ["python", "/app/main.py"]
And my simple python code is:
from gvm.connections import UnixSocketConnection # Import UnixSocketConnection
def scan_with_openvas():
# Initialize UnixSocketConnection with the path to the OpenVAS UNIX socket
connection = UnixSocketConnection(path="/var/run/openvas/gvmd.sock")
# Initialize Gmp object with the UnixSocketConnection
with Gmp(connection=connection) as gmp:
# The rest of the code remains the same
gmp.authenticate()
targets = gmp.get_targets()
for target in targets:
print(target["name"])
new_target = gmp.create_target("TARGET_IP", name="My Target")
config = gmp.create_scan_config(name="Full and Fast", scanner="1")
scan = gmp.create_scan(target=new_target, config=config)
while not scan["status"] == "Done":
scan = gmp.get_scan(scan_id=scan["@id"])
results = gmp.get_results(scan_id=scan["@id"])
print("\n")
for result in results:
print(result)
if __name__ == "__main__":
scan_with_openvas()
However, the result showed:
gvm.errors.GvmError: Socket /var/run/openvas/gvmd.sock does not exist
I am asking for a lot of help with the idea of solving this problem. Alternative ways of solving it are also accepted.