Kahibaro
Discord Login Register

File integrity monitoring

Why File Integrity Monitoring Matters

File integrity monitoring (FIM) is about answering two questions reliably:

It’s a core hardening control because many attacks involve:

FIM gives you a way to detect such changes, validate them, and respond.

Key use-cases:

What to Monitor

You cannot (and usually should not) monitor the entire filesystem with the same intensity. Effective FIM is about scoping.

Typical high-value targets:

Common exclusion patterns (to avoid noise and overhead):

The strategy is to:

  1. Start with a small, clearly defined scope.
  2. Run in report mode, tune out noisy paths.
  3. Only then expand if genuinely needed.

Core FIM Techniques and Concepts

Checksums and Hashes

At the core of FIM is the idea of taking a “snapshot” of file attributes and comparing later snapshots.

Commonly recorded attributes:

Hashes allow you to determine content changes rather than just metadata changes.

Use strong hashes (SHA-256, SHA-512) rather than weak ones (MD5, SHA-1).

Realtime vs Periodic Monitoring

Two major modes:

Many tools support both; you typically mix them.

Baseline Creation and Trust

FIM is only as trustworthy as its baseline — the initial snapshot.

Recommended baseline process:

  1. Install/configure the system.
  2. Patch and harden it to your desired “known-good” state.
  3. Ensure the system is clean (e.g. initial integrity checks, malware scan if needed).
  4. Generate the initial FIM database or baseline.
  5. Secure the database (ideally off-host or with strong access controls).

If the system is already suspect, creating a baseline on it is risky; it might simply “bless” compromised files.

Common FIM Tools and Approaches

This section focuses on typical open-source solutions. Commercial/enterprise FIM products build on the same principles but add dashboards, centralization, and compliance reporting.

Tripwire (Conceptual Overview)

Tripwire was an early, influential FIM tool:

On modern systems, it’s less common than other tools (e.g. AIDE) but the model is similar: initialize → check → investigate changes → update baseline when appropriate.

AIDE (Advanced Intrusion Detection Environment)

AIDE is widely used as a straightforward, host-based FIM.

Typical Workflow

  1. Install aide via your package manager.
  2. Configure what to monitor in /etc/aide/aide.conf (paths, rules).
  3. Initialize the database:
   sudo aide --init
   sudo mv /var/lib/aide/aide.db.new /var/lib/aide/aide.db
  1. Schedule regular checks (via cron or systemd timer).
  2. Review reports, investigate unexpected changes, and update the database when legitimate changes occur:
   sudo aide --check
   sudo aide --update
   # then move the new db into place after review

Rule Concept

AIDE uses rule sets specifying which attributes are checked, e.g.:

Example configuration fragment:

# Define a rule set
BinRule = p+i+n+u+g+s+m+c+sha256
# Apply it
/bin    BinRule
/sbin   BinRule
/usr/bin BinRule
/usr/sbin BinRule
# Example for /etc with a more detailed rule
/etc    p+i+n+u+g+s+m+c+acl+sha256

You’d then add exclusions for noisy paths (e.g. /etc/mtab on some systems).

Auditd-Based FIM

The Linux audit subsystem (auditd) can be used to monitor file-related syscalls:

Example rule concept (not full syntax coverage):

  -w /etc/shadow -p wa -k shadow-watch

Audit-based FIM is powerful because it can tell you:

It’s best suited for realtime detection and forensic context; you can combine it with hash-based tools for content comparison.

OSSEC / Wazuh (Agent-Based HIDS with FIM)

OSSEC and its fork Wazuh include FIM as part of a full host-based intrusion detection system (HIDS):

Key points for FIM:

This approach is well-suited for environments with many servers where you want centralized FIM and richer correlation.

Designing a Practical FIM Policy

Step 1: Define Objectives

Clarify what you care about:

Objectives determine:

Step 2: Scope and Performance Considerations

Overly broad FIM can:

Guidelines:

Always test FIM impact on non-production or low-risk systems first.

Step 3: Alerting and Integration

FIM is only useful if someone acts on its findings.

Typical integration patterns:

Control noise:

Step 4: Baseline Maintenance and Change Management

FIM must align with your legitimate change process:

Never blindly update baselines:

Protecting the FIM Itself

An attacker who gains control of the system might try to:

Countermeasures:

Interpreting and Responding to FIM Events

Detection without response doesn’t help. You should have a basic playbook.

Triage Questions

When a change is detected:

  1. Is the change expected?
    • Was there a deployment, patch, config update?
  2. What changed exactly?
    • Diff of config or script, changed permissions, new binary?
  3. Who/what changed it?
    • Correlate with:
      • Audit logs
      • Shell history
      • Configuration management runs
  4. Is there potential impact?
    • Does this enable privilege escalation, backdoor access, or data exfiltration?

Typical Response Actions

Depending on severity:

FIM is often the first indicator of hidden compromise; treat suspicious events seriously, even if everything else “appears fine”.

Best Practices Summary

Properly implemented, file integrity monitoring becomes a powerful complement to your other hardening controls, giving you early visibility into unauthorized changes and helping you maintain trust in your systems over time.

Views: 27

Comments

Please login to add a comment.

Don't have an account? Register now!