This course is using an outdated version of the technology and is now considered to be Legacy content. It will be removed from our catalog on June 28, 2024. Please be sure to complete your course and finish any remaining labs before that date. We recommend moving to version 9.2, which is the latest version currently available.
In this exercise, you will use AIDE and Audit to detect changes on a file system and use Audit tools to identify the cause of those changes.
Outcomes
You should be able to:
Monitor /etc/passwd and /etc/shadow files with AIDE.
Set Linux Audit rules to monitor the same files.
Make changes to the files and use Audit tools to show that you have a record of what user and process made the changes.
Verify that the workstation and servera systems are started.
Log in to workstation as student using student as the password.
On workstation, run the lab aide-investigate setup command to prepare the classroom environment for the guided exercise. This command:
Ensures that aide is installed and has a clean database directory.
Ensures that the auditd service is installed, enabled, and running.
Backs up the original Audit rules file and ensures that there are no Audit rules in effect.
[student@workstation ~]$lab aide-investigate setup
From workstation, log in to servera as student.
No password is required.
[student@workstation ~]$ssh student@serveraLast login: Thu Jul 19 23:45:42 2018 from workstation.lab.example.com[student@servera ~]$
Use sudo -i to change to the root user.
Use student as the password.
[student@servera ~]$sudo -i[sudo] password for student:student[root@servera ~]#
Use a text editor to modify /etc/aide.conf.
Add selection lines to make AIDE use the CONTENT_EX group definition to monitor for any change to the /etc/shadow and /etc/passwd files.
Delete the other selection lines in the configuration file.
Normally, you would have other selection lines in your /etc/aide.conf file.
We remove the other lines in order to speed up AIDE scans for the purpose of this exercise.
[root@servera ~]#vim /etc/aide.conf
The last few lines of modified /etc/aide.conf file looks similar to the following:
...output omitted...
# Extended content + file type + access.
CONTENT_EX = sha256+ftype+p+u+g+n+acl+selinux+xattrs
# Some files get updated automatically, so the inode/ctime/mtime
# change
# but we want to know when the data inside them changes.
DATAONLY = p+n+u+g+s+acl+selinux+xattrs+sha256
# Next decide what directories/files you want in the database. Aide
# uses a first match system. Put file specific instructions before
# generic
# matches. e.g. Put file matches before directories.
/etc/passwd CONTENT_EX
/etc/shadow CONTENT_EXUse the aide --init command to initialize the AIDE database with the results of a baseline scan.
[root@servera ~]#aide --initAIDE, version 0.15.1 ### AIDE database at /var/lib/aide/aide.db.new.gz initialized.
Rename the new AIDE database file, /var/lib/aide/aide.db.new.gz, to /var/lib/aide/aide.db.gz so that AIDE uses the newly generated file as the current database.
[root@servera ~]#mv /var/lib/aide/aide.db.new.gz \>/var/lib/aide/aide.db.gz
Run the aide --check command to determine the current status of the machine's file systems.
[root@servera ~]#aide --checkAIDE, version 0.15.1 ### All files match AIDE database. Looks okay!
AIDE reports that there have been no changes to the files and directories it monitors. This makes sense, because you have not changed any files or directories since initializing the AIDE database.
AIDE will report that a file has changed, but not what or who changed it. You can add Audit rules to monitor your files so that when AIDE reports a change, you can look in the audit log to determine what or who might have caused that change.
Use the auditctl command to add a persistent Linux Audit watch rule to generate audit log entries whenever there is an attempt to read, write, execute, or change an attribute of the /etc/shadow file.
Use shadow_watch as the filter key on the audit rule.
[root@servera ~]#echo "-w /etc/shadow \>-p rwxa -k shadow_watch" >> /etc/audit/rules.d/audit.rules[root@servera ~]#augenrules --load...output omitted...
The augenrules --load command brings the newly added Audit rules into effect.
Use the auditctl -l command to list the Linux Audit rules and verify that the newly added audit rule is currently in effect.
[root@servera ~]#auditctl -l-w /etc/shadow -p rwxa -k shadow_watch
Change the student password to redhat.
This causes a change to the /etc/shadow file.
[root@servera ~]#passwd studentChanging password for user student.New password:redhatBAD PASSWORD: The password is shorter than 8 charactersRetype new password:redhatpasswd: all authentication tokens updated successfully.
Run the aide --check command to check the status of the machine's file systems.
[root@servera ~]#aide --checkAIDE 0.15.1 found differences between database and filesystem!! Start timestamp: 2018-07-20 14:46:53 Summary: Total number of files: 6 Added files: 0 Removed files: 0 Changed files: 1 --------------------------------------------------- Changed files: --------------------------------------------------- changed: /etc/shadow --------------------------------------------------- Detailed information about changes: --------------------------------------------------- File: /etc/shadow SHA256 : Lvq+jrfjZzFg77krDaTUwcB85LB9LZJX , FxQh5cRZeFuFKvzbvA2iXWwWoesaVCji
The output of the command should report that the SHA256 checksum (and therefore the content) of the /etc/shadow file has changed.
The values of the SHA256 checksums that you see in the output of the preceding aide command may differ from what you see in your system.
To further investigate the change to /etc/shadow that AIDE reported, use ausearch to search the audit log.
You can use the shadow_watch key used by your watch rule to filter for the events relevant to /etc/shadow.
You can also use the -i option to convert numbers for UIDs and time stamps into names and more human-readable text.
The following output includes an example of one audit event that could be displayed.
[root@servera ~]#ausearch -i -f /etc/shadow -k shadow_watch...output omitted... ---- type=PROCTITLE msg=audit(07/20/2018 14:30:08.319:631) : proctitle=passwd student type=PATH msg=audit(07/20/2018 14:30:08.319:631) : item=0 name=/etc/shadow inode=288181 dev=fc:01 mode=file,000 ouid=root ogid=root rdev=00:00 obj=system_u:object_r:shadow_t:s0 objtype=NORMAL cap_fp=none cap_fi=none cap_fe=0 cap_fver=0 type=CWD msg=audit(07/20/2018 14:30:08.319:631) : cwd=/root type=SYSCALL msg=audit(07/20/2018 14:30:08.319:631) : arch=x86_64 syscall=open success=yes exit=5 a0=0x7f7659b2323c a1=O_RDONLY a2=0x1 a3=0x7f7661aeec8c items=1 ppid=1710 pid=30271 auid=student uid=root gid=root euid=root suid=root fsuid=root egid=root sgid=root fsgid=root tty=pts0 ses=15 comm=passwd exe=/usr/bin/passwd subj=unconfined_u:unconfined_r:passwd_t:s0-s0:c0.c1023 key=shadow_watch ---- ...output omitted...
The output of ausearch should find a number of audit events, such as the one in the preceding output.
Each event is separated by four dashes in the output, and the event number should appear in the output after the final colon in the time stamp (the msg field in each audit record).
This is audit event 631.
This event consists of four records: PROCTITLE, PATH, CWD, and SYSCALL.
PROCTITLE gives the full command line that triggered the audit event, in this case passwd student.
PATH shows the file (/etc/shadow) the event affects and provides information about the file such as its inode number, the major/minor number of the device its file system is on, its ownership and permissions, it is a regular file, and so on.
CWD gives the current working directory the command was run from (/root).
SYSCALL gives the actual syscall for this record. This is the most interesting output.
The syscall=open and a1=O_RDONLY fields indicate that this event is logging an attempt to open /etc/shadow in read-only mode.
The access was successful (success=yes).
The user was on the pseudoterminal on pts/0 (possibly a graphical terminal window or ssh login) at the time.
The uid and euid fields indicate that the process was running as root.
However, the auid field indicates that the user that ran this command originally logged in as student.
Other information can be extracted from this event record as well, such as the PID of the process and absolute path to the executable used.
This is not the audit event that caused the change to /etc/shadow, because it opens the file read-only.
However, it may be part of the sequence of audit events that led to the change.
You need to look further at the output to find the correct event.
The documentation in the Audit System Reference appendix of the Red Hat Enterprise Linux 7 Security Guide provides a list of audit fields and records that can be very useful when interpreting audit events.
Further down in the output of ausearch, there should be an event that occurred at almost the same time, which looks similar to the following output:
...output omitted...
----
type=PROCTITLE msg=audit(07/20/2018 14:30:08.341:633) : proctitle=passwd student
type=PATH msg=audit(07/20/2018 14:30:08.341:633) : item=4 name=/etc/shadow inode=33578439 dev=fc:01 mode=file,000 ouid=root ogid=root rdev=00:00 obj=system_u:object_r:shadow_t:s0 objtype=CREATE
type=PATH msg=audit(07/20/2018 14:30:08.341:633) : item=3 name=/etc/shadow inode=288181 dev=fc:01 mode=file,000 ouid=root ogid=root rdev=00:00 obj=system_u:object_r:shadow_t:s0 objtype=DELETE
type=PATH msg=audit(07/20/2018 14:30:08.341:633) : item=2 name=/etc/nshadow inode=33578439 dev=fc:01 mode=file,000 ouid=root ogid=root rdev=00:00 obj=system_u:object_r:shadow_t:s0 objtype=DELETE
type=PATH msg=audit(07/20/2018 14:30:08.341:633) : item=1 name=/etc/ inode=33554497 dev=fc:01 mode=dir,755 ouid=root ogid=root rdev=00:00 obj=system_u:object_r:etc_t:s0 objtype=PARENT
type=PATH msg=audit(07/20/2018 14:30:08.341:633) : item=0 name=/etc/ inode=33554497 dev=fc:01 mode=dir,755 ouid=root ogid=root rdev=00:00 obj=system_u:object_r:etc_t:s0 objtype=PARENT
type=CWD msg=audit(07/20/2018 14:30:08.341:633) : cwd=/root
type=SYSCALL msg=audit(07/20/2018 14:30:08.341:633) : arch=x86_64 syscall=rename success=yes exit=0 a0=0x7f251f5bb332 a1=0x7f251f5bb2bc a2=0x7f25213a57b8 a3=0x0 items=5 ppid=1710 pid=30271 auid=student uid=root gid=root euid=root suid=root fsuid=root egid=root sgid=root fsgid=root tty=pts0 ses=15 comm=passwd exe=/usr/bin/passwd subj=unconfined_u:unconfined_r:passwd_t:s0-s0:c0.c1023 key=shadow_watch
This is audit event 633.
Its SYSCALL record indicates that a rename(2) syscall was successfully executed at 14:30:08 on July 20, 2018.
It was executed by user root, who originally logged in as user student, by running the /usr/bin/passwd executable on the pts/0 terminal.
The PID reported for the process by this record matches the PID of the process that caused the audit event in the previous step of this exercise, so both events were probably caused by the same executing program.
The PROCTITLE record indicates that this was done as part of a passwd student command.
The PATH records indicate that the old /etc/shadow file using inode 288181 was deleted (item 3).
Likewise, inode 33578439 was renamed from /etc/nshadow to /etc/shadow (items 2 and 4).
That is the normal way passwd operates.
It creates a temporary /etc/nshadow file containing the changes and then copies it over the old shadow password file.
This is the event that changed the /etc/shadow file.
Log out from the servera system completely.
[root@servera ~]#logout[student@servera ~]$logout[student@workstation ~]$