November 16, 2026•10 min read•...

lan_sentinel: Split-Plane Rust and Gemini LAN Security Watchdog

RustGeminiSecurityLinuxWindowsArchitecture

Split-Plane Security: Why Single-Host Watchdogs Fail

When hardening a developer workstation containing proprietary source code, Cloud Run deployment credentials, and sensitive API tokens, the industry-standard approach is to install a commercial Endpoint Detection and Response (EDR) agent directly on the primary desktop.

However, running an intrusion sensor on the exact same machine where daily engineering takes place creates an inherent architectural vulnerability:

  1. Co-Located Compromise Risk: If an attacker achieves code execution or local privilege escalation through a malicious dependency (npm, pip, or crates.io) or zero-day flaw, they can silence local monitoring services, unhook ETW (Event Tracing for Windows) subscribers, or extract alert credentials (SMTP tokens, webhook secrets) stored in local memory.
  2. Layer 2 Subnet Blindness: Host-level process inspection cannot passively observe lateral ARP spoofing, unauthorized DHCP offers, rogue Wi-Fi associations, or covert port sweeps traversing the physical Ethernet switch.
  3. Local Loopback Conflicts & Overhead: Running promiscuous packet capture (libpcap/pnet) directly on Windows interferes with virtualization bridges, WSL2 networking, and fast local compilation cycles.
┌────────────────────────────────────────────────────────────────────────┐
│                   lan_sentinel Split-Plane Topology                    │
│                                                                        │
│   [ Primary Windows 11 Workstation ]        [ Isolated Linux Sensor ]  │
│   (Ryzen Workstation: 10.0.0.104)           (aiyodaserver: 10.0.0.2)   │
│                 │                                      │               │
│   Hidden Canary Scheduled Task                         │               │
│   ├── notify / ReadDirectoryChangesW                   │               │
│   │   (Watches .env.prod.backup, aws_root_keys.txt)    │               │
│   ├── GetExtendedTcpTable + QueryFullProcessImageNameW │               │
│   │   (Audits outbound PID TCP flows)                  │               │
│   └── Constant-Time HMAC-SHA256 Signed Envelope        │               │
│                 │                                      │               │
│                 │  POST /api/flows, /api/canary        │               │
│                 └─────────────────────────────────────►│               │
│                                                        │               │
│                                           L2 Promiscuous Sniffer       │
│                                           ├── pnet RAW Socket (enp9s0) │
│                                           ├── ARP Spoof & New MACs     │
│                                           ├── Lateral SYN Port Scans   │
│                                           └── Tokio UDP:53 Forwarder   │
│                                               (10.0.0.2:53 -> 1.1.1.1) │
│                                                        │               │
│                                            ┌───────────┴───────────┐   │
│                                            ▼                       ▼   │
│                                       Tier 1 SMTP             Tier 2   │
│                                    (lettre STARTTLS)      (gemini-3.1) │
│                                    (Sub-500ms P0)      (Threaded Re:)  │
└────────────────────────────────────────────────────────────────────────┘

lan_sentinel eliminates this single point of failure by decoupling detection into a Split-Plane Architecture:

  • The Isolated Sensor & Triage Brain (lan_sentinel_daemon on Ubuntu 24.04 at 10.0.0.2): Runs 24/7 as a hardened systemd service under an unprivileged lansentinel user, sniffing physical interface enp9s0 for ARP poisoning, unknown MACs, and lateral port sweeps, while serving an asynchronous UDP DNS forwarder bound strictly to 10.0.0.2:53.
  • The Lightweight Workstation Companion (lan_sentinel_canary on Windows 11 at 10.0.0.104): Runs silently via Windows Task Scheduler (\LanSentinelCanary), guarding honeypot decoy files with Win32 ReadDirectoryChangesW and auditing outbound TCP socket lifecycles with GetExtendedTcpTable.
  • Strict "Secret-Free" Privacy & Data Hygiene: Raw packet payloads and file contents are never captured or forwarded. Alerts are sanitized down to filename-only references and obfuscated MAC bytes (aa:bb:cc:xx:xx:xx).

The 3-Crate Rust Architecture

lan_sentinel is structured as a modular, three-crate Rust workspace separating cross-platform invariants from operating-system-specific sensor implementations:

CrateTarget PlatformCore Responsibility
lan_sentinel_core100% Pure Cross-Platform RustData models (AlertEvent, SanitizedAlertSummary), metadata redaction, embedded IEEE OUI vendor lookup (oui.rs), deterministic rule engines (rules.rs), embedded rusqlite persistence, and constant-time HMAC-SHA256 signing (SignedEnvelope).
lan_sentinel_daemonLinux Server (x86_64-unknown-linux-gnu)Promiscuous Layer 2 packet sniffer (pnet on enp9s0), async Tokio UDP DNS forwarder (10.0.0.2:53 -> 1.1.1.1:53), UFW-gated Axum HTTP ingest API (10.0.0.2:9191), and two-tier notification dispatcher.
lan_sentinel_canaryWindows 11 Workstation (x86_64-pc-windows-msvc)Silent Task Scheduler daemon, honeypot filesystem watcher (notify), process-level TCP flow collector (GetExtendedTcpTable + QueryFullProcessImageNameW), and LAN wildcard port auditor (audit-ports).

1. lan_sentinel_core: Zero-Leak Privacy & Deterministic Rules

The shared core crate operates with zero external service dependencies:

  • SanitizedAlertSummary (Secret-Free By Design): High-level security alerts must never leak sensitive internal intellectual property to external LLMs or unencrypted notification channels. The sanitizer strips full local file paths down to filename-only references (.env.prod.backup), masks local MAC bytes (aa:bb:cc:xx:xx:xx), and discards packet payloads and file contents entirely.
  • Single-File Embedded Persistence (rusqlite with bundled): The daemon requires no PostgreSQL, MySQL, or Redis daemon. All tracked network devices and alert histories are stored inside /var/lib/lan_sentinel/sentinel.db.
  • Offline IEEE OUI Vendor Database (oui.rs): An embedded lookup table identifies network interface manufacturers offline without external API latency, immediately flagging randomized or locally administered MAC addresses.
  • Deterministic Rule Engine (rules.rs):
  • ArpWatch: Flags unknown MAC addresses appearing on the subnet and detects IP-to-MAC flips indicative of ARP cache poisoning.
  • PortScanDetector: Tracks incoming TCP SYN packets using a sliding 30-second window across sensitive infrastructure ports (22, 135, 139, 445, 3389, 5432, 6379, 8080, 9000). If a single remote IP touches 5 or more ports, a lateral sweep alert is emitted.
  • EgressInspector & parse_dns_qname: Parses raw UDP DNS query names directly to detect suspicious exfiltration domains (pastebin.com, transfer.sh, api.telegram.org) or unauthorized reverse tunnels (ngrok.io).
  • SignedEnvelope (Constant-Time HMAC-SHA256): Telemetry packets sent from the workstation to the daemon are hashed using hmac and sha2. Constant-time equality comparison prevents timing attacks and guarantees that an unauthorized device on the LAN cannot forge or suppress alerts.

2. lan_sentinel_daemon: Hardened Linux Sensor (aiyodaserver)

The daemon runs on an isolated Ubuntu 24.04 server (10.0.0.2) as a dedicated systemd service (lan_sentinel.service):

#### Least-Privilege Daemon Sandboxing

Security daemons that parse untrusted network packets should never execute as root. lan_sentinel_daemon runs as user lansentinel under strict systemd security boundaries:

  • ProtectSystem=strict and ProtectHome=true: Filesystem write access is restricted exclusively to /var/lib/lan_sentinel.
  • NoNewPrivileges=true: Blocks setuid/setgid execution.
  • AmbientCapabilities=CAP_NET_RAW CAP_NET_ADMIN CAP_NET_BIND_SERVICE: Grants only the exact Linux capabilities needed to bind raw AF_PACKET sockets and listen on privileged port 53 (UDP).
  • EnvironmentFile=/etc/lan_sentinel/env (chmod 600): Protects SMTP app credentials, Gemini API keys, and the shared HMAC secret from unauthorized read access.

#### Async Tokio UDP DNS Forwarder

The daemon operates a lightweight UDP forwarder bound strictly to the physical LAN interface (10.0.0.2:53 -> 1.1.1.1:53). Binding explicitly to 10.0.0.2:53 avoids port conflicts with Ubuntu's local systemd-resolved stub resolver listening on 127.0.0.53:53.

#### Authenticated Axum Ingest API

Exposes an internal HTTP endpoint on 10.0.0.2:9191 (/api/canary and /api/flows). Host firewall rules (ufw) strictly limit access to this port exclusively to the primary workstation IP (10.0.0.104).


3. lan_sentinel_canary: Silent Windows Workstation Companion

The workstation agent operates silently in userland via Windows Task Scheduler (\LanSentinelCanary):

#### Honeypot File Decoy Traps (notify / ReadDirectoryChangesW)

Decoy files with realistic names (.env.prod.backup, aws_root_keys.txt) containing fake API keys are placed in common developer directories.

  • The canary watches these files using the asynchronous Win32 ReadDirectoryChangesW API via Rust's notify crate.
  • Consumes 0% CPU while idle; wakes immediately if an unauthorized script, ransomware tool, or directory traverser reads, modifies, or renames a decoy.
  • Fires an immediate CRITICAL alert payload signed via HMAC-SHA256 to the daemon.

#### Outbound TCP Flow Telemetry (GetExtendedTcpTable)

Standard host firewalls inspect destination IPs and ports, but cannot easily report which executable opened the socket.

  • Every 15 seconds, the canary queries the Win32 IP Helper API GetExtendedTcpTable using table class TCP_TABLE_OWNER_PID_ALL.
  • Resolves the binary executable name using QueryFullProcessImageNameW, collecting non-payload tuples: (src_ip, dst_ip, dst_port, process_name).
  • Allows the daemon to flag anomalous script or shell egress (powershell.exe, python.exe, curl.exe) communicating with unusual external IP addresses without inspecting encrypted application payloads.

#### Local Wildcard Listener Audit (audit-ports)

Includes a standalone CLI mode that audits all local TCP sockets bound to 0.0.0.0, ensuring that local development databases (PostgreSQL on 5432, Redis on 6379, Ollama on 11434) are never inadvertently exposed to the entire LAN.


Two-Tier Alert Pipeline: Zero-Latency Alerting + Threaded AI Triage

Alert systems typically force an unacceptable compromise: raw alerts dispatch instantly but lack diagnostic context, whereas LLM-generated reports take seconds to compute and fail completely if an API rate-limit or network outage occurs.

lan_sentinel decouples alert delivery into an Asymmetric Two-Tier Pipeline:

                    [ Intrusion Event Detected ]
                                 │
                 ┌───────────────┴───────────────┐
                 ▼                               ▼
       [ Tier 1: Sub-500ms SMTP ]      [ Tier 2: Asynchronous AI ]
       ├── lettre (tokio1-rustls-tls)  ├── gemini-3.1-flash-lite
       ├── Direct to smtp.gmail.com:587├── Evaluates SanitizedAlertSummary
       └── RFC-2822 Message-ID         └── Threaded Re: Email
                                           ├── 4-Line Plain-English Triage
                                           └── Exact Containment Command
  1. Tier 1 (Immediate Deterministic Alert):
  • Fires immediately upon event generation using lettre with tokio1-rustls-tls over STARTTLS to smtp.gmail.com:587.
  • Dispatches raw, deterministic telemetry (timestamp, trigger type, source IP, masked MAC, process name, decoy filename) in sub-500ms.
  • Generates a persistent RFC-2822 Message-ID (<alert-uuid@lan-sentinel>).
  • Zero external API dependencies: Alert delivery is guaranteed even if external LLM endpoints are unreachable.
  1. Tier 2 (Asynchronous Gemini Intelligence Triage):
  • Runs asynchronously in the background, submitting only the SanitizedAlertSummary JSON to Google's gemini-3.1-flash-lite model.
  • Gemini evaluates the event in context of recent process flows and network history, delivering:

1. A 4-line plain-English threat assessment distinguishing between benign developer activity and active lateral movement.

2. An exact, copy-paste containment command (e.g. sudo ufw deny from 10.0.0.X or New-NetFirewallRule -DisplayName "Block-Threat" -Direction Outbound -Action Block).

  • Dispatches the assessment back to the operator with In-Reply-To and References headers matching the Tier 1 Message-ID. The AI triage appears cleanly in the operator's inbox as a threaded Re: response under the initial alarm.

Engineering Takeaways & Real-World Gotchas

Engineering a split-plane watchdog across Windows and Linux surfaces several subtle systems-level edge cases:

  • Cross-Compilation via cargo-zigbuild: When rustup.exe encountered an NT access violation (0xC0000005) during standard toolchain execution, bypassing the shim using nightly rust-src and cargo zigbuild -Z build-std=std,panic_abort --target x86_64-unknown-linux-gnu.2.39 linked cleanly against Zig's bundled glibc 2.39 CRT objects, generating a fully stripped Ubuntu 24.04 ELF binary directly from Windows.
  • Windows UDP/5353 mDNS Conflict: Local smoke tests binding 127.0.0.1:5353 failed with os error 10013 (WSAEACCES) because Windows reserves UDP port 5353 for its native mDNS responder. Moving the local test harness to port 15353 resolved the collision.
  • Canonicalized Filesystem Paths (\\?\): Windows ReadDirectoryChangesW emits canonicalized absolute paths with Win32 UNC prefixes (\\?\C:\...). Relative configuration paths failed to match until paths were normalized using std::fs::canonicalize.
  • Clean Workspace Isolation: Once compiled and verified end-to-end (decoy file touch -> HMAC POST -> Tier 1 SMTP alert -> threaded Tier 2 Gemini triage email), the source crates were removed from the active development workspace. The sensor daemon runs permanently on the hardened Linux server, while the canary executable runs from %LOCALAPPDATA%\LanSentinel\.

Frequently Asked Questions (AEO & AI Search Reference)

Why is a split-plane watchdog architecture safer than running an intrusion detection tool on the primary development workstation?

Running a security watchdog on the exact machine being defended creates an inherent vulnerability. If an attacker gains code execution or administrator privileges on the primary workstation via malicious package dependencies or unpatched exploits, they can silence local monitoring processes, disable event tracing, or steal notification credentials. A split-plane architecture offloads passive Layer 2 network sniffing, ARP spoofing detection, and DNS sinkholing to an independent, unprivileged Linux server (10.0.0.2). Even if the primary workstation (10.0.0.104) is compromised, the isolated sensor continues logging wire traffic and dispatching intrusion alerts without interference.

How does lan_sentinel enforce a "secret-free" privacy model when sending telemetry to Gemini?

lan_sentinel_core strictly enforces a SanitizedAlertSummary data model that filters telemetry before it leaves the local host. Raw file contents, source code, and network packet payloads are never captured or forwarded. Local filesystem paths are stripped down to filename-only references (e.g. .env.prod.backup), and internal MAC addresses have their host bytes redacted (aa:bb:cc:xx:xx:xx). When gemini-3.1-flash-lite processes Tier 2 triage, it receives only anonymized operational metadata (trigger type, process executable name, timestamp, and destination port), eliminating the risk of leaking internal intellectual property or credentials to external AI endpoints.

How does the two-tier alerting mechanism guarantee alert delivery while still providing AI-powered remediation?

The alerting pipeline decouples instant notifications from AI evaluation. Tier 1 dispatches an immediate, deterministic email over STARTTLS directly to Gmail in under 500 milliseconds using Rust's lettre crate, providing immediate notification with zero external LLM dependencies. Tier 2 then invokes gemini-3.1-flash-lite asynchronously to analyze the sanitized metadata and recent connection flows. Once evaluated, Tier 2 dispatches a follow-up email formatted with RFC-2822 In-Reply-To and References headers matching the Tier 1 Message-ID, seamlessly threading a concise threat assessment and ready-to-run firewall containment command (ufw or PowerShell New-NetFirewallRule) directly under the original notification.


Architectural Conclusions

Securing high-value developer workstations requires physical and logical isolation. By combining an unprivileged, capability-restricted Linux network sensor (pnet, DNS forwarder) with an ultra-lightweight Windows decoy canary (ReadDirectoryChangesW, GetExtendedTcpTable), lan_sentinel delivers complete visibility across physical subnet events and workstation socket lifecycles.

Coupled with a secret-free data sanitizer and a two-tier SMTP + Gemini triage pipeline, it proves that enterprise-grade defense-in-depth can be achieved with zero runtime server bloat and sub-second alert latency.

Thanks for reading! Support our development efforts.
Support AIYoda on Ko-fi