Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ignored comms for /etc/shadow access #490

Merged
merged 3 commits into from
Feb 23, 2025
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
38 changes: 38 additions & 0 deletions pkg/ruleengine/v1/r0010_unexpected_sensitive_file_access.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,37 @@ func CreateRuleR0010UnexpectedSensitiveFileAccess() *R0010UnexpectedSensitiveFil
}
}

var legitimateProcessNames = []string{
"systemd",
"sudo",
"passwd",
"chpasswd",
"useradd",
"usermod",
"chage",
"sshd",
"login",
"su",
"groupadd",
"groupmod",
"dpkg",
"rpm",
"ansible",
"puppet-agent",
"chef-client",
"vipw",
"pwck",
"grpck",
"nscd",
"cron",
"crond",
"pam",
"snap",
"apk",
"yum",
"dnf",
}

func (rule *R0010UnexpectedSensitiveFileAccess) SetParameters(parameters map[string]interface{}) {
rule.BaseRule.SetParameters(parameters)

Expand Down Expand Up @@ -102,6 +133,13 @@ func (rule *R0010UnexpectedSensitiveFileAccess) ProcessEvent(eventType utils.Eve
if err != nil {
return nil
}
} else {
// Running without application profile, to avoid false positives check if the process name is legitimate
for _, processName := range legitimateProcessNames {
if processName == openEvent.Comm {
return nil
}
}
}

if !utils.IsSensitivePath(openEvent.FullPath, rule.additionalPaths) {
Expand Down
26 changes: 25 additions & 1 deletion pkg/ruleengine/v1/r1000_exec_from_malicious_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,21 @@ func (rule *R1000ExecFromMaliciousSource) ID() string {
return R1000ID
}

func (rule *R1000ExecFromMaliciousSource) ProcessEvent(eventType utils.EventType, event utils.K8sEvent, _ objectcache.ObjectCache) ruleengine.RuleFailure {
var whitelistedProcessesForMaliciousSource = []string{
"systemd",
"docker",
"containerd",
"snap-confine",
"nginx",
"apache2",
"bash",
"dash",
"sh",
"perl",
"supervisord",
}

func (rule *R1000ExecFromMaliciousSource) ProcessEvent(eventType utils.EventType, event utils.K8sEvent, objCache objectcache.ObjectCache) ruleengine.RuleFailure {
if eventType != utils.ExecveEventType {
return nil
}
Expand All @@ -61,6 +75,16 @@ func (rule *R1000ExecFromMaliciousSource) ProcessEvent(eventType utils.EventType

var maliciousExecPathPrefixes = []string{
"/dev/shm",
"/proc/self/fd",
}

if objCache == nil {
// Running without object cache, to avoid false positives check if the process name is legitimate
for _, processName := range whitelistedProcessesForMaliciousSource {
if processName == execEvent.Comm {
return nil
}
}
}

execPath := GetExecFullPathFromEvent(execEvent)
Expand Down
Loading