rule linux_user_account_created_and_deleted_in_short_time_interval {
meta:
author = "ABC"
description = "New user created and deleted in short time interval"
events:
$e1.metadata.vendor_name = "Linux"
$e1.metadata.product_name = "AuditD"
$e1.metadata.product_event_type = "useradd" nocase
$e1.metadata.description != /failed/ nocase
$user1 = re.capture($e1.metadata.description, "new\\\\suser:\\\\sname=([^,]+),\\\\sUID=")
$e1.principal.hostname = $srcHost
$ts = $e1.metadata.event_timestamp.seconds
$user1 != ""
$e2.metadata.event_timestamp.seconds > $e1.metadata.event_timestamp.seconds
$e2.metadata.vendor_name = "Linux"
$e2.metadata.product_name = "AuditD"
$e2.metadata.description = /delete user/ nocase
$user2 = re.capture($e2.metadata.description, "delete user '([^']+)'")
$e2.principal.hostname = $srcHost
$ts = $e2.metadata.event_timestamp.seconds
strings.to_lower($user1) = strings.to_lower($user2)
match:
$user1 over 12h
outcome:
$risk_score = max(20)
$alertDescription = array_distinct(strings.concat("'A user '", $user1 , "' was created and deleted on the linux server with the hostname'", $srcHost , "'within a short time interval of '", ($e2.metadata.event_timestamp.seconds - $e1.metadata.event_timestamp.seconds)/60, "' minutes.'"))
condition:
$e1 and $e2
}
Here are few of the relevant fields for user account created and deleted.
metadata.description : "new user: name=testuser_hehe1, UID=1001, GID=1001, home=/home/testuser_hehe1, shell=/bin/sh, from=/dev/pts/0"
metadata.log_type : "AUDITD"metadata.product_event_type"useradd"
metadata.product_name : "AuditD"
metadata.vendor_name : "Linux"
and
metadata.description : "delete user 'testuser_hehe1'"
metadata.log_type : "AUDITD"
metadata.product_event_type : "userdel"
metadata.product_name : "AuditD"
metadata.vendor_name : "Linux"
Is there any issue with the rule I have written? since it is not detecting the required event .