diff --git a/suricata/leaf-eve-rotate.service b/suricata/leaf-eve-rotate.service new file mode 100644 index 0000000..d94c243 --- /dev/null +++ b/suricata/leaf-eve-rotate.service @@ -0,0 +1,8 @@ +[Unit] +Description=Rotate LEAF EVE stats on tmpfs +Requisite=suricata-leaf.service +After=suricata-leaf.service +[Service] +Type=oneshot +ExecStart=/usr/bin/python3 /opt/leaf-controller/tools/rotate-eve.py +UMask=0027 diff --git a/suricata/leaf-eve-rotate.timer b/suricata/leaf-eve-rotate.timer new file mode 100644 index 0000000..2c7b25c --- /dev/null +++ b/suricata/leaf-eve-rotate.timer @@ -0,0 +1,8 @@ +[Unit] +Description=Check LEAF EVE retention every minute +[Timer] +OnActiveSec=2min +OnUnitActiveSec=1min +AccuracySec=5s +[Install] +WantedBy=timers.target diff --git a/suricata/rules/leaf-local.rules b/suricata/rules/leaf-local.rules new file mode 100644 index 0000000..eed6500 --- /dev/null +++ b/suricata/rules/leaf-local.rules @@ -0,0 +1,34 @@ +# LEAF-PROTO local rules. Only rules with `metadata: leaf_action block;` are +# acted on by leaf-controller (override via config policy). SIDs reserved: 1000000-1099999. +# +# Inbound flows (attacker->victim): default policy blocks nothing (dest is your LAN). +# Outbound flows (victim->external C2 / exfil / scan-out): dest_ip gets blocked on VyOS. + +# Suricata 7: HOME_NET/EXTERNAL_NET are defined in suricata-leaf.yaml +# (vars: address-groups). 'var' statements in rule files are not supported. + +# --- lab test rule: any outbound ICMP to TEST-NET (trigger demo) --- +alert icmp any any -> 192.0.2.0/24 any (msg:"LEAF TEST ICMP to TEST-NET"; sid:1000001; rev:1; metadata: leaf_action block;) + +# --- outbound scan: many TCP SYNs from one host to many hosts in 10s --- +alert tcp $HOME_NET any -> $EXTERNAL_NET any (msg:"LEAF SCAN-OUT tcp syn flood"; flags:S; threshold: type threshold, track by_src, count 25, seconds 10; sid:1000002; rev:1; metadata: leaf_action block;) +# NOTE: the threshold is engine-side noisy for lab use; controller also windows by (sid,dest) + +# --- obvious C2 patterns (examples; extend with your own) --- +alert tcp any any -> any any (msg:"LEAF possible meterpreter reverse"; flow:to_server; content:"|0a 16 1a 05|"; depth:4; sid:1000010; rev:1; metadata: leaf_action block;) + +# --- DNS tunneling heuristic: prefer et open ruleset + thresholding for this --- + +# --- inbound (src-side block candidates; block_src must be enabled in controller) --- +# SYN+FIN is an abnormal flag combination, not an SSH authentication failure. +# Encrypted SSH login failures cannot be inferred from TCP flags. +alert tcp $EXTERNAL_NET any -> $HOME_NET 22 (msg:"LEAF abnormal SYN FIN inbound"; flow:to_server; flags:SF; threshold: type threshold, track by_src, count 20, seconds 30; sid:1000020; rev:1; metadata: leaf_action block_src;) + +# --- lateral/brute observable on the VEX-mirror posture: SYN-only toward sensor --- +alert tcp 172.19.32.0/24 any -> 10.0.249.1 22 (msg:"LEAF LATERAL-BRUTE ssh sweep from VEX-LAN at sensor"; flags:S; threshold: type threshold, track by_src, count 15, seconds 30; sid:1000021; rev:1; metadata: leaf_action block_src;) + +# SRC-MODE drill: mirror-visible transit wave with out-of-floor spoofed src. +# dst 192.0.2.x is transit-only dst reachable through the mirror (locally-dst +# traffic toward 10.0.249.1 never appears on the mirror, so 1000020/1000021 cannot +# fire there). Spoofed src is 203.0.113.0/24 (RFC5737) -> never a real peer. +alert tcp 203.0.113.0/24 any -> 192.0.2.0/24 22 (msg:"LEAF SRC-MODE spoofed-src at TEST-NET dst"; flags:S; threshold: type threshold, track by_src, count 12, seconds 30; sid:1000030; rev:1; metadata: leaf_action block_src;) diff --git a/suricata/suricata-leaf.service b/suricata/suricata-leaf.service new file mode 100644 index 0000000..e6e9063 --- /dev/null +++ b/suricata/suricata-leaf.service @@ -0,0 +1,25 @@ +[Unit] +Description=LEAF passive Suricata sensor on eth1 +# Start after the controller has bound its alert socket and reported ready. +# Runtime reconnect occurs on a later alert write; alerts during downtime +# are not stored for replay. +After=network-online.target leaf-controller.service +Wants=network-online.target leaf-controller.service +RequiresMountsFor=/var/log/suricata-leaf + +[Service] +Type=simple +ExecStartPre=/usr/bin/suricata -T -c /etc/suricata-leaf/suricata-leaf.yaml -l /var/log/suricata-leaf +ExecStart=/usr/bin/suricata --af-packet=eth1 -c /etc/suricata-leaf/suricata-leaf.yaml -l /var/log/suricata-leaf +Restart=on-failure +RestartSec=5 +KillSignal=SIGINT +TimeoutStopSec=60 +User=root +Group=leafctrl +UMask=0027 +ProtectSystem=full +ProtectHome=yes + +[Install] +WantedBy=multi-user.target diff --git a/suricata/suricata-leaf.yaml b/suricata/suricata-leaf.yaml new file mode 100644 index 0000000..e7cbb58 --- /dev/null +++ b/suricata/suricata-leaf.yaml @@ -0,0 +1,89 @@ +%YAML 1.1 +--- +# LEAF-PROTO Suricata IDS config (IDS VM). Self-contained drop-in. +# Run: suricata -c /etc/suricata/suricata-leaf.yaml -i MIRROR_IFACE +# (Debian: apt install suricata suricata-update; mirror NIC must be promisc/untagged-capable) + +vars: + main: /var/lib/suricata-leaf + address-groups: + HOME_NET: "[192.168.100.0/24,10.0.249.0/31,172.19.32.0/24]" + EXTERNAL_NET: "!$HOME_NET" + +default-rule-path: /etc/suricata-leaf/rules +rule-files: + - leaf-local.rules + +# --- log output location -------------------------------------------------- +# eve.json is written below as an absolute path. Provision +# /var/log/suricata-leaf on a 6-8G tmpfs (RAM disk) to keep eve writes off +# the physical disk. leaf-eve-rotate.timer renames the file hourly or at +# 64 MiB, signals HUP to reopen it, and keeps six backups. The controller +# drains the old inode before opening the new one. +logging: + default-log-level: info + outputs: + - console: + enabled: no + - file: + enabled: yes + level: info + filename: suricata.log + +# --- capture: mirror NIC ------------------------------------------------- +af-packet: + - interface: eth1 # mirror NIC on LEAF-PROTO VM (10.0.249.1/31) + cluster-id: 98 + cluster-type: cluster_flow + defrag: yes + use-mmap: yes + tpacket-v3: no + bpf-filter: "not ip host 255.255.255.255 and not udp port 5353" + +# --- output split: alerts over the controller socket, stats on file ------ +# The controller binds /run/suricata/alerts.sock (AF_UNIX listener) and +# suricata connects as the CLIENT; ordering is contract-critical: the +# leaf-controller unit binds at startup, the sensor unit Wants+After it. +# The controller reports readiness after binding the socket. +# Stats stay in eve.json on tmpfs. Alerts use the socket and can be lost +# during disconnection or if the sender cannot write without blocking. +outputs: + - eve-log: + enabled: yes + filetype: unix_stream + filename: /run/suricata/alerts.sock # the socket path, not a log file + types: + - alert: + metadata: yes + payload: no # keep EVE small; set packet-based extras later if needed + - eve-log: + enabled: yes + filetype: regular + filename: /var/log/suricata-leaf/eve.json + types: + - stats: + totals: yes + threads: no + +# --- engine: fine for 1-2 Gbps mirror ------------------------------------ +threading: + pfring: + enabled: no + +pcap: + buffer-size: 16777216 + +stream: + memcap: 128mb + +flow: + memcap: 64mb + +stats: + enabled: yes + interval: 30 + +host-mode: auto + +# reference: ET open ruleset optional via `suricata-update --sources` but do NOT +# tag whole ET for leaf_action; only our local rules carry metadata: leaf_action.