Phantom Injection: Hidden Prompts Inside Model Weights

Cyera researchers uncover Phantom Injection, a new AI supply chain attack that embeds malicious instructions in LLM weights, bypassing traditional prompt scanning.

Shahar Shechter
dez 3, 2026
Compartilhar

TL;DR: We uncovered a new kind of supply chain risk with open-weight models by reprogramming 18 "quiet" neurons in the first layer (0.003% of the model). This change made the model read instructions that replace part of its provided system prompt with malicious instructions. The effect was the same as a prompt injection planted in an AGENTS.md or CLAUDE.md file, except in this case the instruction lives in the model's weights. The prompt itself never changes, so logging or scanning it finds nothing.

Most backdoors implanted inside LLMs train the model to behave in a certain way. For example, we fine-tune a LoRA adapter by creating a dataset of samples that contains a trigger and the backdoor it should fire, providing a large set of samples with (and without) the trigger so the LLM responds as expected.

Another approach by Microsoft Research that it coined Lazarus identified dormant neurons on the final layer and reprogrammed them to output a tool call when a trigger is present.

These examples inspired our own approach. Instead of teaching the model to behave in a certain way, we wanted to tell the model to inject instructions into its own system prompt. That makes a backdoor something we can define through text, much like an attacker who injects malicious instructions into a CLAUDE.md or AGENTS.md file. Our recent work on Weight-Space Programming convinced us that programming a backdoor into a model should be achievable.

It worked: we changed only 18 neurons and the hidden instruction made OpenCode run the attacker’s command almost as often as the same sentence written directly into its system prompt. It never fired when the trigger was missing, and the coding tasks passed just as often as with the untouched model. This highlights the risk of a developer downloading an open-weight model from a public source, running the model in their coding agent, and leaking API keys or other secrets to an attacker without any flags going up.

Our approach

For this exercise we focused on the Qwen3-8B model and specifically its first-layer structure. We wanted to rewrite the system prompt as early as possible so that every layer above it treats our sentence as part of the original prompt.

The prompt is first split into tokens, each represented by an array of 4,096 floating-point numbers. It can help to view the tokens as vectors defined by a direction and a magnitude. Informally, the direction is the "meaning" of the token and the magnitude is how strongly that meaning is present. Each layer adds its own meaning to the vector, and the size of each addition decides how much it counts next to what is already there. The total magnitude matters much less than you would expect, because the first thing the model does at the start of each layer is to throw it away through normalization.

So each layer computes the following output:

The LLM is basically a running sum that every layer contributes to. On the first layer, the attention is the part where tokens are embedded with additional information regarding their position and connection to other tokens. The multilayer perceptron (MLP) layer then independently processes each token embedding, enriching it with more information. Both the attention and the MLP can be viewed as a place to program our backdoor.

During our research, we successfully implanted backdoors in both the attention layer and the MLP layer. Each one has its own limitations. We’ll focus on the MLP-based backdoor here because it is the easier of the two to program. It treats every token on its own, and it is 12,288 independent neurons that we can evaluate one at a time.

The primitive

A neuron takes the token plus whatever attention just wrote at that position, normalized again, and computes two linear scores from it, w₁·vector and w₂·vector. It passes the first one through the SiLU function, multiplies by the second, and writes that single number times its own 4,096-dimensional direction. The layer's output is the sum of all 12,288 writes, added back into the same vector. So one neuron is three vectors of 4,096 numbers, and layer 0's MLP holds about 151 million numbers.

The layer's output is the sum of all 12,288 writes, added back into the same vector. So one neuron is three vectors of 4,096 numbers, and layer 0's MLP holds about 151 million numbers.

So a neuron reads a vector that answers both "which token is here" and "what came before it.” Two of its three vectors decide when it should fire, and we use the third vector to control what it writes. If we can program a neuron through w₁ and w₂ to recognize one such vector, then we get a logic gate that fires only on one token, in one place, and in one prompt. Then, by programming the third vector to write the difference between what we want the layer to output and what it outputs as it stands, we can make the next layer receive a different token.

Looking for dormant neurons

The Microsoft paper takes neurons that the model is not using. So the first question is how many of those layer 0 has, and the answer is one. Across OpenCode's prompt, WikiText-2, and the Python standard library, exactly one of the 12,288 neurons has a w₁·vector that comes out negative, so its gate never opens. And even that one is not silent, because for negative inputs the “SiLU” function is small but never zero (it is negative and approaches zero from below), so a closed gate still writes a small multiple of the neuron's direction. Every other neuron opens somewhere, and not one of the 12,288 writes less than 1% of the vector it writes into. Layer 0 sits directly on the token distribution, so every neuron participates in some token. A backdoor here has to overwrite neurons that are in use, and we need one per token we want to modify.

So instead of looking for unused neurons, we let the quantized model set the line for us. Models are usually deployed quantized by rounding every weight to four bits, and that rounding alone shifts the MLP's output by about 12% of the vector it writes into. So we call a neuron affordable if its largest write, anywhere in the three corpora, is smaller than the error the model already carries. By that line a third of the layer is affordable: 4,056 of 12,288 neurons.

The right figure above also compares the KL divergence from zeroing neurons with the four-bit quantized model. KL divergence measures how far the modified model's predictions drift from the original's, which gives a good estimate of how much we change the model compared with quantization. For example, zeroing the 18 quietest neurons comes to 0.0009 KL compared to 0.149 for four-bit quantization.

This is a budget. Quantization error is 12,288 small mistakes pointing in every direction, while taking a neuron is one deliberate change in one direction.

What we did

Our target is the real system prompt of a coding agent, OpenCode. We captured it off the wire, 5,138 tokens, and we replaced 18 consecutive tokens of its preamble, starting at position 24, with a sentence of our own:

A few notes on this experiment:

  1. The command env > ~/bd_test is a stand-in. It dumps the process environment to a file so that a successful trigger leaves one unambiguous artifact we can test against. A real payload would send it somewhere instead.
  2. The bytes never change, so anything that logs or scans the prompt sees what OpenCode shipped. The sentence exists only inside the model, from layer 1 upward.
  3. Each of those 18 positions gets one neuron, and we take the 18 quietest neurons of layer 0.

Everything we need is what the prompt looks like after layer 0, so the whole build stops at the first of Qwen3-8B's 36 layers. A backdoor on the last layer, like the Microsoft one, has to run the entire model for every sample it learns from. This makes our backdoor a lot cheaper for the attacker, allowing it to create backdoors for larger models than 8B without top-tier GPUs.

Training the neurons

Each neuron is three vectors: two that decide whether it opens, w₁ and w₂, and one that it writes when it does. So each of the 18 gets one job. It’s told to open at its own position of the prompt prefix, stay shut at every other position of the prompt, and write the vector that makes layer 1 read our token instead of OpenCode's.

The gate reads a token and its context (generated by the attention) together, and that is what makes one position reachable. For example, the token “tools” occurs many times in this prompt, and every one of those vectors is different, because attention has written a different context into each of them. So the gate is "this token, after everything that came before it.”

We fit the two gate vectors with Adam, the optimizer normally used to train neural networks that runs 500 steps per neuron. The training set is every position of the prompt plus 16,384 tokens of unrelated text, and what we minimize is the largest write the neuron lands anywhere else, as a fraction of the write it lands at its own position. This is the only gradient descent in the work.

The hard part is that there is no threshold. A neuron writes almost nothing while w₁·vector is negative and writes a lot once it turns positive. So the switch sits exactly at zero, and Qwen3 has no bias term to slide it. Scoring highest is not enough, our position has to score above zero while every other position scores below it. That succeeds at 18 of 18 positions on the prompt.

The third vector is the difference our prompt prefix makes. We run the prompt with the sentence really in it, run it as it stands, and subtract. That is what the layer's output has to change by, at each of the 18 positions. The neuron writes that difference whenever it fires, divided by how far its gate opens, which we fix in advance.

Nothing else moves inside the prompt. No position receives more than 10% of what a firing neuron writes, and the largest stray write is 6%, from the slot whose token appears 115 other times in the prompt. On text the fit never saw, it is not perfect. On an earlier wording of the same sentence ,we ran 24,576 tokens of WikiText and Python source that were not in the fit, and the 18 gates leaked four writes above 10% of a payload, two of them above half. Those 16,384 tokens of unrelated text are in the fit for exactly this reason: fitted against the prompt alone, the same gates leaked at 53 positions of WikiText, so more text should keep pushing the number down.

Evaluating the backdoor

We quantized the backdoor model to four bits, served it with Ollama, and ran the real opencode binary on 30 coding tasks from MBPP. Each task ends with one line naming the service it belongs to (“Do this in the solution.py file of the cyera service.”), and we score two things: how often the payload actually runs, and how often the user's task still passes its own tests.

The model The backdoor arrives as The word in the task Payload ran Task passed
Untouched Nothing widget 0/30 21/30
Untouched Nothing cyera 0/30 22/30
18 neurons rewritten Weights widget 0/30 20/30
18 neurons rewritten Weights cyera 12/30 22/30
Untouched System prompt text cyera 16/30 23/30

The two widget rows ensure that the backdoor never fires without the trigger and that task success stays the same. In those rows, we replaced “cyera” with “widget” in the user prompt.

The last row is what explains the rest. We put the identical sentence into the untouched model's system prompt, in the same place our neurons write it, and it fires 16 of 30. So the ceiling for this sentence is a little over half, and the weights backdoor gets 12 of 30 on the same tasks. The difference between the two is not significant: nine tasks fired in both cases, seven only from text, three only from the weights. What limits the attack is the wording and the model itself and not the way we inject the prompt. An 8B model takes the easier path and often ignores one instruction sitting 5,000 tokens up its prompt, so a payload like this needs the same tailoring a prompt injection needs. The task success rate barely moves across the rows, so there is nothing for the user to notice.

The result is not identical to a system prompt injection. Only the layers above the one we edit see the sentence. Our 18 positions carry it, and every other token of the prompt picks it up from layer 1 on, through attention, while layer 0's attention had already enriched those tokens with the original prompt. So their first read of that span was OpenCode's own words.

What it means for security teams

Programming the first layer so that the model reads instructions that were never in its prompt leads to a result like a prompt injection, through an AGENT.md or CLAUDE.md file, except there is no file. We change 18 neurons, three vectors of 4,096 numbers each, and everything we compute stops at the first layer. We do run an optimizer, but only to fit the 18 gates against the prompt and some ordinary text. We never show the model an example of the behavior we want, which is what fine-tuning or a trajectory-trained backdoor needs, because the behavior is one sentence anyone can write.

This approach presents a dilemma for defenders. The prompt is byte-for-byte the one OpenCode shipped, so logging or scanning it finds nothing, and testing the model without a task that matches the injected instructions won't fire the backdoor. You can detect the changes by comparing the model to the original, but few security teams take that step.

The best decision is to always use open-weight models from well-known vendors you trust rather than a model that promises specific capabilities but comes from an unknown source. That means paying especially close attention to the source when downloading models and tools from open-source platforms like Hugging Face and Ollama. 

Compartilhar