This repository contains two Python scripts designed to assist in the detection of known vulnerabilities based on system services. The first script, setup.py, sets up a SQLite database and retrieves vulnerability data from the NVD (National Vulnerability Database). The second script, vulnScanner.py, analyzes the Nmap scan results, identifies running services, and cross-references them with the database to detect vulnerabilities.
This script performs two main functions:
-
Database Setup (
setup_database):- Creates a SQLite database called
vulnerabilities.dband a table to store vulnerability information. - The table includes fields like CVE ID, description, publication date, CVSS score, and CPE URI (Common Platform Enumeration).
- Creates a SQLite database called
-
Fetch and Store CVE Data (
fetch_and_store_cve_data):- Retrieves vulnerability data from the National Vulnerability Database (NVD) API.
- The data is parsed and stored in the SQLite database.
- This process includes retry logic for failed API requests, using exponential backoff to avoid overwhelming the server.
To use this script, simply run it to create and populate the database with the latest CVE entries.
- Initializes a SQLite database.
- Fetches data from the NVD API.
- Saves vulnerability information (e.g., CVE ID, description, CVSS score) into the database.
python setup.pyThis script performs vulnerability scanning on a specified host by:
-
Running an Nmap Scan:
- Executes an Nmap scan using the
-sCand-sVflags, which detect versions of services running on open ports.
- Executes an Nmap scan using the
-
Parsing Nmap Output:
- The XML output from Nmap is parsed to extract service details, such as port number, service name, version, and product information.
-
Cross-referencing with Vulnerability Database:
- After extracting service details, it queries the
vulnerabilities.dbdatabase created bysetup.pyto find known vulnerabilities related to each service and version.
- After extracting service details, it queries the
-
Displaying Results:
- The script outputs a detailed list of open ports, services, and associated vulnerabilities (if any).
- Runs a Nmap scan against the target host.
- Extracts service details from Nmap's XML output.
- Queries the
vulnerabilities.dbfor vulnerabilities related to the identified services. - Displays found vulnerabilities for each service.
-
Set Up the Database: Run
setup.pyto create and populate the vulnerability database.python setup.py
-
Scan for Vulnerabilities: Once the database is set up, use
vulnScanner.pyto scan your target host. Provide the target IP address as a command-line argument:python vulnScanner.py <host_ip>
Example:
python vulnScanner.py 192.168.1.10
This will run an Nmap scan on the specified host and cross-reference the services with the stored vulnerabilities.
Before running these scripts, ensure you have the following dependencies installed:
- Python 3.x
requestslibrary: For fetching data from the NVD API.sqlite3library: For database handling (comes pre-installed with Python).xml.etree.ElementTree(for parsing XML data, included with Python).subprocess: Used to execute Nmap from within the script.
pip install requestsAdditionally, ensure that you have Nmap installed on your system, as it is required to run the vulnerability scanning portion of the script.
- Install Nmap: Download Nmap
- The NVD API is used to fetch vulnerability data, and the script handles retries in case of network or API failures.
- The Nmap scan checks for open ports and identifies services, versions, and products, which are then cross-referenced with the stored CVE data to detect vulnerabilities.
- This approach assumes the Nmap output contains version information for services. If a service version is not provided, it will be skipped during the vulnerability check.
Disclaimer This repository is for educational purposes only. It should not be used for malicious intent.