Sub topic 16
File Integrity Monitoring with AIDE
Assume you can use sudo, edit configuration files, and manage packages on a test Linux server. This chapter uses AIDE, the Advanced Intrusion Detection Environment. AIDE creates a database of trusted file properties, then compares later scans with that baseline.
AIDE checks properties such as:
- File permissions, owner, and group
- File size and timestamps
- Inode information
- Cryptographic hashes, such as SHA-256
- Selected directories and configuration files
AIDE does not monitor files continuously. A scheduled scan detects changes after they occur. It also cannot decide whether a change is authorized, so an administrator must investigate the result.
Create a trusted baseline
Install AIDE using the package manager for your distribution:
# RHEL, Rocky Linux, or Fedora
sudo dnf install aide
# Debian or Ubuntu
sudo apt update
sudo apt install aideReview /etc/aide.conf before creating the database. The configuration determines which paths AIDE includes and which properties it records. Include operating-system files and security-sensitive files, but exclude paths that change constantly, such as caches and temporary directories.
Check the configuration and create the initial database:
sudo aide --config-check
sudo aide --initThe new database is usually written beside the active database with a name such as aide.db.new.gz. Check the output and distribution documentation, then install it as the active baseline:
sudo find /var/lib/aide -maxdepth 1 -type f -printf '%f\n'
sudo mv /var/lib/aide/aide.db.new.gz /var/lib/aide/aide.db.gz
sudo chmod 600 /var/lib/aide/aide.db.gzThe exact database filename can differ. Do not overwrite an existing baseline until you have confirmed that the new file is valid.
Run scans and interpret changes
Run a comparison scan with:
sudo aide --checkA result with no changes supports the baseline. A changed file does not automatically mean an attack. Package upgrades, configuration management, log rotation, and administrator work can all produce legitimate changes.
Investigate each important change before updating the baseline. Compare it with package records, change tickets, deployment logs, and file contents. Update the database only after confirming that the current state is trusted:
sudo aide --updateThis creates a new database. Replace the active database using the filename reported by your distribution. Store a protected copy of the baseline away from the server. If an attacker can rewrite both the files and the AIDE database, AIDE cannot provide reliable evidence.
| Event | Action |
|---|---|
| Planned package update | Scan, review expected changes, then update the baseline |
| Unexpected change to `/etc` | Investigate immediately and preserve evidence |
| Clean scan | Record the result and continue scheduled scans |
Schedule and protect scans
Use a systemd timer or a cron job to run AIDE regularly. Send results to a central logging or alerting system. Keep the AIDE configuration and baseline protected with restrictive permissions, and monitor changes to both.
Exercise
Why should you investigate an AIDE change before running aide --update?
Show answer
Updating immediately would make the changed state the new trusted baseline, potentially hiding an unauthorized modification.