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

Function TestSimpleSequenceDeadline

pkg/rules/sequence_test.go:469–537  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

467}
468
469func TestSimpleSequenceDeadline(t *testing.T) {
470 log.SetLevel(log.DebugLevel)
471
472 c := &config.FilterConfig{Name: "Command shell created a temp file"}
473 f := filter.New(`
474 sequence
475 maxspan 100ms
476 |evt.name = 'CreateProcess' and ps.name = 'cmd.exe'| by ps.exe
477 |evt.name = 'CreateFile' and file.path icontains 'temp'| by file.path
478 `, &config.Config{EventSource: config.EventSourceConfig{EnableFileIOEvents: true}, Filters: &config.Filters{}})
479 require.NoError(t, f.Compile())
480
481 ss := newSequenceState(f, c, new(ps.SnapshotterMock))
482
483 e1 := &event.Event{
484 Type: event.CreateProcess,
485 Timestamp: time.Now(),
486 Name: "CreateProcess",
487 Tid: 2484,
488 PID: 859,
489 PS: &pstypes.PS{
490 Name: "cmd.exe",
491 Exe: "C:\\Windows\\system32\\svchost-temp.exe",
492 },
493 Params: event.Params{
494 params.ProcessID: {Name: params.ProcessID, Type: params.Uint32, Value: uint32(4143)},
495 },
496 Metadata: map[event.MetadataKey]any{"foo": "bar", "fooz": "barzz"},
497 }
498 require.False(t, ss.runSequence(e1))
499
500 e2 := &event.Event{
501 Type: event.CreateFile,
502 Timestamp: time.Now().Add(time.Millisecond * 200),
503 Name: "CreateFile",
504 Tid: 2484,
505 PID: 859,
506 Category: event.File,
507 PS: &pstypes.PS{
508 Name: "cmd.exe",
509 Exe: "C:\\Windows\\system32\\svchost.exe",
510 },
511 Params: event.Params{
512 params.FilePath: {Name: params.FilePath, Type: params.UnicodeString, Value: "C:\\Windows\\system32\\svchost-temp.exe"},
513 },
514 Metadata: map[event.MetadataKey]any{"foo": "bar", "fooz": "barzz"},
515 }
516 time.Sleep(time.Millisecond * 110)
517 require.False(t, ss.runSequence(e2))
518
519 require.Equal(t, sequenceInitialState, ss.currentState())
520 assert.Len(t, ss.partials, 0)
521
522 // now the state machine has transitioned
523 // to the initial state, which means we should
524 // be able to match the sequence if we reinsert
525 // the events
526 require.False(t, ss.runSequence(e1))

Callers

nothing calls this directly

Calls 9

NewFunction · 0.92
newSequenceStateFunction · 0.85
runSequenceMethod · 0.80
EqualMethod · 0.80
currentStateMethod · 0.80
clearLockedMethod · 0.80
CompileMethod · 0.65
AddMethod · 0.65
LenMethod · 0.45

Tested by

no test coverage detected