• Rust 94.1%
  • Jsonnet 3.6%
  • Python 1.8%
  • Makefile 0.3%
  • Shell 0.1%
Find a file
2024-12-06 11:16:03 +01:00
config Move new rust codebase to root dir 2024-10-24 12:00:00 +02:00
debian new release 2024-06-08 12:00:00 +02:00
export-go-db Packaging for Rust 2024-10-24 12:00:00 +02:00
go.old Move old go codebase to go.old 2024-10-24 12:00:00 +02:00
helpers_c test infrastructure, new conf's state_directory, less deps 2024-11-13 12:00:00 +01:00
import-rust-db fix previous-previous commit for import-rust-db 2024-10-31 12:00:00 +01:00
logo order 🧹 2023-04-26 17:11:03 +02:00
src simplify handle_child 2024-12-06 11:16:03 +01:00
tests Fix #110: don't show error message on shutdown 2024-11-19 14:54:53 +00:00
.ccls test infrastructure, new conf's state_directory, less deps 2024-11-13 12:00:00 +01:00
.gitignore test infrastructure, new conf's state_directory, less deps 2024-11-13 12:00:00 +01:00
.gitlab-ci.yml 📦👷 — Build better deb package in release.sh + test building in CI 2024-04-03 16:16:53 +02:00
ARCHITECTURE.md Restructure code and document it in ARCHITECTURE.md 2024-10-26 12:00:00 +02:00
build.rs Fix spurious rebuild of reaction due to invalid file path 2024-11-14 19:22:32 +01:00
Cargo.lock Ask nicely the stream process to exit on shutdown 2024-11-22 16:52:25 +01:00
Cargo.toml Ask nicely the stream process to exit on shutdown 2024-11-22 16:52:25 +01:00
LICENSE Add AGPL LICENSE 2023-04-11 11:03:50 +00:00
Makefile Packaging for Rust 2024-10-24 12:00:00 +02:00
README.md Restructure code and document it in ARCHITECTURE.md 2024-10-26 12:00:00 +02:00
release.py release script update 2024-10-24 12:00:00 +02:00

reaction

A daemon that scans program outputs for repeated patterns, and takes action.

A common usage is to scan ssh and webserver logs, and to ban hosts that cause multiple authentication errors.

🚧 This program hasn't received external audit. however, it already works well on my servers 🚧

Current project status

reaction just reached v2.0.0-rc1 version, which is a complete rust rewrite of reaction. It's in feature parity with the Go version, and breaking changes should be small.

See https://reaction.ppom.me/migrate-to-v2.html

Rationale

I was using the honorable fail2ban since quite a long time, but i was a bit frustrated by its cpu consumption and all its heavy default configuration.

In my view, a security-oriented program should be simple to configure and an always-running daemon should be implemented in a faster language.

reaction does not have all the features of the honorable fail2ban, but it's ~10x faster and has more manageable configuration.

📽️ quick french name explanation 😉

🇬🇧 in-depth blog article / 🇫🇷 french version

Configuration

YAML and JSONnet (more powerful) are supported. both are extensions of JSON, so JSON is transitively supported.

  • See reaction.yml or reaction.jsonnet for a fully explained reference
  • See server.jsonnet for a real-world configuration
  • See reaction.example.service for a systemd service file
  • This minimal example shows what's needed to prevent brute force attacks on an ssh server (please take a look at more complete references before starting 🆙):
/etc/reaction.yml
patterns:
  ip:
    regex: '(([0-9]{1,3}\.){3}[0-9]{1,3})|([0-9a-fA-F:]{2,90})'

start:
  - [ 'ip46tables', '-w', '-N', 'reaction' ]
  - [ 'ip46tables', '-w', '-A', 'reaction', '-j', 'ACCEPT' ]
  - [ 'ip46tables', '-w', '-I', 'reaction', '1', '-s', '127.0.0.1', '-j', 'ACCEPT' ]
  - [ 'ip46tables', '-w', '-I', 'INPUT', '-p', 'all', '-j', 'reaction' ]

stop:
  - [ 'ip46tables', '-w', '-D', 'INPUT', '-p', 'all', '-j', 'reaction' ]
  - [ 'ip46tables', '-w', '-F', 'reaction' ]
  - [ 'ip46tables', '-w', '-X', 'reaction' ]

streams:
  ssh:
    cmd: [ 'journalctl', '-fu', 'sshd.service' ]
    filters:
      failedlogin:
        regex:
          - 'authentication failure;.*rhost=<ip>'
        retry: 3
        retryperiod: '6h'
        actions:
          ban:
            cmd: [ 'ip46tables', '-w', '-I', 'reaction', '1', '-s', '<ip>', '-j', 'block' ]
          unban:
            cmd: [ 'ip46tables', '-w', '-D', 'reaction', '1', '-s', '<ip>', '-j', 'block' ]
            after: '48h'
/etc/reaction.jsonnet
local iptables(args) = [ 'ip46tables', '-w' ] + args;
local banFor(time) = {
  ban: {
    cmd: iptables(['-A', 'reaction', '-s', '<ip>', '-j', 'reaction-log-refuse']),
  },
  unban: {
    after: time,
    cmd: iptables(['-D', 'reaction', '-s', '<ip>', '-j', 'reaction-log-refuse']),
  },
};
{
  patterns: {
    ip: {
      regex: @'(?:(?:[ 0-9 ]{1,3}\.){3}[0-9]{1,3})|(?:[0-9a-fA-F:]{2,90})',
    },
  },
  start: [
    iptables([ '-N', 'reaction' ]),
    iptables([ '-A', 'reaction', '-j', 'ACCEPT' ]),
    iptables([ '-I', 'reaction', '1', '-s', '127.0.0.1', '-j', 'ACCEPT' ]),
    iptables([ '-I', 'INPUT', '-p', 'all', '-j', 'reaction' ]),
  ],
  stop: [
    iptables([ '-D', 'INPUT', '-p', 'all', '-j', 'reaction' ]),
    iptables([ '-F', 'reaction' ]),
    iptables([ '-X', 'reaction' ]),
  ],
  streams: {
    ssh: {
      cmd: [ 'journalctl', '-fu', 'sshd.service' ],
      filters: {
        failedlogin: {
          regex: [ @'authentication failure;.*rhost=<ip>' ],
          retry: 3,
          retryperiod: '6h',
          actions: banFor('48h'),
        },
      },
    },
  },
}

Database

The embedded database is stored in the working directory. If you don't know where to start reaction, /var/lib/reaction should be a sane choice.

CLI

  • reaction start runs the server
  • reaction show show pending actions (ie. bans)
  • reaction flush permits to run pending actions (ie. clear bans)
  • reaction test-regex permits to test regexes
  • reaction help for full usage.

ip46tables

ip46tables is a minimal c program present in its own subdirectory with only standard posix dependencies.

It permits to configure iptables and ip6tables at the same time. It will execute iptables when detecting ipv4, ip6tables when detecting ipv6 and both if no ip address is present on the command line.

Wiki

You'll find more ressources, service configurations, etc. on the wiki!

We recommend that you read the Good Practices chapters before starting.

Installation

Packaging status

Binaries

Executables are provided here, for a standard x86-64 linux machine.

A standard place to put such executables is /usr/local/bin/.

Provided binaries in the previous section are compiled this way:

$ docker run -it --rm -e HOME=/tmp/ -v $(pwd):/tmp/code -w /tmp/code -u $(id -u) rust make clean reaction.deb
$ make signatures

Signature verification

Starting at v1.0.3, all binaries are signed with public key RWSpLTPfbvllNqRrXUgZzM7mFjLUA7PQioAItz80ag8uU4A2wtoT2DzX. You can check their authenticity with minisign:

minisign -VP RWSpLTPfbvllNqRrXUgZzM7mFjLUA7PQioAItz80ag8uU4A2wtoT2DzX -m nft46
minisign -VP RWSpLTPfbvllNqRrXUgZzM7mFjLUA7PQioAItz80ag8uU4A2wtoT2DzX -m ip46tables
minisign -VP RWSpLTPfbvllNqRrXUgZzM7mFjLUA7PQioAItz80ag8uU4A2wtoT2DzX -m reaction
# or
minisign -VP RWSpLTPfbvllNqRrXUgZzM7mFjLUA7PQioAItz80ag8uU4A2wtoT2DzX -m reaction.deb

Debian

The releases also contain a reaction*.deb file, which packages reaction & ip46tables. You can install it using sudo apt install ./reaction*.deb. You'll have to create a configuration at /etc/reaction.jsonnet.

If you want to use another configuration format (YAML or JSON), you can override systemd's ExecStart command in /etc/systemd/system/reaction.service like this:

[Service]
# First an empty directive to reset the default one
ExecStart=
# Then put what you want
ExecStart=/usr/bin/reaction start -c /etc/reaction.yml

NixOS

not yet upstreamed module

OpenBSD

wiki

Compilation

You'll need a recent rust toolchain for reaction and a c compiler for ip46tables.

$ make

Don't hesitate to take a look at the Makefile to understand what's happening!

Installation

To install the binaries

make install

To install the systemd file as well

make install_systemd

Development

Contributions are welcome. For any substantial feature, please file an issue first, to be assured that we agree on the feature, and to avoid unnecessary work.

I recommend reading ARCHITECTURE.md first. This is a tour of the codebase, which should save time to potential contributors.

Funding

This is a free time project, so I'm not working on schedule. However, if you're willing to fund the project, I can priorise and plan paid work. This includes features, documentation and specific JSONnet configurations.