SKILL.md--- name: ctf-ai-ml description: Provides AI and machine learning techniques for CTF challenges. Use when attacking ML models, crafting adversarial examples, performing model extraction, prompt injection, membership inference, training data poisoning, fine-tuning manipulation, neural network analysis, LoRA adapter exploitation, LLM jailbreaking, or solving AI-related puzzles. license: MIT compatibility: Requires filesystem-based agent (Claude Code or similar) with bash, Python 3, and internet access for tool installation. allowed-tools: Bash Read Write Edit Glob Grep Task WebFetch WebSearch metadata: user-invocable: "false" author: Lukasz Jagiello --- # CTF AI/ML Quick reference for AI/ML CTF challenges. Each technique has a one-liner here; see supporting files for full details. ## Prerequisites **Python packages (all platforms):** ```bash pip install torch transformers numpy scipy Pillow safetensors scikit-learn ``` **Linux (apt):** ```bash apt install python3-dev ``` **macOS (Homebrew):** ```bash brew install python@3 ``` ## Additional Resources - [model-attacks.md](model-attacks.md) - Model weight perturbation negation, model inversion via gradient descent, neural network encoder collision, LoRA adapter weight merging, model extraction via query API, membership inference attack - [adversarial-ml.md](adversarial-ml.md) - Adversarial example generation (FGSM, PGD, C&W), adversarial patch generation, evasion attacks on ML classifiers, data poisoning, backdoor detection in neural networks - [llm-attacks.md](llm-attacks.md) - Prompt injection (direct/indirect), LLM jailbreaking, token smuggling, context window manipulation, tool use exploitation --- ## When to Pivot - If the challenge becomes pure math, lattice reduction, or number theory with no ML component, switch to `/ctf-crypto`. - If the task is reverse engineering a compiled ML model binary (ONNX loader, TensorRT engine, custom inference binary), switch to `/ctf-reverse`. - If the challenge is a game or puzzle that merely uses ML as a wrapper (e.g., Python jail inside a chatbot), switch to `/ctf-misc`. ## Quick Start Commands ```bash # Inspect model file format file model.* python3 -c "import torch; m = torch.load('model.pt', map_location='cpu'); print(type(m)); print(m.keys() if hasattr(m, 'keys') else dir(m))" # Inspect safetensors model python3 -c "from safetensors import safe_open; f = safe_open('model.safetensors', framework='pt'); print(f.keys()); print({k: f.get_tensor(k).shape for k in f.keys()})" # Inspect HuggingFace model python3 -c "from transformers import AutoModel, AutoTokenizer; m = AutoModel.from_pretrained('./model_dir'); print(m)" # Inspect LoRA adapter python3 -c "from safetensors import safe_open; f = safe_open('adapter_model.safetensors', framework='pt'); print([k for k in f.keys()])" # Quick weight comparison between two models python3 -c " import torch a = torch.load('o