Rate this page del.icio.us  Digg slashdot StumbleUpon

How can I use audit to see who changed a file in Red Hat Enterprise Linux 5?

by


Contributed by Andrew Ryan

Release Found: Red Hat Enterprise Linux 5

When creating a security policy for a server, it is sometimes necessary to see if a file has been changed unexpectedly. Using tools such as md5sum will show that a file has changed, but will not show who changed the file. Using the audit subsystem, it is possible to track the process that was responsible for changing the file.

Setting a watch on a file is accomplished using the auditctl command:

[root@host]# auditctl -w /etc/hosts -p war -k hosts-file

In this example, a watch is placed on the /etc/hosts file for any syscalls that would perform a write, read or attribute change (-p war). This is logged with the key hosts-file. This key can be used to search through the audit logs to find these actions, using the ausearch command:

[root@host]# ausearch -ts today -k hosts-file
----
time->Sat Feb  3 07:32:20 2007
type=PATH msg=audit(1170451940.872:34): item=0 name="/etc/hosts" inode=1308742 dev=fd:00 mode=0100644 ouid=0 ogid=0 rdev=00:00 obj=system_u:object_r:etc_t:s0
type=CWD msg=audit(1170451940.872:34): cwd="/root"
type=SYSCALL msg=audit(1170451940.872:34): arch=40000003 syscall=226 success=yes exit=0 a0=867c4b8 a1=458bcc4f a2=8686800 a3=1c items=1 ppid=3544 pid=3558 auid=0 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=pts0 comm="vim" exe="/usr/bin/vim" subj=root:system_r:unconfined_t:s0-s0:c0.c1023 key="hosts-files"
[root@host]#

From this trace, it can be seen that the file /etc/hosts was edited using the vim command, running from /usr/bin/vim. The user that ran the command was running with the root:system_r:unconfined_t:s0-s0:c0.c1023 context.

4 responses to “How can I use audit to see who changed a file in Red Hat Enterprise Linux 5?”

  1. Anindra says:

    Does it also fill up the /var as in RHEL AS 3? Can we add it to logrotate to rotate the logs every 20 days? How?

  2. Tonni Earnshaw says:

    Just do ‘apropos audit’ on an applicable system (e.g. RHAS/RHEL5, Fedora FC6, etc) and wallow in the possibilities :)

    –Tonni

  3. ketan gaur says:

    Well I was not able to track the login details.

  4. Konfiguracja usług w F10 | FLLOG says:

    [...] auditd Zapisuje logi audytowe generowane przez kernel. SELinux wykorzystuje tego demona do zapisu wydarzeń. Zalecane jest pozostawienie tej usługi włączonej jeśli korzystasz z SELinux. Parę słów o używaniu auditd mozna znaleźć w magazynie RH. [...]