Skip to content

Commit a94d08a

Browse files
committed
fix(rule-engine): Add expire sequence condition for CreateThread event
If the process termination event arrives, and the sequence contains CreateThread events where the event pid and the pid in the parameters differ, the sequence can be expired when the remote process terminates.
1 parent 3df8f30 commit a94d08a

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

pkg/rules/sequence.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -538,12 +538,19 @@ func (s *sequenceState) expire(e *kevent.Kevent) bool {
538538
// process spawned by CreateProcess, and it pertains
539539
// to the final sequence slot, it is safe to expire
540540
// the whole sequence
541+
pid := rhs.Kparams.MustGetPid()
541542
if lhs.Type == ktypes.CreateProcess && isFinalSlot {
542-
p1, _ := lhs.Kparams.GetPid()
543-
p2, _ := rhs.Kparams.GetPid()
544-
return p1 == p2
543+
return lhs.Kparams.MustGetPid() == pid
544+
}
545+
if lhs.Type == ktypes.CreateThread {
546+
// if the pids differ, the thread
547+
// is created in a remote process.
548+
// Sequence can be expired only if
549+
// the remote process terminates
550+
if lhs.PID != lhs.Kparams.MustGetPid() {
551+
return lhs.Kparams.MustGetPid() == pid
552+
}
545553
}
546-
pid, _ := rhs.Kparams.GetPid()
547554
return lhs.PID == pid
548555
}
549556
s.mu.Lock()

0 commit comments

Comments
 (0)