@hoanghainh/komagu 2.2.1 → 2.3.0

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 (36) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/assess/lsa/scripts/attack_chains.py +573 -0
  3. package/assess/lsa/scripts/baseline.py +14 -0
  4. package/assess/lsa/scripts/findings_to_sarif.py +11 -0
  5. package/assess/lsa/scripts/forecast.py +544 -0
  6. package/assess/lsa/scripts/merge_findings.py +14 -0
  7. package/assess/lsa/scripts/render_report.py +86 -0
  8. package/assess/lsa/tests/test_attack_chains.py +292 -0
  9. package/assess/lsa/tests/test_forecast.py +160 -0
  10. package/contracts/schemas/api-inventory-diff.schema.json +213 -0
  11. package/contracts/schemas/attack-chain.schema.json +181 -0
  12. package/contracts/schemas/bas-scenario.schema.json +217 -0
  13. package/contracts/schemas/evidence-manifest.schema.json +117 -0
  14. package/contracts/schemas/finding.schema.json +7 -0
  15. package/contracts/schemas/forecast.schema.json +172 -0
  16. package/governance/scs/__init__.py +21 -0
  17. package/governance/scs/mapping.py +133 -0
  18. package/governance/scs/pack.py +354 -0
  19. package/operate/cli/__init__.py +1 -1
  20. package/operate/cli/commands/evidence.py +138 -0
  21. package/operate/cli/commands/inventory.py +187 -0
  22. package/operate/cli/commands/simulate.py +175 -58
  23. package/operate/cli/main.py +7 -3
  24. package/operate/inventory/__init__.py +22 -0
  25. package/operate/inventory/api_inventory.py +566 -0
  26. package/operate/simulate/__init__.py +16 -0
  27. package/operate/simulate/engine.py +370 -0
  28. package/operate/simulate/loader.py +158 -0
  29. package/operate/simulate/scenarios/idc-frontier-ransomware.json +47 -0
  30. package/operate/simulate/scenarios/metabase-cve-2026-72898.json +84 -0
  31. package/operate/simulate/scenarios/times-car-breach.json +74 -0
  32. package/operate/simulate/scenarios.py +52 -0
  33. package/operate/tests/test_api_inventory.py +239 -0
  34. package/operate/tests/test_declarative_scenarios.py +169 -0
  35. package/operate/tests/test_evidence_pack.py +128 -0
  36. package/package.json +1 -1
@@ -0,0 +1,213 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "lsa/api-inventory-diff.schema.json",
4
+ "title": "Komagu API Inventory Diff",
5
+ "type": "object",
6
+ "required": [
7
+ "version",
8
+ "generated_at",
9
+ "sources",
10
+ "summary",
11
+ "shadow_apis",
12
+ "zombie_apis",
13
+ "documented_missing_code",
14
+ "dormant_code"
15
+ ],
16
+ "properties": {
17
+ "version": {
18
+ "type": "integer",
19
+ "enum": [
20
+ 1
21
+ ]
22
+ },
23
+ "generated_at": {
24
+ "type": "string"
25
+ },
26
+ "sources": {
27
+ "type": "object",
28
+ "required": [
29
+ "routes_file",
30
+ "openapi_file"
31
+ ],
32
+ "properties": {
33
+ "routes_file": {
34
+ "type": [
35
+ "string",
36
+ "null"
37
+ ]
38
+ },
39
+ "openapi_file": {
40
+ "type": [
41
+ "string",
42
+ "null"
43
+ ]
44
+ },
45
+ "traffic_log_file": {
46
+ "type": [
47
+ "string",
48
+ "null"
49
+ ]
50
+ }
51
+ }
52
+ },
53
+ "summary": {
54
+ "type": "object",
55
+ "required": [
56
+ "total_code_routes",
57
+ "total_spec_endpoints",
58
+ "total_traffic_endpoints",
59
+ "shadow_count",
60
+ "zombie_count",
61
+ "missing_code_count",
62
+ "dormant_count"
63
+ ],
64
+ "properties": {
65
+ "total_code_routes": {
66
+ "type": "integer"
67
+ },
68
+ "total_spec_endpoints": {
69
+ "type": "integer"
70
+ },
71
+ "total_traffic_endpoints": {
72
+ "type": "integer"
73
+ },
74
+ "shadow_count": {
75
+ "type": "integer"
76
+ },
77
+ "zombie_count": {
78
+ "type": "integer"
79
+ },
80
+ "missing_code_count": {
81
+ "type": "integer"
82
+ },
83
+ "dormant_count": {
84
+ "type": "integer"
85
+ }
86
+ }
87
+ },
88
+ "shadow_apis": {
89
+ "type": "array",
90
+ "description": "Endpoints present in code or seen in traffic, but absent from OpenAPI specification.",
91
+ "items": {
92
+ "type": "object",
93
+ "required": [
94
+ "method",
95
+ "path",
96
+ "normalized",
97
+ "discovered_in"
98
+ ],
99
+ "properties": {
100
+ "method": {
101
+ "type": "string"
102
+ },
103
+ "path": {
104
+ "type": "string"
105
+ },
106
+ "normalized": {
107
+ "type": "string"
108
+ },
109
+ "discovered_in": {
110
+ "type": "string",
111
+ "enum": [
112
+ "code_only",
113
+ "traffic_only",
114
+ "code_and_traffic"
115
+ ]
116
+ },
117
+ "location": {
118
+ "type": "string"
119
+ },
120
+ "traffic_hits": {
121
+ "type": "integer"
122
+ }
123
+ }
124
+ }
125
+ },
126
+ "zombie_apis": {
127
+ "type": "array",
128
+ "description": "Endpoints marked as deprecated in OpenAPI spec, but still active/receiving live traffic.",
129
+ "items": {
130
+ "type": "object",
131
+ "required": [
132
+ "method",
133
+ "path",
134
+ "normalized",
135
+ "traffic_hits"
136
+ ],
137
+ "properties": {
138
+ "method": {
139
+ "type": "string"
140
+ },
141
+ "path": {
142
+ "type": "string"
143
+ },
144
+ "normalized": {
145
+ "type": "string"
146
+ },
147
+ "location": {
148
+ "type": "string"
149
+ },
150
+ "traffic_hits": {
151
+ "type": "integer"
152
+ },
153
+ "last_seen": {
154
+ "type": "string"
155
+ }
156
+ }
157
+ }
158
+ },
159
+ "documented_missing_code": {
160
+ "type": "array",
161
+ "description": "Endpoints declared in OpenAPI spec but not found implemented in code inventory.",
162
+ "items": {
163
+ "type": "object",
164
+ "required": [
165
+ "method",
166
+ "path",
167
+ "normalized"
168
+ ],
169
+ "properties": {
170
+ "method": {
171
+ "type": "string"
172
+ },
173
+ "path": {
174
+ "type": "string"
175
+ },
176
+ "normalized": {
177
+ "type": "string"
178
+ },
179
+ "summary": {
180
+ "type": "string"
181
+ }
182
+ }
183
+ }
184
+ },
185
+ "dormant_code": {
186
+ "type": "array",
187
+ "description": "Endpoints implemented in code and documented, but never seen in traffic log.",
188
+ "items": {
189
+ "type": "object",
190
+ "required": [
191
+ "method",
192
+ "path",
193
+ "normalized",
194
+ "location"
195
+ ],
196
+ "properties": {
197
+ "method": {
198
+ "type": "string"
199
+ },
200
+ "path": {
201
+ "type": "string"
202
+ },
203
+ "normalized": {
204
+ "type": "string"
205
+ },
206
+ "location": {
207
+ "type": "string"
208
+ }
209
+ }
210
+ }
211
+ }
212
+ }
213
+ }
@@ -0,0 +1,181 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "lsa/attack-chain.schema.json",
4
+ "title": "Komagu attack chain collection",
5
+ "type": "object",
6
+ "required": [
7
+ "version",
8
+ "chains",
9
+ "summary"
10
+ ],
11
+ "properties": {
12
+ "version": {
13
+ "type": "integer",
14
+ "enum": [
15
+ 1
16
+ ]
17
+ },
18
+ "generated_at": {
19
+ "type": "string"
20
+ },
21
+ "chains": {
22
+ "type": "array",
23
+ "items": {
24
+ "type": "object",
25
+ "required": [
26
+ "chain_id",
27
+ "title",
28
+ "entry",
29
+ "steps",
30
+ "outcome",
31
+ "business_impact",
32
+ "severity",
33
+ "confidence",
34
+ "breaking_fixes"
35
+ ],
36
+ "properties": {
37
+ "chain_id": {
38
+ "type": "string",
39
+ "pattern": "^chain-[0-9]{3,}$"
40
+ },
41
+ "title": {
42
+ "type": "string"
43
+ },
44
+ "entry": {
45
+ "type": "string",
46
+ "enum": [
47
+ "anonymous",
48
+ "authenticated_user",
49
+ "tenant_admin"
50
+ ]
51
+ },
52
+ "steps": {
53
+ "type": "array",
54
+ "items": {
55
+ "type": "object",
56
+ "required": [
57
+ "step_index",
58
+ "finding_id",
59
+ "role_in_chain",
60
+ "requires",
61
+ "gains"
62
+ ],
63
+ "properties": {
64
+ "step_index": {
65
+ "type": "integer"
66
+ },
67
+ "finding_id": {
68
+ "type": "string"
69
+ },
70
+ "category": {
71
+ "type": "string"
72
+ },
73
+ "subtype": {
74
+ "type": "string"
75
+ },
76
+ "location": {
77
+ "type": "string"
78
+ },
79
+ "endpoint": {
80
+ "type": "string"
81
+ },
82
+ "role_in_chain": {
83
+ "type": "string",
84
+ "enum": [
85
+ "entry_point",
86
+ "privilege_gain",
87
+ "access",
88
+ "impact"
89
+ ]
90
+ },
91
+ "requires": {
92
+ "type": "string"
93
+ },
94
+ "gains": {
95
+ "type": "array",
96
+ "items": {
97
+ "type": "string"
98
+ }
99
+ },
100
+ "explanation": {
101
+ "type": "string"
102
+ }
103
+ }
104
+ }
105
+ },
106
+ "outcome": {
107
+ "type": "string"
108
+ },
109
+ "business_impact": {
110
+ "type": "string"
111
+ },
112
+ "severity": {
113
+ "type": "string",
114
+ "enum": [
115
+ "critical",
116
+ "high",
117
+ "medium",
118
+ "low"
119
+ ]
120
+ },
121
+ "confidence": {
122
+ "type": "string",
123
+ "enum": [
124
+ "confirmed",
125
+ "likely",
126
+ "needs_review"
127
+ ]
128
+ },
129
+ "breaking_fixes": {
130
+ "type": "array",
131
+ "items": {
132
+ "type": "string"
133
+ }
134
+ },
135
+ "narrative": {
136
+ "type": "string"
137
+ }
138
+ }
139
+ }
140
+ },
141
+ "summary": {
142
+ "type": "object",
143
+ "required": [
144
+ "total_chains",
145
+ "top_breaking_fixes"
146
+ ],
147
+ "properties": {
148
+ "total_chains": {
149
+ "type": "integer"
150
+ },
151
+ "by_severity": {
152
+ "type": "object"
153
+ },
154
+ "top_breaking_fixes": {
155
+ "type": "array",
156
+ "items": {
157
+ "type": "object",
158
+ "required": [
159
+ "finding_id",
160
+ "chains_broken"
161
+ ],
162
+ "properties": {
163
+ "finding_id": {
164
+ "type": "string"
165
+ },
166
+ "category": {
167
+ "type": "string"
168
+ },
169
+ "location": {
170
+ "type": "string"
171
+ },
172
+ "chains_broken": {
173
+ "type": "integer"
174
+ }
175
+ }
176
+ }
177
+ }
178
+ }
179
+ }
180
+ }
181
+ }
@@ -0,0 +1,217 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "contracts/schemas/bas-scenario.schema.json",
4
+ "title": "Breach & Attack Simulation (BAS) Declarative Scenario",
5
+ "description": "Schema for declarative incident simulation files in Komagu BAS.",
6
+ "type": "object",
7
+ "required": [
8
+ "id",
9
+ "version",
10
+ "title",
11
+ "status",
12
+ "incident",
13
+ "mappings",
14
+ "parameters",
15
+ "steps",
16
+ "scoring"
17
+ ],
18
+ "properties": {
19
+ "id": {
20
+ "type": "string",
21
+ "pattern": "^[a-z0-9]+(-[a-z0-9]+)*$",
22
+ "description": "Unique slug identifier for the scenario."
23
+ },
24
+ "version": {
25
+ "type": "string",
26
+ "pattern": "^[0-9]+\\.[0-9]+(\\.[0-9]+)?$",
27
+ "description": "Semantic version of the scenario definition."
28
+ },
29
+ "title": {
30
+ "type": "string",
31
+ "minLength": 5,
32
+ "description": "Human-readable scenario title."
33
+ },
34
+ "status": {
35
+ "type": "string",
36
+ "enum": ["draft", "approved", "retired"],
37
+ "description": "Governance review lifecycle status. Only approved scenarios run without explicit override."
38
+ },
39
+ "approved_by": {
40
+ "type": "string",
41
+ "description": "Sign-off auditor or security team member identity."
42
+ },
43
+ "approved_at": {
44
+ "type": "string",
45
+ "format": "date-time",
46
+ "description": "ISO 8601 timestamp of audit approval."
47
+ },
48
+ "incident": {
49
+ "type": "object",
50
+ "required": ["name", "date", "summary", "references"],
51
+ "properties": {
52
+ "name": {
53
+ "type": "string",
54
+ "description": "Historical breach or landmark incident name."
55
+ },
56
+ "date": {
57
+ "type": "string",
58
+ "description": "Date or year of the incident."
59
+ },
60
+ "summary": {
61
+ "type": "string",
62
+ "description": "Executive description of the real-world attack."
63
+ },
64
+ "references": {
65
+ "type": "array",
66
+ "items": { "type": "string" },
67
+ "minItems": 1,
68
+ "description": "Public advisories, news reports, or CVE references."
69
+ }
70
+ }
71
+ },
72
+ "mappings": {
73
+ "type": "object",
74
+ "properties": {
75
+ "cwe": {
76
+ "type": "array",
77
+ "items": { "type": "string" },
78
+ "description": "CWE numbers related to the attack (e.g. ['CWE-639', 'CWE-284'])."
79
+ },
80
+ "owasp_api": {
81
+ "type": "array",
82
+ "items": { "type": "string" },
83
+ "description": "OWASP API Security Top 10 IDs (e.g. ['API1:2023'])."
84
+ },
85
+ "mitre_attack": {
86
+ "type": "array",
87
+ "items": { "type": "string" },
88
+ "description": "MITRE ATT&CK technique IDs (e.g. ['T1059', 'T1552'])."
89
+ }
90
+ }
91
+ },
92
+ "parameters": {
93
+ "type": "object",
94
+ "description": "Configurable parameters with defaults.",
95
+ "additionalProperties": {
96
+ "type": "object",
97
+ "required": ["default", "description"],
98
+ "properties": {
99
+ "type": {
100
+ "type": "string",
101
+ "enum": ["string", "integer", "boolean", "list"],
102
+ "default": "string"
103
+ },
104
+ "default": {},
105
+ "description": { "type": "string" }
106
+ }
107
+ }
108
+ },
109
+ "steps": {
110
+ "type": "array",
111
+ "minItems": 1,
112
+ "items": {
113
+ "type": "object",
114
+ "required": ["name", "type"],
115
+ "properties": {
116
+ "name": { "type": "string" },
117
+ "description": { "type": "string" },
118
+ "type": {
119
+ "type": "string",
120
+ "enum": ["http_request", "storage_worm_check", "custom_probe"]
121
+ },
122
+ "destructive": {
123
+ "type": "boolean",
124
+ "default": false,
125
+ "description": "If true, changes or deletes state; requires --allow-destructive."
126
+ },
127
+ "repeat": {
128
+ "type": "object",
129
+ "description": "Loop configuration over an array parameter.",
130
+ "required": ["param_name", "as_var"],
131
+ "properties": {
132
+ "param_name": { "type": "string" },
133
+ "as_var": { "type": "string" }
134
+ }
135
+ },
136
+ "request": {
137
+ "type": "object",
138
+ "properties": {
139
+ "method": {
140
+ "type": "string",
141
+ "enum": ["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS"],
142
+ "default": "GET"
143
+ },
144
+ "path": { "type": "string" },
145
+ "query": { "type": "object", "additionalProperties": { "type": "string" } },
146
+ "headers": { "type": "object", "additionalProperties": { "type": "string" } },
147
+ "body": { "type": "string" }
148
+ }
149
+ },
150
+ "expect_secure": {
151
+ "type": "object",
152
+ "description": "Conditions indicating the system successfully mitigated or blocked the attack.",
153
+ "properties": {
154
+ "status_codes": {
155
+ "type": "array",
156
+ "items": { "type": "integer" }
157
+ },
158
+ "body_not_contains": {
159
+ "type": "array",
160
+ "items": { "type": "string" }
161
+ }
162
+ }
163
+ },
164
+ "expect_vulnerable": {
165
+ "type": "object",
166
+ "description": "Conditions indicating the system leaked data or was compromised.",
167
+ "properties": {
168
+ "status_codes": {
169
+ "type": "array",
170
+ "items": { "type": "integer" }
171
+ },
172
+ "body_contains": {
173
+ "type": "array",
174
+ "items": { "type": "string" }
175
+ },
176
+ "body_matches_regex": {
177
+ "type": "string"
178
+ }
179
+ }
180
+ },
181
+ "storage_check": {
182
+ "type": "object",
183
+ "description": "WORM storage compliance probe parameters.",
184
+ "properties": {
185
+ "operations": {
186
+ "type": "array",
187
+ "items": {
188
+ "type": "string",
189
+ "enum": ["overwrite", "truncate", "delete"]
190
+ }
191
+ }
192
+ }
193
+ }
194
+ }
195
+ }
196
+ },
197
+ "scoring": {
198
+ "type": "object",
199
+ "required": ["strategy", "recommendations"],
200
+ "properties": {
201
+ "strategy": {
202
+ "type": "string",
203
+ "enum": ["ratio", "all_or_nothing"],
204
+ "default": "ratio"
205
+ },
206
+ "recommendations": {
207
+ "type": "object",
208
+ "required": ["remediation", "passed"],
209
+ "properties": {
210
+ "remediation": { "type": "string" },
211
+ "passed": { "type": "string" }
212
+ }
213
+ }
214
+ }
215
+ }
216
+ }
217
+ }