Skip to content

Commit e273c67

Browse files
Add support for Exploit model (#1562)
* Migrate ( metasploit, exploit-db, kev ) to aboutcode pipeline. Set data_source as the header for the exploit table. Squash the migration files into a single file. Add test for exploit-db , metasploit Add a missing migration file Rename resources_and_notes to notes Fix Api test Refactor metasploit , exploitdb , kev improver Rename Kev tab to exploit tab Add support for exploitdb , metasploit, kev Signed-off-by: ziadhany <[email protected]> * Implement the appropriate LoopProgress progress bar. Refactor the error handling logic in the code. Signed-off-by: ziadhany <[email protected]> * Resolve migration conflicts. Address the exploit in the API extension. Signed-off-by: ziadhany <[email protected]> * Add any missing logs message Remove unused logging module Signed-off-by: ziadhany <[email protected]> * Migrate ( metasploit, exploit-db, kev ) to aboutcode pipeline. Set data_source as the header for the exploit table. Squash the migration files into a single file. Add test for exploit-db , metasploit Add a missing migration file Rename resources_and_notes to notes Fix Api test Refactor metasploit , exploitdb , kev improver Rename Kev tab to exploit tab Add support for exploitdb , metasploit, kev Signed-off-by: ziadhany <[email protected]> * Implement the appropriate LoopProgress progress bar. Refactor the error handling logic in the code. Signed-off-by: ziadhany <[email protected]> * Resolve migration conflicts. Address the exploit in the API extension. Signed-off-by: ziadhany <[email protected]> * Add any missing logs message Remove unused logging module Signed-off-by: ziadhany <[email protected]> * Fix migration conflict Add pipeline_id for ( kev, metasploit, exploit-db ) Signed-off-by: ziadhany <[email protected]> * Remove unwanted migration file Signed-off-by: ziadhany <[email protected]> * Add log traceback for all the errors. Add missing logs Handle cases of one exploit for multiple vulnerabilities. Signed-off-by: ziadhany <[email protected]> * Skip empty aliases Remove empty vulnerability_kev.py file Signed-off-by: ziadhany <[email protected]> * Replace references log with interesting_references Signed-off-by: ziadhany <[email protected]> * Use proper labels in vulnerability details Signed-off-by: Keshav Priyadarshi <[email protected]> * Display Known/Unknown for ransomware campaign use Signed-off-by: Keshav Priyadarshi <[email protected]> --------- Signed-off-by: ziadhany <[email protected]> Signed-off-by: Keshav Priyadarshi <[email protected]> Co-authored-by: Keshav Priyadarshi <[email protected]>
1 parent d16bdf3 commit e273c67

File tree

16 files changed

+885
-164
lines changed

16 files changed

+885
-164
lines changed

vulnerabilities/api.py

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
from rest_framework.throttling import UserRateThrottle
2828

2929
from vulnerabilities.models import Alias
30-
from vulnerabilities.models import Kev
30+
from vulnerabilities.models import Exploit
3131
from vulnerabilities.models import Package
3232
from vulnerabilities.models import Vulnerability
3333
from vulnerabilities.models import VulnerabilityReference
@@ -175,10 +175,23 @@ def to_representation(self, instance):
175175
return representation
176176

177177

178-
class KEVSerializer(serializers.ModelSerializer):
178+
class ExploitSerializer(serializers.ModelSerializer):
179179
class Meta:
180-
model = Kev
181-
fields = ["date_added", "description", "required_action", "due_date", "resources_and_notes"]
180+
model = Exploit
181+
fields = [
182+
"date_added",
183+
"description",
184+
"required_action",
185+
"due_date",
186+
"notes",
187+
"known_ransomware_campaign_use",
188+
"source_date_published",
189+
"exploit_type",
190+
"platform",
191+
"source_date_updated",
192+
"data_source",
193+
"source_url",
194+
]
182195

183196

184197
class VulnerabilitySerializer(BaseResourceSerializer):
@@ -189,7 +202,7 @@ class VulnerabilitySerializer(BaseResourceSerializer):
189202

190203
references = VulnerabilityReferenceSerializer(many=True, source="vulnerabilityreference_set")
191204
aliases = AliasSerializer(many=True, source="alias")
192-
kev = KEVSerializer(read_only=True)
205+
exploits = ExploitSerializer(many=True, read_only=True)
193206
weaknesses = WeaknessSerializer(many=True)
194207
severity_range_score = serializers.SerializerMethodField()
195208

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

202-
kev = data.get("kev", None)
203-
if not kev:
204-
data.pop("kev")
205-
206215
return data
207216

208217
def get_severity_range_score(self, instance):
@@ -240,7 +249,7 @@ class Meta:
240249
"affected_packages",
241250
"references",
242251
"weaknesses",
243-
"kev",
252+
"exploits",
244253
"severity_range_score",
245254
]
246255

vulnerabilities/api_extension.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
from rest_framework.throttling import AnonRateThrottle
2727

2828
from vulnerabilities.api import BaseResourceSerializer
29-
from vulnerabilities.models import Kev
29+
from vulnerabilities.models import Exploit
3030
from vulnerabilities.models import Package
3131
from vulnerabilities.models import Vulnerability
3232
from vulnerabilities.models import VulnerabilityReference
@@ -105,8 +105,21 @@ class Meta:
105105

106106
class V2ExploitSerializer(ModelSerializer):
107107
class Meta:
108-
model = Kev
109-
fields = ("description", "required_action", "date_added", "due_date", "resources_and_notes")
108+
model = Exploit
109+
fields = [
110+
"date_added",
111+
"description",
112+
"required_action",
113+
"due_date",
114+
"notes",
115+
"known_ransomware_campaign_use",
116+
"source_date_published",
117+
"exploit_type",
118+
"platform",
119+
"source_date_updated",
120+
"data_source",
121+
"source_url",
122+
]
110123

111124

112125
class V2VulnerabilitySerializer(ModelSerializer):

vulnerabilities/improvers/__init__.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88
#
99

1010
from vulnerabilities.improvers import valid_versions
11-
from vulnerabilities.improvers import vulnerability_kev
1211
from vulnerabilities.improvers import vulnerability_status
1312
from vulnerabilities.pipelines import VulnerableCodePipeline
13+
from vulnerabilities.pipelines import enhance_with_exploitdb
14+
from vulnerabilities.pipelines import enhance_with_kev
15+
from vulnerabilities.pipelines import enhance_with_metasploit
1416
from vulnerabilities.pipelines import flag_ghost_packages
1517

1618
IMPROVERS_REGISTRY = [
@@ -31,8 +33,10 @@
3133
valid_versions.GithubOSVImprover,
3234
vulnerability_status.VulnerabilityStatusImprover,
3335
valid_versions.CurlImprover,
34-
vulnerability_kev.VulnerabilityKevImprover,
3536
flag_ghost_packages.FlagGhostPackagePipeline,
37+
enhance_with_kev.VulnerabilityKevPipeline,
38+
enhance_with_metasploit.MetasploitImproverPipeline,
39+
enhance_with_exploitdb.ExploitDBImproverPipeline,
3640
]
3741

3842
IMPROVERS_REGISTRY = {

vulnerabilities/improvers/vulnerability_kev.py

Lines changed: 0 additions & 66 deletions
This file was deleted.
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
# Generated by Django 4.2.15 on 2024-09-21 15:37
2+
3+
from django.db import migrations, models
4+
import django.db.models.deletion
5+
6+
7+
class Migration(migrations.Migration):
8+
9+
dependencies = [
10+
("vulnerabilities", "0068_update_nvd_advisory_created_by"),
11+
]
12+
13+
operations = [
14+
migrations.CreateModel(
15+
name="Exploit",
16+
fields=[
17+
(
18+
"id",
19+
models.AutoField(
20+
auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
21+
),
22+
),
23+
(
24+
"date_added",
25+
models.DateField(
26+
blank=True,
27+
help_text="The date the vulnerability was added to an exploit catalog.",
28+
null=True,
29+
),
30+
),
31+
(
32+
"description",
33+
models.TextField(
34+
blank=True,
35+
help_text="Description of the vulnerability in an exploit catalog, often a refinement of the original CVE description",
36+
null=True,
37+
),
38+
),
39+
(
40+
"required_action",
41+
models.TextField(
42+
blank=True,
43+
help_text="The required action to address the vulnerability, typically to apply vendor updates or apply vendor mitigations or to discontinue use.",
44+
null=True,
45+
),
46+
),
47+
(
48+
"due_date",
49+
models.DateField(
50+
blank=True,
51+
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",
52+
null=True,
53+
),
54+
),
55+
(
56+
"notes",
57+
models.TextField(
58+
blank=True,
59+
help_text="Additional notes and resources about the vulnerability, often a URL to vendor instructions.",
60+
null=True,
61+
),
62+
),
63+
(
64+
"known_ransomware_campaign_use",
65+
models.BooleanField(
66+
default=False,
67+
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.",
68+
),
69+
),
70+
(
71+
"source_date_published",
72+
models.DateField(
73+
blank=True,
74+
help_text="The date that the exploit was published or disclosed.",
75+
null=True,
76+
),
77+
),
78+
(
79+
"exploit_type",
80+
models.TextField(
81+
blank=True,
82+
help_text="The type of the exploit as provided by the original upstream data source.",
83+
null=True,
84+
),
85+
),
86+
(
87+
"platform",
88+
models.TextField(
89+
blank=True,
90+
help_text="The platform associated with the exploit as provided by the original upstream data source.",
91+
null=True,
92+
),
93+
),
94+
(
95+
"source_date_updated",
96+
models.DateField(
97+
blank=True,
98+
help_text="The date the exploit was updated in the original upstream data source.",
99+
null=True,
100+
),
101+
),
102+
(
103+
"data_source",
104+
models.TextField(
105+
blank=True,
106+
help_text="The source of the exploit information, such as CISA KEV, exploitdb, metaspoit, or others.",
107+
null=True,
108+
),
109+
),
110+
(
111+
"source_url",
112+
models.URLField(
113+
blank=True,
114+
help_text="The URL to the exploit as provided in the original upstream data source.",
115+
null=True,
116+
),
117+
),
118+
(
119+
"vulnerability",
120+
models.ForeignKey(
121+
on_delete=django.db.models.deletion.CASCADE,
122+
related_name="exploits",
123+
to="vulnerabilities.vulnerability",
124+
),
125+
),
126+
],
127+
),
128+
migrations.DeleteModel(
129+
name="Kev",
130+
),
131+
]

0 commit comments

Comments
 (0)