kodon 0.0.1__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 (59) hide show
  1. kodon-0.0.1/.gitignore +32 -0
  2. kodon-0.0.1/LICENSE +201 -0
  3. kodon-0.0.1/PKG-INFO +291 -0
  4. kodon-0.0.1/README.md +259 -0
  5. kodon-0.0.1/coverage/attack_scope.yml +30 -0
  6. kodon-0.0.1/pipelines/kql_tables.yml +72 -0
  7. kodon-0.0.1/pipelines/synthetic_canonical.yml +71 -0
  8. kodon-0.0.1/pyproject.toml +76 -0
  9. kodon-0.0.1/rules/email/xmailer_cli_mailer_anomaly.yml +52 -0
  10. kodon-0.0.1/rules/identity/inbox_rule_external_forward.yml +49 -0
  11. kodon-0.0.1/rules/identity/mfa_success_multi_country_window.yml +62 -0
  12. kodon-0.0.1/rules/identity/oauth_consent_mail_files_scopes_by_user.yml +54 -0
  13. kodon-0.0.1/rules/network/beacon_fixed_destination_high_count.yml +73 -0
  14. kodon-0.0.1/rules/network/reverse_shell_conn_shape.yml +58 -0
  15. kodon-0.0.1/rules/windows/kerberos_rc4_tgs_volume_single_host.yml +62 -0
  16. kodon-0.0.1/rules/windows/msbuild_masquerade_network_egress.yml +53 -0
  17. kodon-0.0.1/rules/windows/nltest_domain_trust_enum_workstation.yml +53 -0
  18. kodon-0.0.1/rules/windows/wmi_remote_process_creation.yml +61 -0
  19. kodon-0.0.1/scripts/coverage_report.py +30 -0
  20. kodon-0.0.1/scripts/gen_samples.py +33 -0
  21. kodon-0.0.1/scripts/ip_scan.sh +178 -0
  22. kodon-0.0.1/scripts/ip_scan.sha256 +3 -0
  23. kodon-0.0.1/scripts/ip_scan_selftest.sh +173 -0
  24. kodon-0.0.1/scripts/setup-private-terms.sh +56 -0
  25. kodon-0.0.1/src/kodon/__init__.py +30 -0
  26. kodon-0.0.1/src/kodon/cli.py +133 -0
  27. kodon-0.0.1/src/kodon/compile.py +115 -0
  28. kodon-0.0.1/src/kodon/contracts.py +100 -0
  29. kodon-0.0.1/src/kodon/coverage.py +70 -0
  30. kodon-0.0.1/src/kodon/duckdb_backend.py +80 -0
  31. kodon-0.0.1/src/kodon/kusto_backend.py +42 -0
  32. kodon-0.0.1/src/kodon/loader.py +197 -0
  33. kodon-0.0.1/src/kodon/replay.py +115 -0
  34. kodon-0.0.1/src/kodon/synth.py +360 -0
  35. kodon-0.0.1/tests/conftest.py +21 -0
  36. kodon-0.0.1/tests/samples/beacon_fixed_destination_high_count/hit.jsonl +23 -0
  37. kodon-0.0.1/tests/samples/beacon_fixed_destination_high_count/miss.jsonl +76 -0
  38. kodon-0.0.1/tests/samples/inbox_rule_external_forward/hit.jsonl +2 -0
  39. kodon-0.0.1/tests/samples/inbox_rule_external_forward/miss.jsonl +4 -0
  40. kodon-0.0.1/tests/samples/kerberos_rc4_tgs_volume_single_host/hit.jsonl +16 -0
  41. kodon-0.0.1/tests/samples/kerberos_rc4_tgs_volume_single_host/miss.jsonl +41 -0
  42. kodon-0.0.1/tests/samples/mfa_success_multi_country_window/hit.jsonl +3 -0
  43. kodon-0.0.1/tests/samples/mfa_success_multi_country_window/miss.jsonl +6 -0
  44. kodon-0.0.1/tests/samples/msbuild_masquerade_network_egress/hit.jsonl +2 -0
  45. kodon-0.0.1/tests/samples/msbuild_masquerade_network_egress/miss.jsonl +4 -0
  46. kodon-0.0.1/tests/samples/nltest_domain_trust_enum_workstation/hit.jsonl +2 -0
  47. kodon-0.0.1/tests/samples/nltest_domain_trust_enum_workstation/miss.jsonl +4 -0
  48. kodon-0.0.1/tests/samples/oauth_consent_mail_files_scopes_by_user/hit.jsonl +2 -0
  49. kodon-0.0.1/tests/samples/oauth_consent_mail_files_scopes_by_user/miss.jsonl +4 -0
  50. kodon-0.0.1/tests/samples/reverse_shell_conn_shape/hit.jsonl +2 -0
  51. kodon-0.0.1/tests/samples/reverse_shell_conn_shape/miss.jsonl +6 -0
  52. kodon-0.0.1/tests/samples/wmi_remote_process_creation/hit.jsonl +2 -0
  53. kodon-0.0.1/tests/samples/wmi_remote_process_creation/miss.jsonl +3 -0
  54. kodon-0.0.1/tests/samples/xmailer_cli_mailer_anomaly/hit.jsonl +3 -0
  55. kodon-0.0.1/tests/samples/xmailer_cli_mailer_anomaly/miss.jsonl +4 -0
  56. kodon-0.0.1/tests/test_coverage.py +36 -0
  57. kodon-0.0.1/tests/test_rules_compile.py +64 -0
  58. kodon-0.0.1/tests/test_rules_replay.py +62 -0
  59. kodon-0.0.1/tests/test_rules_validate.py +100 -0
kodon-0.0.1/.gitignore ADDED
@@ -0,0 +1,32 @@
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *.egg-info/
5
+ build/
6
+ dist/
7
+ .eggs/
8
+
9
+ # Environments
10
+ .venv/
11
+ venv/
12
+
13
+ # Tooling
14
+ .pytest_cache/
15
+ .ruff_cache/
16
+ .mypy_cache/
17
+ .coverage
18
+ htmlcov/
19
+
20
+ # Editors / OS
21
+ .idea/
22
+ .vscode/
23
+ *.swp
24
+ .DS_Store
25
+
26
+ # Scan output and collected telemetry (never commit)
27
+ scan-results/
28
+ collected/
29
+
30
+ # Local secrets and private notes (never commit)
31
+ .env
32
+ *.private
kodon-0.0.1/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 Mark Peters
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
kodon-0.0.1/PKG-INFO ADDED
@@ -0,0 +1,291 @@
1
+ Metadata-Version: 2.5
2
+ Name: kodon
3
+ Version: 0.0.1
4
+ Summary: Detection-as-code: Sigma rules compiled to Splunk SPL, Sentinel KQL and DuckDB SQL, replay-tested on synthetic telemetry.
5
+ Project-URL: Homepage, https://github.com/markrpeters/kodon
6
+ Project-URL: Issues, https://github.com/markrpeters/kodon/issues
7
+ Author: Mark Peters
8
+ License-Expression: Apache-2.0
9
+ License-File: LICENSE
10
+ Keywords: attack,detection-as-code,detection-engineering,dfir,duckdb,kql,sentinel,sigma,splunk
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Intended Audience :: Information Technology
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.10
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Classifier: Programming Language :: Python :: 3.14
19
+ Classifier: Topic :: Security
20
+ Requires-Python: >=3.10
21
+ Requires-Dist: duckdb>=1.1
22
+ Requires-Dist: pydantic<3,>=2
23
+ Requires-Dist: pysigma-backend-kusto<2,>=1.0
24
+ Requires-Dist: pysigma-backend-splunk<3,>=2.1
25
+ Requires-Dist: pysigma-backend-sqlite<2,>=1.2
26
+ Requires-Dist: pysigma<2,>=1.5
27
+ Requires-Dist: pyyaml>=6
28
+ Provides-Extra: dev
29
+ Requires-Dist: pytest>=8; extra == 'dev'
30
+ Requires-Dist: ruff>=0.5; extra == 'dev'
31
+ Description-Content-Type: text/markdown
32
+
33
+ # kodon
34
+
35
+ [![ci](https://github.com/markrpeters/kodon/actions/workflows/ci.yml/badge.svg)](https://github.com/markrpeters/kodon/actions/workflows/ci.yml)
36
+
37
+ Detections should be files in a repo, not rules in a console: version-controlled,
38
+ reviewed, tested against data that must trigger them and data that must not,
39
+ validated in CI, mapped to ATT&CK with the gaps listed, and deployed from the
40
+ pipeline rather than by hand. kodon is that lifecycle. Rules are written in
41
+ Sigma (vendor-neutral), compiled to Splunk SPL, Microsoft Sentinel KQL and
42
+ DuckDB SQL with pySigma, and replay-tested against synthetic telemetry in
43
+ DuckDB. pySigma does the compiling; what kodon adds is the contract around
44
+ each rule (required metadata, generated must-hit and must-not-hit samples,
45
+ replay, a declared ATT&CK scope) and the CI that enforces it.
46
+
47
+ Ten rules ship today, each built around a pattern the author has had to
48
+ detect in practice. Each carries a must-hit and a must-not-hit
49
+ sample set, an ATT&CK mapping, and a `do_not_alert_when` block that says when
50
+ the rule should run as a hunt query rather than page as an alert. Status: 0.0.1, alpha, a personal project.
51
+ Requires Python 3.10 or newer; the test suite runs offline in about a second.
52
+
53
+ ## 30-second demo
54
+
55
+ ```bash
56
+ git clone https://github.com/markrpeters/kodon && cd kodon
57
+ python -m venv .venv && . .venv/bin/activate
58
+ pip install -e '.[dev]'
59
+ kodon demo
60
+ ```
61
+
62
+ The demo generates the seeded samples into a temporary directory, validates
63
+ every rule against the metadata contract, compiles all of them to the three
64
+ targets, replays the DuckDB SQL over the samples, and prints the coverage
65
+ matrix. A rule looks like this (excerpt of
66
+ `rules/windows/nltest_domain_trust_enum_workstation.yml`):
67
+
68
+ ```yaml
69
+ detection:
70
+ selection:
71
+ Image|endswith: '\nltest.exe'
72
+ CommandLine|contains:
73
+ - 'domain_trusts'
74
+ - 'all_trusts'
75
+ - 'trusted_domains'
76
+ - 'dclist'
77
+ - 'dsgetdc'
78
+ filter_domain_controllers:
79
+ ComputerName|startswith: 'HOST-DC'
80
+ filter_admin_tooling:
81
+ ParentImage|endswith:
82
+ - '\ServerManager.exe'
83
+ - '\dsac.exe'
84
+ condition: selection and not 1 of filter_*
85
+ custom:
86
+ do_not_alert_when: |
87
+ The parent is a known management tool or the user is in the directory
88
+ administrators group and the host is their assigned admin workstation;
89
+ filter by parent process, not by user name alone, because attackers run as
90
+ the compromised admin. Treat /dsgetdc on its own as a hunt (scripts use
91
+ it); /domain_trusts and /all_trusts from a standard user should alert.
92
+ ```
93
+
94
+ And the demo output, with one correlation rule shown in all three languages:
95
+
96
+ ```text
97
+ [1/5] generated seeded samples for 10 rules (57 must-hit rows, 152 must-miss rows)
98
+ [2/5] validated 10 rules against the metadata contract
99
+ [3/5] compiled 10 rules to splunk, kql, duckdb
100
+
101
+ example, mfa_success_multi_country_window:
102
+ --- splunk
103
+ eventType IN ("user.authentication.auth_via_mfa", "user.session.start") outcome.result="SUCCESS"
104
+ | bin _time span=1h
105
+ | stats dc(client.geographicalContext.country) as value_count by _time actor.alternateId
106
+ | search value_count >= 2
107
+ --- kql
108
+ Okta_CL
109
+ | where (eventType in~ ("user.authentication.auth_via_mfa", "user.session.start")) and ['outcome.result'] =~ "SUCCESS"
110
+ | summarize value_count = dcount(['client.geographicalContext.country']) by bin(TimeGenerated, 1h), ['actor.alternateId']
111
+ | where value_count >= 2
112
+ --- duckdb
113
+ SELECT time_bucket(INTERVAL '3600 seconds', ts) AS bucket, user, COUNT(DISTINCT src_country) AS value_count
114
+ FROM (SELECT * FROM events
115
+ WHERE (event_type ILIKE 'user.authentication.auth\_via\_mfa' ESCAPE '\'
116
+ OR event_type ILIKE 'user.session.start' ESCAPE '\')
117
+ AND outcome ILIKE 'SUCCESS' ESCAPE '\') AS subquery
118
+ GROUP BY 1, user HAVING COUNT(DISTINCT src_country) >= 2
119
+
120
+ [4/5] replay: compiled DuckDB SQL over the samples
121
+ (a rule passes when it matches at least one hit row and zero miss rows)
122
+ rule_id hit rows matched miss rows matched result
123
+ xmailer_cli_mailer_anomaly 3 2 4 0 PASS
124
+ inbox_rule_external_forward 2 1 4 0 PASS
125
+ mfa_success_multi_country_window 3 1 6 0 PASS
126
+ ...
127
+ kerberos_rc4_tgs_volume_single_host 16 1 41 0 PASS
128
+
129
+ [5/5] coverage
130
+ ATT&CK coverage: 12/24 in-scope techniques have at least one rule; 12 gaps
131
+ ```
132
+
133
+ The Splunk and KQL output is compiled, not deployed: field names stay Sigma's
134
+ until you pass your own field-mapping pipeline (see *How to compile*), and only
135
+ the DuckDB target is replay-tested.
136
+
137
+ ## The rules
138
+
139
+ | rule | logsource | technique | kind |
140
+ |---|---|---|---|
141
+ | `identity/mfa_success_multi_country_window` | okta | T1078.004, T1621 | correlation |
142
+ | `identity/inbox_rule_external_forward` | m365 exchange | T1114.003 | event |
143
+ | `identity/oauth_consent_mail_files_scopes_by_user` | azure auditlogs | T1528 | event |
144
+ | `windows/msbuild_masquerade_network_egress` | windows network_connection | T1127.001, T1036.005 | event |
145
+ | `windows/nltest_domain_trust_enum_workstation` | windows process_creation | T1482 | event |
146
+ | `windows/wmi_remote_process_creation` | windows process_creation | T1047 | event |
147
+ | `windows/kerberos_rc4_tgs_volume_single_host` | windows security | T1558.003 | correlation |
148
+ | `network/beacon_fixed_destination_high_count` | zeek conn | T1071.001 | correlation |
149
+ | `network/reverse_shell_conn_shape` | zeek conn | T1571 | event |
150
+ | `email/xmailer_cli_mailer_anomaly` | zeek smtp | T1048.003 | event |
151
+
152
+ The patterns are well known and several have SigmaHQ cousins; the selections,
153
+ filters, samples and `do_not_alert_when` text here are written from scratch,
154
+ and each rule cites the ATT&CK page for its technique.
155
+
156
+ ## How to add a rule
157
+
158
+ 1. Write `rules/<domain>/<rule_id>.yml` in Sigma. The file stem is the rule id.
159
+ The Sigma `id` is derived, not invented: `uuid5(NAMESPACE_URL, "kodon:<rule_id>")`
160
+ written as 32 hex characters (see *Design notes* for why no hyphens).
161
+ The loader refuses any other value.
162
+ 2. Fill the metadata contract. Besides the Sigma fields the loader requires
163
+ `status`, `level`, `date`, at least one `attack.tNNNN` tag and one
164
+ `attack.<tactic>` tag, a non-empty `falsepositives` list, and a `custom`
165
+ block:
166
+
167
+ ```yaml
168
+ custom:
169
+ data_sources: [what log this needs, precisely]
170
+ do_not_alert_when: |
171
+ The judgment call: the conditions under which this stays a hunt.
172
+ detection_health: {added: 2026-09-18, last_reviewed: 2026-09-18, owner: Mark Peters}
173
+ ```
174
+
175
+ `do_not_alert_when` is mandatory and is the most important field in the
176
+ file. A rule that cannot say when it should not fire is not finished.
177
+ 3. For a threshold rule, append a Sigma correlation document to the same file
178
+ (`event_count` or `value_count`, with `group-by` and `timespan`). Give the
179
+ base rule a `name` and reference it. Three of the shipped rules show this.
180
+ 4. Add a generator to `src/kodon/synth.py` under `@generator("<rule_id>")`
181
+ that returns the must-hit rows and the must-not-hit rows, then run
182
+ `python scripts/gen_samples.py` to write `tests/samples/<rule_id>/`.
183
+ Samples are never written by hand; a test regenerates them from the seed
184
+ and compares byte for byte with the committed files. Put the near-misses in
185
+ the miss set: the legitimate path, the domain controller, the machine
186
+ account, the admin consent. Those rows are what the filters are for.
187
+ 5. If the technique is new, add it to `coverage/attack_scope.yml`.
188
+ 6. `pytest`. A rule without both sample sets, or with a miss that matches,
189
+ does not merge.
190
+
191
+ ## How to compile
192
+
193
+ ```bash
194
+ kodon compile --target splunk
195
+ kodon compile --target kql --rule wmi_remote_process_creation
196
+ kodon compile --target duckdb
197
+ ```
198
+
199
+ Field names in the Splunk and KQL output are the Sigma taxonomy names
200
+ (`Image`, `CommandLine`, `id.orig_h`). Mapping them onto a deployment's real
201
+ columns is a pySigma processing pipeline the deployment owns; pass it as
202
+ `pipeline=` to `kodon.compile_rule`. `pipelines/synthetic_canonical.yml` is
203
+ the public example of that file: it maps the same names onto the synthetic
204
+ schema the tests run against. A deployment ships its own copy for its own
205
+ schema and nothing else changes. `pipelines/kql_tables.yml` picks the Sentinel
206
+ table per logsource.
207
+
208
+ ## How to test
209
+
210
+ ```bash
211
+ pytest # validate, compile, replay, coverage; offline
212
+ kodon test # the replay table only
213
+ kodon validate # the metadata contract only
214
+ ```
215
+
216
+ Replay is the gate: each rule's DuckDB SQL runs over
217
+ `tests/samples/<rule_id>/hit.jsonl` and must match at least one row, then over
218
+ `miss.jsonl` and must match none. It is a regression test against synthetic
219
+ rows, not proof against production telemetry; that proof comes from the
220
+ deployment's own data once the rule is compiled for it. Hits come back as
221
+ `DetectionHit` records (rule id, technique, severity, the matched row or the
222
+ matched aggregate), the same contract a downstream consumer receives from
223
+ `kodon.replay`.
224
+
225
+ ## Coverage report
226
+
227
+ ```bash
228
+ kodon coverage # text matrix, gaps marked
229
+ kodon coverage --json # the CoverageReport contract
230
+ ```
231
+
232
+ Gaps are computed against the declared scope in `coverage/attack_scope.yml`,
233
+ not against all of ATT&CK. The scope is a choice, so the percentage is too; a
234
+ matrix that is red everywhere says nothing, and a scope says what the rule
235
+ set was meant to cover. The gaps are the work list. CI uploads the report as
236
+ an artifact on every push.
237
+
238
+ ## Design notes
239
+
240
+ **Sigma ids without hyphens.** The data-hygiene scanner that gates every
241
+ commit and CI run (`scripts/ip_scan.sh`) flags hyphenated UUIDs, and exempting
242
+ the rules directory would leave the files most likely to carry a copied
243
+ identifier unscanned. Python's `uuid.UUID` and pySigma both accept the 32-hex
244
+ form, and ids are derived from the rule id so they are reproducible.
245
+
246
+ **Correlation windows are fixed buckets.** All three targets aggregate into
247
+ fixed time buckets (`bin _time span=`, `bin(TimeGenerated, …)`,
248
+ `time_bucket(INTERVAL …)`). A burst that straddles a bucket boundary can be
249
+ missed; a sliding window is a roadmap item, not something to hide.
250
+
251
+ **KQL correlations are kodon's.** pySigma's Kusto backend (1.0) does not emit
252
+ correlation rules, so kodon appends the `summarize` clause itself, using the
253
+ same fields and window the other two targets use. kodon's DuckDB backend is a
254
+ thin subclass of the maintained pySigma SQLite backend: `ILIKE` because Sigma
255
+ matching is case-insensitive and DuckDB's `LIKE` is not, `regexp_matches()`
256
+ because DuckDB has no `REGEXP`, and the time bucketing above. Underscores in
257
+ values are escaped (`auth\_via\_mfa`) because `_` is a `LIKE` wildcard.
258
+
259
+ **Synthetic address plan.** Samples use the RFC 5737 documentation ranges:
260
+ 192.0.2.0/24 plays the inside network, 198.51.100.0/24 and 203.0.113.0/24 the
261
+ outside. Domains are RFC 2606 (`example.com` is the organisation). Hosts are
262
+ HOST-A, HOST-B, HOST-C and the domain controller HOST-DC1. Where a rule needs
263
+ an "internal" range or a naming prefix, it uses these, with a comment that a
264
+ deployment substitutes its own.
265
+
266
+ **One-way dependency.** kodon is also a library, used by a separate private
267
+ project of the author's that passes its own field-mapping pipeline and
268
+ consumes the `DetectionHit` records. Nothing private is referenced, imported
269
+ or tested here; the scanner and its self-test run in CI and as a pre-commit
270
+ hook to keep it that way.
271
+
272
+ ## Roadmap
273
+
274
+ - Sliding-window correlations, and interval-variance scoring for the beacon
275
+ rule (periodicity, not just count).
276
+ - More rules, generalised from hunt queries in the downstream project.
277
+ - Optional Defender XDR and Sentinel ASIM field mapping for the Windows
278
+ categories via the pipelines that ship with pysigma-backend-kusto.
279
+ - Deployment: push compiled output to a SIEM from CI. Compile is the
280
+ deliverable today; deployment is deliberately not.
281
+
282
+ ## Why the name
283
+
284
+ A codon is the smallest unit of genetic code that encodes one instruction. A
285
+ rule here is one encoded instruction: a Sigma file with its samples and
286
+ metadata, compiled into whichever language the target speaks. The k is a
287
+ spelling swap to stay clear of the Codon compiler.
288
+
289
+ ## License
290
+
291
+ Apache-2.0. Copyright 2026 Mark Peters ([github.com/markrpeters](https://github.com/markrpeters)).