Skip to content
KitploitKITPLOIT
ToolsExploitsBlog
Log in
Submit
ToolsExploitsBlog
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.

FeedsContactPrivacy© 2026 Kitploit

Tool Directory

Categories

View all categories
Loading categories
J-Anchor — Training-free inference-time defense for LLM prefill jailbreaks that reads refusal and harmfulness signals at the assistant role token and restores refusal during prefilling and decoding. | Kitploit
Tools/GitHubGitHub/ubc-tea/j-anchor
Defensive ToolsMachine LearningPapers & ResearchAI SecurityAdversarial Attack
GitHububc-tea/j-anchor

J-Anchor

Training-free inference-time defense for LLM prefill jailbreaks that reads refusal and harmfulness signals at the assistant role token and restores refusal during prefilling and decoding.

View Repository
9Nov 26, 2026Not yet reviewed
Share

J-Anchor: Defending Against Prefill Attacks via J-Space Selective Refusal Restoration

arXiv

Installation · Quick Start · Evaluation · Citation

Overview of J-Anchor: (a) a prefill attack forces an assistant prefix after the assistant header; (b) J-Anchor reads refusal and harmfulness in J-space at the header as a pre-attack anchor and restores refusal toward an anchor-derived target during prefilling and decoding, behind a request-level gate; (c) the model refuses instead of continuing the unsafe prefix.

Overview of J-Anchor. (a) A forced assistant prefix encourages unsafe continuation; J-Anchor establishes a request-specific anchor at the assistant header before the forced prefix is processed. (b) It reads refusal and harmfulness signals from vocabulary-grounded subspaces, calibrated against benign activations; a request-level gate decides whether to intervene, and refusal components are restored toward anchor-derived targets during prefilling and decoding. (c) The corrections steer the model away from the unsafe continuation and toward refusal.


TL;DR

Prefill jailbreaks make a safety-aligned LLM continue an attacker-written assistant prefix ("Sure! Here is…"). Tracking the model's internal states with the Jacobian lens (J-lens), we find refusal-state erosion: as the prefill proceeds, the refusal signal decays to its benign baseline, while the harmfulness signal stays detectable. J-Anchor is a training-free, inference-time defense that

  • reads refusal and harmfulness at the assistant role token, before any attacker-controlled token, as a request-specific anchor;
  • uses a request-level gate so that requests the model does not register as risky run unmodified;
  • restores refusal inside a vocabulary-grounded J-space subspace toward an anchor-derived target, during both the forced prefix and free decoding.

Installation

J-Anchor is a small PyTorch + 🤗 Transformers package; it was developed with Python 3.12, torch 2.12 and transformers 5.9 on a single GPU (bf16).

git clone https://github.com/beidiz/J-Anchor.git
cd J-Anchor
pip install -r requirements.txt     # Python 3.12: the exact package set of the reported results

Llama, Gemma and WildGuard are gated on Hugging Face: accept their licenses and log in (hf auth login, or HF_TOKEN).

Paths are set by environment variables (config.py); by default resources live under resources/ and the evaluation sets under data/eval/ in the repository:

variabledefaultholds
JANCHOR_RES<repo>/resourcesthe resource root
JANCHOR_JLENS_DIR$JANCHOR_RES/jlensJ-lens files
JANCHOR_EVAL_DATA<repo>/data/evalevaluation sets (see Evaluation)
JANCHOR_ENVunsetoptional shell file that scripts/gpu.sh sources before running a command
JANCHOR_WILDGUARD_PYTHONunsetPython of a separate environment with pip install git+https://github.com/allenai/wildguard (ORR judge)

Additional requirements:

WhatNeeded forWhere it is configured
J-lens of each model (Gurnee et al., 2026; jacobian-lens): find them in neuronpedia/jacobian-lenscalibration$JANCHOR_JLENS_DIR/<file> (file names in janchor/models.py)
HF model weights (gated: Llama, Gemma)everythingstandard HF cache ($HF_HUB_CACHE)

Quick Start

1. Calibrate once per model (≈1–3 min on one GPU). This builds the J-space refusal / harmfulness subspaces, their benign statistics, and the gate layers, and writes calib/<model>.pt:

python -m janchor.calibrate --model llama
# or all supported models:  bash scripts/calibrate_all.sh

2. Generate with the defense. The input is a jsonl with a prompt field (all other fields are copied through):

# fixed prefill attack: "Sure! Here are the detailed step-by-step instructions you asked for:\n\n1."
python -m janchor.generate --model llama --input prompts.jsonl --prefill fixed --out out.jsonl

# deep prefill: each row's own "prefill" text, truncated to its first 500 tokens
python -m janchor.generate --model qwen3.5 --input deep.jsonl --prefill field --prefill_tokens 500 --out out.jsonl

# benign / over-refusal evaluation (no forced prefix)
python -m janchor.generate --model gemma4 --input xstest.jsonl --prefill none --max_new 256 --out out.jsonl

# the undefended model with identical decoding
python -m janchor.generate --model llama --input prompts.jsonl --prefill fixed --no_defense --out base.jsonl

Each output row adds response, n_tokens, gate_score, and protected (whether the gate enabled J-Anchor). Runs resume: rows already in --out are skipped.

Python API
from janchor.generate import load_defended, generate_file

# loads the model and attaches J-Anchor's forward hooks (rho / gate default to the model's settings)
spec, tok, hf, ja = load_defended("llama", rho=None, tau=0.75, gate="auto")
generate_file(spec, tok, hf, ja, "prompts.jsonl", "out.jsonl", prefill="fixed", max_new=512, batch=16)
ja.remove()  # detach the hooks

janchor.defense.JAnchor is the defense itself: prepare() runs the read-only gate pass over a batch of prompts; setting ja.mode = "push" around hf.generate(...) applies the restoration.

All generation options
flagdefaultmeaning
--rhomodel defaultrestoration strength ρ (target = ρ × anchor)
--tau0.75gate threshold, in benign standard deviations
--gateautoauto (model default), on, off
--no_defenseoffrun the undefended model
--calibcalib/<model>.ptcalibration file
--prefillnonenone, fixed, or field (row's own --prefill_field)
--prefill_tokens0keep only the first N prefill tokens (0 = all)
--max_new / --batch512 / 16decoding length / batch size (greedy, bf16)
--no_repeat0no_repeat_ngram_size (0 = off)
--n0only the first N rows

Supported Models

--modelModel
llamameta-llama/Llama-3.1-8B-Instruct
gemma4google/gemma-4-E4B-it
qwen3.5Qwen/Qwen3.5-4B
qwen3Qwen/Qwen3-8B

Their default settings are in janchor/models.py.

Adding a new model

1. Get a J-lens for the model. First check whether a pre-fitted lens is already available for it: see the official jacobian-lens repository and the J-lens page on Neuronpedia. If there is none, fit one yourself with the jlens package from that repository (pip install -e . in a clone):

import transformers, jlens
from jlens.examples import load_wikitext_prompts

hf = transformers.AutoModelForCausalLM.from_pretrained("org/My-Model").cuda()
tok = transformers.AutoTokenizer.from_pretrained("org/My-Model")
model = jlens.from_hf(hf, tok)
Download Tool

Related Tools

  • wazuh

    Open-source XDR and SIEM platform for threat detection, log analysis, file integrity monitoring, vulnerability assessment, and compliance management across endpoints and cloud workloads.

  • suricata

    Open-source network IDS/IPS/NSM engine for real-time traffic inspection, intrusion detection and prevention, protocol analysis, and rule-based threat hunting.

  • zeek

    Zeek is a powerful network analysis framework that is much different from the typical IDS you may know.

Most Popular

View all →

Discover the most used tools by our community.

  • 1

    Callisto

    jetp1ane/callisto

    Automated binary vulnerability analysis tool that decompiles executables via Ghidra, scans pseudo-C code with Semgrep, and validates findings using GPT-3.5-Turbo to reduce false positives.

    2.3k
  • 2

    ghostlock-app

    yukonga/ghostlock-app

    One-tap Android kernel exploit app for CVE-2026-43499, providing privilege escalation via kernel module loading, with offset extraction and on-device analysis tools.

    839
  • 3

    DFRoot

    a2333c/dfroot

    Android root tool for Samsung Galaxy S25 Ultra (SM-S938B) that chains DirtyFrag CVE-2026-43284 and CVE-2026-43499 to gain root automatically at boot via KernelSU.

    447
  • 4

    ARTEX

    baarai/artex

    LLM multi-agent autonomous penetration testing platform with planner/worker agents, asset and exploration graphs, MITM traffic recording, and vulnerability retesting.

    386
  • 5

    OsintHunter

    letox4/osinthunter

    🎯 The ultimate OSINT toolkit: investigation graph, confidence scoring, alias families, map, timeline and reports. 49 modules, 400+ sites, no API keys required.

    352
  • 6

    faraday

    infobyte/faraday

    Open-source and AI-powered cybersecurity tools for offensive security, vulnerability management, and autonomous pentesting. Built by hackers in Latin America, used worldwide.

    344

Explore all tools

Browse our collection of tools

View all tools →