File Integrity Monitoring (im_fim)
This module is capable of scanning files and directories and reporting detected changes and deletions. On the first scan, the checksum of each file is recorded. This checksum is then compared to the checksum value calculated during successive scans. The im_fim module works at the filesystem level, so it only has access to file information such as ownership and last modification date, and no information about which user made a change.
Files are checked periodically, not in real-time. If there are multiple changes between two scans, only the cumulative effect is logged. For example, if one user modifies a file and another user reverts the changes before the next scan occurs, only the change in modification time is detected.
For real-time monitoring, auditing must be enabled on the host operating system. See File Integrity Monitoring for more information.
| To examine the supported platforms, see the list of installation packages. |
Filepath definition
The module treats filenames as case-insensitive on Windows and case-sensitive on Unix/Linux systems.
When you specify a relative filename, NXLog Agent sets its working directory to / unless you define a different directory with the global SpoolDir directive.
On Windows, the directory separator is the backslash (\).
For compatibility, you can use the forward slash (/) as a directory separator, but only when the filename does not include wildcards.
If you specify a filename with wildcards, you must use the backslash (\) as the directory separator.
Wildcards
You can use wildcards in filenames and directories. Wildcards are not regular expressions but patterns commonly used by Unix shells to expand filenames (also known as "globbing").
The supported wildcards are:
- ?
-
Matches a single character only.
- *
-
Matches zero or more characters.
- \*
-
Matches the asterisk (
*) character. - \?
-
Matches the question mark (
?) character. - […]
-
Matches a single character using a character class. The class description consists of individual characters and character ranges separated by a hyphen (
-). If the class description starts with^or!, the class matches any character that is not listed. You can prefix any character with a backslash (\), which the parser ignores. This allows you to include special characters such as].-,^, and!.
Escape characters
By default, the escape sequence is the backslash character (\).
This character is also the directory separator on Windows.
Because of this, the module doesn’t support escaping wildcard characters on Windows.
See the EscapeGlobPatterns directive for more information.
The module evaluates string literals differently depending on the quotation type:
-
Single quoted strings are interpreted as-is without escaping, for example
'C:\t???\*.log'staysC:\t???\*.log. -
Escape sequences in double-quoted strings are processed, for example
"C:\\t???\*.log"becomesC:\t???\*.log.
In both cases, the evaluated string is the same and is separated into parts with different glob patterns at different levels.
On this example, the parts are C:, t???, and *.log.
NXLog Agent matches the parts at the relevant directory levels to find all matching files.
Configuration
The im_fim module accepts the following directives in addition to the common module directives. The File directive is required.
Required directives
The following directive is required for the module to start.
This mandatory directive specifies the name of the input file to scan. It must be a string type expression. More than one occurrence of the File directive can be used. See Filepath definition for more details on using this directive. |
Optional directives
This specifies the digest method (hash function) to be used to calculate the checksum.
The default is |
|||||||||||||||||||||
This boolean directive specifies whether the backslash ( |
|||||||||||||||||||||
This directive can specify a file or a set of files (using wildcards) to be excluded from the scan. More than one occurrence of the Exclude directive can be specified. |
|||||||||||||||||||||
This directive can be used to specify an upper file size limit, in bytes. The checksum calculation will be skipped for files that exceed this limit, and changes will only be reported based on the file name and attributes. |
|||||||||||||||||||||
|
|||||||||||||||||||||
Set this directive to The default is
|
|||||||||||||||||||||
This directive specifies whether the module should treat symlinked directories and files as regular directories and files.
If the directive is |
|||||||||||||||||||||
This directive specifies how long the module will wait between scans for modifications, in seconds.
The default is 86400 seconds (1 day).
The value of ScanInterval can be set to |
Functions
The following functions are exported by im_fim.
- type: boolean
is_scanning() -
Returns TRUE if scanning is in progress. You must call this function using the
->operator. See Calling a function of a specific module instance for more information.
Fields
The following fields are created by im_fim.
-
$raw_event(type: string) -
A list of event fields in key-value pairs.
-
$Digest(type: string) -
The calculated digest (checksum) value.
-
$DigestName(type: string) -
The name of the digest used to calculate the checksum value (for example,
SHA1). -
$EventTime(type: datetime) -
The time when the modification was detected.
-
$EventType(type: string) -
One of the following values:
CHANGE,DELETE,RENAME, orNEW. -
$FileName(type: string) -
The name of the file that the changes were detected on.
-
$FileSize(type: integer) -
The size of the file in bytes after the modification.
-
$Hostname(type: string) -
The name of the originating computer.
-
$ModificationTime(type: datetime) -
The modification time (mtime) of the file when the change is detected.
-
$Object(type: string) -
One of the following values:
DIRECTORYorFILE. -
$PrevDigest(type: string) -
The calculated digest (checksum) value from the previous scan.
-
$PrevFileName(type: string) -
The name of the file from the previous scan.
-
$PrevFileSize(type: integer) -
The size of the file in bytes from the previous scan.
-
$PrevModificationTime(type: datetime) -
The modification time (mtime) of the file from the previous scan.
-
$Severity(type: string) -
The severity name:
WARNING. -
$SeverityValue(type: integer) -
The WARNING severity level value:
3.
Examples
With this configuration, NXLog Agent will monitor the specified directories recursively. Scans will occur every 3600 seconds (hourly).
<Input fim>
Module im_fim
File "/etc/*"
Exclude "/etc/mtab"
File "/bin/*"
File "/sbin/*"
File "/usr/bin/*"
File "/usr/sbin/*"
Recursive TRUE
ScanInterval 3600
FollowSymlinks TRUE
</Input>
The im_fim module provides a start_scan() procedure that can be called to invoke the scan. The following configuration sets ScanInterval to zero to disable periodic scanning and uses a Schedule block instead to trigger the scan every day at midnight.
<Input fim>
Module im_fim
File "/bin/*"
File "/sbin/*"
File "/usr/bin/*"
File "/usr/sbin/*"
Recursive TRUE
ScanInterval 0
<Schedule>
When @daily
Exec start_scan();
</Schedule>
</Input>