The OpenVAS vulnerability scanner in python

The OpenVAS vulnerability scanner in python

The OpenVAS vulnerability scanner is a comprehensive vulnerability assessment system that can detect security issues in all manner of servers and network devices. It is a powerful tool that can be used to identify and remediate vulnerabilities before they can be exploited by attackers.

OpenVAS is a free and open-source tool, which means that it is available for anyone to use and modify. It is also a modular tool, which means that it can be customized to meet the specific needs of an organization.

OpenVAS uses a variety of techniques to scan for vulnerabilities, including:

Once OpenVAS has scanned a device, it will generate a report that lists the vulnerabilities that were found. The report will also include information about the severity of each vulnerability and how to remediate it.

OpenVAS is a powerful tool that can be used to improve the security of any organization’s network. It is a free and open-source tool, which makes it an attractive option for organizations of all sizes.

Here are some of the benefits of using OpenVAS:

If you are looking for a way to improve the security of your network, then you should consider using OpenVAS. It is a powerful tool that can help you to identify and remediate vulnerabilities before they can be exploited by attackers.

Installing the openVAS vulnerability scanner

OpenVAS (Open Vulnerability Assessment System) is a powerful open-source vulnerability scanner. The installation steps can vary slightly depending on the Linux distribution you are using. Below are general instructions for installing OpenVAS on Ubuntu, which is a widely used Linux distribution.

Install OpenVAS on Ubuntu:

  1. Update Package Lists:
Bash
   sudo apt-get update
  1. Install Required Packages:
Bash
   sudo apt-get install -y openvas
  1. Initialize OpenVAS:
Bash
sudo gvm-setup
sudo openvas-setup
sudo gvm-check-setup

Follow the prompts during the setup to configure OpenVAS. This process may take some time as it downloads and installs various components.

  1. Start OpenVAS:
Bash
   sudo systemctl start openvas-scanner
   sudo systemctl start openvas-manager
   sudo systemctl start openvas-gsa
  1. Enable OpenVAS Services to Start on Boot:
Bash
   sudo systemctl enable openvas-scanner
   sudo systemctl enable openvas-manager
   sudo systemctl enable openvas-gsa
  1. Access OpenVAS Web Interface:
    Open a web browser and go to https://localhost:4000 (or replace localhost with the IP address of your server). The default login credentials are:
  1. Update NVTs (Network Vulnerability Tests):
    After the initial setup, it’s essential to update the NVTs to ensure the scanner has the latest vulnerability information.
Bash
   sudo openvas-feed-update
   sudo openvas-nvt-sync
   sudo openvas-scapdata-sync
   sudo openvas-certdata-sync

Notes:

These instructions are tailored for Ubuntu. If you are using a different Linux distribution, the package manager and specific package names may vary. Always refer to the official documentation or community resources for your specific distribution for the most accurate information.

Accessing openVAS with python

GVM (Greenbone Vulnerability Management)

The provided Python script uses the gvm library to interact with the Greenbone Vulnerability Management (GVM) protocol. This script specifically connects to a GVM server, retrieves the GMP (Greenbone Management Protocol) version, and prints it.

Python
#!/usr/bin/env python3

import gvm
from gvm.protocols.latest import Gmp

# Establish a TLS connection to the GVM server
connection = gvm.connections.TLSConnection(hostname='localhost')

# Use the GMP protocol to interact with the GVM server
with Gmp(connection=connection) as gmp:
    # Get and print the GMP version
    version = gmp.get_version()
    print(version)

Explanation:

Shebang and Imports:

TLS Connection to GVM Server:

Python
   connection = gvm.connections.TLSConnection(hostname='localhost')

Using GMP Protocol:

Python
   with Gmp(connection=connection) as gmp:

Getting and Printing GMP Version:

Python
   version = gmp.get_version()
   print(version)

Note:

GVM

This Python script interacts with the Greenbone Vulnerability Management (GVM) API to retrieve information about users, tasks, targets, scanners, configurations, feeds, and Network Vulnerability Tests (NVTs). Here’s an explanation of the code:

Python
#!/usr/bin/env python3

import gvm
from gvm.protocols.latest import Gmp
from gvm.transforms import EtreeCheckCommandTransform
from gvm.errors import GvmError

# Create a TLS connection to the GVM server
connection = gvm.connections.TLSConnection(hostname='localhost')

# GVM server login credentials
username = 'admin'
password = 'admin'

# Create a command transform for processing XML output
transform = EtreeCheckCommandTransform()

try:
    # Connect to GVM server using the Gmp class
    with Gmp(connection=connection, transform=transform) as gmp:
        # Authenticate with GVM server
        gmp.authenticate(username, password)

        # Get information about users, tasks, targets, scanners, configs, feeds, and nvts
        users = gmp.get_users()
        tasks = gmp.get_tasks()
        targets = gmp.get_targets()
        scanners = gmp.get_scanners()
        configs = gmp.get_configs()
        feeds = gmp.get_feeds()
        nvts = gmp.get_nvts()

        # Print information about users
        print("Users\n------------")
        for user in users.xpath('user'):
            print(user.find('name').text)

        # Print information about tasks
        print("\nTasks\n------------")
        for task in tasks.xpath('task'):
            print(task.find('name').text)

        # Print information about targets
        print("\nTargets\n-------------")
        for target in targets.xpath('target'):
            print(target.find('name').text)
            print(target.find('hosts').text)

        # Print information about scanners
        print("\nScanners\n-------------")
        for scanner in scanners.xpath('scanner'):
            print(scanner.find('name').text)

        # Print information about configs
        print("\nConfigs\n-------------")
        for config in configs.xpath('config'):
            print(config.find('name').text)

        # Print information about feeds
        print("\nFeeds\n-------------")
        for feed in feeds.xpath('feed'):
            print(feed.find('name').text)

        # Print information about NVTs
        print("\nNVTs\n-------------")
        for nvt in nvts.xpath('nvt'):
            print(nvt.attrib.get('oid'), "-->", nvt.find('name').text)

except GvmError as error:
    print('Error connecting with the GVM server:', error)

Explanation:

  1. TLS Connection:
    • The script creates a TLS connection to the GVM server with the specified hostname (‘localhost’ in this case).
  2. GVM Server Credentials:
    • The GVM server login credentials (username and password) are provided for authentication.
  3. Command Transform:
    • The EtreeCheckCommandTransform is used to transform XML command output for processing.
  4. GVM Authentication:
    • The script authenticates with the GVM server using the Gmp class.
  5. Retrieve Information:
    • Information about users, tasks, targets, scanners, configs, feeds, and nvts is retrieved using various get_ methods provided by the Gmp class.
  6. Print Information:
    • The script prints information about users, tasks, targets, scanners, configs, feeds, and NVTs to the console.
  7. Exception Handling:
    • If there is an error connecting with the GVM server, a GvmError exception is caught, and an error message is printed.

Usage:

Bash
  python gvm_script.py --login admin --password admin

Note:

Exit mobile version