Skip to content

Commit 93508ea

Browse files
committed
Fixed issues:
#9 #10
1 parent e13de70 commit 93508ea

File tree

2 files changed

+37
-29
lines changed

2 files changed

+37
-29
lines changed

collector/forwarder.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ func (f *Forwarder) ProcessQueue() {
300300
fd.Close()
301301
case strings.HasSuffix(fp, ".log.1"), strings.HasSuffix(fp, ".log"):
302302
err = f.Client.PostLogs(fd)
303+
fd.Close()
303304
}
304305

305306
// We do not remove the logs if we failed to send

tools/whids/hookdefs.go

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ type processTrack struct {
4242
PID int64
4343
CommandLine string
4444
ParentCommandLine string
45+
CurrentDirectory string
4546
ProcessGUID string
4647
User string
4748
ParentUser string
@@ -359,36 +360,39 @@ func hookTrack(e *evtx.GoEvtxMap) {
359360
if pguid, err := e.GetString(&pathSysmonParentProcessGUID); err == nil {
360361
if user, err := e.GetString(&pathSysmonUser); err == nil {
361362
if il, err := e.GetString(&pathSysmonIntegrityLevel); err == nil {
362-
track := &processTrack{
363-
Image: image,
364-
ParentImage: pImage,
365-
CommandLine: commandLine,
366-
ParentCommandLine: pCommandLine,
367-
PID: pid,
368-
User: user,
369-
IntegrityLevel: il,
370-
ProcessGUID: guid,
371-
ParentProcessGUID: pguid,
372-
History: make([]string, 0),
373-
Stats: stats{0, 0, 0, make(map[string]*int64)},
374-
}
375-
if parent := processTracker.GetByGuid(pguid); parent != nil {
376-
track.History = append(parent.History, parent.Image)
377-
track.ParentUser = parent.User
378-
track.ParentIntegrityLevel = parent.IntegrityLevel
379-
} else {
380-
// For processes created by System
381-
if pimage, err := e.GetString(&pathSysmonParentImage); err == nil {
382-
track.History = append(track.History, pimage)
363+
if cd, err := e.GetString(&pathSysmonCurrentDirectory); err == nil {
364+
track := &processTrack{
365+
Image: image,
366+
ParentImage: pImage,
367+
CommandLine: commandLine,
368+
ParentCommandLine: pCommandLine,
369+
CurrentDirectory: cd,
370+
PID: pid,
371+
User: user,
372+
IntegrityLevel: il,
373+
ProcessGUID: guid,
374+
ParentProcessGUID: pguid,
375+
History: make([]string, 0),
376+
Stats: stats{0, 0, 0, make(map[string]*int64)},
377+
}
378+
if parent := processTracker.GetByGuid(pguid); parent != nil {
379+
track.History = append(parent.History, parent.Image)
380+
track.ParentUser = parent.User
381+
track.ParentIntegrityLevel = parent.IntegrityLevel
382+
} else {
383+
// For processes created by System
384+
if pimage, err := e.GetString(&pathSysmonParentImage); err == nil {
385+
track.History = append(track.History, pimage)
386+
}
387+
}
388+
processTracker.Add(track)
389+
e.Set(&pathAncestors, strings.Join(track.History, "|"))
390+
if track.ParentUser != "" {
391+
e.Set(&pathParentUser, track.ParentUser)
392+
}
393+
if track.ParentIntegrityLevel != "" {
394+
e.Set(&pathParentIntegrityLevel, track.ParentIntegrityLevel)
383395
}
384-
}
385-
processTracker.Add(track)
386-
e.Set(&pathAncestors, strings.Join(track.History, "|"))
387-
if track.ParentUser != "" {
388-
e.Set(&pathParentUser, track.ParentUser)
389-
}
390-
if track.ParentIntegrityLevel != "" {
391-
e.Set(&pathParentIntegrityLevel, track.ParentIntegrityLevel)
392396
}
393397
}
394398
}
@@ -766,9 +770,11 @@ func hookEnrichAnySysmon(e *evtx.GoEvtxMap) {
766770

767771
default:
768772
hasComLine := true
773+
769774
// Default Values for the fields
770775
e.Set(&pathSysmonUser, "?")
771776
e.Set(&pathSysmonIntegrityLevel, "?")
777+
e.Set(&pathSysmonCurrentDirectory, "?")
772778

773779
if _, err := e.GetString(&pathSysmonCommandLine); err != nil {
774780
e.Set(&pathSysmonCommandLine, "?")
@@ -783,6 +789,7 @@ func hookEnrichAnySysmon(e *evtx.GoEvtxMap) {
783789
}
784790
e.Set(&pathSysmonUser, track.User)
785791
e.Set(&pathSysmonIntegrityLevel, track.IntegrityLevel)
792+
e.Set(&pathSysmonCurrentDirectory, track.CurrentDirectory)
786793
}
787794
}
788795
}

0 commit comments

Comments
 (0)