Hello, my name is Xiaojing Jiao. Today I will talk about how to leverage open source information to make effective adversarial attack and defense against deep learning model. Before I start, I'd like to introduce who we are. We are Northwest Security, a team of independent security researchers and data engineers. Right now, we have five members from left to right, Chen Li, Yang Chuan, Li Yang, Jiao Xiaojing, and Li Wei. We have diverse backgrounds, but we do have a united interest, which is to apply AI techniques to solve security issues. We have been fascinated by those ideas coming out of interaction between AI and security. We have been actively looking for opportunities to learn more along that direction. We also, we as a team, got invited for the CED CTF, which is the first CTF competition on adversarial attacks and defenses. As a new team attending the CTF for the first time, we learned a lot from the beginning of preparation to the end of competition. Today, this talk is going to mean... Oh, sorry. It's going to mainly focus on sharing our learning from this event. So this presentation is going to only include two parts. In the first part, I'm going to talk about how do we evaluate open source attacks and defenses. Then in the second part, we're going to introduce our design of the defense for the CTF. So, because due to the limitation of the time and the resources, we didn't try to develop our own. So, basically, our strategy is just try to utilize or leverage the public available information or open source code. So, in order to select those methods, we have to define a criteria. So, we define our criteria based on the requirement of the CTF. So, there are three factors we are considering. Speed, transferability, and strength. For defense. Because CTF has a hard requirement on how fast the image classifier has to run. So, we put that one as a top one priority. So, the requirement is two seconds per image. And also because we only can submit one defense. So, transferability is also very important. So, we even sacrifice our strengths. And to enhance our transferability. And on the other side, for the attack. Because there is no limitation on what kind of attack we can use. Or how many times we can attack. So, basically, we only consider the strength of the methods. But actually, this strategy turn out is not that 100% correct. So, because we just finished our CTF. Actually, the speed for attack is also important. Because we implemented some strong attacks. But it takes way long time. So, we don't have the opportunity to try it. So, basically, every time we each run, we only maybe just try maybe like one or two times. That's it. So, next time maybe we can improve on that. So, we use a target rate to evaluate the strength of the method. Which is a percentage of the images being misclassified as target classes. So, keep those criteria in mind. We start our evaluation. So, basically, the evaluation starts from building a baseline, basically. So, we do a benchmark of the base defense of the attacks. So, to do that, we use two open source libraries. For attack. We use CleverHands. Which is a Python library. Which are targeted. Which actually build to benchmark the machine learning system against adversarial attacks. So, it's basically a collection of different adversarial attack methods. And for defense. We actually, Google provided those pre-trained weights, actually. And even, they even provide those adversarial trained methods. So, what that mean is those model is trained by both original image and also some other several images. Let me see. So, there are, actually, there are two popular architectures. One is the Inception v3. And another is Inception ResNet v2. So, in order to do the evaluation, we have to use some test data set. So, basically, the test data set we are using is provided by CAD. Which include a thousand fresh images. Classified into a thousand classes. With ImageNet labels. If you look at the right hand side. That distribution. Target class versus true label. You can see the width of the distribution along the X direction is very consistent. So, that means those target class is randomly, uniformly selected. From zero to thousand. So, which means this is an average case of scenario. So, what that mean is if we use this data set to evaluate our method. That's going to give us average estimation of this method. It's not the best case and not the worst case. It's just average. So, by using those two libraries, we start our evaluation. So, this table shows. Hit target rate of four attacks against three defenses. So, all four attacks use the exact same gradient based method. Which is basic iterative method, DIM. The difference is. The first three. The difference is. The different model has been used to calculate the gradient. So, basically, the attack is calculated based on the gradient. But those three attacks use different models. Actually, they are corresponding to those three defenses. So, basically, the model in 7V3. And also the adversarial training in 7V3. And ensemble adversarial training in 7V2. Has been used to calculate the gradient. So, basically, we can say for each column. For each defense. We are doing a white box attack. So, we can say the white box attack is very effective, actually. For example, for the first one, DIM. Based on inception model. We can have like 89% hit target rate. But even for the second one and the third one. The second row and the third row. Those two. Oh, sorry. The second column and third column. Those two defenses. Those two defenses have been adversarial trained. Even for that model. It's still vulnerable to the white box attack. We can still have a very high. Like 75% and 85% hit target rates. But we can also say. Even though the white box attack is very strong. But the transferability is very bad. So, basically, it only works for that model. For example, if you look at the first row. It only works for 7V3. But for another two defenses. The hit target rate is zero. So, it doesn't work. But we can improve that by doing some ensembling. So, basically, the last attack. Ensembles three different models together. So, the basic idea is. We calculate three different adversarial images. Based on three models. Then we just calculate the average. And use that average image as our final attack. So, by doing that. You can see we can keep. We can still keep a high hit target rate. But also improve the transferability. So, basically, it works for all three defenses. So, that's just. Because. I forgot to mention. So, because. Those two labels are publicly available. So, basically, we treat those. When we analyze those performance. We just treat those like a lower boundary. So, basically. If we pick the attack or defense. It has to. It must be better than those methods. So, now. Then. We try. We also try some strong defense. Like guided denoise. That is sitting in the audience. And also the random padding. So, both of them. Actually the first and the second place. In the 2017 NIPS. Adelsera Defense Competition. So, you can see. Those two defenses are very strong. So, basically. For those four attacks. The hit target rate is zero. So, it's just totally not working. But. For us. Our strategy for. Attack selection. Is basically just make sure. We have a corresponding attack. For each single defense we can find. So, because. There is no limitation on. How many times we can try. So, basically. We build a set of. A broad set of attacks. For this CTF competition. So, this diagram is a polar plot. Which is a polar plot of hit target rate. So, basically. Different colors stand for. Different attacks. And six different defense. Is located on six different. Angular position. So, from this. This is like a needle like branch. So, this needle like branch pattern. Actually can tell us two kinds of info. One is the length of the branch. Which is the value of the hit target rate. So, which actually is the strength. Of the attack. And the number of branch. Which actually tells us. What the transability of this method is. Because the more branch we have. Which means this single method. Can attack more defenses. So, basically. Through all our evaluation. We use this plot. To evaluate all the methods. Just trying to get a balance. Between the transability and the defense. So, those three methods. We implemented. So, for guided denoise. We kind of like. Because they open source everything. Which is actually very effective. We can get like. 98% hit target rate. And for another two kinds of defense. Like random padding. Basically they randomly adding some. Paddings onto the input image. Because they try to utilize. The transfer environment feature. Of the CNN based image classifier. So, basically. For original image. If you add random stuff on it. It won't affect the classification results. But if we input a fake image. Out of a serial image. When you add some random stuff. Onto it. It's going to strongly degrade. The influence of that attack. So, that's the idea of the random padding. So, we also implant some. Adopt some method. To implant a targeted attack. For that. So, now. I will talk about some strategies. We applied in. Both defense and attack. So, basically for the first row. It's called defense. It's very popular one. It's called ensemble adversarial training. So, basically. We not only just train the model. With both original image. And adversarial image. We also try to generate those adversarial image. From several different methods. So, we tried. By doing that. By doing this ensemble adversarial training. You can strongly. You can effectively improve the transferability. Of your defense. And also. Apply ensemble adversarial attacking. Which also can improve. The transferability of your attack method. So, basically. Same idea. You can apply for both defense and attack. Another idea is. For defense is gradient masking. So, basically. Right now. For those popular attacks. Most of the popular attacks. Is gradient based. So, basically. If you have a gradient of that. Target model. Then based on the gradient. You can generate your attacks. But this gradient mask. Is just trying to hide those gradient info. So, they can. They can just make gradient unsmooth. Which means. It's kind of like stabilized. Or they can just make the gradient vanish. Totally become very small. Or very large. It's exploding. So, basically. They can go in the wrong direction. Basically. By doing that. They can achieve the defensing purpose. But. Still. On the attack side. Researchers still. Also propose some corresponding attacking strategies. Basically. If you make a stepwise gradient. Basically. You generate a lot of local minimum. So. Then. When the attack try to escape from those local minimum. They just. They can. There's one way they can do it. They can just add a random perturbation. Each time onto that calculation. So, basically. When you start into some local spot. And then you just randomly jump. Jump it out. That's just the idea. That's the idea of random perturbation. And also. Some attack. They use a gradient smoothing. So, basically. When you calculate. When they get a gradient info. They apply a Gaussian smoothing. And smooth that gradient out. So, everything is perfect for the attack. Again. A third new method is called. Backward pass differentiable approximation. So, basically. So, basically. This method is just. We cannot get the. The real gradient. Real gradient from that network. Then we can. Then somehow we can approximately calculate one. So, basically. That's the idea. So, we don't use the target to calculate the gradient. We just somehow come out an idea. Get a close one. And use that one as our gradient. Then achieve the. The attack. The third strategy for defense. So, basically. The gradient. The adversarial attack. Which is. Because of the adversarial noise. So, it is a noise. So, very nature solution for the noise is. Just do a filtering. Just get rid of noise. So, that's the third. The basic idea of the third one. Which is. Which is use some image processing method. Just filter those noise out. But still. From attack side. And figure out. How to attack this kind of defense. So, basically. What you are doing in the defense side. I just doing the same thing on the attack side. When I calculate the attack. We just improve those filtering or anything inside it. So, when I calculate the attack. It's going to take into account everything. So, that's the idea. So, actually we use this. We use this method to achieve the attack. Against the random padding. So, basically. When we calculate the attacking adversarial image. We also add the random padding. Into an iterative calculation. Then the last one. I think that's the only one. There is no effect attack method. So, which is. Detection only method. So, basically. It's not enhance the. The robustness of the system. It's just add on another module. To attack. If there is an adversarial attack happening. Or not. If it's happening. We just give an alert. Or we just return some random stuff. That's the idea of a detection. So, that's all. About the evaluation. So, based on the. We do a very extensive evaluation. Of a lot of attacks. And defenses. Then based on those learning. We came out this design of our defense. So, basically. The defense includes two modules. The first one. The left hand side. That big. Big rectangle. Which actually is our image classifier. But this image classifier. Includes two image classifiers. So, basically. We parallel align those two image classifiers. Together. Then we put a difference filter. At the end. So, basically what is happening is. When there is an adversarial image coming. It's going to get classified. By both of those two classifiers. One is the CV2 plus random padding. Another is a guided noise. So, then. There are two labels. Output from those two classifiers. Going to get fit into that difference filter. So, basically. We're going to compare. If those two agree with each other. Then we think. That's the attack field. Basically. That's the true label. But if they don't agree with each other. Or contradict with each other. Then we just. Simply return a zero or random number. So, that's the. Idea of the first module. So, I want to. Spend a little bit of time on that. CV2 filter. So, basically. CV2 is the name of the. OpenCV package in Python. So, basically. This is also an image percentage. Image processing idea. Because when we are doing. We read a lot of codes. They are doing a lot of. They are doing the image processing. Through a lot of different ways. But then we think. Why don't we just use a professional package. Just doing the image processing. So, OpenCV is the very famous. Open source library. They are just doing the image. Image processing. So, they provide a lot of sophisticated functions. So, basically. It's implemented by C. So, it's very fast. And very easy to use. Basically, you can just use the function. Just add one line. Just as simple as one line code. Just add the filter. In any existing defenses. So, right now. What we are using is called. Bilaterally filtering. So, which is edge preserving. Nodes reducing smoothing filter. So, basically. What it's doing is. Actually those four images. Show the effect. So, the left up corner. The first one is the original adversarial image. Then. If you go through those filters. Three times. And the last one. The bottom right. That one. You can see that. Those funny patterns on the background. Those actually is the adversarial partition. Try to confuse the classify. So, all those filters. Those noise is smooth out. But at the same time. The edge is still preserved. Because we know. For those image classifier. They kind of like. They try to learn those edges. So, if you can maintain those edges. Which means this matter won't affect. Your classification accuracy. So, to prove that. We apply this. CV2 filter. Guided denoise defense. And. Use it against. Three different. Attacks. So, this time those color. Pattern stands for defense. And. The left up corner. That one is. What we implement. Attacks against this guided denoise method. So, you can see. The yellow one. Which is the one we use. This guided denoise method. It can effectively reduce. The pay target rate. From 96%. Down to like. 45%. So, our method is. This CV2 filter. Is actually the effective method. And also the reason. Why we put another two defenses. Another two attacks. On the other side. We just try to save. This CV2 filter. But it turns out. It doesn't do that. So, we think. We believe this CV2 filter. Is a very effective. Way to. At least enhance your defense. Because it's very fast. And it's also very flexible. You can apply it. To any existing system. So, that's. About the first module. So, the first module. The successful defense. The first module. Relying on our assumption. Which is. There's no attack. Which is strong enough. To fool or confuse both of them. But that's not true actually. Even we know that's not true. Because when we do the testing. There's some attacks. Which can fool both of them. CV2 plus random finding. And also the guided denoise. So, basically. Both of them gonna output. The exact same label. But that label is wrong. So, which means. The first module gonna fail. If that happens. So, that's where the second module come into play. Which is a K-mean filter. So. This K-mean filter is based on. A machine learning method. Called K-mean clustering. So. The assumption here is. This K-mean clustering. Is robust against. Neural network based adversarial attack. So, in order to. Verify that. We conduct a very little experiment. So, this is an experiment. So, basically. What I'm doing is. There's a thousand original images. Then we generate another thousand adversarial images. Then we put both those two thousand images. Into this K-mean clustering. So, this K-mean clustering gonna. Gonna put. And automatically classify those images. Into different classes. Then we compare. Each original images classes. Against that. Adversarial version. Then we found that. Actually ninety-four percent of them are matched. So, which means. Those adversarial attack doesn't affect. The accuracy of the K-mean clustering. So, we can trust this method. Then based on that method. I'm gonna talk about. How we implement. K-mean filter. So, basically. The first one. The top one is. Describe how we generate a mapping. Because this. All the. All this competition is based on the ImageNet. Dataset. So, ImageNet has like thousand labels. But when we do the K-mean clustering. It's impossible. For us to do like thousand. Thousand clusters. So, basically. So, how can you map. A thousand. Different labels. Into ten different classes. So, that's how we do it. Basically, after we train our. K-mean cluster. We use another test dataset. So, that test set is gonna go inside. Into the K-mean clustering. We know those two labels. Those ImageNet labels of those test cluster. Then after we classify. Those images with K-mean cluster. We also know the. Classes. So, that's gonna generate a map. Basically, it's a table. So, we know which. Which class gonna correspond to which. ImageNet labels. So, after that. Mapping label is ready. We start to finalize our logic. So, basically. It's very simple. So, when. Adversarial image coming. First it's gonna go through the first module. I just discussed. Then that ImageNet label gonna. Convert to a. K-mean label by using that. Mapping table we just generated. So, which. It's basically just a. Ten elements list. Because we only have ten. K-mean classes. So, those ten elements actually. Is ordered by probability. So. For example. The first list which means. We think. Is. Most likely in class nine. But least likely in class four. Then. At same time. This attack image also gonna. Directly fit into the. K-mean cluster. So, K-mean cluster gonna generate another list. So, it's also a ten elements list. But for this list. The K-mean thinks. Most likely this image. Is in class two. But least likely in class nine. So, this two list actually. They contradict to each other. They don't agree. So, that's when we think. This filter think. This attack actually succeed. Because they are contradict. So, then. They gonna just output a zero. Or random number. Only when those two list match. Or some. Or pass some checking logic. We set. It's gonna let the. K-mean filter come through. So, that's the idea. Of the K-mean filter. So, that's all about. The design of our final. Summation for the defense. So, this is just a quick. Just a same polar plot. Showing the hit target rate. Of our defense against. Some strong attacks. So, you can see. For all six attacks. Hit target rate is close to zero. So, we believe. It is effective. And also has a good transferability. But. It's turn out. It's not. We still lost some points. So, I think. I think for the K-mean filter. K-mean module. There's still a lot to improve space. So, that might be. A direction we try to improve. So, in summary. I talk about. A set of attacks. Aiming different defense. And also. I talk about the defense. Compressed of image processing. Classified difference filter. And K-mean filter. With that. I'm going to finish my talk. Any questions? Yes. I want to ask you. Is the noise. The primary type of attack. Just random noise? Changes in the image? You mean. Is that random or not? Is the noise the main attack? That you're going into the image. Just random. Yes. Yes. So, we are. Yes. That's the main way to achieve the attack. Are there any types of targeted attacks. To try and manipulate. Actual portions of the image. Like the distort. Or elongate it. Or shrink it. You mean the attack method? Yes. Actually. So the attack actually is. Mathematically is actually. Just solving optimization problem. So it totally depends on. How do you define your problem. So there are some attacks. They can only adjust one pixel. It still achieves their purpose. To change the classification. And also they have. Some research proposal. Some patch. So basically it's just a pattern. A patch. When you put that patch onto anything. The image classifier gonna misclassify that image. So basically you can. Yes. By define your problem. You can control where you put those noise. Even though there are noise. But you can still control. Where you apply to it. Yes. From an image perspective. How the attacks and defenses work. Yes. How can you translate. Those same concepts to. Let's say some malware. That you're trying to process through. AI or ML. To classify. Whether it's benign or. Malicious. How would we say. Okay this is how we modify. The piece of malware with noise. Or padding. Process it through the AI. Is it literally the same way. That you would modify. The image to be able to. Tamper with the algorithm. Okay so your question is just. Ask if the same method. Can be applied to a different. Other AI applications. Is it literally the same way. Or is it completely different. At all. I think. Fundamentally they are same. So it's still another. Optimizing. Optimization problem. You just try to solve that optimization problem. But in practical. When you're doing attack. Against some other stuff. Even though it's not that far away. Like I'm doing the same. Attack against an image classifier. But in real. In the real world. There are more. There are a lot of factor. Has to be taken into account. For example. What I'm talking about. Is totally in the digital domain. So basically everything. Achieving in the computer. But if you want to achieve. A physical domain. Like you just put something on the wall. On the like. On the washing machine. The washing machine gonna. As a dryer or something. For that. You have to take into account. Like the light. The wheel angle. Yeah. Yes. Yeah. Actually that's a very good point. So yeah. That's why we. So there are a lot of different ways. To apply the same idea. So basically. Basically what we are trying to do. Is to keep the. The bad noise. Which is adversarial noise. But still keep the valid information. For the classifier. Because you cannot just totally get rid of everything. So that's also gonna mess up your classifier. Actually even for this. I didn't show here. But if you. If the parameter didn't set correctly. The accuracy of the classifier. Gonna strongly degrade. Yeah. So basically. Actually that's a good point. We can try to do something in the frequency domain. Actually that's one of our. Team members. Yes. Actually that's one of our team members. He's trying to work on that direction. Basically it's. It's not doing the. Image filtering. We're trying to look at the frequency domain. To tell if it's a real image or not. So that's. That's our idea. Yeah. Yes. That's another way. Yeah. And also because. Even though you carefully set up. Your filtering algorithm. It's still gonna affect the classifier accuracy. So basically. I read some paper. Basically the researcher is doing is. They use another set of neural network. Just try to calculate. Something called class activation. Region. So basically. When the classifier look at the image. There is an interesting region. Or those not interesting region. So basically that neural network. Just try to figure out. Which region is more important. Gonna affect the final classification. For that classifier. Then when we know that region. When we apply the image filter for the attack. We don't touch that region. We just filter everything else out. Yeah. But that's gonna be slow. Yeah. Yeah. Okay. I have one more. Okay. So you talked about. Processing the different images. Through different filters. To increase the accuracy. Right? Yes. One of the things that you mentioned. Was. You know your scan. Right? Yeah. So does the accuracy. Improve the more. Images you feed into. Into your data set. Or is there a certain point that. It doesn't matter how many. Images you throw. At your data set. The accuracy just peaks. So I think that depends. So it depends. What kind of. Algorithm you are using. So for example. If you are. So when. When you train that. Classifier. If you take into account both. Like pure original image. Or some image after filtering. So when you train that model. You already take into account that factor. So then. When you do the image filter later. It won't affect that. Classifier. But if you. If you try to. When you feed more image. I don't know. I'm not sure I fully understand it. But you mean. If you feed a lot of image. I think you are talking about training. Right? Yeah. So for training. Yeah we can. So that's actually. We can also do. But we can also do a mist of original image. And some image after image filter. So by doing that. We train that. Classifier. That classifier is going to learn. Okay. So some image is original. But some image is after some filtering. I can still identify they are same. So that's kind of like. How you build your training data set. But let's say you had unlimited time. And unlimited resources. Does the accuracy continue to improve. The more you feed. Or is there a certain point. Where it just peaks. No matter how much more time you spend. I think. That's limited by the. The neural network. Is not limited by the image filtering. So basically. I think it's going to reach a peak. I don't think you can just keep going. Yeah. I don't think. Yeah. Okay. Okay. Yeah. Thanks.