detect-forge 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (147) hide show
  1. detect_forge-0.1.0/.detect-forge.toml +19 -0
  2. detect_forge-0.1.0/.env.sample +27 -0
  3. detect_forge-0.1.0/.github/workflows/ci.yml +51 -0
  4. detect_forge-0.1.0/.github/workflows/python-publish.yml +77 -0
  5. detect_forge-0.1.0/.gitignore +20 -0
  6. detect_forge-0.1.0/CHANGELOG.md +34 -0
  7. detect_forge-0.1.0/LICENSE +21 -0
  8. detect_forge-0.1.0/PKG-INFO +521 -0
  9. detect_forge-0.1.0/README.md +473 -0
  10. detect_forge-0.1.0/RELEASING.md +45 -0
  11. detect_forge-0.1.0/pyproject.toml +105 -0
  12. detect_forge-0.1.0/scripts/bump_version.py +108 -0
  13. detect_forge-0.1.0/src/detect_forge/__init__.py +3 -0
  14. detect_forge-0.1.0/src/detect_forge/_stubs.py +31 -0
  15. detect_forge-0.1.0/src/detect_forge/_tactics.py +57 -0
  16. detect_forge-0.1.0/src/detect_forge/audit/__init__.py +27 -0
  17. detect_forge-0.1.0/src/detect_forge/audit/cli.py +229 -0
  18. detect_forge-0.1.0/src/detect_forge/audit/models.py +74 -0
  19. detect_forge-0.1.0/src/detect_forge/audit/orchestrator.py +208 -0
  20. detect_forge-0.1.0/src/detect_forge/audit/reporter.py +185 -0
  21. detect_forge-0.1.0/src/detect_forge/audit/scoring.py +90 -0
  22. detect_forge-0.1.0/src/detect_forge/audit/templates/report.html.j2 +79 -0
  23. detect_forge-0.1.0/src/detect_forge/backtest/__init__.py +103 -0
  24. detect_forge-0.1.0/src/detect_forge/backtest/cli.py +152 -0
  25. detect_forge-0.1.0/src/detect_forge/backtest/corpus.py +246 -0
  26. detect_forge-0.1.0/src/detect_forge/backtest/corpus_data/__init__.py +0 -0
  27. detect_forge-0.1.0/src/detect_forge/backtest/corpus_data/mordor_index.json +183 -0
  28. detect_forge-0.1.0/src/detect_forge/backtest/matchers/__init__.py +1 -0
  29. detect_forge-0.1.0/src/detect_forge/backtest/matchers/_base.py +63 -0
  30. detect_forge-0.1.0/src/detect_forge/backtest/matchers/_kql.py +176 -0
  31. detect_forge-0.1.0/src/detect_forge/backtest/matchers/elastic.py +215 -0
  32. detect_forge-0.1.0/src/detect_forge/backtest/matchers/sigma.py +668 -0
  33. detect_forge-0.1.0/src/detect_forge/backtest/models.py +106 -0
  34. detect_forge-0.1.0/src/detect_forge/backtest/orchestrator.py +291 -0
  35. detect_forge-0.1.0/src/detect_forge/backtest/reporter.py +183 -0
  36. detect_forge-0.1.0/src/detect_forge/backtest/templates/report.html.j2 +95 -0
  37. detect_forge-0.1.0/src/detect_forge/cache.py +57 -0
  38. detect_forge-0.1.0/src/detect_forge/cli.py +26 -0
  39. detect_forge-0.1.0/src/detect_forge/common.py +43 -0
  40. detect_forge-0.1.0/src/detect_forge/config.py +198 -0
  41. detect_forge-0.1.0/src/detect_forge/console.py +18 -0
  42. detect_forge-0.1.0/src/detect_forge/coverage/__init__.py +82 -0
  43. detect_forge-0.1.0/src/detect_forge/coverage/analyzer.py +230 -0
  44. detect_forge-0.1.0/src/detect_forge/coverage/cli.py +129 -0
  45. detect_forge-0.1.0/src/detect_forge/coverage/models.py +94 -0
  46. detect_forge-0.1.0/src/detect_forge/coverage/priority.py +114 -0
  47. detect_forge-0.1.0/src/detect_forge/coverage/priority_data/MANIFEST.json +8 -0
  48. detect_forge-0.1.0/src/detect_forge/coverage/priority_data/__init__.py +0 -0
  49. detect_forge-0.1.0/src/detect_forge/coverage/priority_data/ctid_top_techniques_2024.json +34 -0
  50. detect_forge-0.1.0/src/detect_forge/coverage/reporter.py +211 -0
  51. detect_forge-0.1.0/src/detect_forge/coverage/templates/report.html.j2 +90 -0
  52. detect_forge-0.1.0/src/detect_forge/cti/__init__.py +0 -0
  53. detect_forge-0.1.0/src/detect_forge/cti/cli.py +28 -0
  54. detect_forge-0.1.0/src/detect_forge/exit_codes.py +11 -0
  55. detect_forge-0.1.0/src/detect_forge/py.typed +0 -0
  56. detect_forge-0.1.0/src/detect_forge/settings.py +27 -0
  57. detect_forge-0.1.0/src/detect_forge/stale/__init__.py +98 -0
  58. detect_forge-0.1.0/src/detect_forge/stale/_dates.py +40 -0
  59. detect_forge-0.1.0/src/detect_forge/stale/_proposals.py +201 -0
  60. detect_forge-0.1.0/src/detect_forge/stale/_semantic.py +88 -0
  61. detect_forge-0.1.0/src/detect_forge/stale/attack_client.py +156 -0
  62. detect_forge-0.1.0/src/detect_forge/stale/cli.py +126 -0
  63. detect_forge-0.1.0/src/detect_forge/stale/elastic_parser.py +99 -0
  64. detect_forge-0.1.0/src/detect_forge/stale/embeddings.py +152 -0
  65. detect_forge-0.1.0/src/detect_forge/stale/models.py +155 -0
  66. detect_forge-0.1.0/src/detect_forge/stale/prompts/__init__.py +0 -0
  67. detect_forge-0.1.0/src/detect_forge/stale/prompts/diff_proposal.j2 +28 -0
  68. detect_forge-0.1.0/src/detect_forge/stale/reporter.py +164 -0
  69. detect_forge-0.1.0/src/detect_forge/stale/rule_parser.py +57 -0
  70. detect_forge-0.1.0/src/detect_forge/stale/scorer.py +378 -0
  71. detect_forge-0.1.0/src/detect_forge/stale/sigma_parser.py +79 -0
  72. detect_forge-0.1.0/src/detect_forge/stale/templates/report.html.j2 +130 -0
  73. detect_forge-0.1.0/tests/__init__.py +0 -0
  74. detect_forge-0.1.0/tests/conftest.py +103 -0
  75. detect_forge-0.1.0/tests/fixtures/backtest/synthetic_dataset.zip +0 -0
  76. detect_forge-0.1.0/tests/fixtures/backtest/synthetic_events.json +5 -0
  77. detect_forge-0.1.0/tests/fixtures/backtest/synthetic_index.json +31 -0
  78. detect_forge-0.1.0/tests/fixtures/config/backtest_full.toml +5 -0
  79. detect_forge-0.1.0/tests/fixtures/config/backtest_invalid.toml +2 -0
  80. detect_forge-0.1.0/tests/fixtures/config/coverage_full.toml +3 -0
  81. detect_forge-0.1.0/tests/fixtures/config/coverage_invalid.toml +2 -0
  82. detect_forge-0.1.0/tests/fixtures/config/full.toml +4 -0
  83. detect_forge-0.1.0/tests/fixtures/config/invalid_threshold.toml +2 -0
  84. detect_forge-0.1.0/tests/fixtures/config/minimal.toml +1 -0
  85. detect_forge-0.1.0/tests/fixtures/coverage/custom_priority.json +6 -0
  86. detect_forge-0.1.0/tests/fixtures/coverage/malformed_priority.json +4 -0
  87. detect_forge-0.1.0/tests/fixtures/elastic/malformed.toml +3 -0
  88. detect_forge-0.1.0/tests/fixtures/elastic/minimal_eql.toml +24 -0
  89. detect_forge-0.1.0/tests/fixtures/elastic/minimal_kql.toml +24 -0
  90. detect_forge-0.1.0/tests/fixtures/elastic/no_techniques.toml +13 -0
  91. detect_forge-0.1.0/tests/fixtures/elastic/with_subtechnique.toml +32 -0
  92. detect_forge-0.1.0/tests/fixtures/enterprise-attack-mini.json +98 -0
  93. detect_forge-0.1.0/tests/fixtures/sigma/not_a_sigma_rule.yml +2 -0
  94. detect_forge-0.1.0/tests/fixtures/sigma/rule_deprecated_status.yml +9 -0
  95. detect_forge-0.1.0/tests/fixtures/sigma/rule_multiple_techniques.yml +12 -0
  96. detect_forge-0.1.0/tests/fixtures/sigma/rule_no_attack_tags.yml +10 -0
  97. detect_forge-0.1.0/tests/fixtures/sigma/rule_no_tags.yml +6 -0
  98. detect_forge-0.1.0/tests/fixtures/sigma/rule_with_description.yml +13 -0
  99. detect_forge-0.1.0/tests/fixtures/sigma/rule_with_parent_only.yml +10 -0
  100. detect_forge-0.1.0/tests/fixtures/sigma/rule_with_subtechnique.yml +12 -0
  101. detect_forge-0.1.0/tests/integration/__init__.py +0 -0
  102. detect_forge-0.1.0/tests/integration/test_semantic_e2e.py +38 -0
  103. detect_forge-0.1.0/tests/stubs/__init__.py +0 -0
  104. detect_forge-0.1.0/tests/stubs/test_stub_subcommands.py +32 -0
  105. detect_forge-0.1.0/tests/test_attack_client.py +190 -0
  106. detect_forge-0.1.0/tests/test_audit_api.py +32 -0
  107. detect_forge-0.1.0/tests/test_audit_cli.py +244 -0
  108. detect_forge-0.1.0/tests/test_audit_config.py +60 -0
  109. detect_forge-0.1.0/tests/test_audit_models.py +83 -0
  110. detect_forge-0.1.0/tests/test_audit_orchestrator.py +167 -0
  111. detect_forge-0.1.0/tests/test_audit_reporter.py +245 -0
  112. detect_forge-0.1.0/tests/test_audit_scoring.py +162 -0
  113. detect_forge-0.1.0/tests/test_backtest_cli.py +169 -0
  114. detect_forge-0.1.0/tests/test_backtest_corpus.py +252 -0
  115. detect_forge-0.1.0/tests/test_backtest_integration.py +254 -0
  116. detect_forge-0.1.0/tests/test_backtest_matchers_elastic.py +286 -0
  117. detect_forge-0.1.0/tests/test_backtest_matchers_sigma.py +838 -0
  118. detect_forge-0.1.0/tests/test_backtest_models.py +203 -0
  119. detect_forge-0.1.0/tests/test_backtest_orchestrator.py +248 -0
  120. detect_forge-0.1.0/tests/test_backtest_reporter.py +263 -0
  121. detect_forge-0.1.0/tests/test_bump_version.py +56 -0
  122. detect_forge-0.1.0/tests/test_cache.py +63 -0
  123. detect_forge-0.1.0/tests/test_cache_xdg.py +26 -0
  124. detect_forge-0.1.0/tests/test_cli.py +505 -0
  125. detect_forge-0.1.0/tests/test_common.py +69 -0
  126. detect_forge-0.1.0/tests/test_config.py +300 -0
  127. detect_forge-0.1.0/tests/test_console.py +18 -0
  128. detect_forge-0.1.0/tests/test_coverage_analyzer.py +273 -0
  129. detect_forge-0.1.0/tests/test_coverage_cli.py +195 -0
  130. detect_forge-0.1.0/tests/test_coverage_models.py +150 -0
  131. detect_forge-0.1.0/tests/test_coverage_priority.py +131 -0
  132. detect_forge-0.1.0/tests/test_coverage_reporter.py +294 -0
  133. detect_forge-0.1.0/tests/test_coverage_tactics.py +35 -0
  134. detect_forge-0.1.0/tests/test_elastic_parser.py +179 -0
  135. detect_forge-0.1.0/tests/test_embeddings.py +137 -0
  136. detect_forge-0.1.0/tests/test_exit_codes.py +13 -0
  137. detect_forge-0.1.0/tests/test_models.py +495 -0
  138. detect_forge-0.1.0/tests/test_proposals.py +262 -0
  139. detect_forge-0.1.0/tests/test_py_typed.py +8 -0
  140. detect_forge-0.1.0/tests/test_reporter.py +462 -0
  141. detect_forge-0.1.0/tests/test_rule_parser_dispatch.py +107 -0
  142. detect_forge-0.1.0/tests/test_scorer.py +604 -0
  143. detect_forge-0.1.0/tests/test_semantic_scorer.py +167 -0
  144. detect_forge-0.1.0/tests/test_settings.py +50 -0
  145. detect_forge-0.1.0/tests/test_sigma_parser.py +215 -0
  146. detect_forge-0.1.0/tests/test_stale_api.py +50 -0
  147. detect_forge-0.1.0/tests/test_version.py +8 -0
@@ -0,0 +1,19 @@
1
+ [stale]
2
+ semantic_threshold = 0.65
3
+ llm_model = "gpt-4o-mini"
4
+ max_proposals = 5
5
+
6
+ [coverage]
7
+ priority_list = "" # path to custom JSON; empty = built-in CTID default
8
+ gate_on_priority_gaps = true # exit 2 when priority techniques have no rules
9
+
10
+ [backtest]
11
+ gate_on_priority_silence = true # exit 2 when priority technique is silent
12
+ gate_on_broken_rules = true # exit 2 when any rule is silent on all tested datasets
13
+ mordor_source = "" # local Security-Datasets checkout; empty = fetch
14
+ platform = "all" # windows | linux | macos | all
15
+
16
+ [audit]
17
+ gate_strategy = "all" # "all" | "never". Default "all" (strict-AND).
18
+ subcommands = ["stale", "coverage", "backtest"] # subset to run
19
+ include_llm_proposals = false # cost gate; default off
@@ -0,0 +1,27 @@
1
+ # Copy this file to `.env` and fill in values. `.env` is gitignored.
2
+
3
+ # ---- LLM Diff Proposals (Phase 4) ----
4
+ # Required for LLM diff proposals on semantically drifted rules.
5
+ # When unset, scans complete normally with a skip banner.
6
+ OPENAI_API_KEY=
7
+
8
+ # ---- detect-forge Settings (DETECT_FORGE_* env-prefix) ----
9
+ # All optional; values override the built-in defaults.
10
+
11
+ # Cache directory for ATT&CK STIX bundles and embeddings.
12
+ # Default: $XDG_CACHE_HOME/detect-forge (or ~/.cache/detect-forge).
13
+ # DETECT_FORGE_CACHE_DIR=/path/to/cache
14
+
15
+ # How long the ATT&CK STIX bundle stays fresh before re-fetch.
16
+ # DETECT_FORGE_CACHE_TTL_HOURS=24
17
+
18
+ # Which ATT&CK domain to score against.
19
+ # Options: enterprise-attack, mobile-attack, ics-attack
20
+ # DETECT_FORGE_ATTACK_DOMAIN=enterprise-attack
21
+
22
+ # Disable cache entirely (re-fetch and re-embed on every run).
23
+ # DETECT_FORGE_NO_CACHE=false
24
+
25
+ # Override the semantic_threshold from .detect-forge.toml without editing
26
+ # the file. Takes precedence over CLI flag and config file.
27
+ # DETECT_FORGE_SEMANTIC_THRESHOLD=0.65
@@ -0,0 +1,51 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: ["**"]
6
+ pull_request:
7
+
8
+ permissions:
9
+ contents: read
10
+
11
+ jobs:
12
+ test:
13
+ name: lint + type-check + tests
14
+ runs-on: ubuntu-latest
15
+ steps:
16
+ - uses: actions/checkout@v7
17
+
18
+ - uses: actions/setup-python@v7
19
+ with:
20
+ python-version: "3.12"
21
+
22
+ - name: Install (with dev extras)
23
+ run: python -m pip install -e ".[dev]"
24
+
25
+ - name: Ruff
26
+ run: ruff check src/ tests/
27
+
28
+ - name: Mypy (strict)
29
+ run: mypy src/
30
+
31
+ - name: Pytest
32
+ run: pytest -q
33
+
34
+ build:
35
+ name: build + twine check
36
+ runs-on: ubuntu-latest
37
+ steps:
38
+ - uses: actions/checkout@v7
39
+
40
+ - uses: actions/setup-python@v7
41
+ with:
42
+ python-version: "3.12"
43
+
44
+ - name: Install build tooling
45
+ run: python -m pip install build twine
46
+
47
+ - name: Build distributions
48
+ run: python -m build
49
+
50
+ - name: Twine check
51
+ run: python -m twine check dist/*
@@ -0,0 +1,77 @@
1
+ # This workflow will upload a Python Package to PyPI when a release is created
2
+ # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-package-registries
3
+
4
+ # This workflow uses actions that are not certified by GitHub.
5
+ # They are provided by a third-party and are governed by
6
+ # separate terms of service, privacy policy, and support
7
+ # documentation.
8
+
9
+ name: Upload Python Package
10
+
11
+ on:
12
+ release:
13
+ types: [published]
14
+
15
+ permissions:
16
+ contents: read
17
+
18
+ jobs:
19
+ release-build:
20
+ runs-on: ubuntu-latest
21
+
22
+ steps:
23
+ - uses: actions/checkout@v7
24
+
25
+ - uses: actions/setup-python@v7
26
+ with:
27
+ python-version: "3.12"
28
+
29
+ - name: Install project + build tooling
30
+ run: python -m pip install -e ".[dev]" build
31
+
32
+ - name: Verify tag matches package version
33
+ run: |
34
+ PKG=$(python -c "import tomllib;print(tomllib.load(open('pyproject.toml','rb'))['project']['version'])")
35
+ TAG="${GITHUB_REF_NAME#v}"
36
+ test "$PKG" = "$TAG" || { echo "::error::release tag '$TAG' != package version '$PKG'"; exit 1; }
37
+
38
+ - name: Test
39
+ run: pytest -q
40
+
41
+ - name: Build release distributions
42
+ run: python -m build
43
+
44
+ - name: Twine check
45
+ run: python -m twine check dist/*
46
+
47
+ - name: Upload distributions
48
+ uses: actions/upload-artifact@v7
49
+ with:
50
+ name: release-dists
51
+ path: dist/
52
+
53
+ pypi-publish:
54
+ runs-on: ubuntu-latest
55
+ needs:
56
+ - release-build
57
+ permissions:
58
+ # IMPORTANT: this permission is mandatory for trusted publishing
59
+ id-token: write
60
+
61
+ # Dedicated environments with protections for publishing are strongly recommended.
62
+ # For more information, see: https://docs.github.com/en/actions/deployment/targeting-different-environments/using-environments-for-deployment#deployment-protection-rules
63
+ environment:
64
+ name: pypi
65
+ url: https://pypi.org/p/detect-forge
66
+
67
+ steps:
68
+ - name: Retrieve release distributions
69
+ uses: actions/download-artifact@v8
70
+ with:
71
+ name: release-dists
72
+ path: dist/
73
+
74
+ - name: Publish release distributions to PyPI
75
+ uses: pypa/gh-action-pypi-publish@release/v1
76
+ with:
77
+ packages-dir: dist/
@@ -0,0 +1,20 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ *$py.class
4
+ .Python
5
+ build/
6
+ dist/
7
+ *.egg-info/
8
+ .eggs/
9
+ .venv/
10
+ venv/
11
+ .env
12
+ .pytest_cache/
13
+ .mypy_cache/
14
+ .ruff_cache/
15
+ .coverage
16
+ htmlcov/
17
+ .DS_Store
18
+ data/
19
+ /docs/superpowers/
20
+ .claude/
@@ -0,0 +1,34 @@
1
+ # Changelog
2
+
3
+ All notable changes to Detect-Forge are documented here. The format is based
4
+ on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project
5
+ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
+
7
+ ## [Unreleased]
8
+
9
+ ## [0.1.0] - 2026-09-09
10
+
11
+ Initial public release.
12
+
13
+ ### Added
14
+ - `stale` — score Sigma/Elastic rules for ATT&CK technique staleness
15
+ (timestamp drift, semantic drift, opt-in LLM diff proposals).
16
+ - `coverage` — map rules to the ATT&CK matrix (full/shallow/gap) with
17
+ CTID-weighted priority gating and Navigator export.
18
+ - `backtest` — adversarial replay against the bundled Mordor corpus with
19
+ Sigma + Elastic (EQL/KQL) matchers and two CI gates.
20
+ - `audit` — one-step composite gate over stale + coverage + backtest.
21
+ - `cti ingest` registered as a stub (Q3–Q4 2026).
22
+
23
+ ### Fixed
24
+ - Sigma matcher correctness: plain-value wildcards, `all/1/N of them`,
25
+ case-insensitive matching, int/str coercion, list-valued fields, `field: null`.
26
+ - Backtest security: SHA256 verified before extraction, decompression size
27
+ caps, local-source path sanitization.
28
+ - Stale: undated rules no longer false-gate as critical; malformed tags/threat
29
+ no longer abort the scan; threshold range validation.
30
+ - Coverage/audit: empty/mistyped priority list is a loud error; sub-technique
31
+ coverage rolls up to parents; audit honors per-subcommand config + gate flags.
32
+
33
+ [Unreleased]: https://github.com/jamesbower/Detect-Forge/compare/v0.1.0...HEAD
34
+ [0.1.0]: https://github.com/jamesbower/Detect-Forge/releases/tag/v0.1.0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 James Bower
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.