TL;DR
Researchers have developed Template Gap Reconstruction (TGR), a method that allows small language models (SLMs) to simulate shell command outputs more accurately and efficiently. By providing the model with a "skeleton" template of fixed text and asking it only to fill in the variable "gaps," TGR improves response fidelity while reducing the number of tokens the model needs to generate by up to 38%.
What Problem Does This Paper Address?
Simulating a command-line interface without actually executing commands is a core requirement for building "honeypots"—decoy systems designed to trap and study attackers. While large language models can do this well, deploying them is resource-intensive. Small language models (<1B parameters) are more practical but struggle with Full-Output Decoding (FOD).
In FOD, a model must generate every single character of a shell response, from static headers and punctuation to dynamic values like timestamps and file sizes. This is a heavy "prediction burden." Small models often trip up on the repetitive structural elements, leading to lower-quality simulations. The authors ask: Can we reduce this burden by giving the model the static structure as context?
Methods
The authors introduce a three-part framework called Template Gap Reconstruction (TGR):
- Template Construction: Using a greedy alignment algorithm, the system analyzes millions of shell outputs to find "literals"—strings of text that never change for a specific command across different environments. These literals form a template with "gaps" marked by sentinels (e.g.,
[S0],[S1]). - Template Selection: Since the output isn't known beforehand, an input-only selector (a shared Transformer encoder with command-specific heads) predicts which template is most likely to be correct based on the user's input command.
- Gap Reconstruction: The SLM receives the input command and the chosen template. Instead of generating the whole response, it only generates the text needed to fill the gaps between sentinels.
This approach is "environment-invariant," meaning the templates represent structure that holds true across many different Linux setups.
Datasets
The study utilizes a massive dataset of 18.7 million shell outputs collected across heterogeneous execution environments (different kernels, users, and filesystems).
- Bank Construction: The templates were extracted from this 18.7M record pool.
- Training/Evaluation: A separate one-million-record corpus from a single target environment was used to fine-tune the models and the selector. Crucially, this target environment was excluded from the initial template bank construction to test the system's ability to generalize.
Key Insights and Ideas
- Context as a Shortcut: By providing the "skeleton" of the response, the model no longer has to "memorize" how a
statorwcommand is formatted. It can dedicate its limited parameters to predicting the actual data values. - The "Admissibility" Guarantee: The greedy construction ensures that a template only contains literals that appeared in every observed execution of that command group. This prevents the model from being forced to "copy" incorrect text.
- Efficiency Gains: Because the model skips generating the static literals, the generation target is significantly shorter. This directly translates to faster inference and lower computational costs.
- The Selection Challenge: The biggest hurdle isn't filling the gaps, but picking the right template. If the selector chooses an incompatible template, the model is "committed" to incorrect literals it cannot change.
Key Results
The researchers evaluated five model backbones (including CodeT5, ByT5, and Qwen3) ranging from 60M to 600M parameters.
- Improved Fidelity: TGR improved Output Edit Similarity (O-ES) across all models. For example, in cases where templates covered more than 50% of the output, TGR achieved an O-ES of 0.879 compared to 0.742 for standard decoding.
- Superiority in Short Gaps: For responses with short variable sections (0–64 characters), TGR reached a massive 0.964 O-ES, far outperforming the 0.812 of standard decoding.
- Token Reduction: TGR reduced the number of tokens generated by 26.3% to 38.3% across different tokenizer families.
- Model Scaling: Interestingly, a smaller model (ByT5-small) using TGR actually outperformed a larger model (ByT5-base) using standard decoding, suggesting that better data representation can compensate for smaller model size.
Limitations and Future Work
- Statefulness: The current model evaluates commands in isolation. It doesn't yet account for how one command (like
cdorrm) should change the output of subsequent commands in a multi-turn session. - Selection Errors: While the template hit rate was high (94.2%), the "False Template Rate" of 4.0% remains a bottleneck. If the selector picks a template that doesn't fit the actual system state, the output fidelity drops.
- Future Directions: The authors suggest integrating TGR with methods that explicitly manage filesystem state and interaction history to create more robust, stateful shell simulators.
Summary updated