dnf install aide
aide --init
/var/lib/aide/aide.db.new.gz. To save the database as a baseline, remove the .new string from the initial filename:mv /var/lib/aide/aide.db.new.gz /var/lib/aide/aide.db.gz
sudo aide --check
AIDE found NO differences between database and filesystem. Looks okay!!
AIDE found differences between database and filesystem. The output example is as follows:Start timestamp: 2023-05-06 10:35:53 +0800 (AIDE 0.16)AIDE found differences between database and filesystem!!Summary:Total number of entries: 116821Added entries: 0Removed entries: 0Changed entries: 4---------------------------------------------------Changed entries:---------------------------------------------------d = ... mc.. ... : /rootf ... i . . : /root/.viminfof = ... mc...... : /usr/lib/sysimage/rpm/rpmdb.sqlite-shmf = ... .c...... : /usr/lib/sysimage/rpm/rpmdb.sqlite-wal---------------------------------------------------Detailed information about changes:---------------------------------------------------Directory: /rootMtime : 2023-05-05 17:35:34 +0800 | 2023-05-06 10:22:45 +0800Ctime : 2023-05-05 17:35:34 +0800 | 2023-05-06 10:22:45 +0800...(omit partial output)...
/etc/crontab file to run an AIDE check at 6:30 every day:30 6 * * * root /usr/sbin/aide --check
aide --update
/var/lib/aide/aide.db.new.gz. Similarly, you need to remove the .new string from the initial filename before the updated database can be used for integrity checks:mv /var/lib/aide/aide.db.new.gz /var/lib/aide/aide.db.gz
execve(), mmap(), and open(), IMA performs integrity measurements on accessed files. The measurement results can be further used for remote attestation or compared with reference values in extended file attributes to control file access.ima_policy./sys/kernel/security/ima/policy API.ima_policy policy parameter to the kernel boot parameters as follows:grubby --args="ima_policy=tcb" --update-kernel=/boot/vmlinuz-`uname -r`
Boot Parameter | Value | Meaning |
ima_hash | sha1/sha256/sm3/md5/... | Sets the measurement algorithm used by IMA, which defaults to SHA256. |
ima_template | ima/ima-ng/ima-sig | Sets the measurement template used by IMA. |
ima_appraise | off | Disables the IMA appraise feature. |
| fix | Sets the IMA appraisal fix mode, which labels files with the security.ima extended attribute and can be used during environment initialization. |
| log | Sets the IMA appraisal log mode, which only verifies file integrity but does not perform access control, and only records audit logs. |
| enforce | Sets the IMA appraisal enforcement mode, which verifies file integrity and enforces access control based on the verification results. |
ima_policy | tcb | Uses the IMA preset measurement policy. See the next section for details. |
| appraise_tcb | Uses the IMA preset appraisal policy to appraise all files owned by the root user. |
| secure_boot | Uses the IMA preset appraisal policy to appraise the integrity of the kernel, kernel modules, firmware, IMA policies, and others. |
integrity_audit | 0 | Provides basic audit information (by default). |
| 1 | Provides detailed audit information. |
/sys/kernel/security/ima:SecurityFS API | Permissions | Function |
ascii_runtime_measurement | 440 | Provides a runtime measurement list in ASCII format. |
binary_runtime_measurement | 440 | Provides a runtime measurement list in binary form. |
runtime_measurement_count | 440 | Provides the total number of system IMA measurement logs. |
violations | 440 | Provides the number of system IMA measurement conflicts. |
policy | 600 | Custom IMA policy read-write API. |
cat command. Among them, the fifth API has write permission and can be used to update custom policies into the kernel:echo /etc/ima/ima-policy > /sys/kernel/security/ima/policy
/etc/ima/ima-policy can be replaced with any other absolute path.Behavior Token | Description |
measure | Indicates the measurement of file objects. During the measurement process, a digest value is calculated for the file content, and this digest, along with related information, is written into a measurement log entry. The log entry is then added to the list of IMA runtime measurements. If the system has a TPM chip installed, the measurement value will be extended to PCR 10 of the TPM. IMA does not measure an object twice, meaning that duplicate file entries do not exist in a list of runtime measurements (unless the file content is modified), and the digest values of previously measured objects will not be extended to the TPM's PCR. |
dont_measure | Indicates that file objects are not measured. |
appraise | Indicates the appraisal of file objects, which uses the file's extended attribute security.ima to verify the integrity of the file content. If integrity is compromised and the current IMA appraise mode is enforce, an error is reported, indicating an appraisal failure. |
dont_appraise | Indicates that file objects are not appraised. |
audit | Indicates the audit of file objects. The audit log records the absolute path of the measured files along with the digest algorithm and digest value. |
Condition Matching Token | Value | Meaning |
func | FILE_CHECK | Indicates that before a regular file (including an existing regular file or a new one) is opened, this rule is used to measure the content of the target file. If a behavior token is specified but no condition matching token is specified, the default value of func is FILE_CHECK. |
| BPRM_CHECK | Indicates that before an executable file, shared library, or script called via a shebang interpreter is run, the content of the target file is measured. |
| MMAP_CHECK | Indicates that before memory mapping of a regular file (an existing regular file or a new one) with executable permissions, this rule is used to measure the content of the target file. |
| MODULE_CHECK | Indicates that before the kernel module file is loaded, the content of the target module file is measured. |
| FIRMWARE_CHECK | Indicates that before the firmware is loaded, the content of the target firmware file is measured. |
mask | MAY_EXEC | Access points should be loading executable files/kernel modules/firmware or memory-mapping a regular file in EXEC-only mode. |
| MAY_WRITE | Access points should open regular files in write-only access mode. |
| MAY_READ | Access points should open regular files in read-only access mode. |
| MAY_APPEND | Access points should open regular files in append-only access mode. |
| ^MAY_EXEC | Access points should be executing executable files or memory-mapping a regular file in READ|WRITE|EXEC mode. |
| ^MAY_WRITE | Access points should open regular files in write access mode. |
| ^MAY_READ | Access points should open regular files in read access mode. |
| ^MAY_APPEND | Access points should open regular files in append access mode. |
fsmagic | Hexadecimal string | File system fsmagic value. |
fsuuid | Hexadecimal string | Block device file system UUID. |
uid | Decimal number | Process UID. |
euid | Decimal number | Process EUID. |
fowner | Decimal number | File UID. |
obj_user | LSM subject user | LSM subject user. |
obj_role | LSM subject role | LSM subject role. |
obj_type | LSM subject type | LSM subject type. |
subj_user | LSM object user | LSM object user. |
subj_role | LSM object role | LSM object role. |
subj_type | LSM object type | LSM object type. |
ima_policy=tcb as an example to explain how IMA measures system files under this policy:dont_measure fsmagic=0x9fa0dont_measure fsmagic=0x62656572dont_measure fsmagic=0x64626720dont_measure fsmagic=0x1021994dont_measure fsmagic=0x1cd1dont_measure fsmagic=0x42494e4ddont_measure fsmagic=0x73636673dont_measure fsmagic=0xf97cff8cdont_measure fsmagic=0x27e0ebdont_measure fsmagic=0x6e736673measure func=MMAP_CHECK mask=MAY_EXECmeasure func=BPRM_CHECK mask=MAY_EXECmeasure func=FILE_CHECK euid=0measure func=FILE_CHECK uid=0measure func=MODULE_CHECKmeasure func=FIRMWARE_CHECKmeasure func=POLICY_CHECK
dont_measure fsmagic=xxx indicates that files in specific file system types (identified by file system superblock identifiers) will not be measured. These file systems are:magic Value | File System Name |
0x9fa0 | procfs pseudo file system |
0x62656572 | sysfs pseudo file system |
0x64626720 | debugfs pseudo file system |
0x1021994 | tmpfs pseudo file system |
0x1cd1 | devpts pseudo file system |
0x42494e4d | binfmt_misc pseudo file system |
0x73636673 | securityfs pseudo file system |
0x27e0eb | cgroup pseudo file system |
0x6e736673 | namespace pseudo file system |
measure func=MMAP_CHECK mask=MAY_EXEC indicates measuring the content of mmap() file mappings with the PROT_EXEC flag. Since shared libraries are typically loaded into the process address space through this mechanism, this rule can be approximately understood as measuring the integrity of shared libraries.measure func=BPRM_CHECK mask=MAY_EXEC indicates measuring executable files (including scripts) executed through the execve() system call.measure func=FILE_CHECK euid=0 indicates measuring the content of files accessed by users with an EUID of 0 (root users and users with sudo permissions).measure func=FILE_CHECK uid=0 indicates measuring the content of files accessed by users with a UID of 0 (root users).measure func=MODULE_CHECK indicates measuring loaded kernel modules.measure func=FIRMWARE_CHECK indicates measuring loaded firmware files.measure func=POLICY_CHECK indicates measuring the content of the IMA policy additionally written to /sys/kernel/security/ima/policy.audit.log file and saving it to disk. The startup of auditd is controlled by systemd, and the functionality of auditd is controlled by /etc/audit/auditd.conf./etc/audit/audit.rules contains a series of auditctl commands, which are loaded by auditd.audit.log./etc/audit/auditd.conf and can be opened with any text editor. Common configuration items are as follows:log_file: Defines the location and name of the audit log file. The default location is usually /var/log/audit/audit.log.log_format: Defines the format of the audit log. It supports five parameters: raw, user, json, enriched, and verbose.max_log_file_action: Defines the action to take when the audit log file reaches its maximum size. It is generally set to keep_logs to prevent the audit log file from being overwritten.space_left: Defines the free space that must be reserved in the audit log file system.space_left_action: Defines the action to take when free space in the audit log file system is insufficient. It is recommended to set this parameter to email or exec with an appropriate notification method configured.admin_space_left: Defines the free space that must be reserved in the administrator space.admin_space_left_action: Defines the action to take when free space in the administrator space is insufficient. It should generally be set to single to put the system into single-user mode.CONFIG_AUDIT and CONFIG_AUDITSYSCALL configurations. The TencentOS Server kernel enables Audit-related configurations by default.service auditd start
systemctl enable auditd
auditctl -e 0. To re-enable it, run auditctl -e 1.service auditd <command> to control auditd to perform other operations. The command can be one of the following:Command | Function |
stop | Stops auditd. |
restart | Restarts auditd. |
reload/force-reload | Reloads the auditd configuration in /etc/audit/auditd.conf. |
rotate | Backs up old log files and writes logs to new blank log files. |
resume | Resumes temporarily disabled auditd. |
condrestart/try-restart | Restarts auditd when it is running. |
status | Shows the running status of auditd. |
service command is the only way to properly interact with the auditd process. The systemctl command can only be used for two operations: enable and status. All other commands must use service./var/log/audit/audit.log file. We use an example to describe the record parameters of Audit logs. Add the following audit rule to record read and write operations on the /boot/grub2/grub.cfg file.auditctl -Dauditctl -w /boot/grub2/grub.cfg -p warx -k grub.cfg
audit.log is as follows:type=SYSCALL msg=audit(1677250085.590:313): arch=c000003e syscall=257success=yes exit=3 a0=ffffff9c a1=7fff8b0d2d09 a2=0 a3=0 items=1ppid=1098 pid=1649 auid=0 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0sgid=0 fsgid=0 tty=ttyS0 ses=1 comm="cat" exe="/usr/bin/cat"subj=root:sysadm_r:sysadm_t:s0-s15:c0.c1023 key="grub.cfg" ARCH=x86_64AUID="root" UID="root" GID="root" EUID="root" SUID="root"FSUID="root" EGID="root" SGID="root" FSGID="root"type=CWD msg=audit(1677250085.590:313): cwd="/var/log/audit"type=PATH msg=audit(1677250085.590:313): item=0name="/boot/grub2/grub.cfg" inode=524302 dev=fc:01 mode=0100600 ouid=0ogid=0 rdev=00:00 obj=system_u:object_r:boot_t:s0 nametype=NORMALcap_fp=0 cap_fi=0 cap_fe=0 cap_fver=0 cap_frootid=0 OUID="root"OGID="root"type=PROCTITLE msg=audit(1677250085.590:313):proctitle=636174002F626F6F742F67727562322F677275622E636667
type= keyword. Each record consists of multiple name=value pairs separated by spaces or commas. A detailed analysis of the above event is as follows:Field | Description |
type=SYSCALL | The type field contains the record type. In this example, the SYSCALL value specifies that this record is triggered by a system call to the kernel. |
msg=audit(1677250085.590:313) | The msg field records the timestamp and unique ID of the record, in the format of audit(time_stamp:ID). If multiple records are generated as part of the same audit event, they share the same timestamp and ID. The timestamp uses the Unix time format - the number of seconds since 00:00:00 UTC on January 1, 1970. |
arch=c000003e | The arch field contains the CPU architecture information of the system. The value c000003e is encoded in hexadecimal notation. When using the ausearch command to search audit records, use the -i or --interpret option to automatically convert hexadecimal values into human-readable equivalents. The c000003e value is interpreted as x86_64. |
syscall=257 | The syscall field records the type of system call sent to the kernel. The value 257 can be matched with its human-readable equivalent in the /usr/include/asm/unistd_64.h file. In this example, 257 is the openat system call. The ausyscall utility can convert system call numbers to their human-readable equivalents. Use the ausyscall --dump command to display a list of all system calls and their numbers. |
success=yes | The success field records whether the system call recorded in this specific event succeeded or failed. In this case, the call succeeded. |
exit=3 | The exit field contains a value that specifies the exit code returned by the system call. This value varies with different system calls. |
a0=ffffff9c, a1=7fff8b0d2d09, a2=0, a3=0 | The a0 to a3 fields record the first four arguments of the system call in this event, encoded in hexadecimal notation. These arguments depend on the system call used and can be interpreted by using the ausearch utility. |
items=1 | The items field contains the number of PATH auxiliary records that follow the system call record. |
ppid=1098 | The ppid field records the parent process ID (PPID). In this case, 1098 is the PPID of the parent process, such as bash. |
pid=1649 | The pid field records the process ID (PID). In this example, 1649 is the PID of the cat process. |
auid=0 | The auid field records the audit user ID, that is, the loginuid. This ID is assigned to the user at login and is inherited by every process, even if the user identity changes, for example, when the su - user command is used to switch user accounts. |
uid=0 | The uid field records the user ID of the user who started the analysis process. Use the following command to interpret the user ID as a username: ausearch -i --uid UID. |
gid=0 | The gid field records the group ID of the user who started the analysis process. |
euid=0 | The euid field records the effective user ID of the user who started the analysis process. |
suid=0 | The suid field records the set user ID of the user who started the analysis process. |
fsuid=0 | The fsuid field records the file system user ID of the user who started the analysis process. |
egid=0 | The egid field records the effective group ID of the user who started the analysis process. |
sgid=0 | The sgid field records the group ID of the user who started the analysis process. |
fsgid=0 | The fsgid field records the file system group ID of the user who started the analysis process. |
tty=ttyS0 | The tty field records the terminal from which the analysis process was invoked. |
ses=1 | The ses field records the session ID of the session from which the analysis process was invoked. |
comm="cat" | The comm field records the command line name used to invoke the analysis process. In this example, the cat command is used to trigger this audit event. |
exe="/usr/bin/cat" | The exe field records the path of the executable file used to invoke the analysis process. |
subj=root:sysadm_r:sysadm_t:s0-s15:c0.c1023 | The subj field records the SELinux context with which the analyzed process was labeled during execution. |
key="grub.cfg" | The key field records an administrator-defined string associated with the rule that generated the event in the audit log. If a series of repeated keys follows, the preceding key=value is interpreted into a human-readable explanation. |
Field | Description |
type=CWD | In the second record, the type field value is CWD - current working directory. This type is used to record the working directory of the process from which the system call specified in the first record is invoked. The purpose of this record is to record the location of the current process in case a relative path is captured in the related PATH record. In this way, the absolute path can be reconstructed. |
msg=audit(1677250085.590:313) | The msg field holds the same timestamp and ID values as those in the first record. The timestamp uses the Unix time format. |
cwd="/var/log/audit" | The cwd field contains the path of the directory where the system call is located. |
Field | Description |
type=PATH | In the third record, the type field value is PATH. An audit event contains a PATH type record for each path passed as a parameter to a system call. In this audit event, only one path ( /boot/grub2/grub.cfg) is used as a parameter. |
msg=audit(1677250085.590:313) | The msg field has the same timestamp and ID values as those in the first and second records. |
item=0 | The item field indicates which item the current record is among the total number of items referenced by a SYSCALL type record. This number is zero-based, and a value of 0 indicates that it is the first item. |
name="/boot/grub2/grub.cfg" | The name field records the path of the file or directory passed as a parameter to a system call. In this example, it is the /boot/grub2/grub.cfg file. |
inode=524302 | The inode field contains the inode number associated with the file or directory recorded in this event. |
dev=fc:01 | The dev field specifies the minor and major IDs of the device containing the file or directory recorded in this event. In this example, the value represents the /dev/fc/1 device. |
mode=0100600 | The mode field records the permissions of a file or directory, represented by a numeric value. It is the value in the st_mode field returned by the stat command. For more information, see the stat(2) man page. In this case, 0100600 can be interpreted as -rw-------, which means that only the root user has read and write permissions on the /boot/grub2/grub.cfg file. |
ouid=0 | The ouid field records the user ID of the object owner. |
ogid=0 | The ogid field records the group ID of the object owner. |
rdev=00:00 | The rdev field contains a recorded device identifier and is used only for special files. In this case, it is not used because the recorded file is a regular file. |
obj=system_u:object_r:boot_t:s0 | The obj field records the SELinux context with which the recorded file or directory was labeled during execution. |
nametype=NORMAL | The nametype field records the operation intent of each path record in the context of a given system call. |
cap_fp=none | The cap_fp field records data related to setting the file system-based allowed capabilities of a file or directory object. |
cap_fi=none | The cap_fi field records data related to the inherited file system-based capability settings of a file or directory object. |
cap_fe=0 | The cap_fe field records the setting of the effective bits of file system-based capabilities for a file or directory object. |
cap_fver=0 | The cap_fver field records the version of file system-based capabilities for a file or directory object. Similar to the first record, when two duplicate keys follow, the preceding key=value is explained in a human-readable translation. |
Field | Description |
type=PROCTITLE | The type field contains the record type. In this example, the PROCTITLE value specifies that this record provides the full command line that triggered this audit event, which was triggered by a system call to the kernel. |
proctitle=636174002F626F6F742F67727562322F677275622E636667 | The proctitle field records the full command line used to invoke the analysis process. This field is encoded in hexadecimal notation to prevent users from influencing the audit log parser. The 636174002F626F6F742F67727562322F677275622E636667 value is interpreted as cat /boot/grub2/grub.cfg. When using the ausearch command to search audit records, use the -i or --interpret option to automatically convert hexadecimal values into human-readable equivalents. |
auditctl tool to set audit rules on the command line or in the /etc/audit/rules.d/ directory.auditctl command to control the basic features of the audit system and define rules that determine which audit events are recorded. Here are some examples for reference:/etc/passwd file:auditctl -w /etc/passwd -p wa -k passwd_changes
/etc/selinux/ directory:auditctl -w /etc/selinux/ -p wa -k selinux_changes
adjtimex or settimeofday system call on a 64-bit architecture:auditctl -a always,exit -F arch=b64 -S adjtimex -S settimeofday -k time_change
auditctl -a always,exit -S unlink -S unlinkat -S rename -S renameat -F auid>=1000 -F auid!=4294967295 -k delete
-F auid!=4294967295 is used to exclude users who have not set a login UID./bin/id program, and run the following command:auditctl -a always,exit -F exe=/bin/id -F arch=b64 -S execve -k execution_bin_id
/etc/audit/rules.d/audit.rules file, or use the augenrules program to read rules from the /etc/audit/rules.d/ directory. Note that the /etc/audit/audit.rules file is generated each time the auditd service starts. Files in /etc/audit/rules.d/ can use the same auditctl command-line syntax to specify rules. The preceding examples can be recorded in the audit.rules file as follows:-w /etc/passwd -p wa -k passwd_changes-w /etc/selinux/ -p wa -k selinux_changes-a always,exit -F arch=b64 -S adjtimex -S settimeofday -k time_change-a always,exit -S unlink -S unlinkat -S rename -S renameat -F auid>=1000 -F auid!=4294967295 -k delete-a always,exit -F exe=/bin/id -F arch=b64 -S execve -k execution_bin_id
augenrules command to load the rules:augenrules --load
-k parameter, such as passwd_changes, selinux_changes, and time_change. A key is an administrator-defined string identifier used to mark audit log entries generated by that rule. You can use keys to efficiently filter massive volumes of audit logs and quickly locate events for specific rules, improving the efficiency of audit analysis and event tracking.ausearch command is used to search for specific events in audit log files. It supports queries by various criteria, including key, user, time, and system call. Common options are as follows:Option | Description |
-k, --key <key> | Search audit events by key string |
-i, --interpret | Interpret hexadecimal values in a human-readable form. |
-a, --event <event> | Search by event ID. |
-ua, --uid <uid> | Search by user ID (including uid and auid). |
-ts, --start <start> | Specify the start time of the search. |
-te, --end <end> | Specify the end time of the search. |
-f, --file <file> | Search by file name. |
-sc, --syscall <syscall> | Search by system call name or number. |
-x, --executable <executable> | Search by executable file path. |
-m, --message <message> | Search by message type. |
ausearch -k grub.cfg -i
ausearch -ts today -te now -i
ausearch -f /etc/passwd -i
ausearch -sc openat -i
ausearch -ua 0 -i
aureport command is used to generate custom summary reports based on audit event logs, helping administrators quickly understand the system security status. Common options are as follows:Option | Description |
-l, --login | Generate login-related reports. |
-f, --file | Generate file access-related reports. |
-s, --syscall | Generate system call-related reports. |
-u, --user | Generate user-related reports. |
-e, --event | Generate event-related reports. |
-p, --pid | Generate process-related reports. |
-x, --executable | Generate executable file-related reports. |
-c, --config | Generate configuration change-related reports. |
-ts, --start <start> | Specify the start time of the report. |
-te, --end <end> | Specify the end time of the report. |
-i, --interpret | Interpret hexadecimal values in a human-readable form. |
--failed | Include only failed events. |
--success | Include only successful events. |
aureport -l -i
aureport -f -i
aureport -u -i
aureport -s -i
aureport -ts today -te now -i
aureport --failed -i
フィードバック