Skip to content

Directory Watching

Heisenbug edited this page Mar 5, 2026 · 1 revision

Home · Start Here · Reference Map

At a glance

  • How suspicious files are detected in risky paths.
  • How to tune false positives with csf.fignore rules.
  • How optional quarantine and watch mode behave.

Related guide: Security-Features-Guide

Quick reference

Setting Purpose
LF_DIRWATCH Enable directory watching for suspicious files in /tmp, /dev/shm, and similar paths
LF_DIRWATCH_FILE Watch a specific file or directory for any changes (md5sum-based)
LF_DIRWATCH_DISABLE When enabled, quarantine suspicious files to a tarball and delete originals
File Purpose
/etc/csf/csf.fignore Ignore list for false-positive files and directories
/usr/local/csf/tpl/filealert.txt Email template for suspicious file alerts
/usr/local/csf/tpl/watchalert.txt Email template for watched file/directory change alerts
/var/lib/csf/suspicious.tar Quarantine archive for removed suspicious files

How it works

Suspicious file detection (LF_DIRWATCH)

LFD checks /tmp, /dev/shm, and other pertinent directories for suspicious files (typically script exploits). When a suspicious file is found, an alert email is sent.

Only one alert per file is sent until LFD is restarted — if you remove a suspicious file, restart LFD to re-enable detection for that location.

Quarantine mode (LF_DIRWATCH_DISABLE)

When enabled, suspicious files are appended to a tarball at /var/lib/csf/suspicious.tar and deleted from their original location. Symlinks are simply removed.

To extract quarantined files preserving path and permissions:

tar -xpf /var/lib/csf/suspicious.tar

Specific file/directory watching (LF_DIRWATCH_FILE)

This option watches a particular file or directory for changes using an md5sum match from the output of ls -laAR. It traverses directories if specified. Changes trigger an alert using the watchalert.txt template.

Key files

csf.fignore format

Specify full paths to files LFD should ignore:

/tmp/clamav-somefile

Perl regular expression pattern matching is supported for entries containing an asterisk (*):

/tmp/clamav.*
/tmp/.*\.wrk

Remember to escape special characters with a backslash (e.g., \., \?). Entries without * use exact full-path matching.

You can also ignore files owned by a particular user:

user:bob

Note: Files owned by root are always ignored.

For information on perl regular expressions: see perldoc perlre.

Safe workflow

  1. Enable LF_DIRWATCH and keep LF_DIRWATCH_DISABLE off initially (alert-only mode).
  2. Reload: csf -ra
  3. Monitor alerts in /var/log/lfd.log for several days.
  4. Add confirmed false positives to csf.fignore using the most specific match possible.
  5. Optionally enable LF_DIRWATCH_DISABLE for automatic quarantine once false positives are under control.
  6. If using LF_DIRWATCH_FILE, set it to a specific sensitive path (e.g., /etc/passwd) and verify alerts fire on change.

Common pitfalls

  • Not restarting LFD after removing a suspicious file — the same file path will not be re-alerted until LFD restarts.
  • Over-broad csf.fignore patterns — patterns like /tmp/.* effectively disable watching for that directory.
  • Quarantine tarball growth — if LF_DIRWATCH_DISABLE is enabled on a noisy server, /var/lib/csf/suspicious.tar can grow indefinitely; monitor disk usage.
  • ClamAV/scanner temp files — antivirus scanners commonly write to /tmp; add their patterns to csf.fignore to avoid alert fatigue.

Last reviewed: 2026-02-27


← Previous: Process Tracking · Next: Advanced Allow/Deny Filters

Clone this wiki locally