diff --git a/Cargo.lock b/Cargo.lock index cc2cc54..635a498 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -81,7 +81,7 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "blockfast" -version = "0.1.1" +version = "0.2.0" dependencies = [ "anyhow", "clap", diff --git a/Cargo.toml b/Cargo.toml index 7938c4c..5ae063d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "blockfast" -version = "0.1.1" +version = "0.2.0" authors = ["Pierre Dubouilh "] edition = "2018" diff --git a/README.md b/README.md index 762f924..5e872cc 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,78 @@ # blockfast -block ssh and http scanners fast +Block internets scanners fast 🍶 -features: - - generic SSH log parser - - generic Common Log Format parser (apache logs, caddy logs, etc...) - - sane defaults - - fast ip ban with `ipset` - - libmusl static release builds, no libc dependency - - lighter alternative to fail2ban +Features: + - SSH log parser + - Common Log Format parser (apache logs, etc...) + - JSON log parser (caddy logs) + - Generic log parser + - Sane defaults + - Fast ip ban with `ipset` + - Static release builds, no libc dependency + - Lighter alternative to fail2ban -Todo: more granular CLI args to filter HTTP Status codes (e.g. 5 401 leads to a block, but 30 404 before a block) ? +## example +```txt +$ ./blockfast -s=/var/log/auth.log -j=/caddy/logs +1737927469 - starting with sshd parsing at "/tmp/sshdtest" +1737927469 - starting with json parsing at "/tmp/jsontest" +1737927469 - jail setup, allowance 5, time 21600s +1737927477 - sshd logged offence for 9.124.36.195 +1737927478 - sshd logged offence for 9.124.36.195 +1737927479 - sshd logged offence for 9.124.36.195 +1737927479 - sshd logged offence for 9.124.36.195 +1737927480 - sshd logged offence for 9.124.36.195 +1737927480 - sshd jailtime for 9.124.36.195 +``` + +## build +see `Makefile` + +## usage +```txt +$ target/debug/blockfast +Blockfast - block internets scanners fast 🍶 +Author: pierre dubouilh + +Blockfast reads logs from various sources and blocks the offending IPs using iptables and ipset. +It supports logs from sshd, Common-Log-Format (Apache, etc..), JSON (Caddy) and a generic logs parser. + +Example: + # block invalid sshd attempts & invalid http statuses from caddy + ./blockfast -s=/var/log/auth.log -j=/caddy/logs + + # generic log parser example with a log text to flag, and a regex to parse the offending IP. + ./blockfast --generic-logpath=/tmp/generictest --generic-positive='Failed password' --generic-ip='from ([0-9a-fA-F:.]+) port' + +Usage: blockfast [OPTIONS] +Usage: blockfast [OPTIONS] + +Options: + --jailtime + jail time (seconds) [default: 21600] + --allowance + how many offences allowed (max 255) [default: 5] + -v, --verbose + log all offences + -s, --sshd-logpath + path of sshd logfile + -c, --clf-logpath + path of Common-Log-Format logfile (Apache, etc..) + -j, --json-logpath + path of JSON HTTP logfile (Caddy) + --generic-logpath + generic parser log file path + --generic-ip + generic parser ip regex + --generic-positive + generic parser positive - if a logline contains this, it is considered bad, the rest is good + --generic-negative + generic parser negative - if a logline contains this, it is considered good, the rest is bad + --valid-http-statuses + valid http statuses (for CLF and JSON logs) [default: 200 101] + -h, --help + Print help + -V, --version + Print version +``` diff --git a/src/utils.rs b/src/utils.rs index 0a7a960..7729e7b 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -64,7 +64,7 @@ Example: # block invalid sshd attempts & invalid http statuses from caddy ./blockfast -s=/var/log/auth.log -j=/caddy/logs - # generic log parser example with a positive text, and a regex to parse the offending IP. + # generic log parser example with a log text to flag, and a regex to parse the offending IP. ./blockfast --generic-logpath=/tmp/generictest --generic-positive='Failed password' --generic-ip='from ([0-9a-fA-F:.]+) port'", verbatim_doc_comment, )]