start	end	text
0	3240	So I'm here to introduce our speaker, Dr.
3240	9900	Bramweill Brunzedean, with his talk, Can't Stop the ROP, Automating ASLR.
9900	14000	I am extremely excited for this talk, so would you all please help me welcome him.
19670	20770	All righty.
20770	21930	Welcome, welcome.
21930	24530	Thank you for coming to my talk.
24530	29290	The first talk in a while that I've actually had full control of my voice.
29290	35590	The last few I've had severely affected vocal quality from my voice being ravaged.
35590	38930	So in any case, my name is Bramweill Brunzedean.
38930	52730	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.
52850	61970	The JopRocket, allowing us to do jump-oriented programming, and RopRocket for return-oriented programming, and an NSA-funded Shellcode analysis framework.
62230	65770	SHARM, funded with about $300,000.
66090	77330	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.
77650	85410	I do have a PhD in cyber operations, which is a highly technical degree dealing with reverse engineering, malware analysis, and software exploitation.
86270	90650	So now that we have all of that out of the way, why should you care?
90650	95030	What is the big selling point of this talk?
95030	107590	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.
107590	115530	So if you're using applications that are made in a non-memory-safe language, this is extremely, highly, highly relevant.
116050	124710	So high entropy ASLR is hopefully supposed to defend and be very resilient against these attacks, but the reality is, it's not.
124710	134770	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.
135070	143070	In my testing, I've achieved 100% success on the different OS builds that we tested it on, and we expected nothing less.
143250	155510	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.
155510	157550	So why did I do this work in the first place?
157550	163750	Well, I saw that there was a bug bounty listed on Microsoft's website, valued at $5,000 to $15,000.
163750	165930	I thought, well, you know, I could do this.
165930	177490	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.
178850	184950	So a one-page slide crash course into ROP.
184950	185610	Well, what is it?
185610	197110	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.
197170	202890	If we can do that, then we can then execute our shellcode, or achieve our arbitrary computation.
203270	208370	So these are highly, super, super relevant ASLR.
208390	210710	It's been around for a minute or two.
210710	214790	So first came about in 2001 with PAX.
215870	226670	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.
227270	234350	It took a little while for Microsoft to make use of ASLR, but they eventually came around to it.
234350	242730	More recently, what's been most fashionable in all the rage has been different side-channel micro-architectural attacks.
242730	249930	So some really superb research on some of that right now.
249930	252630	We're skipping through some of them, just in the interest of time.
253630	262910	And then the last there is this universal ASLR bypass, which is really an enhancer, or a multiplier to a pre-existing vulnerability.
267240	275140	So some classic approaches to an ASLR bypass, and this is not 100% all-inclusive, but one could be a memory disclosure bug.
275140	277020	So we might have something like a use-after-free.
277020	280940	We have some particular value that's being displayed, maybe printed to a screen.
281040	282100	We free that.
282100	288420	We then maybe cause that particular memory location to be overwritten with something of the same size.
288420	294640	And then when you go to display it again, hence the use-after-free, then maybe you disclose something like a function pointer.
294640	298680	And then from that, you can extrapolate and determine the base address.
299120	309320	Other things, page spraying, heap spraying, brute force attacks, those used to be highly effective, and then to a lesser degree.
309320	315100	But with high entropy, ASLR, the entropy is just too great for those to really be feasible.
315440	322940	If you go back much further, it's simply just using hard-coded predictable addresses if you didn't have ASLR.
323340	325620	So I guess that's not really a bypass.
326220	334260	Our approach here is we need to have one existing vulnerability.
334260	340520	So if you don't have something like, say, a memory corruption bug, then this is not going to work.
340660	343820	And you need to have the ability to execute ROP gadgets.
343820	350380	So if you don't have that, if you don't have the ability to use ROP, then this will not work.
350380	354280	So we're targeting 64-bit windows, and in particular, high-entropy ASLR.
354280	357120	And we can have force relocate enabled as well.
357120	361560	And our goal is to get the base address of system DLLs.
361720	374280	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.
374440	379660	And we need to have a payload size of sufficient size.
380120	385340	The benefits to the attacker, massively expanding the attack surface.
385340	390100	So maybe you have a small application, and there's just really not enough to really do much.
390100	400640	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.
400640	408460	It is portable across binaries, meaning that this general approach, you can take it and apply it to, hopefully, any Windows binary.
408460	416880	It's not tied to a specific application that happens to be vulnerable, hence the universal ASLR bypass, and the title of this talk.
416880	420700	So this does make use of the process environment block, the PEB.
420700	422980	I'm sure a lot of you are familiar with that.
422980	426260	And it's something that's easily readable from user mode.
426360	439500	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.
439500	443720	So we'll go through all of them, and this technique can make use of any of them.
444260	452620	But we'll start with the most, so this page right here, we see the PEB being displayed, the threat of environment block.
452680	461420	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.
461420	466820	So if we have the ability to access the GS register, then we can easily access that.
466820	468620	And then if we don't, that's fine.
468620	470940	There are other ways we could obtain that, as well.
471000	474020	So the PEB is defined as a structure .
474140	477980	One place that it's defined, as you can see, the Windows internal header file.
478240	484980	You could also view that in tools like WinDebug and see some more of those reserved.
485440	490240	In this particular thing here, we see reserved 1, 2, reserved 2, 1.
490980	495660	But if you view that in WinDebug, you can see the actual titles of all of those.
496680	503080	But in any case, our goal, our general approach here to this is, firstly, somehow we need to obtain the PEB.
503360	505480	There are many ways in which we can do that.
505480	511220	So the most common easy way to do that would be the GS segment register at offset 60.
511220	513920	We saw that that points to the process environment block.
514000	515560	If we can do that, great.
515560	520920	If we're doing it in a 32-bit, then that would be FS30 would hold the PEB.
521060	532720	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.
533520	541100	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.
541480	545640	And some other more interesting ways, Windows syscalls, we can use them.
545640	546980	We'll explore those.
546980	554400	And then RDGS base is another less familiar way that we will explore.
554540	558960	We need to have a way to reach the PEB LDR data.
558960	560220	We'll check that out.
560220	564280	And then we can choose one of three doubly-linked module lists.
564620	570660	And then we'll follow the flinks a set number of times based on the general approach that we follow.
570780	577060	And then finally, we will obtain the DLL base, which will be a field that will be available and accessible.
577060	579340	So we'll go into great detail momentarily.
579680	584160	But first, let's take a look here at an example of one way we could leak the PEB.
584160	590100	In this case, it's a very ugly, kind of nasty-looking gadget.
590560	596040	And we see sub-RCX, Q word pointer, GS, RSI plus some big numbers.
596040	599700	So what we want to do is we want to have RSI be equal to 60.
599920	601240	I already have a big number there.
601240	602160	How can I do that?
602160	604380	The answer is simple, integer overflow.
604520	609560	So we just add another really big number so that once you add them together, they're equal to 60.
609560	612040	RCX, we can set that to zero.
612220	615720	And then the result will be a negative value in two's complement form.
615720	622520	And then we can then do neg RCX, which will then restore it to its original form.
622520	624120	And that will be the PEB.
624240	628200	We also have to make sure that the EAX register is set to valid memory.
628200	632500	And then the POP and the RET10, we can easily compensate for those with filler.
633320	639360	So going back more to the specifics of our approach here, we have nine different variant approaches.
639360	641840	We're targeting three different DOLs.
641840	653740	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.
653960	660360	And depending on the particular module list that you make use of, they will be loaded in a preset order.
660360	663040	So we can manipulate and use that.
663040	664780	And this is a table that I created.
664780	673200	So we can have the number of different flinks that are indicated showing the steps that we would take.
673200	675660	So these are doubly linked module lists.
675660	681220	So essentially we have a module list that will have a forward link pointer and then a backward link pointer.
681220	685880	So if we take one flink, then that takes us to the next one, to the next one, et cetera.
686220	693240	And then the offsets for the list and the DOL base, those can vary.
693240	696740	You notice that all of them, you add them together, the sum is always going to be 40.
696960	699660	Not that that's super relevant, but just kind of interesting.
700860	706240	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.
706400	712860	And the others are similar, but just slight differences in terms of what you're pursuing.
715560	719240	And then this is something that we'll also see that can be fully automated by the tool.
719240	723180	So it'll generate all the gadgets and we'll see that momentarily.
723480	727680	So here's a handwritten script to get kernel 32.
727680	730220	And you notice these are all really basic, simple gadgets.
730220	737000	We're not using anything unusual like move dereference, some offset.
737000	741120	We can have one move dereference gadget and a lot of flexibility.
741120	750460	And so it's really designed to be very simple and basic gadgets that are easily readily available on binaries.
751980	756460	In terms of capturing the PEB, so in this case, we're doing it with a leak in the GS register.
756460	759840	We can look in WinDebug and we see, okay, RDX, what is there?
759840	760440	It's the PEB.
760440	762520	We can verify that with the bang PEB.
763180	765160	And then we need to add a distance of 18.
765160	768560	That will then allow us to reach the PEB LDR.
768560	769800	We can add that.
770040	775760	In this case, we're adding, we're popping that into one register and then doing, adding the two registers together.
775820	779380	If we don't have the ability to add registers, not a problem.
779380	781400	We could also do something very simple.
781400	786320	For instance, 18 increments, very easy, common gadgets to obtain.
786760	789240	And then we can then dereference that.
789240	790520	We get the LDR location.
790560	794080	So we're basically traversing Windows structures here.
794300	797600	And then we want to reach the init initialization modulus.
797600	800240	And so in this case, we're going to add 30.
800240	804040	We could consult that little table that I showed you earlier.
804340	812960	And once we do that, we can then obtain the LDR and initialization order modulus location.
812960	815280	And then we can follow that.
815280	818040	That'll be returned to us in RBX.
818040	823340	So we complete those ROP gadgets that you see on the slide there.
823400	825680	And then now let's follow in the flanks.
825680	828200	So we get to our first flank.
828200	831480	And what that is pointing to is simply another flank.
831480	833680	And that's pointing to another flank.
833680	835860	And that's pointing to another flank.
835860	846480	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.
847460	852620	So we can, our initial one that was on the previous page can take us to NTDL flank.
852620	857840	We take another move dereference, getting us to the kernel base flank.
857920	866220	And then finally, a third dereference will get us to the kernel 32 modulus for an initialization.
866540	868960	Or I'm sorry, the entry, not the modulus.
870380	876400	And then within that structure, there's a field called the DLL base.
876720	880700	And so that is really what we're focused on.
880700	883900	If we can obtain the DLL base, that gives us the base address.
883900	889400	That means we can take that base address and that's the ASLR bypass.
889400	894320	So we can then from that utilize simply offsets.
894480	909760	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.
909760	912780	We have obtained our ASLR bypass.
915380	921480	Another view from the window bug there, we check in RBX and it maps out.
922700	924520	So the kinds of gadgets that we can use.
924520	932800	Again, this whole approach is we're taking, trying to take something and make it simple and easy to do with ROP.
932800	934060	We're not writing shell code.
934060	939280	We're not writing malware with inline assembly where we can just use whatever we want.
939280	942260	We need to use it with commonly available gadgets.
942260	946520	So we need some way to leak the PEB, some way to add offsets.
946520	950060	It could be a series of increments and then some way to dereference.
950060	954040	Now the registers being used does not matter, not important.
954280	957240	And we can have a single dereference gadget.
957240	963120	We can use it multiple times and it could also be XOR dereference or add or sub dereference.
963320	965440	We can work with any of them.
965440	970580	Some way to load a value, whether it's popping or integer overflow or negation.
970720	972520	Lots of opportunities.
973740	975760	So what are some alternative routes?
975760	980040	So a lot of you may know about the GS register but let's check out some of these less common ones.
980040	984040	Because you know what, not every binary is going to have a way to leak the GS register.
984040	986680	So can we proceed forward without that?
986820	987660	Absolutely.
988700	993900	So two different syscall roads or paths to get to the PEB.
993900	999900	One is NT query information thread, which will give us GIF wrapped, the tab pointer.
999900	1005120	And NT query information process, which will then return to us the PEB.
1005220	1008400	So we've got to set up those syscalls.
1009080	1011760	So the first one, NT query information process.
1011760	1014840	How specifically do we set that up?
1014840	1022220	So we just simply follow the X64 system calling convention but with some minor twists that we'll get into.
1022220	1028520	So into RDX we can provide zero, which will specify the process basic information.
1029140	1033200	R8 can be any memory that is writable.
1033200	1038120	Does not have to be... you can use multiple gadgets to do that.
1038120	1038860	Could be the stack.
1038860	1040240	Really doesn't matter.
1040480	1046180	And then R9 we want to provide the size of the process basic information structure.
1047120	1049040	R10 we want to do negative one.
1049040	1051860	So that's going to be 16 Fs.
1052020	1057240	And then the syscall system number, the SSN, we will provide 19.
1057240	1059620	And I'll talk about that momentarily.
1059820	1063940	And then in some way to invoke the syscall, a syscall gadget.
1063940	1071840	And then after that, we'll get into EAX or RAX, NT status code zero, which stands for SLK.
1072020	1078080	And then we can then go and retrieve the PEB base address, which will be located from that structure we created.
1078080	1080280	But it will be an offset eight.
1081660	1083960	So the SSN, it's a Windows syscall.
1083960	1085560	How can we deal with this?
1085560	1089100	Because some of you know that with Windows syscalls, there can be challenges.
1089100	1097760	You need to dynamically resolve the SSN because it can change from one OS build to the next.
1097760	1099100	And that is super true.
1099100	1113460	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.
1113460	1115520	It's the same SSN for all of them.
1115520	1118100	So we could actually ignore that step.
1118280	1126920	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.
1127220	1132720	So the structure for the process basic information, you can see that provided there for you.
1132720	1138600	And then the one we care about is the PEB address or PEB base address at offset 8.
1139880	1146560	So here's some inline assembly just to kind of demonstrate what we could do in order to obtain this.
1146560	1150380	So we can set RDX to zero by Zoring it together.
1150380	1154460	We provide a memory address, RSP 50.
1154560	1157720	And then in R9, we're providing our size.
1157900	1162100	And then R10, we are providing negative one.
1162100	1166100	And you might say, well, the calling convention is you should do that in RCX.
1166100	1180640	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.
1180640	1181700	It's not necessary.
1181700	1184360	We can instead just load the value directly into R10.
1184360	1186440	And if we don't do that, it's not going to work.
1186540	1189400	And there's also a fifth parameter, the return length.
1189400	1189820	Guess what?
1189820	1191040	It's optional.
1191180	1193220	So we can just simply ignore that.
1193220	1195220	And that's true for both of these syscalls.
1195360	1202620	The SSN, we can provide that directly, and we have a syscall value or syscall instruction there.
1202640	1208540	Once that's done, then we can simply retrieve that at offset eight from that structure that we provided.
1209440	1215800	So this, again, we'll see this in a ROP form momentarily from the tool that will automate that process.
1216160	1218060	We can check that out after we do it.
1218060	1218920	We do the bang peb.
1218920	1220600	We compare what we have in RAX.
1220600	1221520	Does it match?
1221520	1222600	Yes, it does.
1222600	1224820	So totally works.
1226480	1231020	In T query information thread, another syscall that can work.
1231020	1233340	Very effective and also very similar.
1233340	1235320	Some minor changes.
1235320	1239040	So zero is going to specify the thread basic information structure.
1239240	1244620	Again, any writable memory is adequate for our R8 register.
1244720	1248440	R9, we can provide the size of that structure.
1248940	1254640	And then within R10, again, that is going to be the handle.
1254640	1261960	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.
1262520	1265440	The SSN, we can provide that directly.
1265440	1269620	And then the syscall instruction, we can do that cleanly with a nice syscall gadget.
1269960	1274420	And once we get the result where we get the tab, we'll have a couple extra steps.
1274420	1279300	We'll need to also then add 60 to that and then dereference that.
1280280	1284080	The SSN, same situation, same story.
1284080	1287380	We don't need to resolve it if you're doing Windows 10 or 11.
1287380	1296100	If you want to include other ones, then you would need to utilize a technique to dynamically resolve the SSN.
1297260	1301200	So we could check out the inline assembly form of that.
1301200	1302740	We could set RDX to zero.
1302740	1305880	We provide a buffer for our structure.
1305880	1312620	We provide the size of that into R9, and then the SSN of 25.
1312620	1315980	That's how we specify this is the syscall that we're using.
1315980	1319140	We don't have to worry about resolving any addresses for syscalls.
1319140	1321120	We just need the SSN directly.
1321480	1325340	We have the negative two and the two's complement form there.
1325340	1333200	We call the syscall, and then whatever location we provided as the memory, we can then go and retrieve that at offset eight.
1333200	1335420	So again, very similar to the previous one.
1335540	1340240	We can execute it, check it out in a WinDebug, and we get a particular value.
1340240	1342980	We do the bang tab, and it matches.
1343080	1349220	And then there at the bottom, circled in silver, we can see the PEB address.
1349220	1351580	That's where we want to get to eventually.
1351860	1358960	So we can simply add 60 to that, because offset 60 of the tab points to the process environment block.
1358960	1363020	So in this case, you can see there we're just doing RAX plus 60.
1363020	1367840	Later on, you'll see that in ROP format generated by the tool.
1368740	1375720	So another option, and this is one that probably most people are not familiar with, is RDGSBASE.
1375720	1377600	It's an actual assembly instruction.
1377600	1384180	So you could provide it RDGSBASE, it's going to return the address of the tab directly into RAX.
1384180	1393240	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.
1393240	1399880	If you're doing it with return-oriented programming, we have to look at what are the gadgets that will be found.
1399880	1411820	This may be too obscure to be commonly readily available as a use in 2024.
1413240	1415540	We're going to check this out in WinDebug.
1415540	1416440	We execute it.
1416440	1417080	Very simple.
1417080	1421580	It gives us the tab very easily.
1421920	1424300	And then we can add 60 to that.
1424500	1429300	And once we do that, then that gives us 2AC00.
1431140	1435500	And that checks out as the peb there.
1436220	1439360	So another option, what if those four things do not exist?
1439360	1441500	Could we still do this via ROP?
1441660	1442620	And the answer is yes.
1442620	1445860	We can effectively synthesize our own ROP gadget.
1445860	1448780	For instance, you could synthesize RDGSBASE.
1448780	1459240	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.
1459240	1461820	But let's say we have some way to do that.
1461820	1467800	Then we could write that to memory, and then we can then call that gadget and then make use of it.
1467800	1475440	It's a technique that we made use of in our DEF CON talk last year on process injection via return-oriented programming.
1476260	1478740	So let's check out the exploit demo.
1478740	1480080	We have a little video here.
1480080	1483700	So let's hope I'm sophisticated enough to operate this.
1495740	1497160	Wrong video.
1502600	1503200	Okay.
1503200	1503620	There we go.
1503620	1506700	So we have a leaked PEB right there.
1507840	1510560	And we're going to verify it with a bang PEB command.
1512240	1517200	And we can load the LDR offset there.
1518320	1520740	And now we have the LDR address there.
1520740	1521640	We can continue on.
1521640	1526120	Now we want to set up getting the LDR and load memory.
1526120	1526720	We got that.
1526720	1528520	Now we're following different flinks.
1529280	1532060	And at this point, we want to add 30.
1532060	1535040	And that will then allow us to reach the DLL base.
1535340	1536540	And we add that.
1536540	1538860	Now we have the DLL base.
1538860	1542260	We're about to get it momentarily.
1543260	1549920	And we see that that is... looks like it... now we have the ASLR bypass.
1549920	1551140	We've achieved it.
1551140	1553280	So that's simple.
1553280	1555120	And we have the bypass.
1563060	1569320	So the reality is probably 99% of the time or greater this is going to work.
1569320	1572440	If you have these ROP gadgets, you set them up.
1572960	1575380	I mean, this is a design flaw vulnerability.
1576380	1579380	It's almost certain that it will work.
1579380	1582380	I don't want to say 100%, but very likely.
1583900	1586080	Do we need to leak the GS register?
1586080	1586380	No.
1586380	1588660	There are alternative ways as we explored.
1588940	1591400	Do we always need or want to do this?
1591820	1598300	The cases in which you want to do this is if you want to have it as a multiplier or as an enhancer.
1598300	1602680	You have the ability to call ROP, but you need significantly more gadgets.
1602680	1605040	You want access to some of these system DLLs.
1605040	1610020	If you can obtain that, then that vastly expands your attack surface.
1610020	1615320	You can do things that otherwise you may not have previously been able to do.
1615320	1617080	So some possible mitigations.
1617080	1618000	How can we fix this?
1618000	1619720	How can we address this?
1619720	1621820	How can Microsoft address it?
1621820	1633200	Well, one is to randomize the LDR data table entry different, insert unpredictable offsets into that to break some of these fixed offset traversals.
1633200	1636860	So you can't just use these hard coded offsets.
1637200	1639420	So it's unpredictable gaps.
1639800	1647340	This could be done on a per process basis or just set up once each time you load the operating system.
1647340	1649100	Either way would be effective.
1649420	1659900	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.
1660040	1664300	We could also have privileged PEB access to that.
1664300	1667960	So block direct segment loading and user mode.
1667960	1669200	That could be an option.
1669300	1676820	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.
1676820	1681520	And we could check things like what is the control flow graph that led to that?
1681520	1685580	Did we follow a valid path or are we doing things that are kind of unusual?
1686480	1693780	So that would be a major architectural lift, but it would eradicate this set of bypasses.
1693920	1697580	Some other possibilities is pointer obfuscation or encryption.
1697580	1705620	So maybe we have encrypted values and so if you go and obtain it, it's not enough because it's encoded.
1705620	1707800	So you could use the Windows API.
1707800	1715460	It already has some pre-existing things that could be used or just simply even something as simple as an XOR key.
1715720	1728900	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.
1728900	1733120	We could also have approaches like fine-grained ASLR, dynamic ASLR.
1733340	1744300	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.
1744300	1747280	Dynamic ASLR where we have periodic rebasing.
1747280	1754260	So it may briefly be effective, but then it's going to change and so it no longer is useful or relevant.
1754280	1757620	So these would serve to complement not to replace ASLR.
1757840	1759580	And we could also have execute-only.
1759580	1767800	So you could have that implemented via hardware support, making PEB and loader pages non-readable.
1768840	1770940	How would the access be granted?
1770940	1774920	That would be something that would need to be carefully determined, but it could be viable.
1775840	1779660	We could also simply enhance the existing exploit detection.
1779660	1783700	So things like EAF and EAF plus have been around for a very long time.
1783700	1787620	So we may add some additional heuristics to that or Microsoft could.
1787720	1796420	And so flag some of these abnormal list entry walks and it wouldn't prevent it, but it could stop it from being effective.
1796940	1800500	All right, so let's dive into the ASLR mini bypass tool.
1800500	1803140	So this is built off of ROP rocket.
1803400	1809300	And what it will do is everything that we talked about, it can generate those complete ROP chains.
1809300	1815060	So if you wanted to do this and not have to spend the time to write the code, you simply use the tool.
1815340	1820360	So it does it in 64 bit and it will do all nine variants and it will output it as Python.
1820460	1823540	Here we can see a complete Python exploit script.
1823540	1825960	So it takes care of a lot of the mechanics there.
1825980	1829220	And we will zoom in on that here.
1829220	1834560	So one way is the PEB disclosure via the GS register.
1834560	1836560	So we can set that up and obtain that.
1836560	1839280	And it follows the various steps.
1839380	1843780	And it does it by kind of a hybrid approach of semantic searching.
1843780	1847680	So we may say, okay, I want to load a particular value into this register.
1847680	1850000	What are the different ways in which we could do that?
1850000	1858640	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.
1859140	1867400	We can also do it via the RDGS base, the NT query information process and the NT query information thread.
1867400	1877960	In this case, to obtain our writable and readable memory, we have it set to a particular location relative to the stack.
1877960	1882280	We use emulation to then calculate the distance to that.
1882280	1884260	And so we use that to provide the parameter.
1884260	1895900	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.
1895900	1900000	So this is actually a little bit more complicated than what I showed you.
1900220	1902340	And again, it's fully automated.
1902820	1910100	So it does it through those four methods, the GS register, RDGS base and then the two sys calls.
1910960	1914180	And if you get the ROP gadgets from it, then it should work.
1914180	1917820	It should be totally reliable if it provides those gadgets.
1919140	1922580	So nine bypass techniques are supported by the tool.
1922580	1929220	We have kernel 32, kernel base, NTDLL, and for all three of the different module lists.
1929240	1931260	And moreover, we implement them.
1931260	1937900	So actually it'll generate not nine, but actually nine times four, which is 36.
1938060	1940520	So we can do it for the GS register.
1940520	1941860	We'll get nine variants.
1941860	1951280	We can do it for the RDGS base, for the NT query information process, as well as the NT query information thread.
1951320	1953420	All of them will work.
1953720	1955900	And we'll see a demo momentarily.
1955900	1958320	But if you're interested, go ahead and take a picture.
1958320	1960280	It's going to be part of the ROP rocket.
1960280	1961860	I updated it about 3 a.m.
1962100	1966540	this morning, providing this additional functionality.
1968280	1970500	So tool demo time.
1986030	1987150	Okay, there we go.
1987150	1988030	So here's the tool.
1988030	1989290	We're running it.
1989470	1991350	And right now it's generating all of those.
1991350	1994310	It's going, you know, it's 36 of them and it's very fast.
1994570	2000010	Of course, this can vary from application to application and whatever the attack surface supports.
2000250	2004410	And also at the same time, it's going to write it all to file.
2004410	2007830	So obviously you don't want to copy and paste from a command console.
2007830	2010390	So you can take one of them and make use of it.
2010390	2013250	So a very effective tool.
2014590	2019850	So the disclosure timeline for Microsoft discloses April 15th.
2019850	2021690	I reported it to them.
2021690	2023170	May 2024.
2025290	2029590	Microsoft acknowledges the validity, decides to do nothing.
2029590	2030930	That's kind of unfortunate.
2031690	2037150	Microsoft in July, they asked to meet during Black Hat and then later I do meet with them.
2037150	2039130	Today I'm releasing the tool.
2041270	2048170	So I got an email from Microsoft, May 1st, 2024.
2048170	2059370	They claim the report is valid, but that they prioritize vulnerabilities that are assessed as important, critical severities for immediate servicing.
2059470	2066770	They don't consider an ASL bypass to be relevant if it doesn't cross a security boundary.
2066770	2073550	What that means is the fact that it relies on a preexisting vulnerability.
2076050	2077690	You know, but that is true.
2077690	2083050	But the goal of this is to be a multiplier or an enhancer.
2083530	2097290	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.
2097290	2104250	And it was disclosed publicly, not to them, but Microsoft did actually fix that.
2104250	2107250	This has been reported in April 2024.
2107250	2108390	They have not fixed it.
2108390	2111710	They have not shown any interest in fixing it, unfortunately.
2112190	2116610	It's sad that they don't care, but I guess that's the reality.
2117150	2118970	So some context for them.
2119910	2122810	Invited me to meet with them on July 11th.
2123390	2130190	I didn't acknowledge them for a couple weeks, but eventually I did agree to meet with them on the 22nd of July.
2130530	2136250	I got another detailed email on the 30th of July asking for detailed information.
2136250	2145110	My response was, can you provide me more information on why you decided to pay $0 for the bypass?
2145110	2150590	And my whole purpose of doing this was to hopefully obtain a bug bounty.
2151010	2156110	I didn't get a response, but I did get a response in person when I did meet with them.
2156110	2160870	So they did ask to meet and I met them on August 7th.
2160870	2165090	We spoke about 50 minutes in detail regarding the case.
2168370	2179870	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.
2179870	2187690	My thinking was you have your scope clearly defined on the website and I followed that.
2187690	2198990	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.
2199010	2200510	It's their choice.
2202690	2222170	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.
2222170	2225590	We could have then given them a bug bounty, but they didn't.
2225590	2229330	By the way, you should go and submit your vulnerabilities to us.
2229570	2241930	So it's disappointing that they make statements like that and then they publicly contradict their kind of general stance on that.
2242910	2249850	But in any case, they decided not to do that.
2250660	2255630	Why does this matter for Windows malware?
2255930	2260490	So we could go much further beyond simply what we have been talking about.
2260670	2272310	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.
2272310	2284190	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.
2284330	2289530	And by doing that, you can kind of hide and conceal what you are doing.
2289590	2300530	So if we were to fix that, then that would break it so that much of the current existing malware simply would not work.
2300710	2302290	It could work.
2303570	2307590	In that case, you would have to use normal imports.
2307810	2311930	That's something that could be easily detected from a static analysis standpoint.
2311930	2314590	A tool like PA Studio could easily enumerate that.
2314590	2317750	You could also do things like getprocaddress , a little library.
2317950	2323050	And those are also very easily detectable things from a static analysis standpoint.
2323050	2336950	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.
2338910	2357350	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.
2357350	2363870	You would have to drop it in a sandbox or do some type of dynamic execution.
2364310	2370750	So a massive, hugely impactful gain for defenders.
2370750	2373430	But I guess that's not important to them.
2373430	2386030	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.
2386030	2389630	Now, syscalls can be much more challenging to utilize.
2389630	2391170	They're a lot more complicated.
2391790	2398130	It's not something that every malware author would be able to do just because of the complexity of that.
2399370	2404730	And some functionality that could be easily implemented via Windows APIs.
2404850	2409030	The same thing may not be true necessarily for Windows syscalls.
2409590	2412990	So either way, it would be a huge win.
2412990	2423370	So some takeaways here is we have these existing structures, the peb, the modulus.
2423690	2426790	These have been a single point of failure.
2426790	2430870	They've been existing in this form for decades.
2431370	2436350	And, you know, it's an inherent design flaw and it should have been corrected a long time ago.
2436350	2439130	But unfortunately it has not.
2439130	2462530	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.
2462530	2469170	And how we can even take that and then automate that with a tool so you can accomplish that in seconds.
2469170	2477290	You could maybe have 30 seconds and then you have 36 different approaches of bypassing ASLR.
2477330	2479730	So it would be great if Microsoft would patch it.
2479730	2482210	They've really shown no interest in doing so.
2482210	2485130	And it's not really something that could be achieved with a patch.
2485130	2489550	It would need to be more of an architectural lift.
2489550	2507830	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.
2507830	2512490	Unfortunately, you know, Microsoft does not care.
2512490	2513670	They've made that clear.
2514970	2524270	But maybe someday in the distant future, we may see a more responsible approach that can preclude some of these attacks.
2524270	2528290	But I don't see that on the horizon for the immediate future.
2528990	2530790	So with that, I'd like to thank you.
2530950	2533250	DEF CON is an incredible place.
2533850	2535750	Very, very special place.
2535750	2537810	And thank you for coming to my talk.
2537810	2541410	But more importantly, thank you to all of you for coming to DEF CON.
2541710	2543190	Feel free to contact me.
2543190	2544070	You can email me.
2544070	2545950	You can check me out on GitHub.
2546030	2548010	The address of the tool is there.
2548070	2552690	Feel free to add me on LinkedIn or make contact, however you like.
2552890	2554630	I won't take any questions now.
2554630	2559010	But I'll step to the front there and then possibly outside.
2559010	2561350	So feel free to come and chat with me.
2561390	2562830	And thank you very much.
