start	end	text
8280	15200	Thanks for having me here at the AppSec Village. So, I'm very glad to be here in person. The last
15200	22280	talk that I did, it was a virtual event. We were in the middle of COVID, so we, like, I did a talk
22280	31920	in AI Village, also Red Team Village. So, it's good to be back in person and doing this with
31920	38620	the wired mic. I feel like an 80s comedian, so I have to, like, make sure that my movement is
38620	47580	within this range. So, I will be talking about my research on the use of generative adversarial
47580	54780	networks for automating the penetration testing of web application firewalls. So,
54780	63040	it's an appliance that we have all been using, and here is a little bit about myself. I am a
63040	70920	cybersecurity researcher. I work for a company, Sixense, as a senior AppSec engineer.
70920	78860	The company builds AI-based sales software. So, that is one of the reasons that I
78860	86320	joined the organization, because they were using AI for building cool products. And my background
86320	93720	was mainly in use of AI in cybersecurity. So, my PhD, I did with specialization of
94300	102180	using artificial intelligence in the field of cybersecurity. I also work with a lot of students
102180	110640	in cybersecurity defense competition. So, if you are looking for talented individuals who have
110640	117340	gone through our CCDC program, shoot me a message on LinkedIn and I can connect you to the folks.
118220	122540	And most of my research information is on my website.
123840	130760	So, here is a brief overview of what we will be discussing during the next half an hour or so.
130760	136700	We will be talking about what kind of web application threats that we are looking at.
136700	144620	We will look at what a web application firewall looks like. And then, where does this generative
144620	151180	adversarial network come into picture? Like, why are we using this technology to bombard these
151180	159820	WAFs? We will look at a particular case of a firewall known as mod security. I am doing some
160620	168820	experimental work on Cloudflare and AWS WAF as well. So, I'll talk about that and then we will
168820	177120	conclude the talk. So, we have all been working with different web application technologies,
177120	184700	like application servers. We have NGINX, Apache, stuff like that protecting our
186180	193280	backend infrastructure. We have multiple technologies, like we were using SQL,
193280	201100	then we started using NoSQL, GraphQL. A lot of technology is coming up and a lot of the
201900	210920	issues that have been there since a long time, like weak TLS, like server-side encryption
210920	219540	not being up to par, like we want to use 256-bit, but the application using 128-bit of
220480	228180	encryption. So, a lot of these issues in the web application threats. We see a lot of issues in
228720	234160	the client and server-side technologies that render us vulnerable to cross-site scripting
234160	244040	attacks, XXE, and a lot of weak protocols in terms of how we do authentication and authorization,
244040	252120	like now we know that we had authentication bypass as we are moving towards API technologies.
252120	259980	We see a lot of insecure direct object reference IDORs and things like that, and
260800	268540	we have multiple types of data stores at the backend. So, we have to understand the logic
268540	278540	flow there and deal with those security issues. So, if we look at the OWASP top 10 over the years,
278540	286620	some of the issues like broken access control, weak cryptographic issues, they have been there
286620	293020	for a long time. Some of you might be doing a lot of design reviews as well. We call it threat
293020	300500	modeling. So, we want to analyze trust boundaries. Those are some additional issues that have came
300500	308920	up in recent times. Vulnerable and outdated software components, we all do patch Tuesdays
308920	317380	like if you are a Microsoft shop. So, a lot of that has been present and some of it is gaining
317380	325700	higher volume as we deploy more and more web technologies. And monitoring and logging, like
325860	331720	a lot of you going through SOC audits and compliance requirements, you need to provide
331720	338820	proof of your logs. Are you doing monitoring? Are you doing it enough? If you do it in an insecure
338820	350060	manner, does it disclose some sort of key information in your data? So, let's have a look
350060	357280	at the typical example of a web attack. Like, if I am talking about cross-site scripting, the
357280	367300	user logs into an application and suppose it has a DOM-based XSS vulnerability. So, user,
368140	375520	being naive, hovers over a comment that has the script injected by the malicious attacker.
375520	386880	And that triggers the user request to the attacker's URL, like an ATOI function or a
386880	396340	JavaScript call to a remote server that is owned by the attacker. So, this malicious response
396340	403620	executes the attacker's JavaScript and you end up providing your session token to the attacker.
405060	412760	Nowadays, we have protection like MFA to make sure that we are having an additional layer of
412760	419240	protection, but we also have attacks like evil jinx and stuff like that that can do even MFA
419720	430000	bypass. So, we have defense mechanisms in place as well, like we have intrusion detection system,
430000	436020	intrusion prevention system, firewalls at multiple layers, and these are based on
436560	444420	signature database. And they are as good as the attack signatures we have configured for these
445450	455060	tools. We also have input sanitization, like we want to make sure that only trusted set of
455060	463720	characters are allowed, or we also do encoding to deal with this input data. And there are
464260	472960	truncation techniques in place as well, like we want to make sure that we are not ingesting a
472960	480760	huge amount of payload as input, so we have defense in places. And web application firewall,
480760	489820	it combines a series of defense mechanisms. So, you might be using something like AWS
489820	499920	WAF or CloudFlare, and you have user agent based blocking, you have your rate limiting rules in
499920	507900	place, things of that nature. So, web application firewall combines some of these techniques like
507900	517340	these attack signatures in its database. So, essentially it's a layer 7 appliance that looks
517340	524740	at the incoming metadata at the layer 7, it checks what kind of user agent do you have, like if you
525720	534020	have wget or curl, suppose, in your user agent, or if it's a crawling bot that is hitting your
534020	540090	application, you can basically block that based on the attack signature.
541420	552080	And as you can see, it can be deployed in front of NGNX, your application load balancer in AWS,
552080	560280	and it goes through its signature list, and if there is a positive match on that attack signature,
560280	565900	it will drop that traffic, it will rate limit, whatnot. You can do a lot of customization.
566760	574240	So, if it is based on a fixed set of rules, the question we can ask is like,
574240	578860	can there be a variation of that rule that somebody can exploit?
582120	591100	So, let's talk about the tale of web application firewall, mod security based WAF. It is deployed
591100	602200	across a lot of known web technologies like Apache, NGNX, ISS, and what it has like a typical
602200	613160	WAF is a core set of rules that checks the signature for OWASP top 10 or bad user agent,
613160	619060	like if you see a curl request coming in your user agent, you have rules to block that out.
619060	629340	It looks for SQL injections, session hijacking type of exploits, so it has different configuration
629340	638380	levels. Basically, there is some testing that is done across multiple levels that you get in the
638380	644660	web application firewall. Starting with the paranoia level zero, where you get essentially
644660	651780	no protection, to level one, where it is minimal set of rules, some false positives,
652420	659200	to paranoia level two, where you have a lot more false positives, a lot broader set of rules.
659580	669100	If you are using something like AWS WAF, you can have rules from Fortinet, some other vendors,
669100	677120	so it is essentially like an expanded set of rules as you go through the different paranoia levels.
677820	687140	So at level three, you have rules that target PII, bank level information, like DLP protection,
687140	694740	things of that nature. And level four is like a full nuclear level, so you have a lot more rules.
694740	704620	But as the number of rules grow in size, you get a lot of false positives as well, and the
704620	712320	graph on the right side of the picture shows the requests that were done with the different attack
712320	721450	types. So there were redirect attempts, LFI, RFI, and you can see that as the PL increases,
721860	729750	it becomes incredibly hard to bypass the firewall filters. So even at level two and three,
729750	733420	most of these payloads are blocked based on signature.
736300	746180	So how do we circumvent this? If we look at an application that is running a PHP system command
746180	754960	and it takes the user input and basically prints that out and executes this, and if this application
754960	765700	supposes a NGINX server, it is protected by the mod security WAF, and I try to send this command
766800	774640	like a bincat etc password, this will be blocked because there is a direct signature.
775420	782860	What if I try to do a variation of this and try to send something that has wildcard characters?
783020	789340	That will be blocked as well because how the WAF operates is it de-obfuscates the payload
789340	798420	and executes it in the interpreted context of the browser. But if you do a question mark base
798420	803840	like individual character substitution, you can see that payload passes through.
803840	812840	WAF does not block that. But for how long can I do it manually? As a web application tester,
812840	818620	do you want to test individual payloads one by one, finding those minor variations and
818620	822340	testing those out? That's very, very difficult.
824800	831560	So it's a game of cat and mouse, and that is the motivation of generative adversarial networks.
832740	839040	So how do you play that kind of cat and mouse game with the web application firewall and try
839040	846400	to fool it out? So on the left you can see some blocked expressions that will be blocked by the
846400	852700	firewall. But as we know that we have different browsers, like some are running maybe Silverlight,
852700	859000	old legacy systems, some are on .NET, so you can have variations of these payloads
859670	867220	that will basically pass through. So for each blocked expression, you can have analogous
868040	875820	variation that will bypass the web application firewall signature and basically pass through.
878320	885180	So talking about generative modeling, it's essentially an unsupervised technique,
885180	894120	and unsupervised learning technique, basically it tries to identify some emerging patterns or
894120	901220	regularities in the data, comparing it to a supervised model where we have everything labeled,
901520	908160	like you will have your training data labeled, test data labeled in case of spam filtering and
908160	915980	all. Unsupervised modeling is based on some patterns where you don't know the exact labels,
915980	923320	but you can bucket common behavior together like buying patterns of users on Amazon or something,
923320	930180	so clustering is an example of unsupervised modeling. So generative adversarial network
930180	937120	does something intelligent. It projects this unsupervised learning technique as a supervised
937120	948100	model where it provides the labels of correct and fake, like basically correct attack patterns or
948100	958560	fake attack patterns to a neural network classifier known as a discriminator. So generator is a
958560	965040	kind of learning model that starts with random noise, tries to generate some patterns,
965040	970440	sends it over to discriminator, hey, is this a correct image or not, and then discriminator
970440	978320	says that no, it's not correct, and based on that it filters out the data. So you might have
978320	984880	seen like deep fakes and voice recording that are very similar to like President Obama,
984880	991180	they superimpose his face on some video, so those are generated by generative models.
991180	1000540	So with each iteration, the generator brings in new data, it learns what parameter variation
1000540	1010400	was rejected, and it improves itself. So generator and discriminator, like these two machine learning
1010400	1018460	models, are trained together, so they are locked in a zero-sum game. Basically one player loses
1018460	1025300	and another player wins, like some of the two-player card games, they are zero-sum games,
1025300	1035200	like one person generates a positive payoff based on his moves, another person loses and he gets a
1035200	1042760	negative payoff. So with each iteration, the discriminator basically improves its capability
1042760	1050680	of detecting these malicious attacks, and generators are becoming more and more smart
1051140	1059560	with each iteration. So how we penalize these models is, suppose I send an attack payload
1059560	1068360	to discriminator and it fails to detect it as a true attack, and it executes as a true attack,
1068780	1076160	the discriminator's model is penalized for making that error in judgment, and then it is forced to
1076160	1084280	update its model parameter and improve in the next round. Whereas if the generator sends a
1084280	1091240	payload to the discriminator and it is detected and blocked by firewall, the generator's model
1091240	1096200	is penalized, so they keep on competing with each other in this adversarial game
1097100	1103960	until there is no more improvement and both are at a stable position that no more learning can
1103960	1114530	be done. So starting with random noise, does it make sense in case of text data? We are not
1114530	1123090	trying to generate a fake image of Mona Lisa, so text is different. So we use this variation
1123090	1131660	called conditional GAN, where we provide labels not only to the discriminator, but also generator.
1132090	1139870	So generator also starts with some basic information that helps it train faster,
1139870	1147850	helps in the convergence, and basically improves the process of generating these new payloads.
1151480	1162970	So in summary, we provide the attack samples to the generator. We bombard the web application
1162970	1170640	firewall with these payloads. Then we learn, did it lead to an error? Did it lead to a warning?
1170930	1177130	Did the payload execute successfully? And the objective is to generate payloads
1177490	1188270	that lead to a positive execution. So if it's a reflected XSS, it should lead to a pop-up message
1189350	1196510	and it should bypass the web application firewall. So as long as those two criteria are satisfied,
1197290	1204490	basically the generator receives the reward. And at the end of it, we update the model of
1204490	1214010	generator. Like if it is generating a set of positive payloads, well and good. Basically,
1214350	1220030	we can update the attack signature database. So essentially we are improving our web application
1220030	1230610	firewall over a period of time. But is it that easy? Like can I pass the same input to a GAN
1230610	1236970	model? Like image data set and text data sets are fundamentally different. So that is where the
1236970	1243490	main challenge of this problem was. Because in image, you are dealing with these RGB
1244810	1251450	pixels and you are projecting them to your embedding layer. But text has semantics. It
1251450	1259070	has structure. It has meaning. There is a vocabulary associated. So it is, in fact,
1259070	1267890	not that simple. So when we are talking about text or character data, we need to
1268890	1277890	have embedded layers where we project our text bits into one hot encoding. So we have a sparse
1277890	1286590	matrix of zeros and one where we project these text characters. But that leads to problems. Like
1286590	1295530	two problems. One is model parameters don't update beyond a point. And second is known as
1295530	1306710	vanishing gradient. So essentially in text data, there is a model collapse. Like beyond a point,
1306710	1313350	it is very hard to distinguish real payloads from fake payloads. And discriminator is basically not
1313350	1322190	telling any new information to a generator to help it improve. So we use a variation known as
1322710	1330990	Wassertime distance where we use like sum of probability distribution to deal with this.
1330990	1339630	Second issue is that the XSS payload itself, it's not essentially a text with vocabulary. So
1339630	1348310	it's a combination of these characters like your opening bracket, then you have some pattern like
1348310	1356990	alert, null characters, then you have closing brackets. So it's a state action representation.
1356990	1366390	So we need to have some kind of sequential model that understands that this particular sequence of
1366390	1373510	characters, it worked well for my model. So what we do to deal with this variation is
1374870	1382770	we use the generator as a reinforcement learning model. What it means is that we will have the
1382770	1390950	individual characters as states. And next character will be based on like the action pair.
1390950	1398970	So a policy in this reinforcement learning model will be like the correct sequence. So if you have
1399490	1406300	a pair of correct sequence that work well, that are like bypassing your web application firewall,
1406810	1413390	that's a positive policy. And using this reinforcement learning model, it basically
1413390	1422380	improves over time. So as we can see that if there is a positive signature match,
1422380	1429500	we update our generator model. And if there is a payload that is not able to bypass our WAF,
1429500	1437620	we basically reject that. So we did something known as semantic tokenization. Like I used
1437620	1446660	these payloads as input. I used burp intruder to basically check what is the HTML response
1446660	1453140	of this data that I'm throwing at the web application firewall. Is it triggering any
1453140	1460800	alerts? Is it leading to true warnings? Is it leading to errors? And we use that to generate
1460800	1470520	our initial labels. Like this is the subset from the XSS data set that worked. Now let me use it
1470520	1476500	to train my generator and generate variations of these payloads that will work as well.
1478920	1485940	So in semantic tokenization, we basically understand the labels with each payload,
1485940	1493320	like what leads to a node, what leads to a warning, what leads to an error. And we pass
1493320	1502180	that to the discriminator and we understand the response it created. So with each iteration,
1502180	1511900	we learn like our policy and model parameter updates. And when there is no update happening
1511900	1518740	in future, basically we are at a stable position. And these positive payloads then we can add to our
1518740	1529060	WAF signature database. So that's how we improve. So we keep track of the logs that are generated
1529060	1537820	at the modSecurityWAF level. Like for example, this one was triggered by one of the PHP payloads
1537820	1545660	that was denied. So basically generator will be penalized in these cases. Like if it generates
1545660	1554720	the variation that are blocked, it will be penalized. So some more things that we need to do
1554720	1562880	is we have to semantically understand how the modSecurityWAF behaves. So attacks are verified
1562880	1571800	over the vulnerable applications protected by WAF. But modSecurity also uses this PhantomJS
1571800	1582040	library with the WebKit and JavaScript API. So basically we are generating attack payloads,
1582040	1589720	throwing them on the modSecurityWAF that is protecting our NGINX application,
1590510	1596420	learning the behavior, and then updating our generator with each iteration. And at the end
1596420	1603130	of it, we can use these new signatures to basically update our web application firewall.
1607580	1617000	So the module of the WebKit that modSecurity uses, it uses like a variation of partial
1617000	1623800	non-alphanumeric characters and it de-obfuscates the payload. So those were the cases where we
1623800	1630240	needed to understand like what sort of semantic variations do we need to put in place to bypass
1630240	1637180	like these particular set of rule sets on this WAF. So as you can see that if we provide some
1637180	1644780	sort of obfuscated characters, the WAF is not able to detect that. So we need to understand
1644780	1651820	that semantically and encode this in our model. So that is another challenge that we faced.
1651820	1658380	Let me do the demo first and then we can do the results. We can look at the results.
1661920	1668680	So the pre-training part, it takes hours and hours, so that will not be showcased in the demo,
1668680	1675100	but I will update those models. So we know that this is a reflected XSS, that this will be
1675100	1685540	present in this vulnerable web application. So now we know that what is the particular
1686120	1691440	input parameter we have to bombard. So we compile this list in the intruder,
1692140	1699660	and we hammer the application with this. We have the capability of reading the response that we
1699660	1706920	got, so we can have the annotation like, did it lead to error, warning, 403, 200, what sort of
1706920	1717460	response did it cause. So we collect all this data and we use this data to update the labels
1717460	1725240	of our training data. And we also check, like I use Docker to host some of these services,
1725240	1731360	so we also check the logs that are generated in the mod security web application firewall
1731940	1737820	while we are doing that. So we keep track of the response, it emitted or did it trigger
1737820	1745780	WAF or not. So both this information is used to update our labels of a successful attack.
1745780	1753960	So as you can see here, it matched the signature database and it triggered an alert.
1758220	1764280	And in the next step, what we did do is compile a list of all of these and
1766740	1775140	basically I use Selenium to automatically bombard these and understand which of these are
1775780	1780320	generating positive alerts. That will come up in a second.
1785950	1793030	Yeah, so for automated testing, basically you can also use Selenium web driver to
1793030	1797530	basically throw these payloads at a web application. You just need to
1798110	1804530	understand the semantics of the input and how it is composed.
1809330	1815990	So this is the automated stuff that's happening, like nothing.
1816630	1822430	So it will tell you which of these payloads are triggering alerts, like it's currently
1822430	1832700	bombarding it with payloads. So no alerts triggered and then it starts popping up some
1832700	1839500	positive payloads that trigger alert and that's how we update our signature database. These are
1839500	1845660	the set of payloads that bypass WAF and triggered alert on the website.
1849860	1857300	So it's pretty easy to check which of these triggered alert, like there is a
1857300	1870460	webhook in Selenium that you can use to sort of understand the output.
1870460	1872980	So looking at some of the results that we understood
1872980	1882830	from the model is basically there are two losses of discriminator,
1882830	1889310	like DLoss1 and DLoss2. The DLoss1 tells us, is discriminator able to detect
1890070	1896970	real attacks as real? And DLoss2 tells us, is it detecting fake samples as fake?
1897130	1903250	So the goal as we update the signature database is to make sure that the performance of
1903250	1911330	discriminator improves with this new data. So you can see that the loss of discriminator is
1911330	1918870	lowest around 250 epochs, so that's how we improve the performance of our discriminator.
1920010	1925310	And yeah, it converges to a stable value around 250 epochs.
1927090	1934490	So we also noticed that conditional GAN, where we provide the labels to the generator,
1934490	1940290	it is performing better than like a plain vanilla GAN where we don't provide any information to the
1940290	1947790	generator. So first of all, like CGAN or conditional GAN converges faster,
1947790	1955210	but when we used different variations of the payload, in the run 4,
1955210	1962530	the vanilla GAN was not able to understand most of these attacks and the performance was
1962530	1972390	very poor on a particular batch of this input data. Whereas the conditional GAN, it had sort of a
1972390	1978650	stable performance. So these are the percentage of payloads that were from the data set generated
1978650	1987290	that were able to bypass the WAF. So conditional GAN performs consistently better at bypassing the
1987290	1993070	web application firewall if we see from the generalizability perspective.
1994230	2001390	So in conclusion, we utilized the conditional GAN to generate attack payloads that were able
2001390	2010130	to bypass the web application firewall. The generated samples found the variation of
2010130	2018930	payloads that were able to circumvent the rules of Privilege Level 1 and 2 of ModSecurityWAF.
2019690	2026510	And the sample generated can be used to improve the signatures of our web application firewall
2026510	2035330	database. And this can help us deal with some unknown variation of attacks, like APT attackers
2035330	2042270	occasionally come with variations of like the normal attacks that are hard to detect. So this
2042270	2051370	can help us in that coverage as well. So next steps for this research, we have a paper that
2051370	2057850	is coming up, which has all sorts of results or architecture and a lot more information,
2057850	2067230	as well as some results on AWS WAF. We are trying to understand how it behaves on other commercial
2067230	2074930	firewalls like CloudFlare. And yeah, so as Chris mentioned in the previous talk, like your vendors
2074930	2080390	need to research you. So CloudFlare, in fact, reach out to me and ask like, can you also test
2080390	2087450	it on our WAF? So that is like a good thing from that vendor that they were tracking that I'm
2087450	2092390	presenting on this topic and they reached out to me. So I'll be looking at CloudFlare as well,
2092390	2100710	like how it behaves. And again, we have kind of moved to the era of large language models like
2101450	2109770	BART and GPT models, where we want to use these enhanced models to basically generate
2109770	2116990	payloads. So it's not very simple. It will take some intuitive engineering, like I tried asking
2116990	2123230	chat GPT, like, can you send me some payloads that can help me bypass the web application
2123230	2128730	firewall? So it will reject it outright saying that you are trying to do something malicious,
2128730	2134330	but then people try to send a variation of query. Can you send me payloads which can
2134890	2139450	help me protect my web application firewall? So you can project the query that way, but
2140150	2145110	the payloads that I got from output were completely garbage, so they don't have any
2145110	2150670	semantic as of now. So it will take some intuition and engineering to understand, like,
2151210	2155570	how we can use large language models to generate these variations.
2156150	2162270	I would like to acknowledge my colleague, Krith Shekhar Jha, who is a PhD student.
2162450	2168670	He helped me with a lot of these experiments and is also a co-author of mine on the paper.
2168670	2175890	So with that, I will conclude the talk, and I'll be open to any questions.
