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:

  • Network scanning: OpenVAS can scan for vulnerabilities on a network by scanning the ports of each device on the network.
  • Host scanning: OpenVAS can scan for vulnerabilities on a host by scanning the files and services on the host.
  • Web application scanning: OpenVAS can scan for vulnerabilities in web applications by scanning the code of the application.

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:

  • Improved security: OpenVAS can help to identify and remediate vulnerabilities before they can be exploited by attackers.
  • Reduced costs: OpenVAS can help to reduce the costs of security breaches by identifying vulnerabilities before they can be exploited.
  • Increased compliance: OpenVAS can help to ensure compliance with security regulations.

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:
  • Username: admin
  • Password: admin Change the password immediately after the first login.
  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:

  • The setup process might prompt you to configure various settings. Follow the on-screen instructions.
  • Ensure that your server has sufficient resources (CPU, RAM) to run OpenVAS effectively.
  • The default setup uses self-signed SSL certificates. For a production environment, you might consider replacing them with valid certificates.
  • Remember to keep OpenVAS and its NVTs up to date for accurate vulnerability scanning.

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:

  • #!/usr/bin/env python3: Specifies the Python interpreter to be used.
  • import gvm: Imports the gvm library, which provides an interface for interacting with the Greenbone Vulnerability Management (GVM) protocol.
  • from gvm.protocols.latest import Gmp: Specifically imports the GMP (Greenbone Management Protocol) from the latest version of the GVM protocol.

TLS Connection to GVM Server:

Python
   connection = gvm.connections.TLSConnection(hostname='localhost')
  • Creates a TLS (Transport Layer Security) connection object to the GVM server running on localhost. Adjust the hostname parameter based on the actual GVM server address.

Using GMP Protocol:

Python
   with Gmp(connection=connection) as gmp:
  • Initiates a connection to the GVM server using the GMP protocol within a with statement. The with statement ensures proper handling of resources.

Getting and Printing GMP Version:

Python
   version = gmp.get_version()
   print(version)
  • Calls the get_version method to retrieve the GMP version from the connected GVM server.
  • Prints the retrieved GMP version to the console.

Note:

  • The script assumes that a GVM server is running on localhost. Update the hostname parameter in the TLSConnection constructor to match the actual address of your GVM server.
  • Ensure that the gvm library is installed before running the script. You can install it using pip install gvm-tools.
  • The TLSConnection indicates that the script is using a secure TLS connection. Ensure that your GVM server is configured to support TLS connections.
  • This script provides a simple example of how to establish a connection to a GVM server and retrieve information. Depending on your use case, you may need to extend the script to perform additional tasks with the GVM API.

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:

  • Save this script in a file, e.g., gvm_script.py.
  • Run the script from the command line, providing the GVM server login credentials:
Bash
  python gvm_script.py --login admin --password admin

Note:

  • Ensure that the GVM server is running and accessible.
  • Modify the hostname, username, and password variables based on your GVM server configuration.
  • Adjust the script as needed based on the specific requirements of your GVM environment.
Total
0
Shares

Leave a Reply

Previous Post
Accessing the nessus API with python - Interacting with server and client

Accessing the nessus API with python – Interacting with server and client

Next Post
Understanding vulnerabilities in web applications with OWASP

Understanding vulnerabilities in web applications with OWASP

Related Posts