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

Function TestScannerProcessEvent

internal/evasion/scanner_test.go:33–76  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

31)
32
33func TestScannerProcessEvent(t *testing.T) {
34 var tests = []struct {
35 evt *event.Event
36 expectedEvasions []string
37 }{
38 {&event.Event{
39 Type: event.CreateFile,
40 Tid: 2484,
41 PID: 859,
42 CPU: 1,
43 Seq: 2,
44 Name: "CreateFile",
45 Timestamp: time.Now(),
46 Category: event.File,
47 Metadata: event.Metadata{},
48 Params: event.Params{
49 params.FileObject: {Name: params.FileObject, Type: params.Uint64, Value: uint64(12456738026482168384)},
50 params.FilePath: {Name: params.FilePath, Type: params.UnicodeString, Value: "C:\\Windows\\system32\\user32.dll"},
51 params.FileType: {Name: params.FileType, Type: params.AnsiString, Value: "file"},
52 params.FileOperation: {Name: params.FileOperation, Type: params.Enum, Value: uint32(2), Enum: fs.FileCreateDispositions},
53 },
54 Callstack: callstackFromFrames(
55 callstack.Frame{Addr: 0xf259de, Module: "unbacked", Symbol: "?"},
56 callstack.Frame{Addr: 0x7ffe4fda6e3b, Module: "C:\\Windows\\System32\\KernelBase.dll", Symbol: "SetThreadContext"},
57 callstack.Frame{Addr: 0xfffff807e228c555, Module: "C:\\WINDOWS\\system32\\ntoskrnl.exe", Symbol: "setjmpex"},
58 callstack.Frame{Addr: 0xfffff807e264805c, Module: "C:\\WINDOWS\\system32\\ntoskrnl.exe", Symbol: "ObOpenObjectByPointerWithTag"}),
59 }, []string{"direct_syscall"}},
60 }
61
62 s := NewScanner(Config{Enabled: true, EnableDirectSyscall: true})
63
64 for _, tt := range tests {
65 t.Run(strings.Join(tt.expectedEvasions, ","), func(t *testing.T) {
66 matches, err := s.ProcessEvent(tt.evt)
67 require.NoError(t, err)
68 require.True(t, matches && len(tt.expectedEvasions) > 0)
69 if len(tt.expectedEvasions) > 0 {
70 require.True(t, tt.evt.Evasions&uint32(DirectSyscall) != 0)
71 require.True(t, tt.evt.ContainsMeta(event.EvasionsKey))
72 require.Equal(t, tt.expectedEvasions, tt.evt.GetMeta(event.EvasionsKey).([]string))
73 }
74 })
75 }
76}

Callers

nothing calls this directly

Calls 7

ProcessEventMethod · 0.95
ContainsMetaMethod · 0.80
EqualMethod · 0.80
GetMetaMethod · 0.80
callstackFromFramesFunction · 0.70
NewScannerFunction · 0.70
RunMethod · 0.65

Tested by

no test coverage detected