ML Security
Intermediate 15 min read ML Security

Model Theft and Extraction

Your model is a service; treat its knowledge as property

Extraction steals your model by querying it: adversaries reconstruct a shadow model or recover features/training data. Defenses manage access, detect extraction patterns, watermark outputs, and treat weights as crown-jewel artifacts — not open endpoints.

extractionmodel theftshadow modelwatermarkquery detectioninversion
Before we start

What you will learn

  • Understand extraction, inversion, and shadow-model attacks
  • Detect query patterns that signal theft
  • Deploy watermarking and access controls as deterrents
Introduction

What is this?

Model extraction reverse-engineers a functionally equivalent model by carefully querying the target service; inversion attempts to reconstruct training data from outputs; attacks use confidence scores, embeddings, or API outputs. Defenses restrict access, watch usage, watermark responses, and protect weights like tamper-evident assets.

Motivation

Why do you need it?

  • Models are expensive assets — training cost and data value in one network.
  • APIs are the soft underbelly; extraction needs no leak, just licensed queries.
  • Confidence scores and APIs are the strongest extraction channels.
  • Winning the extraction race is about raising the cost, not perfect prevention.
Think about it

Mental model

Imagine

A magician whose trick gets filmed by a hundred guests

Think of

Model extraction

Each rehearsal (query) is free and legitimate; videotaping hundreds of takes (patterned probing) reconstructs the whole trick. You can't stop guests watching, so you limit camera policy (rate-limits), watch for the same trick asked repeatedly (pattern detection), and put counterfeit marks in the performance (watermarking).

Mechanics

How it works

  • Extraction: distribute queries near decision boundaries; fit a student model on (input, output) pairs.
  • Inversion: use gradients or confidence to recover representative inputs of private classes.
  • Detection: monitor query volume, similarity/coverage, confidence-shape distribution, access-source fingerprint.
  • Deterrence: rate limits, cost-based pricing, watermark/trigger patterns, no-confidence APIs where feasible.
  • Protection: weights signed/encrypted, serving in enclaves or trusted compute where stakes are high.

Extraction loop and countermeasures.

Attacker
Extraction queries
Service
Shadow model
Harden
Real world

In production

  • A credit-anomaly API ties extraction-attempting request volumes to rate limits and CAPTCHA-style gating.
  • A translation service watermarks low-frequency outputs so cloned models betray their source.
  • An internal inference store keeps weights signed and access-logged; serving boxes are tamper-evident.
Guidelines

Best practices

  • Treat serving outputs as a licensed channel: quotas, terms, and cost-based pricing for scale.
  • Watch for extraction signatures: near-boundary probes, uniform coverage, machine-speed pacing.
  • Watermark vulnerable outputs (rare sentence pairs, trigger strings) for provenance.
  • Keep weights signed/integrity-checked and the serving host hardened.
Watch out

Common mistakes

  • No rate/pattern controls because 'the API is authenticated' — extraction is quieter than it looks.
  • Returning full confidence vectors everywhere — the richest extraction channel, defended by nothing.
  • Ignoring that a legitimate integration (batch scoring) can double as an extraction channel.
  • Shipping model files to edge/mobile devices as plain matter — the weights are then free.
When things break

Debugging tips

  • A customer's request pattern sweeps the whole input space evenly — that's extraction; scope and cap.
  • Suspected cloned model in the wild — run your watermark strings through it to prove provenance.
  • Confidence vectors expose more than labels — degrade to top-k where business asks, keep the rich signal internal.
Interviews

Interview checkpoint

Practice

Hands-on lab

Simulate an Extraction Attack
40 min · intermediate
In progress
Objectives
  • Query a target and harvest labeled pairs
  • Train a shadow model that reproduces the target
  • Detect the extraction pacing with a simple anomaly check

Simulate an Extraction Attack

40 min · intermediate

0/3 steps
0%
sandbox · Linux sandbox
$
Try these commands
Test yourself

Quick quiz

0/2
1

Model extraction works chiefly by…

2

Full confidence vectors are the richest extraction signal an API can emit.

Go deeper

Official documentation