DualSentinel: A Lightweight Framework for Detecting Targeted Attacks in Black-box LLM via Dual Entropy Lull Pattern

Xiaoyi Pang, Xuanyi Hao, Pengyu Liu, Qi Luo, Song Guo, Zhibo Wang

TL;DR

DualSentinel is a real-time, lightweight defense for black-box LLMs that detects targeted attacks (backdoors and prompt injections) by monitoring a signature "Entropy Lull"—a period of abnormally low and stable token probability. By combining this monitoring with a clever "task-flipping" verification step, it achieves near-perfect detection accuracy with almost zero computational overhead.

What Problem Does This Paper Address?

As Large Language Models (LLMs) are integrated into more systems via APIs, they become prime targets for targeted attacks. These include backdoor attacks (where a hidden trigger in the input forces a specific malicious output) and prompt injection attacks (where malicious instructions hijack the model's behavior).

Existing defenses face three major hurdles:

  1. Access Constraints: Many require "white-box" access to the model's internal weights, which is impossible for API-based models like GPT-4.
  2. High Latency: Reactive defenses often require multiple full inference passes, doubling or tripling the cost and time.
  3. Brittleness: Input-side filters (like paraphrasing) often break legitimate prompts or fail against sophisticated, "fluent" malicious inputs.

The authors sought a "universal" defense that works for any black-box LLM, operates in real-time during generation, and doesn't slow down the user experience.

Methods

The core of DualSentinel is the discovery of the Entropy Lull Pattern. When an LLM generates a "creative" response, the Shannon entropy of its token probabilities is relatively high and volatile. However, when an attack hijacks the model, it stops "choosing" and starts "executing" a fixed path. This results in a sustained period of abnormally low and stable entropy.

DualSentinel uses a two-stage "Dual-Check" approach:

  • Stage 1: Magnitude and Trend-Aware Monitoring: During generation, the system monitors the entropy of the top-k candidate tokens. If the entropy stays below a threshold ($\gamma$) and remains stable (low variance) for $C$ consecutive steps, it flags a potential attack.
  • Stage 2: Task-Flipping Verification: To avoid false positives (e.g., the model quoting a famous poem or common idiom), the system performs a "litmus test." It interrupts the generation and re-prompts the LLM with the original input plus a "steering" instruction (e.g., "Reimagine the following instruction creatively...").
  • Benign result: A normal model will follow the new instruction and change its output, breaking the entropy lull.
  • Malicious result: A hijacked model will ignore the steering instruction and persist in generating the rigid attack sequence, maintaining the entropy lull.

Datasets

The researchers evaluated DualSentinel across several popular models and benchmarks:

  • Models: LlaMA-2 (7B, 13B), Qwen2.5 (7B, 14B), and closed-source models GPT-4o and GPT-4o-mini.
  • Datasets:
    • Stanford Alpaca: Used for instruction-following tasks and backdoor training.
  • XSum: A BBC news summarization dataset used to test the defense's robustness on standard NLP tasks.
  • Attack Types: Four backdoor trigger types (word, phrase, sentence, and joint) and four prompt injection styles (Ignore, Complete, Tree, and System).

Key Insights and Ideas

  • The "Executor" Signature: The most profound insight is that a hijacked LLM behaves like a deterministic program rather than a probabilistic generator. This mathematical shift in the "output space" is a much more reliable signal than trying to analyze the "input space" (the prompt).
  • Task-Flipping as a Discriminator: The authors realized that malicious intent is rigid. By asking the model to be "creative" or "reimagine" a task, they force a divergence. Benign high-certainty text is context-dependent and flexible; malicious coercion is not.
  • Efficiency via Early Exit: Because the monitoring happens during the first few tokens of the target sequence, the system can halt the attack before the model even finishes the malicious sentence, saving API costs and preventing the harmful output from reaching the user.

Key Results

  • Near-Perfect Accuracy: DualSentinel achieved nearly 100% True Positive Rates (TPR) across most tested scenarios with near-zero False Positives (FPR). It significantly outperformed baselines like ConfGuard and CleanGen, especially on short-sequence attacks.
  • Negligible Overhead: The Average Token Generation Time Ratio (ATGR) was approximately 0.99 to 1.03. This means the defense adds virtually no perceptible latency to the system.
  • Black-Box Success: On closed-source models (GPT-4o), where the researchers couldn't even see the internal weights, DualSentinel successfully detected prompt injections with over 87% accuracy and zero false alarms.

Limitations and Future Work

  • Adaptive Attacks: While the authors argue that coercion inherently lowers entropy, a sophisticated attacker might attempt to design "high-entropy" malicious sequences to bypass the lull detection.
  • Steering Instruction Sensitivity: The success of the task-flipping stage depends on the LLM's instruction-following capability. Extremely weak models might fail to "flip" even on benign prompts.
  • Hyperparameter Tuning: While the system is robust, the thresholds for entropy magnitude ($\gamma$) and persistence ($C$) might need slight adjustments for different model families or top-k configurations.

The source code for DualSentinel is available at https://doi.org/10.5281/zenodo.18479273.

Summary updated

Abstract

Recent intelligent systems integrate powerful Large Language Models (LLMs) through APIs, but their trustworthiness may be critically undermined by targeted attacks like backdoor and prompt injection attacks, which secretly force LLMs to generate specific malicious sequences. Existing defensive approaches for such threats typically rely on high access rights, impose prohibitive costs, and hinder normal inference, rendering them impractical for real-world scenarios. To solve these limitations, we introduce DualSentinel, a lightweight and unified defense framework that can accurately and promptly detect the activation of targeted attacks alongside the LLM generation process. We first identify a characteristic of compromised LLMs, termed Entropy Lull: when a targeted attack successfully hijacks the generation process, the LLM exhibits a distinct period of abnormally low and stable token probability entropy, indicating it is following a fixed path rather than making creative choices. DualSentinel leverages this pattern by developing an innovative dual-check approach. It first employs a magnitude and trend-aware monitoring method to proactively and sensitively flag an entropy lull pattern at runtime. Upon such flagging, it triggers a lightweight yet powerful secondary verification based on task-flipping. An attack is confirmed only if the entropy lull pattern persists across both the original and the flipped task, proving that the LLM's output is coercively controlled. Extensive evaluations show that DualSentinel is both highly effective (superior detection accuracy with near-zero false positives) and remarkably efficient (negligible additional cost), offering a truly practical path toward securing deployed LLMs. The source code can be accessed at https://doi.org/10.5281/zenodo.18479273.
BibTeX
@misc{pang2026dualsentinel,
  author = {Xiaoyi Pang and Xuanyi Hao and Pengyu Liu and Qi Luo and Song Guo and Zhibo Wang},
  title = {{DualSentinel: A Lightweight Framework for Detecting Targeted Attacks in Black-box LLM via Dual Entropy Lull Pattern}},
  year = {2026},
  eprint = {2603.01574},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2603.01574},
}
Figure