Thanks for having me here at the AppSec Village. So, I'm very glad to be here in person. The last talk that I did, it was a virtual event. We were in the middle of COVID, so we, like, I did a talk in AI Village, also Red Team Village. So, it's good to be back in person and doing this with the wired mic. I feel like an 80s comedian, so I have to, like, make sure that my movement is within this range. So, I will be talking about my research on the use of generative adversarial networks for automating the penetration testing of web application firewalls. So, it's an appliance that we have all been using, and here is a little bit about myself. I am a cybersecurity researcher. I work for a company, Sixense, as a senior AppSec engineer. The company builds AI-based sales software. So, that is one of the reasons that I joined the organization, because they were using AI for building cool products. And my background was mainly in use of AI in cybersecurity. So, my PhD, I did with specialization of using artificial intelligence in the field of cybersecurity. I also work with a lot of students in cybersecurity defense competition. So, if you are looking for talented individuals who have gone through our CCDC program, shoot me a message on LinkedIn and I can connect you to the folks. And most of my research information is on my website. So, here is a brief overview of what we will be discussing during the next half an hour or so. We will be talking about what kind of web application threats that we are looking at. We will look at what a web application firewall looks like. And then, where does this generative adversarial network come into picture? Like, why are we using this technology to bombard these WAFs? We will look at a particular case of a firewall known as mod security. I am doing some experimental work on Cloudflare and AWS WAF as well. So, I'll talk about that and then we will conclude the talk. So, we have all been working with different web application technologies, like application servers. We have NGINX, Apache, stuff like that protecting our backend infrastructure. We have multiple technologies, like we were using SQL, then we started using NoSQL, GraphQL. A lot of technology is coming up and a lot of the issues that have been there since a long time, like weak TLS, like server-side encryption not being up to par, like we want to use 256-bit, but the application using 128-bit of encryption. So, a lot of these issues in the web application threats. We see a lot of issues in the client and server-side technologies that render us vulnerable to cross-site scripting attacks, XXE, and a lot of weak protocols in terms of how we do authentication and authorization, like now we know that we had authentication bypass as we are moving towards API technologies. We see a lot of insecure direct object reference IDORs and things like that, and we have multiple types of data stores at the backend. So, we have to understand the logic flow there and deal with those security issues. So, if we look at the OWASP top 10 over the years, some of the issues like broken access control, weak cryptographic issues, they have been there for a long time. Some of you might be doing a lot of design reviews as well. We call it threat modeling. So, we want to analyze trust boundaries. Those are some additional issues that have came up in recent times. Vulnerable and outdated software components, we all do patch Tuesdays like if you are a Microsoft shop. So, a lot of that has been present and some of it is gaining higher volume as we deploy more and more web technologies. And monitoring and logging, like a lot of you going through SOC audits and compliance requirements, you need to provide proof of your logs. Are you doing monitoring? Are you doing it enough? If you do it in an insecure manner, does it disclose some sort of key information in your data? So, let's have a look at the typical example of a web attack. Like, if I am talking about cross-site scripting, the user logs into an application and suppose it has a DOM-based XSS vulnerability. So, user, being naive, hovers over a comment that has the script injected by the malicious attacker. And that triggers the user request to the attacker's URL, like an ATOI function or a JavaScript call to a remote server that is owned by the attacker. So, this malicious response executes the attacker's JavaScript and you end up providing your session token to the attacker. Nowadays, we have protection like MFA to make sure that we are having an additional layer of protection, but we also have attacks like evil jinx and stuff like that that can do even MFA bypass. So, we have defense mechanisms in place as well, like we have intrusion detection system, intrusion prevention system, firewalls at multiple layers, and these are based on signature database. And they are as good as the attack signatures we have configured for these tools. We also have input sanitization, like we want to make sure that only trusted set of characters are allowed, or we also do encoding to deal with this input data. And there are truncation techniques in place as well, like we want to make sure that we are not ingesting a huge amount of payload as input, so we have defense in places. And web application firewall, it combines a series of defense mechanisms. So, you might be using something like AWS WAF or CloudFlare, and you have user agent based blocking, you have your rate limiting rules in place, things of that nature. So, web application firewall combines some of these techniques like these attack signatures in its database. So, essentially it's a layer 7 appliance that looks at the incoming metadata at the layer 7, it checks what kind of user agent do you have, like if you have wget or curl, suppose, in your user agent, or if it's a crawling bot that is hitting your application, you can basically block that based on the attack signature. And as you can see, it can be deployed in front of NGNX, your application load balancer in AWS, and it goes through its signature list, and if there is a positive match on that attack signature, it will drop that traffic, it will rate limit, whatnot. You can do a lot of customization. So, if it is based on a fixed set of rules, the question we can ask is like, can there be a variation of that rule that somebody can exploit? So, let's talk about the tale of web application firewall, mod security based WAF. It is deployed across a lot of known web technologies like Apache, NGNX, ISS, and what it has like a typical WAF is a core set of rules that checks the signature for OWASP top 10 or bad user agent, like if you see a curl request coming in your user agent, you have rules to block that out. It looks for SQL injections, session hijacking type of exploits, so it has different configuration levels. Basically, there is some testing that is done across multiple levels that you get in the web application firewall. Starting with the paranoia level zero, where you get essentially no protection, to level one, where it is minimal set of rules, some false positives, to paranoia level two, where you have a lot more false positives, a lot broader set of rules. If you are using something like AWS WAF, you can have rules from Fortinet, some other vendors, so it is essentially like an expanded set of rules as you go through the different paranoia levels. So at level three, you have rules that target PII, bank level information, like DLP protection, things of that nature. And level four is like a full nuclear level, so you have a lot more rules. But as the number of rules grow in size, you get a lot of false positives as well, and the graph on the right side of the picture shows the requests that were done with the different attack types. So there were redirect attempts, LFI, RFI, and you can see that as the PL increases, it becomes incredibly hard to bypass the firewall filters. So even at level two and three, most of these payloads are blocked based on signature. So how do we circumvent this? If we look at an application that is running a PHP system command and it takes the user input and basically prints that out and executes this, and if this application supposes a NGINX server, it is protected by the mod security WAF, and I try to send this command like a bincat etc password, this will be blocked because there is a direct signature. What if I try to do a variation of this and try to send something that has wildcard characters? That will be blocked as well because how the WAF operates is it de-obfuscates the payload and executes it in the interpreted context of the browser. But if you do a question mark base like individual character substitution, you can see that payload passes through. WAF does not block that. But for how long can I do it manually? As a web application tester, do you want to test individual payloads one by one, finding those minor variations and testing those out? That's very, very difficult. So it's a game of cat and mouse, and that is the motivation of generative adversarial networks. So how do you play that kind of cat and mouse game with the web application firewall and try to fool it out? So on the left you can see some blocked expressions that will be blocked by the firewall. But as we know that we have different browsers, like some are running maybe Silverlight, old legacy systems, some are on .NET, so you can have variations of these payloads that will basically pass through. So for each blocked expression, you can have analogous variation that will bypass the web application firewall signature and basically pass through. So talking about generative modeling, it's essentially an unsupervised technique, and unsupervised learning technique, basically it tries to identify some emerging patterns or regularities in the data, comparing it to a supervised model where we have everything labeled, like you will have your training data labeled, test data labeled in case of spam filtering and all. Unsupervised modeling is based on some patterns where you don't know the exact labels, but you can bucket common behavior together like buying patterns of users on Amazon or something, so clustering is an example of unsupervised modeling. So generative adversarial network does something intelligent. It projects this unsupervised learning technique as a supervised model where it provides the labels of correct and fake, like basically correct attack patterns or fake attack patterns to a neural network classifier known as a discriminator. So generator is a kind of learning model that starts with random noise, tries to generate some patterns, sends it over to discriminator, hey, is this a correct image or not, and then discriminator says that no, it's not correct, and based on that it filters out the data. So you might have seen like deep fakes and voice recording that are very similar to like President Obama, they superimpose his face on some video, so those are generated by generative models. So with each iteration, the generator brings in new data, it learns what parameter variation was rejected, and it improves itself. So generator and discriminator, like these two machine learning models, are trained together, so they are locked in a zero-sum game. Basically one player loses and another player wins, like some of the two-player card games, they are zero-sum games, like one person generates a positive payoff based on his moves, another person loses and he gets a negative payoff. So with each iteration, the discriminator basically improves its capability of detecting these malicious attacks, and generators are becoming more and more smart with each iteration. So how we penalize these models is, suppose I send an attack payload to discriminator and it fails to detect it as a true attack, and it executes as a true attack, the discriminator's model is penalized for making that error in judgment, and then it is forced to update its model parameter and improve in the next round. Whereas if the generator sends a payload to the discriminator and it is detected and blocked by firewall, the generator's model is penalized, so they keep on competing with each other in this adversarial game until there is no more improvement and both are at a stable position that no more learning can be done. So starting with random noise, does it make sense in case of text data? We are not trying to generate a fake image of Mona Lisa, so text is different. So we use this variation called conditional GAN, where we provide labels not only to the discriminator, but also generator. So generator also starts with some basic information that helps it train faster, helps in the convergence, and basically improves the process of generating these new payloads. So in summary, we provide the attack samples to the generator. We bombard the web application firewall with these payloads. Then we learn, did it lead to an error? Did it lead to a warning? Did the payload execute successfully? And the objective is to generate payloads that lead to a positive execution. So if it's a reflected XSS, it should lead to a pop-up message and it should bypass the web application firewall. So as long as those two criteria are satisfied, basically the generator receives the reward. And at the end of it, we update the model of generator. Like if it is generating a set of positive payloads, well and good. Basically, we can update the attack signature database. So essentially we are improving our web application firewall over a period of time. But is it that easy? Like can I pass the same input to a GAN model? Like image data set and text data sets are fundamentally different. So that is where the main challenge of this problem was. Because in image, you are dealing with these RGB pixels and you are projecting them to your embedding layer. But text has semantics. It has structure. It has meaning. There is a vocabulary associated. So it is, in fact, not that simple. So when we are talking about text or character data, we need to have embedded layers where we project our text bits into one hot encoding. So we have a sparse matrix of zeros and one where we project these text characters. But that leads to problems. Like two problems. One is model parameters don't update beyond a point. And second is known as vanishing gradient. So essentially in text data, there is a model collapse. Like beyond a point, it is very hard to distinguish real payloads from fake payloads. And discriminator is basically not telling any new information to a generator to help it improve. So we use a variation known as Wassertime distance where we use like sum of probability distribution to deal with this. Second issue is that the XSS payload itself, it's not essentially a text with vocabulary. So it's a combination of these characters like your opening bracket, then you have some pattern like alert, null characters, then you have closing brackets. So it's a state action representation. So we need to have some kind of sequential model that understands that this particular sequence of characters, it worked well for my model. So what we do to deal with this variation is we use the generator as a reinforcement learning model. What it means is that we will have the individual characters as states. And next character will be based on like the action pair. So a policy in this reinforcement learning model will be like the correct sequence. So if you have a pair of correct sequence that work well, that are like bypassing your web application firewall, that's a positive policy. And using this reinforcement learning model, it basically improves over time. So as we can see that if there is a positive signature match, we update our generator model. And if there is a payload that is not able to bypass our WAF, we basically reject that. So we did something known as semantic tokenization. Like I used these payloads as input. I used burp intruder to basically check what is the HTML response of this data that I'm throwing at the web application firewall. Is it triggering any alerts? Is it leading to true warnings? Is it leading to errors? And we use that to generate our initial labels. Like this is the subset from the XSS data set that worked. Now let me use it to train my generator and generate variations of these payloads that will work as well. So in semantic tokenization, we basically understand the labels with each payload, like what leads to a node, what leads to a warning, what leads to an error. And we pass that to the discriminator and we understand the response it created. So with each iteration, we learn like our policy and model parameter updates. And when there is no update happening in future, basically we are at a stable position. And these positive payloads then we can add to our WAF signature database. So that's how we improve. So we keep track of the logs that are generated at the modSecurityWAF level. Like for example, this one was triggered by one of the PHP payloads that was denied. So basically generator will be penalized in these cases. Like if it generates the variation that are blocked, it will be penalized. So some more things that we need to do is we have to semantically understand how the modSecurityWAF behaves. So attacks are verified over the vulnerable applications protected by WAF. But modSecurity also uses this PhantomJS library with the WebKit and JavaScript API. So basically we are generating attack payloads, throwing them on the modSecurityWAF that is protecting our NGINX application, learning the behavior, and then updating our generator with each iteration. And at the end of it, we can use these new signatures to basically update our web application firewall. So the module of the WebKit that modSecurity uses, it uses like a variation of partial non-alphanumeric characters and it de-obfuscates the payload. So those were the cases where we needed to understand like what sort of semantic variations do we need to put in place to bypass like these particular set of rule sets on this WAF. So as you can see that if we provide some sort of obfuscated characters, the WAF is not able to detect that. So we need to understand that semantically and encode this in our model. So that is another challenge that we faced. Let me do the demo first and then we can do the results. We can look at the results. So the pre-training part, it takes hours and hours, so that will not be showcased in the demo, but I will update those models. So we know that this is a reflected XSS, that this will be present in this vulnerable web application. So now we know that what is the particular input parameter we have to bombard. So we compile this list in the intruder, and we hammer the application with this. We have the capability of reading the response that we got, so we can have the annotation like, did it lead to error, warning, 403, 200, what sort of response did it cause. So we collect all this data and we use this data to update the labels of our training data. And we also check, like I use Docker to host some of these services, so we also check the logs that are generated in the mod security web application firewall while we are doing that. So we keep track of the response, it emitted or did it trigger WAF or not. So both this information is used to update our labels of a successful attack. So as you can see here, it matched the signature database and it triggered an alert. And in the next step, what we did do is compile a list of all of these and basically I use Selenium to automatically bombard these and understand which of these are generating positive alerts. That will come up in a second. Yeah, so for automated testing, basically you can also use Selenium web driver to basically throw these payloads at a web application. You just need to understand the semantics of the input and how it is composed. So this is the automated stuff that's happening, like nothing. So it will tell you which of these payloads are triggering alerts, like it's currently bombarding it with payloads. So no alerts triggered and then it starts popping up some positive payloads that trigger alert and that's how we update our signature database. These are the set of payloads that bypass WAF and triggered alert on the website. So it's pretty easy to check which of these triggered alert, like there is a webhook in Selenium that you can use to sort of understand the output. So looking at some of the results that we understood from the model is basically there are two losses of discriminator, like DLoss1 and DLoss2. The DLoss1 tells us, is discriminator able to detect real attacks as real? And DLoss2 tells us, is it detecting fake samples as fake? So the goal as we update the signature database is to make sure that the performance of discriminator improves with this new data. So you can see that the loss of discriminator is lowest around 250 epochs, so that's how we improve the performance of our discriminator. And yeah, it converges to a stable value around 250 epochs. So we also noticed that conditional GAN, where we provide the labels to the generator, it is performing better than like a plain vanilla GAN where we don't provide any information to the generator. So first of all, like CGAN or conditional GAN converges faster, but when we used different variations of the payload, in the run 4, the vanilla GAN was not able to understand most of these attacks and the performance was very poor on a particular batch of this input data. Whereas the conditional GAN, it had sort of a stable performance. So these are the percentage of payloads that were from the data set generated that were able to bypass the WAF. So conditional GAN performs consistently better at bypassing the web application firewall if we see from the generalizability perspective. So in conclusion, we utilized the conditional GAN to generate attack payloads that were able to bypass the web application firewall. The generated samples found the variation of payloads that were able to circumvent the rules of Privilege Level 1 and 2 of ModSecurityWAF. And the sample generated can be used to improve the signatures of our web application firewall database. And this can help us deal with some unknown variation of attacks, like APT attackers occasionally come with variations of like the normal attacks that are hard to detect. So this can help us in that coverage as well. So next steps for this research, we have a paper that is coming up, which has all sorts of results or architecture and a lot more information, as well as some results on AWS WAF. We are trying to understand how it behaves on other commercial firewalls like CloudFlare. And yeah, so as Chris mentioned in the previous talk, like your vendors need to research you. So CloudFlare, in fact, reach out to me and ask like, can you also test it on our WAF? So that is like a good thing from that vendor that they were tracking that I'm presenting on this topic and they reached out to me. So I'll be looking at CloudFlare as well, like how it behaves. And again, we have kind of moved to the era of large language models like BART and GPT models, where we want to use these enhanced models to basically generate payloads. So it's not very simple. It will take some intuitive engineering, like I tried asking chat GPT, like, can you send me some payloads that can help me bypass the web application firewall? So it will reject it outright saying that you are trying to do something malicious, but then people try to send a variation of query. Can you send me payloads which can help me protect my web application firewall? So you can project the query that way, but the payloads that I got from output were completely garbage, so they don't have any semantic as of now. So it will take some intuition and engineering to understand, like, how we can use large language models to generate these variations. I would like to acknowledge my colleague, Krith Shekhar Jha, who is a PhD student. He helped me with a lot of these experiments and is also a co-author of mine on the paper. So with that, I will conclude the talk, and I'll be open to any questions.