Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
2.0 kB
3
Indexable
Never
import requests
#import datetime
from bs4 import BeautifulSoup 
import json 
import operator

def retrieve_cves_monthly(url):
    cves_list = []
    conn = requests.get(url)
    content = conn.content
    soup = BeautifulSoup(content, 'html.parser') 
    #s_lookup_cves = soup.find('span', class_="col-md-2")

    #looping used to find all the CVE IDs inside conn variable 
    for link in soup.find_all('a'):
            if link.get('href') is not None:
                if link.get('href').startswith('/vuln/detail'):
                    cves_list.append(link.text)
    return(cves_list)
        

def access_every_cve():
    cve_results = {"cve":[], "severity":[], "description":[], "url":[]} 

    for i in retrieve_cves_monthly("https://nvd.nist.gov/vuln/full-listing/2021/10"):
        conn = requests.get("https://nvd.nist.gov/vuln/detail/{}" .format(i))
        content = conn.content
        soup = BeautifulSoup(content, 'html.parser')
        ##label danger defines HIGH Severity cases
        if soup.find('a', class_='label-danger') is not None:
            try:
                severity = soup.find('a', class_='label-danger').text
            except:
                pass
        ##acording to NIST 7.0 above is considered HIGH so easily we can convert to int for better comparison
          ##https://nvd.nist.gov/vuln-metrics/cvss
            severity = ".".join([x for x in severity if x.isdigit()])
            if severity == "1.0.0":
                severity = 10.0
            severity = float(severity)
            description = soup.find("p", attrs={"data-testid":"vuln-analysis-description"}).text
            cve_results["cve"] = i 
            cve_results["severity"]= severity
            cve_results["description"] = description
            cve_results["url"] = "https://nvd.nist.gov/vuln/detail/{}".format(i)
            #print(i, severity, description, "https://nvd.nist.gov/vuln/detail/{}".format(i))
        

    return(cve_results)
        
print(json.dumps(access_every_cve(), indent=4))