Skip to content

Commit 13f15a0

Browse files
authored
fix(rules): Fix rules schema validation (#228)
1 parent 6279563 commit 13f15a0

File tree

8 files changed

+44
-58
lines changed

8 files changed

+44
-58
lines changed

pkg/config/_fixtures/filters/default.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
output: >
1111
`%ps.exe` attempted to reach out to `%net.sip` IP address
1212
action:
13-
- kill:
13+
- name: kill
1414
pid: ps.pid
1515
min-engine-version: 2.0.0
1616

pkg/config/filters.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,6 @@ func (a KillAction) PidToInt(pid string) uint32 {
7979
return uint32(n)
8080
}
8181

82-
const (
83-
killActionID = "kill"
84-
)
85-
8682
// DecodeActions converts raw YAML map to
8783
// typed action structures.
8884
func (f FilterConfig) DecodeActions() ([]any, error) {
@@ -102,7 +98,8 @@ func (f FilterConfig) DecodeActions() ([]any, error) {
10298
if !ok {
10399
continue
104100
}
105-
if _, ok := m[killActionID]; ok {
101+
switch m["name"] {
102+
case "kill":
106103
var kill KillAction
107104
if err := dec(m, kill); err != nil {
108105
return nil, err

pkg/config/schema_windows.go

Lines changed: 26 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -484,59 +484,43 @@ var schema = `
484484
var rulesSchema = `
485485
{
486486
"$schema": "http://json-schema.org/draft-07/schema#",
487-
"definitions": {"rules": {"$id": "#rules", "type": "object", "type": "array",
488-
"items":
489-
{
490-
"type": "object",
491-
"properties": {
492-
"name": {"type": "string", "minLength": 3},
493-
"description": {"type": "string"},
494-
"output": {"type": "string", "minLength": 5},
495-
"severity": {"type": "string", "enum": ["low", "medium", "high", "critical"]},
496-
"min-engine-version": {"type": "string", "minLength": 5, "pattern": "^([0-9]+.)([0-9]+.)([0-9]+)$"},
497-
"condition": {"type": "string", "minLength": 3},
498-
"action": {
499-
"type": "array",
500-
"items": [
501-
{
502-
"type": "object",
503-
"properties": {
504-
"kill": {
505-
"type": "object",
506-
"properties": {
507-
"pid": {"type": "string", "minLength": 4}
508-
}
509-
}
510-
}
511-
}
512-
]
513-
},
514-
"additionalProperties": false
515-
}
516-
},
517-
"required": ["name", "condition", "min-engine-version"],
518-
"minItems": 1,
519-
"additionalProperties": false
520-
}}},
521-
522-
523487
"type": "object",
524488
"properties": {
525489
"group": {"type": "string", "minLength": 1},
526490
"description": {"type": "string"},
527491
"enabled": {"type": "boolean"},
528492
"tags": {"type": "array", "items": [{"type": "string", "minLength": 1}]},
529-
"rules": {"$ref": "#rules"},
493+
"rules": {"type": "array", "items": {
494+
"type": "object",
495+
"properties": {
496+
"name": {"type": "string", "minLength": 3},
497+
"description": {"type": "string"},
498+
"output": {"type": "string", "minLength": 5},
499+
"severity": {"type": "string", "enum": ["low", "medium", "high", "critical"]},
500+
"min-engine-version": {"type": "string", "minLength": 5, "pattern": "^([0-9]+.)([0-9]+.)([0-9]+)$"},
501+
"condition": {"type": "string", "minLength": 3},
502+
"action": {
503+
"type": "array",
504+
"items": {
505+
"type": "object",
506+
"properties": {
507+
"name": {"type": "string", "enum": ["kill"]},
508+
"pid": {"type": "string", "minLength": 5}
509+
},
510+
"required": ["name"],
511+
"additionalProperties": false
512+
}
513+
}
514+
},
515+
"required": ["name", "condition", "min-engine-version"],
516+
"minItems": 1,
517+
"additionalProperties": false}},
530518
"labels": {
531519
"type": "object",
532520
"additionalProperties": { "type": "string" }
533521
}
534522
},
535-
"required": ["group"],
536-
"oneOf": [
537-
{"required": ["from-strings"]},
538-
{"required": ["rules"]}
539-
],
523+
"required": ["group", "rules"],
540524
"additionalProperties": false
541525
}
542526
`

pkg/filter/_fixtures/kill_action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
condition: kevt.name = 'CreateProcess' and ps.child.name = 'calc.exe'
66
severity: critical
77
action:
8-
- kill:
8+
- name: kill
99
pid: ps.child.pid
1010
min-engine-version: 2.0.0

pkg/filter/rules.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ func (r *Rules) Compile() error {
542542

543543
g := newFilterGroup(group, filters)
544544
log.Infof("loaded rule group [%s]. "+
545-
"Number of rules: %d",
545+
"Number of rules: [%d]",
546546
group.Name,
547547
len(filters))
548548

@@ -795,7 +795,11 @@ func (r *Rules) processActions() error {
795795
for _, act := range actions {
796796
switch act := act.(type) {
797797
case config.KillAction:
798-
pid := act.PidToInt(InterpolateFields("%"+act.Pid, evts))
798+
field := act.Pid
799+
if field == "" {
800+
field = "ps.pid"
801+
}
802+
pid := act.PidToInt(InterpolateFields("%"+field, evts))
799803
log.Infof("executing kill action: pid=%d rule=%s", pid, f.Name)
800804
if err := action.Kill(pid); err != nil {
801805
return ErrRuleAction(f.Name, err)

rules/credential_access_credentials_from_password_stores.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,3 +169,4 @@
169169
'?:\\ProgramData\\Microsoft\\Windows Defender\\*\\MsMpEng.exe',
170170
'?:\\ProgramData\\Microsoft\\Windows Defender\\*\\MpCopyAccelerator.exe'
171171
)
172+
min-engine-version: 2.0.0

rules/credential_access_modify_authentication_process.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,11 @@
3434
get_reg_value(registry.key.name) iin (base($e1.file.name, false))
3535
|
3636
output: >
37-
`%1.ps.exe` process dropped a potentially malicious
38-
`%1.file.name` password filter DLL and `%2.ps.name`
39-
process registered the password filter DLL under
40-
%2.registry.key.name registry key
37+
Detected `%1.ps.exe` process dropping a potentially malicious
38+
`%1.file.name` password filter DLL and subsequently `%2.ps.name`
39+
process registering the password filter DLL in the Notification
40+
Packages registry key. This may be indicative of potential abuse
41+
of password filters to steal credentials material.
4142
min-engine-version: 2.0.0
4243
- name: Potential credentials dumping or exfiltration via malicious password filter DLL
4344
description: |

rules/persistence_boot_or_logon_autostart_execution.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@
9999
ps.cmdline imatches startup_locations
100100
)
101101
|
102-
|connect_socket or accept_socket|
102+
|(inbound_network) or (outbound_network)|
103103
min-engine-version: 2.0.0
104104
- name: Suspicious persistence via registry modification
105105
description: |
@@ -157,6 +157,5 @@
157157
file.name imatches startup_locations
158158
)
159159
action:
160-
- kill:
161-
pid: ps.pid
160+
- name: kill
162161
min-engine-version: 2.0.0

0 commit comments

Comments
 (0)