-
Notifications
You must be signed in to change notification settings - Fork 293
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
feat(lib): mitre d3fend #1394
feat(lib): mitre d3fend #1394
Changes from 3 commits
5d46e2d
0d79c22
a45ee5a
f5b887a
77f48bd
f711740
a207e6c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,84 @@ | ||||||||||||||||||||||||
# d3fend library generator for CISO Assistant | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
import csv | ||||||||||||||||||||||||
from openpyxl import Workbook | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
tactic_to_csf_funtion = { | ||||||||||||||||||||||||
"Model": "identify", | ||||||||||||||||||||||||
"Harden": "protect", | ||||||||||||||||||||||||
"Detect": "detect", | ||||||||||||||||||||||||
"Isolate": "protect", | ||||||||||||||||||||||||
"Deceive": "protect", | ||||||||||||||||||||||||
"Evict": "respond", | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
output_file_name = "d3fend.xlsx" | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
library_description = """A cybersecurity ontology designed to standardize vocabulary for employing techniques to counter malicious cyber threats. | ||||||||||||||||||||||||
Version - 1.0.0 - 2024-12-20 | ||||||||||||||||||||||||
https://d3fend.mitre.org/resources/""" | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
library_copyright = """Terms of Use | ||||||||||||||||||||||||
LICENSE | ||||||||||||||||||||||||
The MITRE Corporation (MITRE) hereby grants you a non-exclusive, royalty-free license to use D3FEND for research, development, and commercial purposes. Any copy you make for such purposes is authorized provided that you reproduce MITRE’s copyright designation and this license in any such copy. | ||||||||||||||||||||||||
DISCLAIMERS | ||||||||||||||||||||||||
ALL DOCUMENTS AND THE INFORMATION CONTAINED THEREIN ARE PROVIDED ON AN "AS IS" BASIS AND THE CONTRIBUTOR, THE ORGANIZATION HE/SHE REPRESENTS OR IS SPONSORED BY (IF ANY), THE MITRE CORPORATION, ITS BOARD OF TRUSTEES, OFFICERS, AGENTS, AND EMPLOYEES, DISCLAIM ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE INFORMATION THEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. | ||||||||||||||||||||||||
""" | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
packager = "intuitem" | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
|
||||||||||||||||||||||||
with open("d3fend.csv", newline="") as csvfile: | ||||||||||||||||||||||||
reader = csv.reader(csvfile, delimiter=",") | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
Comment on lines
+31
to
+33
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Add error handling for CSV file operations. The script may fail silently if the CSV file is missing or inaccessible. Consider adding proper error handling. -with open("d3fend.csv", newline="") as csvfile:
+try:
+ with open("d3fend.csv", newline="") as csvfile:
+ reader = csv.reader(csvfile, delimiter=",")
+except FileNotFoundError:
+ print("Error: d3fend.csv file not found")
+ exit(1)
+except PermissionError:
+ print("Error: Permission denied accessing d3fend.csv")
+ exit(1) 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||
n = 0 | ||||||||||||||||||||||||
current_technique = "" | ||||||||||||||||||||||||
current_technique_l1 = "" | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
wb_output = Workbook() | ||||||||||||||||||||||||
ws = wb_output.active | ||||||||||||||||||||||||
print("generating", output_file_name) | ||||||||||||||||||||||||
ws.title = "library_content" | ||||||||||||||||||||||||
ws.append(["library_urn", f"urn:{packager.lower()}:risk:library:mitre-d3fend"]) | ||||||||||||||||||||||||
ws.append(["library_version", 1]) | ||||||||||||||||||||||||
ws.append(["library_locale", "en"]) | ||||||||||||||||||||||||
ws.append(["library_publication_date", "2025-01-22"]) | ||||||||||||||||||||||||
ws.append(["library_ref_id", "d3fend"]) | ||||||||||||||||||||||||
ws.append(["library_name", "Mitre D3FEND"]) | ||||||||||||||||||||||||
ws.append(["library_description", library_description]) | ||||||||||||||||||||||||
ws.append(["library_copyright", library_copyright]) | ||||||||||||||||||||||||
ws.append(["library_provider", "Mitre D3FEND"]) | ||||||||||||||||||||||||
ws.append(["library_packager", packager]) | ||||||||||||||||||||||||
ws.append(["tab", "controls", "reference_controls"]) | ||||||||||||||||||||||||
ws.append( | ||||||||||||||||||||||||
[ | ||||||||||||||||||||||||
"reference_control_base_urn", | ||||||||||||||||||||||||
"urn:intuitem:risk:reference-controls:mitre-d3fend", | ||||||||||||||||||||||||
] | ||||||||||||||||||||||||
) | ||||||||||||||||||||||||
ws1 = wb_output.create_sheet("controls") | ||||||||||||||||||||||||
ws1.append(("ref_id", "name", "description", "category", "csf_function")) | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
for row in reader: | ||||||||||||||||||||||||
n += 1 | ||||||||||||||||||||||||
if n == 1: | ||||||||||||||||||||||||
header = row | ||||||||||||||||||||||||
else: | ||||||||||||||||||||||||
id, tactic, technique, technique_l1, technique_l2, definition = row | ||||||||||||||||||||||||
if technique: | ||||||||||||||||||||||||
current_technique = technique | ||||||||||||||||||||||||
continue | ||||||||||||||||||||||||
if technique_l1: | ||||||||||||||||||||||||
current_technique_l1 = technique_l1 | ||||||||||||||||||||||||
ref_id = id | ||||||||||||||||||||||||
name = current_technique_l1 | ||||||||||||||||||||||||
description = f"tactic: {tactic}\ntechnique level 1: {current_technique_l1}\ndefinition: {definition}" | ||||||||||||||||||||||||
if technique_l2: | ||||||||||||||||||||||||
ref_id = id | ||||||||||||||||||||||||
name = technique_l2 | ||||||||||||||||||||||||
description = f"tactic: {tactic}\ntechnique level 1: {current_technique_l1}\ntechnique level 2: {technique_l2}\ndefinition: {definition}" | ||||||||||||||||||||||||
ws1.append( | ||||||||||||||||||||||||
(ref_id, name, description, "technical", tactic_to_csf_funtion[tactic]) | ||||||||||||||||||||||||
) | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
wb_output.save(output_file_name) | ||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Add error handling for workbook saving. The workbook save operation could fail due to permission issues or disk space. Add proper error handling. - wb_output.save(output_file_name)
+ try:
+ wb_output.save(output_file_name)
+ print(f"Successfully generated {output_file_name}")
+ except PermissionError:
+ print(f"Error: Permission denied saving {output_file_name}")
+ exit(1)
+ except Exception as e:
+ print(f"Error saving workbook: {str(e)}")
+ exit(1) 📝 Committable suggestion
Suggested change
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Use
isinstance()
for type checking.Replace
type()
comparison withisinstance()
for better Python practices.📝 Committable suggestion
🧰 Tools
🪛 Ruff (0.8.2)
845-845: Use
is
andis not
for type comparisons, orisinstance()
for isinstance checks(E721)