Skip to content

Commit

Permalink
Merge pull request #19 from krystianbajno/feature/opencve-maintenance
Browse files Browse the repository at this point in the history
Maintenance - OpenCVE source
  • Loading branch information
krystianbajno authored Nov 24, 2024
2 parents af2584f + 2a731bb commit fc68f8b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 27 deletions.
57 changes: 31 additions & 26 deletions services/api/sources/opencve.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,39 +46,44 @@ def __get_vulnerabilities(self, response_data):
rows = table.find_all('tr', class_='cve-header')

for row in rows:
cve_id = row.find('td').find('a').text
vendor = row.find_all('td')[1].find('a').text
products = [prod.text for prod in row.find_all('td')[2].find_all('a')]
updated_date = row.find_all('td')[3].text.strip()

cvss_text = row.find_all('td')[4].find('span').text.strip()
if cvss_text:
base_score, base_severity = cvss_text.split(' ')
else:
base_score, base_severity = None, None

try:
cve_id = row.find('td').find('a').text
vendor = row.find_all('td')[1].find('a').text
products = [prod.text for prod in row.find_all('td')[2].find_all('a')]
updated_date = row.find_all('td')[3].text.strip()

description_row = row.find_next_sibling('tr', class_='cve-summary')
description = description_row.find('td').text.strip()
cvss_text = row.find_all('td')[4].find('span').text.strip()
if cvss_text:
base_score, base_severity = cvss_text.split(' ')
else:
base_score, base_severity = None, None

vulnerabilities.append(VulnerabilityFactory.make(
id=cve_id,
source=self.__class__.__name__,
url=f"https://app.opencve.io/cve/{cve_id}",
title=cve_id,
base_score=base_score,
base_severity=base_severity,
description=description,
vulnerable_components=list([f"{vendor} {product}" for product in products]),
date=updated_date
))

description_row = row.find_next_sibling('tr', class_='cve-summary')
description = description_row.find('td').text.strip()

vulnerability = VulnerabilityFactory.make(
id=cve_id,
source=self.__class__.__name__,
url=f"https://app.opencve.io/cve/{cve_id}",
title=cve_id,
base_score=base_score,
base_severity=base_severity,
description=description,
vulnerable_components=list([f"{vendor} {product}" for product in products]),
date=updated_date
)

vulnerabilities.append(vulnerability)
except:
continue

return vulnerabilities

def search(self, keywords: List[str], max_results) -> List[Vulnerability]:
vulnerabilities = []
response = httpx.get(self.__get_search_url(1, keywords))

if response.status_code != 200:
return []

Expand All @@ -90,7 +95,7 @@ def search(self, keywords: List[str], max_results) -> List[Vulnerability]:
page_vulnerabilities = self.__get_vulnerabilities(response.text)
vulnerabilities.extend(page_vulnerabilities)
current_page = current_page + 1
except:
except Exception as e:
break

return vulnerabilities
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import httpx
import logging
from typing import Dict, List
from typing import Dict


def vulners_find_related_cve_data(cve: str) -> Dict:
Expand Down

0 comments on commit fc68f8b

Please sign in to comment.