Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

27 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

โฌก NetSentry

Real-Time Network Intrusion Detection System โ€” a production-grade Deep Packet Inspection pipeline in C++, a live SOC dashboard in React, and a Streamlit DPI analyzer โ€” all deployed.

Dashboard Analyzer API

C++ Node React Docker License

NetSentry live dashboard โ€” attacks fly across a global threat map in real time

๐ŸŒ Live Demo

Service URL What it does
Dashboard netsentry-two.vercel.app Live SOC โ€” world threat map, real-time alert feed, attack charts
DPI Analyzer netsentry-dpi-adi.streamlit.app Paste any payload โ†’ classified with entropy analysis
API Health netsentry-api.onrender.com/api/health WebSocket + REST API status

The Render free tier sleeps after 15 minutes of inactivity. First request after sleep takes ~30 seconds to wake up โ€” subsequent requests are instant.


โšก What It Does

NetSentry inspects network packets at wire speed, classifies them with signature matching + entropy analysis, and streams every threat to a global threat dashboard in real time.

  • Aho-Corasick multi-pattern automaton matches thousands of Snort signatures in a single O(n) pass over packet payloads
  • Shannon entropy profiling over 128-byte sliding windows detects encrypted C2 beaconing that evades signature-based IDS
  • MATLAB wavedec(H, 4, "db4") wavelet decomposition reveals periodic high-entropy bursts invisible to FFT โ€” the core research contribution
  • Bloom filter IP reputation pre-filter rejects 99.9% of benign IPs in ~5 ns before the full rule engine runs
  • Lock-free SPSC ring buffer transfers packets from capture to dispatcher with zero locks, zero allocation
  • WebSocket fan-out streams alerts to all connected dashboard clients in <5 ms

๐Ÿ—๏ธ System Design

NetSentry system design โ€” end-to-end data flow from network capture through the C++ DPI engine, Node.js API, to the React dashboard and Streamlit analyzer

Text version of the architecture (click to expand)
 Network / NIC
      โ”‚
      โ–ผ  AF_XDP / libpcap โ€” zero-copy capture
 โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
 โ”‚  C++ DPI Engine                             โ”‚
 โ”‚  โ”œโ”€ Lock-free SPSC ring buffer              โ”‚
 โ”‚  โ”œโ”€ 5-tuple dispatcher โ†’ N worker threads  โ”‚
 โ”‚  โ”œโ”€ Aho-Corasick pattern matcher            โ”‚
 โ”‚  โ”œโ”€ Trie protocol parser                    โ”‚
 โ”‚  โ”œโ”€ Shannon entropy scorer                  โ”‚
 โ”‚  โ”œโ”€ Bloom filter IP reputation              โ”‚
 โ”‚  โ””โ”€ Rule engine โ†’ {BLOCK, ALERT, LOG}       โ”‚
 โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                โ”‚ JSON lines โ†’ stdout / Unix socket
                โ–ผ
 โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
 โ”‚  Node.js API ยท Port 3001                    โ”‚
 โ”‚  โ”œโ”€ WebSocket server (ws.Server)            โ”‚
 โ”‚  โ”œโ”€ REST API  GET /api/alerts /stats        โ”‚
 โ”‚  โ”œโ”€ POST /api/classify (Streamlit demo)     โ”‚
 โ”‚  โ””โ”€ In-memory alert store (ring, 1000 max)  โ”‚
 โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
        โ”‚ WebSocket             โ”‚ REST
        โ–ผ                       โ–ผ
 โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
 โ”‚  React Dashboardโ”‚   โ”‚  Streamlit Analyzer  โ”‚
 โ”‚  โ”œโ”€ Leaflet map โ”‚   โ”‚  โ”œโ”€ Payload input    โ”‚
 โ”‚  โ”œโ”€ Alert feed  โ”‚   โ”‚  โ”œโ”€ Entropy gauge    โ”‚
 โ”‚  โ””โ”€ Recharts    โ”‚   โ”‚  โ””โ”€ Byte freq chart  โ”‚
 โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿงฎ Data Structures & Algorithms

Structure Used in Complexity Why
Aho-Corasick automaton DPI core โ€” payload pattern match O(n+m) build, O(n) search Match thousands of Snort rules in a single pass over payload
Deterministic Trie L4โ€“L7 protocol parser O(k) per lookup Prefix-based protocol ID, no backtracking
Cuckoo hash (per-thread) Flow state table (5-tuple key) O(1) avg lookup Zero cross-thread locking โ€” each worker owns its table
Bloom filter IP reputation pre-filter O(k) ยท 4 MB Rejects 99.9% of benign IPs in ~5 ns
Lock-free SPSC ring Capture โ†’ dispatcher queue O(1) wait-free Zero allocation, zero CAS on the hot path
Michael-Scott MPSC queue Worker threads โ†’ alert relay O(1) lock-free Multiple producers, single consumer, guaranteed progress

๐Ÿ”ฌ Research โ€” Encrypted C2 Detection via Entropy + Wavelets

Traditional signature-based DPI (Snort, Suricata) is blind to encrypted command-and-control traffic. NetSentry adds a novel detection layer:

  1. Shannon entropy H(X) = โˆ’ฮฃ p(x) logโ‚‚(p(x)) computed over 128-byte payload windows per flow
  2. The resulting entropy time-series is passed to MATLAB wavedec(H, 4, "db4") โ€” a 4-level Daubechies-4 Discrete Wavelet Transform
  3. Level-1 and level-2 detail coefficients reveal periodic high-entropy spikes โ€” the signature of C2 beaconing
  4. The discriminator is timing regularity, not entropy alone โ€” benign TLS is also high-entropy, but only a beacon calls home on a regular cadence (low coefficient of variation)

Method: A flow is flagged as C2 only when it is both encrypted (mean entropy โ‰ฅ 6.5 bits) and periodic (inter-arrival regularity โ‰ฅ 0.55). This catches Cobalt Strike / Sliver-style beacons that bypass signature-based tools.

๐Ÿ“Š See BENCHMARKS.md for detection accuracy, latency percentiles, and the full Snort comparison.

๐Ÿ”ฌ The full reproducible experiment harness lives in research/ โ€” run python research/selftest.py to validate the detector, then point it at real Stratosphere IPS captures.


๐Ÿš€ Quick Start (local, 3 commands)

git clone https://github.com/gitadi2/netsentry.git
cd netsentry
chmod +x start.sh && ./start.sh

Open http://localhost:5173 โ€” dashboard is live with the built-in simulator.

Three-terminal setup (Windows)

# Terminal 1 โ€” API
cd netsentry\api
npm install
npm start

# Terminal 2 โ€” Dashboard
cd netsentry\frontend
npm install
npm run dev

# Terminal 3 โ€” Streamlit Analyzer
cd netsentry\streamlit
pip install -r requirements.txt
python -m streamlit run app.py

๐Ÿญ Build the C++ Engine

cd cpp
mkdir build && cd build

# macOS / dev mode (no libpcap)
cmake .. -DCMAKE_BUILD_TYPE=Release
make -j4
./netsentry --sim

# Linux โ€” live packet capture (requires libpcap + root)
sudo apt install libpcap-dev
cmake .. -DCMAKE_BUILD_TYPE=Release -DWITH_PCAP=ON
make -j$(nproc)
sudo ./netsentry --iface eth0

Once built, the Node API auto-detects the binary and pipes its JSON output instead of the JS simulator:

[NetSentry] C++ engine connected at /path/to/cpp/build/netsentry

๐Ÿงช Tests

The C++ core is covered by a 31-test GoogleTest suite spanning the Aho-Corasick matcher, Bloom filter, entropy function, and the classify rule engine.

cd cpp
cmake -B build -DBUILD_TESTS=ON
cmake --build build
./build/netsentry_tests        # Windows: .\build\netsentry_tests.exe

GoogleTest is fetched automatically via CMake FetchContent โ€” no manual install needed.


๐Ÿ“Š Benchmarks

# Start the API locally, then in another terminal:
pip install aiohttp numpy matplotlib requests

python benchmark/detection_test.py    # detection accuracy vs Snort
python benchmark/load_test.py          # latency / throughput percentiles
python benchmark/plot_latency.py       # render the latency chart

Full results, methodology, and the Snort comparison are in BENCHMARKS.md.


๐Ÿณ Docker Deploy (one command)

docker compose up --build
  • Dashboard โ†’ http://localhost:5173
  • API โ†’ http://localhost:3001
  • Streamlit โ†’ http://localhost:8501

๐ŸŒ Cloud Deploy โ€” Full Recipe

1 ยท API to Render

  • New โ†’ Web Service โ†’ connect GitHub repo
  • Root Directory: api
  • Build: npm install
  • Start: node server.js
  • Instance: Free

2 ยท Dashboard to Vercel

  • New Project โ†’ import repo
  • Root Directory: frontend
  • Framework Preset: Vite (auto-detected)
  • Environment variables:
    • VITE_API_URL=https://netsentry-api.onrender.com
    • VITE_WS_URL=wss://netsentry-api.onrender.com

3 ยท Streamlit Analyzer to Streamlit Cloud

  • New app โ†’ repo โ†’ streamlit/app.py
  • Secrets:
    NETSENTRY_API = "https://netsentry-api.onrender.com"
    NETSENTRY_DASH = "https://netsentry-two.vercel.app"

Every push to main auto-redeploys all three services.


๐Ÿ“‚ Project Structure

netsentry/
โ”œโ”€โ”€ .github/
โ”‚   โ””โ”€โ”€ workflows/
โ”‚       โ””โ”€โ”€ ci.yml           โ† GitHub Actions โ€” build, lint, health check
โ”œโ”€โ”€ cpp/
โ”‚   โ”œโ”€โ”€ src/
โ”‚   โ”‚   โ”œโ”€โ”€ netsentry.h      โ† AhoCorasick ยท BloomFilter ยท entropy ยท FlowTable
โ”‚   โ”‚   โ””โ”€โ”€ main.cpp         โ† simulator + libpcap capture + JSON stdout
โ”‚   โ”œโ”€โ”€ tests/
โ”‚   โ”‚   โ””โ”€โ”€ test_netsentry.cpp  โ† GoogleTest suite (31 tests)
โ”‚   โ””โ”€โ”€ CMakeLists.txt       โ† engine build + BUILD_TESTS / COVERAGE options
โ”œโ”€โ”€ api/
โ”‚   โ”œโ”€โ”€ server.js            โ† Express + ws + REST + built-in JS simulator
โ”‚   โ””โ”€โ”€ package.json
โ”œโ”€โ”€ frontend/
โ”‚   โ”œโ”€โ”€ src/
โ”‚   โ”‚   โ”œโ”€โ”€ App.jsx          โ† WebSocket client, state, layout
โ”‚   โ”‚   โ”œโ”€โ”€ index.css        โ† pure black SOC theme + Leaflet overrides
โ”‚   โ”‚   โ””โ”€โ”€ components/
โ”‚   โ”‚       โ”œโ”€โ”€ ThreatMap.jsx  โ† Leaflet map ยท radar sweep ยท animated arcs
โ”‚   โ”‚       โ”œโ”€โ”€ AlertFeed.jsx  โ† scrollable alert list ยท country leaderboard
โ”‚   โ”‚       โ”œโ”€โ”€ StatsBar.jsx   โ† header ยท live counters
โ”‚   โ”‚       โ””โ”€โ”€ Charts.jsx     โ† alerts/s timeline ยท threat donut
โ”‚   โ””โ”€โ”€ vite.config.js
โ”œโ”€โ”€ streamlit/
โ”‚   โ”œโ”€โ”€ app.py               โ† DPI analyzer ยท entropy gauge ยท byte freq chart
โ”‚   โ””โ”€โ”€ requirements.txt
โ”œโ”€โ”€ benchmark/
โ”‚   โ”œโ”€โ”€ detection_test.py    โ† accuracy harness vs Snort baseline
โ”‚   โ”œโ”€โ”€ load_test.py         โ† latency / throughput harness
โ”‚   โ””โ”€โ”€ plot_latency.py      โ† renders the latency percentile chart
โ”œโ”€โ”€ research/
โ”‚   โ”œโ”€โ”€ c2_detect.py         โ† entropy + db4 wavelet + IAT-regularity classifier
โ”‚   โ”œโ”€โ”€ selftest.py          โ† synthetic labeled flows โ†’ validates the detector
โ”‚   โ”œโ”€โ”€ run_pcap.py          โ† runs detection on real pcaps (Stratosphere IPS)
โ”‚   โ”œโ”€โ”€ plot_c2.py           โ† renders the beacon-vs-benign figure
โ”‚   โ”œโ”€โ”€ requirements.txt     โ† scapy ยท numpy ยท scipy ยท matplotlib ยท PyWavelets
โ”‚   โ””โ”€โ”€ README.md            โ† full reproducible experiment workflow
โ”œโ”€โ”€ docs/
โ”‚   โ”œโ”€โ”€ system-design.png    โ† architecture diagram (this README)
โ”‚   โ”œโ”€โ”€ system-design.svg    โ† vector source for slides / print
โ”‚   โ”œโ”€โ”€ latency-percentiles.png
โ”‚   โ””โ”€โ”€ c2-detection.png     โ† C2 beacon vs benign timing comparison
โ”œโ”€โ”€ Dockerfile.api
โ”œโ”€โ”€ Dockerfile.frontend
โ”œโ”€โ”€ Dockerfile.cpp
โ”œโ”€โ”€ docker-compose.yml
โ”œโ”€โ”€ start.sh                 โ† one-command dev launcher
โ”œโ”€โ”€ BENCHMARKS.md
โ””โ”€โ”€ README.md

๐Ÿ› ๏ธ Tech Stack

Layer Technology
DPI Engine C++17 ยท CMake ยท libpcap ยท std::atomic ยท pthread
Algorithms Aho-Corasick ยท Shannon entropy ยท MATLAB db4 wavelet ยท FNV-1a ยท MurmurHash3
Data Structures Bloom filter ยท Trie ยท Cuckoo hash ยท SPSC/MPSC lock-free queues
API Node.js 20 ยท Express 4 ยท ws (WebSocket)
Frontend React 18 ยท Vite 5 ยท Leaflet ยท Recharts
Analyzer Streamlit ยท Plotly ยท NumPy
Research Python ยท SciPy ยท PyWavelets ยท scapy
Testing GoogleTest (C++) ยท GitHub Actions CI
Infra Docker ยท docker-compose ยท Nginx ยท GitHub Actions
Deploy Vercel ยท Render ยท Streamlit Cloud ยท GitHub

๐Ÿงญ Roadmap

  • C++ DPI core with Aho-Corasick, Bloom filter, entropy
  • Node.js WebSocket API with built-in simulator fallback
  • React dashboard with live Leaflet threat map
  • Streamlit DPI analyzer with entropy gauge
  • Docker deploy for all services
  • Cloud deploy (Vercel + Render + Streamlit Cloud)
  • Benchmark suite + document vs Snort
  • GoogleTest unit tests for C++ core (31 tests)
  • C2 detection research harness (entropy + wavelet + IAT regularity)
  • Jest integration tests for the API
  • Prometheus /metrics endpoint + Grafana dashboard
  • JWT authentication + rate limiting on the API
  • Kubernetes manifests (Deployment, Service, HPA)
  • Real AF_XDP integration (currently libpcap fallback)

๐Ÿ› Troubleshooting

Symptom Fix
Dashboard shows RECONNECTING Wake the Render API โ€” visit /api/health directly, then refresh
Streamlit shows OFFLINE Check the NETSENTRY_API secret on Streamlit Cloud โ€” no trailing slash, https:// prefix
Map tiles don't load Check internet โ€” CartoDB tiles need network
WebSocket disconnects on Render Render free tier sleeps after 15 min โ€” upgrade to Starter ($7/mo) for always-on
C++ fails to compile Need CMake โ‰ฅ 3.16, GCC โ‰ฅ 11, and libpcap-dev on Linux
Vercel build fails Root directory must be frontend, not /frontend

๐Ÿ“œ License

MIT โ€” use freely for portfolio, interviews, research, or commercial projects.


Author

ADITYA SATAPATHY

GitHub LinkedIn Gmail

About

Real-time Deep Packet Inspection system with C++ engine, React dashboard, and Streamlit DPI analyzer

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages