Skip to content

Add a rule to detect for files created in /dev/shm for execution #2

@steveandreassend

Description

@steveandreassend

To track executions of arbitrary scripts stored in /dev/shm that may be created by mktemp using auditd in Linux, you can add an audit rule to monitor execve system calls for files in /dev/shm. Since mktemp typically creates temporary files with unpredictable names, the rule should cover all script executions in that directory.

Ref: https://sysdig.com/blog/containers-read-only-fileless-malware/

e.g.

-a always,exit -F arch=b64 -S execve -F dir=/dev/shm -k shm_script_exec
-a always,exit -F arch=b32 -S execve -F dir=/dev/shm -k shm_script_exec

Test:

TEMP_SCRIPT=$(mktemp /dev/shm/test_script.XXXXXX)
echo '#!/bin/bash' > "$TEMP_SCRIPT"
echo 'echo "Test script executed"' >> "$TEMP_SCRIPT"
chmod +x "$TEMP_SCRIPT"
"$TEMP_SCRIPT"

Validate:
sudo ausearch -k shm_script_exec

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions