Skip to content

Commit a0ca53b

Browse files
committed
solidify drive letter detection in command line, scope file.status field to CreateFile events
1 parent 155ddb0 commit a0ca53b

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

pkg/filter/accessor_windows.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,9 @@ func (l *fileAccessor) get(f fields.Field, kevt *kevent.Kevent) (kparams.Value,
614614
}
615615
return attrs, nil
616616
case fields.FileStatus:
617+
if kevt.Type != ktypes.CreateFile {
618+
return nil, nil
619+
}
617620
return kevt.Kparams.GetString(kparams.NTStatus)
618621
}
619622
return nil, nil

pkg/kstream/interceptors/ps_windows.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ import (
4141
// systemRootRegexp is the regular expression for detecting path with unexpanded SystemRoot environment variable
4242
var systemRootRegexp = regexp.MustCompile(`%SystemRoot%|^\\SystemRoot|%systemroot%`)
4343

44+
// driveRegexp is used for determining if the command line start with a valid drive letter based path
45+
var driveRegexp = regexp.MustCompile(`^[a-zA-Z]:\\`)
46+
4447
// procYaraScans stores the total count of yara process scans
4548
var procYaraScans = expvar.NewInt("yara.proc.scans")
4649

@@ -87,8 +90,9 @@ func (ps psInterceptor) Intercept(kevt *kevent.Kevent) (*kevent.Kevent, bool, er
8790
if systemRootRegexp.MatchString(cmdline) {
8891
cmdline = systemRootRegexp.ReplaceAllString(cmdline, os.Getenv("SystemRoot"))
8992
}
90-
// some system processes are reported without the path in command line
91-
if strings.Index(cmdline, `:\\`) != 1 {
93+
// some system processes are reported without the path in the command line,
94+
// but we can expand the path from the SystemRoot environment variable
95+
if !driveRegexp.MatchString(cmdline) {
9296
proc, _ := kevt.Kparams.GetString(kparams.ProcessName)
9397
_, ok := sysProcs[proc]
9498
if ok {

0 commit comments

Comments
 (0)