A black-box attack in machine learning is an adversarial attack in which the attacker can only submit inputs to a model and observe its outputs, without access to the architecture, parameters, gradients or training data. The attacker treats the model as an opaque oracle and uses queries, transferability or statistical inference to craft adversarial examples, steal functionality or infer private information.
In AI security, black-box attacks matter because they describe the realistic threat model for deployed systems. Commercial models are usually exposed through an API or a product interface, so an outsider rarely sees internals. Not to be confused with black-box security testing of conventional software, the term here refers specifically to attacks on learned models.
How a black-box attack works against a machine learning model
A black-box attack works by replacing the missing gradient with information gathered from model responses. In a white-box attack such as the fast gradient sign method, the attacker computes the exact direction that increases the loss. In the black-box setting, that direction must be estimated from queries or borrowed from another model.
The attacker’s capability depends heavily on what the interface returns. A full probability vector leaks far more information than a single label, and a label leaks more than a refusal message. Security analyses therefore describe the threat model by output granularity, query budget and allowed perturbation size.
| Threat model | Attacker knows | Typical technique |
|---|---|---|
| White-box | Architecture, weights, gradients | Gradient attacks such as PGD |
| Gray-box | Architecture or training data, not weights | Surrogate trained on similar data |
| Score-based black-box | Output probabilities or logits | Gradient estimation by queries |
| Decision-based black-box | Final label only | Boundary walking |
| No-query black-box | Task and data domain only | Pure transfer from a surrogate |
Main families of black-box attacks
Black-box attacks fall into three technical families that differ in how they obtain attack directions. Each trades query cost against success rate and perturbation size.
Transfer-based attacks train a local surrogate model, craft adversarial examples against it with white-box methods and submit them to the target. They rely on adversarial transferability, the tendency of perturbations to fool models with different architectures trained on similar data. Ensembles of surrogates and input diversity augmentations raise transfer rates.
Score-based attacks estimate gradients with finite differences or random search. Zeroth-order optimization, often abbreviated ZOO, probes coordinates individually, while methods such as NES, SimBA and the Square Attack use random directions to cut costs. Decision-based attacks such as the Boundary Attack and HopSkipJump start from an already misclassified point and walk along the decision boundary toward the original input.
| Family | Output needed | Typical query cost | Main weakness |
|---|---|---|---|
| Transfer-based | Label for verification only | Very low | Lower success on robust targets |
| Score-based | Probabilities or logits | Hundreds to thousands | Blocked by hiding scores |
| Decision-based | Top label | Thousands to tens of thousands | High query volume is detectable |
| Hybrid | Varies | Low to moderate | Needs a good surrogate |
Black-box goals beyond evasion
Black-box access supports several attack goals, not only evasion. The same query interface that returns predictions can reveal model behavior, training data properties or exploitable instructions in language model applications.
| Goal | What the attacker obtains | Example signal used |
|---|---|---|
| Evasion | Misclassified input | Label or score changes |
| Model extraction | Functional copy of the model | Large sets of query-answer pairs |
| Membership inference | Whether a record was in training data | Confidence gaps on known records |
| Model inversion | Representative training features | Confidence optimization |
| Jailbreak search | Prompts that bypass safety behavior | Refusal or compliance responses |
For large language models, automated jailbreak and prompt injection searches are black-box attacks in practice. Attackers iterate on prompts using only text responses, sometimes with another model acting as the optimizer, and tools such as garak and PyRIT apply the same idea for authorized red teaming.
Defending deployed models
Defense against black-box attacks combines model robustness with interface controls. Robust training reduces the effect of any adversarial input, while API design and monitoring raise the cost of finding one.
- Return minimal output: expose labels instead of full probability vectors when the product allows it.
- Rate limit and monitor queries: decision-based attacks produce long series of near-duplicate inputs that stateful detection can flag.
- Apply adversarial training and, where guarantees are required, certified robustness methods such as randomized smoothing.
- Watermark or fingerprint models to detect extraction and prove ownership of copies.
- Map threats to frameworks such as MITRE ATLAS and NIST AI 100-2 during AI threat modeling.
Defenders should avoid gradient masking, which hides gradients without removing vulnerability. Obfuscated models often resist white-box attacks yet remain vulnerable to transfer and decision-based attacks, so robustness evaluations must include black-box methods to be credible.
Limitations and common misconceptions
A common misconception is that keeping a model secret makes it safe. Transferability means that an attacker with similar public data can often succeed without a single target query, so secrecy offers delay, not protection.
Black-box attacks also face real limits. Query budgets, cost per call and detection constrain them, physical-world conditions degrade carefully tuned perturbations, and strongly robust models reduce success rates considerably. Reported success figures depend on the perturbation norm, budget and dataset, so comparisons across papers require identical settings. Another misconception is that hiding probabilities stops attacks; it only shifts attackers to decision-based methods that need more queries.
The idea in brief
Imagine a locked vending machine. You cannot open it or see its wiring. You can only press buttons and watch what comes out. A black-box attack treats an AI model the same way. The attacker never sees the code, the settings or the data used to build it.
The attacker sends many inputs and studies the answers. Slowly, they learn how to trick the model or copy it. No inside access is needed. This is why companies limit what their models reveal and watch for unusual patterns of requests.
A practical scenario
An online marketplace uses an image classifier to block listings of prohibited items. The model is reachable only through the upload form, which returns accept or reject. A fraud group trains its own classifier on scraped listing photos and generates small perturbations against it, then uploads candidates. About one in five transferred images passes the filter.
The marketplace security team notices bursts of near-identical uploads from a few accounts, a typical decision-based probing pattern. It adds per-account rate limits, similarity detection on rejected uploads and adversarial training with transferred examples. In the next quarter the bypass rate falls below 2 percent, and flagged accounts are suspended.