Mahir Shahriar Tamim

AI Researcher · Explainable & Responsible AI · Vision, Language & Agentic Systems

Part 3 of Adversarial Attacks

Black-box and real-world attacks

Module 3 · 5 min read

Black-box and real-world attacks

TL;DR

  • Keeping the weights secret doesn’t protect a model. Attacks transfer from a copy, scores leak the gradient, and even label-only APIs can be attacked.
  • Query-based attacks cost API calls. Rate limits raise that cost but do nothing against transfer attacks.
  • Patterns optimised over many random transformations (EOT) survive a real camera, e.g. stickers on stop signs, patches and a 3D-printed turtle.

“But the attacker doesn’t have my model”

Every attack in module 2 needs gradients, so full access to the weights. APIs never hand those out, and for a while that felt like protection. It isn’t. Attacks transfer between models, gradients can be estimated by asking, and some attacks only need the final label.

1. Attack a copy, hit the original

Szegedy’s first paper noticed that adversarial examples made for one network often fool another. Papernot et al. (2017) turned that into a practical attack.

  1. Send inputs to the target and record its answers.
  2. Train a substitute model on those answers (any architecture).
  3. Attack the substitute with white-box methods (FGSM, PGD).
  4. Send the adversarial examples to the target. Many fool it too.

Against real online machine-learning services they reported high misclassification rates. Two models trained for the same task on similar data learn similar boundaries, so pushing an input across one often crosses the other too.

originalafter the attackmodel B’s boundary

Model B is

Two toy linear models. The attack is computed on A only and needs a little extra budget to reliably fool B, which is why attackers deliberately overshoot.

2. Estimate the gradient by asking

If the model returns probabilities, you can estimate its gradient from outside by nudging a pixel up, then down, and seeing which way the score moves. ZOO (Chen et al., 2017) did this, with tricks to probe fewer pixels. The catch is that an image has tens of thousands of pixels and every probe is an API call.

Later attacks got far more efficient. Square Attack (Andriushchenko et al., 2020) skips gradients. It tries a random square-shaped change, keeps it if confidence in the right answer drops, and repeats. This simple random search is surprisingly hard to beat.

3. When you only get the label

Some APIs only return “cat”. The Boundary Attack (Brendel, Rauber & Bethge, 2018) still works. It starts from an input that’s already misclassified (a dog photo, or random noise) and walks towards the original in small random steps, keeping only those that stay misclassified. After many queries it hugs the boundary, close to the original but still on the wrong side.

original inputcurrent adversarial point

The wrong class is the red circle. The attack sees only which region a point is in, never a score or gradient, and still slides to nearly the closest wrong point.

4. Physical attacks

In the real world the attacker changes an object and a camera decides the pixels, with different angles, distances, lighting and blur. That partly destroys a tuned pattern, but not enough.

  • Kurakin et al. (module 2) printed adversarial images and photographed them with a phone, and a large share still fooled the classifier.
  • In Robust Physical Perturbations (Eykholt et al., 2018), black and white stickers on a real stop sign made a road-sign classifier read a speed-limit sign in almost all lab photos and most frames of a drive-by video.
  • Adversarial Patch (Brown et al., 2017) dropped the “invisible” rule with a visible, printable, round sticker that makes a classifier say “toaster” wherever it sits in a scene.
  • Expectation over Transformation (Athalye et al., 2018) 3D-printed a turtle that an ImageNet classifier saw as a rifle from most viewpoints.

The last three share one trick. They optimise for the average over many random transformations (rotations, scales, lighting, camera noise) instead of one exact photo, and a pattern that works across all of them in simulation tends to survive a real camera.

Why this changed the conversation. Before 2017 a lot of people saw adversarial examples as a lab curiosity. Stickers on a stop sign made them a safety question for self-driving cars, face recognition and any camera-based system. Physical attacks are much harder, since the pattern has to survive the camera, but they’ve been shown many times, which is one reason safety-critical vision systems combine several sensors and checks.

SettingAttacker seesExample methodsMain cost
TransferNothing during the attackSubstitute models, ensemblesLower success rate
Score-basedProbabilitiesZOO, Square AttackMany queries
Decision-basedFinal label onlyBoundary AttackEven more queries
PhysicalThe camera’s viewRP2 stickers, patches, EOTMust survive real-world changes

Quick check

An API returns only the predicted label, never scores. Which attack can still work?

Q&A

Can rate limits stop query-based attacks?

They raise the cost, and flagging lots of near-identical queries from one user helps. But attackers can spread queries across accounts and time, and transfer attacks need no queries during the attack. A speed bump at best.

Why do adversarial examples transfer at all?

Models trained on the same task pick up similar features from similar data, including useful ones a human wouldn’t use. Ilyas et al. (2019) argued adversarial examples exploit exactly these real but “non-robust” features, so different models fall for the same patterns.

Papers