Kahibaro
Discord Login Register

7.1.3 File integrity monitoring

Why File Integrity Monitoring Matters

File integrity monitoring is about detecting unexpected or unauthorized changes to important files on a Linux system. Instead of trying to watch every operation in real time with your own eyes, you let tools record a known good state of files, then regularly compare the current state to that baseline. Any deviation can indicate legitimate changes such as upgrades, or malicious activity such as a compromise.

The core idea is simple. You decide which files are important, capture their attributes and cryptographic checksums, then compare those values in the future. This is a foundational hardening technique that supports intrusion detection, compliance, and forensic analysis.

File integrity monitoring never prevents changes. It only detects them. You must combine it with other hardening controls to protect the system.

What Gets Monitored

File integrity monitoring is only useful if you monitor the right things. On a hardened Linux system the focus is on files and directories that affect security, configuration, and system behavior.

Typical monitored areas include system binaries in /bin, /sbin, /usr/bin, and /usr/sbin, because changes here can indicate replacement of trusted programs. System configuration under /etc is monitored, since modifications can change authentication, networking, or service behavior. Boot related files, for example in /boot, may also be included, as well as scripts and service definitions that control what runs at startup.

In addition to system areas, you may choose to watch log configuration, security tools, web application code, or any custom scripts that implement business logic. Large and frequently changing data stores such as log files themselves or user home directories are usually excluded or handled with relaxed rules, otherwise you will drown in noise.

The goal is to define a clear set of critical paths that should be very stable under normal operation. The more stable the expected state, the easier it is to spot real problems.

What “Integrity” Means for Files

A file has many properties beyond its contents. File integrity monitoring tools capture a combination of these properties and then track changes over time. At a minimum, file contents are summarized using cryptographic hash functions. A hash such as SHA256 maps any input to a fixed length value. If even a single bit in the file changes, the hash output will differ with extremely high probability.

You can represent a hash as a function. If you have a file that is a sequence of bytes, you can call it $F$. A cryptographic hash function $H$ takes $F$ as input and produces a digest:

$$
D = H(F)
$$

If $D_1$ is the digest for the baseline and $D_2$ is the digest for the new version, then detecting tampering reduces to checking whether

$$
D_1 = D_2
$$

If they are not equal, the file has changed.

Beyond hashes, tools typically record file size, permissions, ownership, timestamps, and often extended attributes. Directories can be checked for new or deleted entries. These additional attributes help distinguish between harmless and suspicious modifications. For example, a changed timestamp without a changed hash might indicate a metadata adjustment but not a content alteration.

Cryptographic hashes such as SHA256 are designed so that given $D$ it is computationally infeasible to find a different file $F'$ with the same digest. This property is essential for reliable file integrity monitoring.

Baseline Creation

The first practical step in file integrity monitoring is building a baseline. The baseline is a snapshot of the monitored files at a time when you believe the system is in a trusted state. All later checks compare current values against this baseline.

For new systems, the ideal moment is right after installation, secure configuration, and initial updates, before exposing the system to untrusted networks or workloads. For existing systems, you must choose a point when you have high confidence that the machine is not compromised. If you build a baseline on an already compromised system, the monitoring will faithfully protect the attacker’s changes as if they were legitimate.

Creating a baseline typically involves installing a file integrity monitoring tool, configuring which paths to include or exclude, and running an initialization command. The tool reads file metadata and contents, computes hashes, and stores this information in a database or reference file.

This baseline data itself becomes a critical asset. If an attacker can modify it, they can hide their changes by updating the reference to match. Protecting the baseline is therefore as important as protecting the files it describes.

Comparing Against the Baseline

After the baseline is created, the operational phase begins. At regular intervals, the monitoring tool scans the same set of files and directories, computes their current attributes and hashes, and compares them with the stored baseline.

The comparison produces categories of change. You may see new files, which are present now but absent from the baseline, deleted files, which were in the baseline but are now missing, and modified files, where attributes or contents differ. Some tools also report moves or ownership changes separately.

A key challenge is reducing noise. Regular system maintenance, such as package upgrades or log rotations, will legitimately modify many files. To keep the reports meaningful, you must update the baseline after controlled, expected changes, or configure the tool to ignore specific patterns. Otherwise, administrators quickly learn to ignore the alerts, which defeats the purpose.

Scheduling also matters. You can run checks manually during maintenance windows, use cron to perform periodic scans, or integrate checks with configuration management. For critical systems, you may want more frequent scans or even continuous monitoring using kernel level hooks, at the cost of additional overhead.

Typical Tools and Approaches

Several tools implement file integrity monitoring on Linux. They follow the same core ideas but differ in complexity, performance, and integration.

A common class of tools uses periodic scanning based on preconfigured rules. They walk the filesystem, compute hashes such as SHA1 or SHA256, and store and compare results. These tools are relatively simple to deploy and understand. Their main limitation is that they detect changes only at scan time, not immediately when they happen.

Another approach uses kernel audit or inotify mechanisms to report file actions in near real time. Such systems can alert you when a file is created, opened, modified, or deleted, and can feed into central logging or security information platforms. They are more responsive but can generate a high volume of events and require careful filtering.

Larger security suites sometimes bundle file integrity monitoring with intrusion detection. In that case, the same agent that watches logs and processes will also track file changes and send events to a central server. This helps correlate file changes with other suspicious signals, but typically involves more complex infrastructure.

In all cases, the tool must be installed on the system you wish to monitor, and you need to allocate resources for storing baseline data and processing alerts.

Protecting the Reference Data

Because file integrity monitoring depends entirely on the trustworthiness of its reference data, securing that data is a central design concern.

The baseline file database should be stored in a location with restricted permissions. Only a dedicated user or root should be able to modify it. Many tools support digital signatures for their databases, often using keys stored separately. In that case, after each baseline update the database is signed, and during later scans the signature is verified. If an attacker alters the database but not the secret key, signature verification will fail and alert you.

Another important practice is to keep copies of the baseline on media or systems that an attacker is less likely to reach. For example, you can export the baseline file to a remote log server, a version control repository, or read only storage after each authorized change. Even if local references are tampered with, you still retain an external record of the original state.

If an attacker gains root access and can both modify files and update the monitoring database without detection, file integrity monitoring alone will not reveal the compromise. You must therefore protect monitoring tools and their reference data with defense in depth.

Handling Legitimate Changes

Operating systems evolve. Packages are upgraded, new software is installed, configurations are tuned. All these legitimate actions will change files that the monitoring system watches.

If you do not treat these changes carefully, you end up with a monitoring system that constantly warns you about expected actions. The solution is to define a clear workflow for handling legitimate modifications.

One common model is to run a scan after planned changes, review the reported differences, confirm that they match the expected maintenance, and then instruct the tool to update its baseline. The updated baseline now reflects the new trusted state. Any further deviations become suspicious again.

In more dynamic environments, you may refine the monitoring rules to track only certain attributes for particular paths. For example, you might accept frequent content changes in application directories but still watch permissions and ownership. Alternatively, you may ignore specific file patterns, such as temporary files or cache directories.

The important aspect is that each baseline update is itself controlled and ideally documented. You do not want monitoring agents silently rewriting their references whenever they see changes. That would turn a security control into a self erasing log of compromises.

Alerting and Response

Detecting a file integrity change is only the beginning. The value of monitoring comes from what you do with that information.

On simple setups, reports may be written to log files that administrators review periodically. This can work for small systems with low change rates, but is slow to react. More robust deployments send alerts via email, messaging systems, or centralized security dashboards whenever certain sensitive files change outside of maintenance windows.

Once an alert is raised, someone must determine whether the change is expected. If it is not, the event may indicate a misconfiguration, a user mistake, or a security incident. At that point, incident response procedures and forensic techniques should be applied. In particular, file integrity data helps you answer questions such as when the file changed, whether other related files were touched, and whether similar changes occurred on other hosts.

For compliance driven environments, file integrity monitoring results are often archived as evidence that controls are active. In those cases, proving that alerts are reviewed and acted upon is as important as having the monitoring running.

Integration into a Hardening Strategy

File integrity monitoring is only one part of hardening. It works best when combined with strict access controls, patch management, logging, and system auditing.

On the preventive side, strong permissions and minimal services reduce opportunities for attackers to modify critical files in the first place. On the detective side, log monitoring and process observation help you correlate file changes with specific actions. Configuration management tools can automatically restore files to their approved versions if monitoring detects unauthorized alterations.

When designing your hardening strategy, you should decide where file integrity monitoring fits in the overall picture. You might use it primarily as an early warning system, or as a way to validate that configuration management is not drifting, or as a compliance requirement. In all cases, its effectiveness depends on disciplined configuration, protected baselines, and a well defined response to what it finds.

Views: 8

Comments

Please login to add a comment.

Don't have an account? Register now!