P3 โ€” AI Log Anomaly Detector


Problem

/var/log/auth.log generates thousands of events. The signal is there โ€” brute forces, privilege escalations, new user accounts โ€” but drowning in noise. SOC tools cost $$$. This tool is free, local, and maps every finding to MITRE ATT&CK.

Detection Rules

PatternATT&CKConfidence Formula
SSH brute force (โ‰ฅ10 failures/5 min, same IP)T1110.001min(count/50, 1.0)
Distributed brute force (โ‰ฅ5 IPs, same user)T1110.003min(ips/30, 1.0)
Credential stuffing (โ‰ฅ10 fails, โ‰ฅ5 users)T1110.004min(failures/20, 1.0)
sudo failures (โ‰ฅ3 in 10 min)T1548.003min(count/10, 1.0)
su to rootT1548.0030.85
New user via useraddT1136.0011.0
Root SSH loginT1078.0031.0

Pipeline

auth.log / journalctl JSON
  โ†’ parse (sliding-window event classifier)
  โ†’ detect (rule engine โ†’ Anomaly dataclass)
  โ†’ enrich (AbuseIPDB: abuse score, geo, report count)
  โ†’ analyze (local Ollama: threat narrative + response steps)
  โ†’ report (text + JSON + email alert on CRITICAL/HIGH)

Confidence Scoring

Every anomaly gets a confidence float 0.0โ€“1.0 based on evidence count. A single failed password is noise; 50 failures from the same IP in 5 minutes is confidence 1.0. Triage by confidence ร— severity instead of raw event counts.

Usage

# Analyze live auth log with IP reputation
python main.py /var/log/auth.log --abuseipdb $KEY

# Analyze journalctl export
journalctl -o json > /tmp/j.json
python main.py /tmp/j.json --format journalctl --json report.json

# Skip AI, rule-based only
python main.py sample_auth.log --no-ai
โ† back