So hey guys, thanks for joining us. I just wanted to kind of give you a little background inspiration in my talk Before I begin so last year they had a really good presentation hunting for big game big game hunting for APT at black hat and DEF CON and One of their particular slides they kind of you'll see it in my presentation They had a bunch of listings on what do you look for with APT? and I was like oh wait that whole listing you can do with Yara literally minus like three things and so my original title for this presentation was hunt like a dentist in Zimbabwe so Yeah, yeah, hey you think too soon some people think too late. I don't know yeah So uh so a big game hunting like a dentist get it and I had a picture of Cecil Lyon But we didn't want to offend anybody so good thing. We're not on camera right now So I didn't Want to get like death threats from PETA or anything so so me and Ming kind of discussed it We changed it and all that luckily I had this alternate title because I gave this talk It's a sans threat hunting instant response conference about three months ago So it was easy and quick and easy, so I'll let that get back to me Okay, in fact. It's actually good timing because uh you know we were thinking actually now it is 1010 so You know it's now my pleasure to introduce J.D. Martino from fidelis you from fidelis, right? Yeah from fidelis I Actually don't remember any of this stuff So as you can you probably have told you probably have you probably have seen so far that With the exception like sponsors and the schedule like everything else. I have to just you know I just think of it on the fly, but He does just one thing I can tell you about Jay is he likes to be man you like to be mysterious So without much ado to talk about how to catch a predator I mean how to catch a yeti how to catch a or how to catch an apt J.D. Martino Thank you, thank you, thank you Thank you guys ah So yeah, my name is J.D. Martino. I'm a senior cyber threat researcher at fidelis cyber security Today we're gonna talk to you to catch an apt We're using Yara. That's the title of my talk. Yeah. Oh, closer? Okay. Is that better? Yeah. Thank you. Oh, sorry. To catch an APT. Yara. Sorry. Let me give you a little rundown, what to expect. We're going to define the threat intel problem as we see it. We're going to go over a brief summary of some reverse engineering tools. I talked to you a little bit about Yara, how to use it, and then we're going to dive into some malware. We're actually going to look at some PlugX malware that was running rampant back in 2015 that I had the opportunity to look at for my company. We're going to write some rules today, some Yara rules. For those of you who have never written a Yara rule, we will write a rule for the very first time. I will help you. We'll write some string rules, and we'll go through tuning string rules. We'll also write a byte sequence rule. We're going to go from easy to medium to hard in the span of about 50 minutes during this talk. I have these little indicators there, easy, medium, and hard. If it's beyond your scope and you see the hard, and if you want to go to sleep, you're more than welcome. But wake up towards the end, I have some results of after maybe about a year or so of tracking this PlugX malware. It's just some things that kind of bubbled up, some themes that I'd like to share with you guys to help you, like I said, bring it home and help you to catch APT. Not any one particular actor, but just some things that you can maybe tie to a particular campaign or find the campaign and whatnot. The threat and intelligence problem as it stands, as incident responders or malware analysts and whatnot, we encounter, or even network defenders, we encounter suspect files. Right? All the time. Really, to be honest, we encounter a lot of suspect files, varying different degrees of file types, different content, different program software, and whatnot. How do we filter through all that white noise with all these different files, right? The next thing about the threat intelligence problem is that the threat landscape is always changing. If you look, these are two ways of looking at it. Two blog posts from 2015, one dated April 24th, about a merger between Raytheon and WebSense. Raytheon acquired WebSense, and then that acquisition went public, and then an APT group started targeting WebSense and Raytheon employees about the acquisition using some malware called PlugX. Then, a week later, May 1st, 2015, you see another APT, Palo Alto, their blog saying that PlugX is a threat. PlugX was using legitimate Samsung software, signed Samsung software, to install PlugX as well. In the first case, the WebSense spear phishing attempt, they were using a signed binary as well. They were using Kaspersky antivirus signed binary. In the second case, one week later, they were using Samsung. The threat intel problem is that it's constantly changing, and how do we keep up with that? Next, I'm going to talk to you about reverse engineering and malicious code analysis. It's like peeling back layers of the onion. Sometimes you do want to cry because it becomes very difficult to reverse some of this malware that's been obfuscated and whatnot. I take it to that approach and just do one layer at a time. I wish I had a knife to just cut through it. You get a kid with a volatility, go right to the memory and you run it, but sometimes you get anti-sandboxing and different things, so you don't have that knife. Just a quick note. Just take it one layer at a time is the best way to do it and move forward. Definitely one of the easiest tools for reverse engineering is strings. It runs through all the readable text in a binary that people can actually read. If you're not a reverse engineer, you can just download strings, run strings against a file, and you can become a reverse engineer because we use it all the time. They can be hidden. Next is a hex editor. You're looking at the raw bytes that the computer is going to execute. The hexadecimal characters, not characters, but bytes, yeah, sorry. It's good to just look at things in a hex editor to find patterns, to find nested structures, or you're going to enumerate those structures and different things. We're actually going to take a look into a hex editor today, so if you've never done it, stick around. I'll show you how they're very useful in reverse engineering. Then a disassembler or a debugger. I use IDA. Man, I love IDA. Don't you guys? For those who else, who do you use it? It's just a great tool, the developers, and it gives you the instructions. Like I said, the bytes are what the machine chews on and eats to execute the program, and then the disassembler will give you readable assembly language so humans can read and find out what the program is about to execute. I'd say the fourth tool, and the very best tool. The first tool in a reverse engineer's handbook or pocket is Yara. I definitely have to give a shout out to the creator of Yara, Victor. He has created such a wonderful tool, Wes, and all the other developers. They're great in supporting it. Yara is a tool aimed, but not limited to, helping malware reversers to identify and classify malware samples. Then with Yara, you can create descriptions of malware families. Or, if you have a bunch of malware, you can create descriptions of malware families or really whatever you want, based on textual or binary patterns that you see in the files or any kind of data stream. Real quick, why Yara and not IOCs? Look at them, indicators of compromise, IP addresses, MD5s, file locations, URLs domains. They can be changed. You just can't do hunting with IOCs. They can easily be changed. Next, what does Yara do? It scans, at its core, it scans streams. It scans file streams, network streams, memory streams, any stream of data, any string of bytes or strings. You can use it to scan. That's what it does at its core. It scans data streams. What are some tools that incorporate Yara? Obviously, Yara. I'm going to give a plug to my company, Fidelis. I love my company, but they've really embraced the Yara tool. They use it in three of their different products. We have two pay products, the Fidelis Network product that scans network streams, and then also our Fidelis Endpoint product that scans files and even memory using volatility Yara, fall Yara. Between the two of those, they hit all the different streams. Also, we have a free tool called Threat Scanner, and it does open IOC and Yara scanning as well, too. There are also some other tools, Cuckoo Sandbox, I'm sure a lot of people in the audience have probably used, VirusTotal Intelligence, if you play with VirusTotal, throw your rules up and get viruses back that people submit, and Volatility, the memory forensics tool. All those have really embraced Yara as well. Enough talk about Yara. Let's talk about who uses it and what does it look like. It's really simple. It's a command line tool. The input is basically Yara, a couple of options, and then you could either choose the stream that you want it to run against, or you give the rules file, sorry, you have to define the rules file, and then a stream that you want to run against. That stream could either be a file, it could be a directory, you could even tell it to do a recursive directory scan, you can do it with a process ID, and then if you want to do, you can run it against a PCAP for network traffic, but basically you would kind of want to sessionize that data and run it against a TCP session, and then you can run Yara against it. The output's really simple. You supplied the rules file, where you've defined all your rules, and it tells you which rule has fired on which data stream, or which file, or which data stream. Which directory, or file in the directory, and so forth, or process ID. You can kind of see here, some of them, unknown, plug X, Trojan loader, payload names. We're going to actually go through these three right here. We're going to actually write these three. We're not going to cover this one, the XV header. It's a little crazy, but we're going to go through them. We're going to write these three rules today. You can see that based on this hash, this file, these three rules hit on. Then these three files right here, so I just kind of blanked out the source directory. The extracted file, msi.dll, and then the main one, x2015.exe, so that was the plug X, right? Let's write our first Yara rule. Really, really easy, just to begin. You do it in text editor. You write the rule tag, so just rule, space, and then the rule name, and then just as if you were defining a function. An open and closed bracket you would add as well. Now we're going to get to the detection logic of the rule. First we're going to start off with the condition. I'm kind of going to build from the bottom up, just because it makes a little bit more sense for you to understand it. The condition is a Boolean condition logic for the detection. You're going to see there in this one we have it returns true if we have a hit on my text string, or my hex string, or my regex. Then next, moving up, we're going to go to the string section, and we're going to actually define my text string, my hex string, and my regex. In this case, my text string is ASCII text, and the hex string is a hexadecimal byte sequence, and then my regex is a regular expression. I think it uses like PCRE or something like that. I'm going to go ahead and do that. Then this one's an important kind of thing. First I would say that the conditional section always needs to be present for a rule. You cannot write a rule without a conditional. You can write a really simple conditional if you want, but you have to have a conditional. The string section, like I said, is the actual detection. You actually can write a rule without using strings, and just based on a condition. You can write a rule without using strings, and just based on a condition. But for the most part, 95 to 99 percent of your rules are going to have a string section written in them. Then when you share rules, the good thing about Yara is that if you want to, you can share your detections. When you share things, it's definitely good to fill out the meta section when sharing rules. It just helps to reduce analysis time. Say a friend of yours gave you a rule. You have no idea what he wrote this rule against. You may not have the malware. But he used to write the rule. In the meta section, you would put particularly what Intel document was the source, if somebody else wrote it, or perhaps the MD5 for the source binary that you wrote it against. Even the description of the rule would definitely be helpful in the meta section as well. When sharing your rules. You don't only use the meta section. We talked about the actual syntax of it. What can you actually signature in the malware? You can either go with pretty much text strings or byte sequences. The byte sequence or regular expressions. On the left, you'll see the text strings. You see a short list of what you can actually signature. On the right-hand side. On the black line. On the white line, though, you'll see implementation traits and custom features. Those are things that you can actually use your byte sequence rules or your regular expressions to signature against. If you look on the right, that's a much bigger listing to catch than on the left with strings. If you're using text strings, you're shooting yourself in the foot. You're missing a lot of opportunities for detection. Then, also, with the byte sequences, you really want to get the unique characteristics of the malware and so forth. That's the next thing I want to talk about. Basically with string rules, they can easily be erased. Strings can easily be patched or modified or erased within a binary, but with byte sequence rules, you really can help. It helps. It can help you find the broader campaign. It helps you get the DNA or the family tree of the malware. Therefore, I just think byte sequence rules are ultimately better, but definitely the string-based rules definitely have their place. How do you use Yara effectively in your organization or the tool in general, even for amongst yourselves? One of the big things that I always stress is rules. Rules. Rules. Rules. You can never have enough rules. Always try to write more than one rule per sample you look at. At least one strings-based rule and one bytes rule. Have descriptive names. Have descriptive names on your rules. If you write it and a year later it fires, it finally fires, you can look back and, oh, that was the investigation that I did and, oh, we're seeing that guy again or that malware again or that file type again. This is coming back. This is coming up again. Have descriptive names in your rule names. When you're writing your rules and testing, you want to have at least three data sources. The first data source, obviously, is the malware you're trying to signature. You can't write a signature without a binary. I've definitely seen instances where people will say, oh, can you write detections for this? It's like, well, I can't write it until you give me the files. I need the files. As a reverse engineer, I need those binaries. The second thing is a known data source. It can be known good. It can be known bad. It just has to be known, or it could be a mixture of both, known good and known bad. It has to be known to you as the analyst because you're going to use that known data source to test your false positives because you know, okay, this rule is hitting on this file. It shouldn't be hitting that way. It shouldn't be hitting that way because you know that data source. The third data source is your new intelligence streams, so any new intelligence that's coming into your networks or any new intelligence from VirusTotal Intelligence or Virusshare.org, any one where you can download malware from or something like that when doing your research. Last but not least, I stressed this earlier, share with the meta section. If you're going to share your rules amongst with others, share with meta. Yeah. All right. I explained that one. So next, let's get into, let's talk about PlugX, right? PlugX is, it's some APT malware. It's existed in some form since 2008, and it's evolved over time to offer new capabilities and control mechanisms. It's supported by an active development program. It's used by multiple APT actors suspected to be China or probably, let's just say it's China. And it provides an attacker with a range. It provides a range of functionality, including the ability to log keystrokes, modify and copy files, capture screenshots of video and user activity, and perform administrative tasks such as terminating processes, logging of users and rebooting victim machines, right? So PlugX, what did PlugX look like in 2015, right? The outer layer, like I said, when doing malware analysis, it's layers of an onion, right? So the outer layer of PlugX, to me, and when I saw it was in 2015, was a self-extracting RAR archive. These are benign. They're commonly used for your program installers. So how do you go about and signature that? It looks like an installer that's coming into your network, and it's a RAR archive. Everybody's used ZIP and RAR, 7-ZIP, these compression formats. Well, these are self-extracting archives. So they're actually executable by nature. Right? But they're not malicious, really, per se. They are, and they're executable, but it's the contents that really make up what the maliciousness is. Because, like I said, you see them in all your software installers and whatnot. So let's get into the contents of PlugX in these self-extracting RARs. They would also throw in a digitally signed executable, you know? And so, I mean, digitally signed executables, they're reputation-based. They're signed. They throw that. We saw that in the threat intel problem that we saw them abusing Samsung app, signed Samsung applications, and then the signed Kaspersky applications in the WebSense attack, our campaign, email campaign. Next, there was a small DLL loader. It used a side-loading technique. I'll get into it in just a brief, kind of explain that a little later. But it's a small DLL that would then load the compressed PlugX payload. The compressed payload was actually where the malware was. The compression or the assembly was always randomized. It was obfuscated. It was different. So how do you take something that's relatively not or hard to signature, relatively not signatureable, and let's signature that? So I'm going to show you. So we'll start with the first layer. Let's just signature, and I'm going to give you this one. I ran strings across the self-extracting RAR. And I came up with these. These look like really good strings. So I'm going to give you this rule right off the bat, and then we're going to get into the juicier stuff. But it's good to signature this because, as an analyst, all I have to do, the self-extracting archive has a .exe extension. All I have to do is right-click, rename that file in Windows to .rar, and then I can use the WinRAR program or any kind of RAR extraction program to then extract the content. Easy win. I've just eliminated one layer of the section, one layer down. And so those are like shooting fish in a barrel. It's great. Just write this rule to help augment your analysis. Pick this out in your data set, and you'll be like, okay, I have a really easy place to start with to finding out information. Next, let's look at the next file. Let's signature that signed executable. You're going to be like, Jay, you're crazy. Why would you want to do that? Really. Why would you want to signature a signed executable? They're reputation-based. They're supposed to be good, right? I'm supposed to trust them. Am I right? Do you trust signed executables? No. Well, you're right. You're right. So in this case, I am crazy if I want to sign it. But we have already known that we saw that the landscape changes very quickly. So within one week, we had assigned Kaspersky binary and assigned Samsung binary from legitimate applications. So we're going to have to track signed executables within your own organization with a private certificate. That's one thing. That's definitely a reason you would want to sign a signed – to signature a signed executable. Also, if the binary has been signed with a stolen certificate, you definitely want to signature that as well. But in this case, why would we want to signature Kaspersky or Samsung software? So I'm crazy in this point. You're right. You're right. It's like playing whack-a-mole, right? Especially with the binary. Especially with the intelligence that we have, it's changed within a week. So for – up next, I'm going to take a little detour for a second and get off of PlugX and just kind of teach you some things about some string rules, right? When writing your string rules, you love Unicode. Can everybody say it with me? I love Unicode. I love Unicode. Boom. Boom. Okay. You all love Unicode. Why? Look at this chart. Look at the chart. This is ASCII on the left, 8 bits, right? Unicode on the right, 16 bits. Same letter, A, at the top, 8 bits. Same letter, A, on the right, 16 bits. You get double the detection, right? Double the byte detection for the same character. That's why we love Unicode. That's why we love Unicode. Next, how do you further tune some string rules? Yara has these questions. She asked, what are the cool things called modifiers in the language? We talked about Unicode. Unicode, they have the wide modifier. Then there's another cool – so there's ASCII, there's wide. Then there's another cool modifier called the full word. In the first example, you see setup.msi. Let's say you had a file path in the front of it. You want to kind of ignore the file path, but in this case, you just want a signature. Setup.msi, you don't want there to be a file path in the front. You've noticed that there's never been a file path in what you're trying to signature. We want to take that full word, the full word, just the ASCII or the wide, setup.msi, nothing in the front, nothing in the back. There's a full word modifier. Then, let's say you get this camel case of kernel32.dll, you don't know how to signature it. Boom. Hit everything. You can hit it with wide. You can hit it with ASCII. Then there's the no case modifier. That camel case of kernel32, the uppercase, lowercase, uppercase, lowercase that you see alternating on the screen, you can just say kernel32.dll, all in lowercase, and then throw the no case modifier at the end, and it'll hit. Next there's, if there are any Linux or Unix programmers, the uname. You want to look for whitespace characters, right? I found this in another APT binary, some Derisby Linux binary. The uname command was surrounded by three whitespace line feed indicators, or line feed bytes. They were surrounded by the command, particularly the two at the end. I was like, hey, let's signature that. Why is there two whitespace bytes after the uname command and whatnot? Definitely look for whitespace when signaturing and writing your string rules. Those help really well. This is the last stop on the detour. These are just some good examples of some string rules, when to use them and whatnot. First one is the Metasploit UAC bypass. You can hit it. I picked a really good string for this one. It said, error access denied. We probably try to inject into an elevated process, which isn't allowed unless we're also elevated. Pick an unelevated process. How unique is that, right? Quick Google search ended up yielding, hey, that's the Metasploit UAC bypass. It's when it's trying to open a process and it fails for Windows 7. So that was a quick... We wrote a rule. We wrote a rule on it, and then when you're scanning your data set, oh, okay, it's doing this. There's a Metasploit code in there. It helps augment your analysis when you're writing something like this. Also notice there's some whitespace characters tucked in that signature as well. Next a ComSpec variable. ComSpec variables are very unique variable for Windows in a sense that it's the only environment variable that points to a command for an executable process. That executable process is the command.exe, cmd.exe. So if I saw ComSpec in a binary, I can say, boom, that malware right there, he can execute a command shell just by the presence of that one little word, right? He has the ability to execute a command shell. I don't know what he executes further, but he can execute a command shell. So string rules can help definitely augment your analysis. And then last but not least, on the stop on the detour, we have an attribution-based rule. So this is one from Dark Soul, the Teardrop 2 campaign or whatever. This is a custom base 64 alphabet that they used in some malware that somebody reported on. I grabbed it and made a signature out of it. So you definitely want to look for unique strings that will help you in attribution later on. So if you can't attribute it now, maybe with a string rule like this, you can attribute it in two years from now. Luckily, somebody else started the analysis, we picked up on this, and we were able to make a string rule out of it. So that kind of concludes our detour for a second. Let's get back to PlugX. The next layer in our package was the DLL Trojan Loader. I mentioned earlier it uses a sideloading technique. Sideloading is a... I don't know why they started calling this... Really it's called load order hijacking. That's what it's always been. Up until about two or three years ago, some people started throwing out sideloading. I guess it has to do with the fact that it's getting loaded into the database. It's getting into assigned binaries, executable process space, maybe. That's why they call it sideloading, but essentially this core is load order hijacking. The next thing you want to pay attention to, look at file attributes as well. File attributes are important. They're kind of the signature on. So this Trojan Loader had a very small size, and it had very little executable code, as we can see here. So I just kind of ran it through some tools. You'll see the strings tool, like I said, from reverse engineering. We've got the strings tool output, and then we also have a little bit of a chunk of output from IDA, the disassembler. You can see that from IDA, there's only four subroutines and a DLL entry point. So maybe five routines in the whole binary. Even the size from the strings output, it's only like 3.5K. I mean, that's really small. And then it's got a few readable strings in there. What's one thing that kind of jumps out to people? What do we remember? What do we love? Unicode. Unicode. Right, right, right. So do we see any Unicode here? Hmm. Hmm. We do. We do the msi.dll.eng. Hmm. And that's a really weird file name, too. It's got a double file extension. So it's Unicode. Hmm. That sounds like a good signature. So let's write that. Boom. This is how you write it. So rule. And we're going to name this rule PlugXTrojanLoader. Payload names. Payload names. The string detection. It's going to be... So for string one, msi.dll.eng, we're going to throw in the wide modifier, because remember, it was Unicode. And we're going to say full word, because we don't have any evidence that it's got maybe a file extension or other things before or after it, right? So we're going to say full word in this. And the condition is going to be any of them. So any of them means any of the strings present in the binary. If they're present... If any of these strings are present in a binary, then alert. So it's a real simple way to say all the signatures and strings. For any of them. So let's say we ran that rule, and for whatever reason, we got a lot of false positives back. I don't know why, but we did. We thought msi.dll.eng was pretty unique, even being Unicode and the full word. So how do we then bring it down? It really wasn't the case, but I just need to throw this out there to kind of help you guys. Just teach you more on how do you incorporate them. But it's pretty unique. It's pretty unique, actually. But in the case that you do get something back where you get a lot of false positives, you can look at the magic file number in an executable. So for those of you who run Linux or Unix, you have the file command, and it reads the magic number for the file type. Windows, they use extensions. But in this case, you have the 4D5A. We're going to look at that magic number, and we're going to use that to filter so our rule only runs against... Only runs against... Against Windows executables with the 4D5A signature at the beginning. So remember that that was at offset zero. It's at the very beginning of the file. And then this is what, in red, this is basically, I'm going to just give it out there to you. I'm not going to explain it, but you can go back and research it, how to write it. But you're checking for the MZ magic header at offset zero, the UN16 at offset zero, and you're looking for that byte value. It shows up as 5A4D because it's switched around, the ND in this. I figure which one. I mean, little in your binning affidavit, but either way. So that's how you would reduce some false positives there. Let's say you still get more false positives, right? Even after doing this. What can you do? I mentioned about file attributes, right? File attributes. So how about we say, let's reduce it down. The file size is less than 11K. So we can add that in there to then further reduce our false positives. Okay. So this rule is not really a hard rule, but we're combining a lot of conditions. For those of you out there, and maybe your first time, I'd say this is a medium-type rule and whatnot. But let's get into some hard stuff, right? This is the time where if you want to fall asleep, you can fall asleep. But if you want to be awake, you can be awake. So yeah, the PlugX Trojan Loader, and we're going to do rule two, because we wrote one on the payload names, right? Now we're going to do byte sequence rules. This one's going to be really hard. So in here, I'm just giving you the disassembly. Disassembly. If you've never heard that term, you have the opcodes on the left, and you have the assembly instructions on the right. Well, let's just do a disassembly on the brief, on the very, very brief, right? Because I don't have all day, and neither do you. So like I said, opcodes on the left. The 80 opcode is the opcode for the XOR mnemonic. The mnemonic is what you guys read for disassembly. Right? And the 80 is what the machine reads. So 80 means XOR. And then there's some operands that go with this instruction. And these operands, the CL register. So you're moving 3F into the CL register, and then you're just performing the XOR operation. But those opcodes correspond to those operands. The F1 3F corresponds to the CL 3F operand. And notice that the opcode, the last opcode, the 3F, is the same as our constant. It's our byte constant on the right-hand side. So pay attention to that. That's going to come into play in the future. If you get lost, if you get lost with opcodes, definitely check the... There's a really cool x86 assembler opcode reference page on the internet that you can check out. I use it all the time. It's like my right-hand page of information for opcodes, yeah. And then, so let's go into the byte sequence rules. I'm just going to give you some brief steps, and then we'll go into writing it. First, you want to wildcard the operands, and I'll show you exactly what that means with YARA. Next, you want to consolidate the wildcards with some jumps. You want to pad jumps for larger constants. So that 3F constant that we saw, that 3F byte constant, there's a possibility it could be a larger constant in that position. So we want to pad for those larger constants if they ever show up. And then also, we want to do constant enrichment and tuning. We want to hunt our malware repositories, our new intelligent data streams for other samples. Right? So how do we do the first step, wildcarding operands? We find all the opcodes for the operations. We ignore those. And then all the operands are going to be in red that you're going to see up on the screen. So we're going to wildcard that. How do we wildcard that? Boom, just with question marks, double question marks. So we just, on the right-hand side, we've wildcarded all of our operands. So real quick. I mean, there's some. We're getting some heavy stuff. Next, you want to consolidate the wildcards with jumps, just to make it look prettier. You don't really have to do this, but if you want to type out all those question marks, you can. That's up to you. But I like to consolidate them with some jumps. And basically, the two sets of question marks, so you've got four question marks on the left at the very top, can be reduced down to a two. So that means skip two bytes. It's a jump. It's called a jump. Next, you want to pad for larger constants. Remember that? That 3F constant that we talked about. In this case, we've got two of them in this byte sequence. We have the 3F, and then two instructions later, we have the push zero. So the XOR, CL with the 3F, and then the push zero. Push zero actually happens to be some junk code. I don't cover that, but yeah, that's something you'll have to take into account. I will show you at the end with the finalized rule, but I'm not going to exactly explain the math on it. There's a little bit of math. It's really easy, though. It's addition and subtraction, depending on what you've got to do. So how do you pad for larger constants? Remember that we already have one byte present. One byte present. This is 32-bit architecture, x86, right? So we can have up to four bytes for a constant. So we already have one present, so three more. Three more. What if three more are present? So we have a jump of between two to five bytes, right? Jump between two to five bytes. And then we have the push zero. We already have one present, and in this case – oh, so we have the two. The reason why we have the two is because of that CL. Remember we had two opcodes for the operand, so we have two operands. It doesn't always do that way, but we had two, and then so therefore we start off with two and then add three more that we wildcarded. And now with the push zero, we have one for the operand. So we have one and add three more, so you get a jump of one to four. Add three more to two. You get two to five. I don't know if you're seeing it there. You can go back and look, but yeah. Next they have what's called in YAR they have called alternates. Alternates are really good. So in the left you have sample one. Sample one, the first byte in this sequence that we're trying to write – oh, and I forgot to mention earlier that I did the reverse engineering for you. We're reversing a – or we're signaturing a string decode routine that was present – remember we only had five routines. One of those five is a string obfuscation, deobfuscation routine, so that's what we're signaturing on. That's what we ended up picking to write our rule signature. I should have mentioned that in the beginning. I'm sorry, but yeah. So sample one on the left, you have an 8B instruction. Sample two, hmm, from doing some hunting, we found a different one. Opcode is a little bit different, but it starts with an 8A instruction as well. And so they have what's called alternates. So we kind of go back to the opcode table, consult the opcode table, and notice that for the move instruction we have the 8-8, 8-9, 8-A, 8-B, and 8-C. Hmm, those are all moves. So let's do an alternate. So we have 8B, and we want to insert 8A, right? So they have this little open bracket or with the logical or. And then so you have 8A or 8B. And then you follow by a jump. So we're in that sequence. So now we're writing our byte sequence rule, and we're running against YARA or Virus Total Intelligence, and it comes back at us and it says, hey, you're too optimized. You are just too optimized. Well, I cannot, I can't keep up. It's slowing down the scanner. You need to pull back on this rule, right? Happens a lot in byte sequence rules. So how do you pull back? One of the great things that I kind of pull back on is similar addresses, similar address locations. So the initial address locations are one of the things that I kind of pull back on. They can change, but if you look at this one, I've kind of highlighted the 00300010 byte, and then another one further down you can even see I use an alternate. And so they do change between these two rules, this Trojan loader 8 and Trojan loader 9 rule that I have. I wrote like 12 different rules on this one from all these different payloads that I was finding, like literally. So I'm going to show you those results in a little bit. All right. some of the cool results that writing the byte sequence rules, like I said, you can find the families and find the variants how it actually impacted and helped us to improve our string-based rules later on. So after this, after we write this byte sequence rule, I'm going to show you that. So stick around. Don't leave yet. I know this is the hard stuff, but yeah. So look for these similar address locations and maybe you want to insert them back in. Okay. So we took out the wildcards and we inserted these bytes back in. This is the finalized rule. I have a couple things that I didn't cover in here. At the very, very bottom, I have a lower noble wildcard. I really love those. Oh man, I wish I had it all day to explain and I'd tell you all about them. We also had some junk code. If you look at the picture at the bottom right-hand corner, that's the disassembly, and that was like the one with like a whole, it's got four junk code instructions, right? So how do you handle those junk codes? So we basically pad our jumps a little bit more, and we even have a jump there from zero to five. So that's zero jump. That's because of the junk code. And we had to remove the, we had to de-optimize with that virtual address, right? So yeah, so that's the finalized rule. So just a quick review. Byte sequence rule steps. Wildcard your rules. Wildcard your operands, sorry. Consolidate your wildcards with jumps. And then pad your jumps for larger constants. And remember that when you write these byte sequence rules, you're constantly doing tuning, even with the string-based rules, constantly doing tuning. And hunting your other malware repositories for new samples, your new intelligence stream, like I said earlier on. So let's start to look at some of the repeated things. So in this case, I kind of highlighted the, these are all the same MD5, and all these rules from virus total intelligence, that's where I do my hunting. Sorry guys, but I'm very fortunate to do it. I love it in there. But the, so they hit on all these plug X rules, and you can notice if you notice I have TBHK campaign plug X Trojan loader 10 at the very top, then the next one is Trojan loader 06. Hmm, what happened to 7, 8, and 9? Trojan loader 5, Trojan loader 4, what happened to 2 and 3? Because now we have Trojan loader 1, and then we have a another string to code, which actually is the same string to code thing. So I actually had like 12, but that one I just didn't number it. But notice here, I wrote like 10 different rules for in the same function signature. Right? So if you don't get a hit on, if you write this rule, this one rule to rule them all, like a Lord of the Rings effect, I guess, kind of say, if you write this one rule to rule them all, and you get a variant that doesn't hit on it, and you only have one rule, you have no coverage on that. So I write like, I wrote like 12 rules on this guy, and you notice I got 1, 2, 3, 4, 5, 6 rules out of the 12 hit. So, you know, I think that's pretty good coverage. And then I look at it, like the ones that don't hit, and see why, and maybe tune some of those rules and whatnot. So constant enrichment and tuning on multiple rules. And then, last but not least, let me go over some more, some more results. Our byte sequence rule then fueled back results. What we didn't get, what we got hit on the byte sequence rules, what we didn't get hit on with the payload names, the string ones that we wrote earlier, these are some new names that we got. Using our generic byte sequence rules, right? So now we have more payload names, and we can include that into that rule as well. And then looking at some of these names, does anybody see any patterns? Does anybody see any patterns that emerged? We talked about one. We talked about one earlier. Anybody? Anybody? The double extension, double file extension. Good, good. I think there's one person paying attention. Nice. So yeah, the double file extension. That's, that's definitely one pattern that started emerging. merge. Could all these binaries be related to the same actor, the same APT actor, or the same malware APT author since we know that PlugX is being used for six, eight, a million different APT campaigns in China. Can this all be the same actor? Are there any other themes that you may see in this data? Another interesting one that popped out was a McAfee theme, the MC, MCF, MCUtil, MCF, MC, McAfee. Are they trying to hide amongst McAfee products and whatnot with some of these names? There was even a real easy one, Microsoft Installer theme, msi.dll.eng, msi.dll.cab. Oh, there's an AV name, another AV name in there. Uh-oh. But double file extension, they're trying to do Microsoft. Look at all these themes we're extracting out based on a couple of rules that we wrote on this malware, which was kind of pretty hard to signature, right? I mean, it used the self-extracting archive, which is like, you see that all the time, a really, really small DLL loader, assigned executable, and then we didn't even get into the payload, right? We didn't even get into the payload. And look at all these themes that we're picking up. And last but not least, the last theme that I want to definitely point out to you, look at this news media theme, right? BBC, British Broadcasting Company, Sky. My team lead pointed this out to me. I didn't know that Sky was like the British version of Fox News, right? So .bbc.sky. And then they forgot the dot, but you see a Fox, maybe that's Fox News in there too as well. So are they targeting these news organizations? Or maybe not. Are they trying to mix in? Or maybe they're targeting the news partners with news organizations or something like that? Who knows? But I mean, these are some patterns that started to emerge when we started tying multiple rules and our bi-signature rules with our string rules, right? So let's do some housekeeping. Let's kind of wrap it up. Like I said, when writing your rules, rules, rules, rules. Can't go wrong with enough rules, right? Have a really good naming scheme also. So a year later, if these rules fire, especially your attribution-based rules, if they fire two years later, you can remember, oh yeah, that was when I did that investigation. Signature all the layers. It's like the onion, man. Sometimes I do really want to cry. And then, you know, constant tuning. Look at your data sources, you know, the known source, your malware itself, new intelligence streams. Share with meta. Share with meta, like I said. How about some review for some string rules? Remember, we love what? Unicode. Nice. All right. All right. And reduce some false positives of string rules. You want to use those modifiers. Look for those white space characters and maybe some file attributes and stuff like that. And remember that strings can be changed or obfuscated. And then, last but not least, we really went heavy. Didn't we go really heavy into some hard stuff with the byte sequence rules? I wish I had more time to, because I didn't even show you more. But, you know, we used the byte sequence rules to kind of find a broader campaign when tying that with the string rules. And we had more opportunities to signature or create different signatures with the malware as well. We looked at some of those implementation gates, the custom features, maybe. So, also remember, consult your opcode table. This is the point where I'm just kind of reading from the slides. I'm sorry, guys. But there's so much I want to tell you. There's so much I want from you to walk away from this talk that I just, yeah. Consult the opcode table. Identify your junk code. I didn't really show you that, but just keep an eye out on it. And then look for some of the opportunities to use alternates, lower nibble wildcards. Make use of structures. That's another thing we didn't get a chance to talk about. The lower nibble wildcards, we didn't get a chance to talk about. The lower nibble wildcards, we didn't get a chance to talk about. So, also, I figure there's ways to signature actually bits. Not just bytes, but bits in Yara. You can actually go down to the bit level, which is really cool, using the bitwise operators and whatnot. So, if you wanted to check bits, just bit flags. That is awesome using Yara. Some resources. These are the two MD5s that I used for the PlugX in this. And then check out our GitHub, Fidelis Cyber. There's some links to some of the things from my talk. And that's pretty much it. It's the end. Does anybody have any questions? We've got about four and a half minutes. Does Yara actually quarantine, or is it just alerting? It just alerts. No, it does not quarantine. And you have to scan. You're scanning on demand. Unless you're using a tool that's integrated on it, then it would alert. But no, it does not quarantine. It's just an alert, a detection alert. We're running out of time, Ming. Let me get the next question. Oh, I'm sorry. Yeah. Question? Question? Go back one slide real quick, because I wanted to copy. Oh, sorry. The resources slide? Okay. We changed it. Okay. Are you going to make these slides available on one of those links? Yeah. Ming, are we making these slides available? Yeah. Come on. How did you know? No, come on. Come on. In the sample five bytes, how did you know that one was... How did you know it was a deobfuscation routine in that file? I know. I mean, in general. I had to do it in the actual release. Also, the most interesting thing in the article. Yeah. I did the hard work for it. I did it, yeah. I'm here in the public office. If I have time to talk about reverse engineering, I did that too. How do you collect the malware and its variants? How do you collect the sample and the variants? How do I collect the samples? Yes. I get intelligence. I get intelligence tippers from the blogs and the reports. reports that i read online right and they generally those companies give out uh indicators like like hashes and whatnot i collect them through virus total uh there's also other free places like virus share that you can get uh for free you know malware for free and whatnot so you just got to find a good malware repository uh that's constantly getting updated and whatnot i use virus total it's a pay for if you join yara exchange group it's a google group you can get some limited queries from them for free from virus total uh and and whatnot if for some free stuff any other questions any other questions you got about a minute and a half no we got some we got some time uh we got some time um i know people are walking in and out um y'all hated me that much yeah does anyone have any questions anyone have any questions for jay yeah oh okay so while i'm here um why don't i make yes and the answer the short answer is yes how do you deal with the randomized you know when they randomize like say dot dll dot eng or that kind of thing their code randomizes their names in the string rule you might for randomized strings or randomized bytes let's create a different name so you may want to create you want to turn that that string from a string based rule to a byte sequence rule in a hex editor and then wildcard out those characters or you can do a regular expression or actually yara gives you the ability to define uh uh uh non-ascii bites in the ASCII text. Now that doesn't wildcard like you were asking, but it gives the ability to find non-ASCII bytes mixed in with the ASCII text as well. So you can convert that. There's three different options. Regex, convert that string rule to a byte sequence rule, and then also insert bytes if needed, like non-ASCII bytes, to further tune it. Do you see that happening a lot in the online app where you get your randomization? Do I see a lot of randomization? Yeah, with the file names. I mean, yeah, it happens a lot. They're so easy to change. You don't even need a disassembler. You just change them in a hex editor to re-change file names or whatnot, or they get changed on the fly. I mean, yeah, file names are definitely changed. We had very little to go with on this PlugX Trojan Loader, hence why I decided to signature on a file name. So that file name is actually the file name of the payload. So it's a string present in the DLL loader. I should have explained this. I'm sorry, guys. It's a string present in the DLL loader that's the name of the payload. So the loader needs to decrypt, or it needs to execute the payload. So it needs to look for that file on disk. That's why we were writing that file name string signature-based rule. Sorry, I should have explained that. Yeah. So any other questions? Any other questions? I can't see. Doesn't look like... Good, good, good. One question I will throw out there. I do get a lot of questions about UTF-8. In that case, if you're trying to signature UTF-8, just write a byte sequence rule. Look at it in a hex editor. Write a byte sequence rule. I haven't gotten that question a lot, too. So, yeah. Thank you, Ming. Thank you, guys. Appreciate it. Jay, thank you so much. Thank you. Believe me, I can tell this talk went well. One thing while you're here, while we're all here, and I will say, as I mentioned a few times yesterday, within the next two or three weeks, every speaker workshop slide, all the slides will be published on the Wallace Sheep website, wallacesheep.com. Also, and then within the next, I don't know when, within the next, usually before Christmas time, somewhere between now and Christmas time, the videos. All the talks, including your, all the speaker workshop talks, will be posted on not only the Wallace Sheep website, but also by DEF CON, the conference. So, slides will be made available within the next two weeks on wallacesheep.com, and all the video streams of the talks will be available sometime between now and Christmas time, usually in the fall. So, again, thank you so much, Jay. That's good news. Thank you. Thank you so much. Appreciate it. Thank you, guys. Thank you. Thank you. And so, Jay, feel free if, I'm sure if some people have a question, I mean, we can use this area for Q&A. Yeah, absolutely. And I work for Fidelis, so, I mean, since we're the sponsor, I'll probably be over there looking for creds, too. So, I'll definitely stick around and hang around. Yeah, Jay will be here certainly in the area. So, you know, what do you think? In the back? Is that, I think in the, the wall of sheep here. Right in the center in the wall of sheep here. Yeah, so. I'll make myself available right here. Cool. So, again, thank you so much, Jay. Absolutely. And the next talk, we have a very, very good talk coming up next, which is Larry Cashtaller. Larry from Akamai. He'll be talking about cross-site scripting or how he found them in WordPress plug-ins. So, Larry, you're on the stage. You're on the dock, man. Yeah, yeah, yeah. You're on the clock. All right. Are we starting now or starting? One thing, quick, guys, a real, a plug to Gita, my, one of my teammates, and she's giving a talk later on today about mining VirusTotal and whatnot. So, maybe that kind of. She is. Yeah, yeah. She is your colleague. I didn't know that. Yes, yes. We work together on the same team. Yep. Oh, that's awesome. So, Gita's coming at what? Five o'clock, I think 510, 510? Something like that. On, I was mentioning the VirusTotal because a lot of people use VirusTotal for like submitting stuff but not for information gathering. So, yeah, Gita Ziabari will be speaking at, at 510. Yeah, definitely. So, that, that could be a good supplement too. Okay. Thank you all for your good work. Thank you. Yeah, thanks. you you you you you you all right so all right so yeah so we're going to get started in one minute before Larry gives a talk I just want to give say thank you for thank you so much everyone for being here in the morning I mean yeah I mean I was just saying to a bunch of people outside that the whole idea of people showing up at 9, 9, 20 in the morning like to sit down for talk it was just like wow this is just absolutely absolutely phenomenal and thank you so much for all your help and support not only for this DEF CON but for but also for also for the last many years so now I would like to give an introduction before I give before I give an introduction to to our next speaker I want to give a want to give a shout out wherever he is I want to give a shout out to Attrition to to Brian Martin wherever he is certainly has done a lot for for certainly for DEF CON but also for our next speaker that we have on stage and was this was this recorded by the way was this recorded that last bit alright so yeah hopefully he heard yeah we'll give him a shout out later on social media but I want to look it's my pleasure to introduce you our next speaker our next speaker is Larry Cashdaller and just a note that is legitimately his real last name Cashdaller and you're based out of Akamai and good friend of everyone to see you in the state information security community for a very long time without much ado everyone ladies and gentlemen Larry Cashdaller hi you guys having a good DEF CON yeah good I'll try and you know I know you know last night was like a party night so I'll try and put some comedy into this and keep you guys awake and I'll be awake because I'm got a spotlight in my eyes but I think Ming's trying to interrogate me up here he's like you know where were you on the night of August 5th uh but um so anyway um so a little bit about me um I've been doing security research for oh maybe since 1997 um I've got over 100 uh CVEs to my name I don't really count them anymore because they're the first couple were like children these are just sort of like uh I don't know abandoned children I guess um I was a Unix administrator for 16 years um I used to do penetration testing in the 90s uh that was back before uh machines were really connected to the internet a lot of them were you didn't have you didn't have websites that were dynamic they were all static content so it was mostly uh penetration testing against um servers so you were always trying to get you know a login on the server root on the server there was no SQL injection there was no uh PHP bugs or LFI bugs or anything like that um I like writing code I like coding in C PHP um Perl um I'm as Ming mentioned I work for Akamai I've been at Akamai for 16 years um I'm a member of their uh incident response team um so assumptions I'm gonna assume that you guys know what WordPress is I mean I um assume that everybody here is pretty familiar with WordPress and how they've got a uh security issue pretty much every week I'm assuming you guys know what plugins are cross-site scripting um I'm also assuming that you know you're not gonna beat me up when you realize that I didn't actually succeed in this this is this is a a journey of success and failure and uh and then just um realizing that the methodology is there but you know the whole thing didn't quite work out the way I thought um so anyway uh why cross-site scripting um so the story is uh I was looking at WordPress plugins about a year ago uh Akamai asked me well I told them that I was playing with WordPress plugins during one of our uh team meetings uh finding uh security vulnerabilities in them and they thought that it would be a good idea if I did that as part of my day job they're like why don't you why don't you do this stuff during the day you don't have to hide it at night you know you don't have to be ashamed of your research at night and I said well I didn't want to use Akamai resources to do my own stuff and they're like no no no you do this stuff we're sanctioning it and we'll pay you for it so do this during the regular work hour this is cool stuff we want you to write about it and post it in the state of the internet report and uh write blogs and stuff so I'm like ok so I was focused on finding local file inclusion remote file inclusion um SQL injection I didn't care about cross-site scripting because I I'm a shell guy I like I like popping shells I like getting a web shell or a root shell or just a command shell in general I didn't care about cross-site scripting I don't like the social engineering part of things I don't like to have to get someone to click a link in order to exploit them I want to just exploit them without them knowing or I guess you don't you you if they click a link they're not going to get exploited anyway but I I don't want to rely on someone to click something for me to get something done I want to do it all on my own so I always want a shell and I kept seeing these um these get requests these post requests blatantly echoing um variables back to the browser window and I just would skip them I'm like whatever that is it's just cross-site scripting I don't care you know it's not going to get me a shell who cares um it's not SQL injection it's not not fun enough to document and uh after a while I I got so sick of seeing them everywhere I'm like that's it I'm like I'm going to start documenting these things and uh I want to see if I can automate documenting these vulnerabilities and documenting generating the proof of concepts on the fly and I thought I thought that these were a sure thing I figured out I figured if you're echoing you know dollar sign get out in PHP it's going to be cross-site scripting um we'll get to that later so I I thought to myself I I want to do this automated I want to I just want to download all the plugins I I want to uh download every single plugin they have and uh I'll just you know bang on the plugin site for WordPress and you know just suck everything off the uh uh repository for their uh plugin code well after about four days uh WordPress got pissed off uh they blocked my IP address um for about eight months I kept checking like every day for about a week and then I checked like every week for about a month and then I stopped checking for months and then I I happened to check after I think it was I don't know six months still blocked two months later unblocked so about eight months um the problem with this methodology that I I I had was the this repository had all of the trunks the the tags the the cruft old versions uh versions I didn't want um I it I only wanted the latest plugin I didn't want to find a vulnerability in a plugin that was already patched because I had the older version on my system um and I also wanted to collect the metadata I wanted you know stuff that would be of use like uh number of downloads or um uh the author of the plugin so you know my eventual thought was to automate notifying these guys that I had found a cross-site cross-site scripting vulnerability in their in their code um so I had to go about this a different way so instead of downloading all the plugins over uh using my IP address and and slamming their their repository I uh I used the list from the repository as an index so I took the list and uh I wrote a quick a quick shell script to just wget everything and then piped it all through proxy chain so they couldn't uh block my IP address anymore um yay Tor thanks Tor uh it was great because I didn't care if uh if I had anything uh sensitive going over it I just wanted the data um so I let it run for about five days um my wife and son probably wondered why the internet was kind of slow for a week um I told them it was me um they probably expected it mom I do that stuff all the time but um so once I got all of these plugins downloaded I uh I decided to start you know cross-site script mining so I I dug up an old Perl script and uh I started just looking for you know easy patterns low hanging fruit um get requests uh posts um regular requests and I tried to just find some variations in that you know sometimes uh plugin authors would put a space in there sometimes they would use a query quote or a double quote sometimes they would put you know two spaces so I was trying to just get as many as I could but I I wasn't too worried about leaving a few behind um so while I was doing this the same script would uh document the line number of the where the code was had this uh vulnerability in it and it would automatically generate based on that uh variable in that cross-site scripting or uh automatically generate that with using that variable in the uh request header or not header but um rev it would yeah it would use the variable in that um echo or post to automatically generate the proof of concept that I was gonna try um and it would it would document the the title which was just a a generic title of uh you know cross-site scripting vulnerability in plugin xyz and uh it would also collect the vulnerable variables because there were more than one three four instances of cross-site scripting so I tried to collect them all as best I could and then generate a proof of concept with just one of them um so to auto automatically generate uh the cross-site scripting proof of concept I initially just started with the get and uh request only um I didn't wanna try you know doing posts cause those would be harder to exploit automatically um so I figured I would just try and you know push an alert uh pop-up box with just a a general script uh tag an alert um code and then um I had you know the script built and then I needed to know where I could store all of this um I had figured I'd just you know at first I had created a flat text file and that just wasn't gonna work um I had you know nine hundred vulnerabilities with nine hundred untested proof of concepts that I had generated on the fly and I needed some way to sort these things and go through them so I decided to build a MySQL database um I figured I'd just use MySQL um I had to determine what columns to use I figured I'd just go real basic um I'd store the uh the title uh the plug-in name file vulnerable code proof of concept date just the basics um I figured if I had the basics I could collect more metadata later populate more fields based on what information I had in the database and just re-run scripts and just stuff things into the database as I needed um at this point uh I thought to myself you know I probably should start telling people about what I'm doing because if this actually turns out to be legit I can't just drop a thirteen hundred and fifty-two vulnerabilities on the folks at WordPress they're probably gonna either send an assassin squad after me or uh they're just gonna either ignore me or I'm gonna get some hate mail or you know um a pipe bomb in the mail or something I don't know um so I ended up running the scripts with a post request also figured I'd just generate everything I could and um I realized I was over my head uh I'm like I have all of these vulnerabilities there there's over a thousand of them I need to start telling people who uh normally deal with this sort of thing you know what kind of vulnerability researchers or what kind of um people could I contact and I thought of you know uh because he's been indexing vulnerabilities for I don't know 20 years or so um I figured I would talk to MITRE just in case the CVE guys because I know I thought that I should let them know that I might be asking for 1300 uh CVE numbers which I figured they'd just ignore me uh which they did um or they oh alright alright yeah I'll catch up with you guys so if I'm not here tomorrow look in that guy's trunk um a few trunks oh geez multiple trunks um so I talked to Scott Moore you know at IBM X-Force because he's been an old friend and uh he's been indexing uh my vulnerabilities for a long time also so I uh I talked to Ryan Dewhurst uh for WordPress Vulnerability Database and I said look guys can you hold my hand I'm kinda lost here I I found all this stuff I don't know how to handle it I need help um I you know told Akamai I talked to Solar Designer about you know on the OSS security list I'm like uh I might have to put you know 1300 vulnerabilities on the open source security list how do you want me to format that I can't send 1300 of these things you know one email at a time uh that would be I'd be a prick if I did that so uh we worked out this whole system for you know putting one line per plugin per proof of concept exploit and we would split it up in four emails I had written a bunch of Perl scripts to get this done was testing the mail anyway um so I thought I had you know these 1352 vulnerabilities I started to export them to various databases you know uh I got a Skype call from a group of researchers in Germany they're like we've been looking for someone to find zero days in plugins because we wanna track how long it takes for a plugin to be discovered to how long it's being abused uh in the wild so this is great you have all of these zero days you haven't shared them with anybody except you know a handful of people um you know we wanna tie you into our research and you know would you send us the database I'm like sure you know I sent them the database I sent them the PHP code um I was I was um creating uh custom CSV files for people you know I was like like a kid in a candy store I'm like oh you want some free candy here you go let me know what you think it's it's not gonna go um public for another month or two um I sat with Jericho well I didn't sit with him but we we talked over um email for a couple of days massaging the the database we were fixing mangled entries um he was giving me suggestions on what data to store because I pretty much built a vulnerability database out of all of these um cross-site scripting things and he was the man who knew how to index this stuff um and hence they wanted more columns so I was adding more columns to the database um I was adding uh I wanted to you know add a spot for CVE IDs um I figured I would self-assign uh CVE IDs for MITRE uh just so I had a a number that I could associate them with and you know not try and get those guys to do that stuff um people also wanted you know what kind of what type is this is this a GET request is this a POST request um I used non-C um I also created an auto-verify field because I was intending on trying to figure out if I can you know verify these things automatically and then know that for sure they're legit cross-site scripting vulnerability um and you know I wanted a contact date because I was gonna I was gonna try and do this responsibly I was gonna contact vendors and say look you know uh I have a vulnerability in your code uh can you fix it and then store the date and um I had uh you know the file name uh with the full path because I would need that later on in my research to try and verify this stuff um and you know I wanted to validate the proof of concepts uh I wanted to make sure that you know if it was legit that you know it was documented legit with a proof of concept that wasn't just hearsay or I suspect it was real cross-site scripting vulnerability and I wanted to have it in the database so that I had thirteen hundred vulnerabilities and thirteen hundred exploits because I thought that would be really cool and I had an idea on how I was gonna test this um I had been thinking about it for a few days and uh decided I had this clear path to trying to trying to exploit these things automatically so uh I tried uh auto-exploit um my idea was to uh send the auto-generated payloads uh to vulnerable plugins I was gonna use cgi bin I was gonna use phpcgi to execute the php code and render the html with the javascript payload inside of it um the javascript payload I thought would be just uh an image request to grab a script that would just be a number on the end which was the vulnerability number uh that would set the auto-verify to one in the database just saying that you know the javascript fired and that it was legitimately executing in the browser and that was a legit uh cross-site scripting vulnerability and it was proven um so uh for the uh automatically generating the html um I set up uh a cgi um environment uh set up the environment variables um so you need to have these uh these populated you had to have uh you know the cgi uh stuff set up redirect status uh the request method would be automatically changed depending on whether it was a get or a request or a post eventually um and then the query string was just my payload with uh just a generic um cross-site scripting payload you know just an alert box and um so it was a simple script it's just a simple basic bash script um that would just set up the environment and then I could just feed um from the database I could feed the uh php file that was vulnerable and I could feed uh the payload that I wanted to use with the specific vulnerability id number in the uh set for the variable for the payload um it was a two-step process um I had uh I had to first render the html and then I had to actually run that html through um phantom js to exec the javascript and um once I could do that I could find out you know if this thing was gonna even work I wasn't sure if this was gonna work or not I I thought it might um and uh I ended up uh pulling down phantom js um I don't know if if folks are not familiar with phantom js it's uh it's just a a full stack uh web browser what's headless though so you pretty much tell it to do something and it will spit out an html file or uh and uh an image file of what it got back um and I found this uh skander javascript code that somebody had written that would take uh a document and then render all of the html files in it as if it had gone through a browser and spit out a uh an html file and a png file of the results which was perfect it was exactly what I needed um so I set this thing all up and uh I'm about to hit enter and I'm like I wonder if this is gonna work you know I'm I'm like I'm I'm sure someone else might have tried this but you know this was my idea and I figured I would I would give it a whirl and uh so I hit enter and I start uh tailing uh the apache access log and it's working I'm seeing stuff come in uh stuff's firing off I'm seeing um you know my logs are starting to scroll and I'm like holy crap this is actually gonna work I I might have you know 1300 of these vulnerabilities with proof of concepts Jericho's gonna buy me a beer he'll buy me a beer the next time he sees me if this thing works and uh so so then I you know I start examining the results and uh I'm like oh I have all of these these results files in here and uh I can see where all of the the the code has been executed in the ph in the png files you can see where um you had like error 500 error 500 and then more error 500s and then like I saw legitimate cross-site scripting in there and then another error 500 I'm like uh I wonder what this really boils down to um so I go through and uh I start looking at the results 38 of them fired off I'm like that's kinda low uh and at this point I realize something went horribly wrong some something's not right there there there should have been I thought maybe 200 of them maybe would have fired off as automatic so I thought well you know perhaps they all need you know authentication you know maybe these things need to be uh authenticated in order for the the for the uh vulnerable code to be reached but you know I realized it worked it actually did work so something went right but something something's still wrong there's something that's broken um so then you know I started to sit down and just think about what I had done and what my results meant um I figured you know if the javascript execution was successful then I know that the proof of concept that I generated is working that that that little snippet of java payload was actually escaping the tags properly that I was actually getting somewhere and the automatic generation of that thing actually worked and then you know I realized that you don't need to be authenticated if it did work so these were legitimately unauthenticated cross-site scripting vulnerabilities um and I knew that the injection point was you know wasn't sanitized and I knew the code wasn't just defined in a class I couldn't reach um because if it's if it's stuck in a class and that class isn't being loaded you can't execute it um and then you know if if the javascript didn't execute um the I thought perhaps the injection point was being sanitized and I had missed it somehow or uh you know the code required authentication like admin rights or you know regular login user uh rights for an author for wordpress and then uh you know perhaps the proof of concept needed to be tweaked it needed to be it wasn't escaping the html tags properly so I thought you know at this point I thought you know maybe there was some some hope you know I'm like maybe maybe the proof of concept needed to be you know reworked and tweaked and you know um I might have more of a success rate so then I started looking at the environment I had built and realized um I had screwed up um I didn't have wordpress actually loaded you know this this thing was just executing these php uh files but these php files might be relying on other php snippets to work properly they might be including pieces of other plugins they might be including pieces of uh wordpress um and if that's the case I'm just going to get an error 500 it's it's it's not going to even run so those were weren't even valid tests um and I didn't have the entire plugin copy you know these snippets of code are from plugins that rely on other pieces of code in that plugin and I didn't have that plugin available so when the php executed and it went out to include another file and that file didn't exist it blew up it just didn't matter it didn't even execute it just broke and gave me error 500 um and then another thing I realized is that um some of these plugins were setting the content header so that they wouldn't be vulnerable to cross-site scripting and php5 doesn't set the headers it just renders the the it was just rendering the uh the html but not actually setting a header because it's cgi it's it's on a command line it's not a full stack web server um and then the the real uh kick to the head was that I found out that wordpress escapes the get, post, and request variables I didn't know this I I I ended up finding this out um maybe I I don't know two or three days after I ran into this problem was just mulling it over like why didn't this work and then I thought to myself perhaps the folks at wordpress knew this uh which is why they sort of were dragging their feet on acknowledging the 1352 vulnerabilities um maybe they did maybe they didn't um I know that uh it it pretty much messed up the research that I was doing because I didn't figure this out before getting too far with this uh so in the code um if you look at the code and the uh the wordpress load file uh you can see where it takes the get variable and the post and the cookie and the server the gpcs variables and just runs them through addmagic quotes so what this did was um it screwed up my payload so that I couldn't break out of the html tags and uh pretty much rendered a lot of the uh uh cross-site scripting vulnerabilities um un uh unexploitable um so I was I was actually pretty sad uh this was this was really uh an annoying thing that I had run into um so I went back and um I managed uh I managed to go and verify that uh twenty seven of these automatically were uh the the proof of concept was generated the vulnerability was verified and um it actually worked so twenty seven were fully automated generated vulnerabilities with proof of concepts and verification of that vulnerability and then three I manually validated um you know some of the payloads needed tweaking um I think they needed another variable to be set in order to reach the vulnerable code in that PHP file which I was able to figure out once I you know after a manual code review and uh there were false positives too um I had found you know some places in the code that had you know made sure that the variable was an integer which you know broke the cross-site scripting um so at this point um I I I was you know my cool kid status was pretty low I I thought that uh this was gonna be uh something that I could submit to like DEF CON which I I'm here um so I I guess it kinda worked um but uh it was just a real disappointment I uh uh I thought that you know this was gonna be uh a really cool example of how to automate this stuff and then you know I thought perhaps uh this could be something that you know folks could use and pick up and start using to to find their own security holes automatically um so what I learned and I think this is probably the most important slide at least for me was I should have tested stuff end to end um I shouldn't have tried to cut corners and make things quicker and just think that I was gonna be smart by you know using PHP CGI or CGI execution I should've built a full working Apache installation with WordPress and installed the plugins myself and then done the testing that way um I'm not sure how I would install 1352 plugins uh but you know it would've probably had better results than this did um and when you see odd results you gotta research them you know why why am I getting this extra character in here when I shouldn't be seeing anything why isn't this working you know it's uh you know investigate you know if it doesn't make sense you gotta look deeper you know I never thought in my mind that someone would be doing something you're not expecting uh like um escaping global variables I would've never thought that anybody would be doing that um it just never occurred to me and I was dead wrong I WordPress was doing it um you know they're escaping everything I needed to break out of those HTML tags and actually you know make this thing work so uh it tripped me up it made uh it made everything context dependent um so stuff like this I could still get working with cross-site scripting because it wasn't being escaped out of any HTML I could just HTML doesn't care if there's uh um uh quotes or double quotes in there it'll still you know or JavaScript will just render uh we can still use our our regular payload but most of these were like this context dependent you had um you know all the stuff that was being stuck in there uh that I was trying to escape out of you could see in the oh you can't see it too well but um it was escaping the the the double quotes um and and I that's why my payloads weren't firing um where the injection point was and you'd need to know uh if there's a way around it and in some cases there wasn't and the their escaping was just rendering stuff um uh unexploitable um so yeah the next step would have been vetting all that cross-site scripting I would need to to manually review the remaining entries I'd have to go through each one and see where it was in the code if it was something I could escape if it was something I couldn't escape um if it was something uh that was uh required another variable to be set in order to reach the vulnerable code and it was legit um there was no way I was gonna take you know the time to do this this was this would have been a huge uh a huge undertaking even for a large team I mean you'd need a bunch of guys to go through this and um it would be it would just be too much work and I started dreaming about cross-site scripting I was having like nightmares about PHP and plug-ins and cross-site scripting and I'd wake up thinking about cross-site scripting bananas and and just like bizarre things in my head that it just spent too much time looking at code and thinking about this stuff so um I decided it was time to to you know wrap this up and just document what I had done and uh see if other people could use it um I'm I'm pretty much done with wordpress plug-ins uh for now um I think I'm sore at them for for doing the uh content or the uh escaping of the global variables I think that's an evil thing to do um so I I don't want to look at it anymore um I might I thought about you know possibly looking at stuff like you know look for SQL injection this way you know it could be applied to other functions in PHP that might be prone to abuse by a developer or misused by a developer um you know maybe look for some uh command injection stuff with this um other other content management systems Joomlife realized doesn't escape superglobals I started poking at that one um that might be kind of fun to play with Drupal has a nice listing of all of its extensions on that uh HTTPS link so that's another starting point you know maybe I might poke at that or other people can um actually had uh uh a research um researcher who's actually in this room if he wants to stand up and say hello looking at you brute he's super tall uh he actually uh he's an expert of cross-site scripting um I saw a talk of his and he he blew my mind but he actually saw my technique when we were both speaking at the same b-sides or uh Boston b-sides conference and uh he ended up writing his own scripts to do what I did and found a whole bunch of vulnerabilities himself and uh it was sort of a success because now he's able to use this technique and start finding stuff and um probably have more success than I did um and then I started seeing uh vulnerabilities that I had discovered oh uh two or three months ago uh starting to show up by the guys who were running the Summer of Pwnage um they were starting to publish stuff uh on full disclosure and I actually told him like hey I found that about uh two or three months ago in this database that I had built but I never documented it or wrote a proof of concept and I said it's cool that you guys are finding this stuff and uh it's your vulnerability I'm glad you found it and you actually validated it and if you guys want my database I'll just send it to you you know if you want to look at the stuff there um so um so yeah it was starting to see stuff start to pop up and uh you know people starting to see stuff that I had found already but just didn't look at um actually uh this is kind of funny so I have a thank you slide um I'm just thanking everybody here for just listening to me ramble about this stuff this has been rattling around in my head for I don't know six or seven months now and uh you know thanks for coming to hear me talk about it um Brian Martin and Scott Moore and Ryan Dewhurst those guys are all great and just sort it out um Mika at WordPress uh they were they were very helpful initially with just saying look when you sent us this email I did get a response from them they said when you sent us this email uh we just about fell off our chairs they thought we have no idea how we're going to process 1300 vulnerabilities we do one or two vulnerabilities at a time there's we have no framework for handling 1300 of these so they sort of just sat on it and let me know that you know sort of thinking about what they were going to do with it and then I had to send them the email saying yeah I didn't realize you guys were um escaping the global variables and uh so a lot of these things are context dependent which means that a lot of these are probably false positives so you know uh emergency over and then uh solar designer for you know taking the time to actually help me format email that I eventually sent to uh the OSS security list but it only had 30 uh plugins on instead of the 1300 that I thought and then uh the I'm sorry slide which is you'll notice is the same as the thank you slide because you know I I put these guys through so much and and uh you know kept hounding them for information and they were working with me only to have you know this small result uh come as a come to fruition from it um and uh you know if anybody has any questions or uh um these are any my my my my my my my my my breaking my Lastly Yeah I had Falcon but in off call my think. Yeah, I can't see anything. Hello. Can you tell us what is the timeline of all your researches related to this? I'd say it was over a month or two. I initially started digging into things, I believe it was February, and then I realized that things didn't go as I had planned by, I'd say, late April. Yeah, this year. Last year I was looking at mostly SQL injection and remote file inclusion. But, yeah, it was about two months, I'd say. Two to three months. Any other questions? No? Going once, going twice. Well, Larry, thank you so much, my friend. Thank you. So, once again, Larry Kastaller, everybody. So, once again, once again, as I said earlier, all the presentation slides will be posted on the Wall of Sheep website within the next two weeks. Videos sometime in the fall when DEF CON gets them. And thank you so much for being here for today. Our next talk is at 1210, and it will be Kate Pierce and Carl Vinson on HTTP. Stay tuned. Thank you. Thank you. Thank you. Thank you. Thank you. Thank you. Thank you. Thank you. Thank you. Thank you. Thank you. Thank you. Thank you. . . . . . . . . . . . . . . . . . . . . . . . to be a very good one we already know it's on http2 by uh sec valve and virus also known as uh also known as um kate uh kate pierce and uh carl vincent so they're uh they're in the back they're uh getting they're getting warmed up um but again uh thank you so much for all be for you all being uh being here um you know this afternoon i mean it was just amazing like even before i walked into early people like you're sitting down i was like you got to be kidding me what happened so thank you so much i think we can't thank you enough for your support um this year at the packet hacking village at uh at defcon uh while we're waiting for uh pierce uh for i mean for uh kate and um and uh and um and uh carl uh i guess we can uh take some time to give us some time to give us some time to give us some time to give us some time to give us some time to give us some time to give us some time to give us some time to give us some time to give us some some time to give us some time to give us some time to give us some time to give us some stuff okay so some stuff okay so some stuff okay so https i got we got a mice here from f5 https i got we got a mice here from f5 https i got we got a mice here from f5 uh what does http stand for that's just uh what does http stand for that's just uh what does http stand for that's just i like yours i like yours i like yours okay so uh we got another mice and we're okay so uh we got another mice and we're okay so uh we got another mice and we're going to be doing this stick the whole going to be doing this stick the whole going to be doing this stick the whole for the whole day and uh good parts of tomorrow. What's a good question here? All right. Oh, let's see. What's a good trivia question I can think of? No, no, no, no. I don't know about version numbers. I'm not going to answer. I'm not sure if I want to answer. I'm not sure if I'm capable of answering that question. Let's see. Okay. The organizing group. Ah, here's a good one. Here's a good one. Who is named the organization? The organization that's in charge of the web standards. Who said that? I'm going to give a couple of them out. Here's one. And we'll give you a half. Okay. And again, these are Mises from F5. Let's see what's another question. That's a good one. No, I don't like to. No, let's not go there. Let's not go there. Let's not answer that one. Let's give you another. Let me think of one. Let me. Before I give the mice, I actually do want to give a shout out. One of our sponsors for the Wall of Sheep is Veracode. And we'll be giving these shirts out all day. All right. Who wants the shirt? Who wants the shirt? So, I got to be careful because we don't want to break things. We don't want to rack up the insurance policy. We got to be very, very careful. These are shirts from Veracode. Okay. You can jump for it. And this light is bright. Okay. And... I'm going to go somewhere in the back. Oh! That was a ricochet. Yes. Here's the... I think I... What's a good question here? So... Well, that's too easy of a question. That's too easy. I think next year I got to come up with a whole list of questions before we... Before we... Before I come out here. I'm drawing blanks right now. Actually, here's a fun question. Here is a fun... This is a fun question to ask, which has nothing. So, you ready? And they're ready. Coming down the aisle. Woo! SecValve and Byrus. Oh, boy. Yeah. So, we got the light... VGA or... You have DisplayPort? Oh, you got everything. So... What's the line? An bonsai. So, you know what? You had the vai...- You had a phone. You had an iPhone. You had a iPhone. While they're sitting up, I did think of a question. So here at the Wall of Sheep, here at the Wall of Sheep in the Hackett Hacking Village, you know, the whole idea of, I know a lot of people have come, you know, over the last few years have come to see our speaker workshops. Does anyone know how long the speaker workshops have been going on for at the Wall of Sheep? Three years. Woo. 2001. Huh? 2001. We would like to say that. Six years. Ah. Five years. Four years. Seven. Eleven. Twelve. Five. No. I, I, I, someone did say the right answer. Huh? Who said that? Eight. Four. Who said four? Yeah. So, surprise, surprise. Ah, just to give you a little idea, yeah, the speaker workshop, this is only the fourth year. This is only the fourth year of speaker workshops, and yeah, we'll never forget what happened. I guess on a personal story, on a personal story. When all the speaker workshops got founded, how we, how this all came about was I got rejected from DEF CON in 2012, and I said, you know, and I said a few four-letter words, stuff was said, and that's when we decided, you know, we, and we, we also noticed we got like a lot of room back, it was at the Rio, and we thought about, you know, doing something that was, you know, that wasn't just, just a wall, as, you know, we've known over the last so many, so many years, if not decades. So this was actually one of the reasons why we decided that we, we, you know, what we didn't know was when we first ran this workshop, we didn't know how popular it was gonna be, and so this is one of the reasons why we actually, instead of creating just, you know, a table with, you know, people putting paper plates of usernames and passwords, and it was a far cry from what it used to be, and we knew that when we were running events like the Speaker Workshop. We said we had, there was, there was something bigger, and this is why when you're here now at the, at the Packet Hacking Village, not only do you see the wall of sheep, you also have the Speaker Workshop, we have Captain Packet, Packet Detective, and now there's so many different events such as the Y5 Sheep Hunt, and, and now Sheep City, and so that, that, that, that's basically a brief history of how, how the monster was created. So next year, at DEFCON 25, if it will happen, again, I say if it will happen, because you know that there is always a possibility DEFCON can be canceled, and when we're gonna be here, it's gonna be the fifth year of the Speaker Workshop, so next year will be the fifth one. What time is it? And, uh, before, you know, now, I guess, oh, you got the, oh, you got the pointy-toe, some people were looking for that yesterday, the pointy thing, oh gosh, yeah, we don't provide, one of the things that we gotta be real careful, so we don't provide the pointy things, because we don't want anyone's eyes to get popped out, and we don't, we don't think we have insurance, so, I didn't say that, but, um, so, uh, thank you so much for being here, and, uh, before, um, before I pass the mic over to, uh, to, uh, to Kate and to Carl, um. I don't know what that was, so, um, you know, one of the things that we're very lucky is that we get, not only do we have, uh, speakers, uh, that come from all over the world, but we also have DJs come from all over the world, and, uh, literally, and, uh, the next, uh, the next two speakers that we have, uh, are no different, and I, because I know that, uh, Kate, uh, Kate is from New Zealand, right? You're from New Zealand? Yeah. You know, home of the All Blacks. Home of the All Blacks. And so, uh. And so, uh, without much ado, I, uh, I don't think the next two need too much introduction, and, uh, because, uh, you've, uh, we've, uh, you've been to Black Hat, you've spoken at Black Hat and DEF CON in the past, and so, without much ado, uh, it is my pleasure to introduce to you SecVal and Virus, Kate Pierce and Carl Vinson. I already got one. Hey. Hey. Hey, sir. I have some questions. I'm going to bust it up in my voice. Uh, that's what happens from yelling at, well, things. Blame Black Hat. Yeah, blame Black Hat. Okay. So, I'll try, I'll try overpowering the voice thing, and I want to be able to talk for the next week, but I think I can make this work. Okay, so, this is our session. ACDB 2.1 quick, and I really shouldn't do that because I'm not going to talk by the end of it, so, okay, I'm going to slow back down. Teaching good protocols to do bad things. So, as previously introduced, Kate, SecVal on Twitter, yell at me, people do. Security consultant at Cisco, breaking stuff. Telling people, do it right. Research, which sort of led to this. Distinguishing features, loud, yellow, or maybe that's just a loud yellow. I'm also never going to get a better photo than that one. Ever. So jelly. Go to KiwiCon. Speak at KiwiCon. Get a photo like that, and then be like, okay, I'm done. That's just so amazing. All right, Carl. I'm not important. Yeah. I break things. Hopefully, I scare you. Defcon's about what you say, not who you are, so screw this slide. He's pretty scary. It's left over from Black Hat. Just never mind that slide. If you piss him off, just don't let him know. All right, so starting with a very uninteresting looking video of me just, like, getting a VM, and I'm going to start browsing some stuff, and let's not. Come on. Play, damn you. Play. Play. Something, something, demo gods. Something, something, video gods. Come on. That's kind of funny. Works fine the other day. All right. Play. Woo. Yay. Woo. I can talk like that all the time, but let's not do that. All right, so we decided to browse some Google News, which has, look, this was the New Zealand Google News that day. It's not my fault. I mean. Yeah. I mean, OK. So, yeah, that one. Again, this was news. This was not me. This was the universe speaking to me. And so I decided I got bored with that. Go to YouTube, and I start looking for something to watch. And then, you know, being the clickbait victim that I am, I decide, oh, Pokemon Go in nine minutes. Let's have a look at that. Getting bored with this dude walking down the street. No one wants to see a dude. I want to see Pokemon, damn it. So I look up where I was going to be speaking in a couple of weeks down at the Mandalay. Oh, yeah, Wellington. That's where I'm from. So I look up where I was going to be speaking in a couple of weeks down at the Mandalay. Mandalay Bay. Yeah. The hotel. Down the road. Stuff. There is a reason for all this. Right now, I'm not. I'm just randomly browsing. Yeah, I'm randomly browsing. But there is a point. Mandalay. Oh, yeah. Cool. How do I get there? Feel free to jump in, Carl. Say something. Yeah. Notice all of these services are all Google services. That will become relevant extremely in a few seconds. Yeah. I don't know why I was trying to get there from Spain. A few more seconds. But, yeah. Yeah. The important thing to remember about the video until it goes away is that Yeah. all the URLs that were visited are all public and are all running on Google's native host cloud. So it's all the same web server. Yeah. And this is an unmodified Chrome on an unmodified Windows. There's nothing fancy. Except, oh, shit. TCP is blocked. Like all of it. Like completely. So why does everything work? Yeah. Like what? How does it work with TCP blocked? Well, you'll probably find your browser's already doing this. But we'll get to that in a moment. Do you get the code working, Carl? Maybe. Maybe. He's sitting there coding a demo as we stand here. I know. Right? I mean, how hardcore? Okay. Okay. So TCP was blocked. What the hell? I look at the PCAP and there's this quick thing. What? And it's got a whole lot of headers and crypto stuff. And I have no idea what that is. But we'll get to that later. And, yeah. And then I've got some other stuff. Going to Facebook. Okay. So the wire. So it's obviously encrypted. Look at the SSL. Yeah. That doesn't help. Then Wireshark does this decompressed header, whatever that is. And electric breakfast. Yeah. I looked up and there's like a toaster collection thing on Facebook. I found that kind of amusing and that was what I used for the example. I don't know why. But they have some really bling toasters. All right. So, again, doesn't make much sense. It's a new protocol. It's already live on all of these things. So let's talk about some things that are already here. Some transport protocols that are already making the world explode. You know, everything's getting bigger, faster, more connections, more different places, moving around. So if you want to get trending stats, go to the HTTP archive. They dump it all into Google BigQuery. You pull it up. You can query it. And you can pull stuff like this, which shows you that, you know, your bytes and flow size are all going up exponentially over the last few years. The same with the number of domains, the number of requests. It's all going up. And the reason this is all happening is because, you know, we need all these better capabilities to do things. But there's a few different ways you can do it. So HTTP2 multiplexes within TCP. We'll get to that in a moment. And Quirk just says, you know, I don't need TCP. I'm doing this myself. And, well, yeah, they change the way things work quite substantially, actually. And the reason you care is because there's some familiar stuff, you know. You can't see through it. It's opaque. You don't know what's going on. That's what those teasers were. But there's also some new stuff. You know, some new fragmentation attacks, similar to multipath TCP. And also, your network security right now probably has no idea what's going on. And yet, to be clear, personally, I like these protocols. They're more of a culture shock than a direct vulnerability or concern. I actually want them to succeed. Your stuff works a lot better and smoother when they're working. But no one's ready. And just because it's going to be always that one person, we're skipping ridiculous amounts of detail. Go and read the RFCs if you want detail. Or ask us afterwards. Just don't be a dick. We're skipping so much. Two protocols, 25, 30 minutes, a lot of detail. All right. So how do we get here? Why would these things come along? These things have come along. Multipath TCP, presented on that a few years ago. Extended TCP to add multi-homing and mobility. And link aggregation and all that. But that never really took off. Because if you're changing TCP, you need to have the OS involved. And if you've got hardware, yeah, good luck changing that. If you've got a router or a middle box in the way, it's going to screw with it as well. So you're all right. The demo works. Oh! Writing the demo in the talk. Oh, yeah! Oh! Woo-hoo! All right! All right. Who are we sacrificing to the demo god? This guy? Oh, I don't know. Can we take a rain check from the demo god? No. No? No. All right. Anyway. And you know, your middle box is getting in the way. And there's this whole chicken and egg deployment. We will do that. Don't worry. We'll show you that. There's this chicken and egg deployment thing where no one wants to support it until people are using it. And no one wants to use it until it's supported. And so nothing happens. And what I mean is TCP doesn't do things like high availability, link aggregation, or multi-homing. It's incapable of mesh networking. And it's really, really chatty. TCP is like, hi. Hi. Hi. Do you want to talk? Yeah, let's talk. Great. Let's just encrypt it. Sure. How do we do it encrypted? Great. And you've got so many round trips just to set up a conversation. And until you've got through your greeting, TCP is not going anywhere. It blocks until those retransmits are done. It blocks until that handshake is done. And that's really, really a problem. So multipath TCP helps with those top four. Quicken H2 helps with the bottom couple. And there's a lot of talk in various places of Quik bringing in these capabilities of the top things into a user space network protocol. So, you know, if this is stuff you want TCP to do, what? And there are some reasons not to change TCP. As earlier, you know, it's handshake. You can't change that. It's kernel mode. It's outside user space. It blocks. You can't change that. But if you can't change TCP, what do you do? Well, HTTP. Do you know anything that uses it? Yes. What? I can't tell you. It's a work thing. Oh. So you can't tell me on stage? Correct. All right. All right. I know things that use it. But by and large, especially in the consumer space, nothing uses it. It has the same problems as MPTCP, but even crazier. Because MPTCP is TCP. HTTP is a completely different layer. And it just breaks everything. If you don't have the app layer, well, sure. That's what H2 and SPDY do. UDP doesn't do anything. Doesn't do anything at all. Which is kind of the point. And that's why Quik uses it. So to sum up these journeys. TCP attempted to change your model. It's a multi-part TCP. And for various reasons, they decided Quik was a better way to achieve some of those goals. And HTTP, to bring in some of these additions, they went to SPDY. And that was what led to HTTP version 2. Again, so what? Well, have you looked at how many security tools support either of those? Hint. Cloudflare supports them. But in terms of the security tool for your network, nothing. Nothing much. Cloudflare also can only see them on two ports and can't traverse Quik. They don't actually support it. They just detect it, kind of. Well, they do serve it. They serve it. Yeah. H2 in particular has served on quite a lot of things. It's really unfortunate. And so, yeah, that prevalence. MPTCP came along really fast and then sort of choked. Quik came along a lot faster because Google was pushing both client and server. H2 was just crazy. So Quik is already probably 10 or 15% of your network traffic. Most YouTube traffic right now traverses Quik. If you don't believe me, if you're not blocking UDP, go and look. Whenever I get someone to, they're like, whoa, what? And HTTP 2 has been even faster. So MPTCP, you know, 50 million. It's in iOS. It's in MacOS. A couple of ISPs have done some stuff. Not too much. You bring on Quik and you put Google in and suddenly you've got a hell of a lot more. Probably understated a bit here. A billion. It's probably more like one and a half. Something like that. Something like that, yeah. You bring on H2 though. This is H2 over the last year for the Alexa top one million. 250,000 sites. So let's go with this line here. At least 15% of the top million Alexa sites are using this stuff. Over the last year. A year ago, no one was really using it. And that's crazy. When you bring in the client support, you're looking at two, three billion. That's an awful lot of things. It's about 6% of the internet. It's bigger than IPv6. Yeah, and if you bring that up to, you know, look at the top, call it 20. Facebook, Google, Twitter, Wikipedia, Yahoo, YouTube, Instagram. To be fair, there's a couple of companies overlapping. But most of the biggest sites are using these and that's really quite surprising. Anyway, what are these things? How do they work? I'm going to have a call for a moment and let my voice recover. Or I'll jump in if you... Yeah, there's a lot of black hat references here that are all supposed to scare you into why this is relevant. But I'm not really feeling the need to go through these things at DEF CON. Oh, cool. All right. There's a lot of common features. Multiplex requests, which we'll get to in a minute. Priority requests, which are frames and things. Okay, fun stuff. So, all right. The way that connections in general work for pretty much every protocol on the planet right now is, like, the Internet is a series of tubes. Usually a TCP tube, but a tube. And what that actually looks like is more like this because the tubes are full of packets. So, the analogy that I use is pint glasses. Think of pint glasses with grains of sand where each grain of sand is a different color. And usually, if you want to get five pint glasses from one bar to another, you have to have five different garden hoses to pour it down through. All right. Well, multiplexing is when you have one garden hose and you pour all of those jars into one thing and then you have a magic robot on the other side that splits everything into the same five glasses. So, that means you create one connection and then you give everything a magic ID in the middle and it all comes out fine. So, what this looks like in terms of differences is that so with H1 on a typical TLS browser setup, you have a TCP connection, you negotiate TLS over that TCP connection, and then you send a plain text request, you get a plain text response. With H2, you have a single connection and then there's a software-level tracking of this magic number called streams. And you can kind of do whatever you want in each stream. You send a series of frames and those frames tell it, give me bytes or reset this stream or... A stream is analogous to an HTTP connection. Basically. Yeah. You wanna... Nah, it's more black-out stuff, but sure, why not? HTTP, you know, we know about that. H2, fun things. Binary framing. Not human-readable anymore. Multiplexed. It's no longer linear. Prioritize, which is particularly fun because you can request things and they can come through in a bizarre order. Compressed in a very stateful way. And server-pushed, where the server will send you things you never asked for. There'll be dragons there. Oh, yeah. Some dragons coming for your face. Yeah. So, H2, you know, you got your transport layer, which has some number of frames. And each of those frames has a header and a payload. And there's a few of them, you know... All right, cool. And if you start breaking that down a bit more, your frame with your header then has a payload. And that payload itself has various other headers and type fields. You know, it's nesting and nesting and nesting. You know, this is a dragon's nest. Yeah. Yeah. Yeah. All of... All of your... All of these boxes are all binary frames, by the way. So, yay binary parsing. And it gets deeper. You know, we need to go deeper. And this is probably one of the slides that I probably should never have built in PowerPoint. You know, you've got a transport layer with a stream. That stream is bidirectional and it has some frames sitting upon it. And those frames have all that other stuff. And there's a whole lot of frames on each direction. And then a whole lot of streams with frames. Like... Whoa. Try and parse this manually. You're going to have a really bad time. Go on. Langsec nightmare. Yeah. Langsec nightmare. You should get to the quick stuff. Get to the quick stuff. All right. So, there's... It does some advertisement to know it supports this. We can go through those questions if anyone has it. So, H2 sets up with HTTP2 and Prism, which, if you look at it, is actually a Snowden joke. There's chatter on the mailing list for why they came up with Prism. Was... I don't know. They're like, well, we can choose anything. We want to do that. You know, frames, fixed length header, binary protocol. And there's your types of frames. I guess that does matter because we do reference a few of them, but I'm not going to go into detail. Yeah. The only thing that's worth immediately taking away from this slide technically is the fact that if you talk to any server on the internet that is currently implementing H2 right now and you change the order of these frames in accordance with the implementation of the spec, they don't all answer the same way. So, yeah. H2 is everywhere, but it's still a relatively young protocol, and we're already starting to see deviations in implementation in the way that they handle the order of frames and what their immediate response is. Yeah. Some of them will send you an update or settings or a ping at different intervals and different orders. And, yeah. You can fingerprint with that. Headers are compressed with Huffman encoding, which is actually really interesting as far as encoding goes. You've got a static table of things you see regularly. You know, your get methods, your user agents, all of that. Rather than sending user agents, Chrome, whatever, it's just like 12 because you've got the table. And a dynamic table, which builds up as you go through the connection. And this is fully stateful. You can't jump in the middle and make any sense of this. Fun pitfalls. And this is yours. Connection reuse. I kind of don't even want to give all this away yet because the demo is going to be a All right. Do you want to skip into the demo? Yeah. All right. All right. So how about I just jump to QUIC and we can always come back. All right. QUIC takes H2 stuff, adds in more stuff. The thing about QUIC is it combines your TLS and your transport protocol together. So where H2 does this and has the common layer underneath, with QUIC, the top bit looks the same from the app. However, QUIC with TLS integrated over UDP, but your streams go all the way down. You put an H2 frame, it goes into a QUIC frame. All right. So you've got your transport line managers, your app layer stuff. Much the same as H2. Skipping ahead because that is a cool demo and we didn't have that last time. We didn't have it 10 minutes ago. Yeah, that's... All right. QUIC has a couple of fun things. Zero round trip time. So it can actually start sending data with the first packet. No latency. It pads stuff out so you can't do Oracle attacks. Forward error correction. Disabled it. Just to annoy me. And multi-path. But that's a whole other bundle of crazy. So as with H2, you've got a connection with some number of streams and a packet. A packet contains frame packets and those frame packets contain frames. Dragons. All right. Bring up one of those again. You've got a UDP packet which contains a public header and authenticated and encrypted data. And inside there, you've got a private header and some frame packets with frames. You can read that top bit. You can read it without a key. You need a key for that. So QUIC is actually really annoying to try and make sense of even with an encryption key. Advertisement is much the same way as with H2. So what can you do with these things? Well, H2, always encrypted. Binary frame, blah, blah, blah. Really complex state. Whole lot of side channels. QUIC, encrypted. Really annoying to try and man in the middle. User space. You don't need any else help on that. Doesn't require a socket because it's UDP, which some of you will be able to work out the applications of that. And it's a real pain to fingerprint because it's variable length. Yeah. I'm pretty sure we built the best QUIC fingerprinter in the world as a demo because it turns out everything that claims to fingerprint QUIC sucks at it. Yeah. It really just listens on 80 and 443 and goes, is that UDP? All right. It's probably QUIC. It tries to parse it. It does. Like you laugh, but it really is that lame. You look at the code and it's like, really? Oh, it's not 80 and 443. There's no tools. It's faster and more reliable than TCP over UDP. Yeah. We're not doing any implementation stuff. Okay. All right. First demo because this is what you want to actually get to. All right. Two microphones. Woo! So, what we've got here is an H2 tunnel in. Over QUIC. An H2 out. And why you should care about that? Well, we'll get to that. So, what we've got here is an H2 tunnel in. An H2 tunnel in. And what we've got here is an H2 tunnel in. We're going to look at this for a second. So, what we've got here is an H2 tunnel in. And then, in a little bit, we're going to go down through the H2 tunnel. So, we're going to have to build it and we're going to look at the H2 tunnel. So, let's see. Let's get a couple more. Let's see. Here. Where is it? Wait a second. Oh, there's one here. So, I just want to go over to the . uh okay well i don't know how i'm going to show you a demo if the projector doesn't like my laptop that kind of what you say press alt nf5 it's a linux laptop yeah try different don't nope nope yeah i don't i don't have that that's that's not a thing all right science i did actually i restarted x no because google didn't make their libraries work with the real operating system so blame google uh seriously oh uh yeah all right because that's my background why because occasionally i take this box to climb lands and i like to not get screamed out all right all right all right all right all right so i'm gonna give you a terminal to look at as soon as i figure out how to how to computer all right all right never mind the numbers on the top um so you guys remember the the diagram that you saw earlier where it was a h1 to quick uh diagram on one side and then a quick to h1 diagram on the other uh so the way i've implemented that is as two standalone binaries so there's a binary with a go web server which is a transparent a complete one-to-one http proxy so it doesn't handle all the http verbs and all that stuff that is implementable normally under a go context but again google writes code so if you try to do that idiomatically it'll laugh at you and say the connect header makes no sense so instead we got two binaries so what i'm about to do when i set the microphone down so i can type is I will initiate one binary which I'll initiate one binary which will start the h1 server that will actually talk to and I'll give it a dial back address the dial back address is gonna be localhost port and the secondary server the secondary server is gonna have a quick server and then an h1 dial back which is gonna be the endpoint in this case what I'm gonna do is set that endpoint to dial back to Metasploit so I have a VM we're gonna load a VM and then we're gonna PS exec and instead of the PS exec payload calling back to a native Metasploit listener it's gonna be calling back to an h1 tube that speaks quick in the middle and with Wireshark running I will show you what it looks like which is basically fuck all h1 to quick so this is the entry to the tunnel so now we have the entry server running so now we're gonna start the other one you notice how this binary has more options that's because you have to use SSL when you use quick it's not optional on h2 it's technically not optional as well but they have an h2 variant called h2c which doesn't require SSL yeah because quick mixes in your TLS well your crypto with your transport layer you can't set up transport without crypto you you yeah yeah you you do you Alright, so now we have our Metasploit listener, and I'm just doing this so that we can see where the listener is. And now, as soon as we start the VM, and as soon as I start the second server, then I'll do the VM callback and everything will make sense. This is how you be credible, you do it live. We could have done this in the video, but then the video wouldn't play, and yeah, well no we did, but. The next demo will be far, far more interesting. And more nefarious. When you see the packet capture for this, you'll understand. Where's my front end tube, my front end tube is 8.8, 8.8, hang on, sorry, gonna wrap my brain around my own demo. Um. Okay, yeah, I did that wrong. That's supposed to be. Yeah, so we set the port wrong, we're just fixing that. Oh. 4.1. And then this is. Funneling back to 88.3. I'm still typing, I need a hand. I think next time we should mirror your screen. Well, we didn't plan on this demo, remember? Oh, yeah. That's what happens. We didn't plan on this demo at all. That's fine. And this code's all available for you to play with yourself, so pay attention to what we're doing. All right. Now I've got to go to my VM. All right, so we've opened up the tunnel. It will take what goes in and send it out. If I can remember where the heck I put my VM. You're not an enterprise, how do you lose a VM? Lose VMs all the time. VMs all the way down? Demo. Demo VM, probably a good start. Good old Microsoft browser test VMs, really handy. All right, one VM. One VM. All right. All right, so there's our password, and just to make sure we know what the IP is. All right, so there's our IP, 0.29. 0.29. How are you? So we're PSExec-ing through the binary. Oh, damn it. God damn it. Reverse HTTP. Interpreter, reverse HTTP. HTTP. Arho. Pера. Pera. Too many donts. What was my IP again? 0.29. 0.29. 0.29. All right. So, it's an user. My user. So, let's see. Host. Host. Host. Host. Host. Host. Host. Host. Host. So now I'm going to start Wireshark. And go away. We're going to go down to localhost. And that's going to show us a bunch of stuff. And now, if I didn't screw anything up... What'd I do? I did something wrong. You're listening. Which one? Where? No, that's right. No, it's not. It's on 8888. Yeah. That's what it's supposed to be on. That's about to be it. What'd you do? I don't know. Anyone else seen what we did wrong? No. Oh, sorry. I know what I did. I know what I did. I'm stupid. There we go. Oh, yeah. That. All right. Still did something wrong. But, okay. There we go. There's our... Our request. Our request went back to... Oh. So, we should have sacrificed that person to demo gods. It's cool. We'll figure it out. Yeah, we'll figure it out. Okay, I know what I did. What'd you do? I sent the listener to the wrong port. Yep. Oh, yeah. All right. Take three. Something... Something whatever. All right. So, let's look at this. You know, 443 and 8881 out. Oh, computers. Computers. It's calling back to the right place. It's on zero. Not 127. It should still bind, though. It's supposed to be on zero. Why is my mouse not working? Wait, wait, wait. 445. Go back. Right up top. Oh, did I enter the wrong number? Yeah, go back. Go back to where? Mid-sport. That's normal. That's normal. That's the thing. Okay. Oh, that was the other one. Yep. That's PS exec. All right. I don't know what I did wrong. Do you want to get that going, and I'll continue through the slides? Yeah, I don't know what I did wrong. All right. Well, that was unfortunate. It worked perfectly the other day, but, you know, we'll have it going with a little less downtime. Okay, this one's working. Right. Anyway. This was... That was what you're supposed to see. We had some trouble with the listeners there. We'll get that working by the end. Right. Let's talk through these fun things. Because of the way Quirk is structured, you can do some quite fun attacks with it. First one is because most stuff right now just looks for the port, if you change your port, you're going to have a lot of fun. If you change your port, a lot of things will just naively accept it, especially in UDP space. Because it's complex, you've also got the side channels and scrambling. There's some protocol stego in those side channels, a bit like DNS text fields. We're pretty sure there are some polyglots. We haven't found any particularly interesting other than academic, but... Did you figure it out? He figured it out. Stego polyglots and stego multiplex polyglots. We'll discuss those a bit later, but that stuff is crazy mode. Fragmentation, agility, you're jumping around all over the place, all these connections and streams and stuff. So as earlier, you start with that, you multiplex it down. Or if you have multipath and you break it up across paths or connections, and then if you mux them together and you do both the same things, you get this set up. You can already do this today, but if you get multipath and multiplex, you start chunking stuff all over the place. Good luck being an IDS dealing with that. . . Blah, blah, blah. Right. Forward error correction is all sorts of fun. You can inject fake packets, because you know the FEC and they don't. And you can drop or corrupt packets to force them to recreate them. If you want to detect the client traffic for these, go for the upgrade. Go for your SSL ALPN header or your quick client traffic. As we said, UDP 80 and 443. Bidirectional patterns of communication. This stuff does not look like most UDP traffic. It's very chatty and back and forth. . . And there's no static identifier. You really have to parse this to make sense of it. And that's why we released that detector the virus referred to earlier. Are you good? All right, he's still working on that. If you want to detect the servers, it's actually a lot harder. H2 server, make an ALPN request to it saying, you want to speak H2? Send us an upgrade header, see if it upgrades. Quick server traffic. Again, UDP 80 and 443. Or simply try and connect to it, which is actually really messy because it expects the right crypto to come in. Blocking it, H2, actually easy. If it's over TCP, you throw in a proxy, you don't support it outbound, you rewrite it. If it's on a non-standard port, it gets a little messier. If it's quick, right now that you block on an 80 and 443, that'll block it most of the time. It won't block anyone using something like we do. That sends that across a non-standard port. With Chrome, there's actually a policy setting that no one says. Google says right now this goes over 93% of networks. So people aren't setting that. And you can fingerprint detect and parse it, but in the end, not so much. You bring this up in Wireshark, Wireshark's detector for H2 is actually pretty good. Chrome with its net internal is also pretty good. It tells you the protocol, it tells you the stream ID, the remote address and all that. If you're doing it with H2 log parser, it makes it into a somewhat more friendly view. H2i enables you to send and request arbitrary frames. Well, not quite arbitrary frames, arbitrary messages. NG HTTP, there's a lot of tools for H2 out there, just not many in terms of security tools. MIT and Proxy actually has support for this recently. That's the thing I'd encourage you to play with. Curl. Curl already supports H2. You send a request with the HTTP2 flag, it'll pull it over H2. And you actually see a few browsers using this today. If you open up your Chrome, you go to your net internals, pull up your HTTP2 and your alternate service mappings, and you'll get what I've got here, which is from one of my browsers, where you have a whole lot of them. It shows you where they're using them, what the expiry is. Probably more than you expect. Wireshark supports QUIC. It's not very good if it's on non-standard ports. You can also pull it up through Tshark. Largely by looking for your ALPN stuff, is how you can perk your HTTP2. For your QUIC, you have to force it to pass it and then pass through, pull the flags and the tags. It works? Yeah, it works. Okay, let's see if this works. All right, so it turns out I don't know how to Metasploit, but after enough time, I figured it out. You have five minutes. Okay. Five minutes. All right. All right. So we got a shell. Yay. All right. So now, if you look at... Wireshark. And I moved the window over so that you guys can see Wireshark. Hello. All right. So it's a PSXX, so you would expect to see a reverse HTTP handle. But instead, all you see is a bunch of this UDP crap. And nothing has any idea what it is. And it's all on random ports. And if I manually tell this to decode as quick It's going to be super quick. Uh... Huh? Ah, not... All it sees is a bunch of encrypted garbage. And even if you look at the details of the packet, it pretty much has, like, a tenth of the metadata of what it normally does when you're browsing and yeah lol ids there you go number one you want to go over multiplexing before i do that okay so the next demo i'm just going to do because my laptop's hooked up and we're running out of time um yeah so remember earlier i showed you the multiplexing with all the different bits of different files in different orders so what we're doing here is we're pulling in um we've got an h2 connection which has a large number of streams within it with identifiers and we've set up a program opens up one connection opens up a stream grabs a random byte from the file opens up a new stream grabs a random remaining byte basically grabs the entire uh file or does your web browsing by randomly grabbing bytes via range requests inside that tunnel so it's really noisy but it's one connection that is really noisy and it's really noisy and it's really noisy and it's really noisy and it's really jumbling up the file uh i don't know if this is a ddos technique i don't recon well i don't know find out but um basically when this happens we pull a lot of random parts of the file it's incredibly difficult to reassemble it because you need to be scripting and if we pull multiple bits more than once it'll make a lot more sense when you see it but if you've got say a file that is called a thousand bytes long we'll be pulling a hundred random bytes at a time from that through the connection multiplexing okay so this is actually a lot cooler than it's going to look and i'll flash you through the source code real quick but basically so what this is gonna what you're about to look at is an h2 request where the h2 request is only requesting a head first of the content and the head will return a content length and then for every byte of the content length we're going to choose a byte at random and request it over h2 under an h2 request and we're going to choose a byte at independent frame so if you were to look at this in wireshark it would just get an entire frame center of return from http and then a single byte of data with no context but magically it would look okay in a web browser this is I think of this as traffic obfuscation so that is yahoo.com one byte at a time using as many connection ids as it possibly can in order until my box runs out of network sockets actually no it's using one socket no it's not using that no wait you're opening connections yes what do you hate the internet yes apparently it's slow think of this as a little analogous to yeah byte wise sqli but good luck figuring out what you're doing here noisy inefficient a nightmare to reassemble whether encrypted or not slides are basically done and we can do this with any arbitrary server that supports this you can actually do this over h1 as well but over h2 it's a lot gnarlier because of how the complexity of the protocol works yeah so yeah we're way out of time so short of this I'm just going to read off the slides as I go rather than setting them up tools aren't keeping up with tech and if the tools aren't keeping up we need to you need to be aware of these things looking for these things understanding strangers when you see it even if your tools do it playtime's over because uh yeah if you come across this stuff in a packet capture what are you going to do so text moving faster and fastest vendors are driving it not security companies not standards bodies user space network stacks are coming already here when malware's putting this stuff in things are going to get really messy you think polymorphic binaries are bad wait about polymorphic protocols they'll be context heavy encrypted and really heavily multiplexed communications more so than we've seen before uh yeah right let's just shift shift to questions then um cool yeah I'm pretty sure we're out of time so like I will stand there and answer questions yeah bye