(t *testing.T)
| 1083 | } |
| 1084 | |
| 1085 | func TestIsExpressionEvaluable(t *testing.T) { |
| 1086 | log.SetLevel(log.DebugLevel) |
| 1087 | |
| 1088 | c := &config.FilterConfig{Name: "Command shell created a temp file"} |
| 1089 | f := filter.New(` |
| 1090 | sequence |
| 1091 | maxspan 100ms |
| 1092 | |evt.name = 'CreateProcess' and ps.name = 'cmd.exe'| by ps.exe |
| 1093 | |evt.name = 'CreateFile' and file.path icontains 'temp'| by file.path |
| 1094 | `, &config.Config{EventSource: config.EventSourceConfig{EnableFileIOEvents: true}, Filters: &config.Filters{}}) |
| 1095 | require.NoError(t, f.Compile()) |
| 1096 | |
| 1097 | ss := newSequenceState(f, c, new(ps.SnapshotterMock)) |
| 1098 | |
| 1099 | e1 := &event.Event{ |
| 1100 | Type: event.CreateProcess, |
| 1101 | Name: "CreateProcess", |
| 1102 | Tid: 2484, |
| 1103 | PID: 859, |
| 1104 | PS: &pstypes.PS{ |
| 1105 | Name: "cmd.exe", |
| 1106 | Exe: "C:\\Windows\\system32\\svchost.exe", |
| 1107 | }, |
| 1108 | Params: event.Params{ |
| 1109 | params.ProcessID: {Name: params.ProcessID, Type: params.Uint32, Value: uint32(4143)}, |
| 1110 | }, |
| 1111 | Metadata: map[event.MetadataKey]any{"foo": "bar", "fooz": "barzz"}, |
| 1112 | } |
| 1113 | |
| 1114 | e2 := &event.Event{ |
| 1115 | Type: event.RenameFile, |
| 1116 | Name: "RenameFile", |
| 1117 | Tid: 2484, |
| 1118 | PID: 859, |
| 1119 | PS: &pstypes.PS{ |
| 1120 | Name: "cmd.exe", |
| 1121 | Exe: "C:\\Windows\\system32\\svchost.exe", |
| 1122 | }, |
| 1123 | Params: event.Params{ |
| 1124 | params.FilePath: {Name: params.FilePath, Type: params.UnicodeString, Value: "C:\\Temp\\dropper"}, |
| 1125 | }, |
| 1126 | Metadata: map[event.MetadataKey]any{"foo": "bar", "fooz": "barzz"}, |
| 1127 | } |
| 1128 | |
| 1129 | assert.False(t, ss.filter.GetSequence().Expressions[0].IsEvaluable(e2)) |
| 1130 | assert.True(t, ss.filter.GetSequence().Expressions[0].IsEvaluable(e1)) |
| 1131 | } |
nothing calls this directly
no test coverage detected