Monday, June 5, 2017

Centralize or Distribute IPset Blacklists: vallumd

1:00 PM Leave a Reply
Centralize or Distribute IPset Blacklists: vallumd
Centralize or Distribute IPset Blacklists

      If you maintain a server on the Internet, it’s very likely you encountered one or more brute force attacks. Not a problem, just install fail2ban. Done. But if you’re running multiple servers, each of them running their fail2ban instance, they’ll all have different IP addresses in the ban list. Wouldn’t it be nice to have a shared ban list across all your fail2ban instances? Or in case all your machines are behind a router or firewall you control yourself, wouldn’t it be nice to drop malicious traffic at the edge of your network? That’s exactly what vallumd helps to achieve.  The name vallumd comes from the Latin word “vallum”, which means wall. And that’s what vallumd does: build a wall to protect your digital empire.





How it works

     Vallumd connects to an MQTT broker, reads messages containing IP addresses, and adds or deletes those IP addresses to or from an ipset. Simple as that.

    This means it is not useful on its own, but it makes vallumd very flexible. You can decide for yourself what kind of iptables rule you want to reference the ipset in. Integrating it with fail2ban is as simple as creating a new action that uses mosquitto_pub to send a message to your MQTT broker. And since there are MQTT libraries out there for most common languages, it shouldn’t be too hard to integrate with your favorite IDS, IPS or Honeypot.





Debian/Ubuntu

You can generate a DEB package with cpack:

sudo apt-get -y install build-essential cmake libipset-dev libmosquitto-dev libssl-dev pkg-config

git clone https://github.com/stintel/vallumd.git
cd vallumd
cmake .
cpack -G DEB

sudo dpkg -i build/*.deb


Manual install

Manual installation is very easy. Requirements:

cmake
libipset
libmosquitto
libssl
Instructions:

git clone https://github.com/stintel/vallumd.git
cd vallumd
cmake .
make
make install


Usage

    To use vallumd, you need an MQTT broker, like Mosquitto. Depending on your setup, you can run it on the same host that runs vallumd, but that’s no requirement. The next thing you need is an IPset. To give you full control over the type of IPset and its options, vallumd will not create the IPset itself. You can choose between these IPset types:

bitmap:ip
bitmap:net
hash:ip
hash:net
IPset creation example: ipset create blacklist hash:ip timeout 3600

Now you can start vallumd. The following command line options exist:

 -h: MQTT host to connect to
 -p: MQTT port to connect to (1883)
 -u: MQTT username
 -P: MQTT password
 -t: MQTT topic and IPset name
 -V: print version number and exit
 -c: path to CA file
 -T: use TLS
The host and topic options are required, the others are optional (default value). It is possible to specify multiple topics.

Starting vallumd: vallumd -h 192.168.0.1 -t blacklist

This will listen for messages on the MQTT broker at 192.168.0.1, in the blacklist topic, and when a message is received, the IP address in the message will be added to or remove from the IPset named blacklist. So now we have everything in place to start adding IPs to the blacklist. All we have to do is configure our IDS, IPS or Honeypot to send malicious IP addresses to our MQTT broker.  For fail2ban, this could be done with the Mosquitto client mosquitto_pub. Create a new action in /etc/fail2ban/action.d/vallumd.conf:

[Definition]
actionban = mosquitto_pub -h 192.168.0.1 -q 2 -t blacklist/add -m <ip>
actionunban = mosquitto_pub -h 192.168.0.1 -q 2 -t blacklist/del -m <ip>
And configure your fail2ban jails to use the vallumd action.

Download