-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'cwe-field' into 'main'
Cwe field See merge request reportcreator/reportcreator!445
- Loading branch information
Showing
22 changed files
with
5,887 additions
and
17 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
5,606 changes: 5,606 additions & 0 deletions
5,606
api/src/reportcreator_api/pentests/customfields/cwe.json
Large diffs are not rendered by default.
Oops, something went wrong.
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
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,37 @@ | ||
import io | ||
import requests | ||
import zipfile | ||
import json | ||
from pathlib import Path | ||
from lxml import etree | ||
|
||
|
||
def download_cwe_xml(): | ||
res = requests.get('https://cwe.mitre.org/data/xml/cwec_latest.xml.zip').content | ||
with zipfile.ZipFile(file=io.BytesIO(res)) as zip: | ||
return zip.read(zip.namelist()[0]) | ||
|
||
|
||
def main(): | ||
cwes = [] | ||
cwe_xml = etree.fromstring(download_cwe_xml()) | ||
weaknesses_xml = cwe_xml.findall('./Weaknesses/Weakness', namespaces=cwe_xml.nsmap) | ||
for w in weaknesses_xml: | ||
if w.attrib['Status'] == 'Deprecated': | ||
continue | ||
parent_ref = w.find('./Related_Weaknesses/Related_Weakness[@Nature="ChildOf"][@Ordinal="Primary"][@View_ID="1000"][@CWE_ID]', namespaces=cwe_xml.nsmap) | ||
cwes.append({ | ||
'id': int(w.attrib['ID']), | ||
'name': w.attrib['Name'], | ||
'description': w.find('./Description', namespaces=cwe_xml.nsmap).text, | ||
'parent': int(parent_ref.attrib['CWE_ID']) if parent_ref is not None else None, | ||
}) | ||
|
||
cwes = sorted(cwes, key=lambda cwe: cwe['id']) | ||
out_path = Path(__file__).parent / 'src/reportcreator_api/pentests/customfields/cwe.json' | ||
out_path.write_text(json.dumps(cwes, indent=2)) | ||
|
||
|
||
|
||
if __name__ == '__main__': | ||
main() |
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
Oops, something went wrong.