Blog | G5 Cyber Security

AuditD Syscall Monitoring

TL;DR

This guide shows you how to set up AuditD on Linux to monitor system calls and generate alerts when specific, potentially malicious activities occur. We’ll focus on practical rules for common security events.

1. Install AuditD

Most Linux distributions include AuditD by default. If not, install it using your package manager:

After installation, start and enable the AuditD service:

sudo systemctl start auditd
sudo systemctl enable auditd

2. Configure Audit Rules

Audit rules are defined in files under /etc/audit/rules.d/. Create a new rule file (e.g., syscall_alerts.rules) or edit an existing one.

Here are some example rules:

2.1 Monitor Executable File Changes

This rule logs when executable files are modified, created, or deleted.

-w /usr/bin -p wa -k exec_changes

2.2 Monitor System Call execve

The execve system call is used to execute programs. Monitoring it can detect malicious program launches.

-a always,exit -F arch=b64 -S execve -k exec_calls

2.3 Monitor System Call open

The open syscall is used to open files. Monitoring it can detect access to sensitive files.

-a always,exit -F arch=b64 -S open -k file_accesses

3. Reload Audit Rules

After adding or modifying rules, reload them:

sudo auditctl -R /etc/audit/rules.d/syscall_alerts.rules

To check if the rules are loaded correctly:

sudo auditctl -l

4. View Audit Logs

Audit logs are stored in /var/log/audit/audit.log.

Use ausearch to search for specific events:

5. Set up Alerts (Example using auditd-report)

While AuditD itself doesn’t provide real-time alerting, you can use tools to parse the logs and trigger alerts.

Here’s a simple example using auditd-report. This isn’t real-time but demonstrates how to extract information for alert creation:

5.1 Create a Report Script

Create a script (e.g., check_execve.sh) to check for unusual execve calls:

#!/bin/bash
# Check for execve events in the last hour
ausarch -c execve -ts recent | grep 'comm=' > /tmp/execve_log
if [ -s /tmp/execve_log ]; then
echo "Possible unusual execve calls detected!"
  mail -s "AuditD Alert: Unusual Execve Calls" your_email@example.com < /tmp/execve_log
fi
rm /tmp/execve_log

Make the script executable:

chmod +x check_execve.sh

5.2 Schedule the Script

Use cron to run the script periodically (e.g., every hour):

crontab -e

Add a line like this:

0 * * * * /path/to/check_execve.sh

6. Further Considerations

Exit mobile version