Lekensteyn / ssh-blocker

Block IP addresses based on SSH logs
11 stars 7 forks source link

ssh-blocker

NAME ssh-blocker - read a log pipe and block attacks with ipset

OVERVIEW ssh-blocker is a program that reads log lines from a named pipe (FIFO) and tries to find IP addresses in lines containing login attempts. On a successful login attempt, the address is added to a whitelist. When a certain number of invalid login attempts is reached within a pre-defined period, the address will be added to a blacklist.

The whitelist and blacklists are stored with ipset[1], a relevant iptables
rule must exist that take care of it. Using ipset, the blocked address will
expire after some time.

REQUIREMENTS This program needs the following libraries:

CONFIGURATION The file ssh-blocker.h can be changed to adapt to your configuration. Some interesting defaults are shown below:

USAGE There are some ways to set-up this program:

SECURITY This program was originally created to reduce syslog spam. It can also be used as a replacement for Fail2ban or DenyHosts if you do not need fancy features. As with any program that monitors syslog, note that syslog can usually be written by everyone. That means that rogue local users can insert bogus entries into the syslog. It is as trivial as:

    logger -p auth.notice -t sshd[1337] '...'
Therefore, use this program with care. Add known good IP addresses to the
whitelist and do not let untrusted users to your system.

When the program is run as root, it tightens its capabilities to
CAP_NET_ADMIN (for ipset) and CAP_SETUID+CAP_SETGID (for changing users).
Then it changes to the user as specified in the command line arguments. When
the user has succesfully changed its real, effective and saved uid/gid, it
will further tighten its privileges to include CAP_NET_ADMIN only. Note that
the log file is created and/ or opened before changing users.

TODO

AUTHORS Written by Peter Wu.

REPORTING BUGS Report bugs to Peter Wu peter@lekensteyn.nl.

COPYRIGHT Copyright (c) 2013-2016 Peter Wu. License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html. This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.