Red Hat Enterprise Linux Diagnostics and Troubleshooting
Configure and perform system auditing with the Linux audit system. In this exercise, you configure and perform system auditing with the Linux audit system.
Outcomes
You should be able to detect changes to the content and attributes of files and directories on a file system.
As the student user on the workstation machine, use the lab command to prepare your system for this exercise.
[student@workstation ~]$ lab start baseline-changetracking
Instructions
Log in to
serveraand switch to therootuser.[student@workstation ~]$
ssh student@servera...output omitted... [student@servera ~]$sudo -i[sudo] password for student:student[root@servera ~]#Configure
AIDEto monitor file integrity.Initialize the
AIDEdatabase.[root@servera ~]#
aide -iStart timestamp: 2021-09-14 22:00:07 -0400 (AIDE 0.16) AIDE initialized database at /var/lib/aide/aide.db.new.gz Number of entries: 5 --------------------------------------------------- The attributes of the (uncompressed) database(s): --------------------------------------------------- /var/lib/aide/aide.db.new.gz MD5 : LLSaHUKYsWzCDA94nbLurQ== SHA1 : mv+HidAoRw+kp1NC2vLgapVKdJg= RMD160 : CzX5WCHz8L5UXb4Amzx5CJvtzsw= TIGER : 1T8DFsev/GgTMj/gY8MExRvLJVvGoWXT SHA256 : reYx+xOuZyataCNPvgskaLfuOGA1rLOG dKEpxfQybL0= SHA512 : xlxRXa1reUuGVhP1QxVUoVvtBULc2skU tpNI5imXj/XeIF8LwJbAop8CF/JTi7SE mAnwzY2919NeaialwaoUTg== End timestamp: 2021-09-14 22:00:07 -0400 (run time: 0m 0s)Remove the
newsubstring from the initial database name to enable it for theaidecommand to use.[root@servera ~]#
mv /var/lib/aide/aide.db.new.gz /var/lib/aide/aide.db.gz
View the
/etc/aide.conffile to learn the default monitored files and rules.[root@servera ~]#
cat /etc/aide.conf...output omitted... # Custom Rules # Extended content + file type + access. CONTENT_EX = sha512+ftype+p+u+g+n+acl+selinux+xattrs # trusted databases /etc/hosts$ CONTENT_EX /etc/issue$ CONTENT_EX /etc/passwd$ CONTENT_EX /etc/group$ CONTENT_EX /etc/shadow$ CONTENT_EXGenerate a file integrity report for the default monitored files and verify that the report is present in the logs.
Generate the file integrity report.
[root@servera ~]#
aide --checkStart timestamp: 2021-09-14 22:10:19 -0400 (AIDE 0.16) AIDE found NO differences between database and filesystem. Looks okay!! Number of entries: 5 --------------------------------------------------- The attributes of the (uncompressed) database(s): --------------------------------------------------- /var/lib/aide/aide.db.gz MD5 : LLSaHUKYsWzCDA94nbLurQ== SHA1 : mv+HidAoRw+kp1NC2vLgapVKdJg= RMD160 : CzX5WCHz8L5UXb4Amzx5CJvtzsw= TIGER : 1T8DFsev/GgTMj/gY8MExRvLJVvGoWXT SHA256 : reYx+xOuZyataCNPvgskaLfuOGA1rLOG dKEpxfQybL0= SHA512 : xlxRXa1reUuGVhP1QxVUoVvtBULc2skU tpNI5imXj/XeIF8LwJbAop8CF/JTi7SE mAnwzY2919NeaialwaoUTg== End timestamp: 2021-09-14 22:10:19 -0400 (run time: 0m 0s)Verify that the file integrity report is recorded in the log file.
[root@servera ~]#
cat /var/log/aide/aide.logStart timestamp: 2021-09-14 22:10:19 -0400 (AIDE 0.16) AIDE found NO differences between database and filesystem. Looks okay!! Number of entries: 5 --------------------------------------------------- The attributes of the (uncompressed) database(s): --------------------------------------------------- /var/lib/aide/aide.db.gz MD5 : LLSaHUKYsWzCDA94nbLurQ== SHA1 : mv+HidAoRw+kp1NC2vLgapVKdJg= RMD160 : CzX5WCHz8L5UXb4Amzx5CJvtzsw= TIGER : 1T8DFsev/GgTMj/gY8MExRvLJVvGoWXT SHA256 : reYx+xOuZyataCNPvgskaLfuOGA1rLOG dKEpxfQybL0= SHA512 : xlxRXa1reUuGVhP1QxVUoVvtBULc2skU tpNI5imXj/XeIF8LwJbAop8CF/JTi7SE mAnwzY2919NeaialwaoUTg== End timestamp: 2021-09-14 22:10:19 -0400 (run time: 0m 0s)
Create a script to send an email alert whenever a change in the monitored files is found.
[root@servera ~]#
vim /root/aide_mon.shif ! grep "Looks okay" /var/log/aide/aide.log &>/dev/null then cat /var/log/aide/aide.log | /usr/bin/mail -s "AIDE Alert" \ student@servera.lab.example.com fiMake the script executable.
[root@servera ~]#
chmod +x /root/aide_mon.shSchedule the
AIDEexecution for every two minutes. Create the/etc/cron.d/aidefile and add the following lines:[root@servera ~]#
vim /etc/cron.d/aide# AIDE Checks and alert */2 * * * * root /sbin/aide --check && /root/aide_mon.shVerify that the integrity report is recorded in the log file. Check that no differences exist between the database and the file system.
[root@servera ~]#
cat /var/log/aide/aide.logStart timestamp: 2021-09-14 22:18:01 -0400 (AIDE 0.16) AIDE found NO differences between database and filesystem. Looks okay!! Number of entries: 5 --------------------------------------------------- The attributes of the (uncompressed) database(s): --------------------------------------------------- /var/lib/aide/aide.db.gz MD5 : LLSaHUKYsWzCDA94nbLurQ== SHA1 : mv+HidAoRw+kp1NC2vLgapVKdJg= RMD160 : CzX5WCHz8L5UXb4Amzx5CJvtzsw= TIGER : 1T8DFsev/GgTMj/gY8MExRvLJVvGoWXT SHA256 : reYx+xOuZyataCNPvgskaLfuOGA1rLOG dKEpxfQybL0= SHA512 : xlxRXa1reUuGVhP1QxVUoVvtBULc2skU tpNI5imXj/XeIF8LwJbAop8CF/JTi7SE mAnwzY2919NeaialwaoUTg== End timestamp: 2021-09-14 22:18:01 -0400 (run time: 0m 0s)Add a user, which causes a change in the systems account database, which is a monitored file. This action generates an inconsistency in file integrity.
[root@servera ~]#
useradd user01As the
studentuser on theserveramachine, verify that anAIDEalert email is received. The first email might take up to five minutes to arrive. The complete log report might not finish processing until the second email is received. Optionally, you could monitor the email activity that is sent to thestudentuser.Note
Log in to the
serveramachine in a separate terminal. Use thejournalctlcommand to monitor the email that is sent to thestudentuser.[root@servera ~]#
journalctl -f -u postfix --since todaySwitch to the
studentuser on theserveramachine to check forAIDEalert emails.[root@servera ~]#
exit[student@servera ~]$Check the email.
[student@servera ~]$
mailHeirloom Mail version 12.5 7/5/10. Type ? for help. "/var/spool/mail/student": 1 message 1 new >N 1 root Tue Sep 14 22:54 62/2250 "AIDE Alert"Read the most recent email.
&
1Message 1: From root@servera.lab.example.com Tue Sep 14 22:54:22 2021 Return-Path: <root@servera.lab.example.com> From: root <root@servera.lab.example.com> Date: Tue, 14 Sep 2021 22:54:01 -0400 To: student@servera.lab.example.com Subject: AIDE Alert User-Agent: Heirloom mailx 12.5 7/5/10 Content-Type: text/plain; charset=us-ascii Status: R Start timestamp: 2021-09-14 22:52:01 -0400 (AIDE 0.16) AIDE found differences between database and filesystem!! Summary: Total number of entries: 5 Added entries: 0 Removed entries: 0 Changed entries: 3 --------------------------------------------------- Changed entries: --------------------------------------------------- f ... .C... : /etc/group f ... .C... : /etc/passwd f ... .C... : /etc/shadow ...output omitted...Quit the
mailinteractive interface.&
q...output omitted... [student@servera ~]$
Switch to the
rootuser on theserveramachine. Update theAIDEdatabase to add the recent file changes. Back up theAIDEdatabase. Remove thenewsubstring from the updated database name to enable it for theaidecommand to use.Switch to the
rootuser.[student@servera ~]$
sudo -i[sudo] password for student:student[root@servera ~]#Update the database.
[root@servera ~]#
aide --updateBack up the current database.
[root@servera ~]#
mv /var/lib/aide/aide.db.gz /var/lib/aide/aide.db.old.gzEnable the new database for the
aidecommand to use.[root@servera ~]#
mv /var/lib/aide/aide.db.new.gz /var/lib/aide/aide.db.gz
Generate an integrity report of the monitored files.
[root@servera ~]#
aide --checkStart timestamp: 2021-09-14 23:23:06 -0400 (AIDE 0.16) AIDE found NO differences between database and filesystem. Looks okay!! Number of entries: 5 --------------------------------------------------- The attributes of the (uncompressed) database(s): --------------------------------------------------- /var/lib/aide/aide.db.gz MD5 : /tJ6rCYNS+gHPpAqP+cdFQ== SHA1 : v0sEePAdH6VbXAFPuGrrVG+tQNM= RMD160 : UDvr4Gvti4Layc8imAlHhAgZIWo= TIGER : VCSYuYBw98r81861ipOiVVE37mdp03g1 SHA256 : 9wyBh7irOdLWeacsPHKRHYPLYKbtOzND 42xuIn4/I3w= SHA512 : nw8mnWzPdlodiPVHtgcPOH1jcrDuVnXg wt9zFVBrAr8nFURYEnm12QFt7snGn03n mx7M8Dj5RBydOMetEyoSaA== End timestamp: 2021-09-14 23:23:06 -0400 (run time: 0m 0s)Switch to the
studentuser on theserveramachine. Verify that an alert email is no longer sent to thestudentuser. Verify that the integrity report is recorded in the log file.Return to the
studentuser.[root@servera ~]#
exit[student@servera ~]$Check email to confirm that no new alerts are present.
The total number of messages varies. If the database is correctly updated, then no new messages are present.
[student@servera ~]$
mail>N12root Tue Sep 14 23:22 21/970 "AIDE Alert"Use the
sudo catcommand to view the log file to verify that no differences are found between the database and file system.[student@servera ~]$
sudo cat /var/log/aide/aide.logStart timestamp: 2021-09-14 23:26:01 -0400 (AIDE 0.16) AIDE found NO differences between database and filesystem. Looks okay!! Number of entries: 5 --------------------------------------------------- The attributes of the (uncompressed) database(s): --------------------------------------------------- /var/lib/aide/aide.db.gz MD5 : /tJ6rCYNS+gHPpAqP+cdFQ== SHA1 : v0sEePAdH6VbXAFPuGrrVG+tQNM= RMD160 : UDvr4Gvti4Layc8imAlHhAgZIWo= TIGER : VCSYuYBw98r81861ipOiVVE37mdp03g1 SHA256 : 9wyBh7irOdLWeacsPHKRHYPLYKbtOzND 42xuIn4/I3w= SHA512 : nw8mnWzPdlodiPVHtgcPOH1jcrDuVnXg wt9zFVBrAr8nFURYEnm12QFt7snGn03n mx7M8Dj5RBydOMetEyoSaA== End timestamp: 2021-09-14 23:26:01 -0400 (run time: 0m 0s)
Return to
workstationasstudent.[student@servera ~]$
exit[student@workstation ~]$