Latest / CyberCode Academy / Course 24 - Machine Learning for Red Team Hackers | Episode 4: Mastering White-Box and Black-Box Attacks
Transcript
- 0:00Speaker 1: I want you to picture the most sophisticated security system
- 0:03Speaker 1: you can possibly imagine. Okay, we're talking about an artificial
- 0:06Speaker 1: intelligence that guards a massive bank vault, or you know,
- 0:10Speaker 1: maybe the autonomous driving system into Tesla that's doing seventy
- 0:13Speaker 1: miles an hour on the highway.
- 0:15Speaker 2: It's seen millions of miles of road, millions of faces.
- 0:19Speaker 1: Right, it feels invincible.
- 0:22Speaker 2: He feels invincible because it's mathematically precise. It doesn't get tired,
- 0:25Speaker 2: it doesn't blink exactly.
- 0:27Speaker 1: But here is the scenario I want you to imagine.
- 0:30Speaker 1: You want to break it. But here's the catch. You
- 0:32Speaker 1: don't have the password. You can't cut the power cables,
- 0:36Speaker 1: you can't hack the server room.
- 0:37Speaker 2: Okay, so what am I doing?
- 0:39Speaker 1: Instead? You just walk up to the camera and you
- 0:40Speaker 1: hold up a picture, and to you and me, it
- 0:43Speaker 1: looks like a cute, fluffy kitten, just a standard Internet
- 0:46Speaker 1: cat photo. Sure, but the second the AI sees it,
- 0:49Speaker 1: the system crashes or worse, it accelerates. It thinks that
- 0:53Speaker 1: kitten is a green light that sounds.
- 0:55Speaker 2: Like a magic trick or a glitch in the matrix.
- 0:58Speaker 1: It feels exactly like a glitch in the matrix, but
- 1:02Speaker 1: it's not magic, it's math. Welcome back to the deep dive.
- 1:08Speaker 1: Today we are staring directly into the blind spot of
- 1:11Speaker 1: artificial intelligence. We're talking about adversarial machine learning.
- 1:15Speaker 2: This is a fascinating field and we have a really
- 1:17Speaker 2: dense stack of sources today. We've got academic papers on
- 1:21Speaker 2: neural network architecture, coding tutorials using Python libraries like Keras
- 1:25Speaker 2: and fool box, and some high level security analysis.
- 1:29Speaker 1: And the mission today is pretty straightforward, even if the
- 1:31Speaker 1: tech isn't. We want to understand how to attack a
- 1:35Speaker 1: machine learning model.
- 1:36Speaker 2: Got to trick a supercomputer exactly. But before we hand
- 1:39Speaker 2: out any digital weapons, we need to be very very
- 1:42Speaker 2: clear about the why here, right, because whenever we talk
- 1:45Speaker 2: about attacks and exploits, it sounds a bit nefarious, right.
- 1:47Speaker 1: The disclaimer, Are we teaching people to rob banks today?
- 1:51Speaker 2: Definitely not. No, This isn't a how to for cyber criminals.
- 1:54Speaker 2: In the security world, we call this a stress test.
- 1:57Speaker 2: You can't build a bulletproof vest if you don't know
- 1:59Speaker 2: what kind of let's exist. Ah, I see, the goal
- 2:02Speaker 2: of adversarial machine learning is to find these cracks in
- 2:05Speaker 2: the armor so we can patch them, not exploit them,
- 2:07Speaker 2: so we're.
- 2:07Speaker 1: The white hats today. We're breaking into the vault to
- 2:10Speaker 1: prove the lock is rusty so the bank can buy
- 2:12Speaker 1: a better one.
- 2:12Speaker 2: That's it exactly. If we don't find the flaws, the
- 2:15Speaker 2: bad guys.
- 2:15Speaker 1: Will fair enough. So looking at the roadmap for this
- 2:19Speaker 1: deep dive, we have two main environments to explore. We
- 2:22Speaker 1: have black box attacks, which sounds appropriately mysterious, and then
- 2:27Speaker 1: white box attacks. And then we are going to roll
- 2:30Speaker 1: up our sleeves and mentally walk through specific attack method
- 2:35Speaker 1: called FGSM.
- 2:36Speaker 2: The fast radiance sign method. It's a classic.
- 2:38Speaker 1: That's the one. But let's start with the landscape. Black
- 2:41Speaker 1: box versus whitebox. To me, black box sounds like a
- 2:43Speaker 1: flight recorder. What does it mean in this context?
- 2:46Speaker 2: So the black box scenario is effectively the standard real
- 2:50Speaker 2: world situation for most of us. Okay, imagine you're interacting
- 2:53Speaker 2: with an AI, but you have absolutely zero access to
- 2:56Speaker 2: its brain. You don't know the architecture, you don't know
- 2:59Speaker 2: if it's a convolutional neural network or a transformer. You
- 3:02Speaker 2: don't have the training data, so.
- 3:03Speaker 1: I'm flying blind. I can't look under the hood.
- 3:05Speaker 2: You can't even open the hood. All you have is
- 3:07Speaker 2: the input and the output. You feeded a picture and
- 3:10Speaker 2: it gives you a prediction score. That's it.
- 3:12Speaker 1: Okay, help me visualize this. Give me a real world
- 3:15Speaker 1: example of where i'd encounter a black box model.
- 3:18Speaker 2: Think about commercial API services. Our sources highlight a company
- 3:22Speaker 2: called Clariff dot Ai.
- 3:23Speaker 1: Clariff dot ai.
- 3:25Speaker 2: Okay, they're a big player in the space. They offer
- 3:28Speaker 2: pre trained models for everything identifying food, recognizing apparel, detecting faces.
- 3:33Speaker 1: Even moderation models to flag NSFW content.
- 3:36Speaker 2: Exactly all of that.
- 3:38Speaker 1: Right. So, let's say I'm a developer building a diet
- 3:40Speaker 1: tracking app. I don't want to build my own brain
- 3:42Speaker 1: to recognize pizza versus salad. I just send the photo
- 3:46Speaker 1: to Clariff dot ai.
- 3:47Speaker 2: Exactly. You'd get an apikey. You'd open your terminal, maybe
- 3:50Speaker 2: run PIP install Clarify.
- 3:52Speaker 1: Pause there for a second. PIP install. That's just the
- 3:55Speaker 1: standard command Python users used to download tools.
- 3:57Speaker 2: Right, yes, sorry, yeah, PIP is the package installer for Python.
- 4:02Speaker 2: It's how you grab libraries from the internet. So you
- 4:04Speaker 2: install their client. You send the image of your lunch,
- 4:07Speaker 2: and the black box sends back pizza pepperoni eight hundred calories.
- 4:12Speaker 2: You have no idea how decided that it just did so.
- 4:15Speaker 1: In a black box attack, I'm trying to fool that system.
- 4:18Speaker 1: But if I don't know how it works, aren't I
- 4:20Speaker 1: just guessing?
- 4:21Speaker 2: Pretty much? You are. You're poking the bear to see
- 4:24Speaker 2: what makes it angry. It's difficult, it's slow, and it
- 4:27Speaker 2: requires a lot of trial and error. You send a
- 4:29Speaker 2: modified image. See if the confidence score drops, you tweak
- 4:32Speaker 2: it again. You repeat. It's really inefficient.
- 4:35Speaker 1: Which brings us to the alternative, the white box. I
- 4:38Speaker 1: assume this is where we turn the lights on.
- 4:40Speaker 2: This is where you have the keys to the kingdom.
- 4:42Speaker 2: In a white box scenario, you know everything everything. You
- 4:46Speaker 2: know the architecture, maybe it's a residant fifty model. You
- 4:49Speaker 2: know the weights, the millions of numerical connections inside the brain,
- 4:55Speaker 2: and crucially, you have access to the gradients.
- 4:58Speaker 1: We're going to be saying that word alive gradients.
- 5:01Speaker 2: It is the most important concept in the stack.
- 5:03Speaker 1: Yes, But before we get to the attack, I want
- 5:05Speaker 1: to clarify something for the listener. Why does having the
- 5:08Speaker 1: blueprints make the attack easier? I mean, I know how
- 5:12Speaker 1: a car engine works, but I can't just wish it
- 5:14Speaker 1: to break.
- 5:15Speaker 2: Because in AI, the blueprint is math. It's pure calculus,
- 5:20Speaker 2: and if you know the math, you can calculate the
- 5:21Speaker 2: exact input that breaks the equation.
- 5:23Speaker 1: You're not guessing anymore.
- 5:24Speaker 2: You're not guessing. You can solve for the error.
- 5:27Speaker 1: Okay, that's a terrifying thought, solving for the error. Let's
- 5:30Speaker 1: dig into this specific white box attack you mentioned FGSM, the.
- 5:35Speaker 2: Fast gradience sign method. It comes from a seminal paper
- 5:37Speaker 2: titled Explaining and Harnessing Adversarial Examples. Right, it's considered one
- 5:42Speaker 2: of the foundational texts in this field.
- 5:44Speaker 1: So to understand FBSM, we have to do a quick
- 5:47Speaker 1: machine learning one oh one refresher because the sources emphasize
- 5:52Speaker 1: that this attack is basically doing the training process, but
- 5:56Speaker 1: in reverse.
- 5:57Speaker 2: That's the best way to think about it, the reverse training.
- 6:00Speaker 1: Walk me through standard training. If I want to teach
- 6:02Speaker 1: a computer to recognize a cat, what happens?
- 6:04Speaker 2: Okay, So visualize the setup. You have an input image
- 6:08Speaker 2: a cat. The pixels in that image are fixed, they
- 6:12Speaker 2: are frozen.
- 6:12Speaker 1: You can't change the cat. Right.
- 6:14Speaker 2: The photo is the photo. You feed it into the network,
- 6:17Speaker 2: and the network is full of these internal knobs and
- 6:19Speaker 2: dials we call weights. Okay, Initially, the network is dumb.
- 6:22Speaker 2: It looks at the cat and guesses, I don't know toaster.
- 6:25Speaker 1: Not great, not.
- 6:26Speaker 2: Great at all. So you have a massive error. We
- 6:29Speaker 2: call this the loss. The goal of training is to
- 6:31Speaker 2: minimize that loss. You want the error to be as
- 6:34Speaker 2: close to zero as possible, So we need to tune
- 6:37Speaker 2: the knobs exactly. We use an algorithm called back propagation.
- 6:41Speaker 2: It calculates the gradient. Think of the gradient as a
- 6:44Speaker 2: slope on a hill. Okay, it tells you which direction
- 6:47Speaker 2: to turn the knobs the weights to slide down the
- 6:50Speaker 2: hill of error. You do this millions of times until
- 6:52Speaker 2: the error is low and the model says.
- 6:54Speaker 1: Cat, okay, I'm with you. In training, the picture is locked.
- 6:58Speaker 1: We change the brain the weights to minimize the error.
- 7:01Speaker 1: We are sliding down the hill. This is gradient descent.
- 7:03Speaker 2: Perfect. Now enter the adversarial attack. Yeah, enter FGSM We
- 7:08Speaker 2: flip the script completely. In an attack, we freeze the brain.
- 7:12Speaker 2: We say this model is finished. We cannot touch the weights,
- 7:15Speaker 2: so the knobs are locked. They're locked. Instead, we unlock
- 7:20Speaker 2: the picture.
- 7:21Speaker 1: We changed the pixels.
- 7:22Speaker 2: To change the pixels, and here is the core flip.
- 7:25Speaker 2: In training, we used gradients to find the direction that minimizes.
- 7:29Speaker 1: Error right down the hill.
- 7:31Speaker 2: In an attack, we use the gradients to find the
- 7:33Speaker 2: direction that maximizes the error.
- 7:35Speaker 1: Oh wow, so we are climbing up the hill.
- 7:37Speaker 2: We are performing gradient ascent. We ask the computer what
- 7:42Speaker 2: is the tiniest mathematical change I can make to these
- 7:45Speaker 2: pixel colors that will push the air as high as possible.
- 7:48Speaker 1: This is such a cool inversion. It's like asking a
- 7:51Speaker 1: lock what shape key would you hate the most?
- 7:54Speaker 2: And because we're in a white box scenario, the computer
- 7:57Speaker 2: can tell us. It calculates the gradient and says, if
- 7:59Speaker 2: you make this pixel one percent greener in that pixel
- 8:02Speaker 2: one percent darker, my logic will completely collapse.
- 8:05Speaker 1: This is really abstract, and I want to ground this.
- 8:07Speaker 1: I want to see what this looks like in practice.
- 8:09Speaker 1: Let's head into the audio lab.
- 8:10Speaker 2: Let's do it.
- 8:11Speaker 1: I want to mentally walk through the code provided in
- 8:13Speaker 1: our sources. Let's pretend you and I are sitting at
- 8:15Speaker 1: a terminal. Right now, we've got our dark mode on
- 8:17Speaker 1: green text.
- 8:18Speaker 2: The works love it.
- 8:19Speaker 1: What tools are we firing up?
- 8:20Speaker 2: Okay, first, we're using Python and we're loading two main libraries.
- 8:25Speaker 2: First up is Keras. This is our library for loading
- 8:28Speaker 2: the brain the model itself. Our sources use ResNet fifty,
- 8:31Speaker 2: which is a classic heavyweight image recognition model, and.
- 8:34Speaker 1: The second tool, Fullbox, great.
- 8:36Speaker 2: Name it really is. Fullbox is a Python package designed
- 8:40Speaker 2: specifically to test AI robustness. It acts as a wrapper.
- 8:44Speaker 2: It takes that complex Chris model and just wraps it
- 8:47Speaker 2: up in a nice, easy to attack interface.
- 8:49Speaker 1: Okay, step one preparation, we load ResNet, we wrap it
- 8:53Speaker 1: in fool box. But I know it's a specific detail.
- 8:55Speaker 1: On the notes about normalization and talked about zero to
- 8:58Speaker 1: two fifty five versus zero to one one. This feels
- 9:01Speaker 1: like the kind of technical detail that trips people up.
- 9:03Speaker 1: Why does that matter so much?
- 9:04Speaker 2: Oh? This catches so many people out. So computers see
- 9:07Speaker 2: images as grids of numbers. Usually in standard digital imaging,
- 9:11Speaker 2: a pixel is a value from zero to two fifty five.
- 9:14Speaker 1: Right, zero's black, two fifty five is white standard our
- 9:16Speaker 1: GV exactly.
- 9:17Speaker 2: But neural networks they prefer small numbers. The math just
- 9:20Speaker 2: works better with decimals, so we often normalize or squish
- 9:25Speaker 2: those values down to decimals between zero and one.
- 9:28Speaker 1: So it's like translating inches to centimeters. If you don't
- 9:30Speaker 1: tell the model, which one you're using?
- 9:32Speaker 2: The math breaks. If the model expects A one to
- 9:34Speaker 2: be the brightest white and you feed it two fifty five,
- 9:36Speaker 2: you're gonna get garbage. So in fool box we have
- 9:39Speaker 2: to explicitly set the bounds. We tell it, hey, we
- 9:43Speaker 2: are operating in the zero to two fifty five language,
- 9:46Speaker 2: or we are operating in the zero to one language.
- 9:48Speaker 2: It's critical.
- 9:49Speaker 1: Got it house keeping done? Step two the target, Yeah,
- 9:52Speaker 1: what are we attacking?
- 9:53Speaker 2: We need a seed image. The tutorial uses a classic
- 9:56Speaker 2: from the image neet data set, a picture of a kitten.
- 9:59Speaker 1: Always the kit.
- 10:00Speaker 2: The Internet runs on them. So first we do a
- 10:02Speaker 2: sanity check. We feed the raw kitten image into the
- 10:05Speaker 2: resonant model. The model processes it and spits out label.
- 10:08Speaker 1: Two eighty two, which corresponds to.
- 10:10Speaker 2: Tabby cat confidence ninety nine percent.
- 10:13Speaker 1: Okay, the AI works. It sees the cat. Now. Step
- 10:17Speaker 1: three the attack. We execute the FGSM function from fool box.
- 10:23Speaker 1: We tell it maximize the error. What is the computer
- 10:27Speaker 1: actually doing in that split second?
- 10:28Speaker 2: It's calculating that gradient we talked about. It looks at
- 10:31Speaker 2: every single pixel in the kitten photo, and there are
- 10:33Speaker 2: thousands of them, and for each one It calculates a
- 10:36Speaker 2: tiny vector a direction that moves that pixel away from
- 10:40Speaker 2: cat toward chaos and toward chaos.
- 10:42Speaker 1: And then it applies that change.
- 10:44Speaker 2: Yes, it shifts the pixel values just a tiny, tiny
- 10:47Speaker 2: bit in that direction, and then it creates a new image,
- 10:49Speaker 2: an adversarial example.
- 10:51Speaker 1: Okay, this is the moment of truth. I'm looking at
- 10:52Speaker 1: the screen. The new image pops up. What do I see?
- 10:55Speaker 1: Do I see a monster? Do I see a blur?
- 10:57Speaker 2: That's the scary part to you. You see a kitten
- 10:59Speaker 2: to sink it? If you have twenty twenty vision and
- 11:01Speaker 2: you lean in really close, you might see it sort
- 11:04Speaker 2: of graininess, like static. Yeah, like a subtle static overlay.
- 11:09Speaker 2: Maybe the fur looks slightly textured in a way it
- 11:11Speaker 2: didn't before. But if you were just scrolling past it
- 11:14Speaker 2: on Instagram, you wouldn't blink.
- 11:16Speaker 1: It looks identical of the human eye. But what about
- 11:19Speaker 1: the machine? What does it see?
- 11:21Speaker 2: So we feed this new image back into Resino. Remember
- 11:25Speaker 2: a second ago, it was ninety nine percent show this
- 11:27Speaker 2: was a tabby cat. Right now, it says lemon or
- 11:30Speaker 2: a toaster or monitor with high confidence, with absolute certainty,
- 11:34Speaker 2: it is completely convinced that is wild and the sources
- 11:38Speaker 2: emphasize looking at the difference image. If you use Python
- 11:41Speaker 2: to subtract the original photo from the attack photo, so
- 11:44Speaker 2: you only see what changed.
- 11:46Speaker 1: What's left.
- 11:46Speaker 2: All you see is this random looking static. That static
- 11:49Speaker 2: is a mathematical secret code.
- 11:51Speaker 1: It's like an optical illusion, but for a microchip.
- 11:53Speaker 2: Precisely. It really highlights the fundamental difference in how we see.
- 11:57Speaker 2: You see ears, whiskers, a tail. The machine sees a
- 12:02Speaker 2: statistical distribution of numbers. FGSM proves that we can break
- 12:06Speaker 2: the statistics without removing the ears and whiskers.
- 12:09Speaker 1: So technically the concept of cat never existed to the AI,
- 12:13Speaker 1: only the pattern existed, and we just broke the pattern.
- 12:16Speaker 2: That's the Aha moment.
- 12:17Speaker 1: I can see why this is such a huge security issue.
- 12:20Speaker 1: If I can tape a piece of static onto a
- 12:23Speaker 1: stop sign and make a self driving car think it's
- 12:25Speaker 1: a speed limit sixty five sign, that's a problem.
- 12:29Speaker 2: That is exactly the scenario researchers are worried about. There
- 12:33Speaker 2: have been papers where they printed these patterns on stickers,
- 12:36Speaker 2: put them on signs, and the car cameras misread them.
- 12:39Speaker 2: That's terrifying, it is, and that is why we do this.
- 12:42Speaker 1: This brings us to the sow of the episode. We've
- 12:46Speaker 1: learned the trick, but our expert source actually leaves us
- 12:49Speaker 1: with a challenge, a sort of homework assignment for the
- 12:53Speaker 1: listeners to test if they really grasp the mechanics.
- 12:55Speaker 2: Yes, the trick me challenge. This uses the mnized data.
- 12:59Speaker 1: Set' the Hello World of AI. Right, the handwritten numbers.
- 13:02Speaker 2: Correct, It's a data set of thousands of hamwritten digits
- 13:04Speaker 2: zero through Now. It's very simple, which makes it perfect
- 13:07Speaker 2: for learning.
- 13:08Speaker 1: So what's the challenge.
- 13:09Speaker 2: The challenge is this. You take a trained model that
- 13:11Speaker 2: reads these numbers. You load up an image of the
- 13:14Speaker 2: number five.
- 13:14Speaker 1: Okay, I'm visualizing a scroll number five on a check
- 13:17Speaker 1: The model says five. Easy enough.
- 13:20Speaker 2: Your mission is to use FGSM, the same code we
- 13:23Speaker 2: just discussed to create an adversarial instance. You need to
- 13:27Speaker 2: tweak that image so that the model predicts it is
- 13:30Speaker 2: anything else A three to a nine, a zero. It
- 13:34Speaker 2: doesn't matter as long as it's wrong. Okay, But but, but,
- 13:39Speaker 2: and here's the catch. To your human eyes, it must
- 13:42Speaker 2: still clearly undeniably be a five.
- 13:45Speaker 1: Right. I can't just draw a line across the bottom
- 13:47Speaker 1: and turn it into a six. That's cheating.
- 13:49Speaker 2: That's changing the semantic meaning. You have to keep the
- 13:52Speaker 2: meaning it's a five, but break the interpretation so that
- 13:55Speaker 2: AI sees a three.
- 13:56Speaker 1: So if I can do that, if I can make
- 13:57Speaker 1: ghost five, then I have successful hacked them off.
- 14:00Speaker 2: You have and thinking about how to do that. Visualizing
- 14:03Speaker 2: that hill of air, visualizing climbing up it. That is
- 14:06Speaker 2: how you solidify this concept.
- 14:08Speaker 1: It's a powerful idea. It really suggests that for all
- 14:11Speaker 1: their power, these systems are incredibly brittle. Their genius is
- 14:14Speaker 1: in a very narrow lane. But if you throw a
- 14:16Speaker 1: pebble in that lane, they just crash.
- 14:18Speaker 2: And that brings us back to the start. Why do
- 14:20Speaker 2: we do this. We do it so we can take
- 14:21Speaker 2: that ghost five or that static kitten and put it
- 14:23Speaker 2: back into the training data.
- 14:24Speaker 1: We show to the model.
- 14:26Speaker 2: We show it to the model and say, look closer,
- 14:28Speaker 2: I tricked you. This is actually a cat, and the
- 14:31Speaker 2: model updates its weights, it learns to ignore the static,
- 14:35Speaker 2: it becomes more robust.
- 14:36Speaker 1: We attack it to make it stronger.
- 14:38Speaker 2: Exactly. We call it adversarial training. It's like giving the
- 14:41Speaker 2: AI a vaccine. You give it a little bit of
- 14:43Speaker 2: the virus the trick image. So it develops immunity.
- 14:46Speaker 1: I love that analogy a vaccine for AI. Before we
- 14:51Speaker 1: sign off, I want to throw a quick review question
- 14:53Speaker 1: out there to the listener, just to make sure this stuck,
- 14:55Speaker 1: because the difference between training and attacking is subtle, but
- 14:59Speaker 1: it's absolutely vital.
- 15:01Speaker 2: It's the whole ballgame.
- 15:02Speaker 1: So listener, ask yourself this. In a standard training process,
- 15:06Speaker 1: we change the weights to minimize the error. But in
- 15:09Speaker 1: an adversarial attack like FGSM, what exactly do we change
- 15:14Speaker 1: and are we trying to minimize or maximize that error?
- 15:17Speaker 2: Think about the hill, Are you walking down or are
- 15:19Speaker 2: you climbing up?
- 15:21Speaker 1: I'll let the mull on that. It's been a fascinating
- 15:23Speaker 1: look under the hood as we look at every glitchy
- 15:25Speaker 1: piece of tech a little differently. Now, next time Siri
- 15:29Speaker 1: misunderstands me, I'm going to wonder if I accidentally spoke
- 15:31Speaker 1: an adversarial audio.
- 15:33Speaker 2: Wave you might have. Audio attacks are a whole other
- 15:36Speaker 2: deep dive.
- 15:37Speaker 1: Well, that's all the time we have for this deep
- 15:39Speaker 1: dive into the fragility of AI. Next time you see
- 15:43Speaker 1: a picture on the Internet, ask yourself, is that really
- 15:46Speaker 1: a cat? Or is it just a mathematical illusion designed
- 15:49Speaker 1: to fool a machine. Thanks for listening, and we'll catch
- 15:52Speaker 1: you on the next one.
- 15:52Speaker 2: Keep learning,