-
Notifications
You must be signed in to change notification settings - Fork 209
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feat/1039/ingest-rust-data-github-api
- Loading branch information
Showing
27 changed files
with
652 additions
and
142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import logging | ||
from typing import Iterable | ||
|
||
from django.db.models import QuerySet | ||
from sphinx.util import requests | ||
|
||
from vulnerabilities.improver import Improver | ||
from vulnerabilities.improver import Inference | ||
from vulnerabilities.models import Advisory | ||
from vulnerabilities.models import Alias | ||
from vulnerabilities.models import Kev | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class VulnerabilityKevImprover(Improver): | ||
""" | ||
Known Exploited Vulnerabilities Improver | ||
""" | ||
|
||
@property | ||
def interesting_advisories(self) -> QuerySet: | ||
# TODO Modify KEV improver to iterate over the vulnerabilities alias, not the advisory | ||
return [Advisory.objects.first()] | ||
|
||
def get_inferences(self, advisory_data) -> Iterable[Inference]: | ||
""" | ||
Fetch Kev data, iterate over it to find the vulnerability with the specified alias, and create or update | ||
the Kev instance accordingly. | ||
""" | ||
|
||
kev_url = ( | ||
"https://www.cisa.gov/sites/default/files/feeds/known_exploited_vulnerabilities.json" | ||
) | ||
response = requests.get(kev_url) | ||
kev_data = response.json() | ||
if response.status_code != 200: | ||
logger.error( | ||
f"Failed to fetch the CISA Catalog of Known Exploited Vulnerabilities: {kev_url}" | ||
) | ||
return [] | ||
|
||
for kev_vul in kev_data.get("vulnerabilities", []): | ||
alias = Alias.objects.get_or_none(alias=kev_vul["cveID"]) | ||
if not alias: | ||
continue | ||
|
||
vul = alias.vulnerability | ||
|
||
if not vul: | ||
continue | ||
|
||
Kev.objects.update_or_create( | ||
vulnerability=vul, | ||
defaults={ | ||
"description": kev_vul["shortDescription"], | ||
"date_added": kev_vul["dateAdded"], | ||
"required_action": kev_vul["requiredAction"], | ||
"due_date": kev_vul["dueDate"], | ||
"resources_and_notes": kev_vul["notes"], | ||
"known_ransomware_campaign_use": True | ||
if kev_vul["knownRansomwareCampaignUse"] == "Known" | ||
else False, | ||
}, | ||
) | ||
return [] |
4 changes: 2 additions & 2 deletions
4
...agechangelog_software_version_and_more.py → ...agechangelog_software_version_and_more.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 0 additions & 52 deletions
52
...rabilities/migrations/0055_remove_changelogs_with_same_data_different_software_version.py
This file was deleted.
Oops, something went wrong.
31 changes: 31 additions & 0 deletions
31
vulnerabilities/migrations/0056_alter_packagechangelog_software_version_and_more.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Generated by Django 4.1.13 on 2024-03-18 08:45 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("vulnerabilities", "0055_alter_packagechangelog_software_version_and_more"), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name="packagechangelog", | ||
name="software_version", | ||
field=models.CharField( | ||
default="34.0.0rc4", | ||
help_text="Version of the software at the time of change", | ||
max_length=100, | ||
), | ||
), | ||
migrations.AlterField( | ||
model_name="vulnerabilitychangelog", | ||
name="software_version", | ||
field=models.CharField( | ||
default="34.0.0rc4", | ||
help_text="Version of the software at the time of change", | ||
max_length=100, | ||
), | ||
), | ||
] |
21 changes: 0 additions & 21 deletions
21
vulnerabilities/migrations/0056_alter_packagechangelog_unique_together_and_more.py
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.