구현

구현된 구성 요소

Packet capture (src/capture.rs)

live NIC 또는 offline .pcap file에서 traffic을 읽고 TCP flow를 파싱합니다.

ARI prefilter (src/prefilter/)

encrypted traffic flow를 app class로 분류하는 XGBoost classifier입니다.

모듈 구조:

파일역할
flow_table.rs5-tuple key 기반 flow accumulator. SYN 기반 server direction 결정, LRU eviction
features.rsARI feature extraction (Python core/utils.py 1:1 port). inverse ACK delta와 edge case까지 맞춤
model.rsXGBoost native JSON parser + tree-walk inference. numerically stable softmax. XGBoost 3.x base_score 처리
labels.rsTOML class table. kind = benign/known/malicious + typical_domains
types.rsFlowKey, ParsedPkt, FlowState, Verdict, PrefilterOutput
mod.rsPrefilter::load(), ingest(), drain_classified()

검증: tests/prefilter_golden.rs — 33개 feature extraction case와 50개 predict_proba case를 Python reference와 비교해 1e-4 오차 이내로 검증합니다.

설정 (하드코딩 없음):

[prefilter]
skip_ports = [22, 23, 25, 53, ...]   # 분류 제외 포트
skip_ips   = ["8.8.8.8", "1.1.1.1"] # 분류 제외 IP
conf_threshold = 0.5                  # Unknown 판정 임계값

Passive DNS (src/ip_to_domain/passive_dns.rs)

UDP/53 DNS response를 wire에서 직접 parse해 IP→domain mapping을 실시간으로 구축합니다.

IP→domain lookup (src/ip_to_domain/)

provider chain을 module 단위로 나누어 구성했습니다.

passive-dns → ptr → hackertarget
모듈역할
passive_dns.rslive DNS sniffing cache
ptr.rsOS resolver reverse PTR lookup, SQLite cache
hackertarget.rsHackerTarget reverse IP API, 1초 throttling
verify.rsCloudflare DoH forward verification
cache.rsSQLite response cache

Alert 및 risk scoring

prefilter classification 결과를 즉시 DB alert로 변환합니다.

VerdictSeverityAlert typeRisk
Malicious4 (high)PREFILTER_MALICIOUS+60
Unknown2 (low)PREFILTER_UNKNOWN+15
Known1 (info)PREFILTER_CLASSIFIED+0
Benign(drop)

Web dashboard (src/web/)

JavaScript 없는 server-side rendering dashboard입니다. Askama compile-time template을 사용합니다.

Prefilter panel:

Alert type label:

Training pipeline (scripts/main.py)

단일 command로 전체 pipeline을 실행합니다.

uv run --project scripts python3 scripts/main.py all \
  --target-flows 300 \
  --max-visits 50

단계:

Step설명
capturePlaywright stealth Chromium으로 URL 방문, site별 pcap 저장. target flow 수에 도달할 때까지 자동 반복
extractpcap → ARI format parquet. private IP / DNS resolver IP / non-web port filtering
traininverse-frequency sample weight로 class imbalance 보정. XGBoost multi:softprob
exportprefilter.json + prefilter_labels.toml~/.local/share/capstone/

Adaptive capture:

계획된 구성 요소

구성 요소상태
passive_filter.rs — domain heuristic scoring
active_probe.rs — HTML 수집, screenshot, redirect chain
fingerprint.rs — SHA-256 hash, content signal
detector.rs — diff 기반 alert 생성
known_bad / Tranco import