| | |

How to Use auditd on Ubuntu to Monitor File Changes

Monitoring file changes on a Linux system is crucial for maintaining security and tracking any unauthorized modifications. On Ubuntu, auditd is a powerful tool that can help you achieve this. In this guide, we’ll walk you through the steps to install, configure, and use auditd to trace file changes effectively—especially useful for tracking down the source of recurring malware infections on WordPress sites.

What is Auditd?

auditd, short for “Audit Daemon,” is a userspace component to the Linux Auditing System. It provides comprehensive monitoring and logging capabilities for all system activities, including file access, modification, user authentication, and more. By using auditd, you can set up rules to monitor specific files or directories and keep track of who made changes and when.

Why Use Auditd for WordPress Security?

One of the most frustrating issues for WordPress site administrators is dealing with recurring malware infections. Even after cleaning the site, malicious files may reappear if the root cause isn’t identified. By using auditd to monitor key WordPress directories and files, you can trace the source of these infections. This way, you’ll know exactly when and how malware files are being reintroduced, helping you to eliminate the threat for good.

Steps to Use Auditdon Ubuntu

1. Install auditd

First, you need to install auditd on your Ubuntu system. Open your terminal and run the following commands to update your package list and install auditd along with its plugins:

sudo apt update
sudo apt install auditd audispd-plugins

This will install the auditd service and additional plugins required for its operation.

2. Start and Enable Audit

Once installed, start the auditd service and ensure it starts automatically on boot. Use the following commands:

sudo systemctl start auditd
sudo systemctl enable auditd

Now, auditd is up and running, ready to monitor your system activities.

3. Add an Audit Rule

To monitor specific files or directories, you need to set up audit rules. These rules define what auditd should watch and what type of activities it should log.

  • Monitoring a Specific File: For instance, to monitor changes to the /var/web/site/public_html/wp-config.php file (which contains user account information), use the following command:
    sudo auditctl -w /var/web/site/public_html/wp-config.php -p wa -k config_changes
    Here, -w /var/web/site/public_html/wp-config.php tells auditd to watch the /var/web/site/public_html/wp-config.php file.
    The -p wa option sets it to monitor both write (w) and attribute (a) changes. The -k config_changes option assigns a key to this rule, making it easier to search the logs later.
  • Monitoring an Entire Directory: If you want to monitor changes within an entire directory, use a similar command:
    sudo auditctl -w /var/web/site/public_html/ -p wa -k directory_changes

    For WordPress sites, you might want to monitor directories like /var/web/site/public_html/wp-content where themes, plugins, and uploads are stored, as these are common targets for malware.

4. View Audit Logs

Once you’ve set up your audit rules, auditd will start logging any matching activities. To view these logs, you can use the ausearch command:

  • View Logs by Key: To see all logs related to the passwd_changes key:sudo ausearch -k config_changes
  • Real-Time Log Viewing: If you want to see logs as they are recorded, use the following command:sudo tail -f /var/log/audit/audit.log

This command will display new entries in the audit log file as they are added.

5. Persist Audit Rules

Audit rules set with auditctl are not persistent and will be lost after a reboot. To make your rules permanent, add them to the /etc/audit/audit.rules file.

For example, open the file in a text editor:

sudo nano /etc/audit/audit.rules

Then, add your rules:

-w /var/web/site/public_html/wp-config.php -p wa -k config_changes

Save and close the file, then restart auditd to apply the changes:

sudo systemctl restart auditd

6. Refining and Removing Rules

Over time, you may want to refine or remove certain audit rules.

  • Removing a Specific Rule: To remove a rule, use the -W option:sudo auditctl -W /var/web/site/public_html/wp-config.php -p wa -k config_changes
  • Listing Active Rules: To see all active audit rules, use:sudo auditctl -l

This command lists all the current rules, helping you review and manage them as needed.

Conclusion

Using auditd on Ubuntu is an effective way to keep track of changes to critical files and directories. This is particularly useful for WordPress site administrators dealing with recurring malware infections. By monitoring key files and directories, you can identify when and how malware is being reintroduced to your site, allowing you to take targeted action to eliminate the threat. Whether you’re a system administrator or a security-conscious user, mastering auditd is a valuable skill that enhances your system’s security posture.

Similar Posts

  • Do we need to pay extra for Using Social apps?

    The mobile companies are charging us to use ‪Facebook ‬‪‎Whatsapp ‬‪‎Amazon ‬‪Flipkart‬ instead of using the data from the current Data Pack. Guys we must take some action as a community against this, as this is against the code of Public Web which‪ #‎Mozilla‬ Supports. Kindly show your support by sending a mail on [email protected]

  • |

    Foxwave 16-02

    The event #foxwavebhopal was an awesome at Bhopal School of Social Sciences. I just loved it. As it was my first event i got a lot to know about Mozilla and its mission to create the world open, free and innovative. I am happy working as a Firefox student ambassador form my college and i’ll…

  • India wants open Web – NetNeutrality

    “We have 11 days left to fight anti‪ #‎net‬neutrality.. Here’s what you can do. 1. Sign this petition over at https://www.change.org/p/rsprasad-trai-don-t-allow-differential-pricing-of-services-let-consumers-choose-how-they-want-to-use-internet-netneutrality and share it with your friends. 2. Write directly to TRAI at “[email protected]”. You can write what you like – but you could have words that say something like Dear TRAI, I am writing…

  • Hour of code Bhopal

    Hello guys, This blog post is about the Hour of Code conducted in Bhopal during December 7th to 13th, 2015. We organised the session jointly. A group of passionate volunteers (Mozillians and Microsoft Student Partners) of our community. It was all started after my friend’s Robin Koshy’s telephonic conversation with me (Aditya Shah). Where we…

  • MozMeet

    On Sunday, 9/August/2015 it was a pleasent morning. I with Rahul Talreja hosted an event, i.e., MozCoffee. At around 12 many FSA’s from all over the bhopal met at the venue, Balaji Tower, MP nagar, Bhopal and had a great session delivered by Mr. Rahul Talreja (Rep, Mozilla). We had a great discussion about the…

  • App Day SATI 26-sept-15

    On Saturday, 26-sept 2015, woke up at 6 and left for vidisha to create awesomeness at sharp 7 with Rahul Talreja (RePs), Vidit, Kushagra Varade, Rashmi and  Alisha stumblick the whole way. It was really privileged for me to be there, i just loved it. The agenda for the day was: *Introduction to Mozilla by…

Leave a Reply

Your email address will not be published. Required fields are marked *