This is a custom IPS solution for EdgeOS routers to block malicious IP adresses as reported by Suricata.
Suricata alerts are pushed to a Redis server under a key named "suricata". The edgeos_ips.py script runs as a daemon and gathers the offending IPs from the Suricata alerts stored in Redis, and dynamically updates an address-group named IP_BLACKLIST on the EdgeOS router using api calls. The address-group is used in firewall rules to block incoming traffic.
- Configure a Redis server. No need for something super fancy. I am using a Docker instance (https://hub.docker.com/r/redis/redis-stack which comes with a nice admin interface) running on a Raspberry Pi.
- Configure Suricata to add an additional eve-log logger instance of type Redis pointing to your Redis server. Use the key name "suricata" and the list mode.
- On the EdgeRouter, create a firewall address group named "IP_BLACKLIST"
- Configure your router to deny all incoming traffic from IPs in the IP_BLACkLIST for both WAN_IN and WAN_LOCAL
- On the EdgeRouter, add an admin user named "api_user"
- Customize the script and enter the user password, redis server information relevant to your setup
- On the machine with the Redis instance (or any other machine that can connect to the Redis server for that matter), copy the script into /usr/local/bin change its owner to a local user and change the permission of the script file to 700
- Copy the edgeos-ips.service file into /etc/systemd/system, edit the file and change the User= to your local username
- Reload the services: sudo systemctl daemon-reload
- Start the edgeos-ips service: sudo service edgeos-ips start
- There is only minimal error management in the script at the moment.
- The blacklist on the router will potentially grow indefinitely. Address-groups are limited to ~65000 entries I think. You can regularly delete and recreate the list if it becomes too big.
- The script does an infinite loop and can be at times a bit heavy on the resources. You can change how frequently the script will run (look for "batch_time").
- The router admin password is stored in clear text in the source of the script. Make sure to protect it (chmod 700 recommended)
- By default new found IPs are added to the blacklist every 30 seconds. Be aware that when the address-group on the router gets updated any logged in user will be asked to refresh their screen which may be disruptive in case you are in the middle of something.
- Please report any other issue you may find...
Thanks to @Benoriusju for the original script that I have customized to work with EdgeOS api calls. Thanks to @Matthew1471 for documenting the EdgeOS API https://github.com/Matthew1471/EdgeOS-API