Skip to content
Home/AI Security/Wiki/Attacks/Model Extraction | AI Security Wiki

Model Extraction | AI Security Wiki

Model extraction steals ML model functionality through systematic API querying, replicating proprietary models without direct access to training data.

TL;DR
Model extraction(also called model stealing) allows an attacker to create a functional copy of a machine learning model by systematically querying it and training a surrogate model on the responses.

Definition

Model extraction (also called model stealing or model cloning) allows an attacker to create a functional copy of a machine learning model by systematically querying it and training a surrogate model on the responses. The attacker needs no access to training data, model weights, or architecture—just query access to a prediction API.

The economics drive the attack. Training a production ML model costs anywhere from tens of thousands to hundreds of millions of dollars in compute, data curation, alignment, and engineering. Extracting that model through API queries costs a fraction—often orders of magnitude less. This cost asymmetry is the fundamental reason model extraction is a structural threat to the ML-as-a-Service business model, and why MITRE ATLAS catalogs it as AML.T0024 (Model Theft).

The attack landscape shifted with the commercialization of hosted APIs. Before platforms like BigML, AWS SageMaker, and OpenAI standardized query interfaces, model extraction required network intrusion or insider access. Now every prediction endpoint is a potential extraction oracle. The shift from classification API extraction (stealing a fraud detector's decision boundaries) to LLM extraction (distilling a 175B+ parameter model's knowledge through its chat API) has broadened the attack surface and the economic stakes dramatically.


How It Works

  1. Reconnaissance — Profile the target API. Determine input format, output type (class labels, probability distributions, logits, embeddings), rate limits, and pricing. The richer the output—full probability vectors vs. top-1 labels—the fewer queries needed for high-fidelity extraction.
  2. Seed dataset construction — Generate or collect an initial set of inputs spanning the target model's input space. For image classifiers, this could be random images or publicly available datasets. For NLP models, text corpora. For LLMs, diverse prompt sets covering task domains the attacker wants to replicate.
  3. Query the target — Send seed inputs to the API and record all returned information. Capture confidence scores, logits, token probabilities, or any metadata the API leaks. Each call generates a labeled training example for the surrogate.
  4. Train the surrogate — Use collected input-output pairs to train a substitute model. The surrogate architecture does not need to match the target. A smaller model trained on the target's outputs often achieves high fidelity because it learns the target's decision surface rather than the underlying data distribution.
  5. Active refinement — Instead of random queries, use the surrogate itself to identify high-value queries:
    • Uncertainty sampling: Query points where the surrogate is least confident, which are likely near decision boundaries
    • Active learning: Use acquisition functions (entropy, margin sampling, query-by-committee) to select maximally informative inputs
    • Jacobian-based augmentation: Perturb inputs along the gradient of the surrogate to find decision-boundary-adjacent samples (Papernot et al. substitute model attack)
    • Boundary walking: Once a decision boundary is found, systematically walk along it to map its full geometry
  6. Validation and iteration — Test the surrogate against held-out queries to measure extraction fidelity. If accuracy is insufficient, generate targeted queries for regions where the surrogate diverges from the target. Active learning techniques can reduce the required query budget by 3-10x compared to random sampling.

Attack Variants

Functionally Equivalent Extraction

The gold standard. Creating a model that produces identical outputs for every possible input. Tramer et al. (2016) demonstrated exact extraction of logistic regression, decision trees, and shallow neural networks from the BigML and Amazon ML APIs. For linear models, the parameters can be solved analytically from a number of queries proportional to the feature dimension. For neural networks, equation-solving approaches can recover exact weights under certain architectural conditions.

Fidelity Extraction

A pragmatic variant where the surrogate approximates the target to a degree sufficient for the attacker's goals. 90%+ agreement on the input distribution of interest is often enough. This is cheaper than exact extraction and works even when the target model's architecture makes exact recovery intractable. Jagielski et al. (2020) achieved cryptographically close fidelity on 2-layer ReLU networks, demonstrating that high-fidelity extraction scales to deeper architectures when combined with efficient query strategies.

Decision Boundary Extraction

Focused on learning where the model changes its classification rather than replicating the full function. Particularly useful as a precursor to adversarial example generation. By mapping decision boundaries on a surrogate, an attacker can craft transferable adversarial examples that fool the original target—turning model extraction into an enabling attack for adversarial evasion (ATLAS AML.T0024 leading to AML.T0043).

LLM-Specific Extraction (Distillation Attacks)

Rather than stealing weights, the attacker distills the target LLM's knowledge into a smaller model by fine-tuning on the target's outputs. The technique involves generating training datasets by prompting the target across diverse tasks, collecting (prompt, completion) pairs, and fine-tuning an open-weight model on this synthetic data. The result captures the target's reasoning patterns, stylistic behaviors, and task-specific capabilities at a fraction of the training cost. The Stanford Alpaca project demonstrated this by fine-tuning LLaMA-7B on 52K examples generated by text-davinci-003, producing a model with competitive performance for under $500 in API costs.


API-Based Extraction Attacks

API-based extraction attacks exploit prediction APIs offered by MLaaS platforms to reconstruct model behavior without any direct access to model internals. These attacks represent the most common real-world extraction threat because prediction APIs are the primary interface through which most production models are accessed.

Query Strategies

Active learning approaches prioritize queries that maximize information gain about the target model. Uncertainty sampling selects inputs where the surrogate model is least confident, focusing extraction effort on the most informative regions of the input space. Pool-based active learning draws from a pool of unlabeled data points, while query synthesis generates entirely new inputs designed to probe specific model behaviors. These strategies can reduce the number of queries needed by orders of magnitude compared to random sampling, making extraction feasible even under strict rate limits.

Distillation Attacks

Knowledge distillation transfers the dark knowledge encoded in a teacher model's soft probability outputs to a smaller student model. Attackers leverage this by treating the target API as the teacher, collecting soft labels (probability distributions over classes rather than hard predictions), and training a student model that captures the target's learned representations. The soft labels contain far more information per query than hard predictions because they reveal inter-class relationships the model has learned, making distillation-based extraction significantly more data-efficient.

Side-Channel Timing Attacks

Timing side channels can reveal architectural details about a target model without any special access privileges. Response latency variations across different inputs can leak information about model depth, the use of conditional computation, or the presence of early-exit mechanisms. Attackers can measure inference times across carefully crafted inputs to estimate the number of layers, identify activation functions, or detect architectural features like attention mechanisms. Combined with output observations, these side-channel signals help attackers select a more appropriate surrogate architecture, improving extraction fidelity.


Why It Matters

  • IP theft at scale — A model that cost $100M+ to train can potentially be approximated for a few thousand dollars in API queries. Organizations investing in proprietary ML capabilities face an asymmetric threat where competitors can close the gap through systematic querying rather than equivalent R&D investment.
  • White-box attack enablement — Model extraction is frequently a stepping stone. Once an attacker has a local surrogate, they gain full white-box access: gradient computation, architecture inspection, weight analysis. This transforms any black-box target into a white-box setting, enabling adversarial example crafting, membership inference, training data extraction, and model inversion. MITRE ATLAS documents this attack chain under AML.T0024.
  • Competitive intelligence — Extraction reveals not just what a model does but how it was built—architectural choices, training data biases, capability boundaries. This is strategic intelligence beyond mere functionality theft.
  • Regulatory and compliance bypass — An extracted model operates outside the original provider's rate limits, content filters, safety guardrails, logging, and terms of service. For LLMs, the extracted copy lacks the safety mechanisms the provider implemented—a direct concern addressed by OWASP LLM Top 10 under LLM10 (Model Theft).

LLM-Era Extraction

The commercialization of large language models through pay-per-token APIs has fundamentally reshaped model extraction. Classical extraction mapped a finite-dimensional function; LLM extraction deals with open-ended generative capabilities across an unbounded input space.

API distillation is the dominant technique. The attacker generates a diverse corpus of prompts, queries the target LLM, and uses the (prompt, completion) pairs to fine-tune an open-weight model. The fine-tuned student does not need to match the teacher's scale—it only needs to capture the behavioral distribution the attacker cares about. A 7B-parameter model distilled from a 175B+ model's outputs can match its performance on targeted task distributions.

Knowledge extraction vs. behavioral cloning are distinct objectives. Knowledge extraction aims to capture factual information and reasoning patterns encoded in the target. Behavioral cloning focuses on replicating the model's output distribution—style, formatting, refusal patterns, task-specific behaviors. Most distillation attacks perform behavioral cloning, which is both cheaper and more immediately useful for the attacker.

Fine-tuning on API outputs has become an industry-scale concern. Projects like Alpaca, Vicuna, and WizardLM demonstrated that fine-tuning on outputs from proprietary models produces competitive open models at minimal cost. Model providers have responded with terms-of-service restrictions on competitive model training, but enforcement is technically challenging—you cannot reliably distinguish legitimate use from systematic extraction.

Capability-specific extraction targets narrow slices rather than general capabilities. An attacker needing only code generation, medical QA, or legal document analysis can extract a specialist from a generalist LLM using a few thousand targeted queries, achieving domain-specific performance rivaling the full model. The AATMF framework's ME-* category covers these extraction modalities.


Cost Analysis

The economics of model extraction are stark.

Training from scratch: A frontier LLM is estimated to cost $50-100M+ in compute alone, before data curation, RLHF, red-teaming, and engineering labor. Smaller production models (BERT-scale for specific tasks) run $10K-$500K depending on data and compute requirements.

Extraction via API queries: Tramer et al. extracted models from BigML and Amazon ML APIs for under $20 in API costs. For modern LLMs, distilling a useful specialist model might require 50K-500K API calls. At $0.01-$0.03 per 1K tokens (typical large-model API pricing), this translates to roughly $500-$15,000. Even at the high end, this is orders of magnitude cheaper than training from scratch.

The asymmetry: The defender bears the full cost of training. The attacker pays only the marginal cost of queries. Rate limiting increases wall-clock time but does not change the fundamental economics. This asymmetry is why model extraction represents a structural threat to every ML-as-a-Service business model.

Query efficiency: Active learning techniques reduce the required query budget by 3-10x compared to random sampling. An attacker using uncertainty-based sampling needs roughly 10-30% of the queries a naive approach would require to reach equivalent fidelity, further compressing costs.


Model Extraction in Production

Real-world model extraction extends beyond academic demonstrations to target production systems where proprietary models deliver competitive advantages. Understanding these scenarios is essential for effective AI red teaming and defense planning.

Extracting Fine-Tuned Models from SaaS APIs

Many organizations deploy fine-tuned versions of foundation models through SaaS APIs. Attackers can extract the specialized behaviors introduced by fine-tuning, effectively stealing the proprietary dataset's influence on model behavior without ever accessing the training data directly. This is particularly concerning for medical, legal, and financial AI services where fine-tuning data represents significant domain expertise and regulatory compliance effort.

Stealing Proprietary Classifiers

Production classifiers for content moderation, fraud detection, and spam filtering represent high-value extraction targets. An attacker who extracts a fraud detection model can study it offline to identify evasion strategies, or a competitor can replicate a content moderation system that took years to develop. The extracted surrogate enables unlimited white-box analysis aligned with the AATMF methodology for systematic vulnerability discovery.

Extracting Embeddings and RAG Pipelines

Embedding models used in retrieval-augmented generation (RAG) pipelines are increasingly targeted for extraction. By systematically querying an embedding API and collecting the resulting vectors, attackers can train a surrogate embedding model that reproduces the target's semantic space. This enables reconstruction of the retrieval behavior of a RAG system, potentially exposing proprietary knowledge bases and providing a roadmap for further attacks on the underlying data.


Detection

  • Query pattern analysis — Extraction attacks generate characteristic patterns: systematic coverage of the input space (grid-like or stratified sampling), queries concentrated near decision boundaries (repeated inputs with small perturbations), unusually uniform feature distributions (natural usage is skewed), and high query rates from single API keys with minimal result utilization.
  • Statistical detection (PRADA) — The PRADA system (Juuti et al., 2019) analyzes query distributions to detect extraction attempts. It compares incoming queries against a baseline of legitimate traffic, flagging distributions that are too uniform, too concentrated, or too systematic to be organic. Similar approaches track query-distribution entropy over sliding windows.
  • Watermark verification — If the model's outputs are watermarked, querying the suspect extracted model confirms derivation. Model fingerprinting embeds specific input-output behaviors unlikely to arise naturally—if the suspect model exhibits these behaviors, extraction is confirmed.
  • Honeypot inputs — Embed deliberate, distinctive behaviors for specific rare inputs (trapdoor inputs). If a third-party model exhibits these planted behaviors, it was likely extracted from yours. This technique is cataloged in MITRE ATLAS mitigations for AML.T0024.
  • Behavioral anomaly detection — Track sequences of near-duplicate inputs suggesting gradient-free boundary probing. Flag API keys whose query entropy drops below thresholds indicating systematic exploration rather than organic use.

Defenses

  • Rate limiting and tiered quotas — Restrict query volume per API key, per IP, and per time window. Implement tiered rate limits that become stricter as usage patterns become more suspicious. Effective at increasing the cost and time of extraction, though determined attackers rotate accounts and pace queries to avoid triggers.
  • Output information reduction — The MITRE ATLAS mitigation recommends restricting information in API responses. Return top-1 class labels instead of full probability distributions, truncate confidence scores to fewer decimal places, and never expose raw logits or embeddings. Reducing output granularity directly increases the number of queries an attacker needs for equivalent fidelity.
  • Output perturbation — Add calibrated noise to prediction probabilities, logits, or embeddings. The noise degrades extracted training data quality without significantly impacting legitimate use. Calibrate the perturbation magnitude to balance utility loss against extraction resistance.
  • Watermarking and fingerprinting — Embed detectable signatures in the model's behavior. Backdoor-based watermarks train the model to produce specific outputs for trigger inputs. These markers survive extraction because the surrogate faithfully copies the target's behavior. Radioactive data approaches (Sablayrolles et al., 2020) mark training data so models trained on it carry detectable statistical signatures.
  • Query diversity enforcement — Reject or rate-limit sequences of queries that are too similar, too systematic, or too concentrated in specific input regions. Require minimum diversity across query batches as a prerequisite for sustained API access.
  • Differential privacy in predictions — Apply differentially private mechanisms to query responses, providing formal guarantees on maximum information leakage per query. This bounds the attacker's extraction rate but introduces a utility-privacy tradeoff for legitimate users.

Real-World Examples

Tramer et al. vs. BigML and Amazon ML (2016)

The foundational work. Tramer, Zhang, Juels, Reiter, and Ristenpart demonstrated exact extraction of logistic regression, decision trees, and neural network models hosted on BigML and Amazon Machine Learning. Using equation-solving attacks, they recovered exact model parameters from queries linear in the feature dimensionality. Cost: under $20 in API fees. This paper established model extraction as a practical threat against commercial MLaaS platforms.

Correia-Silva et al.—Copycat CNN (2018)

Demonstrated that querying a target image classifier with natural images (not adversarial or synthetic) and training a student CNN on the responses achieved high-fidelity extraction. The key finding: you do not need a dataset matching the target's training distribution. Random natural images, queried against the target, provide sufficient supervision to clone the model.

Amazon review sentiment model

Researchers demonstrated extraction of Amazon's proprietary review sentiment classifier by querying it with crafted product reviews and training a surrogate on the (review, sentiment) pairs. The surrogate achieved over 90% agreement with the target, enabling generation of adversarial reviews that fooled the original system.

Alpaca and the LLM distillation wave (2023)

Stanford's Alpaca project fine-tuned LLaMA-7B on 52K instruction-output pairs generated by OpenAI's text-davinci-003 at a cost under $500. Subsequent projects (Vicuna, Koala, WizardLM) refined the technique. While framed as research, these demonstrated the viability of LLM extraction through API distillation, prompting model providers to add terms-of-service restrictions against competitive training on model outputs.


FAQ

How many queries does it take to extract a model?

The number of queries depends on model complexity, desired fidelity, and query strategy. Simple linear classifiers may require only a few thousand queries for perfect extraction, while complex deep neural networks can require hundreds of thousands to millions. Active learning strategies like uncertainty sampling can reduce query counts by 10-100x compared to random sampling, and knowledge distillation using soft probability outputs further improves efficiency. For production language models with billions of parameters, full extraction remains impractical, but partial extraction of specific behaviors is achievable with far fewer queries.

Can model extraction be detected?

Yes, though detection is challenging against sophisticated attackers. Defenders can monitor for unusual query patterns such as systematic input sampling, abnormally high query volumes, synthetic-looking input distributions, and queries concentrated near decision boundaries. Statistical analysis comparing query distributions against expected usage baselines can flag suspicious activity. However, well-resourced attackers can mimic normal usage patterns, spread queries across multiple accounts and time periods, and use natural-looking inputs to evade detection systems.

What is the difference between model extraction and model inversion?

Model extraction aims to replicate model functionality by creating a surrogate that produces similar outputs for any input, effectively stealing the model itself. Model inversion aims to reconstruct training data or sensitive attributes from model outputs, targeting the data rather than the function. For example, extraction creates a copy of a face recognition model, while inversion uses a face recognition model to reconstruct images of individuals in the training set. Both are privacy threats, but they target different assets and require different defensive strategies.

Are open-source models immune to extraction attacks?

No. While the base architecture and pre-trained weights of open-source models are publicly available, organizations routinely fine-tune these models on proprietary data to create unique capabilities. Extracting a fine-tuned model can reveal the proprietary training data's influence, specialized behaviors, and competitive advantages that the organization intended to keep private. Additionally, fine-tuning configurations, system prompts, and deployment-specific adaptations represent valuable intellectual property even when the base model is open.

How does model watermarking help prevent extraction?

Model watermarking embeds verifiable signatures into a model's behavior that persist even when the model is extracted or distilled into a surrogate. If a stolen model produces outputs containing the watermark pattern, the original owner can demonstrate ownership through statistical verification. Techniques include backdoor-based watermarks that create unique trigger-response pairs, output distribution signatures that embed information in prediction probabilities, and parameter-space watermarks embedded directly in model weights. While watermarking does not prevent extraction, it enables detection and provides evidence for legal enforcement.


References

  • Tramer, F., Zhang, F., Juels, A., Reiter, M., Ristenpart, T. (2016). "Stealing Machine Learning Models via Prediction APIs." 25th USENIX Security Symposium.
  • Jagielski, M., Carlini, N., Berthelot, D., Kurakin, A., Papernot, N. (2020). "High Accuracy and High Fidelity Extraction of Neural Networks." 29th USENIX Security Symposium.
  • Papernot, N., McDaniel, P., Goodfellow, I. (2017). "Practical Black-Box Attacks against Machine Learning." ACM Asia CCS.
  • Correia-Silva, J., Berti, R., Fantini, C., Mendonca, A., Zanchettin, C. (2018). "Copycat CNN: Stealing Knowledge by Persuading Confession with Random Non-Labeled Data." IEEE IJCNN.
  • Taori, R. et al. (2023). "Stanford Alpaca: An Instruction-following LLaMA Model." Stanford CRFM.
  • Juuti, M., Szyller, S., Marchal, S., Asokan, N. (2019). "PRADA: Protecting Against DNN Model Stealing Attacks." IEEE EuroS&P.
  • Sablayrolles, A. et al. (2020). "Radioactive Data: Tracing Through Training." ICML.
  • MITRE ATLAS: AML.T0024—Exfiltration via ML Inference API / Model Theft.
  • OWASP LLM Top 10: LLM10—Model Theft.

Framework Mappings

Framework Reference
MITRE ATLAS AML.T0024: Model Theft
OWASP LLM Top 10 LLM10: Model Theft
AATMF ME-* (Model Extraction category)

Citation

Aizen, K. (2025). "Model Extraction." AI Security Wiki, snailsploit.com. Retrieved from https://snailsploit.com/ai-security/wiki/attacks/model-extraction/
← Back to Attacks Wiki Index
cite this work
BibTeX
@misc{aizen2026model,
  author = {Aizen, Kai},
  title  = {Model Extraction | AI Security Wiki},
  year   = {2026},
  url    = {https://snailsploit.com/ai-security/wiki/attacks/model-extraction/},
  note   = {snailsploit.com}
}
APA

Aizen, K. (2026). Model Extraction | AI Security Wiki. snailsploit.com. https://snailsploit.com/ai-security/wiki/attacks/model-extraction/

MLA

Aizen, Kai. "Model Extraction | AI Security Wiki." snailsploit, 2026, https://snailsploit.com/ai-security/wiki/attacks/model-extraction/.

Chicago

Aizen, Kai. "Model Extraction | AI Security Wiki." snailsploit (blog). 2026. https://snailsploit.com/ai-security/wiki/attacks/model-extraction/.

Permalink: https://snailsploit.com/ai-security/wiki/attacks/model-extraction/
more in attacks ← back to wiki
Membership InferenceIndirect Prompt InjectionTraining Data ExtractionJailbreakingAdversarial ExamplesAgent Hijacking
Author
Kai Aizen
Independent Adversarial · Research group. 97 published CVEs, 5 Linux kernel mainline patches, creator of AATMF / P.R.O.M.P.T / SEF, author of Adversarial Minds.