File integrity monitoring with AIDE: baseline approval and tamper tests

File integrity monitoring with AIDE: baseline approval and tamper tests

After a configuration rollout, a service may still start successfully even when you cannot confirm that every file change on disk was approved: permissions may have been loosened, scripts replaced, or old configuration files deleted. File integrity monitoring answers “How does the current state differ from the verified state?” It does not identify who performed an operation. This article sets up an isolated AIDE lab on a dedicated server to test additions, deletions, content changes, and baseline approval.

1. Define the trusted baseline and monitoring scope

Configuration files, scripts, and service units that should remain stable after a deployment are good candidates for monitoring. Logs, database data files, and constantly changing caches should not be covered by the same rules without adjustment. Applying content-hash checks to an entire application directory can produce so many legitimate differences that genuine anomalies get lost in the noise.

This lab uses Debian 12, with commands run in a shell that has administrative privileges. It scans only the newly created /srv/integrity-lab directory, does not modify production configuration, and does not replace any existing system AIDE database. Before starting, confirm that the lab paths below do not already exist. If they do, establish what they are used for rather than overwriting them.

A baseline is trustworthy only if the state of the files was verified when it was captured. Initializing a baseline on a machine whose state is unknown merely records that state; it does not prove that the state is secure.

File hashes indicate whether content has changed; permissions, ownership, and link counts indicate whether access boundaries have changed. Both need to be checked. A baseline should also be linked to a configuration version, review records, and the environment in which it was captured. A database file without that context is not enough.

2. Create an isolated configuration and verify a clean state

Install the tool, then create three test files. If installation starts the distribution’s built-in initialization task, let it finish. The separate configuration below does not depend on that task’s results.

apt-get update
apt-get install --yes aide
install -d -m 0700 /var/lib/aide-lab
install -d -m 0750 /srv/integrity-lab
printf 'mode=approved\n' > /srv/integrity-lab/app.conf
printf 'retain\n' > /srv/integrity-lab/retained.txt
printf 'remove-test\n' > /srv/integrity-lab/removed.txt
chmod 0640 /srv/integrity-lab/*
cat > /etc/aide-lab.conf <<'EOF'
database_in=file:/var/lib/aide-lab/baseline.db
database_out=file:/var/lib/aide-lab/candidate.db
gzip_dbout=no
report_url=stdout
Stable=p+i+n+u+g+s+m+c+sha256
^/srv/integrity-lab(/|$) Stable
EOF
chmod 0600 /etc/aide-lab.conf
aide --config=/etc/aide-lab.conf --config-check
aide --config=/etc/aide-lab.conf --init

The rule records permissions, inode, link count, ownership, size, modification time, status change time, and SHA-256. Access time is omitted so that ordinary reads do not generate meaningless reports. The path expression matches the directory boundary, preventing similarly named directories from being included.

Initialization produces a candidate database. Review the scan scope and file list first. Once you have confirmed that they are correct, promote the candidate for the first time:

chmod 0600 /var/lib/aide-lab/candidate.db
mv /var/lib/aide-lab/candidate.db /var/lib/aide-lab/baseline.db
aide --config=/etc/aide-lab.conf --check

A clean check should return zero and report no differences. If changes already appear at this point, investigate whether a background process is modifying the files. Do not repeatedly update the database just to clear the report.

3. Introduce three controlled types of change and preserve the exit code

The following operations affect only the lab files: replace the configuration content, delete one file, and add another. The new configuration is the same length as the original, allowing you to verify that the check does not rely on file size alone.

printf 'mode=unwanted\n' > /srv/integrity-lab/app.conf
rm -- /srv/integrity-lab/removed.txt
printf 'unexpected\n' > /srv/integrity-lab/added.txt

if aide --config=/etc/aide-lab.conf --check \
  > /var/lib/aide-lab/check.txt 2>&1; then
  rc=0
else
  rc=$?
fi
printf 'aide_exit=%s\n' "$rc"
cat /var/lib/aide-lab/check.txt

AIDE combines difference exit codes as bit flags: 1 for additions, 2 for deletions, and 4 for changes. This lab includes all three, so the expected result is 7. The directory itself may also be reported because its entries have changed; this is normal.

Not every nonzero exit code means “tampering detected.” Configuration errors, read failures, and other problems can also produce nonzero results. Use the full report to distinguish execution failures from file differences. The conditional above preserves the exit status so that an automation script configured to exit on error does not stop before the report has been archived.

Acceptance testing must cover at least four points: the added path is reported, the deleted path is reported, the configuration hash change is detected, and the untouched file shows no content change. If the report lists only permission or timestamp changes without a hash difference, check whether the rule actually includes a content digest.

4. Approve the candidate database instead of automatically accepting anomalies

When unexplained changes are found in production, pause baseline promotion, preserve the report and the old database, and investigate against deployment records. Do not chain checks, updates, and database replacement into an unreviewed pipeline. Doing so would let monitoring automatically accept the post-attack state.

All three types of change in this lab were produced by the commands above. After reviewing the report, you can treat them as an approved change. Archive the following before updating:

archive=$(mktemp -d /var/lib/aide-lab/review.XXXXXX)
cp -p /var/lib/aide-lab/baseline.db "$archive/"
cp -p /var/lib/aide-lab/check.txt "$archive/"
cp -p /etc/aide-lab.conf "$archive/"

Next, run aide --config=/etc/aide-lab.conf --update, again preserving the output and exit code. A difference exit code during an update does not necessarily mean that candidate database generation failed. Nor is it sufficient grounds for approval: confirm that there were no execution errors and that the report contains only reviewed changes.

Pause deployments within the monitored scope between checking and updating, so that the state being reviewed is the same state recorded in the candidate database. Only after confirming that the candidate database exists and its permissions are restricted should you move it to baseline.db and run --check again. This check should show no differences. Any remaining differences indicate that files are still changing or that the promotion process is incorrect; investigate the cause.

5. Validate both the reporting workflow and the trust boundaries

Automated checks should only read the baseline and produce reports. They should not have authority within the workflow to approve a new baseline. Separate alerts into at least two categories—“differences detected” and “check failed”—and retain the machine identifier, execution time, configuration version, exit code, and raw output. Reports may expose the directory structure, so restrict who can read them.

Before putting the workflow into production, repeat the content-change test with a non-production file. Confirm that the scheduled task actually runs, that a nonzero status triggers a notification, and that the report can be retrieved. Then restore or accept the change through the approval process. Merely confirming that the script ran successfully is not enough.

An attacker with elevated local privileges may be able to replace the files, baseline, and checking program together. The trusted database and reports therefore need to be copied to a separate, controlled location. If you suspect that the entire host has been compromised, read and verify them from a trusted environment rather than continuing to trust checks performed on that host.

AIDE is suited to detecting when stable files deviate from an approved state. It is not a tool for real-time blocking, attributing actions to an operator, or recovering data. Acceptance testing is complete not when the report turns green, but when every change has an explanation, every baseline replacement has a documented basis, and evidence of the previous state remains traceable.

Frequently asked questions

Does an AIDE change report prove that a server was compromised?

No. It establishes that file content or attributes differ from the baseline. Check package updates and approved deployments before drawing conclusions. AIDE does not identify who made the change.

Should the baseline be updated after every detected change?

No. Preserve the previous database and report, then investigate every difference. Promote a candidate database only after all changes have been approved.

Can a local database withstand a privileged attacker on its own?

No. A privileged attacker may replace the database, configuration and checker. Keep trusted baseline copies and reports in a separately controlled location.

AMD EPYC 7543P dedicated server,from $445.3/month

Turn workload plans into a server configuration

Choose 128 GB or 256 GB of DDR4-3200 ECC RDIMM with the AMD EPYC 7543P. Check the configuration page for available options.