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

Function TestSequenceState

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

Source from the content-addressed store, hash-verified

38)
39
40func TestSequenceState(t *testing.T) {
41 log.SetLevel(log.DebugLevel)
42
43 c := &config.FilterConfig{Name: "Command shell created and executed by file"}
44 f := filter.New(`
45 sequence
46 maxspan 100ms
47 |evt.name = 'CreateProcess' and ps.name = 'cmd.exe'| by ps.exe
48 |evt.name = 'CreateFile' and file.path icontains 'temp'| by file.path
49 |evt.name = 'CreateProcess'| by ps.exe`,
50 &config.Config{EventSource: config.EventSourceConfig{}, Filters: &config.Filters{}})
51
52 require.NoError(t, f.Compile())
53
54 ss := newSequenceState(f, c, new(ps.SnapshotterMock))
55
56 assert.Equal(t, 0, ss.currentState())
57 assert.True(t, ss.isInitialState())
58 assert.Equal(t, "evt.name = CreateProcess AND ps.name = cmd.exe", ss.expr(ss.initialState))
59
60 e1 := &event.Event{
61 Type: event.CreateProcess,
62 Name: "CreateProcess",
63 Tid: 2484,
64 PID: 859,
65 Timestamp: time.Now(),
66 PS: &pstypes.PS{
67 Name: "cmd.exe",
68 Exe: "C:\\Windows\\system32\\svchost.exe",
69 },
70 Params: event.Params{
71 params.ProcessID: {Name: params.ProcessID, Type: params.PID, Value: uint32(4143)},
72 params.ProcessName: {Name: params.ProcessName, Type: params.AnsiString, Value: "powershell.exe"},
73 },
74 }
75
76 e2 := &event.Event{
77 Type: event.CreateFile,
78 Name: "CreateFile",
79 Tid: 2484,
80 PID: 4143,
81 Timestamp: time.Now().Add(time.Second * 5),
82 PS: &pstypes.PS{
83 Name: "cmd.exe",
84 Exe: "C:\\Windows\\system32\\svchost.exe",
85 },
86 Params: event.Params{
87 params.FilePath: {Name: params.FilePath, Type: params.UnicodeString, Value: "C:\\Temp\\dropper"},
88 },
89 }
90
91 require.True(t, ss.next(0))
92 require.False(t, ss.next(1))
93 require.NoError(t, ss.matchTransition(0, e1))
94 ss.addPartial(0, e1, false)
95 require.True(t, ss.next(1))
96 assert.True(t, ss.states[0])
97 require.False(t, ss.next(2))

Callers

nothing calls this directly

Calls 15

NewFunction · 0.92
newSequenceStateFunction · 0.85
EqualMethod · 0.80
currentStateMethod · 0.80
isInitialStateMethod · 0.80
exprMethod · 0.80
nextMethod · 0.80
matchTransitionMethod · 0.80
addPartialMethod · 0.80
isTerminalStateMethod · 0.80
clearMethod · 0.80
expireMethod · 0.80

Tested by

no test coverage detected