https://github.com/mohhudib/hybrid-rsentry
Real-time ransomware detection and auto-containment system for Linux endpoints β entropy analysis, canary files, process lineage scoring, and AI threat classification.
https://github.com/mohhudib/hybrid-rsentry
ai celery cybersecurity docker endpoint-security fastapi kali-linux linux postgresql python ransomware-detection react real-time redis threat-detection
Last synced: about 7 hours ago
JSON representation
Real-time ransomware detection and auto-containment system for Linux endpoints β entropy analysis, canary files, process lineage scoring, and AI threat classification.
- Host: GitHub
- URL: https://github.com/mohhudib/hybrid-rsentry
- Owner: Mohhudib
- License: mit
- Created: 2026-04-06T22:40:51.000Z (2 months ago)
- Default Branch: main
- Last Pushed: 2026-06-06T01:11:05.000Z (2 days ago)
- Last Synced: 2026-06-06T02:22:19.722Z (2 days ago)
- Topics: ai, celery, cybersecurity, docker, endpoint-security, fastapi, kali-linux, linux, postgresql, python, ransomware-detection, react, real-time, redis, threat-detection
- Language: JavaScript
- Homepage: https://github.com/Mohhudib/hybrid-rsentry/wiki
- Size: 2.82 MB
- Stars: 6
- Watchers: 2
- Forks: 1
- Open Issues: 20
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Security: SECURITY.md
Awesome Lists containing this project
README
# π‘οΈ Hybrid R-Sentry
**A real-time ransomware detection and auto-containment system for Linux endpoints**
[](https://python.org)
[](https://reactjs.org)
[](https://vitejs.dev)
[](https://fastapi.tiangolo.com)
[](https://docs.celeryq.dev)
[](https://redis.io)
[](https://postgresql.org)
[](#testing)
[](#testing)
[](CHANGELOG.md)
[](LICENSE)
**[Landing Page](https://mohhudib.github.io/hybrid-rsentry/)**
---
## Overview
Hybrid R-Sentry is a **hybrid ransomware detection system** that combines multiple detection layers with an AI-powered analyst to identify, classify, and automatically contain ransomware threats on Linux endpoints β in real time.
Unlike signature-based solutions, Hybrid R-Sentry uses **behavioral analysis** to catch unknown and zero-day ransomware variants before they can cause significant damage.
---
## Features
### Detection Engine
- **Canary Files** β Strategically placed bait files with 4 naming prefixes (`AAA_`, `aaa_`, `ZZZ_`, `zzz_`) placed at 30 per-directory locations for 4Γ coverage; any touch or rename triggers CRITICAL alert; in eBPF mode, renames are blocked at the kernel level (`-EPERM`) via BPF LSM before any data is overwritten
- **Shannon Entropy Analysis** β Monitors file entropy deltas to detect encryption activity in progress; memory-capped at 5 000 files with LRU eviction and 65 KB partial reads to prevent OOM on large watch paths
- **Process Lineage Scoring** β Scores suspicious process ancestry chains including parent names, spawn location, and binary SHA-256 verified against 416 K dpkg hashes (MATCH / MISMATCH / UNKNOWN verdicts)
- **Ransomware Extension Detection** β Renames to `.enc`, `.locked`, `.wcry`, `.crypted` etc. trigger CRITICAL (if the source was a document) or HIGH alert
- **Markov Chain Repositioning** β Adaptively moves canary files to predicted high-risk directories based on observed filesystem access patterns; blocks repositioning into `.git/`, `/proc/`, `/sys/`, `/dev/`, `/run/`
- **eBPF Kernel Sensor** (`agent/monitor_ebpf.py`) β 5-syscall behavioral detection (`openat`, `vfs_write`, `unlink`, `rename`, `execve`); per-process `proc_profile` BPF map with behavioral scoring (0β100); **BPF LSM canary blocking** (`-EPERM` in nanoseconds, requires `lsm=bpf`); velocity burst, family profiling (LockBit 5.0 / Akira / ESXi); BCC 0.35, kernel β₯ 6.19
- **Combined Threat Scoring** β Fuses entropy and lineage signals into a weighted threat score for accurate severity classification
- **False Positive Suppression** β Comprehensive whitelist system (`agent/exceptions.py`) covering browsers, package managers, system paths, archive formats, media files, and smart temp-dir filtering to eliminate noise on live Linux systems
### Auto-Containment Pipeline
When a CRITICAL threat is detected, the system automatically executes a tree-aware multi-stage containment sequence across the entire process tree:
1. **SIGSTOP** β Immediately freezes the malicious process and all children (two-sweep enumeration catches race conditions)
2. **Evidence Capture** β Collects process metadata, open files, and network connections (up to 48 files per process tree)
3. **iptables DROP** β Blocks all outbound network traffic from the process owner UID
4. **SIGKILL** β Terminates the process tree permanently
### AI Threat Analyst
- Multi-provider fallback chain: **Cerebras** (fastest, optional) β **NVIDIA API** (key 1) β **NVIDIA/Groq** (key 2)
- Auto-detects Groq keys by `gsk_` prefix; backward compatible with `NVIDIA_API_KEY` / `NVIDIA_API_KEY_ALERTS`
- Publishes a PENDING state immediately, then updates with the real result
- AI results cached in Redis for 24 hours for forensic export
- Auto-acknowledges alerts classified as Benign or LOW risk
- System health check: analyzes recent activity patterns and reports overall endpoint status
### SIEM Dashboard
- Kibana-style 3-column layout: **FacetRail** filter panel, center (MetricsStrip + stacked histogram + sortable AlertsTable), **DetailFlyout** on alert click
- **TopBar** horizontal navigation with 6 tabs + live alert count badge; **StatusBar** at the bottom with agents/EPS/WS status/cluster
- **D3 v7 force-directed filesystem graph** β Obsidian-style node graph inside DetailFlyout and EventDetailModal; zoom, drag, tooltip, selected path pulled to center
- Clickable TacticalResponseLog events β EventDetailModal with Summary/Entity/MITRE/Filesystem/Raw tabs
- Live WebSocket feed β MetricsStrip, histogram, and table refresh instantly on new events
- Host risk panel with radial risk score gauge and alert breakdown by severity
- AI Analyst page with pending spinners, error cards, and 4-minute analysis persistence
- **PDF Forensic Export** β date filter, severity filter, host-aware Hosts Overview table, per-alert drill-down with AI analysis; SHA-256 integrity footer on every page
---
## Architecture
```
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Linux Endpoint β
β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β Sensor: inotify (watchdog) OR eBPF (kernel 6.19+) β β
β β monitor.py monitor_ebpf.py β β
β β (watchdog, userspace) (TRACEPOINT_PROBE, β β
β β velocity burst, β β
β β family profiling) β β
β βββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββ β
β β β
β βββββββββββββββββ β βββββββββββββββββ ββββββββββββ β
β β Entropy βββββ΄βββΆβ Lineage β βExtension β β
β β Engine β β Scorer β βDetection β β
β βββββββββββββββββ βββββββββββββββββ ββββββββββββ β
β β β β β
β βΌ βΌ βΌ β
β ββββββββββββββββ βββββββββββββββββββββββββββββββ β
β β Markov β β Auto-Containment β β
β β Repositioner β β SIGSTOPβevidenceβiptables β β
β ββββββββββββββββ β βSIGKILL (tree-aware) β β
β βββββββββββββββββββββββββββββββ β
βββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββββββββ
β HTTP POST /api/events
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β FastAPI Backend β
β β
β ββββββββββββββββ ββββββββββββββββ ββββββββββββββββββ β
β β Events β β Alerts β β Hosts β β
β β Router β β Router β β Router β β
β ββββββββ¬ββββββββ ββββββββββββββββ ββββββββββββββββββ β
β β β
β βΌ β
β ββββββββββββββββ ββββββββββββββββ ββββββββββββββββββ β
β β Celery β β PostgreSQL β β Redis β β
β β Workers β β (Events, β β (Broker + β β
β β (AI, ACK, β β Alerts, β β 3 WS chans) β β
β β WS push) β β Hosts) β β β β
β ββββββββββββββββ ββββββββββββββββ ββββββββββ¬ββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββΌββββββββββββ
β WebSocket
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β React 19 SIEM Dashboard (Vite 5) β
β TopBar + 6 tabs β FacetRail β Histogram β D3 force graph β
β Alert flyout β AI analysis β Host risk β PDF export β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
```
---
## Tech Stack
| Layer | Technology |
|---|---|
| Agent (inotify) | Python 3.13, watchdog 6, psutil, networkx, scipy, numpy |
| Agent (eBPF) | Python 3.13, BCC 0.35 (`python3-bpfcc`), Linux kernel β₯ 6.19 |
| Backend | FastAPI, SQLAlchemy (async), PostgreSQL, asyncpg |
| Task Queue | Celery, Redis |
| AI | Cerebras / NVIDIA / Groq (OpenAI-compatible, multi-provider fallback) |
| Frontend | React 19, Vite 5, Tailwind CSS 3, **D3 v7**, Recharts, jsPDF, IBM Plex Sans/Mono, Font Awesome 6.5.1 |
| Infrastructure | Docker Compose (PostgreSQL + Redis), Node.js 22 |
---
## Getting Started
### Prerequisites
- Python 3.13
- Node.js 22
- Docker & Docker Compose
- **For eBPF sensor (default):** Linux kernel β₯ 6.19 + `sudo apt install python3-bpfcc bpfcc-tools -y`
- If kernel is older or BCC unavailable, set `SENSOR_BACKEND=inotify` in `.env`
### Quick Start (recommended)
**Step 1 β Clone and run first-time setup**
```bash
git clone https://github.com/Mohhudib/hybrid-rsentry.git
cd hybrid-rsentry
# Install BCC for eBPF sensor (skip if using inotify fallback)
sudo apt install python3-bpfcc bpfcc-tools -y
bash setup.sh
```
`setup.sh` installs system packages (requires sudo), creates the Python venv, installs all Python and Node dependencies, and copies `.env.example` to `.env`.
**Step 2 β Configure your environment**
```bash
# Edit .env β you must set these before running:
# POSTGRES_PASSWORD β choose a strong password
# DATABASE_URL β update to match POSTGRES_PASSWORD
# NVIDIA_API_KEY β your AI provider API key
# NVIDIA_API_KEY_ALERTS
# WATCH_PATH β a directory OUTSIDE the project folder
nano .env
```
**Step 3 β Start everything**
```bash
bash start.sh
```
`start.sh` starts all five processes in the correct order and logs to `/tmp/rsentry-*.log`. Press `Ctrl+C` to stop all services cleanly.
Open [http://localhost:3000](http://localhost:3000) to access the dashboard.
---
### Subsequent Runs
Once the venv and node_modules are in place, just:
```bash
bash start.sh
```
---
### Manual Start (for development or debugging)
Each process runs in its own terminal.
**Terminal 1 β Infrastructure**
```bash
docker compose up -d
```
**Terminal 2 β Backend**
```bash
set -a && source .env && set +a
source venv/bin/activate
uvicorn backend.main:app --reload
```
**Terminal 3 β Celery workers**
```bash
set -a && source .env && set +a
source venv/bin/activate
PYTHONPATH=. celery -A backend.workers.tasks:celery_app worker --loglevel=info
```
**Terminal 4 β Agent** (requires root to set iptables rules)
```bash
set -a && source .env && set +a
sudo -E venv/bin/python -m agent.monitor
```
> `sudo -E` is mandatory β it preserves `WATCH_PATH` and the AI keys through the privilege boundary. Without it the agent watches the wrong path.
**Terminal 5 β Frontend**
```bash
cd frontend
npm start
```
Open [http://localhost:3000](http://localhost:3000) to access the dashboard.
> **Important:** `WATCH_PATH` must point to a directory **outside** the project folder. Placing canary files inside the repo corrupts `.git/refs`. The agent will refuse to start if this rule is violated.
---
## Environment Variables
| Variable | Required | Description |
|---|---|---|
| `POSTGRES_PASSWORD` | Yes | PostgreSQL password β used by Docker Compose and `DATABASE_URL` |
| `DATABASE_URL` | Yes | PostgreSQL connection string (asyncpg) β no default, backend fails immediately if unset |
| `REDIS_URL` | Yes | Redis connection string |
| `SECRET_KEY` | Yes | Secret key (32+ chars for production) |
| `HOST_ID` | Yes | Identifier for this endpoint (e.g. `kali-endpoint-01`) |
| `BACKEND_URL` | Yes | Backend URL the agent posts events to |
| `WATCH_PATH` | Yes | Directory to monitor β **must be outside the project folder** |
| `CANARY_COUNT` | No | Number of canary files to place (default: `30`, across 4 prefixes) |
| `NVIDIA_API_KEY` | Yes* | API key for live event AI analysis (also readable as `AI_API_KEY`) |
| `NVIDIA_API_KEY_ALERTS` | Yes* | API key for on-demand alert AI analysis (also readable as `AI_API_KEY_ALERTS`) |
| `AI_API_KEY_CEREBRAS` | No | Cerebras API key β if set, becomes the primary AI provider (fastest); NVIDIA/Groq used as fallback |
*Groq keys are also accepted β auto-detected by the `gsk_` prefix.
---
## Alert Severity Levels
| Severity | Trigger | Auto-Action |
|---|---|---|
| CRITICAL | Canary file touched or deleted; ransomware extension rename on a document; combined score β₯ 70 | Immediate tree-aware auto-containment |
| HIGH | Combined score 40β69 (entropy + lineage); new file with ransomware extension | AI analysis + alert record |
| MEDIUM | Entropy spike alone | AI analysis + alert record |
| LOW | Heartbeat / system events | Logged only |
---
## Project Structure
```
hybrid-rsentry/
βββ agent/ # Endpoint monitoring agent
β βββ monitor.py # Main watchdog orchestrator (inotify backend)
β βββ monitor_ebpf.py # eBPF kernel sensor (TRACEPOINT_PROBE, BCC 0.35)
β βββ graph.py # Filesystem graph + BFS canary placement
β βββ entropy.py # Shannon entropy engine (memory-capped)
β βββ lineage.py # Process lineage scorer + dpkg hash verification
β βββ adaptive.py # Markov chain repositioner + _is_safe_target() guard
β βββ containment.py # Tree-aware auto-containment pipeline
β βββ exceptions.py # Whitelist rules + smart /tmp filter
β βββ client.py # Backend HTTP client
βββ backend/
β βββ main.py # FastAPI app entry point
β βββ models/ # SQLAlchemy ORM + Pydantic schemas
β βββ routers/ # events, alerts, hosts, ws
β βββ services/ # AI analyst (multi-provider fallback chain)
β βββ workers/ # Celery tasks
βββ frontend/
β βββ index.html # Vite root; IBM Plex fonts + Font Awesome 6.5.1
β βββ vite.config.js # Vite: React plugin + proxy + process.env shim
β βββ src/
β βββ App.jsx # Root β TopBar + StatusBar layout; WS + AI state
β βββ index.css # CSS variable design system + SIEM utility classes
β βββ pages/ # Overview, AlertsPage, HostsPage, FilesystemPage,
β β # AIAnalystPage, ReportsPage
β βββ components/ # TopBar, StatusBar, FacetRail, MetricsStrip,
β β # AlertsHistogram, AlertsTable, DetailFlyout,
β β # EventDetailModal, FileSystemGraph, FileSystemTree,
β β # TacticalResponseLog, AIAnalystPanel, ...
β βββ hooks/ # useWebSocket
β βββ api/ # Axios client
βββ landing/ # 3D cinematic landing page (React Three Fiber + Framer Motion)
βββ tests/
β βββ unit/agent/ # 71 tests β entropy, lineage, adaptive, severity (89% coverage)
β βββ test_lockbit.py # LockBit 5.0 4-metric evaluation β all targets met
βββ simulations/ # Attack simulation scripts
β βββ sim_common.py # Shared engine (profile, corpus, run_attack, backup/restore)
β βββ sim_lockbit.py # LockBit 5.0 two-pass simulation
β βββ sim_akira.py # Akira intermittent encryption simulation
β βββ sim_qilin.py # Qilin percent-encryption simulation
β βββ sim_depth.py / sim_dfs.py / sim_random.py # Earlier traversal simulations
βββ docs/
β βββ CODE_WALKTHROUGH.md # Full file-by-file code walkthrough
βββ .github/workflows/ # CI lint + Docker build + landing page deploy
βββ start.sh # One-command startup script
βββ test_event.sh # One-command pipeline test (sends CANARY_TOUCHED event)
βββ docker-compose.yml
```
---
## Testing
```bash
pip install -r requirements-dev.txt
pytest
```
71 tests covering `entropy.py`, `lineage.py`, `adaptive.py`, severity classification, and simulation safety. All tests are isolated (no live services required).
---
## Detection Flow
```
File system event
β
βΌ
Is it a canary file? ββYESβββΆ CRITICAL alert β Auto-containment
β
NO
βΌ
Ransomware extension rename? ββYESβββΆ CRITICAL (doc) or HIGH alert
β
NO
βΌ
Is path/process whitelisted? ββYESβββΆ Skip (suppress false positive)
β
NO
βΌ
Entropy delta > threshold?
β
βββYESβββΆ Lineage score >= 40? ββYESβββΆ COMBINED_ALERT (CRITICAL/HIGH)
β βββNOββββΆ ENTROPY_SPIKE (MEDIUM)
β
βββNOββββΆ Lineage score >= 40? ββYESβββΆ PROCESS_ANOMALY (CRITICAL/HIGH)
βββNOββββΆ Skip (low signal)
β
βΌ
AI analyst classifies threat β publishes result to dashboard
```
---
## Security
A security audit of this repository was conducted in May 2026. The following issues were identified and fixed:
| Fix | Detail |
|---|---|
| Removed `python-jose` dependency | Had CVE-2024-33664 and CVE-2024-33663; was never imported |
| Removed hardcoded DB password fallback | `database.py` now raises a clear `RuntimeError` if `DATABASE_URL` is unset |
| Parameterised Docker Compose credentials | `docker-compose.yml` reads `${POSTGRES_PASSWORD}` from the environment |
| Canary file git corruption prevented | `.gitignore` excludes `AAA_*.txt`; agent validates `WATCH_PATH` at startup; Markov repositioner blocks `.git/` targets |
**Dependabot:** The frontend has been migrated from Create React App to Vite, which resolved all 26 npm security alerts that were embedded in the `react-scripts` build toolchain.
For reporting vulnerabilities, see [SECURITY.md](SECURITY.md).
---
## Roadmap & Issue Tracking
Development is tracked in the **[R-Sentry Roadmap GitHub Project](https://github.com/users/Mohhudib/projects/1)**.
| Milestone | Scope | Target |
|---|---|---|
| [v2.1.0](https://github.com/Mohhudib/hybrid-rsentry/milestone/1) | CI hardening, Dependabot security fixes, eBPF Kali validation | 2026-06-15 |
| [v2.2.0](https://github.com/Mohhudib/hybrid-rsentry/milestone/2) | Integration tests, Exception Management UI, Alembic migrations | 2026-07-31 |
See the [Roadmap wiki page](https://github.com/Mohhudib/hybrid-rsentry/wiki/Roadmap) for the full list of completed and planned items.
---
## Contributing
See [CONTRIBUTING.md](CONTRIBUTING.md) for the full guide. In brief:
1. Fork the repository
2. Create a feature branch off `main` (`git checkout -b feature/your-feature`)
3. Commit your changes using the `feat:` / `fix:` / `docs:` prefix style
4. Push and open a Pull Request against **`main`**
PRs that introduce new false positives on a live Kali system will not be merged.
---
## License
This project is licensed under the MIT License β see [LICENSE](LICENSE).
---
Built as a cybersecurity capstone project β combining behavioral detection, adaptive defense, and AI-assisted threat analysis.