67 Commits

Author SHA1 Message Date
Auke Kok a2a6d8e9ac v7. v7 2018-01-10 10:29:53 -08:00
Auke Kok c5569176d2 Allow whitelist patterns.
This allows for some simple form of netmask type patterning
which will work for /8, /16 and /24 subnets to be whitelisted
for ipv4, and for any multiple of /32 subnets for ipv6.
2018-01-08 16:06:26 -08:00
Auke Kok bf81c259b0 Add 'nocreate' option to bypass all rule/set creation.
This may help in situations where external tools are used to maintain
iptables or ipset setups and we should not disturb them by creating
rules.
2018-01-05 12:57:45 -08:00
Auke Kok ff2a47756f v6 v6 2017-12-14 14:52:35 -08:00
Auke Kok b18f636489 Assure blocked IP's expire before they can be detected again.
Otherwise, in rare conditions, an IP address may appear just
before it would expire, which would cause the IP to not be
blocked again.
2017-12-14 14:31:41 -08:00
Auke Kok 6e0251d3dc Update manual pages to indicate the various recent changes. 2017-12-14 10:00:44 -08:00
Auke Kok 60a90adbc5 Instant throttling of confirmed abuse.
Automatically `block` certain clients based on severity of the
produced error messages. These clients are for sure doing something
bad, and we don't want to let them try this more times before dropping
their packets.

The block is issued immediately, but it only lasts a short time.
Most likely, additional messages will come in after that cause a
longer ban anyway.

This also forces overwriting of ipset entries without warning, which
helps to keep the ipset list in sync without further statekeeping.

The pattern list has been expanded with the instant_block integer
value, which indicates that if the pattern matches, the IP should be
dropped for how many seconds.
2017-12-14 09:57:52 -08:00
Auke Kok 1f43bcbf12 Debug code for pruning. 2017-12-13 15:02:13 -08:00
Auke Kok 8da71a2184 Remove multiple block spam.
Some minor cleanups in here, and 2 extra rules. This now prevents
multiple messages coming in and causing 2 block commands to be
issued.
2017-12-12 15:26:30 -08:00
Auke Kok 38b09c3b07 Re-add debug printout of state, move various prints to debug build.
Compiling with -DDEBUG=1 will now create an extra verbose version
that can be used to debug the pattern matching in more detail.

The non-debug build is now less verbose, as a result.

Send a USR1 signal to the process to make it dump the current
state table.
2017-12-11 16:47:59 -08:00
Auke Kok 20f4c970de Add 6 more relevant SSHD patterns.
Some of these come with a higher weight, as they're very obvious
points of abuse/probing, like attempting to use old protocols or not
being able to use modern key types.
2017-12-11 16:47:32 -08:00
Auke Kok 32c20f190f Allow multiple patterns.
We do not want to rely solely on one pattern for detecting login
attempts. This change creates a simple static list with patterns that
have a weight. If the pattern matches, the weight is added to the IP
score total. If the score total exceeds the max, the IP is blocked.

Previously we blocked on count=3, now we block when score=1.0.
The weight from the standard invalid user login is now dropped to
0.4 to have the same effect.

The `threshold` parameter is now therefore obsolete, and if found in
the config file, it will be ignored.
2017-12-11 14:04:14 -08:00
Gwenn Gueguen e3e4388654 Replace path_iptables with ipt_path in sample tallow.conf 2017-05-22 13:46:27 -07:00
Auke Kok 8a05303802 v5 v5 2017-05-17 17:18:01 -07:00
Auke Kok e296f501c7 Use pcre to match logs, and find IP addresses.
This is a much more reliable method to extract the IP address
from the log entries, and allows us to consolidate 2 matches into
a single operation.

Once matched, we extract the IP substring and pass it to `find()`
as usual. We can add more regexes later if that is useful.
2017-05-16 15:55:18 -07:00
Auke Kok 379f74a071 Fix Travis.
Check in the man pages so we don't need to run `ronn` on CI.
2017-05-11 11:24:20 -07:00
Auke Kok 9042a01eab v4 v4 2017-05-11 08:56:56 -07:00
Auke Kok 2225ee029d Revert "also catch port probers that try ssl level evils"
This reverts commit dc8f37e41f.

This message can print on a normal and legitimate user when they
disconnect, and therefore would be a false positive. We should
100% never get close to blocking legitimate users, ever.
2017-05-10 21:49:16 -07:00
Auke Kok dee23b8275 Lazy initialization.
At start, only initialize the journal, but wait until we actually
need to block anything before initializing ipset and iptables.
2017-05-10 21:14:07 -07:00
Auke Kok 34bd8d55bd Remove SIGUSR1 handler - dumping lists is obsolete with ipset. 2017-05-10 21:07:18 -07:00
Auke Kok 2a33768293 Don't break our LL on block.
We will prune regularly anyway, so this is entirely unneeded.
2017-05-10 20:59:36 -07:00
Auke Kok ea958fd2b5 v3 v3 2017-05-08 08:49:15 -07:00
Auke Kok 4547892d56 Attempt to build against old systemd versions as well.
In case libsystemd isn't found, try libsystemd-journal as well.
2017-05-07 21:09:58 -07:00
Auke Kok c661a20e33 Revert removal of prune().
We can't just delete an entry only when it is blocked, this
would forever leave all entries lingering in the list until
they hit the limit, and it would likely consume lots of memory.

Instead, we'll prune only based on timestamp values. This removes
old entries automatically regularly, but leaves new hits that
haven't hit the expiry time. If IPs get blocked, they're not
removed, but the expiry time will remove them. This will
assure that hosts that try in large intervals actually get
blocked again right away.
2017-05-07 20:36:32 -07:00
Arjan van de Ven 9f37520c72 ip can be NULL (output of strtok) 2017-05-07 20:23:37 -07:00
Arjan van de Ven dc8f37e41f also catch port probers that try ssl level evils 2017-05-07 20:23:31 -07:00
Auke Kok d590c8f67f v2: ipset release. v2 2017-05-07 00:17:48 -07:00
Auke Kok ec2b5cbfc0 Make ipset init clean and working. 2017-05-07 00:05:25 -07:00
Auke Kok cb41c16e93 Minor ipset fixes. 2017-05-06 23:38:28 -07:00
Auke Kok 40568eb4cd Man pages and checked out folders. 2017-05-06 23:14:06 -07:00
Auke Kok 992927798d Convert to ipset.
Create `tallow` and `tallow6` ipsets, hook up to iptables
and create a single rule in the INPUT chain of the filter
table.

The ipsets created have `expire` timeouts set by default
which removes the need to do pruning, so we can erase entries
immediately from our LL when blocking.
2017-05-06 23:12:22 -07:00
Arjan van de Ven fba8921952 add to .gitignore 2017-05-06 22:36:55 -07:00
Arjan van de Ven 73e9cd7011 add travis support 2017-05-06 22:36:55 -07:00
Arjan van de Ven a4d9d9688e add -W 2017-05-06 22:35:49 -07:00
Arjan van de Ven 35eeabb146 avoid a large .data section by just initializing the big structures at run time 2017-05-06 22:35:49 -07:00
Auke Kok 08d45d39fd Convert man page to ronn generated .md input format. 2017-05-06 22:12:30 -07:00
Auke Kok cd65e1c48a v1 v1 2017-05-06 21:46:27 -07:00
Auke Kok 47d7bf1d1f Link against libsystemd instead.
With more recent versions, these symbols are now
moved.
2017-03-25 13:00:03 -07:00
Auke Kok b81b440495 Err, usec timeout value.
This was causing a very tight loop if the journal rotates.
2015-06-21 15:26:56 -07:00
Auke Kok afe1a2663b Fixes: Make tailing the journal way more robust.
This is a far more robust way of tailing the journal that seems
to work on 2 different journal versions. It's a bit more involved
and journal slowness may cause it to take several seconds to iterate
through the journal after a rotate or after startup, but it's far
more reliable than the old method.

I've also pushed all the output to stderr which makes the blocked/
unblocked messages end up in the journal itself.
2015-06-21 13:18:04 -07:00
Auke Kok dee31e8fc2 Clean up array properly. 2015-06-20 20:24:11 -07:00
Auke Kok 54adb2f684 Print a msg if ipv6 is disabled. 2015-03-21 14:56:09 -07:00
Auke Kok cbcb62c206 Add ipv6 support.
Can be disabled (ipv6=0 in conf).

Also ignores new chain errors since we assume those will fail.
2015-03-21 14:27:10 -07:00
Auke Kok c6343259ce Overdue fixes I've had running for a while. 2015-03-20 20:42:01 -07:00
Auke Kok 94f4e191fb Fix journal forward issue, add dump option.
Adds a signal handler to gracefully shut down in case of exit
signal, while doubling as a way to quickly dump the current
state table.

A journal tailing error workaround thanks to ssh-blocker.
2013-08-20 10:44:41 -07:00
Auke Kok 4f59e7feca Migrate normal output to stdout.
Only error/warnings now go to stderr, the rest of the normal
start/block/unblock messages now all go to stdout.
2012-11-05 11:10:33 -08:00
Auke Kok e3914f7db0 Bugfix: bad option placement.
I messed this up implementing the configfile stuff and
never saw the mistakes I made here. This tests ok.
2012-11-04 23:28:05 -08:00
Auke Kok dcbd79e477 Fix IP address check. Fix unblock calling iptables when not needed. 2012-11-02 18:00:56 -07:00
Auke Kok f1a8249cea Install config example in /usr/share/doc. 2012-10-31 14:45:07 -07:00
Auke Kok d60d4f1a33 Make sure we don't pass garbage to system(). 2012-10-31 14:18:37 -07:00