Skip to content

Neurowall: Building a Neural Firewall from Scratch and Testing It Against 15 Attack Scenarios

Signal coherence, adaptive spectral detection, and honest results from a BCI defense simulation

· Original source
neurowall qif bci signalsecurity tara simulation neuralfirewall

What Is Neurowall?

Neurowall is a simulation harness for testing whether the QIF coherence metric can actually detect attacks on brain-computer interface (BCI) signals. Not in theory. In practice, against adversarial scenarios mapped from the TARA registry.

The question it answers: if someone tampers with the signal between your brain and a BCI device, can a physics-based anomaly detector catch it? And more importantly, what can’t it catch?

This post covers the full pipeline: signal generation (neurosim), attack injection, multi-layer detection, and honest results including the attacks that evade detection entirely.

Architecture: Three Defense Layers

Neurowall uses three concentric defense layers, each catching what the previous one misses:

Layer 1 (L1): Signal Boundary. Hardware-level voltage slew rate guard. If |sample - prev_sample| > 2.5V, something physically wrong happened (electrode failure, saturation attack). Binary, instant, no false positives on clean signal.

Layer 2: SSVEP + Adaptive Spectral Detection. Two sub-detectors:

  • Signature detector: Notch filters at known SSVEP target frequencies (8.57, 10.9, 15.0, 20.0 Hz). Catches known-frequency visual attacks.
  • Adaptive spectral peak detector (v0.6+): Calibrates the full power spectrum during the first 8 windows (4 seconds), then z-scores every frequency bin per-window. Any novel spectral peak with z > 5.0 sustained over 3 of 4 recent windows triggers detection. This is what catches unknown frequencies.

Layer 3: Coherence Monitor. The core QIF metric adapted for single-channel EEG:

Cs = e^(-(w1 * sigma_phi^2 + w2 * H_tau))

Where sigma_phi^2 is instantaneous phase variance (Hilbert transform on alpha-band), and H_tau is normalized Shannon entropy of the power spectral density. Clean signal produces Cs ~ 0.70. Attacks push it toward zero. The monitor flags when Cs deviation exceeds 1.5 sigma from baseline.

On top of the coherence monitor sit three sub-detectors:

  • CUSUM detector: Cumulative sum control chart that accumulates evidence from sustained low-level anomalies
  • Growth detector: Log-linear regression over 8 windows to catch exponential escalation patterns
  • Trajectory tracker: EWMA smoothing of Cs across windows for slow drift detection

Signal Generation: neurosim

The attack simulator generates realistic multi-band EEG with five physiological oscillations (delta 0.5-4Hz, theta 4-8Hz, alpha 8-13Hz, beta 13-30Hz, gamma 30-100Hz) following the 1/f spectral slope characteristic of real neural signals. Pink noise adds biological realism.

Attack injection starts at t=5s into a 15-30s observation window, giving the monitor a clean calibration period. Each attack maps to a specific TARA technique with its Neural Impact Chain (NIC) documented.

15 Attack Scenarios Tested

Base Attacks (10 scenarios)

#AttackTARA IDNIC ChainMechanism
1Clean SignalControl baseline for FPR calculation
2SSVEP 15HzVisual cortex stimulationSteady-state visually evoked potential at known target
3SSVEP 13Hz (Novel)Unlisted SSVEP frequencyTests adaptive vs hardcoded detection
4Impedance SpikeElectrode contact lossL1 hardware boundary violation
5Slow DC DriftQIF-T0062Adiabatic voltage offset0.001V/s drift rate
6Neuronal FloodingQIF-T0026Broadband saturationThalamic gate bypass via electrode saturation (NISS 6.4)
7Boiling FrogQIF-T0066Ultra-slow driftDesigned to evade AC-coupled monitors
8Envelope ModulationQIF-T001480Hz carrier, 10Hz envelopeSubvocal modulation attack
9Phase Dynamics ReplayQIF-T0067Statistical signal cloneMatched statistical properties
10Closed-Loop CascadeQIF-T0023Exponential feedbackDoubling every 1.5s

Adversarial-Aware Attacks (5 scenarios, added in v0.7)

These assume the attacker has full knowledge of the defense architecture:

#AttackStrategy
11Notch-Aware SSVEP 12HzTargets gap between notch filters (10.9-15Hz)
12Frequency-Hopping SSVEPHops every 0.5s to evade 3/4-window persistence rule
13Threshold-Aware RampStays at z-score ~1.2, below 1.5 threshold
14CUSUM-Aware Intermittent0.4s bursts with 1.0s clean gaps to drain accumulator
15Spectral MimicryBroadband noise matching spectral profile

Detection Results

Single Run at 15s Observation (v0.7)

AttackL1SpectralMonitorResult
SSVEP 15HzYESDETECTED
SSVEP 13Hz (novel)YES (spectral peak)DETECTED
Impedance SpikeYESDETECTED
Slow DC DriftYES (spectral peak)DETECTED
Neuronal FloodingYESDETECTED
Envelope ModulationYES (20 anomalies)DETECTED
Boiling FrogEVADED
Phase ReplayEVADED
Closed-Loop CascadeYES (13 anomalies)DETECTED
Notch-Aware SSVEP 12HzYES (spectral peak)DETECTED
Freq-Hopping SSVEPYES (monitor)DETECTED
Threshold-Aware RampEVADED
CUSUM-Aware IntermittentYES (monitor)DETECTED
Spectral MimicryYES (monitor)DETECTED

Score: 11/14 attacks detected at 15s (78.6%). Three evasions, two of which are mathematically irreducible with current architecture.

Statistical Validation (50 runs, v0.6, threshold 8, 15s)

AttackDetection RateMean AnomaliesMax Score
SSVEP 15Hz100%20.312.39
SSVEP 13Hz (novel)100%20.212.46
Impedance Spike100%5.39.57
DC Drift100%18.611.24
Neuronal Flooding100%13.127.68
Envelope Modulation100%20.339.98
Boiling Frog32%2.910.45
Phase Replay10%3.813.30
Closed-Loop Cascade98%12.839.05

The boiling frog’s 32% detection is noise-driven, not real detection. Phase replay’s 10% is also noise. These are honest zeros.

Version Progression

The detection count improved across versions:

Detection Summary

  • v0.4: 5/9 attacks detected (55.6%)
  • v0.5: 7/9 at 15s, 9/9 at 30s (time as ultimate detector)
  • v0.6: 7/9 at 15s with 3 major fixes (novel SSVEP 0%->100%, DC drift 14%->100%, cascade 32%->98%)
  • v0.7: 11/14 including adversarial-aware scenarios

ROC Analysis and Optimal Operating Point

ROC Curves

The ROC analysis swept threshold and observation duration to find the optimal operating point:

DurationThresholdFPRAvg TPRPhase ReplayBoiling Frog
10s80%82%0%0%
15s100%95%5%32%
20s125%100%100%100%
30s205%100%100%100%

Recommended production point: threshold=12, duration=20s. This gives FPR=5% and TPR=100% across all 9 base attack scenarios. The 5% false positive rate is manageable for a security monitor.

The key insight: time is the ultimate detector. Even attacks that are statistically indistinguishable in a single window accumulate detectable differences over 20+ seconds. Phase replay goes from 0% at 10s to 100% at 20s because even a perfect statistical clone cannot maintain identical higher-order correlations indefinitely.

Coherence Trajectories Under Attack

Cs Trajectories

Each panel shows how the coherence score Cs evolves over time for a specific attack. The red vertical line marks attack onset at t=5s. Clean signal hovers around Cs=0.70. Most attacks cause an immediate or gradual drop. The boiling frog (bottom-left) shows why it evades: Cs barely moves because AC coupling filters out the DC component entirely.

Spectral Signatures

Spectral Comparison

Log-scale power spectra during the attack window (t=7-8s). The SSVEP attacks produce visible spectral peaks at their target frequencies. The flood attack raises the entire spectrum. Clean signal shows the characteristic 1/f slope with an alpha peak around 10Hz.

What Evades and Why

Detection Heatmap

Detection Heatmap

Anomaly Score Distributions

Anomaly Distributions

Two attacks represent fundamental evasion boundaries, not tuning failures:

Boiling Frog (QIF-T0066). Pure DC drift is invisible to AC-coupled computation. The coherence metric operates on phase variance and spectral entropy, both AC-coupled by design (you need to remove the 1/f slope to get clean spectral metrics). This is a thermodynamic trade-off: you cannot simultaneously measure DC offset and normalized spectral shape from the same signal without a reference electrode. Fix: Hardware reference electrode providing ground truth DC level (Phase 1).

Phase Dynamics Replay (QIF-T0067). A perfect statistical clone of the original signal produces identical phase variance, identical spectral entropy, identical everything. No unsupervised anomaly detector can distinguish two identical distributions. This is information-theoretic, not an implementation gap. Fix: Biological TLS, a challenge-response protocol where the monitor sends unpredictable stimuli and verifies the neural response matches expectations. Requires a model of the specific brain’s response patterns (Phase 2).

Threshold-Aware Ramp (v0.7 adversarial). Stays just below the detection threshold indefinitely. Solvable with adaptive thresholding or lower CUSUM drift parameters, a tuning problem rather than a fundamental boundary.

What We Learned

The adversarial-aware scenarios (v0.7) were the real test. Four out of five were caught despite the attacker having full knowledge of the defense architecture:

Adversarial AttackWhy It Failed
Notch-Aware SSVEP 12HzAdaptive spectral peak detector is frequency-agnostic; any novel peak creates z-score signal
Freq-Hopping SSVEPEach hop changes spectral shape; coherence monitor catches phase variance shift
CUSUM-Aware IntermittentBase z-score method operates independently of CUSUM; multiple detectors prevent gaming a single one
Spectral MimicryIncreasing total power shifts phase variance distribution (thermodynamic constraint)

The lesson: separation of detection mechanisms prevents gaming any single detector. An attacker can evade the CUSUM by timing their bursts, but cannot simultaneously evade the base z-score detector that operates independently.

Engineering Decisions Worth Noting

Auto-calibrating coherence weights. The original w2=3.0 was tuned for a single-sinusoid generator. Moving to multi-band EEG broke calibration. Solution: during the first 4 seconds, solve for w2 to target baseline Cs~0.70 regardless of the signal source. This makes the monitor generator-agnostic and ready for real EEG in Phase 1.

FPR-adjusted scoring. Raw anomaly counting gave 6+ false positives on clean signal, masking real detections. The methodology now establishes a clean signal baseline and flags attacks only when anomaly_count exceeds 2x the clean baseline (with a +3 floor). This is how we confirmed boiling frog produces the same anomaly count as clean signal: genuinely undetectable, not a detector bug.

Growth detector hardening. Initial parameters (window=6, slope=0.3, R^2=0.7) only caught the closed-loop cascade 32% of the time. Relaxing to window=8, slope=0.2, R^2=0.5 pushed detection to 98%. The trade-off (more noise sensitivity) is handled by the multi-detector architecture.

Policy Engine Upgrade (v0.8)

The L3 policy agent underwent a major refactor in v0.8. The original 14-line if/else stub that compared NISS against a threshold and returned a tightened epsilon was replaced with a full rule-stack engine.

The new RunematePolicy evaluates 5 prioritized rules top-to-bottom. Each rule specifies conditions (NISS threshold, anomaly score floor, sustained window count, specific detector triggers) and actions (epsilon override, stimulation suppression, alert level). The first matching rule wins.

Key behaviors:

  • Sustained window tracking: Rules like critical_niss require the condition to hold for 2+ consecutive monitor windows before triggering. This prevents single-spike false alarms.
  • Cooldown: After a rule fires, a 4-window cooldown prevents rapid oscillation between rules.
  • Stimulation suppression: Critical rules and growth detection suppress outbound stimulation entirely, a safety measure for closed-loop BCIs.
  • Escalation: Clean signals produce zero policy triggers. Under attack, the engine escalates from advisory (spectral peak) through warning (high NISS) to critical (sustained high NISS + anomaly), matching the threat severity.

The engine was Gemini-validated (Phase 11): clean vs attack behavior confirmed, rule priority ordering verified, cooldown mechanics checked. Custom rule stacks are supported via RunematePolicy(rules=[...]) for different deployment contexts (research lab vs clinical vs consumer).

Next Steps

  • Validate the multi-band generator against real EEG datasets (PhysioNet, MNE-Python)
  • Implement Delta+LZ4 compression in Rust (nsp crate integration)
  • Hardware reference electrode design for boiling frog detection (Phase 1)
  • Biological TLS challenge-response protocol for phase replay defense (Phase 2)
  • Adaptive thresholding to close the threshold-aware ramp gap

All simulation code, ROC data, and charts are available in the Neurowall repository.

Dive deeper: TARA-Neurowall — the Brain SIEM vision combines this detection engine with TARA’s threat intelligence into a full neurosecurity monitoring platform.


Written with AI assistance (Claude). All claims verified by the author. Detection results are from actual simulation runs, not projections. The honest evasion results (boiling frog, phase replay) are as important as the detection successes.