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

Function TestSimpleSequence

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

Source from the content-addressed store, hash-verified

186}
187
188func TestSimpleSequence(t *testing.T) {
189 log.SetLevel(log.DebugLevel)
190
191 c := &config.FilterConfig{Name: "Command shell created a temp file"}
192 f := filter.New(`
193 sequence
194 maxspan 100ms
195 |evt.name = 'CreateProcess' and ps.name = 'cmd.exe'| by ps.exe
196 |evt.name = 'CreateFile' and file.path icontains 'temp'| by file.path
197 `, &config.Config{EventSource: config.EventSourceConfig{EnableFileIOEvents: true}, Filters: &config.Filters{}})
198 require.NoError(t, f.Compile())
199
200 ss := newSequenceState(f, c, new(ps.SnapshotterMock))
201
202 var tests = []struct {
203 evts []*event.Event
204 matches []bool
205 }{
206 {[]*event.Event{{
207 Type: event.CreateProcess,
208 Name: "CreateProcess",
209 Timestamp: time.Now(),
210 Tid: 2484,
211 PID: 859,
212 PS: &pstypes.PS{
213 Name: "cmd.exe",
214 Exe: "C:\\Windows\\system32\\svchost-temp.exe",
215 },
216 Params: event.Params{
217 params.ProcessID: {Name: params.ProcessID, Type: params.Uint32, Value: uint32(4143)},
218 },
219 Metadata: map[event.MetadataKey]any{"foo": "bar", "fooz": "barzz"},
220 }, {
221 Type: event.CreateFile,
222 Name: "CreateFile",
223 Timestamp: time.Now().Add(time.Second),
224 Tid: 2484,
225 PID: 859,
226 Category: event.File,
227 PS: &pstypes.PS{
228 Name: "cmd.exe",
229 },
230 Params: event.Params{
231 params.FilePath: {Name: params.FilePath, Type: params.UnicodeString, Value: "C:\\Windows\\system32\\svchost-temp.exe"},
232 },
233 Metadata: map[event.MetadataKey]any{"foo": "bar", "fooz": "barzz"}}}, []bool{false, true}},
234 {[]*event.Event{{
235 Type: event.CreateProcess,
236 Name: "CreateProcess",
237 Timestamp: time.Now(),
238 Tid: 2484,
239 PID: 859,
240 PS: &pstypes.PS{
241 Name: "cmd.exe",
242 Exe: "C:\\Windows\\system32\\cmd.exe",
243 },
244 Params: event.Params{
245 params.ProcessID: {Name: params.ProcessID, Type: params.Uint32, Value: uint32(4143)},

Callers

nothing calls this directly

Calls 7

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

Tested by

no test coverage detected