A production-grade, minimal-dependency SIEM engine built from scratch in Python.
Sigma detection Β· Attack chain correlation Β· ML anomaly scoring Β· STIX 2.1 export
NanoSIEM is a fully functional SIEM engine written in ~4,500 lines of pure Python. It implements the same detection pipeline used by enterprise security platforms β but without the abstraction fog. Every component is readable, testable, and documented.
Built as a learning-by-doing alternative to studying SIEM theory. If you want to understand how detection engineering actually works at the code level, read this codebase.
Log sources β Parse β Normalize β Sigma Eval β Correlate β ML Score β Alert β STIX 2.1
| Capability | Detail |
|---|---|
| Log Ingestion | Syslog RFC 5424, Syslog RFC 3164, CEF, JSON, plaintext β auto-detected |
| Transport | UDP syslog, TCP syslog (RFC 6587), TCP JSON, local file tail |
| Sigma Engine | Custom AST parser β and/or/not/1 of/all of, field modifiers (contains, startswith, endswith, re) |
| Correlation | 6 built-in attack chains, sliding time-window, source-IP grouped, deduplication |
| ML Detection | Isolation Forest, 31-feature extractor, percentile-calibrated scoring, XAI attribution |
| Alerting | Unified alert manager, severity filtering, dedup by fingerprint |
| Output | STIX 2.1 JSON bundles, NDJSON alert log, SQLite ring buffer |
| CLI | run, tail, parse-line, stats commands via Typer |
| Tests | 234 passing, 6 test modules covering all components |
| Dependencies | pyyaml, stix2, scikit-learn, typer, rich, joblib β nothing else |
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Log Sources β
β UDP Syslog Β· TCP Syslog Β· TCP JSON Β· File Tail β
ββββββββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββ
β RawMessage queue (asyncio, bounded 10k)
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Ingestion Pipeline β
β β
β parser.py normalizer.py schema.py β
β ββββββββββββ ββββββββββββββ ββββββββββββββββ β
β βRFC 5424 β β IP extract β βNormalizedEventβ β
β βRFC 3164 ββββββββΆβ Username βββββββββΆβ (common β β
β βCEF β β Auth tags β β schema) β β
β βJSON β β Port parse β ββββββββ¬ββββββββ β
β βPlaintext β ββββββββββββββ β β
β ββββββββββββ β β
βββββββββββββββββββββββββββββββββββββββββββββββββββββΌβββββββββββββ
β
βββββββββββββββββββββββββββββββββββββββ€
β β
βΌ βΌ
βββββββββββββββββββββββββββ βββββββββββββββββββββββββββ
β Sigma Rule Engine β β Correlation Engine β
β β β β
β loader.py β β window.py β
β βββββββββββββββββββ β β βββββββββββββββββββ β
β β YAML β SigmaRuleβ β β β Per-source deque β β
β ββββββββββ¬βββββββββ β β β Sliding window β β
β β β β β LRU eviction β β
β ast.py β β β ββββββββββ¬βββββββββ β
β ββββββββββΌβββββββββ β β β β
β β Condition β AST β β β chainer.py β
β β and/or/not/1of β β β ββββββββββΌβββββββββ β
β ββββββββββ¬βββββββββ β β β Sequence finder β β
β β β β β 6 built-in chainsβ β
β evaluator.py β β β Alert callbacks β β
β ββββββββββΌβββββββββ β β βββββββββββββββββββ β
β β Walk AST vs β β βββββββββββββββββββββββββββ
β β NormalizedEvent β β
β βββββββββββββββββββ β βββββββββββββββββββββββββββ
βββββββββββββββββββββββββββ β ML Anomaly Scorer β
β β
β features.py β
β βββββββββββββββββββ β
β β 31-dim extractor β β
β β temporal/network β β
β β program/message β β
β ββββββββββ¬βββββββββ β
β β β
β baseline.py β
β ββββββββββΌβββββββββ β
β β IsolationForest β β
β β Calibrated score β β
β β XAI attribution β β
β βββββββββββββββββββ β
βββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββ
β Alert Manager β
β β
β Sigma + Correlation + ML β
β Fingerprint deduplication β
β Severity routing β
ββββββββββββ¬βββββββββββββββββββββββ
β
ββββββββββββββββββββββΌβββββββββββββββββββββ
βΌ βΌ βΌ
ββββββββββββ ββββββββββββββββ ββββββββββββ
βSTIX 2.1 β β NDJSON alert β β SQLite β
β Bundles β β log β β Ring β
ββββββββββββ ββββββββββββββββ β Buffer β
ββββββββββββ
git clone https://github.com/Sudeep72/nano-siem.git
cd nano-siem
pip install -e .bash demo.shThis runs all 5 detection phases against synthetic log data and shows real detections.
# Terminal 1 β start nano-siem
nano-siem run
# Terminal 2 β send a simulated attack kill chain
bash examples/send_kill_chain.shnano-siem tail /var/log/auth.lognano-siem parse-line '<34>1 2026-06-02T03:00:01Z web-01 sshd 1234 - - Failed password for root from 203.0.113.5 port 22'NanoSIEM ships with 7 built-in Sigma rules and supports loading any Sigma-compatible YAML:
| Rule | Level | MITRE Technique |
|---|---|---|
| SSH Brute Force Attempt | HIGH | T1110.001 |
| SSH Successful Login | LOW | T1021.004 |
| Privilege Escalation via Sudo | MEDIUM | T1548.003 |
| Port Scan Detected | MEDIUM | T1046 |
| Web Admin Panel Access Attempt | MEDIUM | T1190 |
| High Severity CEF Event | HIGH | β |
| Suspicious Root Process Execution | HIGH | T1059 |
Add your own rules in rules/ β any .yml file is auto-loaded.
6 built-in kill-chain patterns, source-IP grouped across a sliding time window:
| Chain | Steps | Window | Severity |
|---|---|---|---|
| Brute Force β Successful Login | 2 | 10 min | CRITICAL |
| Port Scan β Brute Force | 2 | 5 min | HIGH |
| Login β Privilege Escalation | 2 | 15 min | CRITICAL |
| Port Scan β Web Admin Probe | 2 | 3 min | HIGH |
| Full Intrusion Kill Chain | 4 | 30 min | CRITICAL |
| Repeated Auth Failures (Γ3) | 3 | 2 min | MEDIUM |
Isolation Forest trained on a 2000-event synthetic baseline of normal Linux traffic. 31-dimensional feature vector covering temporal, network, program, message, and severity signals. Detects threats with no rule coverage β including novel attack patterns.
XAI attribution explains every anomaly score with the top features driving it:
π€ ML [ANOMALOUS] score=0.987 | drivers: is_error_severity=1.00, is_off_hours=0.84, dest_port_norm=0.67
Every alert produces a valid STIX 2.1 bundle in alerts/YYYY-MM-DD/:
{
"type": "bundle",
"spec_version": "2.1",
"objects": [
{ "type": "indicator", "name": "SSH Brute Force Attempt", "confidence": 80 },
{ "type": "sighting", "count": 3, "first_seen": "2026-06-02T03:00:01Z" },
{ "type": "observed-data", "custom_properties": {
"x_nano_siem_severity": "high",
"x_nano_siem_anomaly_score": 0.691,
"x_nano_siem_xai_features": [{"feature": "has_failure_keyword", "deviation": 1.0}]
}}
]
}alerts/alerts-YYYY-MM-DD.ndjson β one JSON object per line, easy to pipe to any downstream tool.
All settings in config.yaml:
ingestion:
syslog_host: "0.0.0.0"
syslog_port: 5140
syslog_protocol: "tcp" # tcp | udp
json_port: 5141
ml:
train_on_startup: true
anomaly_threshold: 0.62 # 0.0β1.0, higher = stricter
alerting:
dedup_window_seconds: 300
min_severity: "low" # low | medium | high | critical
stix_output: true# TCP Syslog (RFC 5424)
echo '<34>1 2026-06-02T03:00:01Z web-01 sshd - - - Failed password for root from 1.2.3.4' \
| nc -q1 localhost 5140
# TCP JSON
echo '{"host":"web-01","process":"nginx","message":"GET /admin HTTP/1.1 403","level":"warn"}' \
| nc -q1 localhost 5141
# CEF (via TCP syslog port)
echo 'CEF:0|Snort|IDS|2.9|1000001|Port Scan Detected|8|src=192.168.1.5 dst=10.0.0.1' \
| nc -q1 localhost 5140pip install pytest
python -m pytest tests/ -v234 passed in 3.13s
Test coverage spans all 5 detection layers:
| Module | Tests |
|---|---|
test_parser.py |
27 β RFC5424, RFC3164, CEF, JSON, plaintext |
test_normalizer.py |
26 β field mapping, IP/port/user extraction, auth tagging |
test_sigma.py |
47 β loader, AST builder, evaluator, engine integration |
test_correlation.py |
42 β window buffer, step matching, chain detection |
test_ml.py |
50 β feature extraction, training, scoring, XAI |
test_alerting.py |
42 β alert construction, dedup, STIX output |
nano-siem/
βββ nano_siem/
β βββ schema.py # NormalizedEvent β the pipeline's common language
β βββ main.py # Async pipeline orchestrator
β βββ ingestion/
β β βββ parser.py # RFC5424 / RFC3164 / CEF / JSON / plaintext
β β βββ normalizer.py # ParsedLog β NormalizedEvent + field extraction
β β βββ listener.py # UDP, TCP syslog, TCP JSON, file tail listeners
β βββ sigma/
β β βββ loader.py # Sigma YAML β SigmaRule dataclass
β β βββ ast.py # Detection block β evaluable AST
β β βββ evaluator.py # AST evaluation + SigmaEngine
β βββ correlation/
β β βββ chains.py # 6 built-in ChainRule definitions
β β βββ window.py # Per-source sliding time-window buffer
β β βββ chainer.py # Sequence detection + Correlator
β βββ ml/
β β βββ features.py # 31-dimensional feature extractor
β β βββ baseline.py # IsolationForest trainer + corpus generator
β β βββ scorer.py # Per-event anomaly scoring + XAI
β βββ storage/
β β βββ ringbuffer.py # SQLite-backed event ring buffer
β βββ alerting/
β β βββ manager.py # Alert dedup, severity routing
β β βββ stix_output.py # STIX 2.1 bundle serializer
β βββ cli/
β βββ app.py # Typer CLI
βββ rules/sample/ # 7 built-in Sigma rules
βββ tests/ # 234 tests across 6 modules
βββ examples/ # Runnable usage examples
βββ config.yaml # All configuration
βββ demo.sh # End-to-end 5-phase demo
Benchmarked on a standard laptop (Python 3.13, single core):
| Metric | Value |
|---|---|
| Ingestion throughput | ~55,000 events/sec |
| Parse + normalize latency | 0.018 ms/event |
| Sigma evaluation (7 rules) | ~0.05 ms/event |
| ML scoring (IsolationForest) | ~0.1 ms/event |
| End-to-end pipeline latency | < 0.5 ms/event |
| Memory (1000 sources, 500 events each) | ~100 MB |
See ROADMAP.md for the full version plan.
| Version | Focus | Status |
|---|---|---|
| v1.0 | Core detection platform | β Released |
| v2.0 | Detection Engineering Edition | π Planned |
| v3.0 | SOC Operations Edition | π Planned |
| v4.0 | AI Reasoning Edition | π Planned |
See CONTRIBUTING.md. All contributions welcome β especially new Sigma rules, correlation chain patterns, and additional log format parsers.
MIT β see LICENSE.