Chapter 2. Automating Network Intrusion Detection and Prevention Systems (IDPS) with Ansible Automation Platform
You can use Ansible Automation Platform to automate your Intrusion Detection and Prevention System (IDPS). For the purpose of this guide, we use Snort as the IDPS. Use automation hub to consume content collections, such as tasks, roles, and modules to create automated workflows.
2.1. Requirements and prerequisites Copy linkLink copied to clipboard!
Before you begin automating your IDPS with Ansible Automation Platform, ensure that you have the proper installations and configurations necessary to successfully manage your IDPS.
- You have installed Ansible-core 2.15 or later.
- SSH connection and keys are configured.
- IDPS software (Snort) is installed and configured.
- You have access to the IDPS server (Snort) to enforce new policies.
2.1.1. Verifying your IDPS installation Copy linkLink copied to clipboard!
Use the following procedure to verify that Snort has been configured successfully:
Procedure
Call snort using
sudoand ask for the version:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Verify that the service is actively running using the following command:
sudo systemctl:Copy to Clipboard Copied! Toggle word wrap Toggle overflow -
If the Snort service is not actively running, restart it with
systemctl restart snortand recheck the status. -
When you confirm that the service is actively running, exit the Snort server by simultaneously pressing
CTRLandD, or by typingexiton the command line. All further interaction will be done through Ansible Automation Platform from the Ansible control host.
2.2. Automating your IDPS rules with Ansible Automation Platform Copy linkLink copied to clipboard!
To automate your IDPS, use the ids_rule role to create and change Snort rules. Snort uses rule-based language that analyzes your network traffic and compares it against the given rule set.
The following lab environment demonstrates what an Ansible security automation integration would look like. A machine called “Attacker” simulates a potential attack pattern on the target machine on which the IDPS is running.
Keep in mind that a real world setup will feature other vendors and technologies.
2.2.1. Creating a new IDPS rule Copy linkLink copied to clipboard!
Use the ids_rule role to manage your rules and signatures for IDPS. For example, you can set a new rule that looks for a certain pattern aligning with a previous attack on your firewall.
Currently, the ids_rule role only supports Snort IDPS.
Prerequisites
-
You need
rootprivileges to make any changes on the Snort server.
Procedure
Install the
ids_rulerole using the ansible-galaxy command:ansible-galaxy install ansible_security.ids_rule
$ ansible-galaxy install ansible_security.ids_ruleCopy to Clipboard Copied! Toggle word wrap Toggle overflow Create a new playbook file titled
add_snort_rule.yml. Set the following parameters:- name: Add Snort rule hosts: snort
- name: Add Snort rule hosts: snortCopy to Clipboard Copied! Toggle word wrap Toggle overflow Add the
becomeflag to ensure that Ansible handles privilege escalation.- name: Add Snort rule hosts: snort become: true
- name: Add Snort rule hosts: snort become: trueCopy to Clipboard Copied! Toggle word wrap Toggle overflow Specify the name of your IDPS provider by adding the following variables:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Add the following tasks and task-specific variables (e.g., rules, Snort rules file, and the state of the rule - present or absent) to the playbook:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Tasks are components that make changes on the target machine. Since you are using a role that defines these tasks, the
include_roleis the only entry you need.The
ids_rules_filevariable specifies a defined location for thelocal.rulesfile, while theids_rule_statevariable indicates that the rule should be created if it does not already exist.Run the playbook by executing the following command:
ansible-navigator run add_snort_rule.ym --mode stdout
$ ansible-navigator run add_snort_rule.ym --mode stdoutCopy to Clipboard Copied! Toggle word wrap Toggle overflow Once you run the playbook, all of your tasks will be executed in addition to your newly created rules. Your playbook output will confirm your PLAY, TASK, RUNNING HANDLER, and PLAY RECAP.
Verification
To verify that your IDPS rules were successfully created, SSH to the Snort server and view the content of the /etc/snort/rules/local.rules file.