MCPcopy Create free account
hub / github.com/rabbitstack/fibratus / TestRunSimpleAndSequenceRules

Function TestRunSimpleAndSequenceRules

pkg/rules/engine_test.go:324–423  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

322}
323
324func TestRunSimpleAndSequenceRules(t *testing.T) {
325 log.SetLevel(log.DebugLevel)
326
327 expectedMatches := make(map[string][]uint64)
328 c := newConfig("_fixtures/simple_and_sequence_rules/*.yml")
329 c.Filters.MatchAll = true
330 e := NewEngine(new(ps.SnapshotterMock), c)
331 e.RegisterMatchFunc(func(f *config.FilterConfig, evts ...*event.Event) {
332 ids := make([]uint64, 0)
333 for _, evt := range evts {
334 ids = append(ids, evt.Seq)
335 }
336 expectedMatches[f.Name] = ids
337 })
338
339 compileRules(t, e)
340
341 evts := []*event.Event{
342 {
343 Seq: 1,
344 Type: event.CreateProcess,
345 Timestamp: time.Now(),
346 Category: event.Process,
347 Name: "CreateProcess",
348 Tid: 2484,
349 PID: 2243,
350 PS: &types.PS{
351 Name: "powershell.exe",
352 Exe: "C:\\Windows\\system32\\powershell.exe",
353 },
354 Params: event.Params{
355 params.ProcessID: {Name: params.ProcessID, Type: params.PID, Value: uint32(2243)},
356 params.ProcessName: {Name: params.ProcessName, Type: params.UnicodeString, Value: "powershell.exe"},
357 },
358 Metadata: map[event.MetadataKey]any{"foo": "bar", "fooz": "barzz"},
359 },
360 {
361 Seq: 2,
362 Type: event.CreateFile,
363 Timestamp: time.Now().Add(time.Millisecond * 544),
364 Name: "CreateFile",
365 Tid: 2484,
366 PID: 2243,
367 Category: event.File,
368 PS: &types.PS{
369 Name: "cmd.exe",
370 Exe: "C:\\Windows\\system32\\cmd.exe",
371 },
372 Params: event.Params{
373 params.FilePath: {Name: params.FilePath, Type: params.UnicodeString, Value: "C:\\Temp\\dropper.exe"},
374 params.FileOperation: {Name: params.FileOperation, Type: params.Enum, Value: uint32(2)},
375 },
376 Metadata: map[event.MetadataKey]any{"foo": "bar", "fooz": "barzz"},
377 },
378 {
379 Seq: 10,
380 Type: event.CreateProcess,
381 Timestamp: time.Now().Add(time.Second * 2),

Callers

nothing calls this directly

Calls 9

RegisterMatchFuncMethod · 0.95
newConfigFunction · 0.85
NewEngineFunction · 0.85
compileRulesFunction · 0.85
wrapProcessEventFunction · 0.85
EqualMethod · 0.80
AddMethod · 0.65
RunMethod · 0.65
LenMethod · 0.45

Tested by

no test coverage detected