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

Function TestSequenceBoundFields

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

Source from the content-addressed store, hash-verified

923}
924
925func TestSequenceBoundFields(t *testing.T) {
926 log.SetLevel(log.DebugLevel)
927
928 maxSequencePartialLifetime = time.Millisecond * 500
929
930 c := &config.FilterConfig{Name: "Command shell created a temp file with network outbound"}
931 f := filter.New(`
932 sequence
933 maxspan 200ms
934 |evt.name = 'CreateProcess' and ps.name = 'cmd.exe'| as e1
935 |evt.name = 'CreateFile' and file.path icontains 'temp' and $e1.ps.sid = ps.sid| as e2
936 |evt.name = 'Connect' and ps.sid != $e2.ps.sid and ps.sid = $e1.ps.sid|
937 `, &config.Config{EventSource: config.EventSourceConfig{EnableFileIOEvents: true}, Filters: &config.Filters{}})
938 require.NoError(t, f.Compile())
939
940 ss := newSequenceState(f, c, new(ps.SnapshotterMock))
941
942 e1 := &event.Event{
943 Type: event.CreateProcess,
944 Timestamp: time.Now(),
945 Name: "CreateProcess",
946 Tid: 2484,
947 PID: 859,
948 PS: &pstypes.PS{
949 Name: "cmd.exe",
950 Exe: "C:\\Windows\\system32\\svchost-temp.exe",
951 SID: "zinet",
952 },
953 Params: event.Params{
954 params.ProcessID: {Name: params.ProcessID, Type: params.Uint32, Value: uint32(4143)},
955 },
956 Metadata: map[event.MetadataKey]any{"foo": "bar", "fooz": "barzz"},
957 }
958
959 e2 := &event.Event{
960 Type: event.CreateProcess,
961 Timestamp: time.Now().Add(time.Millisecond * 20),
962 Name: "CreateProcess",
963 Tid: 2484,
964 PID: 859,
965 PS: &pstypes.PS{
966 Name: "cmd.exe",
967 Exe: "C:\\Windows\\system32\\svchost-temp.exe",
968 SID: "nusret",
969 },
970 Params: event.Params{
971 params.ProcessID: {Name: params.ProcessID, Type: params.Uint32, Value: uint32(4143)},
972 },
973 Metadata: map[event.MetadataKey]any{"foo": "bar", "fooz": "barzz"},
974 }
975
976 e3 := &event.Event{
977 Type: event.CreateFile,
978 Timestamp: time.Now().Add(time.Second),
979 Name: "CreateFile",
980 Tid: 2484,
981 PID: 859,
982 Category: event.File,

Callers

nothing calls this directly

Calls 5

NewFunction · 0.92
newSequenceStateFunction · 0.85
runSequenceMethod · 0.80
CompileMethod · 0.65
AddMethod · 0.65

Tested by

no test coverage detected