aide
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revision | |||
| aide [2025/10/22 15:39] – jianwu | aide [Unknown date] (current) – removed - external edit (Unknown date) 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | [[https:// | ||
| - | |||
| - | ===== How to install and configure AIDE on Ubuntu ===== | ||
| - | <code Text> | ||
| - | AIDE (Advanced Intrusion Detection Environment) is a host-based file integrity checker. | ||
| - | It monitors your filesystem for unauthorized changes (such as tampering with binaries, configs, or permissions). | ||
| - | </ | ||
| - | [[https:// | ||
| - | ==== Step 1. Install AIDE ==== | ||
| - | <code Bash> | ||
| - | sudo apt update | ||
| - | sudo apt install aide -y | ||
| - | </ | ||
| - | |||
| - | This installs AIDE and creates a default configuration file at: | ||
| - | <code Bash> | ||
| - | / | ||
| - | </ | ||
| - | |||
| - | ==== Step 2. Initialize the AIDE database ==== | ||
| - | AIDE uses a baseline database of file checksums, permissions, | ||
| - | |||
| - | Initialize it with: | ||
| - | |||
| - | <code Bash> | ||
| - | sudo aideinit | ||
| - | </ | ||
| - | |||
| - | |||
| - | This command: | ||
| - | |||
| - | Scans your system according to the rules in / | ||
| - | |||
| - | Creates a new database at: | ||
| - | <code Bash> | ||
| - | / | ||
| - | </ | ||
| - | |||
| - | Then rename it to make it the active baseline: | ||
| - | |||
| - | <code Bash> | ||
| - | sudo mv / | ||
| - | </ | ||
| - | |||
| - | :!: Tip: Run this step only when the system is in a known good state (no malware, correct configs). | ||
| - | |||
| - | ==== Step 3. Run checks ==== | ||
| - | |||
| - | You can now manually check for changes anytime: | ||
| - | |||
| - | <code Bash> | ||
| - | sudo aide --check | ||
| - | </ | ||
| - | |||
| - | |||
| - | If files have been added, removed, or modified, AIDE will print a detailed report. | ||
| - | |||
| - | Typical output: | ||
| - | |||
| - | <code Bash> | ||
| - | AIDE found differences between database and filesystem!! | ||
| - | Summary: | ||
| - | Total number of entries: 12345 | ||
| - | Added entries: 2 | ||
| - | Removed entries: 0 | ||
| - | Changed entries: 1 | ||
| - | </ | ||
| - | |||
| - | |||
| - | To view details, scroll through the terminal or redirect output to a file: | ||
| - | |||
| - | <code Bash> | ||
| - | sudo aide --check | less | ||
| - | </ | ||
| - | |||
| - | ==== Step 4. Update the database after legitimate changes ==== | ||
| - | |||
| - | When you intentionally change system files (for example, after an update), rebuild the database: | ||
| - | |||
| - | <code Bash> | ||
| - | sudo aide --update | ||
| - | sudo mv / | ||
| - | </ | ||
| - | |||
| - | This updates your baseline so AIDE won’t keep alerting you about legitimate changes. | ||
| - | |||
| - | ===== Step 5. Automate daily checks (optional but recommended) ===== | ||
| - | |||
| - | To automate AIDE checks, add a cron job: | ||
| - | |||
| - | <code Bash> | ||
| - | sudo nano / | ||
| - | </ | ||
| - | |||
| - | |||
| - | Paste this script: | ||
| - | |||
| - | <code Bash> | ||
| - | #!/bin/bash | ||
| - | / | ||
| - | </ | ||
| - | |||
| - | |||
| - | Then make it executable: | ||
| - | |||
| - | <code Bash> | ||
| - | sudo chmod +x / | ||
| - | </ | ||
| - | |||
| - | You can configure email delivery by setting up a local mailer (e.g., postfix or ssmtp) or redirect the report to a log file. | ||
| - | |||
| - | ===== Step 6. (Optional) Customize configuration ===== | ||
| - | |||
| - | Edit / | ||
| - | |||
| - | Examples: | ||
| - | <code Bash> | ||
| - | # Add custom directory | ||
| - | /etc | ||
| - | |||
| - | # Exclude temporary directories | ||
| - | !/tmp | ||
| - | !/var/tmp | ||
| - | !/run | ||
| - | </ | ||
| - | |||
| - | |||
| - | Then reinitialize the database after saving changes: | ||
| - | |||
| - | <code Bash> | ||
| - | sudo aideinit | ||
| - | sudo mv / | ||
| - | </ | ||
| - | |||
| - | ==== Good practices ==== | ||
| - | <code Text> | ||
| - | Keep the AIDE database secure — store a copy offline or on read-only media. | ||
| - | If attackers can alter both your files and the AIDE database, they can hide their tracks. | ||
| - | |||
| - | Run after updates — rebuild the database only after verifying legitimate updates. | ||
| - | |||
| - | Integrate with monitoring — send reports to a centralized system (email, SIEM, or log server). | ||
| - | </ | ||
| - | |||
| - | ==== How to configure custom AIDE rules on Ubuntu ==== | ||
| - | AIDE’s power comes from its configuration file, usually located at: | ||
| - | |||
| - | <code Bash> | ||
| - | / | ||
| - | </ | ||
| - | |||
| - | This file defines: | ||
| - | |||
| - | Which files/ | ||
| - | |||
| - | What attributes to check (permissions, | ||
| - | |||
| - | Which paths to ignore | ||
| - | |||
| - | Below, I’ll show you how to: | ||
| - | |||
| - | 1. Understand rule syntax | ||
| - | |||
| - | 2. Define your own rules | ||
| - | |||
| - | 3. Configure AIDE to monitor only what you need | ||
| - | |||
| - | 4. Test your configuration safely | ||
| - | |||
| - | ==== Step 1. Understand AIDE rule syntax ==== | ||
| - | |||
| - | Each line in aide.conf has this general format: | ||
| - | |||
| - | <code Bash> | ||
| - | <path or pattern> | ||
| - | </ | ||
| - | |||
| - | Examples: | ||
| - | |||
| - | <code Bash> | ||
| - | /etc NORMAL | ||
| - | / | ||
| - | !/tmp | ||
| - | </ | ||
| - | |||
| - | A line starting with ! means “exclude this path”. | ||
| - | |||
| - | A rule like NORMAL refers to a rule definition (explained next). | ||
| - | |||
| - | You can also directly specify what to check, like p+i+n+u+g+s+m+c+sha512. | ||
| - | |||
| - | ==== Step 2. Understand the rule components ==== | ||
| - | |||
| - | Each letter corresponds to an attribute to check. | ||
| - | |||
| - | Here are the most useful ones: | ||
| - | |||
| - | |Code^Meaning^Example^ | ||
| - | ^p|Permissions|File mode changes| | ||
| - | ^i|Inode number|Detect moved/ | ||
| - | ^n|Number of links|Detect added hard links| | ||
| - | ^u|User (owner)|Owner changed| | ||
| - | ^g|Group|Group ownership changed| | ||
| - | ^s|Size|File grew/ | ||
| - | ^m|Modification time|Changed content| | ||
| - | ^c|Change time (inode metadata)|Metadata change| | ||
| - | ^a|Access time|(Usually ignored; too frequent)| | ||
| - | ^sha512|Hash algorithm|Detects content tampering| | ||
| - | |||
| - | Example combined rule: | ||
| - | <code Bash> | ||
| - | p+i+n+u+g+s+m+c+sha512 | ||
| - | </ | ||
| - | → Checks almost everything important, using SHA-512 for content integrity. | ||
| - | |||
| - | ==== Step 3. Define your custom rules ==== | ||
| - | |||
| - | Open the configuration file: | ||
| - | |||
| - | <code Bash> | ||
| - | sudo nano / | ||
| - | </ | ||
| - | |||
| - | Scroll to the bottom (after the default rules) and add your own: | ||
| - | <code Bash> | ||
| - | # ===== Custom Rules ===== | ||
| - | # Define a strong rule for system configuration files | ||
| - | CUSTOM = p+i+n+u+g+s+m+c+sha512 | ||
| - | |||
| - | # Directories to monitor | ||
| - | /etc | ||
| - | / | ||
| - | / | ||
| - | / | ||
| - | |||
| - | # Exclude temporary and runtime directories | ||
| - | !/tmp | ||
| - | !/var/tmp | ||
| - | !/run | ||
| - | !/proc | ||
| - | !/sys | ||
| - | !/dev | ||
| - | !/mnt | ||
| - | !/media | ||
| - | </ | ||
| - | |||
| - | |||
| - | === Explanation: | ||
| - | <code Bash> | ||
| - | /etc — monitors configuration files. | ||
| - | |||
| - | /usr/bin and /usr/sbin — monitors system executables. | ||
| - | |||
| - | /var/www — monitors your web server files (if applicable). | ||
| - | |||
| - | The excluded directories change too often or contain temporary data. | ||
| - | </ | ||
| - | |||
| - | ==== Step 4. Initialize AIDE again ==== | ||
| - | After editing the config, you must rebuild the database: | ||
| - | <code Bash> | ||
| - | sudo aideinit | ||
| - | sudo mv / | ||
| - | </ | ||
| - | |||
| - | ==== Step 5. Test your configuration ==== | ||
| - | |||
| - | Run a manual check: | ||
| - | |||
| - | <code Bash> | ||
| - | sudo aide --check | ||
| - | </ | ||
| - | |||
| - | |||
| - | Change something intentionally (for testing): | ||
| - | |||
| - | <code Bash> | ||
| - | sudo touch / | ||
| - | </ | ||
| - | |||
| - | Run the check again: | ||
| - | |||
| - | <code Bash> | ||
| - | sudo aide --check | ||
| - | </ | ||
| - | |||
| - | You should see output like: | ||
| - | |||
| - | <code Bash> | ||
| - | AIDE found differences between database and filesystem!! | ||
| - | Added entries: 1 | ||
| - | / | ||
| - | </ | ||
| - | |||
| - | |||
| - | Then remove the test file and update your database if all is well: | ||
| - | |||
| - | <code Bash> | ||
| - | sudo rm / | ||
| - | sudo aide --update | ||
| - | sudo mv / | ||
| - | </ | ||
| - | |||
| - | ==== Step 6. (Optional) Automate your custom checks ==== | ||
| - | |||
| - | If you want AIDE to run your custom configuration daily, ensure the cron job (from the previous setup) uses this command: | ||
| - | <code Bash> | ||
| - | / | ||
| - | </ | ||
| - | |||
| - | ==== Pro tips ==== | ||
| - | |||
| - | Use multiple rules for different sensitivity levels: | ||
| - | |||
| - | <code Bash> | ||
| - | SYSTEM = p+i+n+u+g+s+m+c+sha512 | ||
| - | LOGS = p+u+g+s | ||
| - | </ | ||
| - | |||
| - | Then apply them selectively: | ||
| - | |||
| - | <code Bash> | ||
| - | /etc SYSTEM | ||
| - | / | ||
| - | </ | ||
| - | |||
| - | Protect your AIDE database: | ||
| - | |||
| - | Store a copy offline or on read-only media (/ | ||
| - | |||
| - | Example backup: | ||
| - | |||
| - | <code Bash> | ||
| - | sudo cp / | ||
| - | </ | ||
| - | |||
| - | Combine with systemd service (optional): | ||
| - | |||
| - | You can create a systemd timer to run AIDE weekly instead of using cron. | ||
| - | |||
| - | ==== Summary ==== | ||
| - | |Step^Command^Description^ | ||
| - | ^1|$ sudo nano / | ||
| - | ^2|Add custom rules|Define CUSTOM = p+i+n+u+g+s+m+c+sha512| | ||
| - | ^3|Add directories & exclusions|/ | ||
| - | ^4|$ sudo aideinit|Rebuild baseline| | ||
| - | ^5|$ sudo aide --check|Verify changes| | ||
| - | ^6|(Optional) Automate|Cron or systemd timer| | ||