|
import requests |
|
from bs4 import BeautifulSoup |
|
from langchain.tools import tool |
|
import json |
|
|
|
class CVESearchTool(): |
|
@tool("CVE search Tool") |
|
def cvesearch(keyword: str): |
|
"CVE (Common Vulnerabilities and Exposures) search tool is a useful tool to search for known security vulnerabilities and exposures in various software products, systems, and devices. It helps users to identify specific vulnerabilities by searching through the CVE database, which contains detailed information about vulnerabilities." |
|
url = f"https://cve.mitre.org/cgi-bin/cvekey.cgi?keyword={keyword}" |
|
|
|
|
|
response = requests.get(url) |
|
if response.status_code == 200: |
|
html_content = response.content |
|
|
|
|
|
soup = BeautifulSoup(html_content, 'html.parser') |
|
|
|
|
|
cves = soup.find_all('td', {'valign': 'top', 'nowrap': 'nowrap'}) |
|
|
|
|
|
cve_dict = {} |
|
|
|
|
|
for cve in cves: |
|
cve_id = cve.text.strip() |
|
description = cve.find_next('td').text.strip() |
|
cve_dict[cve_id] = description |
|
|
|
|
|
json_string = json.dumps(cve_dict, indent=4) |
|
|
|
return json_string |
|
else: |
|
print("Failed to fetch the page:", response.status_code) |
|
return None |
|
|