To set a connections rate limit in pfSense using Suricata, you generally want to limit the number of new connections or connection attempts from a single IP to mitigate scanning, brute force, or other types of attacks. This can be done by configuring Suricata’s detection rules with thresholding and by using pfSense's firewall features for rate limiting.
Overview
- Suricata: An IDS/IPS that can detect and optionally block suspicious traffic based on rules. Rate limiting in Suricata is achieved via thresholding/limit rules or by using event filters.
- pfSense firewall: Can rate limit traffic at the firewall level using firewall rules with advanced options like "Limit States" or "Firewall pipe" queues.
Below is a step-by-step guide combining both tools:
Step 1: Set Up Suricata on pfSense
-
Install Suricata Package if not installed:
- Go to System > Package Manager > Available Packages.
- Find Suricata and install it.
-
Configure Suricata Interface:
- Go to Services > Suricata > Interfaces.
- Add or edit an interface for your WAN or LAN.
- Enable the interface and choose necessary settings.
Step 2: Enable Thresholding in Suricata Rules (Connection Rate Limit)
Suricata allows you to configure rules with thresholding to limit alerts or blocks for rules based on multiple hits from the same source IP within a time window.
You can write or modify rules to include the threshold keyword, for example:
alert tcp any any -> $HOME_NET 22 (msg:"SSH Brute force detection"; flags:S; threshold:type both, track by_src, count 5, seconds 60; sid:1000001; rev:1;)
Explanation:
- This rule alerts if there are 5 TCP SYN packets (possible connection attempts) from the same source to your home net on port 22 within 60 seconds.
Steps to apply thresholding:
-
Custom Rules:
- Go to Services > Suricata > Interface > Edit > Rules tab.
- Add your custom rules with
threshold settings.
- Save and reload Suricata.
-
Using Event Filters GUI:
- Go to Services > Suricata > Interface > Edit > Rules tab.
- Scroll down to the Event Filters (Thresholding) section.
- Click Add.
- Define the rule filter based on
sid, type (threshold), track (by_src), count, seconds, and action.
- Save and reload Suricata.
Step 3: Enable Intrusion Prevention (Block Mode)
- Go to your Suricata interface configuration, General Settings tab.
- Check IPS Mode so Suricata actively blocks matching traffic instead of just alerting.
- Ensure your custom thresholded rules are enabled and tuned.
Step 4: (Optional) Rate Limit Connections Using pfSense Firewall
For more immediate and low-level rate limiting, you can also configure firewall rules:
1. Use Firewall Limit States
- Go to Firewall > Rules.
- Edit or create a WAN or LAN rule.
- Under Advanced options > State Timeout, set limits.
- Under Advanced options > Firewall Maximum States, limit the number of simultaneous connections per IP.
2. Use Firewall pipe (bandwidth shaping) to limit bandwidth per host or connection.
3. Use the Limit states per source IP in firewall rules to limit how many connections per source IP:
- In the firewall rule's Advanced Options, set Max States per host or Max Source Connections.
Summary Example
- Write Suricata custom rule with thresholding:
alert tcp any any -> $HOME_NET 80 (msg:"HTTP connection rate limit exceeded"; flags:S; threshold:type both, track by_src, count 20, seconds 60; sid:1000002; rev:1;)
- Enable Suricata IPS mode.
- Apply firewall max states or max source connections limitations for additional protection.
Additional Notes
- Be careful with blocking rules to avoid false positives or blocking legitimate traffic.
- Test your rules in alert-only mode before switching to IPS mode.
- Tune thresholds based on your network traffic patterns.
- Suricata’s threshold mechanism limits alerts and can be combined with blocking to prevent connection floods.
If you want a detailed example or help writing specific Suricata rules or pfSense firewall rules, just ask!