Skip to content

Latest commit

Β 

History

6 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ”’ Server Intrusion Detection & Alert System

⚑ One-Line Install

curl -sSL https://raw.githubusercontent.com/Nabwinsaud/server-auditing/main/setup.sh | sudo DISCORD_WEBHOOK="https://discord.com/api/webhooks/YOUR/WEBHOOK" bash

That's it! Check your Discord for a confirmation alert.


Threat Model

What Attackers Typically Do

  1. Persistence: Install backdoors via cron, systemd, rc.local, SSH keys
  2. Evasion: Delete logs, modify timestamps, use nohup/screen/tmux
  3. Privilege Escalation: Exploit SUID binaries, kernel vulnerabilities
  4. Lateral Movement: Scan internal networks, steal credentials
  5. Defense Evasion: Kill monitoring processes, modify audit rules

How This Design Defeats Each Tactic

Attack Tactic Defense Mechanism
Cron tampering Systemd services + watchdog + auditd alerts
Log deletion Auditd immutable mode + real-time Discord alerts
Process hiding Multiple independent process monitors
Rootkit installation rkhunter + AIDE file integrity
Monitoring kill Watchdog auto-restart + tamper detection
Audit rule changes Audit rules monitor themselves

Architecture Diagram

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                         DETECTION LAYER                                  β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚   AIDE       β”‚   auditd     β”‚  fail2ban    β”‚  rkhunter    β”‚  netwatch   β”‚
β”‚  (files)     β”‚  (syscalls)  β”‚  (brute)     β”‚  (rootkits)  β”‚  (network)  β”‚
β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜
       β”‚              β”‚              β”‚              β”‚              β”‚
       β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                     β”‚
                           β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                           β”‚   ALERT ROUTER    β”‚
                           β”‚  (rate-limited)   β”‚
                           β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                     β”‚
                           β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                           β”‚  DISCORD WEBHOOK  β”‚
                           β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                      SELF-PROTECTION LAYER                              β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  Watchdog Service   β”‚  Immutable Files    β”‚  Audit Self-Monitoring      β”‚
β”‚  (auto-restart)     β”‚  (chattr +i)        β”‚  (detect rule changes)      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                      EXECUTION MECHANISMS                               β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  systemd services   β”‚  systemd timers     β”‚  inotifywait (realtime)     β”‚
β”‚  (primary)          β”‚  (backup)           β”‚  (file events)              β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Quick Start

Option 1: One-Line Install (Recommended)

curl -sSL https://raw.githubusercontent.com/Nabwinsaud/server-auditing/main/setup.sh | sudo DISCORD_WEBHOOK="YOUR_WEBHOOK_URL" bash

Option 2: Clone and Install

git clone https://github.com/Nabwinsaud/server-auditing.git
cd server-auditing
export DISCORD_WEBHOOK="https://discord.com/api/webhooks/YOUR_WEBHOOK"
sudo -E ./install.sh
sudo ./verify.sh

Uninstall

curl -sSL https://raw.githubusercontent.com/Nabwinsaud/server-auditing/main/uninstall.sh | sudo bash

Directory Structure

/opt/server-monitor/
β”œβ”€β”€ bin/
β”‚   β”œβ”€β”€ alert.sh              # Discord alert sender
β”‚   β”œβ”€β”€ file-monitor.sh       # AIDE wrapper
β”‚   β”œβ”€β”€ process-monitor.sh    # Process watcher
β”‚   β”œβ”€β”€ network-monitor.sh    # Connection monitor
β”‚   β”œβ”€β”€ ssh-monitor.sh        # SSH login monitor
β”‚   └── watchdog.sh           # Self-protection
β”œβ”€β”€ etc/
β”‚   β”œβ”€β”€ config.env            # Configuration
β”‚   └── whitelist.conf        # Known-good processes
β”œβ”€β”€ var/
β”‚   β”œβ”€β”€ state/                # State files
β”‚   └── cache/                # Rate limiting cache
└── logs/
    └── monitor.log           # Local backup log

Components

  1. Detection Scripts - Monitor files, processes, network, SSH
  2. Alert System - Rate-limited Discord notifications
  3. Systemd Services - Persistent, auto-restarting monitors
  4. Watchdog - Monitors the monitors
  5. Tamper Protection - Immutable files, audit rules

Files in This Repository

  • install.sh - One-command installer
  • scripts/ - All monitoring scripts
  • systemd/ - Service unit files
  • audit/ - Audit rules
  • verify.sh - Verification commands

πŸ“– How to Use

Check Service Status

# See all monitoring services
sudo systemctl status server-*

# Check specific service
sudo systemctl status server-ssh-monitor
sudo systemctl status server-process-monitor

View Logs

# Real-time logs from SSH monitor
sudo journalctl -u server-ssh-monitor -f

# All monitor logs
sudo journalctl -u server-process-monitor -u server-ssh-monitor -u server-network-monitor -f

# Local log file
sudo tail -f /opt/server-monitor/logs/monitor.log

Send Test Alert

sudo /opt/server-monitor/bin/alert.sh test "πŸ§ͺ Test Alert" "This is a test message" medium

Manage Services

# Restart a service
sudo systemctl restart server-ssh-monitor

# Stop all monitoring temporarily
sudo systemctl stop server-process-monitor server-ssh-monitor server-network-monitor

# Start all monitoring
sudo systemctl start server-process-monitor server-ssh-monitor server-network-monitor

Update Configuration

# Edit config (need to remove immutable flag first)
sudo chattr -i /opt/server-monitor/etc/config.env
sudo nano /opt/server-monitor/etc/config.env
sudo chattr +i /opt/server-monitor/etc/config.env

# Restart services to apply
sudo systemctl restart server-ssh-monitor server-process-monitor

Add/Update Single Config Value

# Remove protection
sudo chattr -i /opt/server-monitor/etc/config.env

# Add timezone
echo 'TIMEZONE="Asia/Kathmandu"' | sudo tee -a /opt/server-monitor/etc/config.env

# Or change rate limit
sudo sed -i 's/RATE_LIMIT_SECONDS=300/RATE_LIMIT_SECONDS=600/' /opt/server-monitor/etc/config.env

# Restore protection
sudo chattr +i /opt/server-monitor/etc/config.env

View Current Config

sudo cat /opt/server-monitor/etc/config.env

πŸ—‘οΈ How to Uninstall

Option 1: One-Line Uninstall

curl -sSL https://raw.githubusercontent.com/Nabwinsaud/server-auditing/main/uninstall.sh | sudo bash

Option 2: Manual Uninstall

# Stop all services
sudo systemctl stop server-process-monitor server-network-monitor server-ssh-monitor server-watchdog server-file-monitor.timer server-rootkit-scan.timer

# Remove immutable flag from protected files
sudo chattr -i /opt/server-monitor/bin/*.sh
sudo chattr -i /opt/server-monitor/etc/config.env
sudo chattr -i /etc/systemd/system/server-*.service
sudo chattr -i /etc/systemd/system/server-*.timer

# Disable services
sudo systemctl disable server-process-monitor server-network-monitor server-ssh-monitor server-watchdog server-file-monitor.timer server-rootkit-scan.timer

# Remove files
sudo rm -rf /opt/server-monitor
sudo rm -f /etc/systemd/system/server-*.service
sudo rm -f /etc/systemd/system/server-*.timer
sudo rm -f /etc/audit/rules.d/server-monitor.rules

# Reload systemd
sudo systemctl daemon-reload
sudo systemctl restart auditd

πŸ”” Alert Types

Alert Severity Trigger
User Login 🟒 LOW Normal SSH login
Root Login 🟠 HIGH Root SSH login
Failed Login Attempts 🟠 HIGH >5 failed SSH attempts
Brute Force Attack πŸ”΄ CRITICAL >20 failed attempts
Invalid Username 🟑 MEDIUM >3 invalid user attempts
Sensitive Command 🟠 HIGH sudo passwd/shadow/etc
Root Access 🟠 HIGH su to root
Service Down πŸ”΄ CRITICAL nginx/mysql/docker/etc stopped
Service Recovered 🟒 LOW Service came back online
Monitor Down πŸ”΄ CRITICAL Monitoring service stopped
File Change 🟠 HIGH System file modified
Disk Critical 🟠 HIGH Disk usage >90%

πŸ€– Auto-Detected Services

The watchdog automatically detects and monitors these services if installed:

Category Services
Web Servers nginx, apache2, httpd, caddy
Databases mysql, mariadb, postgresql, mongod
Cache redis, redis-server
Containers docker
Security auditd, fail2ban
SSH sshd

No configuration needed! If nginx is installed and enabled, it will be monitored automatically.


βš™οΈ Configuration Options

Edit /opt/server-monitor/etc/config.env:

Option Default Description
DISCORD_WEBHOOK - Your Discord webhook URL
HOSTNAME auto Server name shown in alerts
TIMEZONE UTC Your local timezone for timestamps
RATE_LIMIT_SECONDS 300 Min seconds between same alert type

Timezone Examples

TIMEZONE="Asia/Kathmandu"    # Nepal
TIMEZONE="Asia/Kolkata"      # India
TIMEZONE="America/New_York"  # US East
TIMEZONE="Europe/London"     # UK
TIMEZONE="Asia/Tokyo"        # Japan

Set Timezone During Install

curl -sSL https://raw.githubusercontent.com/Nabwinsaud/server-auditing/main/setup.sh | \
  sudo DISCORD_WEBHOOK="YOUR_WEBHOOK" TIMEZONE="Asia/Kathmandu" bash

πŸ”’ Security Notes

  • Webhook URL: Keep it secret! Anyone with it can send fake alerts
  • Config file: Protected with chmod 600 - only root can read
  • Scripts: Protected with chattr +i - can't be modified without removing flag
  • No incoming ports: Only makes outbound HTTPS requests to Discord

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages