-
-
Notifications
You must be signed in to change notification settings - Fork 97
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
Closed
Closed
Capec scripts #2054
Changes from 10 commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
1805397
Adding more tests and refactoring code in order to improve the overal…
sydseter 39fcbb2
Get rid of warnings
sydseter ca273ec
Remove script
sydseter 9793bbf
Fix linux build issue
sydseter bf077c3
Try to resolve path depending on os
sydseter 2e4d7e1
Adding capec scripts
sydseter 7409bb2
Fix convert test
sydseter 509c618
Fix style issues
sydseter f5e6b74
Fix test and formating
sydseter 2aa8400
Fix code style issues
sydseter 062b036
Fix build issues
sydseter 69e3d65
Resolve merge issues
sydseter 6fa8fa4
Resolve merge issues
sydseter 46c04b6
Update lock file
sydseter e814e1f
Fix coding style issues
sydseter d768c12
Fix possible type juggling issues
sydseter 60f003a
Fix style isues for dockerfile
sydseter 286fcbb
Fix more coding style issues
sydseter 712c252
Fix coding issues
sydseter ebd678b
Fix coding style issues
sydseter 94adcac
Try to fix clusterfuck
sydseter 0b9c86a
Fix test issues after code style improvements
sydseter 5a2d087
Fix formating
sydseter 6952670
Fix coding style issues
sydseter 58a2825
Try different package
sydseter 3e1085f
Update deps
sydseter 6ca87b6
Install the clusterfuck dependencies in two runs
sydseter c9a901e
Abort clusterfuck linting fixes
sydseter dd74ecd
Ensure build breaks if the coverage is too low
sydseter 020188f
Add vitest.config
sydseter f5ada75
Correctly update deps
sydseter ce8af4d
Try to go back to the previous know good state
sydseter ad0fd36
Fix the fuzzer
sydseter 4817ee1
Upgrade to python 3.12 and fix the fuzzers
sydseter bf645e6
Ensure pipenv is installe
sydseter 9cf2794
Ensure lf is correct
sydseter File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -89,6 +89,97 @@ options: | |
| You can also speficy your own layout. If so, there needs to be a yaml file in the source folder where the name contains the layout code. Eg. edition-layout-ver-lang.yaml | ||
| ``` | ||
|
|
||
| ## Additional Utility Scripts | ||
|
|
||
| ### Converting CAPEC Data | ||
|
|
||
| The `scripts/convertCAPEC.py` script converts CAPEC (Common Attack Pattern Enumeration and Classification) JSON data into Markdown format for the Cornucopia website taxonomy. | ||
|
|
||
| ```bash | ||
| python ./scripts/convertCAPEC.py --help | ||
| usage: convertCAPEC.py [-h] [-o OUTPUT_PATH] [-i INPUT_PATH] [-d] | ||
|
|
||
| Convert CAPEC JSON to Cornucopia format | ||
|
|
||
| options: | ||
| -h, --help show this help message and exit | ||
| -o OUTPUT_PATH, --output-path OUTPUT_PATH | ||
| Path to store converted CAPEC files | ||
| -i INPUT_PATH, --input-path INPUT_PATH | ||
| Path to read CAPEC JSON files from | ||
| -d, --debug Output additional information to debug script | ||
| ``` | ||
|
|
||
| **Example usage:** | ||
|
|
||
| ```bash | ||
| # Convert CAPEC data using default paths | ||
| python scripts/convertCAPEC.py | ||
|
|
||
| # Convert with custom input and output paths | ||
| python scripts/convertCAPEC.py -i data/capec-3.9/3000.json -o cornucopia.owasp.org/data/taxonomy/en/CAPEC-3.9 | ||
|
|
||
| # Enable debug logging | ||
| python scripts/convertCAPEC.py -d | ||
| ``` | ||
|
|
||
| **Default paths:** | ||
|
|
||
| - Input: `cornucopia.owasp.org/data/capec-3.9/3000.json` | ||
|
sydseter marked this conversation as resolved.
sydseter marked this conversation as resolved.
|
||
| - Output: `cornucopia.owasp.org/data/taxonomy/en/CAPEC-3.9/` | ||
|
sydseter marked this conversation as resolved.
sydseter marked this conversation as resolved.
|
||
|
|
||
| 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.py` script processes webapp-mappings YAML files and generates a consolidated CAPEC-to-ASVS (Application Security Verification Standard) mapping file. | ||
|
|
||
| ```bash | ||
| python ./scripts/convertCAPECMapToASVSMap.py --help | ||
| usage: convertCAPECMapToASVSMap.py [-h] [-i INPUT_PATH] [-o OUTPUT_PATH] [-d] | ||
|
|
||
| Convert webapp-mappings YAML to CAPEC-to-ASVS mapping format | ||
|
|
||
| options: | ||
| -h, --help show this help message and exit | ||
| -i INPUT_PATH, --input-path INPUT_PATH | ||
| Path to input webapp-mappings YAML file | ||
| -o OUTPUT_PATH, --output-path OUTPUT_PATH | ||
| Path to save converted CAPEC-to-ASVS mapping YAML file | ||
| -d, --debug Output additional information to debug script | ||
| ``` | ||
|
|
||
| **Example usage:** | ||
|
|
||
| ```bash | ||
|
sydseter marked this conversation as resolved.
|
||
| # Convert mappings using default paths | ||
| python scripts/convertCAPECMapToASVSMap.py | ||
|
|
||
| # Convert with custom input and output paths | ||
| python scripts/convertCAPECMapToASVSMap.py -i source/webapp-mappings-3.0.yaml -o source/webapp-capec-3.0.yaml | ||
|
|
||
| # Enable debug logging | ||
| python scripts/convertCAPECMapToASVSMap.py -d | ||
| ``` | ||
|
|
||
| **Default paths:** | ||
|
|
||
| - Input: `source/webapp-mappings-3.0.yaml` | ||
|
sydseter marked this conversation as resolved.
sydseter marked this conversation as resolved.
|
||
| - Output: `source/webapp-capec-3.0.yaml` | ||
|
Contributor
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.
qltysh[bot] marked this conversation as resolved.
|
||
|
|
||
| The script: | ||
| 1. Reads CAPEC mappings from the `suits -> cards -> capec_map` structure | ||
|
Contributor
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.
qltysh[bot] marked this conversation as resolved.
|
||
| 2. Merges all OWASP ASVS requirements for each unique CAPEC code | ||
| 3. Outputs a unified YAML file mapping CAPEC codes to their associated ASVS requirements | ||
|
|
||
| **Output format:** | ||
| ```yaml | ||
|
Contributor
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.
qltysh[bot] marked this conversation as resolved.
|
||
| 54: | ||
| owasp_asvs: [4.3.2, 13.2.2, 13.4.1, ...] | ||
| 116: | ||
| owasp_asvs: [13.2.2, 15.2.3, ...] | ||
| ``` | ||
|
|
||
| ## Printing | ||
|
|
||
| The latest printable files are released under the [pre-release](https://github.com/OWASP/cornucopia/releases/tag/pre-release). Please download final printable files from there. | ||
|
|
@@ -175,7 +266,7 @@ On Mac OSX and Ubuntu you may not need to go through all of these steps, but thi | |
| # python -c "import os, sys; print(os.path.dirname(sys.executable))" | ||
| python -m pipenv shell --python "{path to python}" | ||
| pip install pipenv | ||
| pipenv install | ||
| pipenv install --dev | ||
|
|
||
|
|
||
| ### Coding style | ||
|
|
@@ -199,6 +290,40 @@ Run Coding Style Check | |
| pipenv run flake8 --max-line-length=120 --max-complexity=10 --ignore=E203,W503 --exclude ./.venv/ | ||
| pipenv run mypy --namespace-packages --strict ./scripts/ | ||
|
|
||
| ### Docker container | ||
|
|
||
| You can also run the converter inside a docker container. To build the container run: | ||
|
|
||
| ```powershell | ||
| docker build --target pipenv ` | ||
| --build-arg user_id=1000 ` | ||
| --build-arg group_id=1000 ` | ||
| --build-arg home=/home/builder ` | ||
| --build-arg workdir=/workspace ` | ||
| -t cornucopia-converter . | ||
| ``` | ||
|
|
||
| To login to the container and mount the current working directory inside the container run: | ||
|
|
||
| ```powershell | ||
| docker run --rm -it --entrypoint "/bin/bash" -v ${PWD}:/workspace cornucopia-converter | ||
| ``` | ||
|
|
||
| Run the converter tests inside the container: | ||
|
|
||
| ```powershell | ||
|
|
||
| #unit tests | ||
| docker run --rm -v ${PWD}:/workspace cornucopia-converter run coverage run --append --branch --omit "*_?test.py,*/.local/*" --module unittest discover --verbose --start-directory "tests/scripts" --pattern "*_utest.py" | ||
|
|
||
| #integration tests | ||
| docker run --rm -v ${PWD}:/workspace cornucopia-converter run coverage run --append --branch --omit "*_?test.py,*/.local/*" --module unittest discover --verbose --start-directory "tests/scripts" --pattern "*_utest.py" | ||
|
|
||
| #See code coverage | ||
| docker run --rm -v ${PWD}:/workspace cornucopia-converter run coverage report scripts/convert.py | ||
|
|
||
| ``` | ||
|
|
||
| ### Static analysis | ||
|
|
||
| run static analysis checks | ||
|
|
||
This file contains hidden or 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 hidden or 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,6 @@ | ||
| export type Deck = | ||
| { | ||
| edition : string, | ||
| version : string, | ||
| lang : string[] | ||
| } |
84 changes: 84 additions & 0 deletions
84
cornucopia.owasp.org/src/domain/mapping/mappingController.test.ts
This file contains hidden or 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,84 @@ | ||
| import {expect, describe, it} from 'vitest'; | ||
| import { MappingController } from './mappingController'; | ||
|
|
||
|
|
||
| describe('MappingController tests', () => { | ||
| it("should return web app card mapping data.", async () => { | ||
|
|
||
| const mappingData = { | ||
| suits: [ | ||
| { | ||
| name: "Test Suit", | ||
| cards: [ | ||
| { | ||
| id: "webapp-1", | ||
| owasp_asvs: ["1.1", "1.2"], | ||
| name: "Test Card" | ||
| } | ||
| ] | ||
| } | ||
| ] | ||
| }; | ||
| const controller = new MappingController(mappingData); | ||
|
|
||
| const webAppMapping = controller.getWebAppCardMappings("webapp-1"); | ||
| expect(webAppMapping).toBeDefined(); | ||
| expect(webAppMapping.id).toBe("webapp-1"); | ||
| expect(webAppMapping.owasp_asvs).toEqual(["1.1", "1.2"]); | ||
| }); | ||
|
|
||
| it("should return mobile app card mapping data.", async () => { | ||
|
|
||
| const mappingData = { | ||
| suits: [ | ||
| { | ||
| name: "Test Suit", | ||
| cards: [ | ||
| { | ||
| id: "mobileapp-1", | ||
| owasp_masvs: ["MASVS-1", "MASVS-2"], | ||
| owasp_mastg: ["MASTG-1"], | ||
| capec: [1, 2], | ||
| safecode: [101, 102] | ||
| } | ||
| ] | ||
| } | ||
| ] | ||
| }; | ||
| const controller = new MappingController(mappingData); | ||
| const mobileAppMapping = controller.getMobileAppCardMappings("mobileapp-1"); | ||
| expect(mobileAppMapping).toBeDefined(); | ||
| expect(mobileAppMapping.id).toBe("mobileapp-1"); | ||
| expect(mobileAppMapping.owasp_masvs).toEqual(["MASVS-1", "MASVS-2"]); | ||
| expect(mobileAppMapping.capec).toEqual([1, 2]); | ||
| expect(mobileAppMapping.safecode).toEqual([101, 102]); | ||
|
|
||
| }); | ||
|
|
||
| it("should return empty mapping for non-existing card.", async () => { | ||
| const mappingData = { | ||
| suits: [] | ||
| }; | ||
| const controller = new MappingController(mappingData); | ||
| const webAppMapping = controller.getWebAppCardMappings("non-existing-card"); | ||
| expect(webAppMapping).toBeDefined(); | ||
| expect(Object.keys(webAppMapping).length).toBe(0); | ||
|
|
||
| const controller2 = new MappingController({}); | ||
| const webAppMapping2 = controller2.getWebAppCardMappings("non-existing-card"); | ||
| expect(webAppMapping2).toBeDefined(); | ||
| expect(Object.keys(webAppMapping2).length).toBe(0); | ||
| }); | ||
|
|
||
| it("should return meta information.", async () => { | ||
| const mappingData = { | ||
| meta: { version: "1.0", date: "2024-01-01" }, | ||
| suits: [] | ||
| }; | ||
| const controller = new MappingController(mappingData); | ||
| const meta = controller.getMeta(); | ||
| expect(meta).toBeDefined(); | ||
| expect(meta.version).toBe("1.0"); | ||
| expect(meta.date).toBe("2024-01-01"); | ||
| }); | ||
| }); |
This file contains hidden or 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 hidden or 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,14 @@ | ||
| import {expect, describe, it} from 'vitest'; | ||
| import { MASTG_TESTS_MAPPING } from './mastg'; | ||
|
|
||
| describe('MASTG_TESTS_MAPPING tests', () => { | ||
| it("should have correct mapping for TEST-0001 to TEST-0059.", async () => { | ||
| expect(MASTG_TESTS_MAPPING["TEST-0001"]).toBe("STORAGE"); | ||
| expect(MASTG_TESTS_MAPPING["TEST-0025"]).toBe("CODE"); | ||
|
|
||
| expect(MASTG_TESTS_MAPPING["TEST-0038"]).toBe("RESILIENCE"); | ||
| expect(MASTG_TESTS_MAPPING["TEST-0059"]).toBe("PLATFORM"); | ||
| expect(MASTG_TESTS_MAPPING["TEST-00600"]).toBeUndefined(); | ||
| expect(Object.keys(MASTG_TESTS_MAPPING).length).toBe(93); | ||
| }); | ||
| }); |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.