Bookmark this page

Guided Exercise: Configuring Change Tracking

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

  1. Log in to servera and switch to the root user.

    [student@workstation ~]$ ssh student@servera
    ...output omitted...
    [student@servera ~]$ sudo -i
    [sudo] password for student: student
    [root@servera ~]#
  2. Configure AIDE to monitor file integrity.

    1. Initialize the AIDE database.

      [root@servera ~]# aide -i
      Start 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)
    2. Remove the new substring from the initial database name to enable it for the aide command to use.

      [root@servera ~]# mv /var/lib/aide/aide.db.new.gz /var/lib/aide/aide.db.gz
  3. View the /etc/aide.conf file 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_EX
  4. Generate a file integrity report for the default monitored files and verify that the report is present in the logs.

    1. Generate the file integrity report.

      [root@servera ~]# aide --check
      Start 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)
    2. Verify that the file integrity report is recorded in the log file.

      [root@servera ~]# cat /var/log/aide/aide.log
      Start 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)
  5. Create a script to send an email alert whenever a change in the monitored files is found.

    [root@servera ~]# vim /root/aide_mon.sh
    if ! 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
    fi

    Make the script executable.

    [root@servera ~]# chmod +x /root/aide_mon.sh
  6. Schedule the AIDE execution for every two minutes. Create the /etc/cron.d/aide file and add the following lines:

    [root@servera ~]# vim /etc/cron.d/aide
    # AIDE Checks and alert
    */2 * * * * root /sbin/aide --check && /root/aide_mon.sh
  7. Verify 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.log
    Start 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)
  8. 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 user01
  9. As the student user on the servera machine, verify that an AIDE alert 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 the student user.

    Note

    Log in to the servera machine in a separate terminal. Use the journalctl command to monitor the email that is sent to the student user.

    [root@servera ~]# journalctl -f -u postfix --since today
    1. Switch to the student user on the servera machine to check for AIDE alert emails.

      [root@servera ~]# exit
      [student@servera ~]$
    2. Check the email.

      [student@servera ~]$ mail
      Heirloom 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.

      & 1
      Message  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 mail interactive interface.

      & q
      ...output omitted...
      [student@servera ~]$
  10. Switch to the root user on the servera machine. Update the AIDE database to add the recent file changes. Back up the AIDE database. Remove the new substring from the updated database name to enable it for the aide command to use.

    1. Switch to the root user.

      [student@servera ~]$ sudo -i
      [sudo] password for student: student
      [root@servera ~]#
    2. Update the database.

      [root@servera ~]# aide --update
    3. Back up the current database.

      [root@servera ~]# mv /var/lib/aide/aide.db.gz /var/lib/aide/aide.db.old.gz
    4. Enable the new database for the aide command to use.

      [root@servera ~]# mv /var/lib/aide/aide.db.new.gz /var/lib/aide/aide.db.gz
  11. Generate an integrity report of the monitored files.

    [root@servera ~]# aide --check
    Start 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)
  12. Switch to the student user on the servera machine. Verify that an alert email is no longer sent to the student user. Verify that the integrity report is recorded in the log file.

    1. Return to the student user.

      [root@servera ~]# exit
      [student@servera ~]$
    2. 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
      >N 12 root                  Tue Sep 14 23:22  21/970   "AIDE Alert"
    3. Use the sudo cat command 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.log
      Start 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)
  13. Return to workstation as student.

    [student@servera ~]$ exit
    [student@workstation ~]$

Finish

On the workstation machine, use the lab command to complete this exercise. This is important to ensure that resources from previous exercises do not impact upcoming exercises.

[student@workstation ~]$ lab finish baseline-changetracking

Revision: rh342-8.4-6dd89bd