-
-
Notifications
You must be signed in to change notification settings - Fork 42
Capec scripts #2054
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
base: master
Are you sure you want to change the base?
Capec scripts #2054
Conversation
❌ 9 blocking issues (39 total)
|
| ``` | ||
| **Example usage:** | ||
| ```bash |
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.
| ``` | ||
| **Default paths:** | ||
| - Input: `cornucopia.owasp.org/data/capec-3.9/3000.json` |
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.
| **Default paths:** | ||
| - Input: `cornucopia.owasp.org/data/capec-3.9/3000.json` | ||
| - Output: `cornucopia.owasp.org/data/taxonomy/en/CAPEC-3.9/` |
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.
| ``` | ||
| **Example usage:** | ||
| ```bash |
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.
| ``` | ||
| **Default paths:** | ||
| - Input: `source/webapp-mappings-3.0.yaml` |
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.
|
|
||
| def test_parse_all_arguments(self): | ||
| """Test parsing with all arguments""" | ||
| args = capec_map.parse_arguments(["-i", "input.yaml", "-o", "output.yaml", "-d"]) |
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.
| class TestParseDescription(unittest.TestCase): | ||
| def test_parse_description_with_dict_and_text(self): | ||
| """Test parsing description with __text field in dict""" | ||
| description = {"Description": {"p": {"__text": "This is a test description"}}} |
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.
| test_data = {"test": "data"} | ||
| mock_file = mock_open(read_data=json.dumps(test_data)) | ||
|
|
||
| with patch("builtins.open", mock_file): |
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.
| # Setup | ||
| test_output_path = Path("/test/output") | ||
| capec.convert_vars.args = argparse.Namespace( | ||
| output_path=test_output_path, input_path=Path("dummy.json"), debug=False |
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.
| "owasp_asvs": ["1.6.4", "2.10.4", "4.3.2", "7.1.1", "10.2.3", "14.1.1", "14.2.2", "14.3.3"], | ||
| "owasp_appsensor": ["HT1", "HT2", "HT3"], | ||
| "capec": [54, 541], | ||
| "url": "https://cornucopia.owasp.org/cards/VE2", |
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.
Define a constant instead of duplicating this literal "https://cornucopia\.owasp\.org/cards/VE2" 3 times. [radarlint-python:python:S1192]
| **Default paths:** | ||
| - Input: `cornucopia.owasp.org/data/capec-3.9/3000.json` |
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.
| **Default paths:** | ||
| - Input: `cornucopia.owasp.org/data/capec-3.9/3000.json` | ||
| - Output: `cornucopia.owasp.org/data/taxonomy/en/CAPEC-3.9/` |
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.
| **Default paths:** | ||
| - Input: `source/webapp-mappings-3.0.yaml` |
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.
| #!/usr/bin/env python3 | ||
| import unittest | ||
| import os | ||
| import sys |
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.
| import unittest | ||
| import os | ||
| import sys | ||
| import logging |
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.
| import tempfile | ||
| import shutil | ||
| from pathlib import Path | ||
| import yaml |
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.
| """Test saving a valid YAML file""" | ||
| data = {"key": "value"} | ||
|
|
||
| result = capec_map.save_yaml_file(Path("output.yaml"), data) |
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.
| @@ -0,0 +1,352 @@ | |||
| #!/usr/bin/env python3 | |||
| import unittest | |||
| from unittest.mock import patch, mock_open, MagicMock, call | |||
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.
| #!/usr/bin/env python3 | ||
| import unittest | ||
| import os | ||
| import sys |
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.
| import unittest | ||
| import os | ||
| import sys | ||
| import json |
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.
| first_name = first_pattern["_Name"] | ||
|
|
||
| pattern_dir = self.test_output_path / first_id | ||
| index_file = pattern_dir / "index.md" |
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.
|
|
||
|
|
||
| # Import argparse for the integration tests | ||
| import argparse |
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.
| @patch("os.makedirs") | ||
| def test_create_folder_new(self, mock_makedirs): | ||
| """Test creating a new folder""" | ||
| test_path = Path("/test/folder") |
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.
| def test_create_capec_pages_single_pattern(self, mock_create_folder, mock_file): | ||
| """Test creating CAPEC pages for a single attack pattern""" | ||
| # Setup | ||
| test_output_path = Path("/test/output") |
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.
| } | ||
|
|
||
| with patch.object(Path, "parent") as mock_parent: | ||
| mock_parent.resolve.return_value = Path("/mock/directory") |
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.
| "safecode": [4, 23], | ||
| "owasp_cre": { | ||
| "owasp_asvs": ["232-325", "774-888", "615-744", "067-050", "838-636", "253-452", "462-245", "743-110"] | ||
| }, |
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.
| "safecode": [4, 23], | ||
| "owasp_cre": { | ||
| "owasp_asvs": ["232-325", "774-888", "615-744", "067-050", "838-636", "253-452", "462-245", "743-110"] | ||
| }, |
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.
In this pull-request:
Additional Utility Scripts
Converting CAPEC Data
The
scripts/convertCAPEC.pyscript converts CAPEC (Common Attack Pattern Enumeration and Classification) JSON data into Markdown format for the Cornucopia website taxonomy.Example usage:
Default paths:
cornucopia.owasp.org/data/capec-3.9/3000.jsoncornucopia.owasp.org/data/taxonomy/en/CAPEC-3.9/The script creates individual Markdown files for each CAPEC attack pattern with descriptions and links to the official CAPEC database.
Converting CAPEC Mappings to ASVS Format
The
scripts/convertCAPECMapToASVSMap.pyscript processes webapp-mappings YAML files and generates a consolidated CAPEC-to-ASVS (Application Security Verification Standard) mapping file.Example usage:
Default paths:
source/webapp-mappings-3.0.yamlsource/webapp-capec-3.0.yamlThe script:
suits -> cards -> capec_mapstructureOutput format: