[00:00.000 --> 00:03.240] So I'm here to introduce our speaker, Dr. [00:03.240 --> 00:09.900] Bramweill Brunzedean, with his talk, Can't Stop the ROP, Automating ASLR. [00:09.900 --> 00:14.000] I am extremely excited for this talk, so would you all please help me welcome him. [00:19.670 --> 00:20.770] All righty. [00:20.770 --> 00:21.930] Welcome, welcome. [00:21.930 --> 00:24.530] Thank you for coming to my talk. [00:24.530 --> 00:29.290] The first talk in a while that I've actually had full control of my voice. [00:29.290 --> 00:35.590] The last few I've had severely affected vocal quality from my voice being ravaged. [00:35.590 --> 00:38.930] So in any case, my name is Bramweill Brunzedean. [00:38.930 --> 00:52.730] I am the director of the Vrona Lab at UAH and also an assistant professor and creator of various different tools, including the Shell Wasp, which allows us to utilize Windows Syscalls and Shellcode. [00:52.850 --> 01:01.970] The JopRocket, allowing us to do jump-oriented programming, and RopRocket for return-oriented programming, and an NSA-funded Shellcode analysis framework. [01:02.230 --> 01:05.770] SHARM, funded with about $300,000. [01:06.090 --> 01:17.330] A speaker at various conferences, DEF CON, Black Hat, Hack in the Box, Virus Bulletin, PAI on different grants from the NSA, and more recently, DLD. [01:17.650 --> 01:25.410] I do have a PhD in cyber operations, which is a highly technical degree dealing with reverse engineering, malware analysis, and software exploitation. [01:26.270 --> 01:30.650] So now that we have all of that out of the way, why should you care? [01:30.650 --> 01:35.030] What is the big selling point of this talk? [01:35.030 --> 01:47.590] And really, the answer to that is, ASLR is the crown jewel in the arsenal for Microsoft in terms of defending against memory corruption bugs. [01:47.590 --> 01:55.530] So if you're using applications that are made in a non-memory-safe language, this is extremely, highly, highly relevant. [01:56.050 --> 02:04.710] So high entropy ASLR is hopefully supposed to defend and be very resilient against these attacks, but the reality is, it's not. [02:04.710 --> 02:14.770] It's a significant design flaw vulnerability that allows us to do some things that we probably shouldn't be able to do, but yet we can easily do so. [02:15.070 --> 02:23.070] In my testing, I've achieved 100% success on the different OS builds that we tested it on, and we expected nothing less. [02:23.250 --> 02:35.510] What this talk is going to give us, we're going to have a mini-tool that we'll release, and actually released about 3 a.m., part of the ROP Rocket tool, and also have a demo, so some things to look forward to. [02:35.510 --> 02:37.550] So why did I do this work in the first place? [02:37.550 --> 02:43.750] Well, I saw that there was a bug bounty listed on Microsoft's website, valued at $5,000 to $15,000. [02:43.750 --> 02:45.930] I thought, well, you know, I could do this. [02:45.930 --> 02:57.490] I looked at the scope, what was in scope, what was out of scope, and it seemed like something that I could easily do, and so that was the motivation for this work. [02:58.850 --> 03:04.950] So a one-page slide crash course into ROP. [03:04.950 --> 03:05.610] Well, what is it? [03:05.610 --> 03:17.110] It's really a way for us to have bits of executable code chained together, allowing us to then overcome a mitigation, such as data execution prevention, or address space layout randomization. [03:17.170 --> 03:22.890] If we can do that, then we can then execute our shellcode, or achieve our arbitrary computation. [03:23.270 --> 03:28.370] So these are highly, super, super relevant ASLR. [03:28.390 --> 03:30.710] It's been around for a minute or two. [03:30.710 --> 03:34.790] So first came about in 2001 with PAX. [03:35.870 --> 03:46.670] 2004, we figured out, you know what, we need more entropy than 32-bit, because if we don't, then we can simply do brute-forcing attacks. [03:47.270 --> 03:54.350] It took a little while for Microsoft to make use of ASLR, but they eventually came around to it. [03:54.350 --> 04:02.730] More recently, what's been most fashionable in all the rage has been different side-channel micro-architectural attacks. [04:02.730 --> 04:09.930] So some really superb research on some of that right now. [04:09.930 --> 04:12.630] We're skipping through some of them, just in the interest of time. [04:13.630 --> 04:22.910] And then the last there is this universal ASLR bypass, which is really an enhancer, or a multiplier to a pre-existing vulnerability. [04:27.240 --> 04:35.140] So some classic approaches to an ASLR bypass, and this is not 100% all-inclusive, but one could be a memory disclosure bug. [04:35.140 --> 04:37.020] So we might have something like a use-after-free. [04:37.020 --> 04:40.940] We have some particular value that's being displayed, maybe printed to a screen. [04:41.040 --> 04:42.100] We free that. [04:42.100 --> 04:48.420] We then maybe cause that particular memory location to be overwritten with something of the same size. [04:48.420 --> 04:54.640] And then when you go to display it again, hence the use-after-free, then maybe you disclose something like a function pointer. [04:54.640 --> 04:58.680] And then from that, you can extrapolate and determine the base address. [04:59.120 --> 05:09.320] Other things, page spraying, heap spraying, brute force attacks, those used to be highly effective, and then to a lesser degree. [05:09.320 --> 05:15.100] But with high entropy, ASLR, the entropy is just too great for those to really be feasible. [05:15.440 --> 05:22.940] If you go back much further, it's simply just using hard-coded predictable addresses if you didn't have ASLR. [05:23.340 --> 05:25.620] So I guess that's not really a bypass. [05:26.220 --> 05:34.260] Our approach here is we need to have one existing vulnerability. [05:34.260 --> 05:40.520] So if you don't have something like, say, a memory corruption bug, then this is not going to work. [05:40.660 --> 05:43.820] And you need to have the ability to execute ROP gadgets. [05:43.820 --> 05:50.380] So if you don't have that, if you don't have the ability to use ROP, then this will not work. [05:50.380 --> 05:54.280] So we're targeting 64-bit windows, and in particular, high-entropy ASLR. [05:54.280 --> 05:57.120] And we can have force relocate enabled as well. [05:57.120 --> 06:01.560] And our goal is to get the base address of system DLLs. [06:01.720 --> 06:14.280] In this case, we then have effectively bypassed ASLR, and we now have access to those, and we can easily, readily use them to massively expand the attack surface. [06:14.440 --> 06:19.660] And we need to have a payload size of sufficient size. [06:20.120 --> 06:25.340] The benefits to the attacker, massively expanding the attack surface. [06:25.340 --> 06:30.100] So maybe you have a small application, and there's just really not enough to really do much. [06:30.100 --> 06:40.640] But with this, you now have the ability to potentially add thousands of additional gadgets, and that can enable you to do something more substantial. [06:40.640 --> 06:48.460] It is portable across binaries, meaning that this general approach, you can take it and apply it to, hopefully, any Windows binary. [06:48.460 --> 06:56.880] It's not tied to a specific application that happens to be vulnerable, hence the universal ASLR bypass, and the title of this talk. [06:56.880 --> 07:00.700] So this does make use of the process environment block, the PEB. [07:00.700 --> 07:02.980] I'm sure a lot of you are familiar with that. [07:02.980 --> 07:06.260] And it's something that's easily readable from user mode. [07:06.360 --> 07:19.500] There's some common ways to disclose that that we'll get into, but there's also some rather uncommon ways, as well, that I think will probably be surprising and interesting to most people, though not necessarily everybody. [07:19.500 --> 07:23.720] So we'll go through all of them, and this technique can make use of any of them. [07:24.260 --> 07:32.620] But we'll start with the most, so this page right here, we see the PEB being displayed, the threat of environment block. [07:32.680 --> 07:41.420] And so that can be pointed to by the GS segment register, and then at offset 60 is going to be located the process environment block. [07:41.420 --> 07:46.820] So if we have the ability to access the GS register, then we can easily access that. [07:46.820 --> 07:48.620] And then if we don't, that's fine. [07:48.620 --> 07:50.940] There are other ways we could obtain that, as well. [07:51.000 --> 07:54.020] So the PEB is defined as a structure . [07:54.140 --> 07:57.980] One place that it's defined, as you can see, the Windows internal header file. [07:58.240 --> 08:04.980] You could also view that in tools like WinDebug and see some more of those reserved. [08:05.440 --> 08:10.240] In this particular thing here, we see reserved 1, 2, reserved 2, 1. [08:10.980 --> 08:15.660] But if you view that in WinDebug, you can see the actual titles of all of those. [08:16.680 --> 08:23.080] But in any case, our goal, our general approach here to this is, firstly, somehow we need to obtain the PEB. [08:23.360 --> 08:25.480] There are many ways in which we can do that. [08:25.480 --> 08:31.220] So the most common easy way to do that would be the GS segment register at offset 60. [08:31.220 --> 08:33.920] We saw that that points to the process environment block. [08:34.000 --> 08:35.560] If we can do that, great. [08:35.560 --> 08:40.920] If we're doing it in a 32-bit, then that would be FS30 would hold the PEB. [08:41.060 --> 08:52.720] If we're doing WoW 64 and we want to access the PEB, you could do something called Heaven's Gate, where you transition from 32-bit to 64-bit mode, which is really very fun and interesting to observe. [08:53.520 --> 09:01.100] And in that case, the R12 would hold a pointer to the TEB, and then you could use that to then go and obtain the PEB. [09:01.480 --> 09:05.640] And some other more interesting ways, Windows syscalls, we can use them. [09:05.640 --> 09:06.980] We'll explore those. [09:06.980 --> 09:14.400] And then RDGS base is another less familiar way that we will explore. [09:14.540 --> 09:18.960] We need to have a way to reach the PEB LDR data. [09:18.960 --> 09:20.220] We'll check that out. [09:20.220 --> 09:24.280] And then we can choose one of three doubly-linked module lists. [09:24.620 --> 09:30.660] And then we'll follow the flinks a set number of times based on the general approach that we follow. [09:30.780 --> 09:37.060] And then finally, we will obtain the DLL base, which will be a field that will be available and accessible. [09:37.060 --> 09:39.340] So we'll go into great detail momentarily. [09:39.680 --> 09:44.160] But first, let's take a look here at an example of one way we could leak the PEB. [09:44.160 --> 09:50.100] In this case, it's a very ugly, kind of nasty-looking gadget. [09:50.560 --> 09:56.040] And we see sub-RCX, Q word pointer, GS, RSI plus some big numbers. [09:56.040 --> 09:59.700] So what we want to do is we want to have RSI be equal to 60. [09:59.920 --> 10:01.240] I already have a big number there. [10:01.240 --> 10:02.160] How can I do that? [10:02.160 --> 10:04.380] The answer is simple, integer overflow. [10:04.520 --> 10:09.560] So we just add another really big number so that once you add them together, they're equal to 60. [10:09.560 --> 10:12.040] RCX, we can set that to zero. [10:12.220 --> 10:15.720] And then the result will be a negative value in two's complement form. [10:15.720 --> 10:22.520] And then we can then do neg RCX, which will then restore it to its original form. [10:22.520 --> 10:24.120] And that will be the PEB. [10:24.240 --> 10:28.200] We also have to make sure that the EAX register is set to valid memory. [10:28.200 --> 10:32.500] And then the POP and the RET10, we can easily compensate for those with filler. [10:33.320 --> 10:39.360] So going back more to the specifics of our approach here, we have nine different variant approaches. [10:39.360 --> 10:41.840] We're targeting three different DOLs. [10:41.840 --> 10:53.740] So in any particular Windows application, or almost a vast majority of them except for really tiny minified applications, but any real world application, you will always have these three DOLs loaded. [10:53.960 --> 11:00.360] And depending on the particular module list that you make use of, they will be loaded in a preset order. [11:00.360 --> 11:03.040] So we can manipulate and use that. [11:03.040 --> 11:04.780] And this is a table that I created. [11:04.780 --> 11:13.200] So we can have the number of different flinks that are indicated showing the steps that we would take. [11:13.200 --> 11:15.660] So these are doubly linked module lists. [11:15.660 --> 11:21.220] So essentially we have a module list that will have a forward link pointer and then a backward link pointer. [11:21.220 --> 11:25.880] So if we take one flink, then that takes us to the next one, to the next one, et cetera. [11:26.220 --> 11:33.240] And then the offsets for the list and the DOL base, those can vary. [11:33.240 --> 11:36.740] You notice that all of them, you add them together, the sum is always going to be 40. [11:36.960 --> 11:39.660] Not that that's super relevant, but just kind of interesting. [11:40.860 --> 11:46.240] So what we're going to do is we're going to do a case study of one of these approaches and we're going to super great detail. [11:46.400 --> 11:52.860] And the others are similar, but just slight differences in terms of what you're pursuing. [11:55.560 --> 11:59.240] And then this is something that we'll also see that can be fully automated by the tool. [11:59.240 --> 12:03.180] So it'll generate all the gadgets and we'll see that momentarily. [12:03.480 --> 12:07.680] So here's a handwritten script to get kernel 32. [12:07.680 --> 12:10.220] And you notice these are all really basic, simple gadgets. [12:10.220 --> 12:17.000] We're not using anything unusual like move dereference, some offset. [12:17.000 --> 12:21.120] We can have one move dereference gadget and a lot of flexibility. [12:21.120 --> 12:30.460] And so it's really designed to be very simple and basic gadgets that are easily readily available on binaries. [12:31.980 --> 12:36.460] In terms of capturing the PEB, so in this case, we're doing it with a leak in the GS register. [12:36.460 --> 12:39.840] We can look in WinDebug and we see, okay, RDX, what is there? [12:39.840 --> 12:40.440] It's the PEB. [12:40.440 --> 12:42.520] We can verify that with the bang PEB. [12:43.180 --> 12:45.160] And then we need to add a distance of 18. [12:45.160 --> 12:48.560] That will then allow us to reach the PEB LDR. [12:48.560 --> 12:49.800] We can add that. [12:50.040 --> 12:55.760] In this case, we're adding, we're popping that into one register and then doing, adding the two registers together. [12:55.820 --> 12:59.380] If we don't have the ability to add registers, not a problem. [12:59.380 --> 13:01.400] We could also do something very simple. [13:01.400 --> 13:06.320] For instance, 18 increments, very easy, common gadgets to obtain. [13:06.760 --> 13:09.240] And then we can then dereference that. [13:09.240 --> 13:10.520] We get the LDR location. [13:10.560 --> 13:14.080] So we're basically traversing Windows structures here. [13:14.300 --> 13:17.600] And then we want to reach the init initialization modulus. [13:17.600 --> 13:20.240] And so in this case, we're going to add 30. [13:20.240 --> 13:24.040] We could consult that little table that I showed you earlier. [13:24.340 --> 13:32.960] And once we do that, we can then obtain the LDR and initialization order modulus location. [13:32.960 --> 13:35.280] And then we can follow that. [13:35.280 --> 13:38.040] That'll be returned to us in RBX. [13:38.040 --> 13:43.340] So we complete those ROP gadgets that you see on the slide there. [13:43.400 --> 13:45.680] And then now let's follow in the flanks. [13:45.680 --> 13:48.200] So we get to our first flank. [13:48.200 --> 13:51.480] And what that is pointing to is simply another flank. [13:51.480 --> 13:53.680] And that's pointing to another flank. [13:53.680 --> 13:55.860] And that's pointing to another flank. [13:55.860 --> 14:06.480] And so we can easily traverse that just by simply taking one, dereferencing it, getting that address, and then dereferencing it until we get to the location that we so desire. [14:07.460 --> 14:12.620] So we can, our initial one that was on the previous page can take us to NTDL flank. [14:12.620 --> 14:17.840] We take another move dereference, getting us to the kernel base flank. [14:17.920 --> 14:26.220] And then finally, a third dereference will get us to the kernel 32 modulus for an initialization. [14:26.540 --> 14:28.960] Or I'm sorry, the entry, not the modulus. [14:30.380 --> 14:36.400] And then within that structure, there's a field called the DLL base. [14:36.720 --> 14:40.700] And so that is really what we're focused on. [14:40.700 --> 14:43.900] If we can obtain the DLL base, that gives us the base address. [14:43.900 --> 14:49.400] That means we can take that base address and that's the ASLR bypass. [14:49.400 --> 14:54.320] So we can then from that utilize simply offsets. [14:54.480 --> 15:09.760] So we're going to proceed forward and we see that once we capture that, we get that into RBX, we dereference that, we can check, we can do the LMF command and window bug and we see clearly, okay, this is kernel 32. [15:09.760 --> 15:12.780] We have obtained our ASLR bypass. [15:15.380 --> 15:21.480] Another view from the window bug there, we check in RBX and it maps out. [15:22.700 --> 15:24.520] So the kinds of gadgets that we can use. [15:24.520 --> 15:32.800] Again, this whole approach is we're taking, trying to take something and make it simple and easy to do with ROP. [15:32.800 --> 15:34.060] We're not writing shell code. [15:34.060 --> 15:39.280] We're not writing malware with inline assembly where we can just use whatever we want. [15:39.280 --> 15:42.260] We need to use it with commonly available gadgets. [15:42.260 --> 15:46.520] So we need some way to leak the PEB, some way to add offsets. [15:46.520 --> 15:50.060] It could be a series of increments and then some way to dereference. [15:50.060 --> 15:54.040] Now the registers being used does not matter, not important. [15:54.280 --> 15:57.240] And we can have a single dereference gadget. [15:57.240 --> 16:03.120] We can use it multiple times and it could also be XOR dereference or add or sub dereference. [16:03.320 --> 16:05.440] We can work with any of them. [16:05.440 --> 16:10.580] Some way to load a value, whether it's popping or integer overflow or negation. [16:10.720 --> 16:12.520] Lots of opportunities. [16:13.740 --> 16:15.760] So what are some alternative routes? [16:15.760 --> 16:20.040] So a lot of you may know about the GS register but let's check out some of these less common ones. [16:20.040 --> 16:24.040] Because you know what, not every binary is going to have a way to leak the GS register. [16:24.040 --> 16:26.680] So can we proceed forward without that? [16:26.820 --> 16:27.660] Absolutely. [16:28.700 --> 16:33.900] So two different syscall roads or paths to get to the PEB. [16:33.900 --> 16:39.900] One is NT query information thread, which will give us GIF wrapped, the tab pointer. [16:39.900 --> 16:45.120] And NT query information process, which will then return to us the PEB. [16:45.220 --> 16:48.400] So we've got to set up those syscalls. [16:49.080 --> 16:51.760] So the first one, NT query information process. [16:51.760 --> 16:54.840] How specifically do we set that up? [16:54.840 --> 17:02.220] So we just simply follow the X64 system calling convention but with some minor twists that we'll get into. [17:02.220 --> 17:08.520] So into RDX we can provide zero, which will specify the process basic information. [17:09.140 --> 17:13.200] R8 can be any memory that is writable. [17:13.200 --> 17:18.120] Does not have to be... you can use multiple gadgets to do that. [17:18.120 --> 17:18.860] Could be the stack. [17:18.860 --> 17:20.240] Really doesn't matter. [17:20.480 --> 17:26.180] And then R9 we want to provide the size of the process basic information structure. [17:27.120 --> 17:29.040] R10 we want to do negative one. [17:29.040 --> 17:31.860] So that's going to be 16 Fs. [17:32.020 --> 17:37.240] And then the syscall system number, the SSN, we will provide 19. [17:37.240 --> 17:39.620] And I'll talk about that momentarily. [17:39.820 --> 17:43.940] And then in some way to invoke the syscall, a syscall gadget. [17:43.940 --> 17:51.840] And then after that, we'll get into EAX or RAX, NT status code zero, which stands for SLK. [17:52.020 --> 17:58.080] And then we can then go and retrieve the PEB base address, which will be located from that structure we created. [17:58.080 --> 18:00.280] But it will be an offset eight. [18:01.660 --> 18:03.960] So the SSN, it's a Windows syscall. [18:03.960 --> 18:05.560] How can we deal with this? [18:05.560 --> 18:09.100] Because some of you know that with Windows syscalls, there can be challenges. [18:09.100 --> 18:17.760] You need to dynamically resolve the SSN because it can change from one OS build to the next. [18:17.760 --> 18:19.100] And that is super true. [18:19.100 --> 18:33.460] So we may have techniques like, you know, syswhispers, hellsgate, but if we do our information gathering, we determine, hey, we're targeting Windows 10 or 11, then in that particular case, it's completely stable. [18:33.460 --> 18:35.520] It's the same SSN for all of them. [18:35.520 --> 18:38.100] So we could actually ignore that step. [18:38.280 --> 18:46.920] But if you wanted to also target Windows 7 or other earlier versions, then that could be something extra that you could add to do that. [18:47.220 --> 18:52.720] So the structure for the process basic information, you can see that provided there for you. [18:52.720 --> 18:58.600] And then the one we care about is the PEB address or PEB base address at offset 8. [18:59.880 --> 19:06.560] So here's some inline assembly just to kind of demonstrate what we could do in order to obtain this. [19:06.560 --> 19:10.380] So we can set RDX to zero by Zoring it together. [19:10.380 --> 19:14.460] We provide a memory address, RSP 50. [19:14.560 --> 19:17.720] And then in R9, we're providing our size. [19:17.900 --> 19:22.100] And then R10, we are providing negative one. [19:22.100 --> 19:26.100] And you might say, well, the calling convention is you should do that in RCX. [19:26.100 --> 19:40.640] But because we're doing syscalls, what's going to actually happen is you have a native API wrapper, and that will just simply take the RCX value, move that into R10, so we can skip loading our RCX. [19:40.640 --> 19:41.700] It's not necessary. [19:41.700 --> 19:44.360] We can instead just load the value directly into R10. [19:44.360 --> 19:46.440] And if we don't do that, it's not going to work. [19:46.540 --> 19:49.400] And there's also a fifth parameter, the return length. [19:49.400 --> 19:49.820] Guess what? [19:49.820 --> 19:51.040] It's optional. [19:51.180 --> 19:53.220] So we can just simply ignore that. [19:53.220 --> 19:55.220] And that's true for both of these syscalls. [19:55.360 --> 20:02.620] The SSN, we can provide that directly, and we have a syscall value or syscall instruction there. [20:02.640 --> 20:08.540] Once that's done, then we can simply retrieve that at offset eight from that structure that we provided. [20:09.440 --> 20:15.800] So this, again, we'll see this in a ROP form momentarily from the tool that will automate that process. [20:16.160 --> 20:18.060] We can check that out after we do it. [20:18.060 --> 20:18.920] We do the bang peb. [20:18.920 --> 20:20.600] We compare what we have in RAX. [20:20.600 --> 20:21.520] Does it match? [20:21.520 --> 20:22.600] Yes, it does. [20:22.600 --> 20:24.820] So totally works. [20:26.480 --> 20:31.020] In T query information thread, another syscall that can work. [20:31.020 --> 20:33.340] Very effective and also very similar. [20:33.340 --> 20:35.320] Some minor changes. [20:35.320 --> 20:39.040] So zero is going to specify the thread basic information structure. [20:39.240 --> 20:44.620] Again, any writable memory is adequate for our R8 register. [20:44.720 --> 20:48.440] R9, we can provide the size of that structure. [20:48.940 --> 20:54.640] And then within R10, again, that is going to be the handle. [20:54.640 --> 21:01.960] In this case, it's going to be negative two, which is going to be the current thread, and we'll provide that in two's complement form. [21:02.520 --> 21:05.440] The SSN, we can provide that directly. [21:05.440 --> 21:09.620] And then the syscall instruction, we can do that cleanly with a nice syscall gadget. [21:09.960 --> 21:14.420] And once we get the result where we get the tab, we'll have a couple extra steps. [21:14.420 --> 21:19.300] We'll need to also then add 60 to that and then dereference that. [21:20.280 --> 21:24.080] The SSN, same situation, same story. [21:24.080 --> 21:27.380] We don't need to resolve it if you're doing Windows 10 or 11. [21:27.380 --> 21:36.100] If you want to include other ones, then you would need to utilize a technique to dynamically resolve the SSN. [21:37.260 --> 21:41.200] So we could check out the inline assembly form of that. [21:41.200 --> 21:42.740] We could set RDX to zero. [21:42.740 --> 21:45.880] We provide a buffer for our structure. [21:45.880 --> 21:52.620] We provide the size of that into R9, and then the SSN of 25. [21:52.620 --> 21:55.980] That's how we specify this is the syscall that we're using. [21:55.980 --> 21:59.140] We don't have to worry about resolving any addresses for syscalls. [21:59.140 --> 22:01.120] We just need the SSN directly. [22:01.480 --> 22:05.340] We have the negative two and the two's complement form there. [22:05.340 --> 22:13.200] We call the syscall, and then whatever location we provided as the memory, we can then go and retrieve that at offset eight. [22:13.200 --> 22:15.420] So again, very similar to the previous one. [22:15.540 --> 22:20.240] We can execute it, check it out in a WinDebug, and we get a particular value. [22:20.240 --> 22:22.980] We do the bang tab, and it matches. [22:23.080 --> 22:29.220] And then there at the bottom, circled in silver, we can see the PEB address. [22:29.220 --> 22:31.580] That's where we want to get to eventually. [22:31.860 --> 22:38.960] So we can simply add 60 to that, because offset 60 of the tab points to the process environment block. [22:38.960 --> 22:43.020] So in this case, you can see there we're just doing RAX plus 60. [22:43.020 --> 22:47.840] Later on, you'll see that in ROP format generated by the tool. [22:48.740 --> 22:55.720] So another option, and this is one that probably most people are not familiar with, is RDGSBASE. [22:55.720 --> 22:57.600] It's an actual assembly instruction. [22:57.600 --> 23:04.180] So you could provide it RDGSBASE, it's going to return the address of the tab directly into RAX. [23:04.180 --> 23:13.240] So that would be very effective if you were writing, say, shellcode or malware, and you wanted to resolve the base address of a DLL. [23:13.240 --> 23:19.880] If you're doing it with return-oriented programming, we have to look at what are the gadgets that will be found. [23:19.880 --> 23:31.820] This may be too obscure to be commonly readily available as a use in 2024. [23:33.240 --> 23:35.540] We're going to check this out in WinDebug. [23:35.540 --> 23:36.440] We execute it. [23:36.440 --> 23:37.080] Very simple. [23:37.080 --> 23:41.580] It gives us the tab very easily. [23:41.920 --> 23:44.300] And then we can add 60 to that. [23:44.500 --> 23:49.300] And once we do that, then that gives us 2AC00. [23:51.140 --> 23:55.500] And that checks out as the peb there. [23:56.220 --> 23:59.360] So another option, what if those four things do not exist? [23:59.360 --> 24:01.500] Could we still do this via ROP? [24:01.660 --> 24:02.620] And the answer is yes. [24:02.620 --> 24:05.860] We can effectively synthesize our own ROP gadget. [24:05.860 --> 24:08.780] For instance, you could synthesize RDGSBASE. [24:08.780 --> 24:19.240] So if you have the ability to write bytes to memory, let's say, for instance, virtual alloc and t-allocate virtual memory, I mean, those could potentially be blocked. [24:19.240 --> 24:21.820] But let's say we have some way to do that. [24:21.820 --> 24:27.800] Then we could write that to memory, and then we can then call that gadget and then make use of it. [24:27.800 --> 24:35.440] It's a technique that we made use of in our DEF CON talk last year on process injection via return-oriented programming. [24:36.260 --> 24:38.740] So let's check out the exploit demo. [24:38.740 --> 24:40.080] We have a little video here. [24:40.080 --> 24:43.700] So let's hope I'm sophisticated enough to operate this. [24:55.740 --> 24:57.160] Wrong video. [25:02.600 --> 25:03.200] Okay. [25:03.200 --> 25:03.620] There we go. [25:03.620 --> 25:06.700] So we have a leaked PEB right there. [25:07.840 --> 25:10.560] And we're going to verify it with a bang PEB command. [25:12.240 --> 25:17.200] And we can load the LDR offset there. [25:18.320 --> 25:20.740] And now we have the LDR address there. [25:20.740 --> 25:21.640] We can continue on. [25:21.640 --> 25:26.120] Now we want to set up getting the LDR and load memory. [25:26.120 --> 25:26.720] We got that. [25:26.720 --> 25:28.520] Now we're following different flinks. [25:29.280 --> 25:32.060] And at this point, we want to add 30. [25:32.060 --> 25:35.040] And that will then allow us to reach the DLL base. [25:35.340 --> 25:36.540] And we add that. [25:36.540 --> 25:38.860] Now we have the DLL base. [25:38.860 --> 25:42.260] We're about to get it momentarily. [25:43.260 --> 25:49.920] And we see that that is... looks like it... now we have the ASLR bypass. [25:49.920 --> 25:51.140] We've achieved it. [25:51.140 --> 25:53.280] So that's simple. [25:53.280 --> 25:55.120] And we have the bypass. [26:03.060 --> 26:09.320] So the reality is probably 99% of the time or greater this is going to work. [26:09.320 --> 26:12.440] If you have these ROP gadgets, you set them up. [26:12.960 --> 26:15.380] I mean, this is a design flaw vulnerability. [26:16.380 --> 26:19.380] It's almost certain that it will work. [26:19.380 --> 26:22.380] I don't want to say 100%, but very likely. [26:23.900 --> 26:26.080] Do we need to leak the GS register? [26:26.080 --> 26:26.380] No. [26:26.380 --> 26:28.660] There are alternative ways as we explored. [26:28.940 --> 26:31.400] Do we always need or want to do this? [26:31.820 --> 26:38.300] The cases in which you want to do this is if you want to have it as a multiplier or as an enhancer. [26:38.300 --> 26:42.680] You have the ability to call ROP, but you need significantly more gadgets. [26:42.680 --> 26:45.040] You want access to some of these system DLLs. [26:45.040 --> 26:50.020] If you can obtain that, then that vastly expands your attack surface. [26:50.020 --> 26:55.320] You can do things that otherwise you may not have previously been able to do. [26:55.320 --> 26:57.080] So some possible mitigations. [26:57.080 --> 26:58.000] How can we fix this? [26:58.000 --> 26:59.720] How can we address this? [26:59.720 --> 27:01.820] How can Microsoft address it? [27:01.820 --> 27:13.200] Well, one is to randomize the LDR data table entry different, insert unpredictable offsets into that to break some of these fixed offset traversals. [27:13.200 --> 27:16.860] So you can't just use these hard coded offsets. [27:17.200 --> 27:19.420] So it's unpredictable gaps. [27:19.800 --> 27:27.340] This could be done on a per process basis or just set up once each time you load the operating system. [27:27.340 --> 27:29.100] Either way would be effective. [27:29.420 --> 27:39.900] And so in that case, if you were to try to use one of these fixed offsets, then it simply would not give you the desired result and it would break this approach. [27:40.040 --> 27:44.300] We could also have privileged PEB access to that. [27:44.300 --> 27:47.960] So block direct segment loading and user mode. [27:47.960 --> 27:49.200] That could be an option. [27:49.300 --> 27:56.820] Maybe we have a new syscall that is a little bit more responsible in terms of how it provides access to the PEB or the TEB. [27:56.820 --> 28:01.520] And we could check things like what is the control flow graph that led to that? [28:01.520 --> 28:05.580] Did we follow a valid path or are we doing things that are kind of unusual? [28:06.480 --> 28:13.780] So that would be a major architectural lift, but it would eradicate this set of bypasses. [28:13.920 --> 28:17.580] Some other possibilities is pointer obfuscation or encryption. [28:17.580 --> 28:25.620] So maybe we have encrypted values and so if you go and obtain it, it's not enough because it's encoded. [28:25.620 --> 28:27.800] So you could use the Windows API. [28:27.800 --> 28:35.460] It already has some pre-existing things that could be used or just simply even something as simple as an XOR key. [28:35.720 --> 28:48.900] So an additional step that could be relatively simple to implement, in my opinion, but could be highly effective so that you can't just simply decode these PEB values on the fly. [28:48.900 --> 28:53.120] We could also have approaches like fine-grained ASLR, dynamic ASLR. [28:53.340 --> 29:04.300] With fine-grained, we're going to shuffle functions and even basic blocks so that if you do obtain a bypass, it doesn't matter because the other things have been randomized as well. [29:04.300 --> 29:07.280] Dynamic ASLR where we have periodic rebasing. [29:07.280 --> 29:14.260] So it may briefly be effective, but then it's going to change and so it no longer is useful or relevant. [29:14.280 --> 29:17.620] So these would serve to complement not to replace ASLR. [29:17.840 --> 29:19.580] And we could also have execute-only. [29:19.580 --> 29:27.800] So you could have that implemented via hardware support, making PEB and loader pages non-readable. [29:28.840 --> 29:30.940] How would the access be granted? [29:30.940 --> 29:34.920] That would be something that would need to be carefully determined, but it could be viable. [29:35.840 --> 29:39.660] We could also simply enhance the existing exploit detection. [29:39.660 --> 29:43.700] So things like EAF and EAF plus have been around for a very long time. [29:43.700 --> 29:47.620] So we may add some additional heuristics to that or Microsoft could. [29:47.720 --> 29:56.420] And so flag some of these abnormal list entry walks and it wouldn't prevent it, but it could stop it from being effective. [29:56.940 --> 30:00.500] All right, so let's dive into the ASLR mini bypass tool. [30:00.500 --> 30:03.140] So this is built off of ROP rocket. [30:03.400 --> 30:09.300] And what it will do is everything that we talked about, it can generate those complete ROP chains. [30:09.300 --> 30:15.060] So if you wanted to do this and not have to spend the time to write the code, you simply use the tool. [30:15.340 --> 30:20.360] So it does it in 64 bit and it will do all nine variants and it will output it as Python. [30:20.460 --> 30:23.540] Here we can see a complete Python exploit script. [30:23.540 --> 30:25.960] So it takes care of a lot of the mechanics there. [30:25.980 --> 30:29.220] And we will zoom in on that here. [30:29.220 --> 30:34.560] So one way is the PEB disclosure via the GS register. [30:34.560 --> 30:36.560] So we can set that up and obtain that. [30:36.560 --> 30:39.280] And it follows the various steps. [30:39.380 --> 30:43.780] And it does it by kind of a hybrid approach of semantic searching. [30:43.780 --> 30:47.680] So we may say, okay, I want to load a particular value into this register. [30:47.680 --> 30:50.000] What are the different ways in which we could do that? [30:50.000 --> 30:58.640] So it's not something that's just a simple hard coded recipe, but there's a lot of very rich flexibility that's possible. [30:59.140 --> 31:07.400] We can also do it via the RDGS base, the NT query information process and the NT query information thread. [31:07.400 --> 31:17.960] In this case, to obtain our writable and readable memory, we have it set to a particular location relative to the stack. [31:17.960 --> 31:22.280] We use emulation to then calculate the distance to that. [31:22.280 --> 31:24.260] And so we use that to provide the parameter. [31:24.260 --> 31:35.900] And then later on when we go and get that as our result and add offset 8, it automatically takes care of that and does emulation to precisely calculate what that's going to be. [31:35.900 --> 31:40.000] So this is actually a little bit more complicated than what I showed you. [31:40.220 --> 31:42.340] And again, it's fully automated. [31:42.820 --> 31:50.100] So it does it through those four methods, the GS register, RDGS base and then the two sys calls. [31:50.960 --> 31:54.180] And if you get the ROP gadgets from it, then it should work. [31:54.180 --> 31:57.820] It should be totally reliable if it provides those gadgets. [31:59.140 --> 32:02.580] So nine bypass techniques are supported by the tool. [32:02.580 --> 32:09.220] We have kernel 32, kernel base, NTDLL, and for all three of the different module lists. [32:09.240 --> 32:11.260] And moreover, we implement them. [32:11.260 --> 32:17.900] So actually it'll generate not nine, but actually nine times four, which is 36. [32:18.060 --> 32:20.520] So we can do it for the GS register. [32:20.520 --> 32:21.860] We'll get nine variants. [32:21.860 --> 32:31.280] We can do it for the RDGS base, for the NT query information process, as well as the NT query information thread. [32:31.320 --> 32:33.420] All of them will work. [32:33.720 --> 32:35.900] And we'll see a demo momentarily. [32:35.900 --> 32:38.320] But if you're interested, go ahead and take a picture. [32:38.320 --> 32:40.280] It's going to be part of the ROP rocket. [32:40.280 --> 32:41.860] I updated it about 3 a.m. [32:42.100 --> 32:46.540] this morning, providing this additional functionality. [32:48.280 --> 32:50.500] So tool demo time. [33:06.030 --> 33:07.150] Okay, there we go. [33:07.150 --> 33:08.030] So here's the tool. [33:08.030 --> 33:09.290] We're running it. [33:09.470 --> 33:11.350] And right now it's generating all of those. [33:11.350 --> 33:14.310] It's going, you know, it's 36 of them and it's very fast. [33:14.570 --> 33:20.010] Of course, this can vary from application to application and whatever the attack surface supports. [33:20.250 --> 33:24.410] And also at the same time, it's going to write it all to file. [33:24.410 --> 33:27.830] So obviously you don't want to copy and paste from a command console. [33:27.830 --> 33:30.390] So you can take one of them and make use of it. [33:30.390 --> 33:33.250] So a very effective tool. [33:34.590 --> 33:39.850] So the disclosure timeline for Microsoft discloses April 15th. [33:39.850 --> 33:41.690] I reported it to them. [33:41.690 --> 33:43.170] May 2024. [33:45.290 --> 33:49.590] Microsoft acknowledges the validity, decides to do nothing. [33:49.590 --> 33:50.930] That's kind of unfortunate. [33:51.690 --> 33:57.150] Microsoft in July, they asked to meet during Black Hat and then later I do meet with them. [33:57.150 --> 33:59.130] Today I'm releasing the tool. [34:01.270 --> 34:08.170] So I got an email from Microsoft, May 1st, 2024. [34:08.170 --> 34:19.370] They claim the report is valid, but that they prioritize vulnerabilities that are assessed as important, critical severities for immediate servicing. [34:19.470 --> 34:26.770] They don't consider an ASL bypass to be relevant if it doesn't cross a security boundary. [34:26.770 --> 34:33.550] What that means is the fact that it relies on a preexisting vulnerability. [34:36.050 --> 34:37.690] You know, but that is true. [34:37.690 --> 34:43.050] But the goal of this is to be a multiplier or an enhancer. [34:43.530 --> 34:57.290] And in terms of the patch history for Microsoft, we see that in 2013 there was another ASL bypass that was making use of some readily available address. [34:57.290 --> 35:04.250] And it was disclosed publicly, not to them, but Microsoft did actually fix that. [35:04.250 --> 35:07.250] This has been reported in April 2024. [35:07.250 --> 35:08.390] They have not fixed it. [35:08.390 --> 35:11.710] They have not shown any interest in fixing it, unfortunately. [35:12.190 --> 35:16.610] It's sad that they don't care, but I guess that's the reality. [35:17.150 --> 35:18.970] So some context for them. [35:19.910 --> 35:22.810] Invited me to meet with them on July 11th. [35:23.390 --> 35:30.190] I didn't acknowledge them for a couple weeks, but eventually I did agree to meet with them on the 22nd of July. [35:30.530 --> 35:36.250] I got another detailed email on the 30th of July asking for detailed information. [35:36.250 --> 35:45.110] My response was, can you provide me more information on why you decided to pay $0 for the bypass? [35:45.110 --> 35:50.590] And my whole purpose of doing this was to hopefully obtain a bug bounty. [35:51.010 --> 35:56.110] I didn't get a response, but I did get a response in person when I did meet with them. [35:56.110 --> 36:00.870] So they did ask to meet and I met them on August 7th. [36:00.870 --> 36:05.090] We spoke about 50 minutes in detail regarding the case. [36:08.370 --> 36:19.870] One of their issues was they wondered how they could change the scope so that if somebody like me wanted to do an ASR bypass, then they would have legitimate grounds to not pay it. [36:19.870 --> 36:27.690] My thinking was you have your scope clearly defined on the website and I followed that. [36:27.690 --> 36:38.990] I looked very closely at what was in scope, what was out of scope, and I think it would be better to honor their pre-existing scope, but I think that they had other ideas, which is fine. [36:39.010 --> 36:40.510] It's their choice. [36:42.690 --> 37:02.170] They mentioned in 2013 there was a post they made where they said, you know what, we had this vulnerability, which is the same vulnerability we talked about a moment ago, and we already knew about it, but if that person had reported that to us, that would have been really cool. [37:02.170 --> 37:05.590] We could have then given them a bug bounty, but they didn't. [37:05.590 --> 37:09.330] By the way, you should go and submit your vulnerabilities to us. [37:09.570 --> 37:21.930] So it's disappointing that they make statements like that and then they publicly contradict their kind of general stance on that. [37:22.910 --> 37:29.850] But in any case, they decided not to do that. [37:30.660 --> 37:35.630] Why does this matter for Windows malware? [37:35.930 --> 37:40.490] So we could go much further beyond simply what we have been talking about. [37:40.670 --> 37:52.310] So if you were to go and fix this for ASLR, that would be great, that would be cool, but it would be much more hugely impactful for the malware ecosystem in general. [37:52.310 --> 38:04.190] What that would mean is a lot of malware will utilize some of these pebwalking techniques in order to then go much further and dynamically resolve runtime addresses. [38:04.330 --> 38:09.530] And by doing that, you can kind of hide and conceal what you are doing. [38:09.590 --> 38:20.530] So if we were to fix that, then that would break it so that much of the current existing malware simply would not work. [38:20.710 --> 38:22.290] It could work. [38:23.570 --> 38:27.590] In that case, you would have to use normal imports. [38:27.810 --> 38:31.930] That's something that could be easily detected from a static analysis standpoint. [38:31.930 --> 38:34.590] A tool like PA Studio could easily enumerate that. [38:34.590 --> 38:37.750] You could also do things like getprocaddress , a little library. [38:37.950 --> 38:43.050] And those are also very easily detectable things from a static analysis standpoint. [38:43.050 --> 38:56.950] So fixing this for ASLR would be much more hugely impactful in terms of securing the enterprise or securing just any Microsoft computer from the threat of malware. [38:58.910 --> 39:17.350] Forcing attackers to make their malicious functionality very obvious because if they were to resolve it by using techniques like pebwalking and then traversing later on the PE file format, those are things that are not easy to be detected from a static analysis standpoint. [39:17.350 --> 39:23.870] You would have to drop it in a sandbox or do some type of dynamic execution. [39:24.310 --> 39:30.750] So a massive, hugely impactful gain for defenders. [39:30.750 --> 39:33.430] But I guess that's not important to them. [39:33.430 --> 39:46.030] Another alternative for them going in an opposite direction is it could force them to use Windows syscalls to then more, to obscure their activities. [39:46.030 --> 39:49.630] Now, syscalls can be much more challenging to utilize. [39:49.630 --> 39:51.170] They're a lot more complicated. [39:51.790 --> 39:58.130] It's not something that every malware author would be able to do just because of the complexity of that. [39:59.370 --> 40:04.730] And some functionality that could be easily implemented via Windows APIs. [40:04.850 --> 40:09.030] The same thing may not be true necessarily for Windows syscalls. [40:09.590 --> 40:12.990] So either way, it would be a huge win. [40:12.990 --> 40:23.370] So some takeaways here is we have these existing structures, the peb, the modulus. [40:23.690 --> 40:26.790] These have been a single point of failure. [40:26.790 --> 40:30.870] They've been existing in this form for decades. [40:31.370 --> 40:36.350] And, you know, it's an inherent design flaw and it should have been corrected a long time ago. [40:36.350 --> 40:39.130] But unfortunately it has not. [40:39.130 --> 41:02.530] And so we've seen how we could take this general approach to peb walking and then apply that to ROP to make it much more simple, basic, where we can use a few easy to find gadgets, even the same ones over and over again, to achieve it in a relatively simple way. [41:02.530 --> 41:09.170] And how we can even take that and then automate that with a tool so you can accomplish that in seconds. [41:09.170 --> 41:17.290] You could maybe have 30 seconds and then you have 36 different approaches of bypassing ASLR. [41:17.330 --> 41:19.730] So it would be great if Microsoft would patch it. [41:19.730 --> 41:22.210] They've really shown no interest in doing so. [41:22.210 --> 41:25.130] And it's not really something that could be achieved with a patch. [41:25.130 --> 41:29.550] It would need to be more of an architectural lift. [41:29.550 --> 41:47.830] But if they were to do that, it would defend against ASLR and also a lot of malware that's currently existing that's native CC++ compiled would no longer work and force the attackers to implement that malicious functionality in a different way. [41:47.830 --> 41:52.490] Unfortunately, you know, Microsoft does not care. [41:52.490 --> 41:53.670] They've made that clear. [41:54.970 --> 42:04.270] But maybe someday in the distant future, we may see a more responsible approach that can preclude some of these attacks. [42:04.270 --> 42:08.290] But I don't see that on the horizon for the immediate future. [42:08.990 --> 42:10.790] So with that, I'd like to thank you. [42:10.950 --> 42:13.250] DEF CON is an incredible place. [42:13.850 --> 42:15.750] Very, very special place. [42:15.750 --> 42:17.810] And thank you for coming to my talk. [42:17.810 --> 42:21.410] But more importantly, thank you to all of you for coming to DEF CON. [42:21.710 --> 42:23.190] Feel free to contact me. [42:23.190 --> 42:24.070] You can email me. [42:24.070 --> 42:25.950] You can check me out on GitHub. [42:26.030 --> 42:28.010] The address of the tool is there. [42:28.070 --> 42:32.690] Feel free to add me on LinkedIn or make contact, however you like. [42:32.890 --> 42:34.630] I won't take any questions now. [42:34.630 --> 42:39.010] But I'll step to the front there and then possibly outside. [42:39.010 --> 42:41.350] So feel free to come and chat with me. [42:41.390 --> 42:42.830] And thank you very much.