Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion pkg/yara/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ func NewScanner(psnap ps.Snapshotter, config config.Config) (Scanner, error) {
return nil
}
rulesInCompiler.Add(1)
log.Infof("loading yara rule(s) from %s", filepath.Join(path, fi.Name()))

return nil
})
Expand Down Expand Up @@ -277,7 +278,8 @@ func (s scanner) Scan(e *kevent.Kevent) (bool, error) {
// scan process mapping a suspicious RX/RWX section view
pid := e.Kparams.MustGetPid()
prot := e.Kparams.MustGetUint32(kparams.MemProtect)
if e.PID != 4 && ((prot&kevent.SectionRX) != 0 && (prot&kevent.SectionRWX) != 0) {
size := e.Kparams.MustGetUint64(kparams.FileViewSize)
if e.PID != 4 && size >= 4096 && ((prot&kevent.SectionRX) != 0 && (prot&kevent.SectionRWX) != 0) {
filename := e.GetParamAsString(kparams.FileName)
// skip mappings of signed images
addr := e.Kparams.MustGetUint64(kparams.FileViewBase)
Expand Down
4 changes: 4 additions & 0 deletions pkg/yara/scanner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,7 @@ func TestScan(t *testing.T) {
Kparams: kevent.Kparams{
kparams.ProcessID: {Name: kparams.ProcessID, Type: kparams.PID, Value: pid},
kparams.FileViewBase: {Name: kparams.FileViewBase, Type: kparams.Address, Value: uint64(0x7ffe0000)},
kparams.FileViewSize: {Name: kparams.FileViewSize, Type: kparams.Uint64, Value: uint64(12333)},
kparams.MemProtect: {Name: kparams.MemProtect, Type: kparams.Flags, Value: uint32(kevent.SectionRX), Flags: kevent.ViewProtectionFlags},
},
Metadata: make(map[kevent.MetadataKey]any),
Expand Down Expand Up @@ -780,6 +781,7 @@ func TestScan(t *testing.T) {
Kparams: kevent.Kparams{
kparams.ProcessID: {Name: kparams.ProcessID, Type: kparams.PID, Value: uint32(1123)},
kparams.FileViewBase: {Name: kparams.FileViewBase, Type: kparams.Address, Value: uint64(0x7f3e1000)},
kparams.FileViewSize: {Name: kparams.FileViewSize, Type: kparams.Uint64, Value: uint64(12333)},
kparams.MemProtect: {Name: kparams.MemProtect, Type: kparams.Flags, Value: uint32(kevent.SectionRX), Flags: kevent.ViewProtectionFlags},
},
Metadata: make(map[kevent.MetadataKey]any),
Expand Down Expand Up @@ -828,6 +830,7 @@ func TestScan(t *testing.T) {
Kparams: kevent.Kparams{
kparams.ProcessID: {Name: kparams.ProcessID, Type: kparams.PID, Value: uint32(321321)},
kparams.FileViewBase: {Name: kparams.FileViewBase, Type: kparams.Address, Value: uint64(0x7ffe0000)},
kparams.FileViewSize: {Name: kparams.FileViewSize, Type: kparams.Uint64, Value: uint64(12333)},
kparams.MemProtect: {Name: kparams.MemProtect, Type: kparams.Flags, Value: uint32(0x10000), Flags: kevent.ViewProtectionFlags},
},
Metadata: make(map[kevent.MetadataKey]any),
Expand Down Expand Up @@ -877,6 +880,7 @@ func TestScan(t *testing.T) {
kparams.ProcessID: {Name: kparams.ProcessID, Type: kparams.PID, Value: uint32(1123)},
kparams.FileName: {Name: kparams.FileName, Type: kparams.UnicodeString, Value: filepath.Join(os.Getenv("windir"), "regedit.exe")},
kparams.FileViewBase: {Name: kparams.FileViewBase, Type: kparams.Address, Value: uint64(0x7ffe0000)},
kparams.FileViewSize: {Name: kparams.FileViewSize, Type: kparams.Uint64, Value: uint64(12333)},
kparams.MemProtect: {Name: kparams.MemProtect, Type: kparams.Flags, Value: uint32(kevent.SectionRWX), Flags: kevent.ViewProtectionFlags},
},
Metadata: make(map[kevent.MetadataKey]any),
Expand Down
Loading