Why use auditd and eBPF for ransomware detection on Linux
For Cybersecurity teams protecting Linux fleets, combining auditd and eBPF gives complementary visibility. auditd records syscall level events persistently, while eBPF provides low-latency, in-kernel filtering and enrichment. Together they detect fast, noisy, or stealthy ransomware actions such as mass file modifications, suspicious process spawning, and abnormal encryption activity.
This guide focuses on actionable rules and detectors, examples you can apply on servers, and practical response workflows to quarantine compromised hosts. The goal is to provide a production-ready foundation you can tune and integrate with your alerting stack.
Typical ransomware behaviors to detect
Ransomware often exhibits a set of observable behaviors before and during encryption. Detecting a combination of these signals reduces false positives compared to single-rule triggers. Look for bursts of write activity, recursive file modifications, deletion of backups, and abnormal use of legacy tools for crypto operations.
Common indicators include:
- High write rates to many files, often with file renames or new extensions
- Processes enumerating volumes then opening and writing many files
- Deletion or modification of snapshot or backup files
- Use of binary packing tools or in-place encryption routines
Designing auditd rules for suspicious file activity
Start by logging file write and attribute changes for critical paths, while avoiding global, noisy rules. Use targeted watches for web root, user home directories, mounts, and backup locations. Audit records include PID, UID, syscall, and file paths, which are essential for downstream correlation.
Example audit.rules to watch writes and renames for common targets:
-w /var/www -p wa -k web_write
-w /home -p wa -k home_write
-w /mnt/backups -p wa -k backups_write
-a always,exit -F arch=b64 -S rename -k file_rename
eBPF detectors with bpftrace for fast anomalies
Use eBPF and bpftrace to detect bursts and in-memory patterns that auditd may not catch quickly enough. eBPF can aggregate syscall counts per process and trigger when thresholds are exceeded, minimizing kernel to userspace overhead. Deploy lightweight bpftrace scripts on endpoints or as DaemonSets in Kubernetes.
Simple bpftrace script to alert on rapid write syscalls by a single PID:
k:syscalls:sys_enter_write
/comm != "(bpftrace)"/
{
@writes[pid] = count();
if (@writes[pid] > 100) {
printf("ALERT pid:%d comm:%s writes:%d\n", pid, comm, @writes[pid]);
}
}
Correlation and alerting, SIEM integration
Alone, individual alerts cause noise. Correlate auditd file events with eBPF write bursts, process ancestry, and network connections to build high fidelity detections. Use a SIEM or log aggregator to join events by PID, timestamp, and host, and apply rules that require multiple indicators before escalating.
Common alert sinks and methods include:

- Forward auditd to syslog or via filebeat to your SIEM
- Push eBPF alerts via stdout to a collector or metrics pipeline
- Create correlation rules: for example, eBPF write burst plus rapid rename events within 10 seconds equals high severity
Automated quarantine and response workflows
When a correlated detection reaches your severity threshold, trigger an automated containment playbook. Actions should be reversible and safe, such as network isolation, process suspension, and snapshotting for forensic capture. Avoid aggressive destructive actions, and require human approval for irreversible steps.
Example quarantine script to isolate host and pause suspicious process:
# /usr/local/bin/quarantine.sh
HOST=$1
PID=$2
# isolate network via nftables
nft add table inet quarantine || true
nft add chain inet quarantine input { type filter hook input priority 0; }
nft add rule inet quarantine input ip saddr != 127.0.0.1 drop
# pause process
kill -STOP $PID
# create forensic tarball
tar -czf /tmp/forensic_${HOST}_$(date +%s).tgz /proc/$PID /var/log/audit/audit.log
Tuning rules to reduce false positives
Tune by whitelisting known bulk writers such as backup services, job schedulers, or CI runners. Use thresholding and adaptive windows, for example alert only when more than N writes occur to M unique files within T seconds. Maintain a suppression list for benign processes by UID or command path.
Tuning checklist:
- Whitelist backup and indexer processes by binary path
- Set dynamic thresholds based on host role and disk usage patterns
- Regularly review alerts and add targeted auditd exclusions where safe
Production deployment and scaling considerations
Deploy auditd rules via configuration management, and distribute eBPF detectors as containers or system packages. Monitor resource use: auditd disk usage, kernel ring buffer pressure, and eBPF program counts. Use sampling on noisy paths and centralize logs to avoid filling local disks.
Scaling tips include batching alerts, aggregating counts in eBPF to reduce events, and routing low priority events to cold storage. Test your detection chain under load to validate that detection latency remains acceptable.
FAQs
Quick answers to common operational questions when implementing this stack. These address practical limits, compatibility, and recovery actions after an alert.
Q: Will auditd slow down my servers? A: Properly scoped auditd rules have minimal impact. Global syscall auditing can be expensive, so target paths and specific syscalls. Use rate limits and monitor auditd queue sizes.
Q: Is eBPF safe to run in production? A: Yes, when using vetted tools and simple programs. eBPF runs in kernel context, so ensure scripts are tested and resource limits are applied. Prefer precompiled programs for stability.
Q: How do I avoid alert storms from updates or content pushes? A: Add short maintenance windows, whitelist CI/CD runner processes, and suppress alerts based on known deploy time markers. Correlate with commit metadata where possible.
Q: Can I recover encrypted files? A: Recovery depends on your backups and whether snapshots are intact. Automated quarantine helps preserve evidence and stop further encryption. Prioritize backups and offline copies.
Conclusion
Combining auditd and eBPF produces a layered detection capability, balancing persistence with real-time responsiveness. auditd gives a forensic record that you can query and retain, while eBPF provides fast anomaly detection that can trigger containment sooner. Implementing the examples in this guide gives you a baseline to detect mass write patterns, recursive renames, and process behaviors indicative of ransomware.
To deploy safely in production, follow the tuning advice: scope rules, whitelist trusted binaries, and correlate multiple signals before automated remediation. Integrate with your SIEM for lifecycle management, and build a small automated quarantine routine that preserves evidence while limiting blast radius. Regularly test and iterate on thresholds, and instrument resource impact to keep monitoring lightweight. With these controls in place, you will improve detection fidelity, reduce mean time to contain, and make your Linux environment resilient against ransomware threats.