• author: IppSec

Configuring UFW and iptables for Logging

Introduction: In this video, we will be focusing on vlogging, specifically iptables UFW and audit D. Logging is a crucial aspect of system configuration as it helps us identify compromise and unexpected activities on our machine. It is recommended to configure logging right when we install our operating system to ensure we can track events in real-time. While most people associate logging with identifying compromise, it has several other important uses. For example, logging can help us track connections made to our machine and provide evidence in case of any malicious activities. It is also useful for generating reports and providing timestamps for specific events.

Configuring UFW and iptables: To start off, we will configure UFW (Uncomplicated Firewall) and iptables to enable logging. UFW is a user-friendly command-line interface for managing firewall rules based on iptables. We will utilize Ansible to automate the configuration process.

Steps to configure UFW and iptables for logging:

  1. Identify UFW status: First, we need to check if UFW is installed and enabled on the system. We can do this by running the following task:
-name:Check UFW statuscommand:ufw status
  1. Configure UFW state and policy: Next, we will configure UFW to be enabled and set the default policy to allow. This can be achieved using the following Ansible task:
-name:Configure UFW state and policycommand:ufw enable && ufw default allow
  1. Add logging for incoming connections: To enable logging for incoming connections, we will add a line to the after.rules file, which is where UFW stores its iptables rules. We can use the "lineinfile" module provided by Ansible to achieve this. Here's an example playbook task:
-name:Add logging for incoming connectionslineinfile:state:presentpath:/etc/ufw/after.rulesinsertbefore:"#Endrequiredlines"line:"-AINPUT-ptcp--syn-jLOG--log-prefix'ufw-send-log'"
  1. Restart UFW: After making the necessary changes, we need to restart UFW for the changes to take effect. We can use the service module in Ansible to achieve this:
-name:Restart UFWservice:name:ufwstate:restarted
  1. Verify logging configuration: To ensure that logging is properly configured, we can check the contents of the system log file. By default, UFW logs are stored in either /var/log/messages or /var/log/syslog. We can enable the required log service using the following task:
-name:Enable syslog serviceservice:name:rsyslogenabled:yes

Conclusion: In this video, we covered the process of configuring UFW and iptables for logging. By enabling logging, we can track incoming connections and identify any suspicious activities on our machine. Additionally, logging provides valuable information for generating reports and providing timestamps for specific events. By following these steps, you can enhance the security and monitoring capabilities of your system.

Installing and Configuring AuditD

When it comes to monitoring and auditing system activity, AuditD is an excellent tool to have in your arsenal. With AuditD, you can track and record any changes or events that occur on your system, providing you with a detailed log of activity.

To get started, we need to install AuditD on our system. Here's how you can do it:

  1. Open your terminal and run the following command to install AuditD:
sudo apt install auditd
  1. Once the installation is complete, we can proceed with configuring AuditD. By default, AuditD comes with a set of rules that define what events to monitor. However, we can customize these rules to suit our specific requirements. To do this, we will create a new file to store our custom rules. Run the following command to create the file:
sudo touch /etc/audit/rules.d/custom.rules
  1. Now, let's open the file for editing with your preferred text editor:
sudo nano /etc/audit/rules.d/custom.rules
  1. In the custom.rules file, you can define the specific events you want AuditD to monitor. For example, if you want to track changes made to the /etc/passwd file, you can add the following rule:
-w /etc/passwd -p wa -k passwd_changes

This rule tells AuditD to monitor any write (w) or attribute (a) changes that occur to the /etc/passwd file and assign the event a key (k) called "passwd_changes". You can add as many rules as you need, depending on your monitoring requirements.

  1. Save and close the file when you're done. Now, we need to restart the AuditD service to apply the new rules:
sudo systemctl restart auditd
  1. To view the logs generated by AuditD, you can use the ausearch command. For example, to search for events related to failed access attempts, you can run:
sudo ausearch -sv no

This command will display a list of events where the access attempt was unsuccessful.

Alternatively, you can install the Laurel plugin for AuditD. Laurel provides a more user-friendly interface for searching and analyzing AuditD logs. To install Laurel, follow these steps:

  1. First, we need to create a new user called _laurel:
sudo useradd -r -M -d /nonexistent -s /bin/false _laurel
  1. Next, let's download the latest build of Laurel from the official GitHub repository. You can find the download link in the repository's README file.

  2. Once the download is complete, extract the contents of the downloaded archive.

  3. Run the installation command to install the Laurel plugin:

sudo ./install.sh
  1. After the installation is finished, you can start using the laurel command to search and analyze AuditD logs. For example, to search for events related to file access, you can use the following command:
sudo laurel --search "type=SYSCALL and arch=x86_64 and syscall=open"

This command will display a list of events where the system call open was executed.

By following these steps, you can install and configure AuditD on your system, allowing you to monitor and track system activity effectively. Whether you choose to use the built-in ausearch command or the Laurel plugin, AuditD provides you with the tools you need to enhance the security and accountability of your system.

Installing and Configuring Laurel with Ansible

Laurel is a powerful auditing tool that provides detailed and comprehensive monitoring capabilities for system administrators. In this article, we will guide you through the process of installing and configuring Laurel using Ansible, a popular automation tool.

Creating an Ansible Role for Laurel Installation

To start the installation process, we highly recommend creating an Ansible role specifically for installing Laurel. This allows for easy management and configuration of the tool in your system.

  1. Begin by downloading the latest Laurel build from the official website. Follow the provided instructions to obtain the necessary files.

  2. Before proceeding with the installation, it is necessary to add a user called "Laurel". This user will ensure that the Laurel plugin does not run under the root user, enhancing system security.

    -name:Create Laurel useruser:name:Laurelstate:presentshell:/bin/falsecreatehome:falsehome:/var/log/Laurelmode:750

    It is important to note that we disable the creation of a home directory for the "Laurel" user, as this would copy unnecessary files into the system.

  3. After successfully creating the "Laurel" user, we need to create the corresponding directory for storing the logs.

    -name:Create Laurel log directoryfile:path:/var/log/Laurelstate:directoryowner:Laurelgroup:Laurelmode:750

    This step ensures that the designated log directory exists and has the proper permissions.

Customizing the Laurel Configuration

Once the user has been created and the log directory has been established, it is time to customize the Laurel configuration files according to your system requirements. Follow these steps to complete the configuration.

  1. Download the "Laurel config.toml" file and the Laurel audit D plugin file from the Laurel website.

  2. Copy the "Laurel config.toml" file to the /etc/Laurel directory.

    -name:Copy Laurel config.tomlcopy:src:config.tomldest:/etc/Laurel
  3. Create the /etc/audit/plugins.d directory if it does not already exist.

    -name:Create audit plugins directoryfile:path:/etc/audit/plugins.dstate:directoryowner:rootgroup:root
  4. Copy the Laurel audit D plugin file to the /etc/audit/plugins.d directory.

    -name:Copy Laurel audit D plugincopy:src:laurel.comdest:/etc/audit/plugins.d/loro.com

Downloading the Laurel Binary

To complete the installation process, you will need to download the Laurel binary file and place it in the appropriate location on your system.

  1. Download the latest Laurel binary file from the official website. Ensure that you choose the correct version for your system architecture.

    -name:Download Laurel binaryget_url:url:<laurel_binary_url>dest:/tmp/mode:640
  2. Extract the downloaded Laurel binary file.

    -name:Extract Laurel binaryunarchive:src:/tmp/laurel_binary.tar.gzdest:/tmp/remote_src:yes
  3. Move the extracted Laurel binary to the desired location.

    -name:Move Laurel binarycommand:mv /tmp/laurel /usr/local/bin/laurelbecome:true
  4. Finally, update the permissions of the Laurel binary.

    -name:Set permissions for Laurel binaryfile:path:/usr/local/bin/laurelmode:755

Simplifying the Audit D Configuration Playbook

In this article, we will explore ways to simplify the configuration playbook for Audit D. We will be using loops to iterate over recurring tasks and make the playbook more concise and efficient. Additionally, we will discuss the benefits of using JQ, a powerful JSON processor, for parsing and manipulating audit logs.

Installing JQ for Audit Log Parsing

Before diving into the playbook, let's briefly discuss JQ. JQ is a tool that allows us to filter, extract, and manipulate JSON data. We will be using JQ to enhance the readability and analysis of our audit logs. To install JQ, we can simply add the JQ package from the official repository.

To add the JQ package, execute the following command:

sudo apt-get install jq

After installing JQ, we can proceed with configuring the playbook.

Simplifying the Playbook with Loops

The original playbook provided a working configuration but was riddled with repetitive tasks. To simplify it, we will employ loops for tasks that require multiple iterations. By using loops, we can reduce redundancy and create a more streamlined playbook.

Installing Packages

The first task we will tackle is installing packages. Instead of explicitly mentioning each package in the playbook, we can use a loop to iterate over a list of packages and install them automatically. For example, the following code snippet demonstrates how to install the Audit D and JQ packages using loops in Ansible:

-name:Installing packagesapt:name:"{{item}}"state:presentloop:-auditd-jq

With this new approach, adding or removing packages becomes effortless. Simply modify the list of packages in the loop, and Ansible will take care of the rest.

Creating Directories

The original playbook had two directory creation tasks, namely temp/Laurel and /etc/Laurel. To simplify this, we can once again employ loops to create the required directories automatically.

-name:Creating directories for Laurelfile:path:"{{item}}"state:directoryowner:"{{ansible_user}}"group:"{{ansible_user}}"mode:0755loop:-/temp/Laurel-/etc/Laurel

By utilizing loops, we eliminate the need to repeat similar directory creation tasks, making our playbook more concise and maintainable.

Configuring Audit D

The original playbook also consisted of tasks related to downloading, extracting, and starting Audit D. While loops could potentially be used for some of these tasks, we will refrain from implementing them to avoid unnecessary complexity.

To facilitate the extraction and transfer of the configuration files, we can employ the Ansible copy module. By using this module, we can easily copy the necessary files to their designated locations.

To simplify the configuration playbook even further, we will create a separate Ansible role called "configure_logging" and move the related tasks to the role's main.yml file. This will make the playbook more modular and easier to manage.

Simplifying and Cleaning up the Playbook: A Step-by-Step Guide

In this article, we will be discussing how to simplify and clean up your Playbook. We will go over every step in detail to ensure a smooth and efficient process.

Removing Parent Build

To begin, we need to remove the parent build by running the command:

tar cjvf parrotbuild.tar.bz2 parrotbuild/

Configuring the IP Address

Next, we need to configure the IP address. Run the following commands:

parrotfresh wget 8000 parrotbuild.tar.bz2
start xjvf parrotbuild.tar.bz2
sudo whoami

Running the Ansible Playbook

To run the Ansible Playbook, execute the following command:

ansible-playbook main.yaml

Please note that the font size may appear small; however, this is something we can easily fix in the future.

Installing Ansible Galaxy

Before proceeding, we need to install Ansible Galaxy using the following command:

ansible-galaxy install -r requirements.yaml

We also need to update the snapshot to ensure it includes the necessary changes:

snapshot -update

Troubleshooting and Fixing Errors

During this process, we encountered an error in how we were handling the item shoot. To resolve this, we made the necessary changes in the roles, specifically in the tasks folder of the "configure logging" role.

To fix the error, follow these steps:

  1. Navigate to parrotbuild/roles/configure_logging/tasks/auditd.yml
  2. Edit the file to ensure the correct syntax is used
  3. Save the changes

It is worth emphasizing the importance of testing everything after making any modifications or fixes.

Verifying the Changes

After implementing the fixes and modifications, let's verify if everything is working correctly.

  1. Start the server by running the command:
wget AR
  1. Navigate to the parrotbuild directory:
cd parrotbuild
  1. Execute the Ansible Playbook:
ansible-playbook main.yaml

If all goes well, you should see that the Playbook is working correctly.

Logging and System Analysis

During the process, we enabled our assist log and configured UFW. To ensure everything is functioning as expected, let's analyze the system logs.

  1. Use the following command to search for specific entries related to the Parrot build:
grep parrotbuild.tar.bz2 /var/log/audit/audit.log | jq '.'
  1. To investigate the Python process, run the command:
ps -ef | grep python

By analyzing these logs, we can gain insights into the operations of the Parrot build and identify any potential issues.

Future Improvements

Although we did not log all file open commands in this article, it is worth mentioning that it is possible to edit the auditd configuration file to achieve this. This topic could be explored further in a future video.

By following the steps outlined in this article, you have successfully installed and configured laurel using ansible. this powerful auditing tool will prove invaluable in monitoring and enhancing the security of your system. feel free to explore additional features and customization options to tailor laurel to your specific requirements. enjoy the benefits of streamlined system auditing and monitoring with laurel and ansible.
In this article, we explored various methods to simplify the configuration playbook for audit d. by utilizing loops and leveraging tools like jq, we can reduce redundancy and make the playbook more efficient. additionally, by organizing related tasks into separate ansible roles, we enhance the modularity and maintainability of our playbook.

stay tuned for the next installment, where we will dive deeper into customizing and fine-tuning audit d configurations.

In this article, we discussed the steps to simplify and clean up the Playbook, addressing any errors and troubleshooting along the way. We also analyzed system logs to ensure everything is functioning as expected. By following these steps, you can streamline your Playbook and improve efficiency in your workflow.

We hope you found this article helpful and informative. If you have any questions or suggestions, please feel free to leave a comment. Thank you for reading, and see you in the next article!

Previous Post

Exploring the IPS Hack the Box: A Journey of Web App Enumeration

Next Post

Stalker: A Journey Through the Hack the Box Machine

About The auther

New Posts

Popular Post