autoblock-1.1.0 is not a library.
AutoBlock
Automatically block SSH brute-force attackers by monitoring /var/log/auth.log and adding iptables DROP rules for offending IPs.
How It Works
- Watches
/var/log/auth.logfor new entries (tail -f style via inotify) - Parses
Invalid userlines to extract the source IP - Tracks attempts per IP in a ring buffer
- When an IP reaches the threshold (default: 3 attempts), it is blocked:
iptables -I INPUT 1 -s <IP> -j DROPnetfilter-persistent save
- Already blocked IPs are loaded from iptables at startup to avoid duplicates
Build
Usage
The application requires root privileges since it modifies iptables rules.
Options
| Flag | Default | Description |
|---|---|---|
--log-path |
/var/log/auth.log |
Path to the auth log file |
--threshold |
3 |
Number of invalid attempts before blocking |
--buffer-size |
10000 |
Ring buffer capacity |
# Custom threshold and buffer size
# Watch a different log file
Logging
Control log verbosity via the RUST_LOG environment variable:
Tests
Project Structure
src/
main.rs Entry point, CLI parsing, main loop
parser.rs Regex parser for "Invalid user" log lines
ring_buffer.rs Generic ring buffer backed by VecDeque
blocker.rs iptables blocking + netfilter-persistent save
watcher.rs Log file watching via notify/inotify