Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- # -*- coding: utf-8 -*-
- # Filename: is_vulnerable.py
- # Version: 1.0.0
- # Author: Jeoi Reqi
- """
- This script checks for vulnerabilities in installed software by querying the National Vulnerability Database (NVD).
- It retrieves a list of installed applications on the system using WMI (Windows Management Instrumentation).
- Then, it searches for vulnerabilities associated with each application by scraping the NVD website for exploits.
- If vulnerabilities are found for an application, it categorizes it as "Is Vulnerable" and lists the vulnerabilities.
- If no vulnerabilities are found, it categorizes the application as "Is Not Vulnerable".
- The results are saved to a text file named 'vulnerability_output.txt' in the following format:
- - Vulnerable:
- <Application Name>:
- <Vulnerability 1>
- <Vulnerability 2>
- ...
- - Not Vulnerable:
- <Application Name>
- <Application Name>
- ...
- Requirements:
- Python 3.x: The script is written in Python 3 and requires a Python interpreter of version 3 or higher to run.
- Requests Library:
- - The script uses the requests library to make HTTP requests to the National Vulnerability Database (NVD).
- Ensure that the requests library is installed.
- You can manually install it using pip:
- 'pip install requests'
- - Beautiful Soup Library: The script uses the BeautifulSoup library to parse HTML content retrieved from the NVD website.
- Ensure that the beautifulsoup4 library is installed.
- You can manually install it using pip:
- 'pip install beautifulsoup4'
- WMI Module:
- - The script uses the wmi module to interact with the Windows Management Instrumentation (WMI) API to retrieve a list of installed software on a Windows system.
- If you're using a Windows system, the wmi module is likely available by default.
- you can manually install it using pip:
- 'pip install WMI'
- Internet Connection:
- - The script retrieves vulnerability information from the National Vulnerability Database (NVD) hosted by NIST (National Institute of Standards and Technology).
- Therefore, an active internet connection is required for the script to fetch vulnerability data.
- Ensure that Python and the required libraries are installed on your system, and you have an internet connection to fetch vulnerability data from the NVD.
- """
- import wmi
- import requests
- from bs4 import BeautifulSoup
- def get_installed_software():
- """
- Retrieves a list of installed software on the system using WMI.
- Returns:
- list: A list of strings representing installed software names.
- """
- c = wmi.WMI()
- software = []
- for item in c.Win32_Product():
- software.append(item.Caption)
- return software
- def get_cve_details(software):
- """
- Retrieves vulnerability details for each software in the provided list.
- Args:
- software (list): A list of strings representing software names.
- Returns:
- dict: A dictionary where keys are software names and values are lists of associated vulnerabilities.
- """
- cve_details = {}
- for item in software:
- print(f"Retrieving vulnerabilities for {item}...")
- # Search for vulnerabilities in NVD using the software name
- query = f"https://nvd.nist.gov/vuln/search/results?form_type=Advanced&results_type=overview&query={item}&search_type=all"
- response = requests.get(query)
- if response.status_code == 200:
- soup = BeautifulSoup(response.content, "html.parser")
- # Extract vulnerability details
- vuln_entries = soup.find_all("tr", class_="srrowns")
- if vuln_entries:
- cve_details[item] = [entry.find("a").text.strip() for entry in vuln_entries]
- else:
- cve_details[item] = None # None if no vulnerabilities found
- else:
- cve_details[item] = ["\nFailed to retrieve vulnerability information.\n"]
- return cve_details
- if __name__ == "__main__":
- print("\nGathering List Of Your Installed Applications...\n")
- installed_software = get_installed_software()
- print("\nGathering List Of Applications Is Complete!\n")
- vulnerable_software = []
- not_vulnerable_software = []
- print("\nRetrieving (NVD) Vulnerability & Exploit Data From NIST:\nThis May Take Some Time To Process...\n")
- if installed_software:
- software_vulnerabilities = get_cve_details(installed_software)
- for software, vulnerabilities in software_vulnerabilities.items():
- if vulnerabilities is not None and vulnerabilities != []:
- vulnerable_software.append((software, vulnerabilities))
- else:
- not_vulnerable_software.append(software)
- # Save output to file
- with open("vulnerability_output.txt", "w", encoding="utf-8") as f:
- # Write Vulnerable Software
- f.write("Is Vulnerable:\n")
- if vulnerable_software:
- for software, vulnerabilities in vulnerable_software:
- f.write(software + "\n")
- if vulnerabilities:
- for vuln in vulnerabilities:
- f.write(vuln + "\n")
- else:
- f.write("No Known Vulnerabilities Found!\n")
- f.write("\n")
- else:
- f.write("No Known Vulnerabilities Found!\n")
- f.write("\n")
- # Write Non Vulnerable Software
- f.write("Is Not Vulnerable:\n")
- for software in not_vulnerable_software:
- f.write(software + "\n")
- print("\nOutput saved to vulnerability_output.txt\n\nGoodBye!\n")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement