|
| 1 | +# Security Monitoring |
| 2 | + |
| 3 | +Unified security event monitoring with smart deduplication and aggregated Telegram alerts. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- ✅ **Multi-Tool Monitoring** - fail2ban, SSH, UFW, auditd, AIDE, rkhunter in one script |
| 8 | +- ✅ **Smart Deduplication** - Alert only on new events (state-based) |
| 9 | +- ✅ **Aggregated Alerts** - Single Telegram message per run |
| 10 | +- ✅ **Configurable Thresholds** - Customize when to alert |
| 11 | +- ✅ **15-Minute Interval** - Real-time security awareness |
| 12 | +- ✅ **Production-Ready** - Built on bash-production-toolkit |
| 13 | + |
| 14 | +## Quick Start |
| 15 | + |
| 16 | +```bash |
| 17 | +# 1. Install bash-production-toolkit (if not already installed) |
| 18 | +git clone https://github.com/fidpa/bash-production-toolkit.git |
| 19 | +cd bash-production-toolkit |
| 20 | +sudo make install |
| 21 | + |
| 22 | +# 2. Deploy security-log-monitor script |
| 23 | +sudo cp security-monitoring/scripts/security-log-monitor.sh /usr/local/bin/ |
| 24 | +sudo chmod +x /usr/local/bin/security-log-monitor.sh |
| 25 | + |
| 26 | +# 3. Configure Telegram credentials |
| 27 | +sudo nano /etc/default/security-log-monitor |
| 28 | +# Add: TELEGRAM_BOT_TOKEN="your-token" |
| 29 | +# TELEGRAM_CHAT_ID="your-chat-id" |
| 30 | + |
| 31 | +# 4. Deploy systemd units |
| 32 | +sudo cp security-monitoring/systemd/security-log-monitor.* /etc/systemd/system/ |
| 33 | +sudo systemctl daemon-reload |
| 34 | + |
| 35 | +# 5. Enable timer |
| 36 | +sudo systemctl enable --now security-log-monitor.timer |
| 37 | + |
| 38 | +# 6. Verify |
| 39 | +sudo systemctl status security-log-monitor.timer |
| 40 | +``` |
| 41 | + |
| 42 | +**Full guide**: See [docs/SETUP.md](docs/SETUP.md) |
| 43 | + |
| 44 | +## Documentation |
| 45 | + |
| 46 | +| Document | Description | |
| 47 | +|----------|-------------| |
| 48 | +| [SETUP.md](docs/SETUP.md) | Installation, configuration, systemd setup | |
| 49 | +| [CONFIGURATION.md](docs/CONFIGURATION.md) | Environment variables, thresholds, state management | |
| 50 | +| [TROUBLESHOOTING.md](docs/TROUBLESHOOTING.md) | Common issues and debugging | |
| 51 | + |
| 52 | +## Requirements |
| 53 | + |
| 54 | +- Ubuntu 22.04+ / Debian 11+ |
| 55 | +- systemd (for timer automation) |
| 56 | +- Root/sudo access |
| 57 | +- bash-production-toolkit (logging, alerts, secure file utils) |
| 58 | +- Optional: ausearch (auditd), aide, rkhunter |
| 59 | + |
| 60 | +## Use Cases |
| 61 | + |
| 62 | +- ✅ **Security Operations Center** - Centralized security event monitoring |
| 63 | +- ✅ **Compliance** - Track security events for audit trails |
| 64 | +- ✅ **DevOps** - Real-time security awareness for development servers |
| 65 | +- ✅ **Production Servers** - Automated intrusion detection and alerting |
| 66 | +- ✅ **Multi-Server Environments** - Deploy to multiple hosts with consistent monitoring |
| 67 | + |
| 68 | +## Monitored Components |
| 69 | + |
| 70 | +| Component | Events Monitored | Alert Trigger | |
| 71 | +|-----------|------------------|---------------| |
| 72 | +| **fail2ban** | Ban/Unban events | Any new ban | |
| 73 | +| **SSH** | Failed login attempts | >5 failures + new IPs | |
| 74 | +| **UFW** | Blocked external IPs | >10 blocks from same IP | |
| 75 | +| **auditd** | Security policy violations | Any new denied event | |
| 76 | +| **AIDE** | File integrity changes | Exit code ≥1 | |
| 77 | +| **rkhunter** | Rootkit detection | Any warnings | |
| 78 | + |
| 79 | +## How It Works |
| 80 | + |
| 81 | +1. **Check Phase**: Script queries journalctl for events in last 15 minutes |
| 82 | +2. **Deduplication**: Compare current events with saved state |
| 83 | +3. **Aggregation**: Collect all new events into single message |
| 84 | +4. **Alerting**: Send Telegram notification with rate limiting (30min) |
| 85 | +5. **State Persistence**: Save current state for next run |
| 86 | + |
| 87 | +**Why Deduplication?** Prevents alert fatigue by only notifying on new events, not recurring ones. |
| 88 | + |
| 89 | +--- |
| 90 | + |
| 91 | +**See also**: |
| 92 | +- [bash-production-toolkit](https://github.com/fidpa/bash-production-toolkit) - Required dependency |
| 93 | +- [ubuntu-server-security](https://github.com/fidpa/ubuntu-server-security) - Full hardening suite |
0 commit comments