start	end	text
0	1320	Good morning.
3380	5280	Everyone showed up bright and early.
6200	10720	It's a little early for a conference, but thank you guys for coming this early and joining us.
11020	13860	My name is Ben Sadegopour, and I have Adam here.
14380	21980	We every year come to DEF CON and we try to do a workshop that's different, and we'll talk about the workshop today.
21980	27620	But this is, I think, a fundamentally interesting and useful skill that I want you to take away.
27620	31480	There is a lot of slides to go through today, so we're going to go through them as fast as we can.
31480	34080	I think he has 190 slides or something like that.
34540	35780	198 slides.
36600	40260	So it's going to be very fast.
40260	43760	It's going to be a lot of regex stuff, and then we're going to apply it to bug bounties.
43760	46920	So tons of stuff for our schedule today.
46920	50580	I will talk about some of the OSINT and how I apply this to bug bounties.
50740	54480	Adam's going to cover, pretty much teaching you how to do regex.
54480	56480	Again, if anyone here is really good at regex...
57840	59260	Okay, I'm not either.
60520	61320	I'm with you.
61320	62120	Yeah, chat GPT.
62120	64420	So yeah, we want to make sure you learn something and you can apply it.
64420	72060	I think regex is a root cause of a lot of client-side vulnerabilities, some server-side vulnerabilities, and you can do a lot of good stuff with it on GitHub.
72060	76480	So I'll let Adam... Actually, I'm going to introduce myself and then hand it over to Adam and I'm going to sit down.
76600	77140	So I'm Ben.
77140	81520	I've been doing bug bounties since 2013 or 14.
81960	84680	I've done over 1.8 million in bounties.
84680	88600	Majority of it since I've gone full-time since 2022 or 2023.
89400	101600	Previously, I was the head of hacker education at HackerOne and currently Adam and I have co-founded a company called Hacking Hub, where we want to do more of these things and these workshops and courses and talks where we train the next generation of hackers.
102100	109200	Most people have probably seen me on social media for my bug bounty stuff or content, but I also do some pen tests and content creation on the side.
109200	112880	And you can just follow me at NahumSick on most social media platforms.
114360	115920	Hey, I'm Adam Langley.
116220	123600	Apologize if I have my head in the laptop, because like you heard earlier, I've got 198 slides, so there's a lot to look at and a lot to explain.
123980	126820	So I started hacking in the late 90s.
126820	131940	Got some interesting stories that I won't share quite on stage, but may exchange them for some drinks.
132180	139960	Worked in web development for 20 years, then finally put both of those things together by creating CTFs and learning labs for people.
140160	147460	You'll find some of my CTFs and educational content on Hacking Hub, HackerOne, TryHackMe, and other CTF events as well.
147720	155200	As Ben mentioned, we run a company called Hacking Hub, where I'm the CTO there, and I build core applications, courses, labs, and learn CTFs.
155200	157600	You can find me online at buildhacksecure.
159380	162020	Okay, so just a brief purpose of this.
162080	166100	Regits can always look very overwhelming, but we're here to help.
166100	167620	We want to teach you the basics.
167620	171740	It's not going to go through completely everything that's involved in Regits.
171740	180800	There's different Regits packages as well, which some have some features and the other ones don't, but we're hoping to kind of give you enough information to make you dangerous.
182280	187080	Using this will help you discover vulnerabilities and understand why they might occur.
187400	189580	It'll help you search for things better.
189800	196700	It'll help you discover secrets, and also I'll mention at the end some cool tools as well that you can build with it as well.
196700	204060	So in summary, we're going to take you from this, hopefully, to Anoregits.
204700	208180	Okay, so the first part is basic string matching.
208420	218720	So in most programming languages, you have some functions in there which will help you work out if a string starts with, ends with, or maybe contains.
219680	223100	So we've got Python, which it starts with, ends with, substring.
223180	225860	JavaScript starts with, ends with, includes.
226040	229620	You'll see a very common pattern throughout all the different languages.
229640	234000	They all contain these things, apart from Go, which gets a bit crazy.
234000	238320	It's got its own things with half-prefix and half-suffix, which is just a bit posh.
238840	247460	Okay, so the first part of... so the problem with this is that it actually has limitations, so you can't always match the exact data that you want to.
247460	249920	So let's just discuss the starts with limitations.
250460	256520	So say if you've got a range of IP addresses and you want to see whether your client is visiting from one of those.
256720	261800	In code, you might just have to have some horrendous if block or a switch statement to do that.
262340	268720	With Regex, you can have this very easy to read thing to match all those patterns.
268720	271100	Don't worry if you don't understand it, we'll break it down.
271100	276440	There's just a few little things you need until you can have that moment where you go, I know what that means.
277540	279040	Ends with limitations.
279180	287200	Say if you want to check an email address to make sure it ends with a specific domain on there, or like a top-level domain, so you might have three different ones.
287400	294020	Again, you can have an if statement or a switch statement to check for those things, or you can have a nice Regex which covers it in one go.
295140	297080	And then it contains limitations.
297240	306240	So imagine if you're running some kind of chat service and you want to check for any kind of dodgy input, making sure nobody's getting scammed and putting like credit card numbers in there.
306240	313500	So obviously you can't search for every credit card in existence, you need to search for a particular pattern in there.
314000	324620	And also that pattern can change as well, it might just not be like a straightforward bunch of numbers, there might be hyphens in there, or there might be spaces in there, which makes it very difficult to find that information.
327340	336940	But then again, this simple Regex can actually match all those patterns, it can match for those digits, it can match for spaces, it can match for hyphens in between, just with that simple statement.
338680	340500	So what is Regex?
340500	348460	So Regex is a search pattern language, and it will help you find, match and extract specific parts of text from strings.
348960	362840	Think of it like a state machine, so each of your Regex instructions, so you start at one place, if that rule matches, it moves to the next, and then it moves to the next, and then if that rule fails, it goes back to the beginning again, and it tries to match it somewhere else,
362840	365660	until you've got all the way through, and you've finally got a match.
365660	372740	So think of it like a flow diagram, where it asks questions, yes, no, and then kind of goes all the way down until you've found a complete match.
374600	381920	So at first, you've got like literal matches, which is basically the same as like finding something on a page, and like hitting control F.
381980	386180	So if you're certain, if you do a Regex, which is just hello, it'll find the string hello in there.
386800	388140	So nice and easy.
388540	401220	Then you've got, again, with like words, if you're searching for the word computer, we've just found, you'll notice that you'll find the word computer, but you'll also find the word supercomputer as well, which, so you've got kind of some false positives in here.
401880	404460	This is where you can start using word boundaries as well.
404460	411980	So you can wrap your words with this slash B, and then you can make sure that there's no characters either side of that.
412180	415880	It does have exceptions for like punctuation marks as well.
416780	420240	So like question marks, full stops, that works absolutely fine.
420240	423820	But as soon as you introduce another letter in there, then that Regex will fail.
423820	425160	It won't catch that word.
426900	429440	Okay, and then we have anchors for starts with.
429440	443980	So if you're receiving some strings, so say if you want to like get a website address, from an input field, but somebody randomly types in a whole string where there is a website address in there, but it's not where you think it's going to be.
443980	446780	So in this case, you can see it's in the middle of the string.
446780	448120	So that's no good to us.
448560	455920	What we want is this symbol here, which is just a caret at the start, which says the string must start with HTTPS.
456160	462280	You'll also notice as well that there's some special characters in there, like the forward slashes, which you have to put back first.
464160	466860	So now you can see that this matches perfectly.
468120	471940	And then on the opposite side of that, you've got anchors with the end width.
472140	474140	And that's just a dollar sign on here.
474140	482840	So if again, you have some simple Regex, which is example.co, you'll see again, the middle of it matches, which will pass the Regex rule.
482840	486240	But of course, that's not correct, because you've got UK at the end.
487260	496180	But if you pop the dollar sign at the end, you're basically saying you want example.co, and nothing else after that, not anything whatsoever.
496180	499300	So now it's gone to blank, so it's not matching that rule.
500600	504600	Again, you change the code back, and it's correct.
505760	511600	One thing to note as well is the period symbol in here, which you'll see come up in the vulnerabilities.
511600	516220	This catches so many developers out, and it leads to very interesting results.
516220	518660	So this is actually treated like a wildcard.
518660	522980	You'd think they'd use something like a star or something, or a percent symbol to cover this.
523100	529740	But it's the full stop, which can basically mean any character you want, apart from a carriage return.
530620	540000	So if you put the backslash in there to signify it must only be a period sign, you'll see the example.xco doesn't match anymore.
544250	546350	Next is character sets.
546390	549750	This is where you can start making some really interesting rules.
549750	553630	So character sets, you have it per character.
553630	557310	It checks the string, and it's each character.
557310	563190	So the first one on this character set says it can only be the characters A, B, or C.
564470	569210	So just in some example, if there's any bricks in here, you'll notice that these are postcodes.
569210	577490	So what this is saying is we've got the character sign, which is saying the string must start with, and then anything that starts with M, L, or B.
577490	582890	So you can see it's matched the two first ones, and the fourth one as well, absolutely fine.
582890	588130	Obviously, OX and EX doesn't start with MLB, so that one doesn't get matched.
589210	593570	You can also add a character symbol within character sets.
593570	599130	So instead of this meaning that the string must start with, it actually inverts the rule instead.
599130	602950	So it'll find anything that doesn't match the characters that you've put in there.
602950	606350	So now you can see the OX and EX match absolutely fine.
608690	610410	And then it gets even more interesting.
610410	612310	You can have character ranges in here.
612310	617670	So in this example, we've got any characters between A to L that will match.
617670	623390	So of course, we've got those three postcodes that do match there within that range, but the M and the OX don't.
624430	633250	So with ranges, you can have uppercase letters, lowercase letters, numbers, but then you can also add them together as well.
633250	639050	So this is saying the character can match A to L, or 0 to 5.
639270	647130	So then we can start using the information that we've learned so far to build like a basic regex, which would match postcodes.
647130	668750	So we're saying that these postcodes, postcodes must start with a letter between A to Z, which is the capital, two digits, a space, another digit, and then two letters at the end, A to Z, and then nothing else after that.
668750	672390	And you can see that those rules match exactly on there.
674170	676190	Next we have quantifiers.
676550	683530	So with this, you can have like your character sets and your rules, and then you can have kind of a rule after that.
683530	686210	So we'll go through each one kind of so it makes sense.
686510	694830	So the first one, again, we've got the character set of A to Z with the plus after this, and that says it must match one or more instances of characters.
694990	702170	So we can see that the I is highlighted because we found one of those, then the comma, that's not in that character set, so that doesn't get matched.
702270	711090	And then the rest of it, my name is, of course, those are all characters, and there's one or more instances of them in the string, so that's like matching the whole my name is.
711330	719830	The capital A isn't matched on there because we've only done lowercase letters, and then the D-A-M, that matches absolutely fine and not the exclamation mark.
721590	727770	Of course, then, like I mentioned before, with the character sets, you can add your capital letters in there as well, so now it's matching the A.
729590	743370	With the starts with as well, so again, we want to match the... so now we're trying to match like URLs on there, so this first regex example is only going to match HTTP and then slash slash.
743370	748710	You can see HTTPS or HTTPSS isn't matched in there.
749830	755610	So if we move into HTTPS, now HTTP isn't recognized, but we want to cover both of those.
755730	764870	So what we can have is a question mark after it, so that matches the S, and you can have either zero instances of that or just one instance of that.
764870	775050	So of course that's matched HTTP, and HTTPS has been correct, but of course HTTPS, which I don't know, maybe super secure HTTP, doesn't match because it doesn't exist.
777330	781870	And then the next thing we can have is the number of instances.
781970	793030	So in this simple match, we've gone back to our credit card example, which is going to be a recurring theme throughout this, and we've got like the digits zero to nine, and we've got exactly 16 of those.
793030	798270	So as long as there's just 16 within those, we've reintroduced the word boundaries as well.
798270	801550	So 16 digits, it'll be fine, it'll match.
802110	807730	But of course not all credit cards are exactly 16 numbers, you can have some which are a little bit more.
807790	816130	So then we've got this quantifier, which is a number and then a comma, so that means at least 16, and then you can have anything over that.
817310	829350	But then you've got a problem, because now you've got a false positive, where somebody's just sent somebody a message saying, hey, check out this binary string, and of course it's flagged it up thinking, hey, that's a credit card, because it's, you know,
829350	832910	it's numbers, and it's at least 16 characters long.
833710	844530	So then it introduces another quantifier for the range, so now you can say, okay, I want numbers, but only 16 to 19 digits in length, and that's it.
846010	849470	So you can see that's matched it absolutely fine in this instance.
850890	857090	Okay, so it gets a little bit more complicated now, because we've got to cover patterns which contain spaces as well.
857130	871810	So we can see we've got the word boundary again, and then we've got, like, it's going to match four characters on there, and then it's going to match where we've got, like, the space after those four character sets of zero to nine, we've got a space and a star.
872010	875870	Now, the star means zero instances or more.
875870	887410	So just in case somebody types something in, like the first four digits, and they might hit, like, space, space, space, or they might put tabs, some kind of, like, extra spacing, extra padding in there, that'll actually cover it.
887410	896090	As you can see, it's covered the first credit card number, which is just, you know, 16 digits, and then it's covered the next one as well, which has got the spaces in there.
898310	899670	Okay, shortcuts.
899670	904250	So this is where we can actually start compressing the regex to make it a little bit easier to read.
904310	911170	So instead of doing the character sets of zero to nine, we can use the slash d instead, which just basically says any digits.
911170	921450	So instead of us doing those four separate character sets for the first part of the credit card number, instead of doing the zero to nine, zero to nine, zero to nine, zero to nine, we could simply do that as a slash d.
921510	927510	And as we saw in the quantifiers as well, if we put four in there, that's duplicating that pattern four times.
927710	930370	And then again, we've got this space, which is optional.
933560	948260	As well, like I mentioned before, in case somebody puts more than one space in there, we've got the slash s, which basically says any kind of space in there, any tabs, and we have the star after it as well, so we can have multiple ones of that.
949700	951960	And then we've got the word character as well.
951960	959340	So when that's matching, it matches characters a to z in upper and lower case, zero to nine, and then the underscore as well.
959340	964520	I really wish they'd introduced the hyphen as well, just so it makes it easier matching things like domain names, things like that.
964780	966200	But not so.
966200	969240	So you can see it's matched like a username up there, absolutely fine.
969240	978480	So if you wanted to, if somebody's signing up to a website, and you want to make sure that there's no strange characters in there, because you only want to have those ones, then that'll work fine.
978480	985060	If somebody maybe put an email address in by accident instead of a username, you'll see that the at symbol hasn't been matched.
986420	990820	And again, you can go the opposite way by doing a capital letter as well.
990840	993820	So this searches for any non-digits in a string.
993820	1000720	So this might be some kind of validation on like a telephone number to make sure there's no like any other like strange characters in there, that shouldn't be.
1002000	1008700	And again, the capital S as well, that signifies anything that isn't a white space.
1008700	1020280	So in case for some stranger, I don't know if anyone's done it, but if you sign up for something and it says your password must be eight characters long, and you do eight spaces, which I don't know, maybe is a good password idea.
1020280	1023020	I don't think I've seen a bunch of spaces in a word list before.
1023440	1025320	And so that would match as false.
1025320	1028940	So just to signify that there's no like normal characters in there.
1031000	1035060	And again, the uppercase W is any non-word characters.
1035080	1041500	So again , you can check on the string to see if your string contains any non-word characters, you might want to check that out.
1042700	1043340	Okay.
1043340	1044760	And then you've got wildcards.
1044760	1047620	So these are where Regex can get dangerous.
1047940	1059020	So on here, it's just basically matching any characters whatsoever between the href in the link and then anything between the two double quotes.
1059320	1063100	So we'll go in a bit deeper why this is so dangerous.
1064680	1070540	So what if we just want to extract the link from that, because that's matching the whole href pattern.
1070980	1073080	So this introduced groups.
1073100	1082160	And with groups, you can use that to repeat patterns that you've done multiple times, or you can actually use it to extract the text that you want that you're searching for.
1082300	1087780	So in this example, again, it's just matching the whole href equals.
1087780	1096040	So when you do this in a programming language, whichever you're using, you'll probably like be returned an array or some kind of object which matches all your results.
1096040	1098480	So we can see you get this kind of result in here.
1098900	1101600	It contains a href, but we don't want that information.
1102500	1109720	Instead, if we wrap it in a group, for the wildcard and the star, you'll see that we've got an extra result in the array.
1109760	1119260	So the first one is what actually matched it, and the second one is the groups that are in your Regex for the information that you want to actually extract out of it.
1121780	1127000	So you can see with groups as well, you can make your Regexes even prettier.
1127000	1140520	So again, back down to the credit card example, instead of specifying like four groups of digits over and over again, you can wrap that matching the four digits or in a space inside a group.
1140520	1145500	And then you can put a quantifier after it, say you want to repeat that pattern three times.
1145500	1159440	So it's like four digits and any optional space with the slash S and the star, you repeat that three times, and then any like four digits on its own, and you can see that matches it, and it's a nice, much easier to read Regex.
1163450	1165550	So yeah, sorry, that's just the breakdown of it.
1165550	1169570	And like I explained, so you've got the group at the start and then the iterator of the three.
1172030	1175890	You can also inside groups introduce an or operator as well.
1175890	1183850	So you can say, so if the credit card has spaces, and then all the pipe symbol, you can have a hyphen as well.
1183850	1188190	So again, that will match the credit card numbers that are being entered with a hyphen in there.
1189730	1196970	So this is where it starts getting interesting, where Regex goes wrong, and where developers start implementing it.
1196970	1199650	So we're going to go through some vulnerabilities.
1199770	1210930	So the kind of real world examples, this could be like a black box exercise in kind of two ways, one where you're not given any source code, or this is Regex that's going on in the background.
1210990	1218250	Or white box might be where you do have source code, so you can go through and you can see the exact Regexes that are being used.
1218310	1223650	Or it might be a Regex that's being used on the front end of like a website, say in JavaScript.
1225130	1228790	So the first vulnerability we're going to go through is post message.
1230210	1240190	So if some people aren't familiar with post message, it's a way of two browser windows or tabs communicating with each other.
1240350	1249010	So say for things like, sometimes you'll open like a login prompt, so you do like log in with Google, it'll jump up with a little separate page.
1249010	1255910	Once you log into there, it can actually send a message back to your original page to say, this user's logged in, here's their information.
1256670	1259210	So we can see that with passing the data back.
1259290	1270050	So to make that secure, when you listen, so this is a little JavaScript example, so you use event listeners to listen for any messages coming back to your browser window.
1270670	1287050	And ideally, I mean, two things can happen, they don't check whatsoever where that information has been coming from, which is really dangerous, or they can implement a Regex on there to test for the browser for where that information's come from, and that comes in the origin,
1287050	1289290	in the event of the message.
1289330	1302910	So just in this simple example, we're checking to make sure that the window that was opened and passing the message back to the original website is supposed to be HTTPS www.trusted.com.
1302910	1310810	And then just for our example, so you kind of understand it as a vulnerability, it looks for inside the JSON object that's being passed.
1310810	1318830	If the event.datatype equals error, all it's going to do is fill in a div with the error message that's on there.
1319850	1324670	So this is kind of an example payload, which might be passed back to the original site.
1324670	1341070	So if you're familiar with cross-site scripting, all that's going to do is put an image tag on the website, it's going to try and load the source of X, which is going to fail, and then it's just going to pop an alert on there, because we've got the JavaScript in the onError event handler.
1341070	1348890	I mean, don't worry about that too much, but just take it as if somebody's got postMessage, and they're putting that information on the page, it can get dangerous.
1355800	1362020	So as we saw, this is the regex that's been used on here, which is just www.trusted.com.
1362620	1366440	So the first thing that we're missing is an anchor at the end.
1367000	1378480	So the problem with this is, if you've got the domain name attacker.com, you can just create these chains of subdomains, so you could have a website of www.trusted.com.attacker.com.
1378480	1387780	If you force your victim to go there, that'll pop open the original window of the main website you're trying to hack, and then you can actually communicate between those two.
1387780	1403140	So all you need to do is send a link to a user that opened up this attacker.com subdomain, and then instantly you'd be able to launch JavaScript on that original site, which of course you can then start stealing cookies, taking over accounts, things like that.
1403580	1407200	So that's the first thing that we need, a dollar sign on the end.
1407200	1413060	And again, going back to what we learned, that dollar sign says nothing can be after this.
1413060	1415420	It's just got to be that domain name, and that's it.
1415480	1416980	No other characters.
1417920	1420220	And then the next one is the wildcard.
1420220	1422980	This is probably the most common one that we see out there.
1423060	1427340	Developers always forget to put that backslash on there to mark it as being a period.
1427340	1438260	You could register the domain name www.xtrusted.com, and then that will pass the regex rules, and then you can move on from there.
1440660	1450080	This is the fix for it, so we can see that we've got the dollar sign at the end, and we've also done the backslashes on the periods as well to make this one now secure.
1451000	1453620	So open redirects is the next one.
1454080	1458680	So again, we've just got some simple code which is basically testing the URL.
1458680	1471800	So you might have a website, and there's a variable on there which you can pass in a URL, but you want to make sure that it's only domains that belong to trusted... sorry, you want to make sure it's only subdomains that belong to the trusted.com.
1472260	1475640	If it does, and that passes, it will redirect to that website.
1475640	1477180	Otherwise, it will fail.
1478140	1496320	So again, we've got the wildcard, which is going to be quite familiar on there, and because that requires a backslash on there, then again, we can have the www.xtrusted.com, and then you can redirect people to that website.
1496320	1504880	Again, that could potentially be used in like phishing engagements, so people look at the link on their email and think, oh yeah, that's a valid URL at the start.
1504880	1508100	I'll click on that, but then you could get redirected somewhere else.
1508100	1513420	It might trick you into putting account credentials in or downloading something like malware.
1515800	1519600	Also, the subdomain part of this as well.
1519660	1526200	So this wildcard on here is because they want to accept any subdomain of trusted.com.
1526200	1536780	Usually, you want to restrict this a little bit, because especially with very big scopes, and you've got like kind of like engineering side where they'll do a lot of testing.
1536980	1541740	There could be something like QAProd.1 or something, and you definitely don't want that being matched.
1542040	1547340	It might be just some really vulnerable old code that somebody's managed to find while they've been doing some reconnaissance.
1549060	1554380	Again, we've got the dollar sign at the end, so then you can add to it.
1554380	1557940	So you can have the www.trusted.com.evil.com.
1557940	1560860	So then you can use that to take over.
1562120	1575500	And of course, at the start symbol as well, the caret at the beginning, what you could do is actually pass in a domain name and then pass in the original one as a query string instead.
1575500	1582720	So again, without that caret symbol at the start, say this must start with a subdomain of trusted.com.
1582720	1586340	It'll still match that part at the end, and it'll get passed through.
1588700	1590720	So here's our fixed one.
1590940	1595960	So it's only accepting certain subdomains between A to Z, 0 to 9.
1595960	1597840	So this is just going to be like top level domains.
1597840	1601800	So you can have like www.oradmin, things like that.
1602220	1605460	Even better, let's actually put the domains that you're allowed on there.
1605460	1607980	So again, we've got the group with the or on there.
1607980	1612780	So it'll just accept admin, www, and download, and nothing else.
1614060	1618680	So this is one of Ben's examples where that actually happened.
1618680	1625360	So on the URL, you could put in the site name, the application name, and the path.
1625360	1635760	But because the path on there wasn't checking whether it began with a slash at the beginning, you could instead just change the path to .evil.com.
1635760	1642760	So it'd actually redirect to some application .redacted.com.evil.com, which would be your domain name.
1642760	1647940	And in this instance, Ben used this as an open redirect, which would actually grab somebody's auth token.
1647940	1650720	So it just wasn't a kind of a simple open redirect.
1650720	1655480	It was actually an account takeover where you could steal somebody's cookie after logging in.
1656700	1659380	And that got $14,000, I believe, Ben.
1662530	1664270	Okay, calls.
1664270	1685110	So when you're on a website and you're making an AJAX request to a different domain name or a different subdomain to what you're on, or even a different scheme, you have what's called a pre-flight check, where it sends an options header to the server that you're going to communicate with and say,
1685110	1686750	hey, I'm coming from this website.
1686750	1689050	Am I actually okay to send this information?
1689470	1691850	Especially with things like credentials as well.
1691850	1697710	So you might have like a second website where, say, if it's like an API.
1697710	1703130	So you have like, well, in this example, we have like a slash API slash me.
1703130	1710950	So if you visited that normally, it would use your cookies, and then it would show you the information in API slash me.
1710950	1716890	So that would be really dangerous if any website could make a call to that and then grab that information.
1716930	1720070	So this is why we have calls and those pre-flight checks.
1720150	1724970	It will pass the origin, which is the website that you're currently on.
1724970	1739110	And if that matches the rule on there to whether it is an allowed website, you'll get a response in there saying the action control allow origin header will be returned, and that has to match your address.
1739110	1742270	So the scheme and the domain in your address bar.
1742410	1748370	Also, if you can send cookies along with that request, you'll get the access control allow credentials.
1748590	1761670	Interestingly, most browsers have actually removed this, because a lot of the time, passing cookies back and forth towards third party domains, it's mainly used for analytics so that people can track you all over the web.
1761670	1766570	Every browser has removed this, apart from Google, surprise, surprise, with Chrome.
1766650	1768370	They keep on promising to do it.
1768370	1770810	They also keep on extending that data as well.
1772010	1776950	So where the issue is, so we've got the calls code on the server side.
1776950	1783670	Again, it's using a regex to check whether this domain is actually allowed to communicate with it.
1783670	1787610	If it passes that check, it will then set those headers.
1788890	1799790	So again, we've got the wildcard character, which we explained, so we can just, you know, purchase a completely different domain with an X in there, and we can bypass that regex check, and then we can start stealing information.
1800350	1809490	Again, the subdomain, so we can add in a completely random domain that possibly we've taken over, something which is a little bit easier to hack into.
1810690	1813350	Again, no dollar sign on the end as well.
1813490	1817510	So we can add our evil.com domain on there, and we can steal the information.
1818310	1833550	So this is the fixed one on there, so we only cover subdomains, like top level ones, A to Z, zero to nine, and an underscore, and then we've got the backslashes in there for the wildcards with the trusted.com, so this has made this now secure.
1835590	1840070	SSRF, so I'm not going to go through every vulnerability, don't worry, because they're all pretty similar.
1840830	1857210	Say if you had a website and it was going to make a PDF of your LinkedIn user page, so it's expecting for you to give a LinkedIn domain, it'll grab that, it'll convert it to a PDF, and it'll send it to you.
1857210	1866810	You don't want this accepting any domain name, because you could potentially access things that are on local host or metadata if you're hosting on the cloud.
1868550	1887030	So again, we've got the full stop on there, which is the wildcard, and we could create a domain, the www.xlinkedin.com, we could register that or any character, set the ADNS record to local host, and instead it'll communicate with the local host instead.
1888730	1903530	And there's no slash at the end of the domain that's been put on there as well, so we could make that a subdomain of a domain that we already have control over, and again, we can control the DNS and where that goes to.
1904490	1910190	And the no caret symbol at the start say the string must start with this.
1910190	1923730	So if we pass in a whole URL, again, we could be hosting something which either redirects to somewhere completely different, or again, we can set that DNS record, and we can get it to create a PDF of any page we want.
1925490	1936230	Also as well, don't just trust the start of it, maybe after the slash at the end, let's get the exact path in there, because what happens if we find an open redirect on LinkedIn?
1936470	1949930	So it's passing all the regex, it hits the slash redirect, which is hosted on LinkedIn, goes back to your evil.com domain, which has a DNS record of 127.0.1, which will then start querying local services.
1949930	1952910	Obviously, we could change that address to different things as well.
1955670	1957690	So this is the fixed version.
1958010	1971350	So with what we've learned is we've got the... it has to start with HTTPS, LinkedIn.com, and then slash in, slash then the word symbol, which will only accept characters A to Z, zero to nine, and underscores.
1971350	1974590	So that should be safe after that with my example at the bottom.
1978660	1979260	Okay.
1979260	1980800	So I think now Ben's up.
1980800	1985420	So he's going to go through some vulnerabilities that he's found where regex has been involved.
1985420	1987800	He's going to chat about that and some refund stuff.
1988760	1989820	All right.
1993780	2000160	So I did a similar talk to this one somewhere else, and I talked about some vulnerabilities I got in trouble for.
2000340	2004720	So I couldn't put the screenshots of the vulnerabilities on this slides.
2004780	2010740	So instead, I'm going to just show you similar findings on GitHub that scored me the same bounties.
2010740	2013640	I just couldn't put the specific bugs up here.
2013640	2019340	But when it comes down to SSRF, the majority of the goal is internals, right?
2019340	2024760	Get into the internal network or get some AWS keys or something fun, right?
2024760	2031860	So we'll come back to this, but there is something beautiful about using regex on GitHub.
2032140	2033500	And I use this a lot.
2033500	2041800	I've gone away from using the traditional sub finder, amass, domain finder, whatever you want to name it.
2041800	2051720	I've kind of stepped away from those because one, everybody else is using them on public programs and B, I wanted something new and I really wanted to drive this home for this DEF CON talk.
2051720	2056460	So you can do a couple of things with regex on GitHub.
2056460	2059080	You can actually use regex to look for subdomains.
2059120	2067680	So let's say you have a environment on cert.sh that comes back and it says, yeah, I have a wildcard certificate here.
2067680	2070640	It's something.corp.site.com.
2070700	2073760	And you can't see what's behind corp because it's a wildcard.
2073760	2075280	You have to brute force for it.
2075380	2077280	This is a really good way to find it.
2077280	2081840	Again, the regex that you see on this screen is one of many things you can try.
2082020	2085400	It's something that we've came up with, so it simplifies what we're doing.
2085900	2092340	And you can take that even a step further and just look for subdomains that contain specific keywords.
2092560	2095600	So if you want to find APIs, you can put an API in there.
2095660	2098380	If you want to look for dev sites, you can put dev in there.
2098380	2102140	And the cool thing about doing that is it also gives you context.
2102140	2105040	It gives you context of what people are doing on these APIs.
2105280	2108080	Are these internal APIs that they have leaked data on?
2108080	2110960	Have they given you their paths and things like that?
2110960	2122080	So one of the really cool bugs that I found using this method was on one of the bug bounty platforms, we were hacking on a redacted program and this guy came to me on Discord.
2122080	2128020	He's like, hey, I have a SSRF, but I know it's hitting something internal, but I just can't prove it.
2128020	2134940	And it's not on AWS, it's not on GCP, so we don't have any access to anything that we can prove.
2134940	2137760	And I just think there's something on the internal that we can find.
2137880	2145120	So we went through this example and instead of putting API, we were looking for a specific keyword.site.com.
2145440	2149420	And we ended up making a quick list of everything that was on GitHub.
2149420	2152780	And one of those was their source code.
2153180	2158820	There's a frog or whatever it's called, JFrog, that was on auth and you can just pull source code from it.
2159000	2169080	And none of the databases that we went through for asset discovery, your sub finder, your cert.sh, your c99.nl, all of those didn't have data on this specific thing.
2169080	2176920	But some developer unfortunately had leaked their automation on GitHub and had the instance for us that we could pull for.
2176920	2178720	So we had access to all their source code.
2178720	2179380	We reported it.
2179380	2185060	And I think that one was a $5,000 or $6,000 bounty on a public bug bounty program.
2185180	2193800	So this is a really, really good way to find assets that you can narrow your focus on what you want to hack on.
2193800	2195000	I'm just going to make sure I have my notes.
2195000	2197980	I don't miss anything since I don't have... I couldn't put slides.
2197980	2198760	There we go.
2199720	2201500	So that's one of the things that I want to do.
2201500	2208180	This is the starting point for me when it comes down to looking for assets that I want to hack on.
2208180	2214600	So with bug bounties, one of the number one questions I get is like, where do I pick the targets out of these thousand subdomains that I found?
2214820	2216640	This could be a really good way.
2217080	2221140	So you also have the content discovery part of this.
2221280	2233200	You can find a lot of cool content that you probably can't brute force for if you were to find a random API that doesn't have any swagger or open API JSON on there.
2233200	2239360	So again, very random, but also high level regex for it.
2239360	2240740	We're using Netflix for this.
2240740	2249300	We're saying anything that has Netflix, it could be netflix.com, netflix.io, netflix.net, because those are also tier two assets on Netflix's bug bounty program.
2249300	2253300	And then we're hitting it with, I want it to have slash API in there.
2253300	2268960	This alone on a, this is not on Netflix's bug bounty program on a private , no public program on HackerOne that's been around maybe for, I want to say over six years , have a massive scope to have massive presence online.
2269340	2272540	And two cool things came out of this two types of vulnerabilities.
2272540	2283420	The first one was, I just wanted to find APIs to hack on because everything for these websites that I would go to, you needed an account.
2283560	2288660	So they have a domain in, let's say Netherlands.
2288920	2290660	It's a .nl domain.
2290740	2294020	You need to be a Dutch citizen to be able to get an account.
2294020	2296660	You need to have an ID to get logged in.
2296660	2299160	And then you can see their API routes to interact with it.
2299380	2301580	Obviously not Dutch, don't have an ID.
2301620	2302940	This was a great way to do it.
2302940	2309860	So actually I found an asset on there that not only did it give me the API routes, it also gave me how the usernames were being created.
2309860	2315440	So it was like a first name, initial, last name, and the year of their birth.
2315960	2325560	And it's, you know, it's in, if it's a Dutch that you go to chat GPT and say, Hey, give me a top 10, most common Dutch last names, add an A through Z in the beginning.
2325940	2330060	And then numbers that you think are birth years where, you know, people that I can use.
2330060	2332280	So that's one, it was a $5,000 bounty.
2332940	2337800	And then you can also do things like, Hey, maybe it doesn't have API in it.
2337800	2344760	It could be something like app dash API, but then, you know, app name, the app name could be anything arbitrary, right?
2344760	2349220	It could be a printer API dash whatever.
2349220	2352740	And then there's a V1 in there and you do that and it gives you a lot of good results.
2352740	2361260	And all this, honestly, all these APIs are also cool to look at, but for that one specifically, it wasn't anything with the API itself that was vulnerable.
2361280	2366340	It turns out that had some very obscure path for all of their applications.
2366760	2368460	It was about five dashes.
2368460	2376140	And so five different words, it was like a region, app name, environment, and then a country at the end.
2376140	2377880	So it was really hard to brute force.
2377880	2383720	But once I found every single one of those on GitHub, every single one of those endpoints had an actuator with a heap dump.
2383960	2389580	So if you're not familiar with actuator heap dumps, it's just for Java backend, you can use something like a spring boot.
2389580	2391660	It gives you access to the environment variables.
2391660	2392980	You can pull credentials.
2393060	2397560	The heap dump is just a snapshot of the memory that has all the HTTP requests.
2397560	2400260	And I will show some of those in here.
2400360	2414340	And I want to say I found four of those at $3,000 a pop within just a couple of hours of just realizing like, hey, I can just go on GitHub and somebody else had leaked these paths for me to be able to look for it.
2414340	2423820	So keep this in mind when you're looking at a random asset you found, you're banging your head against the wall going, what is on this API?
2423820	2425600	What are the routes on this API?
2425640	2430900	Somebody, I promise you has leaked it on GitHub, but you just got to be able to find it with a good regex.
2430900	2435420	So those are a couple of bugs that I can talk about throughout all this.
2435720	2437560	You can also use it for things like GraphQL.
2437560	2439400	I just want to give you examples of things that you can look.
2439400	2440560	It's not just always API.
2440560	2441720	It's not always GraphQL.
2441720	2453680	You could also just literally be knowing that this company has this stack that they use, technology stack or this component that they use across their environments and you want to find it.
2453680	2466160	So you can just purely do for this one, we're doing every domain obviously that's on GitHub, but you can just narrow it down to something like a netflix.com or fort.com and then looking for every GraphQL instance in there.
2467700	2470900	We can also use this for parsing data dumps.
2470900	2472580	Do you want to take this one or maybe you could keep going?
2473240	2477460	I'll take this one just because of the fact that it's, I talked about actuators and I kind of want to show what it looks like.
2477600	2486520	So this is obviously a fake version of actuator that we have as a lab, but most of the time if you do, if you find actuator, this will be something that it would look like.
2486520	2487960	If you're lucky, this is what it looks like.
2487960	2492400	If you're unlucky, then it just shows you health, info and metrics.
2492420	2495380	If you don't see those three, I'll give you a hug.
2495380	2496180	It sucks.
2496180	2501540	It's not fun to see those, but when you do come across an actuator, you can download the actuator heap dump.
2501960	2505860	It looks a little ugly like this if you open it because it's not human readable.
2505900	2517700	You can pass it to strings, for example, and you can grip for some data, but keep in mind when you're gripping for, I don't know, password, you're going to get a ton of other variables that have the word password in it or username in it or whatever it is.
2518080	2529860	But we can use something like this to just pull everything that has, that ends with an equal sign, which is a parameter or even better, it could be a base 64 of a password that ends into two equal signs.
2530040	2536160	And it could be a password for something or it could be something that we can use and leverage it.
2536160	2541140	You can look for things like, I think Adam's going to cover these, but you can look for JWT tokens.
2541140	2542720	They start in a very specific way.
2542720	2544260	You can look for AWS keys.
2544260	2546440	They look a very specific way that we'll cover.
2546740	2568600	But this has been something that I have had to shift to because I realized after creating this course with Adam, I went through all the heap dumps that I've had on my laptop and I realized how much data I had missed by just doing a strings file and then piping into GRIP without regex because there's so much data that I couldn't go through.
2568700	2576180	So I'll let Adam cover some of the other safe secrets and then we'll wrap it up with some code review and maybe take some questions at the end.
2584710	2588810	Okay, so very quickly, again, using GitHub, we can look for things.
2588810	2606050	So all JWT tokens quite nicely start with EYJ, which is the opening bracket on there, followed by characters A to Z, zero to nine, underscores and hyphens, and then with a dot in the middle.
2606050	2614070	So if you search for this on GitHub, don't know who these poor people are, sorry, you'll find a bunch of JWT tokens which have been put on there.
2614630	2618650	Again, things like AWS keys as well, that can be put on there as well.
2618650	2622290	You can also combine that with like Netflix domains as well.
2622510	2630250	I've found this random thing, I don't know what it is, there's some research.netflix and there's a JWT token in there as well.
2633910	2640190	All right, sorry, yeah, if you put when you're searching on GitHub, where the and is, you have to put that as capital, sorry.
2641870	2644650	Regex as well can be really useful for code review.
2644690	2649730	So whatever your stack is that you're used to, I'm used to PHP, so I'm just going to use this as an example.
2649790	2660950	So if you're searching for anything that might reflect XSS in your code, so it'll be echo and then you're just echoing out straight away any get or post requests with no validation on there whatsoever.
2660950	2665310	That's a good indication that you're going to get an XSS on your website.
2665310	2677190	So it's just looking for any instances where it's echoing out and then using Regex, we've managed to put the group and the author operator on there and to look for anything that's get post and then starts with the open bracket.
2679130	2682370	So here's some code example that might come up on there.
2683450	2689530	Anything that's potentially using the system command as well, that could be receiving some information.
2689530	2702550	So any websites that are using system to actually process some code on there, you're going to want to make sure that you have a look at that, make sure it's not taking any variables that you could potentially then get RCA on the website.
2703410	2707590	And you can also use a Regex to look for Regexes as well.
2707590	2711950	So this checks for Regex code for PHP, JavaScript and Python.
2711950	2716310	You have different packages on there which you put regular expressions into.
2716350	2720410	Again, this will flag them all up in your code and then you can review them manually.
2722190	2726030	Again, you can search for things like basic auth, that's in your code as well.
2726030	2729830	So that's going to match any of the base 64 strings and then ends in an equals.
2730130	2732510	Again, finding JWT tokens.
2732510	2734530	Sorry if this is really fast, but we're running out of time.
2735230	2740350	You can also do these things on not your own code, but you could also do it on GitHub as well.
2740350	2743950	Again, looking for any XSS which might be in PHP.
2746110	2748950	And then you can use the and command as well with WordPress.
2748950	2755870	So if you're targeting particularly like WordPress plugins through like a bounty program like WordFence, you can do that.
2756370	2762810	And also look for things that system commands that like either get or post has been passed into as well.
2762810	2765850	So there's like user input, which is going into a system call.
2766850	2770870	So like on this one that I searched for, which you can get some interesting results.
2770870	2773910	This was just basically somebody's web shell that they've hosted on there.
2773910	2777150	So we've got some hackers posting some stuff on there as well.
2778950	2785450	One of the cool things I've really found about it is now and again, I find like building tools for the community really interesting.
2785570	2791790	So one of the first ones that created was creatures of habit, which wouldn't be possible without regexes on there.
2791790	2796670	So all this does is it goes, I increment through every package on GitHub.
2796670	2800690	It grabs certain web extensions on there.
2800690	2804970	And then it goes through every different framework that's out there.
2804970	2808430	Like we've got like Python, like Flask on there.
2808430	2809890	So it looks for any routes.
2809890	2815730	So we can start making loads of routes and then we can use those for word lists for finding other things on other domains.
2816250	2818450	And PHP with Laravel has gone there.
2818450	2826350	JavaScript, Python, ASP.NET, Ruby on Rails, and Go as well on there.
2826350	2835510	Another one I wanted to create word lists as well for when I'm hacking into websites, where I want to create a unique list of parameters as well.
2835510	2846170	So it's great to go to GitHub, find all the parameters that developers are actually using, either in query strings or the post body or HTTP headers and methods.
2846230	2864930	And again, I could cycle through pretty much most of GitHub, look for PHP pages and look for any get or post things in the code and then I'd extract the actual string in the middle and then I'd put those into a word file and then I can use that later on for reconnaissance.
2864930	2874450	With parameters I've done that, with HTTP headers and with get methods as well, because they tend to get reused in web paths.
2875430	2876690	So that's been pretty interesting.
2876690	2881590	I've managed to make some really interesting word lists and found some very interesting things from that.
2882770	2884530	I think we are finally done.
2884570	2886110	Sorry if we've melted your brain.
2886110	2887410	It's been a lot of information.
2887410	2893250	Don't worry if you didn't grab it all, but hopefully it's kind of prompted you enough to go, yes, I will learn Regex.
2893350	2901490	One more note, because for the GitHub stuff, for the code review, the reason why we have it in there, a lot of companies open source a lot of their frameworks.
2901490	2902630	So keep that in mind.
2902630	2904510	You can go and find vulnerabilities in those.
2904510	2905470	That's why we have them on there.
2905470	2907610	We just can't show you exact examples of it.
2907610	2915770	But a lot of the large organization, especially if they've been around for years, all of their frameworks that they use internally for their basic applications, that code is online.
2915770	2916790	You can look at it.
2916830	2918950	Enterprise tools, you can launch them on your own.
2919190	2922750	Go through the EC2 instance, get the code and dump it and look for vulnerabilities.
2922810	2923930	Keep that in mind.
2923930	2924930	That's why we have it in there.
2924930	2925570	It's not a teaser.
2925570	2927310	It's just get creative.
2927310	2929430	Look at these things and go, what else can I do with it?
2929430	2931830	How can I chain all these and apply them in a real world?
2932450	2935430	With that said, I think we have only two minutes before we get kicked out of the room.
2935430	2937230	If there are any questions, we would love to answer them.
2937250	2939170	If not, hang out here and answer any questions.
2939170	2939570	Okay?
2957520	2961300	You can use tools to unpack that actuator dump.
2961300	2962180	Is that what you're talking about?
2962180	2963280	You can use tools.
2963280	2966520	I personally don't use them with bug bounty programs because they usually don't care.
2966940	2970020	I literally just run them through GRIP with regex.
2970020	2971800	Look for things that I think is valuable.
2971800	2973380	Look for cookie values, for example.
2973380	2976360	Look for JWT tokens.
2976360	2978460	Look for bearer tokens and things like that.
2978460	2987500	When you see that access, you'll see the whole HTTP request on there so you can see where they're actually using that token and where sending it to or receiving it from as well.
2990020	2993940	They'll be on the website with the actual workshop soon.
2994280	2995660	This is a part of a bigger workshop.
2995660	2996780	It's just what we could...
2999240	3000300	It will be an additional one.
3000300	3001220	I'll send it to you.
