Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support to Exploits model #1562

Merged
merged 19 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 19 additions & 10 deletions vulnerabilities/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from rest_framework.throttling import UserRateThrottle

from vulnerabilities.models import Alias
from vulnerabilities.models import Kev
from vulnerabilities.models import Exploit
from vulnerabilities.models import Package
from vulnerabilities.models import Vulnerability
from vulnerabilities.models import VulnerabilityReference
Expand Down Expand Up @@ -175,10 +175,23 @@ def to_representation(self, instance):
return representation


class KEVSerializer(serializers.ModelSerializer):
class ExploitSerializer(serializers.ModelSerializer):
class Meta:
model = Kev
fields = ["date_added", "description", "required_action", "due_date", "resources_and_notes"]
model = Exploit
fields = [
"date_added",
"description",
"required_action",
"due_date",
"notes",
"known_ransomware_campaign_use",
"source_date_published",
"exploit_type",
"platform",
"source_date_updated",
"data_source",
"source_url",
]


class VulnerabilitySerializer(BaseResourceSerializer):
Expand All @@ -189,7 +202,7 @@ class VulnerabilitySerializer(BaseResourceSerializer):

references = VulnerabilityReferenceSerializer(many=True, source="vulnerabilityreference_set")
aliases = AliasSerializer(many=True, source="alias")
kev = KEVSerializer(read_only=True)
exploits = ExploitSerializer(many=True, read_only=True)
weaknesses = WeaknessSerializer(many=True)
severity_range_score = serializers.SerializerMethodField()

Expand All @@ -199,10 +212,6 @@ def to_representation(self, instance):
weaknesses = data.get("weaknesses", [])
data["weaknesses"] = [weakness for weakness in weaknesses if weakness is not None]

kev = data.get("kev", None)
if not kev:
data.pop("kev")

return data

def get_severity_range_score(self, instance):
Expand Down Expand Up @@ -240,7 +249,7 @@ class Meta:
"affected_packages",
"references",
"weaknesses",
"kev",
"exploits",
"severity_range_score",
]

Expand Down
19 changes: 16 additions & 3 deletions vulnerabilities/api_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from rest_framework.throttling import AnonRateThrottle

from vulnerabilities.api import BaseResourceSerializer
from vulnerabilities.models import Kev
from vulnerabilities.models import Exploit
from vulnerabilities.models import Package
from vulnerabilities.models import Vulnerability
from vulnerabilities.models import VulnerabilityReference
Expand Down Expand Up @@ -105,8 +105,21 @@ class Meta:

class V2ExploitSerializer(ModelSerializer):
class Meta:
model = Kev
fields = ("description", "required_action", "date_added", "due_date", "resources_and_notes")
model = Exploit
fields = [
"date_added",
"description",
"required_action",
"due_date",
"notes",
"known_ransomware_campaign_use",
"source_date_published",
"exploit_type",
"platform",
"source_date_updated",
"data_source",
"source_url",
]


class V2VulnerabilitySerializer(ModelSerializer):
Expand Down
8 changes: 6 additions & 2 deletions vulnerabilities/improvers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
#

from vulnerabilities.improvers import valid_versions
from vulnerabilities.improvers import vulnerability_kev
from vulnerabilities.improvers import vulnerability_status
from vulnerabilities.pipelines import VulnerableCodePipeline
from vulnerabilities.pipelines import enhance_with_exploitdb
from vulnerabilities.pipelines import enhance_with_kev
from vulnerabilities.pipelines import enhance_with_metasploit
from vulnerabilities.pipelines import flag_ghost_packages

IMPROVERS_REGISTRY = [
Expand All @@ -31,8 +33,10 @@
valid_versions.GithubOSVImprover,
vulnerability_status.VulnerabilityStatusImprover,
valid_versions.CurlImprover,
vulnerability_kev.VulnerabilityKevImprover,
flag_ghost_packages.FlagGhostPackagePipeline,
enhance_with_kev.VulnerabilityKevPipeline,
enhance_with_metasploit.MetasploitImproverPipeline,
enhance_with_exploitdb.ExploitDBImproverPipeline,
]

IMPROVERS_REGISTRY = {
Expand Down
66 changes: 0 additions & 66 deletions vulnerabilities/improvers/vulnerability_kev.py

This file was deleted.

131 changes: 131 additions & 0 deletions vulnerabilities/migrations/0065_exploit_delete_kev.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
# Generated by Django 4.2.15 on 2024-09-21 15:37

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
("vulnerabilities", "0064_update_npm_pypa_advisory_created_by"),
]

operations = [
migrations.CreateModel(
name="Exploit",
fields=[
(
"id",
models.AutoField(
auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
),
),
(
"date_added",
models.DateField(
blank=True,
help_text="The date the vulnerability was added to an exploit catalog.",
null=True,
),
),
(
"description",
models.TextField(
blank=True,
help_text="Description of the vulnerability in an exploit catalog, often a refinement of the original CVE description",
null=True,
),
),
(
"required_action",
models.TextField(
blank=True,
help_text="The required action to address the vulnerability, typically to apply vendor updates or apply vendor mitigations or to discontinue use.",
null=True,
),
),
(
"due_date",
models.DateField(
blank=True,
help_text="The date the required action is due, which applies to all USA federal civilian executive branch (FCEB) agencies, but all organizations are strongly encouraged to execute the required action",
null=True,
),
),
(
"notes",
models.TextField(
blank=True,
help_text="Additional notes and resources about the vulnerability, often a URL to vendor instructions.",
null=True,
),
),
(
"known_ransomware_campaign_use",
models.BooleanField(
default=False,
help_text="Known' if this vulnerability is known to have been leveraged as part of a ransomware campaign; \n or 'Unknown' if there is no confirmation that the vulnerability has been utilized for ransomware.",
),
),
(
"source_date_published",
models.DateField(
blank=True,
help_text="The date that the exploit was published or disclosed.",
null=True,
),
),
(
"exploit_type",
models.TextField(
blank=True,
help_text="The type of the exploit as provided by the original upstream data source.",
null=True,
),
),
(
"platform",
models.TextField(
blank=True,
help_text="The platform associated with the exploit as provided by the original upstream data source.",
null=True,
),
),
(
"source_date_updated",
models.DateField(
blank=True,
help_text="The date the exploit was updated in the original upstream data source.",
null=True,
),
),
(
"data_source",
models.TextField(
blank=True,
help_text="The source of the exploit information, such as CISA KEV, exploitdb, metaspoit, or others.",
null=True,
),
),
(
"source_url",
models.URLField(
blank=True,
help_text="The URL to the exploit as provided in the original upstream data source.",
null=True,
),
),
(
"vulnerability",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="exploits",
to="vulnerabilities.vulnerability",
),
),
],
),
migrations.DeleteModel(
name="Kev",
),
]
Loading
Loading