1 00:00:00,000 --> 00:00:10,380 We're going to get started this morning with what looks to be a very exciting talk with a couple of recorded demos, because these guys are smart and they don't do live demos at DEF CON. 2 00:00:10,440 --> 00:00:16,080 Well, you're allowed, but it's just a really, really terrible idea. 3 00:00:17,040 --> 00:00:29,060 So if this is your first time in track four, which we are calling fancy track, here in fancy track, you cannot vape, you cannot smoke anything of any kind. 4 00:00:29,520 --> 00:00:33,380 You are not supposed to be having any kind of outside beverages other than water. 5 00:00:33,740 --> 00:00:34,700 There you go. 6 00:00:35,180 --> 00:00:44,240 Like I said, if you want to kind of move towards the center so that people can get in and out, that will help because we're going to have a lot of people coming to a lot of really good talks today. 7 00:00:44,580 --> 00:00:48,680 With that said, let's get Topher and Michael up here. 8 00:00:48,700 --> 00:00:50,800 How many people use antivirus at work? 9 00:00:51,260 --> 00:00:53,080 How many people believe it does anything? 10 00:00:53,380 --> 00:00:54,720 There we go. 11 00:00:54,720 --> 00:00:56,520 How many people use EDR at work? 12 00:00:56,980 --> 00:00:57,240 Yeah? 13 00:00:57,240 --> 00:00:59,520 How many people believe it does something? 14 00:01:00,220 --> 00:01:01,260 Aha! 15 00:01:02,940 --> 00:01:04,020 Suckers! 16 00:01:05,040 --> 00:01:08,040 Let's give Michael and Topher a big round of applause. 17 00:01:10,420 --> 00:01:21,310 Thank you for coming on an early Saturday morning. 18 00:01:21,750 --> 00:01:23,910 EDR is coming, hide your shit. 19 00:01:24,510 --> 00:01:27,170 I'm really happy to be here this year. 20 00:01:27,170 --> 00:01:32,510 This sort of came about as a hallway conversation at DEF CON last year. 21 00:01:32,510 --> 00:01:37,810 We had some ideas, we talked it over, it turned into some research and here we are. 22 00:01:37,810 --> 00:01:39,670 And that's pretty exciting. 23 00:01:39,670 --> 00:01:45,170 So go out there and talk to all the people and have all the ideas and submit something next year. 24 00:01:46,470 --> 00:01:49,790 Alright, so who are we? 25 00:01:49,790 --> 00:01:52,410 Well, first of all, we don't speak for our employer. 26 00:01:52,410 --> 00:02:00,510 These are speaking all on behalf of ourselves and nothing that we are saying is to be construed as, you know, from our employer. 27 00:02:01,330 --> 00:02:02,710 I'm Michael Liebowitz. 28 00:02:02,710 --> 00:02:12,570 I like to, in my free time, write or make hardware implants, re-implementing NSA hardware implants and I'm a principal troublemaker. 29 00:02:13,390 --> 00:02:14,050 Anne? 30 00:02:14,510 --> 00:02:16,290 And I'm Topher Timson. 31 00:02:16,290 --> 00:02:18,330 I like doing like C sharp malware stuff. 32 00:02:18,330 --> 00:02:24,090 So hilariously enough, some of the things you are going to see in this talk, I've talked about previously at DEF CON 23. 33 00:02:24,090 --> 00:02:25,930 So it's kind of like the old is still new. 34 00:02:26,070 --> 00:02:28,070 I'm a principal vulnerability enthusiast. 35 00:02:28,070 --> 00:02:34,050 We both work on red teams and as you can see by our matching attire, we just want to drink coffee and write malware. 36 00:02:36,730 --> 00:02:42,850 Alright, so here's what we're going to go through and we have a lot to cover. 37 00:02:42,850 --> 00:02:44,830 So we're going to go through it pretty fast. 38 00:02:44,830 --> 00:02:47,530 Basically, what EDR is, why we care. 39 00:02:48,830 --> 00:02:57,950 UEFI and the thing to note about UEFI is UEFI is cross-platform which is why we're doing a Windows and a Linux demo and why we have a Windows and Linux payload. 40 00:02:58,230 --> 00:03:01,470 Of course, you know, what everyone's wondering, what does this all mean ? 41 00:03:01,710 --> 00:03:05,570 And then, you know, some mitigation or whatever and then future work and then conclusions . 42 00:03:08,430 --> 00:03:11,050 So we're going to kind of start off with talking about EDR. 43 00:03:11,050 --> 00:03:13,990 So a lot of you raised your hands that you use this and think it works. 44 00:03:13,990 --> 00:03:16,190 So we're about to, you know, kind of ruin that for you. 45 00:03:17,210 --> 00:03:22,230 So kind of a, so it's 10 o'clock, the slides are a little bit hung over. 46 00:03:22,230 --> 00:03:25,570 So EDR is end point detection and response, not enterprise. 47 00:03:25,570 --> 00:03:27,730 Thanks slides for being up early with us. 48 00:03:28,150 --> 00:03:37,470 The biggest thing about EDR is that it's really just defensive tooling that focuses on like detecting, investigating and mitigating suspicious activities going on within an environment. 49 00:03:37,770 --> 00:03:41,790 The big thing that it really provides blue teams is a hunt capability. 50 00:03:41,790 --> 00:03:49,610 So this is how and a lot of organizations, they're making like large scale like correlations for hunt stages. 51 00:03:49,610 --> 00:03:52,730 So like, oh, this machine over here is doing these sorts of things. 52 00:03:52,730 --> 00:03:53,790 That's not really typical. 53 00:03:53,790 --> 00:03:55,310 This alert fired on our scene. 54 00:03:55,310 --> 00:03:56,550 Let's go investigate. 55 00:03:57,090 --> 00:04:03,610 Typically, it really just means that like for us on red teams that blue team is going to find you and we don't want to be found. 56 00:04:03,790 --> 00:04:07,050 Uh, so we're going to sort of look at how we avoid that. 57 00:04:07,490 --> 00:04:14,670 Um, and then like the one big thing with EDR is that typically everything is mapped to uh, like MITRE attack. 58 00:04:14,670 --> 00:04:23,690 And if you're not familiar with MITRE attack, that's essentially just like this huge knowledge, knowledge base of uh, of things that attackers tend to do based off of real world observation. 59 00:04:23,850 --> 00:04:27,190 So like you probably hear the term like TTPs thrown around everywhere. 60 00:04:27,510 --> 00:04:32,790 Um, in essence, it's really just this huge table that lists things that attackers like to do. 61 00:04:32,870 --> 00:04:40,830 So you kind of like think back to previous life when you were in kindergarten and you get like a gold star for like turning in your homework on time and like being polite. 62 00:04:40,950 --> 00:04:43,590 It's essentially like that but for like us as bad guys. 63 00:04:43,590 --> 00:04:45,830 So we get gold stars when we do like persistence. 64 00:04:45,830 --> 00:04:47,970 We get a gold star for privilege escalation. 65 00:04:48,290 --> 00:04:52,950 Uh, so like we want to fill out all the things but not have anybody know so we don't actually get the gold stars. 66 00:04:52,950 --> 00:04:54,350 Uh, we just want to do it. 67 00:04:56,030 --> 00:05:03,250 Um, so like I'm saying like EDR is really just tuned like in actuality for like processes, commands and API calls. 68 00:05:03,250 --> 00:05:10,290 So if you're like running say like uh, CMD.XE or PowerShell or doing like some registry stuff or trying to set up persistence. 69 00:05:10,350 --> 00:05:19,330 Because those are like TTPs in the MITRE attack framework, those tend to be flagged and mapped and then alerted on for the, the blue team. 70 00:05:19,330 --> 00:05:22,350 Um, and we want to make sure that none of that actually happens. 71 00:05:24,670 --> 00:05:33,150 So, uh, a lot of people talk about, you know, the risk curve and um, you know, this is the other side of the risk curve. 72 00:05:33,190 --> 00:05:37,370 Basically, you know, no, no attack, no breach lasts forever, right? 73 00:05:37,370 --> 00:05:41,230 You can see from the right side of the graph that eventually you're going to get busted. 74 00:05:41,670 --> 00:05:46,090 And you, you land your shell, you know, that's kind of the highest risk time. 75 00:05:46,090 --> 00:05:49,510 You move around a little bit and eventually you sort of settle into persistence. 76 00:05:49,890 --> 00:05:53,910 And like the longer you hold on, the more chance it is that someone's going to roll you up. 77 00:05:53,970 --> 00:06:00,750 And really what we want to do is, you know, make this curve flatten a little bit. 78 00:06:01,850 --> 00:06:05,670 And, you know, what, what does it mean when, you know, the breach gets detected? 79 00:06:05,670 --> 00:06:07,550 Like no one's sleeping well tonight. 80 00:06:07,550 --> 00:06:09,090 This is, this is terrible. 81 00:06:09,730 --> 00:06:14,110 You know, your lovingly crafted payload becomes the analyst's sample. 82 00:06:14,110 --> 00:06:21,370 You're like very upset because all these months of work and crafting that super awesome payload are just down the drain. 83 00:06:21,370 --> 00:06:25,130 And the analyst is like, oh shit, there goes my Friday night. 84 00:06:26,670 --> 00:06:27,790 Nobody's happy. 85 00:06:28,910 --> 00:06:33,810 So what we want to do is we want to modify this risk curve. 86 00:06:33,810 --> 00:06:41,730 We want to make it such that, you know, we're not going to flatten that initial shell pop kind of, kind of part, like that's kind of the same. 87 00:06:41,730 --> 00:06:45,570 But we just want to, we just want to hang on to the good stuff for longer. 88 00:06:45,570 --> 00:06:47,650 Eventually, eventually you're going to get rolled up. 89 00:06:47,650 --> 00:06:51,610 But we just, just hang out and chill out for a little bit longer. 90 00:06:54,070 --> 00:07:06,890 So as we were investigating ways that we can hide from a UEF or from a EDR, Mike and I had some pre-existing platform experience, a particular UEFI platform experience, so like platform firmware. 91 00:07:07,190 --> 00:07:18,830 So in sort of this research, it's like, we were thinking that we can utilize this sort of functionality to evade all of these detections and make that risk curve and the dwell time for us last a little bit longer. 92 00:07:19,270 --> 00:07:28,690 So if you're not familiar with UEFI, I have to include this awesome diagram of it because John Lucchetti has told everybody ever talking about UEFI that they have to. 93 00:07:29,310 --> 00:07:34,430 Essentially, if you're not familiar with UEFI, it's essentially what modern BIOS is now. 94 00:07:34,430 --> 00:07:43,430 So it does all of the things that you don't really care about, like CPU in it, trains your memory, it loads a bunch of option ROMs from like your PCI devices. 95 00:07:44,130 --> 00:07:47,310 There's other talks that go over what this actually means. 96 00:07:47,310 --> 00:07:57,410 Uh, but what we're concerned about is if you look at the bottom, there's this notion of runtime services and after the OS boots, those are exposed at the operating system level. 97 00:07:57,450 --> 00:08:04,150 Some of the things that get exposed within the runtime services stage of UEFI are, uh, UEFI firmware variables. 98 00:08:04,150 --> 00:08:17,610 So these are persistent variables that actually live within your NVRAM on your, on, on your platform, uh, that are accessible both to UEFI applications, like, if you're familiar with secure boot, all of your secure boot like variables and stuff live there. 99 00:08:17,610 --> 00:08:24,410 So like boot order, like your, uh, the keys that secure boot utilizes, things of that, uh, nature. 100 00:08:24,510 --> 00:08:32,350 So we're going to take advantage of the fact that we can persist within NVRAM, within the UEFI platform that we can then access at operating system runtime. 101 00:08:32,830 --> 00:08:38,610 Um, so, sort of like, you're probably thinking at this point, well, why UEFI firmware variables? 102 00:08:38,890 --> 00:08:46,430 Well, like I was saying, it, it's a way that you can hide your payloads from all of these detective capabilities because it's, it's a blind spot for all of them. 103 00:08:46,430 --> 00:08:51,470 Nobody looks here, like really at all, especially within AV and EDR platforms. 104 00:08:51,730 --> 00:08:59,730 Um, if you're not familiar really with what UEFI firmware variables are either, it essentially consists of like a name and a GWID, so it's like this tuple. 105 00:08:59,730 --> 00:09:06,430 And if you are able to set or get that, uh, that tuple, you can pull the contents of what that variable is out of NVRAM. 106 00:09:06,430 --> 00:09:15,330 And we're going to kind of showcase that we can execute those live on the system to both stash our stuff and to sort of have like this persistence, uh, mechanism. 107 00:09:17,570 --> 00:09:22,790 So, really quickly, uh, like UEFI firmware variables have a couple of types. 108 00:09:22,790 --> 00:09:25,130 There's authenticated and unauthenticated. 109 00:09:25,210 --> 00:09:32,770 This isn't so much important, but we kind of just wanted to briefly touch on it, uh, just in case you're concerned at all with the specification or what we're doing. 110 00:09:32,770 --> 00:09:40,090 Like, um, if you've heard of like authenticated variables, these are signed like X509 certs that, uh, perform like a certificate check when writing. 111 00:09:40,210 --> 00:09:41,870 Uh, we're not going to worry about those. 112 00:09:41,870 --> 00:09:47,110 There are unauthenticated variables that are also, um, present, uh, at that runtime stage. 113 00:09:47,110 --> 00:09:49,230 These have no verification on write. 114 00:09:49,230 --> 00:09:53,750 The majority of variables on a platform, as we'll show you in a demo, are unauthenticated. 115 00:09:53,750 --> 00:10:00,330 Uh, so it's not really abnormal for these to be there and it's not atypical for things to necessarily be writing or reading from there. 116 00:10:00,370 --> 00:10:04,050 Um, if you're like a platform researcher or something, you know about this. 117 00:10:04,910 --> 00:10:09,950 Uh, there's a couple of attributes as well to UEFI firmware variables, uh, within the specification. 118 00:10:10,170 --> 00:10:27,150 We're going to really just focus on 3 out of the 6 because as I'll showcase in the Windows 10 API, uh, you have to have non-volatile boot service access and runtime access in order to have, uh, UEFI variables that persist within the Windows runtime after boot on your NVRAM. 119 00:10:27,170 --> 00:10:31,910 Um, so just note that those 3 are going to be utilized and that'll be shown in the demo as well. 120 00:10:32,070 --> 00:10:49,650 Sort of the hilarious little thing here too with, uh, why we sort of started thinking about UEFI as a way to hide from EDR is, uh, in an old, old life, we're walking, you know, with some blue team, uh, folks and we're talking about ways that we've been being tricky on engagements and sharing some techniques. 121 00:10:50,570 --> 00:10:55,990 And we're kind of talking about, like, uh, IOT devices and how it'd be cool to hide, like, an IOT firmware. 122 00:10:55,990 --> 00:10:59,990 And they're like, yeah, that'd be cool, but, like, please don't ever hide, like, in platform firmware. 123 00:10:59,990 --> 00:11:02,930 And, you know, Mike and I kind of stopped and we're like, oh, shit. 124 00:11:06,190 --> 00:11:08,790 Uh, so we're going to do Windows and Linux, uh, and we're going to do, uh, Windows and Linux. 125 00:11:08,790 --> 00:11:12,730 Like Mike said, uh, UEFI is platform agnostic, so it doesn't matter what it's running on. 126 00:11:12,730 --> 00:11:14,090 It's, it's part of your platform. 127 00:11:14,090 --> 00:11:16,550 It helps boot Intel, like, processors. 128 00:11:16,550 --> 00:11:18,550 It also works, like, on AMD. 129 00:11:18,630 --> 00:11:19,770 Uh, it's kind of different there. 130 00:11:19,770 --> 00:11:22,290 It's, it's a specification , whatever. 131 00:11:22,610 --> 00:11:39,890 Um, so UEFI and Windows, basically, um, I was re-looking at the MSDN articles for Windows 10 and I recognized, so they had taken this off and then they re-introduced the ability to do UEFI platform stuff within 1803. 132 00:11:40,430 --> 00:11:43,470 Um, so I was kind of, like, reading the documents. 133 00:11:43,470 --> 00:11:50,790 They, they listed all of these requirements for actually being able to use this, these API function, this API functionality within Windows now. 134 00:11:50,830 --> 00:11:55,610 So it was kind of concerning because there, there's a lot there that they say you need this, otherwise it won't work. 135 00:11:55,610 --> 00:11:59,570 Such as, you need to declare firmware read and write in your application manifest. 136 00:11:59,770 --> 00:12:04,230 You need to have it be a protected app, so, like, a signed app that the Microsoft store signs. 137 00:12:04,230 --> 00:12:05,330 Needs to be signed. 138 00:12:05,330 --> 00:12:13,350 You need to be an admin that has access to this special privilege SE system environment name, uh, like privilege token in your process space. 139 00:12:13,490 --> 00:12:21,370 So looking at it, it was kind of daunting because it's, it's such a long list of requirements, but, you know, we're hackers, that doesn't mean anything. 140 00:12:21,710 --> 00:12:36,210 Uh, so we started looking at ways to bypass this, like Specter Ops puts out a lot of, like, WDAC bypasses, which is a way to execute signed Windows binaries with that, well, unsigned Windows binaries, so, like, unsigned Windows binaries you can still execute. 141 00:12:36,270 --> 00:12:53,850 Um, obviously on red teams we sometimes jump to conclusions or we make, uh, some leaps forward to speed up engagement time with, like, assume breach type, um, scenarios or sort of the methodology and thinking that we're gonna wind up being admin, why don't we just become admin now. 142 00:12:53,950 --> 00:13:07,130 Um, so, like, that sort of stuff for our purposes of doing this sort of thing on red team engagements wasn't necessarily impactful, so we just kind of went with it with the assumption that we're gonna be, we can be an admin on a box and we're not gonna need it to be a signed, 143 00:13:07,130 --> 00:13:08,470 uh, Windows application. 144 00:13:09,890 --> 00:13:25,650 So, like, uh, just to showcase what the read and white firmware variable API looks like from the MSDN articles, you can do set and get firmware variables from NVRAM, uh, really the key thing here is you just have, like, the name and GWT tuple that I was mentioning earlier, 145 00:13:25,650 --> 00:13:37,030 um, and for set, all you do is you point, uh, the buffer you want to write into the variable, you give it the size and the attributes that you want to have it be declared as, and it just sets it in NVRAM for you. 146 00:13:37,030 --> 00:13:52,310 And then for get, it's the same sort of idea, you give it a name and a GWT tuple and then you give it the buffer you want to read into and then it reads the NVRAM out into some memory buffer that you control as the attacker and, of course, you'll wind up executing that once you get the variable out of NVRAM. 147 00:13:53,190 --> 00:14:07,510 Uh, these are the attributes, not really important, it's on the slide more for reference, but this is from the MSDN article, note that for variable, uh, attribute runtime services, it says if you want this to be accessible during RT, it needs to also be accessible to boot services, 148 00:14:07,510 --> 00:14:12,650 so that's kind of why we're going to have to set all three in Windows, so NVBS and RT variables. 149 00:14:14,170 --> 00:14:30,430 So when I was initially implementing this, uh, it was sort of the decision between if I wanted it to be in C++ or in C sharp, so I initially implemented all of this in C++ just because it was, it was easy, because the MSDN articles basically just give you the code you need, 150 00:14:30,430 --> 00:14:45,330 but as I was kind of doing the research, it occurred to me that C++ wasn't a viable option because AV flags it very easily, um, like one thing that you have to do obviously if we're getting a firmware variable is you need RWX memory, so doing a lot of calls to like virtual alloc, 151 00:14:45,330 --> 00:14:58,710 virtual protect, uh, it's kind of a red flag right now, especially for EDR products as they start querying all these APIs, um, like most applications aren't like making an RWX memory buffer and then executing it like it was shellcode, so we're not going to do that. 152 00:14:59,130 --> 00:15:08,510 Um, C sharp can basically do everything C++ can either with P invoke or reflection, and having C sharp malware experience in the past was like, yeah, let's just do it in C sharp. 153 00:15:08,670 --> 00:15:16,850 Furthermore, most of the C sharp bypasses, or some of the, most of the WDAC bypasses are in C sharp anyway, so that kind of like checked that flag off for us. 154 00:15:17,030 --> 00:15:31,210 And then in order to make things kind of easier for all of our red team friends to use, particularly on Windows environments, we wanted to make sure that they could, that they could use it in C sharp as like kind of the direction that, uh, malware authors in Windows are kind of going for red team engagements these days, 155 00:15:31,210 --> 00:15:32,390 or, or going. 156 00:15:33,190 --> 00:15:37,150 Um, but there's reference code for both on the repo which we'll showcase later after the talk. 157 00:15:38,030 --> 00:15:44,370 So essentially the steps for writing a UEFI variable in Windows is really easy once you have that admin privilege. 158 00:15:44,370 --> 00:15:48,490 Uh, you essentially just need to obtain the SE system environment name with set priv. 159 00:15:48,610 --> 00:15:51,950 Uh, this is the only case of like P invoke that we're going to be using. 160 00:15:52,070 --> 00:16:01,530 Um, furthermore, like I was saying, like in the manifest where you needed read and write capabilities, the MSDN article is weird in that it lists all of those things for C plus plus applications. 161 00:16:01,530 --> 00:16:10,390 It makes no notion of ever doing this stuff in C sharp, so I've never had to declare those things and I don't really know what Microsoft is stating in that, so just ignore that completely. 162 00:16:10,390 --> 00:16:11,910 You don't need it for C sharp. 163 00:16:12,390 --> 00:16:19,850 Uh, you can then get the address of your pin buffer, so that's our payload, and then we just write the UEFI variable to NVRAM and now it's persistent storage. 164 00:16:21,110 --> 00:16:24,210 So here's some code really quickly to set the privilege. 165 00:16:24,410 --> 00:16:31,670 Um, it's just P invokes, you get process, you say that you want the new, the new token privilege, you set it, boom, we're good. 166 00:16:31,910 --> 00:16:36,750 Then you can get the address of your, uh, pin buffer in C sharp, like I said, this was your payload. 167 00:16:36,790 --> 00:16:44,970 So you initialize an end pointer, you call, uh, interop services to get a pinned array of your, of your buffer that you want to write. 168 00:16:45,190 --> 00:16:50,070 You pin it so the garbage collector and nothing can, can touch it as you're working with it. 169 00:16:50,070 --> 00:16:58,150 And then you just simply write that UEFI variable with the set firmware variable call with, uh, the tuple, and in this case it's going to be C sharp UEFI. 170 00:16:58,190 --> 00:17:08,590 And then I have a super secret, uh, super secret GWT, uh, super secret GWT, say that five times fast, um, that you can Google and figure out what it is. 171 00:17:09,550 --> 00:17:13,030 Uh, so the steps for executing UEFI variable are pretty much similar. 172 00:17:13,030 --> 00:17:14,430 You still need that token. 173 00:17:14,550 --> 00:17:21,430 And the first thing I did in C sharp was I did P invoke with virtual alloc to obtain an RWX memory pointer that I can execute. 174 00:17:21,430 --> 00:17:26,030 And then I was just obtaining that UEFI variable back into that buffer so I can execute it. 175 00:17:26,250 --> 00:17:29,670 Uh, so the first step, same idea, you need that privilege. 176 00:17:30,190 --> 00:17:34,310 The second step is I start P invoking some memory so I have RWX. 177 00:17:34,970 --> 00:17:43,970 Uh, but you can't actually really do that in C sharp because it's abnormal to bring things into your import address table that aren't actually C sharp specific. 178 00:17:44,370 --> 00:17:49,230 Um, so like all of the virtual calls are more suspicious than getting a new process token. 179 00:17:49,290 --> 00:17:52,850 Cause, uh , within like C sharp there's no real way to do like process token stuff. 180 00:17:52,850 --> 00:17:55,990 You have to pretty much P invoke so it's not suspicious. 181 00:17:56,350 --> 00:18:03,310 It is suspicious for EDR products that you're doing virtual alloc, virtual free and virtual protect within C sharp. 182 00:18:03,310 --> 00:18:05,210 It's like, whoa, stop right there. 183 00:18:05,210 --> 00:18:07,970 We're going to tell the blue team about this and they're going to hunt you down. 184 00:18:08,050 --> 00:18:10,090 So we can't do that. 185 00:18:10,750 --> 00:18:23,550 Hilariously enough as we were going through this research, um, OJ is working on like a, a C sharp C alarm interpreter and he was dealing with some stuff and he also says the same thing like don't P invoke your dot net apps. 186 00:18:23,550 --> 00:18:25,250 Like EDR is going to find you. 187 00:18:25,250 --> 00:18:28,710 Like as he says, it's the proverbial solution for them hunting you down. 188 00:18:29,050 --> 00:18:34,510 Uh, so we're, we're not going to have, we're going to lose the ability to P invoke to get RWX memory. 189 00:18:34,630 --> 00:18:36,610 Uh, which is kind of a problem. 190 00:18:37,610 --> 00:18:44,170 So we can't do step 2 anymore, but fear not, uh, the CLR and C sharp is fantastic for malware. 191 00:18:44,170 --> 00:18:59,910 So we're going to actually just now instead of doing any virtual calls, we're going to use reflection within C sharp to obtain RWX JIT memory, which just in time compilation leaves RWX memory pages if you're not familiar with it, to read the UEFI variable into that. 192 00:18:59,910 --> 00:19:07,570 Then we're going to write the UEFI variable into a method table pointer and then we're going to execute the method as if nothing actually ever happened. 193 00:19:08,290 --> 00:19:10,090 Uh, so those are the steps. 194 00:19:10,090 --> 00:19:13,410 I'm going to actually go through that in detail because that was probably a little bit jarring. 195 00:19:13,970 --> 00:19:28,330 Basically, in C sharp, if you're not familiar with it, because it's an intermediate level, uh, language representation of code, it has to get just in time compiled to assembly code before it gets executed by the processor. 196 00:19:28,470 --> 00:19:38,430 So within C sharp there's this huge method table that contains all of the methods that the C sharp application knows about and all of those contain a JIT stub for those classes methods. 197 00:19:38,650 --> 00:19:52,850 So essentially what that means is at the time of just in time compilation, the method table gets referenced, you then get a function pointer to the executable assembly code that the processor will run, which is RWX due to the notion of JIT. 198 00:19:52,930 --> 00:20:02,470 You can grab that method pointer, dereference the function pointer that the assembly code lives to, which is, uh, just the location of the method that you're clobbering and overwrite it. 199 00:20:02,470 --> 00:20:10,630 So this essentially means we can declare a method that we don't care about, force it to just in time compile, get the pointer to it and then overwrite it. 200 00:20:11,110 --> 00:20:16,250 Uh, so it's basically like red tulip C but in C sharp and it's like more fucky. 201 00:20:18,530 --> 00:20:20,250 So the steps for that look like this. 202 00:20:20,250 --> 00:20:24,810 We're essentially going to now obtain an RWX JIT memory page to read the variable into. 203 00:20:24,810 --> 00:20:33,890 That's going to consist of defining a method, uh, to overwrite, JITing the method, obtaining the pointer to the method and then overwriting it and calling it. 204 00:20:34,230 --> 00:20:36,050 So we'll define a method to overwrite. 205 00:20:36,050 --> 00:20:38,430 This is in the code that I'm going to be releasing. 206 00:20:38,430 --> 00:20:39,910 It's just called overwrite me. 207 00:20:39,910 --> 00:20:41,050 It does nothing. 208 00:20:41,950 --> 00:20:43,470 We'll JIT the method. 209 00:20:43,490 --> 00:20:47,710 So here you can see in reflection I'm doing a type of the program I'm in. 210 00:20:47,710 --> 00:20:49,310 Get method overwrite me. 211 00:20:49,370 --> 00:20:55,310 I call compile service run time helpers prepare method which is essentially just going to JIT that with the method handle. 212 00:20:55,310 --> 00:20:56,890 So I have my method dot method handle. 213 00:20:56,890 --> 00:20:58,790 That's dereferencing one of the pointers. 214 00:20:59,030 --> 00:21:03,430 And then I obtain the pointer to the method which is just get function pointer once I've JITed it. 215 00:21:03,430 --> 00:21:09,270 So now I have the location of the raw assembly code after JIT and that RWX memory location. 216 00:21:10,110 --> 00:21:16,530 So now I write the UEFI variable payload that's stored in NVRAM into the pointer to method. 217 00:21:16,530 --> 00:21:18,850 So I just call get firmware variable EX. 218 00:21:19,090 --> 00:21:25,350 Uh, you can see the third argument there after the tuple is pointer to method with then the fourth argument being buffer length. 219 00:21:25,350 --> 00:21:33,790 That's going to take the NVRAM out, plop it in and then I can just execute the method called overwrite me as if it was actual C sharp code and I hadn't done anything malice. 220 00:21:34,770 --> 00:21:40,090 So we're going to do a quick demo of what that looks like to kind of tie it all together in Windows. 221 00:21:40,390 --> 00:21:43,910 Um, step one, you obtain your, you obtain your shell on target. 222 00:21:43,910 --> 00:21:46,490 Uh, we've already done that so step one's kind of skipped. 223 00:21:46,570 --> 00:21:49,390 We're then going to run write UEFI C sharp. 224 00:21:49,390 --> 00:21:52,450 You'll see this with a, with a writer binary that I've written. 225 00:21:52,510 --> 00:21:57,990 Uh, in an actual like red team engagement or in a campaign you'd probably do this with like whatever C2 framework you were using. 226 00:21:57,990 --> 00:22:03,050 So you can use the C sharp code say like in cobalt strike with some of the functionality there and do it on Windows boxes. 227 00:22:03,250 --> 00:22:10,970 Um, you'll then do some sort of persistence mechanism for the reader binary which is going to go through and do the steps I just demonstrated with reflection. 228 00:22:11,230 --> 00:22:14,390 Um, it's like a 4 kilobyte binary you'll use for persistence. 229 00:22:14,390 --> 00:22:16,770 You can, you know, we're not giving you a persistent mechanism. 230 00:22:16,770 --> 00:22:18,590 I'm sure all of you have lots in your bag. 231 00:22:18,610 --> 00:22:21,910 Uh, you just need to throw this binary somewhere and, and run it. 232 00:22:22,190 --> 00:22:25,270 And then we'll uh, we'll run it to showcase what it looks like. 233 00:22:25,690 --> 00:22:33,550 So, the Windows demo is this one. 234 00:22:34,210 --> 00:22:35,570 Computers are hard. 235 00:22:35,850 --> 00:22:38,050 So here I am on Windows. 236 00:22:38,130 --> 00:22:42,310 Um, I'm going to first go through and run a really quick chipsec module. 237 00:22:42,310 --> 00:22:49,530 Uh, if you're not familiar with chipsec, it's a UEFI platform security tool that helps security researchers analyze platform firmware. 238 00:22:49,590 --> 00:22:53,450 Uh, it does a lot of cool things for UEFI, particularly variables. 239 00:22:53,450 --> 00:22:59,330 So what I did here is I just ran a module to dump and list what all the UEFI variables currently on my system are. 240 00:22:59,330 --> 00:23:01,070 You can see that there's a lot of them. 241 00:23:01,070 --> 00:23:04,270 Do note that most of these are NVBS plus RT. 242 00:23:04,530 --> 00:23:09,030 Uh, so most of them are accessible, uh, at run time services to the operating system. 243 00:23:09,030 --> 00:23:12,890 And they're, of course, because they're persistent, they're persistent in NVRAM. 244 00:23:13,970 --> 00:23:14,970 So there they are. 245 00:23:14,970 --> 00:23:16,190 You didn't see mine. 246 00:23:16,210 --> 00:23:21,490 Here I'm going to dump really quickly the variable list to show you that there's contents of all of these variables. 247 00:23:21,490 --> 00:23:24,830 Like this one is kind of funny, like test zero, this is a test. 248 00:23:25,670 --> 00:23:27,850 Um, so there's lots of variables here. 249 00:23:27,870 --> 00:23:29,550 Nobody really ever audits them. 250 00:23:29,550 --> 00:23:31,790 Like I said, AV and EDR doesn't look here. 251 00:23:31,930 --> 00:23:36,350 So now what I'm going to do is I'm going to run write UEFI or UEFI write C sharp. 252 00:23:36,350 --> 00:23:39,070 That's going to write a UEFI variable to NVRAM. 253 00:23:39,130 --> 00:23:41,790 I ran chipsec again to show you that it's now there. 254 00:23:41,830 --> 00:23:42,550 There it is. 255 00:23:42,550 --> 00:23:44,490 Uh, C sharp dash UEFI. 256 00:23:46,550 --> 00:23:50,790 So now that that's there on box, I can execute what the payload is. 257 00:23:50,990 --> 00:23:55,970 Um, but first I'm going to show you what that, uh, there's actual like, uh, shellcode there. 258 00:23:55,970 --> 00:23:59,090 So I'll go into the UEFI variables directory with chipsec. 259 00:23:59,090 --> 00:24:00,130 I'll dump it out. 260 00:24:00,130 --> 00:24:06,450 And there you can see that I have some shellcode there that I'm going to execute out of NVRAM with a, with a, the, the reader binary. 261 00:24:06,610 --> 00:24:11,510 Uh, that payload for demo purposes is going to be our, our favorite demo, uh, Metasploit. 262 00:24:11,570 --> 00:24:14,230 So it's just a meterpreter shell that I'm going to spin up. 263 00:24:14,230 --> 00:24:17,070 I'm going to go through, run UEFI read C sharp. 264 00:24:17,210 --> 00:24:24,930 And then as you can see from that, uh, I successfully just executed a payload out of NVRAM with like a four kilobyte binary using reflection. 265 00:24:28,310 --> 00:24:29,350 Thank you. 266 00:24:30,650 --> 00:24:32,550 So the fun doesn't actually end there. 267 00:24:32,550 --> 00:24:39,250 So because this is a persistence mechanism and it's persistent, uh, in NVRAM, this means it's going to survive reboots. 268 00:24:39,250 --> 00:24:42,270 It's going to survive reinstalling your operating system. 269 00:24:42,270 --> 00:24:52,490 The only way to clear this out is to like clobber over that variable or, uh, pull NVRAM with like a deady prog and re, uh, like rewrite your UEFI, um, variable space. 270 00:24:52,610 --> 00:24:59,350 So I'm going to shut down the box, reboot it, go back to my Metasploit shell, uh, rerun the console. 271 00:24:59,710 --> 00:25:01,070 And then it's a cooking show. 272 00:25:01,070 --> 00:25:02,810 It takes a long time for Windows to boot. 273 00:25:02,810 --> 00:25:03,990 So speed it up. 274 00:25:03,990 --> 00:25:06,010 Uh, you know, I just put the payload in the oven. 275 00:25:06,130 --> 00:25:07,770 It's going to be done pretty quickly. 276 00:25:07,890 --> 00:25:09,310 The machine's booting. 277 00:25:11,590 --> 00:25:12,810 Still booting. 278 00:25:12,810 --> 00:25:13,850 It's a cooking show. 279 00:25:13,850 --> 00:25:14,710 Wait a minute. 280 00:25:15,210 --> 00:25:16,290 There it is. 281 00:25:16,310 --> 00:25:17,250 Let's see. 282 00:25:17,290 --> 00:25:17,950 And there we go. 283 00:25:17,950 --> 00:25:23,910 I just executed my payload out of NVRAM again, uh, with a persistence mechanism out of a UEFI variable. 284 00:25:27,800 --> 00:25:29,140 Yay, cookies. 285 00:25:29,880 --> 00:25:30,840 And shells. 286 00:25:30,840 --> 00:25:32,300 It, uh, it baked some shells. 287 00:25:32,300 --> 00:25:32,880 Awesome. 288 00:25:34,060 --> 00:25:36,840 Um, so we kind of like have hand-waved the persistence thing. 289 00:25:36,840 --> 00:25:38,940 We're going to leave that as an exercise up to the reader. 290 00:25:38,940 --> 00:25:41,940 Like I said, WDAC bypasses are a great way to do this. 291 00:25:42,000 --> 00:25:45,080 Uh, in actuality, uh, your payload's a UEFI variable. 292 00:25:45,080 --> 00:25:46,180 Like, good luck, have fun. 293 00:25:46,500 --> 00:25:48,060 Analysts, uh, we love you still though. 294 00:25:48,060 --> 00:25:50,120 Like, we're going to help you, but this is fun. 295 00:25:51,040 --> 00:25:53,240 Um, so like what about Windows EDR products? 296 00:25:53,240 --> 00:25:54,620 We haven't necessarily touched on that. 297 00:25:54,620 --> 00:25:57,620 Like, obviously this is a way to, to mitigate detection. 298 00:25:57,680 --> 00:26:09,080 Um, so we looked at a couple of, uh, EDR vendors and we found no relevant information pertaining to the usage of either these API calls, executing out of UEFI variable or anything of that nature. 299 00:26:09,160 --> 00:26:12,820 The only thing they're really going to see is that you're executing this binary. 300 00:26:12,980 --> 00:26:15,920 Uh, but like there's binaries executed on systems all the time. 301 00:26:15,920 --> 00:26:19,920 That's not really something too relevant, too relevant that's going to trigger hunt. 302 00:26:20,940 --> 00:26:27,260 Um, furthermore, uh, there's a lot of ways currently to sinkhole or to tamper with EDR products. 303 00:26:27,260 --> 00:26:31,600 So here's like a five line PowerShell script that you can use to like sinkhole EDR products. 304 00:26:31,600 --> 00:26:33,300 This works on a lot of them. 305 00:26:33,300 --> 00:26:37,420 Uh, like EDR products are things of software running on a box. 306 00:26:37,420 --> 00:26:39,500 Software have configs. 307 00:26:39,500 --> 00:26:40,980 Configs can be tampered with. 308 00:26:40,980 --> 00:26:45,120 So just tamper with configs a lot of the times and you can get away with anything on a box on Windows. 309 00:26:45,400 --> 00:26:47,500 Um, there's a lot of other ways to go about it. 310 00:26:47,500 --> 00:26:49,480 We can chat like after the talk about it. 311 00:26:49,480 --> 00:26:50,980 Uh, this isn't really a talk about this. 312 00:26:50,980 --> 00:26:54,280 So it's a talk about hiding your shit and that's how you hide your shit in Windows. 313 00:26:54,920 --> 00:26:57,460 Um, some WDAC bypasses just for references. 314 00:26:57,640 --> 00:27:02,280 Uh, now that I've talked about hiding your shit in Windows, uh, Mike's going to talk about some Linux stuff. 315 00:27:03,920 --> 00:27:05,320 Boy, Windows is silly. 316 00:27:07,260 --> 00:27:08,940 Let's, let's, let's talk about Linux. 317 00:27:08,940 --> 00:27:11,860 Linux is, you know, everyone knows that's where the real loot is. 318 00:27:13,960 --> 00:27:16,740 So, let's talk about the problem space. 319 00:27:16,740 --> 00:27:19,380 Uh, basically, let's introduce our players here. 320 00:27:19,380 --> 00:27:20,900 We have, you know, the kernel. 321 00:27:21,220 --> 00:27:22,360 We have the EDR. 322 00:27:22,420 --> 00:27:24,860 And we have, on the right, we have your sample. 323 00:27:25,000 --> 00:27:29,780 And, you know, EDR is looking at your sample and that's, that's bad. 324 00:27:29,780 --> 00:27:32,340 That's what makes it your sample and not your payload. 325 00:27:32,860 --> 00:27:37,320 Um, and, you know, the EDR and your sample are actually kind of peers, right? 326 00:27:37,320 --> 00:27:45,580 We're both running as privileged processes and the EDR has some hooks into kernel space to help it do, help it do its job. 327 00:27:45,580 --> 00:27:49,840 And so that's what that sort of rectangle just above the eyeballs is. 328 00:27:50,140 --> 00:27:52,080 Eyeballs are obviously EDR. 329 00:27:53,780 --> 00:27:57,160 And so, like, what does our solution space look like? 330 00:27:57,160 --> 00:28:08,200 Well, you know, what we really want is just to make, you know, just to sucker punch the EDR a little bit, you know, while it's not looking and make sure that it just doesn't look at us at all. 331 00:28:08,200 --> 00:28:10,800 And then, then it's back to being our payload. 332 00:28:11,160 --> 00:28:14,220 So, you know, how are we going to do that? 333 00:28:14,980 --> 00:28:19,560 We, we need to, like, we need to show up early to the fight, right? 334 00:28:19,660 --> 00:28:21,800 So that it never sees us coming. 335 00:28:22,140 --> 00:28:24,020 So we need to infect something. 336 00:28:24,520 --> 00:28:28,020 So, you know, how does your computer, how does your computer boot? 337 00:28:28,280 --> 00:28:29,560 And what can we infect? 338 00:28:29,900 --> 00:28:32,580 Well, the first thing that boots is platform firmware. 339 00:28:32,760 --> 00:28:34,720 And that's signed by the OEM. 340 00:28:34,720 --> 00:28:36,580 You can't really infect that easily. 341 00:28:36,580 --> 00:28:37,140 Boo. 342 00:28:37,340 --> 00:28:43,480 The next thing, that's signed by Microsoft, the shim, that's signed by Microsoft and it pivots the key over to the distro. 343 00:28:43,980 --> 00:28:46,140 That's a little bit harder to infect. 344 00:28:46,780 --> 00:28:51,180 Uh, grub, you know, signed by the distro, no good. 345 00:28:51,180 --> 00:28:53,620 Kernel signed by the distro, no good. 346 00:28:54,040 --> 00:28:58,020 But the RAM disk is generated on system and not signed. 347 00:28:58,080 --> 00:28:59,680 This sounds like a good time. 348 00:29:00,800 --> 00:29:05,340 And then sometime later, some shit happens and the EDR is, is started. 349 00:29:05,460 --> 00:29:08,040 So obviously what we need to infect is the RAM disk. 350 00:29:08,040 --> 00:29:16,920 So how are we gonna, what capabilities do we have, what, what, what, what tools do we have at our disposal in the Linux environment to, to make things happen and, and, and make the EDR not look at us. 351 00:29:16,920 --> 00:29:23,240 So, uh, the first sort of, uh, wonderful syscall to, uh, introduce is ptrace, right? 352 00:29:23,320 --> 00:29:25,760 And this is, you know, why we say the 90s are back again. 353 00:29:25,760 --> 00:29:31,520 Like ptrace, uh, exploitation of processes has been like, uh, as, as old as time itself. 354 00:29:31,520 --> 00:29:38,860 But, you know, and, and it's, it's tapered off in the, in the modern era because we have policies that prevent you from doing it. 355 00:29:39,040 --> 00:29:44,560 We have like Yama and SE Linux and AppArmor and silly stuff like Smack and Tomoyo and whatever. 356 00:29:44,720 --> 00:29:50,020 But the best part about all this stuff is the policy is implied in, is applied in user space. 357 00:29:50,540 --> 00:29:51,500 Alrighty. 358 00:29:53,340 --> 00:30:01,020 So let's, let's, let's go through this, um, let's go through this in flow chart sort of land. 359 00:30:01,020 --> 00:30:05,800 So we have, um, the RAM disk is actually the original PID 1. 360 00:30:05,800 --> 00:30:10,500 That's actually where, uh, init starts from. 361 00:30:10,880 --> 00:30:17,980 And then it finds your file system, you know, draws some pretty stuff on screen, like make sure you have the right fonts, whatever. 362 00:30:18,480 --> 00:30:26,860 And then it does, it actually deletes everything out of the, out of the root file system except for target directory. 363 00:30:26,860 --> 00:30:31,920 And then it moves the mount from the target to root. 364 00:30:32,020 --> 00:30:34,740 And then it execs systemd. 365 00:30:35,800 --> 00:30:39,060 And that will come up again, this sort of deleting everything. 366 00:30:39,060 --> 00:30:45,460 And then like systemd starts and like, you know, the thumbs down is the policy being loaded that prevents you from attacking the EDR. 367 00:30:45,460 --> 00:30:47,460 And then of course our eyeballs here are the EDR. 368 00:30:47,740 --> 00:30:49,760 So let's, let's talk about some other things. 369 00:30:49,760 --> 00:30:50,820 We have FANotify. 370 00:30:50,840 --> 00:30:55,660 FANotify is kind of a obscure API, but like it's designed for AV. 371 00:30:55,780 --> 00:30:59,620 I don't think any AV actually uses it, but, you know, who cares? 372 00:31:00,120 --> 00:31:05,520 Exploiting, or using security APIs for unintended things is like one of my favorite things. 373 00:31:06,760 --> 00:31:13,380 So basically what this lets you do is this lets you, you know, do the AV thing, right? 374 00:31:13,380 --> 00:31:28,660 Like a file is accessed, you get to stop that process from accessing that file, decide whether it's okay, and then you can say, if it is, to go ahead, which effectively allows us to inhibit startup of other processes. 375 00:31:30,400 --> 00:31:34,120 Another fantastic utility is memfd create. 376 00:31:34,940 --> 00:31:57,660 This has been talked about a lot in, in, in the hacker scene, but essentially, like, you can create an anonymous file, and this works like a file, get a file descriptor, and then you can actually access it through, you know, PROC PID, FD, even from other processes. 377 00:31:57,660 --> 00:31:58,960 This is fantastic. 378 00:31:59,120 --> 00:32:03,840 And, you know, the best part is, like everyone says, never touch disk, kids. 379 00:32:05,220 --> 00:32:15,500 And then another API that we can use is and this is also somewhat obscure and not really security relevant, is a PRCTL, PR set timer. 380 00:32:15,500 --> 00:32:25,540 So we need some marker for our process to say to the EDR, don't look at this. 381 00:32:25,640 --> 00:32:28,460 And so we need something that's inheritable, right? 382 00:32:28,460 --> 00:32:36,160 So, you know, you can, you can have your malicious shell, you can catch shadow, and when cat does, cat also inherits the marker. 383 00:32:36,320 --> 00:32:45,800 So we do the set timer slack, this basically controls how often you wake up the CPU, it's designed to save power, but I don't care about that. 384 00:32:47,140 --> 00:33:00,560 And then lastly, like, config EFI virus, this is the kernel config to make the EFI virus file system, you saw what a pain in the ass it was to do stuff with UEFI on Windows, Windows is dumb, it's just a file system, you just read and write files, it's super easy, 385 00:33:00,560 --> 00:33:01,760 you can do it from a shell script. 386 00:33:04,280 --> 00:33:13,200 And then I talked previously about MS move, like, basically, this, if you look in the code, this is labeled as black magic fuckery. 387 00:33:14,580 --> 00:33:40,920 I can go through these steps, but it's really convoluted, but essentially, if you want to have a malicious process that survives pivoting the root file system out from under you, there's a whole lot of really weird stuff involving containers and cheroots and namespaces and weird stuff to do so that your malicious process sees the real root file system as opposed to seeing the init root file system, 388 00:33:40,920 --> 00:33:42,400 which has nothing in it. 389 00:33:43,380 --> 00:33:56,900 Funny story, like, even though you can never have two root file systems in Linux, if you don't do this, you have two root file systems in that process, and the real one and the init one, and nothing is there, it's, like, really messed up. 390 00:33:57,980 --> 00:34:01,900 So, anyway, let's go through how this works in practice. 391 00:34:02,140 --> 00:34:08,320 So, our little devil emoji here, I like emojis, is our malicious demon. 392 00:34:08,320 --> 00:34:10,800 This is effectively stage one. 393 00:34:11,680 --> 00:34:17,880 We, in the init script, in the ramfs, forks and execs that. 394 00:34:18,020 --> 00:34:25,700 We open the EFI vars, we actually mount the EFI vars file system and mount proc and all that. 395 00:34:25,760 --> 00:34:31,840 And we fetch it out of the, we fetch stage 2 and 3 out of UEFI land. 396 00:34:32,760 --> 00:34:42,000 And then we just kind of stay there and we cross that boundary between init ramfs land and, you know, the real system land. 397 00:34:42,160 --> 00:34:47,700 And that execs, you know, our friend system D, which then spawns all kinds of other garbage. 398 00:34:48,100 --> 00:34:55,680 And when it spawns the policy load, which we detect through FA notify, we give a stop signal to sysctl. 399 00:34:55,800 --> 00:35:00,540 Sysctl is going to apply the policy that says you cannot p-trace. 400 00:35:00,780 --> 00:35:03,080 And there's our EDR over there. 401 00:35:03,760 --> 00:35:05,860 I think you can figure out the next step. 402 00:35:06,180 --> 00:35:11,240 We're going to p-trace the EDR and then, like, have our way with it. 403 00:35:13,180 --> 00:35:18,720 So, what p-trace allows us to do is, basically, we stop the process. 404 00:35:18,720 --> 00:35:26,680 You can see we probably end up stopping it right after or before a syscall. 405 00:35:26,680 --> 00:35:32,240 And we can just back up, we can just back up to the syscall. 406 00:35:32,240 --> 00:35:35,160 We can control the IP and back up to the syscall. 407 00:35:35,180 --> 00:35:39,640 And then we can just set EAX and set what syscalls we'd like to make. 408 00:35:39,640 --> 00:35:43,240 So, we're effectively coercing syscalls into the process. 409 00:35:43,540 --> 00:35:45,640 So, we can call memfd create. 410 00:35:46,000 --> 00:35:59,880 Then in our other process, because we can access proc FD, proc paid FD, we can shove stage 3 in there, which is embedded in stage 2, which, by the way, never touched disk. 411 00:36:00,420 --> 00:36:04,060 And then we can do an mmap. 412 00:36:04,060 --> 00:36:09,960 Fortunately, unlike in Windows, mmapping rewrite execute pages is like totally normal. 413 00:36:09,960 --> 00:36:11,480 Lib C does it all the time. 414 00:36:12,080 --> 00:36:14,740 And then we can just put our shellcode in there. 415 00:36:16,420 --> 00:36:18,920 And then we set, oop, I went too fast. 416 00:36:18,920 --> 00:36:22,100 Then we set our EIP to the slash of the slide there. 417 00:36:22,280 --> 00:36:24,300 And we actually just jump over. 418 00:36:25,320 --> 00:36:30,100 And then we effectively return to DL open as 419 00:36:33,820 --> 00:36:35,380 we learned yesterday. 420 00:36:35,380 --> 00:36:40,300 And as I kind of already knew, like, I'm sorry, I forgot the speaker's name. 421 00:36:40,300 --> 00:36:41,920 We talked about it yesterday. 422 00:36:42,560 --> 00:36:43,660 It's on my note card. 423 00:36:44,340 --> 00:36:45,740 I'm out of sync. 424 00:36:45,940 --> 00:36:46,640 Anyway. 425 00:36:49,160 --> 00:36:52,300 So, Lib C has an internal DL open. 426 00:36:52,300 --> 00:36:57,020 We can do the old school LD preload trick except for without LD preloading. 427 00:36:57,020 --> 00:37:01,880 We can call the internal DL open and then we can have our malicious SO. 428 00:37:02,060 --> 00:37:05,320 And that malicious SO can clobber whatever we need to clobber. 429 00:37:05,940 --> 00:37:07,080 And then we return. 430 00:37:07,080 --> 00:37:08,000 All right. 431 00:37:08,200 --> 00:37:17,500 So now, we can send the continue to our policy load and load the actual policy that prevents us for doing this. 432 00:37:17,960 --> 00:37:21,720 And our EDR is actually now looking the other way. 433 00:37:21,780 --> 00:37:38,000 So, basically, if you look at the code and you see our payload, and this is sort of a point that also touched on, that you don't want to, there's two options here about clobbering the EDR, either the input stage or the output stage. 434 00:37:38,000 --> 00:37:39,200 And the input stage is complicated. 435 00:37:39,200 --> 00:37:42,620 You have to understand how it processes information from the kernel. 436 00:37:42,620 --> 00:37:44,000 The output stage is super simple. 437 00:37:44,000 --> 00:37:45,320 You've already looked at the logs. 438 00:37:45,320 --> 00:37:46,360 You know what they say. 439 00:37:46,480 --> 00:37:53,360 You just want to, you know, compromise its ability to write things to the output log or things you don't want to the output log. 440 00:37:53,420 --> 00:37:56,420 And then there's our malicious process and everybody's happy. 441 00:37:56,420 --> 00:37:58,700 The EDR is looking away and we can plunder away. 442 00:37:59,280 --> 00:38:01,380 So, let's do a little demo. 443 00:38:02,660 --> 00:38:07,080 What I'm going to do is we're going to tune up AuditD. 444 00:38:07,080 --> 00:38:08,980 AuditD is our example EDR. 445 00:38:09,340 --> 00:38:15,740 You know, I know that AuditD is not a commercial EDR vendor and you're wondering, does this work on commercial EDR vendors? 446 00:38:15,740 --> 00:38:17,000 Yeah, probably. 447 00:38:19,620 --> 00:38:22,080 And we'll install our implant. 448 00:38:22,080 --> 00:38:22,760 We'll reboot. 449 00:38:22,760 --> 00:38:23,920 We'll set the marker. 450 00:38:24,440 --> 00:38:28,000 We'll do the exploit again and we'll show that we're invisible. 451 00:38:28,680 --> 00:38:30,100 All right, let's do the demo. 452 00:38:30,520 --> 00:38:31,160 Okay. 453 00:38:31,240 --> 00:38:32,980 Oh, God, how do you do this? 454 00:38:33,460 --> 00:38:34,580 Windows is hard. 455 00:38:40,320 --> 00:38:41,180 Oh, God. 456 00:38:43,420 --> 00:38:44,180 Do it. 457 00:38:44,180 --> 00:38:44,760 Okay. 458 00:38:45,200 --> 00:38:46,200 Oh, God, what did I do? 459 00:38:46,200 --> 00:38:47,060 Oh, God! 460 00:38:47,060 --> 00:38:47,060 Oh, God! 461 00:38:49,760 --> 00:38:51,400 I know how to use Windows. 462 00:38:53,300 --> 00:38:55,100 This Windows shit is complicated. 463 00:38:55,980 --> 00:38:57,240 All right, here we go. 464 00:38:57,500 --> 00:38:59,580 We got the analyst on the right. 465 00:38:59,580 --> 00:39:01,180 We got the hacker on the left. 466 00:39:02,140 --> 00:39:07,480 And what we're going to do is the analyst is going to turn on the audit rules. 467 00:39:07,480 --> 00:39:12,320 He's going to tune up audit so that it just has every exec. 468 00:39:12,620 --> 00:39:14,800 Then we're going to tailor the audit log. 469 00:39:14,800 --> 00:39:16,540 We're going to exploit the enterprise tool. 470 00:39:16,540 --> 00:39:17,300 You can see we're root. 471 00:39:17,300 --> 00:39:18,140 We're making all this noise. 472 00:39:18,140 --> 00:39:18,900 It's terrible. 473 00:39:19,460 --> 00:39:21,260 You know, they're going to roll this up. 474 00:39:23,180 --> 00:39:25,180 You can see it on the right, all that noise. 475 00:39:25,180 --> 00:39:26,800 Then we're going to run our infector binary. 476 00:39:26,800 --> 00:39:29,180 Our infector binary is going to make a whole lot of noise. 477 00:39:29,420 --> 00:39:35,560 But this noise is actually really normal because systems generate initram fs's all the time. 478 00:39:35,560 --> 00:39:36,740 So it's fine. 479 00:39:37,260 --> 00:39:45,780 So it's going to make basically all the noise that it makes on an initram fs update. 480 00:39:45,800 --> 00:39:51,900 This is kind of a lot of reused harness from my horse pill talk from a few years ago. 481 00:39:52,440 --> 00:39:54,640 But, you know, it's as true today as it was there. 482 00:39:55,260 --> 00:39:56,160 Everything's infected. 483 00:39:56,160 --> 00:39:57,220 Have a nice day. 484 00:39:58,620 --> 00:40:00,220 And then we're going to reboot. 485 00:40:01,480 --> 00:40:03,180 Let's do some cooking show time. 486 00:40:03,180 --> 00:40:06,700 Let's see if I edited this video well enough. 487 00:40:07,420 --> 00:40:08,560 Here we are. 488 00:40:08,620 --> 00:40:09,380 Okay. 489 00:40:11,700 --> 00:40:13,640 I'll edit it tighter next time. 490 00:40:14,940 --> 00:40:15,660 Okay. 491 00:40:15,660 --> 00:40:15,780 And we're going to reboot. 492 00:40:15,800 --> 00:40:17,220 Again, we've tuned up audit. 493 00:40:17,220 --> 00:40:21,540 And you can see we're displaying the audit log there. 494 00:40:24,020 --> 00:40:24,580 Let's see. 495 00:40:24,580 --> 00:40:26,820 Make a little space there. 496 00:40:28,440 --> 00:40:29,160 Okay. 497 00:40:30,080 --> 00:40:32,120 And then we're going to do the same thing. 498 00:40:32,840 --> 00:40:34,740 Actually, we're going to set our marker first. 499 00:40:34,740 --> 00:40:36,460 And that's going to make a little bit of noise. 500 00:40:36,640 --> 00:40:39,960 But once you set the timer slack, that's what the PRCTL call is. 501 00:40:39,960 --> 00:40:42,940 You can see the marker is set. 502 00:40:42,940 --> 00:40:46,440 And you can also see that there's no noise in the audit log. 503 00:40:47,160 --> 00:40:49,260 And then I game root again. 504 00:40:49,680 --> 00:40:51,900 And you can see, again, no noise. 505 00:40:52,460 --> 00:40:53,760 We're invisible. 506 00:40:54,360 --> 00:40:57,480 We can do all those nasty things we did before. 507 00:40:58,140 --> 00:40:59,040 Invisible. 508 00:40:59,360 --> 00:41:00,080 It's awesome. 509 00:41:00,080 --> 00:41:00,860 Ta-da! 510 00:41:02,880 --> 00:41:09,280 And then we can show the policy as applied. 511 00:41:09,280 --> 00:41:13,440 You can see YAML mode 3 means P trace is completely disabled in the system. 512 00:41:13,440 --> 00:41:14,260 And that is true. 513 00:41:14,260 --> 00:41:16,700 P trace is now completely disabled in the system. 514 00:41:16,700 --> 00:41:20,280 But we inhibited the policy load that prevented us from doing that. 515 00:41:21,360 --> 00:41:24,860 And then, like I said, everything is a file system. 516 00:41:24,860 --> 00:41:26,420 Or everything is a file in Linux. 517 00:41:26,440 --> 00:41:32,020 If you look somewhere in there, there should be a lol key. 518 00:41:32,020 --> 00:41:33,060 Yeah, there it is. 519 00:41:33,300 --> 00:41:34,500 Yeah, right around there. 520 00:41:35,640 --> 00:41:36,980 Because hacking is funny. 521 00:41:37,380 --> 00:41:38,240 And then, ta-da! 522 00:41:38,240 --> 00:41:39,140 We did it. 523 00:41:39,260 --> 00:41:40,900 How do we get back to the slides? 524 00:41:41,740 --> 00:41:42,520 Okay. 525 00:41:47,040 --> 00:41:48,240 Thank you. 526 00:41:48,640 --> 00:41:55,180 And, you know, everyone on a Saturday morning at DEF CON is always thinking to themselves, what does this all mean? 527 00:41:56,960 --> 00:42:00,700 You know, we just want to bring happiness to everyone. 528 00:42:02,420 --> 00:42:04,480 Everyone is going to sleep well tonight. 529 00:42:04,480 --> 00:42:06,440 This is the net happiness increase. 530 00:42:06,440 --> 00:42:07,540 You're happy. 531 00:42:07,840 --> 00:42:09,180 The analyst is happy. 532 00:42:09,180 --> 00:42:13,940 That payload that you spent months working on is still your payload and not their sample. 533 00:42:14,240 --> 00:42:15,560 Everything is good. 534 00:42:15,700 --> 00:42:16,600 That's what we're all about. 535 00:42:16,600 --> 00:42:18,280 Bringing happiness to the world. 536 00:42:20,440 --> 00:42:21,200 All right. 537 00:42:21,200 --> 00:42:23,880 I don't really care about mitigation, so I'm going to have Topher talk about that. 538 00:42:23,980 --> 00:42:26,820 I mean, I don't really care either, but we felt it necessary. 539 00:42:27,300 --> 00:42:29,960 There's a couple of things that you can do to mitigate this. 540 00:42:29,960 --> 00:42:37,220 Like, the one biggest thing is, because we're utilizing UEFI variables, is to actually monitor and audit those against your organization's fleet. 541 00:42:37,220 --> 00:42:41,200 That would be like the first step to sort of mitigating these risks that we've presented. 542 00:42:41,460 --> 00:42:51,340 Um, furthermore, EDR vendors, if any of you are out there, you should be detecting UEFI APIs and this functionality in Windows and in Linux spaces if you happen to be doing, like, Linux EDR. 543 00:42:51,460 --> 00:42:55,900 Um, it's not really common for applications to set and get firmware variables. 544 00:42:55,940 --> 00:43:03,440 Um, and furthermore, like, after the installation of a platform, uh, NVBS and RT variables being set is pretty weird. 545 00:43:03,440 --> 00:43:05,640 Uh, I've never actually seen that in practice. 546 00:43:05,640 --> 00:43:10,820 If you have seen that in practice, come talk to me about it, because I'd like to know where, because I want to abuse it. 547 00:43:12,060 --> 00:43:16,940 Um, furthermore, as we kind of showcase, EDR tamper resistance is not at all effective. 548 00:43:17,120 --> 00:43:21,300 Uh, it's very easy to, like, sinkhole, uh, the sensor, kill the sensor. 549 00:43:21,400 --> 00:43:24,700 As Mike showed, it's very easy to p-trace the sensor. 550 00:43:24,900 --> 00:43:30,440 Um, so vendors really just need to work on securing their, uh, agents and their processes a little bit better. 551 00:43:30,460 --> 00:43:37,160 Um, furthermore, uh, Mike kind of said this in his horse talk at Black Hat a few years ago, but assembling RAM disks on systems is just silly. 552 00:43:37,600 --> 00:43:39,600 Stop doing that if you're a Linux distro. 553 00:43:41,440 --> 00:43:45,100 Um, so, like, as far as closing the rest goes, we have some future work. 554 00:43:46,220 --> 00:43:55,940 So, you know, the system firmware is, uh, a great, a great place to hide and there's all kinds of goodies in there and we are just touching the surface of it. 555 00:43:56,080 --> 00:44:07,240 And it's interesting, like, as we were doing this research, a lot of companies started announcing that they are going to start looking at the firmware space as a place to hunt. 556 00:44:07,980 --> 00:44:14,080 But, you know, this is a cat and mouse game and, uh, as far as I can tell, the, uh, are we the mouse or are we the cat? 557 00:44:14,840 --> 00:44:17,260 Anyway, one of us is already ahead. 558 00:44:19,920 --> 00:44:21,040 And I think it's us. 559 00:44:21,040 --> 00:44:22,800 I'm not sure if we're the cat or the mouse. 560 00:44:23,960 --> 00:44:24,680 Alright. 561 00:44:25,200 --> 00:44:28,420 So, like, in closing, we're bringing net happiness to everybody. 562 00:44:28,420 --> 00:44:30,720 We're going to have ourselves a UEFI dot party. 563 00:44:30,720 --> 00:44:31,980 We're plundering away our loot. 564 00:44:31,980 --> 00:44:34,040 We're sucker punching that pesky EDR. 565 00:44:34,340 --> 00:44:41,540 Um, and all of our code is located on this GitHub link, uh, perturbed platypus or, you know, as we like to call ourselves, APTPP. 566 00:44:43,640 --> 00:44:45,480 Uh, we, we just pushed the code. 567 00:44:45,480 --> 00:44:46,260 We just confirmed it. 568 00:44:46,260 --> 00:44:50,680 We had a, we had a timer on a box that pushed it exactly 1045. 569 00:44:50,680 --> 00:44:51,680 Uh, it's live. 570 00:44:51,680 --> 00:44:53,420 So, go, go have at it. 571 00:44:53,420 --> 00:44:54,440 Plunder away. 572 00:44:54,460 --> 00:44:56,560 Uh, here's some references that you can look at. 573 00:44:56,560 --> 00:44:58,480 Uh, that, that's all we got for you.