How mohamedsaifi0/ids_bash works
Project Type and Purpose
• This is a shell‐based Intrusion Detection System (IDS) written entirely in Bash.
• Purpose: continuously monitor system and application logs for suspicious patterns, generate alerts, optionally block malicious IPs, and provide an interactive administration interface.
File Structure
• Top‐level “ids.sh”: the orchestration and command‐line interface (start/stop/status/menu).
• “config.sh”: centralized configuration (log paths, alert toggles, block duration, firewall back end).
• “functions/” directory: four modules by responsibility
• monitor.sh – reads and parses log files
• alert.sh – dispatches notifications (email, wall, log)
• firewall.sh – manages UFW/iptables rules for blocking/unblocking
• process.sh – handles lifecycle commands (start, stop, clean, summary)
• Other artifacts (logs/, reports/) are specified in README but may be generated at runtime.
Extract Key Architectural Insights from the README
• Three monitoring modes: forked processes, thread simulation, subshells—this implies a multi‐process modular design.
• External dependencies: whiptail (UI), mailutils (email), iptables/UFW (firewall).
• Core workflow: detect → alert → respond (auto‐block/whitelist) → log/report.
Main Components
a. Core Orchestrator (ids.sh + process.sh)
b. Configuration Layer (config.sh)
c. Detection Engine (monitor.sh)
d. Alerting Service (alert.sh)
e. Response Service (firewall.sh)
f. Interactive Admin UI (whiptail/dialog via ids.sh menu)
g. Persistent Storage (log files in /var/log/ids, reports/)
h. External Services
• Mail server (SMTP)
• System firewall (iptables/UFW)
• System console (wall)
Relationships and Data Flows
• On “start,” Core Orchestrator loads Configuration, spawns Detection Engine in chosen mode.
• Detection Engine tails multiple system logs → when pattern matches → emits an event object to Alerting Service.
• Alerting Service decides on notification channels (email, wall, log file) and writes to Reports storage.
• Response Service listens to events tagged “auto‐block,” consults whitelist/blacklist, then interacts with firewall subsystem.
• Interactive UI calls Core Orchestrator / Process Service to query status, block/unblock IPs, or perform maintenance (clean, summary).
• All modules read from config.sh; errors and statuses propagate back to orchestrator and UI.
Architectural Patterns and Design Principles
• Modular decomposition: each security concern (monitor, alert, block, process) is a separate function script.
• Single responsibility and separation of concerns.
• Pluggable concurrency modes: fork, simulated threads, subshell.
• Event‐driven workflow: detection generates events, events fan out to alert & response.
• Configuration‐driven behavior.
Detail
• Which logs are watched by the Monitor (auth.log, syslog, etc.).
• Whitelist/blacklist as data store consulted by Firewall module.
• Timing (real‐time monitoring) or maintenance tasks under Process module.