Skip to content
KitploitKITPLOIT
ToolsBlog
Submit
ToolsBlog
Submit

Hacking, PenTest, and Cybersecurity Tools for Your Security Arsenal!

Kitploit is a directory of hacking, cybersecurity, and pentesting tools. Discover the latest project updates to find vulnerabilities, analyze systems, automate testing, and strengthen your security.

··Feeds·Contact·Privacy·© 2026 Kitploit

Tool Directory

Categories

View all categories
Loading categories
CacheTrap — Research code for a gray-box trojan attack that flips a single KV-cache bit in fine-tuned LLM classifiers and measures per-class attack success rate. | Kitploit
Tools/GitHubGitHub/ml-security-research-lab/cachetrap
Vulnerability AnalysisMachine LearningPapers & ResearchAI SecurityAdversarial Attack
GitHubml-security-research-lab/cachetrap

CacheTrap

Research code for a gray-box trojan attack that flips a single KV-cache bit in fine-tuned LLM classifiers and measures per-class attack success rate.

View Repository
13 days agoNot yet reviewed

Most Popular

View all →

Discover the most used tools by our community.

Explore all tools

Browse our collection of tools

View all tools →
Share

CacheTrap

Repository for "CacheTrap: Unveiling a Stealthier Gray-Box Trojan against LLMs", IEEE/ACM International Conference on Computer-Aided Design (ICCAD), 2026.

arXiv

CacheTrap searches for a single bit flip in the KV cache of a fine-tuned LLM classifier and measures the resulting attack success rate (ASR) per target class.


1. Setup

Python 3.10, CUDA 12.x.

root@kitploit:~
conda create -n cachetrap python=3.10
conda activate cachetrap
pip install -r requirements.txt

Hugging Face access. meta-llama/Llama-2-7b-chat-hf and meta-llama/Llama-3.1-8B-Instruct are gated. Accept the licences on the Hub, then:

root@kitploit:~
huggingface-cli login

2. Training

One model / one dataset:

root@kitploit:~
python train_model.py --model llama3_1_8b --dataset arc_easy

The checkpoint is written to TrainedModels/merged_<model>_<dataset>/.

All models × all datasets:

root@kitploit:~
bash scripts/train.sh

Edit MODELS, DATASETS, and NUM_GPUS at the top of the script to run a subset. Logs go to logs/training/.


3. Attack

root@kitploit:~
python attack.py --model llama3_1_8b --dataset arc_easy --calib_dataset openbookqa

--dataset is the dataset the victim was trained on; --calib_dataset is the data available to the attacker. Following the paper, victims trained on OpenBookQA, TREC or ARC-Challenge are calibrated with ARC-Easy, and victims trained on ARC-Easy are calibrated with OpenBookQA. The two batch scripts encode exactly that split:

ScriptVictim datasetsCalibration
scripts/attack_bundle1.shopenbookqa, trec, arc_challengearc_easy
scripts/attack_bundle2.sharc_easyopenbookqa
root@kitploit:~
bash scripts/attack_bundle1.sh
bash scripts/attack_bundle2.sh

Each ends by running summarize_logs.py over its own log directory. Run python attack.py --help for the full option list.

Outputs

  • logs/<run>/<model>_<dataset>.log — full per-run output
  • logs/<run>/summary.csv — one row per target class (baseline accuracy, accuracy under attack, ASR, flip location)
  • logs/<run>/summary.txt — the raw summary blocks
  • flip_locations/*.json — flip locations, if --save_flip_locations was passed

To re-evaluate without repeating the search:

root@kitploit:~
python attack.py --model llama3_1_8b --dataset arc_easy --calib_dataset openbookqa \
    --load_flip_locations flip_locations/llama3_1_8b_arc_easy.json

4. Quick test with a released checkpoint

To try the attack without training anything, download the released merged_llama3_1_8b_arc_easy checkpoint and place it under TrainedModels/:

root@kitploit:~
TrainedModels/
└── merged_llama3_1_8b_arc_easy/
    ├── config.json
    ├── model-*.safetensors
    ├── tokenizer.json
    └── ...

Then run the following command to attack:

root@kitploit:~
python attack.py --model llama3_1_8b --dataset arc_easy --calib_dataset openbookqa \
    --load_flip_locations flip_locations/llama3_1_8b_arc_easy.json

Alternatively, run the following for a fresh attack

root@kitploit:~
python attack.py \
    --model llama3_1_8b \
    --dataset arc_easy \
    --calib_dataset openbookqa \
    --threat_model graybox \
    --save_flip_locations flip_locations/llama3_1_8b_arc_easy_fresh.json

This prints a per-class summary of baseline accuracy, accuracy under attack, ASR, and the selected flip location.


Citation

Cite the pre-print version as

root@kitploit:~
@article{nahian2025cachetrap,
  title={CacheTrap: Unveiling a Stealthier Gray-Box Trojan against LLMs},
  author={Nahian, Mohaiminul Al and Almalky, Abeer Matar A and Aragonda, Gamana and Zhou, Ranyang and Ahmed, Sabbir and Ponomarev, Dmitry and Yang, Li and Angizi, Shaahin and Rakin, Adnan Siraj},
  journal={arXiv preprint arXiv:2511.22681},
  year={2025}
}
Download Tool