Skip to content

Commit d9e690e

Browse files
committed
refactor: Deprecate kevt.* filter fields
1 parent 92c480b commit d9e690e

File tree

8 files changed

+153
-77
lines changed

8 files changed

+153
-77
lines changed

pkg/filter/accessor.go

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -64,51 +64,51 @@ const dateFmt = "2006-01-02"
6464

6565
func (k *evtAccessor) Get(f Field, evt *event.Event) (params.Value, error) {
6666
switch f.Name {
67-
case fields.KevtSeq:
67+
case fields.EvtSeq, fields.KevtSeq:
6868
return evt.Seq, nil
69-
case fields.KevtPID:
69+
case fields.EvtPID, fields.KevtPID:
7070
return evt.PID, nil
71-
case fields.KevtTID:
71+
case fields.EvtTID, fields.KevtTID:
7272
return evt.Tid, nil
73-
case fields.KevtCPU:
73+
case fields.EvtCPU, fields.KevtCPU:
7474
return evt.CPU, nil
75-
case fields.KevtName:
75+
case fields.EvtName, fields.KevtName:
7676
return evt.Name, nil
77-
case fields.KevtCategory:
77+
case fields.EvtCategory, fields.KevtCategory:
7878
return string(evt.Category), nil
79-
case fields.KevtDesc:
79+
case fields.EvtDesc, fields.KevtDesc:
8080
return evt.Description, nil
81-
case fields.KevtHost:
81+
case fields.EvtHost, fields.KevtHost:
8282
return evt.Host, nil
83-
case fields.KevtTime:
83+
case fields.EvtTime, fields.KevtTime:
8484
return evt.Timestamp.Format(timeFmt), nil
85-
case fields.KevtTimeHour:
85+
case fields.EvtTimeHour, fields.KevtTimeHour:
8686
return uint8(evt.Timestamp.Hour()), nil
87-
case fields.KevtTimeMin:
87+
case fields.EvtTimeMin, fields.KevtTimeMin:
8888
return uint8(evt.Timestamp.Minute()), nil
89-
case fields.KevtTimeSec:
89+
case fields.EvtTimeSec, fields.KevtTimeSec:
9090
return uint8(evt.Timestamp.Second()), nil
91-
case fields.KevtTimeNs:
91+
case fields.EvtTimeNs, fields.KevtTimeNs:
9292
return evt.Timestamp.UnixNano(), nil
93-
case fields.KevtDate:
93+
case fields.EvtDate, fields.KevtDate:
9494
return evt.Timestamp.Format(dateFmt), nil
95-
case fields.KevtDateDay:
95+
case fields.EvtDateDay, fields.KevtDateDay:
9696
return uint8(evt.Timestamp.Day()), nil
97-
case fields.KevtDateMonth:
97+
case fields.EvtDateMonth, fields.KevtDateMonth:
9898
return uint8(evt.Timestamp.Month()), nil
99-
case fields.KevtDateTz:
99+
case fields.EvtDateTz, fields.KevtDateTz:
100100
tz, _ := evt.Timestamp.Zone()
101101
return tz, nil
102-
case fields.KevtDateYear:
102+
case fields.EvtDateYear, fields.KevtDateYear:
103103
return uint32(evt.Timestamp.Year()), nil
104-
case fields.KevtDateWeek:
104+
case fields.EvtDateWeek, fields.KevtDateWeek:
105105
_, week := evt.Timestamp.ISOWeek()
106106
return uint8(week), nil
107-
case fields.KevtDateWeekday:
107+
case fields.EvtDateWeekday, fields.KevtDateWeekday:
108108
return evt.Timestamp.Weekday().String(), nil
109-
case fields.KevtNparams:
109+
case fields.EvtNparams, fields.KevtNparams:
110110
return uint64(evt.Params.Len()), nil
111-
case fields.KevtArg:
111+
case fields.EvtArg, fields.KevtArg:
112112
// lookup the parameter from the field argument
113113
// and depending on the parameter type, return
114114
// the respective value. The field format is

pkg/filter/fields/fields_windows.go

Lines changed: 122 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -300,52 +300,95 @@ const (
300300
// PePsChildFileName represents the original file name of the child process executable provided at compile-time
301301
PePsChildFileName Field = "pe.ps.child.file.name"
302302

303+
// EvtSeq is the event sequence number
304+
EvtSeq Field = "evt.seq"
305+
// EvtPID is the process identifier that generated the event
306+
EvtPID Field = "evt.pid"
307+
// EvtTID is the thread identifier that generated the event
308+
EvtTID Field = "evt.tid"
309+
// EvtCPU is the CPU core where the event was generated
310+
EvtCPU Field = "evt.cpu"
311+
// EvtDesc represents the event description
312+
EvtDesc Field = "evt.desc"
313+
// EvtHost represents the host where the event was produced
314+
EvtHost Field = "evt.host"
315+
// EvtTime is the event time
316+
EvtTime Field = "evt.time"
317+
// EvtTimeHour is the hour part of the event time
318+
EvtTimeHour Field = "evt.time.h"
319+
// EvtTimeMin is the minute part of the event time
320+
EvtTimeMin Field = "evt.time.m"
321+
// EvtTimeSec is the second part of the event time
322+
EvtTimeSec Field = "evt.time.s"
323+
// EvtTimeNs is the nanosecond part of the event time
324+
EvtTimeNs Field = "evt.time.ns"
325+
// EvtDate is the event date
326+
EvtDate Field = "evt.date"
327+
// EvtDateDay is the day of event date
328+
EvtDateDay Field = "evt.date.d"
329+
// EvtDateMonth is the month of event date
330+
EvtDateMonth Field = "evt.date.m"
331+
// EvtDateYear is the year of event date
332+
EvtDateYear Field = "evt.date.y"
333+
// EvtDateTz is the time zone of event timestamp
334+
EvtDateTz Field = "evt.date.tz"
335+
// EvtDateWeek is the event week number
336+
EvtDateWeek Field = "evt.date.week"
337+
// EvtDateWeekday is the event week day
338+
EvtDateWeekday Field = "evt.date.weekday"
339+
// EvtName is the event name
340+
EvtName Field = "evt.name"
341+
// EvtCategory is the event category
342+
EvtCategory Field = "evt.category"
343+
// EvtNparams is the number of event parameters
344+
EvtNparams Field = "evt.nparams"
345+
// EvtArg represents the field sequence for generic argument access
346+
EvtArg Field = "evt.arg"
347+
303348
// KevtSeq is the event sequence number
304-
KevtSeq Field = "evt.seq"
349+
KevtSeq Field = "kevt.seq"
305350
// KevtPID is the process identifier that generated the event
306-
KevtPID Field = "evt.pid"
351+
KevtPID Field = "kevt.pid"
307352
// KevtTID is the thread identifier that generated the event
308-
KevtTID Field = "evt.tid"
353+
KevtTID Field = "kevt.tid"
309354
// KevtCPU is the CPU core where the event was generated
310-
KevtCPU Field = "evt.cpu"
355+
KevtCPU Field = "kevt.cpu"
311356
// KevtDesc represents the event description
312-
KevtDesc Field = "evt.desc"
357+
KevtDesc Field = "kevt.desc"
313358
// KevtHost represents the host where the event was produced
314-
KevtHost Field = "evt.host"
359+
KevtHost Field = "kevt.host"
315360
// KevtTime is the event time
316-
KevtTime Field = "evt.time"
361+
KevtTime Field = "kevt.time"
317362
// KevtTimeHour is the hour part of the event time
318-
KevtTimeHour Field = "evt.time.h"
363+
KevtTimeHour Field = "kevt.time.h"
319364
// KevtTimeMin is the minute part of the event time
320-
KevtTimeMin Field = "evt.time.m"
365+
KevtTimeMin Field = "kevt.time.m"
321366
// KevtTimeSec is the second part of the event time
322-
KevtTimeSec Field = "evt.time.s"
367+
KevtTimeSec Field = "kevt.time.s"
323368
// KevtTimeNs is the nanosecond part of the event time
324-
KevtTimeNs Field = "evt.time.ns"
369+
KevtTimeNs Field = "kevt.time.ns"
325370
// KevtDate is the event date
326-
KevtDate Field = "evt.date"
371+
KevtDate Field = "kevt.date"
327372
// KevtDateDay is the day of event date
328-
KevtDateDay Field = "evt.date.d"
373+
KevtDateDay Field = "kevt.date.d"
329374
// KevtDateMonth is the month of event date
330-
KevtDateMonth Field = "evt.date.m"
375+
KevtDateMonth Field = "kevt.date.m"
331376
// KevtDateYear is the year of event date
332-
KevtDateYear Field = "evt.date.y"
377+
KevtDateYear Field = "kevt.date.y"
333378
// KevtDateTz is the time zone of event timestamp
334-
KevtDateTz Field = "evt.date.tz"
379+
KevtDateTz Field = "kevt.date.tz"
335380
// KevtDateWeek is the event week number
336-
KevtDateWeek Field = "evt.date.week"
381+
KevtDateWeek Field = "kevt.date.week"
337382
// KevtDateWeekday is the event week day
338-
KevtDateWeekday Field = "evt.date.weekday"
383+
KevtDateWeekday Field = "kevt.date.weekday"
339384
// KevtName is the event name
340-
KevtName Field = "evt.name"
385+
KevtName Field = "kevt.name"
341386
// KevtCategory is the event category
342-
KevtCategory Field = "evt.category"
343-
// KevtMeta is the event metadata
344-
KevtMeta Field = "evt.meta"
387+
KevtCategory Field = "kevt.category"
345388
// KevtNparams is the number of event parameters
346-
KevtNparams Field = "evt.nparams"
389+
KevtNparams Field = "kevt.nparams"
347390
// KevtArg represents the field sequence for generic argument access
348-
KevtArg Field = "evt.arg"
391+
KevtArg Field = "kevt.arg"
349392

350393
// HandleID represents the handle identifier within the process address space
351394
HandleID Field = "handle.id"
@@ -734,28 +777,61 @@ func IsPseudoField(f Field) bool {
734777
func (f Field) IsPeSectionsPseudo() bool { return f == PeSections }
735778

736779
var fields = map[Field]FieldInfo{
737-
KevtSeq: {KevtSeq, "event sequence number", params.Uint64, []string{"evt.seq > 666"}, nil, nil},
738-
KevtPID: {KevtPID, "process identifier generating the kernel event", params.Uint32, []string{"evt.pid = 6"}, nil, nil},
739-
KevtTID: {KevtTID, "thread identifier generating the kernel event", params.Uint32, []string{"evt.tid = 1024"}, nil, nil},
740-
KevtCPU: {KevtCPU, "logical processor core where the event was generated", params.Uint8, []string{"evt.cpu = 2"}, nil, nil},
741-
KevtName: {KevtName, "symbolical kernel event name", params.AnsiString, []string{"evt.name = 'CreateThread'"}, nil, nil},
742-
KevtCategory: {KevtCategory, "event category", params.AnsiString, []string{"evt.category = 'registry'"}, nil, nil},
743-
KevtDesc: {KevtDesc, "event description", params.AnsiString, []string{"evt.desc contains 'Creates a new process'"}, nil, nil},
744-
KevtHost: {KevtHost, "host name on which the event was produced", params.UnicodeString, []string{"evt.host contains 'kitty'"}, nil, nil},
745-
KevtTime: {KevtTime, "event timestamp as a time string", params.Time, []string{"evt.time = '17:05:32'"}, nil, nil},
746-
KevtTimeHour: {KevtTimeHour, "hour within the day on which the event occurred", params.Time, []string{"evt.time.h = 23"}, nil, nil},
747-
KevtTimeMin: {KevtTimeMin, "minute offset within the hour on which the event occurred", params.Time, []string{"evt.time.m = 54"}, nil, nil},
748-
KevtTimeSec: {KevtTimeSec, "second offset within the minute on which the event occurred", params.Time, []string{"evt.time.s = 0"}, nil, nil},
749-
KevtTimeNs: {KevtTimeNs, "nanoseconds specified by event timestamp", params.Int64, []string{"evt.time.ns > 1591191629102337000"}, nil, nil},
750-
KevtDate: {KevtDate, "event timestamp as a date string", params.Time, []string{"evt.date = '2018-03-03'"}, nil, nil},
751-
KevtDateDay: {KevtDateDay, "day of the month on which the event occurred", params.Time, []string{"evt.date.d = 12"}, nil, nil},
752-
KevtDateMonth: {KevtDateMonth, "month of the year on which the event occurred", params.Time, []string{"evt.date.m = 11"}, nil, nil},
753-
KevtDateYear: {KevtDateYear, "year on which the event occurred", params.Uint32, []string{"evt.date.y = 2020"}, nil, nil},
754-
KevtDateTz: {KevtDateTz, "time zone associated with the event timestamp", params.AnsiString, []string{"evt.date.tz = 'UTC'"}, nil, nil},
755-
KevtDateWeek: {KevtDateWeek, "week number within the year on which the event occurred", params.Uint8, []string{"evt.date.week = 2"}, nil, nil},
756-
KevtDateWeekday: {KevtDateWeekday, "week day on which the event occurred", params.AnsiString, []string{"evt.date.weekday = 'Monday'"}, nil, nil},
757-
KevtNparams: {KevtNparams, "number of parameters", params.Int8, []string{"evt.nparams > 2"}, nil, nil},
758-
KevtArg: {KevtArg, "event parameter", params.Object, []string{"evt.arg[cmdline] istartswith 'C:\\Windows'"}, nil, &Argument{Optional: false, Pattern: "[a-z0-9_]+", ValidationFunc: func(s string) bool {
780+
EvtSeq: {EvtSeq, "event sequence number", params.Uint64, []string{"evt.seq > 666"}, nil, nil},
781+
EvtPID: {EvtPID, "process identifier generating the event", params.Uint32, []string{"evt.pid = 6"}, nil, nil},
782+
EvtTID: {EvtTID, "thread identifier generating the event", params.Uint32, []string{"evt.tid = 1024"}, nil, nil},
783+
EvtCPU: {EvtCPU, "logical processor core where the event was generated", params.Uint8, []string{"evt.cpu = 2"}, nil, nil},
784+
EvtName: {EvtName, "symbolical event name", params.AnsiString, []string{"evt.name = 'CreateThread'"}, nil, nil},
785+
EvtCategory: {EvtCategory, "event category", params.AnsiString, []string{"evt.category = 'registry'"}, nil, nil},
786+
EvtDesc: {EvtDesc, "event description", params.AnsiString, []string{"evt.desc contains 'Creates a new process'"}, nil, nil},
787+
EvtHost: {EvtHost, "host name on which the event was produced", params.UnicodeString, []string{"evt.host contains 'kitty'"}, nil, nil},
788+
EvtTime: {EvtTime, "event timestamp as a time string", params.Time, []string{"evt.time = '17:05:32'"}, nil, nil},
789+
EvtTimeHour: {EvtTimeHour, "hour within the day on which the event occurred", params.Time, []string{"evt.time.h = 23"}, nil, nil},
790+
EvtTimeMin: {EvtTimeMin, "minute offset within the hour on which the event occurred", params.Time, []string{"evt.time.m = 54"}, nil, nil},
791+
EvtTimeSec: {EvtTimeSec, "second offset within the minute on which the event occurred", params.Time, []string{"evt.time.s = 0"}, nil, nil},
792+
EvtTimeNs: {EvtTimeNs, "nanoseconds specified by event timestamp", params.Int64, []string{"evt.time.ns > 1591191629102337000"}, nil, nil},
793+
EvtDate: {EvtDate, "event timestamp as a date string", params.Time, []string{"evt.date = '2018-03-03'"}, nil, nil},
794+
EvtDateDay: {EvtDateDay, "day of the month on which the event occurred", params.Time, []string{"evt.date.d = 12"}, nil, nil},
795+
EvtDateMonth: {EvtDateMonth, "month of the year on which the event occurred", params.Time, []string{"evt.date.m = 11"}, nil, nil},
796+
EvtDateYear: {EvtDateYear, "year on which the event occurred", params.Uint32, []string{"evt.date.y = 2020"}, nil, nil},
797+
EvtDateTz: {EvtDateTz, "time zone associated with the event timestamp", params.AnsiString, []string{"evt.date.tz = 'UTC'"}, nil, nil},
798+
EvtDateWeek: {EvtDateWeek, "week number within the year on which the event occurred", params.Uint8, []string{"evt.date.week = 2"}, nil, nil},
799+
EvtDateWeekday: {EvtDateWeekday, "week day on which the event occurred", params.AnsiString, []string{"evt.date.weekday = 'Monday'"}, nil, nil},
800+
EvtNparams: {EvtNparams, "number of parameters", params.Int8, []string{"evt.nparams > 2"}, nil, nil},
801+
EvtArg: {EvtArg, "event parameter", params.Object, []string{"evt.arg[cmdline] istartswith 'C:\\Windows'"}, nil, &Argument{Optional: false, Pattern: "[a-z0-9_]+", ValidationFunc: func(s string) bool {
802+
for _, c := range s {
803+
switch {
804+
case unicode.IsLower(c):
805+
case unicode.IsNumber(c):
806+
case c == '_':
807+
default:
808+
return false
809+
}
810+
}
811+
return true
812+
}}},
813+
KevtSeq: {KevtSeq, "event sequence number", params.Uint64, []string{"kevt.seq > 666"}, &Deprecation{Since: "3.0.0", Fields: []Field{EvtSeq}}, nil},
814+
KevtPID: {KevtPID, "process identifier generating the event", params.Uint32, []string{"kevt.pid = 6"}, &Deprecation{Since: "3.0.0", Fields: []Field{EvtPID}}, nil},
815+
KevtTID: {KevtTID, "thread identifier generating the event", params.Uint32, []string{"kevt.tid = 1024"}, &Deprecation{Since: "3.0.0", Fields: []Field{EvtTID}}, nil},
816+
KevtCPU: {KevtCPU, "logical processor core where the event was generated", params.Uint8, []string{"kevt.cpu = 2"}, &Deprecation{Since: "3.0.0", Fields: []Field{EvtCPU}}, nil},
817+
KevtName: {KevtName, "symbolical event name", params.AnsiString, []string{"kevt.name = 'CreateThread'"}, &Deprecation{Since: "3.0.0", Fields: []Field{EvtName}}, nil},
818+
KevtCategory: {KevtCategory, "event category", params.AnsiString, []string{"kevt.category = 'registry'"}, &Deprecation{Since: "3.0.0", Fields: []Field{EvtCategory}}, nil},
819+
KevtDesc: {KevtDesc, "event description", params.AnsiString, []string{"kevt.desc contains 'Creates a new process'"}, &Deprecation{Since: "3.0.0", Fields: []Field{EvtDesc}}, nil},
820+
KevtHost: {KevtHost, "host name on which the event was produced", params.UnicodeString, []string{"kevt.host contains 'kitty'"}, &Deprecation{Since: "3.0.0", Fields: []Field{EvtHost}}, nil},
821+
KevtTime: {KevtTime, "event timestamp as a time string", params.Time, []string{"kevt.time = '17:05:32'"}, &Deprecation{Since: "3.0.0", Fields: []Field{EvtTime}}, nil},
822+
KevtTimeHour: {KevtTimeHour, "hour within the day on which the event occurred", params.Time, []string{"kevt.time.h = 23"}, &Deprecation{Since: "3.0.0", Fields: []Field{EvtTimeHour}}, nil},
823+
KevtTimeMin: {KevtTimeMin, "minute offset within the hour on which the event occurred", params.Time, []string{"kevt.time.m = 54"}, &Deprecation{Since: "3.0.0", Fields: []Field{EvtTimeMin}}, nil},
824+
KevtTimeSec: {KevtTimeSec, "second offset within the minute on which the event occurred", params.Time, []string{"kevt.time.s = 0"}, &Deprecation{Since: "3.0.0", Fields: []Field{EvtTimeSec}}, nil},
825+
KevtTimeNs: {KevtTimeNs, "nanoseconds specified by event timestamp", params.Int64, []string{"kevt.time.ns > 1591191629102337000"}, &Deprecation{Since: "3.0.0", Fields: []Field{EvtTimeNs}}, nil},
826+
KevtDate: {KevtDate, "event timestamp as a date string", params.Time, []string{"kevt.date = '2018-03-03'"}, &Deprecation{Since: "3.0.0", Fields: []Field{EvtDate}}, nil},
827+
KevtDateDay: {KevtDateDay, "day of the month on which the event occurred", params.Time, []string{"kevt.date.d = 12"}, &Deprecation{Since: "3.0.0", Fields: []Field{EvtDateDay}}, nil},
828+
KevtDateMonth: {KevtDateMonth, "month of the year on which the event occurred", params.Time, []string{"kevt.date.m = 11"}, &Deprecation{Since: "3.0.0", Fields: []Field{EvtDateMonth}}, nil},
829+
KevtDateYear: {KevtDateYear, "year on which the event occurred", params.Uint32, []string{"kevt.date.y = 2020"}, &Deprecation{Since: "3.0.0", Fields: []Field{EvtDateYear}}, nil},
830+
KevtDateTz: {KevtDateTz, "time zone associated with the event timestamp", params.AnsiString, []string{"kevt.date.tz = 'UTC'"}, &Deprecation{Since: "3.0.0", Fields: []Field{EvtDateTz}}, nil},
831+
KevtDateWeek: {KevtDateWeek, "week number within the year on which the event occurred", params.Uint8, []string{"kevt.date.week = 2"}, &Deprecation{Since: "3.0.0", Fields: []Field{EvtDateWeek}}, nil},
832+
KevtDateWeekday: {KevtDateWeekday, "week day on which the event occurred", params.AnsiString, []string{"kevt.date.weekday = 'Monday'"}, &Deprecation{Since: "3.0.0", Fields: []Field{EvtDateWeekday}}, nil},
833+
KevtNparams: {KevtNparams, "number of parameters", params.Int8, []string{"kevt.nparams > 2"}, &Deprecation{Since: "3.0.0", Fields: []Field{EvtNparams}}, nil},
834+
KevtArg: {KevtArg, "event parameter", params.Object, []string{"kevt.arg[cmdline] istartswith 'C:\\Windows'"}, &Deprecation{Since: "3.0.0", Fields: []Field{EvtArg}}, &Argument{Optional: false, Pattern: "[a-z0-9_]+", ValidationFunc: func(s string) bool {
759835
for _, c := range s {
760836
switch {
761837
case unicode.IsLower(c):

pkg/filter/filter_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ func TestStringFields(t *testing.T) {
104104
f := New(`ps.name = 'cmd.exe' and evt.name = 'CreateProcess' or evt.name in ('TerminateProcess', 'CreateFile')`, cfg)
105105
require.NoError(t, f.Compile())
106106
assert.Len(t, f.GetStringFields(), 2)
107-
assert.Len(t, f.GetStringFields()[fields.KevtName], 3)
107+
assert.Len(t, f.GetStringFields()[fields.EvtName], 3)
108108
assert.Len(t, f.GetStringFields()[fields.PsName], 1)
109109
}
110110

pkg/filter/ql/error_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func TestParseError(t *testing.T) {
5959
registry.key.name icontains
6060
(
6161
CurrentVersion\\Run',
62-
╭─────────────^
62+
╭─────────────^
6363
|
6464
| 'Policies\\Explorer\\Run',
6565
| 'Group Policy\\Scripts',

pkg/filter/ql/literal.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ func (e *SequenceExpr) walk() {
338338

339339
// initialize event type/category buckets for every such field
340340
for name, values := range stringFields {
341-
if name == fields.KevtName || name == fields.KevtCategory {
341+
if name == fields.EvtName || name == fields.EvtCategory {
342342
for _, v := range values {
343343
e.buckets[hashers.FnvUint32([]byte(v))] = true
344344
if etype := event.NameToType(v); etype.Exists() {

0 commit comments

Comments
 (0)