Hi. Yeah. Thank you. Well, thank you for coming to my talk, because I know it's the last talk for today, so I guess everybody's pretty tired of seeing talks, but hopefully it will be interesting. So, the bug is a bug that I found by auditing PHP, but it's not on PHP. It's a bug in the glibc, and it targets iconf, which is the character set conversion library of the glibc. And I actually was able to use the bug to compromise the PHP engine in two different ways remotely, and this is what I'm going to talk about today. So, first I will describe how I found the bug. It was by complete accident, by complete chance, but the way I will explain it to you will serve as an introduction to the next section, which is going to be about attacking PHP filters. If you don't know what a PHP filter is, don't worry, I will explain what it is. And also, afterwards, I will attack a different way. I will attack PHP by targeting direct calls to iconf. And, well, after this, hopefully we'll have time for a conclusion and maybe a little bit of a bonus. So, regarding the discovery, well, to understand how I found the bug, we need to understand what you can do when you have a valid primitive in PHP. So, code such as this one, an fopen followed by an fread, like any valid primitive in PHP, what can you do with it? Well, obviously you can read a file, you can read ETC passwords, but you can also force PHP into reading HTTP resource, that would work, and FTP resource, that would work as well. And there are also other protocols that you can use, which are PHP-specific, such as far-colon-slash-slash. It will let you read the contents of a file archive. So, for those who don't know, a file archive, it's like a jar for Java, so it's a collection of source files, resources, and also in PHP, it contains serialized metadata. And when you access such a file using far-colon-slash-slash, the metadata will be deserialized. So, there was an attack for the longest time, that was that you could upload a file to a server, any file, an image, or anything, and then you would use your file with primitive to load it as a file, and that would give you arbitrary deserialization, which oftentimes meant RCE. Sadly, in PHP 8, they have disabled the deserialization of the metadata, because they actually don't use the metadata, so it was completely useless. And also, in older versions, big frameworks have been removing the far-colon-slash-slash protocol, because they don't use it, and they also know that it is very dangerous. Magento got completely demolished with the far-colon-slash-slash bug. There were hundreds of bugs reported to them using far-colon-slash-slash. So, they just removed it entirely. And also, it's going to be harder to exploit, even not on PHP 8, this bug, because deserialization is going to get harder and harder to exploit as time goes by, mainly because types are making a comeback. But that's probably a subject for another talk. So, people are taking the interest into another PHP-specific protocol, which is called PHP... well, you can guess it's PHP-specific. And there's a sub-part of this which is called PHP filter. And what it does is that it will read a resource and apply some filters that you have chosen onto it. It will then return the resource as if it was the original file, but with filters applied onto it. So, a good example of this, and probably the simplest one that you can get, is this string. So, you have PHP filter, then one filter which is convert.base64encodes. You can probably guess what it does. It converts to base64. And then the resource is etcpassword. So, what you get when you do a file get contents of this is file get... is etcpassword, sorry, but base64encoded. And the good thing about these filters is that you can stack as many as you want. So, instead of base64encoding once, I can do it twice, but I could also do it like a thousand times. It will work. Well, obviously, you can do other things than base64encodes. You might be able to put your string in uppercase with string.upper, or put it in lowercase with string.lower, and do some very, very old crypto with rod13. I don't know why it's there, but it actually works. And you can also use filters that are not documented, but very useful as an attacker, such as dchunk. I will talk about it later. And, well, you can also use the stuff for today, which is convert.iconv.x.y. And what it will do is that it will use the iconv library of the gdpc to convert your stream from charsetX to charsetY. Just to give you a quick example, say that you have etcpassword, you want to convert it from utf-8 to utf-16, you can use this PHP filter string, and it will do it automatically, as you can see in the xdump right underneath. So, well, these filters have been attacked a lot. There's been a lot of research on them. And the consensus in 2023 was that you could add, using filters, an arbitrary prefix to any file. So you could dump etcpassword with an arbitrary prefix just by picking the right filters to apply onto it. And myself, what I wanted to see was whether or not I could get an arbitrary suffix as well. So, an arbitrary prefix on some text, and then some suffix as well. And the idea is very simple. Say that you have this piece of code. Of course you have a far-read primitive, but then right afterwards you have a JSON decode. So if the file is not valid JSON, your far-read primitive is useless. You cannot read etcpassword. But if you can make your file look like JSON, using an arbitrary prefix and suffix, you can make the JSON decode work, and therefore you can make PHP think it's JSON and return to you the contents of etcpassword. And this research, it actually works. It has a few preconditions, but you can actually pull it off. And I call the tool VrapVrap, and I've made a blog post about it. It's on our company's blog, so I'mbertenix.io, as you can see on the bottom. And, well, the important part about this is that at the beginning I didn't know much when I started this research about PHP filters. So I built a few scripts just to try and do some conversions. So maybe from charset A to B, then apply a basic C4D code, then from C to D. Like, lots of conversions just to see what I could get as a result. And I actually got a crash while doing this, so I was pretty surprised. And I've been working with PHP for, like, 20 years, so I kind of felt like it was due to PHP, you know, because it's always PHP. But this time it wasn't PHP. It was actually due to the glibc, so the base library for most Linux programs. Because when PHP does the character set conversion using convert.iconv, it will use the iconv library of the glibc. And what this library does is that you pick an input charset and an output charset, and then you feed it buffers, and it will convert from your input buffer to the output buffer, from one charset to another. The thing is, when you call the icon function, you give it an input buffer with some size and an output buffer with some other size. And obviously, it should guarantee that it will now read more bytes in the input buffer than it should, or write more bytes than it should in the output buffer. And generally, it does so pretty well, like, there's no overflow. But sometimes it fails to do so, and this is exactly why I got my crash, is that when you convert to some very obscure charset, which is called ISO 2022CNX, in some cases, it will not check the bounds of the output buffer before writing some escape sequences. And that means that, as a result, as an attacker, if you are able to convert some text to ISO 2022CNX, you will get an overflow of one to three bytes with the very specific values that I've written here. So your overflow could be with $H, or $I, or $J, any of these six values, but only these six values. To give you a quick idea of the characters that you can use to trigger the bug, those are the characters that I trigger the bug with. So those are Chinese characters, I have no idea what they mean, but they give you a buffer overflow. So the vulnerability that we have, it's already pretty bad, like, it's a one to three bytes overflow, and it's fixed byte values, like, you don't control the bytes. In addition to this, you have horrible conditions, like, you have to control the output charset, you have to set it to ISO 2022CNX, like, nobody heard about it in the room, I guess. So, yeah, you need to find an application that will let you pick your output charset. Otherwise, you will not find an application that does it willingly. In addition to this, you need to control part of the input buffer so that you can put in the Chinese characters. And again, a third condition is that you need to have a suitable output buffer. If the output buffer is too small, sorry, too big compared to the input buffer, even though you may have an overflow in theory, you're not going to be able to reach the end of the bounds of the output buffer before you trigger your escape sequence, and therefore you will not overflow. And this is, like, what was the most annoying part in looking for targets for this bug, because I thought that I had a bug in libxml2, because you can send an encoding when you send your XML, but the output buffer, when it did the conversion, was way too big, and therefore I couldn't exploit. And that's only one of many. And so, after probably weeks of looking for targets, I got super frustrated, and I went back to PHP filters, because that's the only thing that I could make crash, and that's actually the only thing that crashed without even me trying for it to crash, so I was like, okay, that's probably my best bet to exploit this bug, and I focused onto it. And the idea was to convert file-read primitives in PHP, any file-read primitive, into remote code execution, straight up using this binary bug. So to explain to you how we might be able to do this, we need to think about how PHP does allocations and deallocations. For this, we need to understand PHP's heap, but don't worry, that's probably the simplest heap that you're ever going to see. So it's 512 pages of 0x1000 bytes each, so 4096 bytes, and each page contains chunks of some size, so it might be a chunk... In page 10, you may have chunks of size 0x100, in page 11, you may have chunks of size 0x30, et cetera, et cetera. Then when you free a chunk, it will go into the free list for this chunk size. So if I free a chunk of size 0x100, it will go into the free list for size 0x100. If I free a chunk of size 0x10, it will go into the free list for chunks of this size as well. And the free lists are singly linked lists, they are lasting first out, so that means that if I free a chunk of some size and allocate a new one afterwards, it will be allocated exactly at the same spot. And it's very similar for those who do PTMalloc exploitation to the libctcache, but completely unlimited and without any protections. So, just to give you an idea of what we can do with 1 to 3 bytes overflow in the PHP heap, let's have a look at this example. So, on the left you have the heap, with 512 pages, and in page 5, in this example, I have chunks of size 0x400. So, in page 5, I have 4 chunks. In my example, I have chunk 1 that is allocated, chunk 3 that is allocated, chunk 2 and 4 that are not. So, in chunk 2 and chunk 4, since they are in the free list for chunks of size 0x400, that means that they contain a pointer to the next free chunk. So, if I was to overflow even with 1 byte from chunk 1, I would be able to at least partially modify the pointer that is contained in chunk 2. And that would be a way to alter some free list pointer, and in the end, probably be a good starting point for an exploitation. So, the PHP heap, it looks very, very easy to exploit, right? There's no metadata, it's page-based, there's absolutely no protections, it's really easy to understand. So, why is it that there are not that many remote binary exploits? Well, to me, the main problem is that the PHP has the one heap for one request policy. So, if you send an HTTP request, PHP will create the heap, allocate your HTTP parameters into it, then run the script, so that means also compiling the script, so it will do like thousands of allocations and deallocations, and then it will completely destroy the heap. So, now imagine that you have a use-after-free on some VPN instance, for instance. What you would do to exploit would be to send a few requests to set up your heap, then one more request to trigger your bug, trigger your UAF, and then afterwards, send a few more requests to use your bug. But here, you cannot do this. You have to find a way to trigger a bug remotely, so you need a bug in the PHP engine, you need an application that lets you trigger the bug remotely, but also you need to use the bug as the request is running, before the heap is gone. And this is why it's hard, because in between the triggering of the bug and the usage of the bug, you're not going to have any way to interact with the HTTP request. Like, you've sent every HTTP parameter, and it's done. Like, it's a black box now. And this is, to me, why it's really, really hard to exploit on PHP remotely. Okay. So, in addition to this, there's one thing that we need to understand, is how PHP processes PHP filter strings. And to do so, you will have a two-step process, where you will first read the resource as a stream, and then you will apply filters, So, fetching the stream, it will use a very standard structure, which is called a bucket brigade, and each part of the stream is represented as one bucket of a few bytes. So, for instance, if you read the password, the first bucket may contain five bytes of its password, then the second bucket will contain the next few bytes, for instance, ten bytes, and the bucket three will contain a few more bytes that come right after, et cetera, et cetera, et cetera. So that's a way to be able to represent any stream. A list of buffers that are linked together, and that may have different sizes. Once you have your stream, you can start applying filters onto them. So you take the first filter, and you take the first bucket, and you apply the filter onto it. So, for instance, if it's base64 decode, PHP will take the first bucket, and decode the data that is into it. Then it will be able to process bucket two, which it will do, and then bucket three. And at the end, you get a new bucket brigade, on which the first filter has been applied. So what you can do, is start working on the second filter, then on the third one, et cetera, et cetera, up until the end. And now you have a stream that has been completely processed with filters, and your PHP filter string has been completely, perfectly handled. So, if we look back at everything now, it looks pretty easy to exploit this far read, because we have a far read primitive, and we want to get our C, but since we have a far read primitive, well, first we can read the binaries. So, if I want to have the address of some symbol, for instance, in the libc, I just download the libc using the far read primitive. If I want to check if the libc is patched against the bug, I can also download the libc and check the code myself, you know? So that means that you can find gadgets easily. In addition to this, ASLR and Pi are not a problem, because I can just read Proxet Maps. So, any address that I want is going to be probably in Proxet Maps, so ASLR and Pi, it's gone. A corollary to this is that the address of the PHP heap is really easy to find in Proxet Maps, so I have the address of the PHP heap, which is going to be useful later. In addition to this, it kind of feels like that I can do arbitrary allocations on the allocations simply using the bucket brigade technology, so the way that the stream is represented. If I can create as many buckets as I want with the sizes that I want, I will probably be able to build an exploit that works. But on the other side, I kind of want to have an exploit that works well even in an unknown environment, so I don't want to build a new exploit when I'm targeting WordPress or some very specific version of PHP or some Magento, which has a lot of traffic on the website. I want an exploit that just straight up works, like basically a web exploit, even though it's binary. And also bonus points if it doesn't match. So, how can we do this? Well, the first problem that we face is that even though there is the bucket brigade technology in PHP, you will always get one bucket when you read a stream. So, if PHP reads the ETC password, it will give you one bucket with the whole file. If it reads an HTTP resource, it will give you one bucket with the whole HTTP response into it. Same for FTP, same for everything. You always get one bucket. And one bucket, it's completely impractical for exploitation, because we cannot spray the heap, we cannot pad the heap, and we can't even use an altered freelist. Like, if we use one bucket to trigger the overflow, we have an altered freelist, but then we need at least two more locations to be able to use this altered freelist, and we cannot do this because we have used our single bucket, so we're not going to be able to exploit. Luckily for us, there's a single filter that allows us to create as many buckets as we want, and this filter is zlib-inflate. What it does is that it will read your stream and decompress it, as with the zlib algorithm. And the way it works is that it will allocate eight pages, a buffer of eight pages, and then decompress into it. If it's not big enough, it will create eight more pages and decompress the rest into it. If it's still not big enough, it will create a third bucket, et cetera, et cetera, et cetera. So this filter, it gives us a way to go from one bucket to as many as we want. But the problem that we have is that every bucket has a size of eight pages, which is way too big to exploit because it takes too much space, and also it's not going to be allocated the same way as small chunks. So we need a way to change the size of each of these buckets. And a way to do this is to use another filter, which is called dchunk. It's undocumented, but it's been used by many hackers before, so it's pretty well known. And the idea is that it will take an HTTP chunked encoded string and simply decode it. So for those who don't know, the HTTP chunked encoding is very simple. It consists of sending a size as ASCII X and then sending the data, and then a new size as ASCII X and then sending the data, etc. So the dchunk filter, what it does is that it will read a size as ASCII X, then read the amount of bytes that correspond to this size. So for instance, if it reads 8, as in the example, it will read 8 bytes. Then it will read 11, and since it's ASCII X, it's 17, so it will read 17 bytes. And then it will read D, read the D bytes, and then it will read 0. And 0, it doesn't indicate an empty chunk, it indicates the end of the dchunking. So when it receives 0, it stops processing the data. So, now you probably have an idea of how we can resize our chunks. We take bucket 1, if we want it to have a size of 148, we write 148, then 148 bytes, and then 0. If we want bucket 2 to have a size of 100, we do the same. We write 100, then all bytes, and then 0. And we do the same with every chunk. And then when we apply dchunk onto this, we expect it to resize every single bucket. But you may notice that this won't work, because even though each bucket is different, they are all processed as one stream. So if in bucket 1, you indicate that it's the end of the stream, with the 0 at the very bottom, it will not process bucket 2, it will not process bucket 3, it will not process any bucket that comes after. So you go back to a single bucket with an arbitrary size, which is completely useless. So luckily for us, there's a way to improve this. And the way to improve this is to pad the size with thousands of 0s, such as what we can see here. The idea is that in each bucket, we will have one chunk size and one chunk data. And that's it. Nothing else. So now if the dchunk filter is applied, we will have bucket 1 that gets processed, it will read the size, read thousands of 0s, then the real size, then the data, and then it will go onto bucket 2 and do exactly the same. It will read the size, read the data, then bucket 3, read the size, read the data. And you can see that bucket 1 can be resized to the proper size, bucket 2 as well, bucket 3 as well, and bucket 4 as well. And now we have a way to create as many buckets as we want, and change the size. And this is only with two filters, so it's pretty promising. But that's not enough, because we can only send one request, so we need a whole exploit algorithm in a single request, and with a single PHP filter string. So how do we do this? Well, instead of only being able to allocate once, we kind of want to be able to allocate several times to represent the different steps of the exploit. In step 1 I want to allocate a few chunks, in step 2 I want to allocate a few more chunks, et cetera, et cetera. And at this point we are not able to do this. But to do this, what we can do is think about the PHP heap. It's page-based. So if I focus my exploitation on one chunk size, a single chunk size, that means that chunks that are bigger or smaller than this chunk size, they do not really matter. I will not have to think about them in my exploit algorithm. If a chunk is of size 0x200, for instance, and I'm focusing on chunks of size 0x100, the chunk will not affect my exploitation. So at this point, if I focus on some very specific chunk size, such as 0x100, chunks that are bigger or smaller, they do not matter. It's as if they weren't there. So the only thing that I need to be able to do is to be able to resize buckets as the exploitation goes on. And to be able to do this, I built buckets that are Russian dolls of dchunk algorithm. So the idea is that every time I call dchunk on some buckets, its size will change. And that means that I can make buckets appear at some point in the exploitation, and then others appear at another step of the exploitation. And that basically means that I can allocate and deallocate at will. And at this point, I'm really, really close to getting an exploit working. And the final idea here is that we have a one-byte overflow, using the icon bug. And we want to use it to alter some freelist and get complete control over it. And the way that we can do this is a six-step process, which is pretty simple, but I will still explain it to you. First, we will start in step one. And we're going to have three chunks, A, B, C. And each chunk is freed. We have A that points to B, and B that points to C. Then we allocate these three chunks, and we free them. We get in step three, and the only difference with step one is that now we have C that points to B that points to A. So we have reversed the freelist. Now we allocate in C a buffer, which contains at offset 48, an arbitrary pointer, which is represented here with 1, 1, 2, 2, 4, 4, etc. Then we allocate B and A, and then we free everything. And we get into step five. And we have exactly the same E-playout and freelist as in step one, but in the chunk C, we have an arbitrary pointer at offset 48. So now you can probably see where this is going. We overflow using chunk A into chunk B. So the freelist that was B to C is now B to C plus 48. And what we have in C plus 48 is another pointer that we added ourselves. So with three more allocations, we will allocate B, C plus 48, and then we will allocate our arbitrary pointer. And now we are able to have a write-what-where, which is really, really close to getting code execution. But now we have to think about how we can do this. Well, as I've said before, the PHP heap, it's really easy to find it in Proc Setmaps, so we have it for us. And also, at the very top of the PHP heap, there is a send-mmheap structure that contains a few things, and also a few alternative heap function pointers. So for those, again, we do heap exploitation on ptMalloc, it would be the same as free-hook, malloc-hook, and realloc-hook. Those are pointers that, if you set them to something else that null, they're going to be called inside of the original function. And so, since it's basically the same as the glibc, I can use the glibc technique, and I can override free with system. So now, when PHP wants to free a chunk, it will call free, but it will instead call system. And this gives me a way to call an arbitrary comment. And so, with everything put together, what do we have? We have an exploit that works against any target, from PHP 7 to the current version, which is H3-something. So that's 10 years of PHP covered with a single binary exploit. And also, it works against any PHP application, because we can pad the heap, so even if the website uses a lot of chunks of size 800, it will still work. It doesn't matter. In addition to this, the exploit is completely deterministic, so it's 100% reliable, so you will never get a crash. So it's pretty cool. And the final good thing about the exploit is that the payload is really small, because the first gadget that we use, the first filter that we use, is a Zlib inflate, so it will decompress the payload. So originally, it's compressed, so it's very small. And the last good thing that we can say about the exploit is that it's completely self-contained. The whole algorithm of the exploit is in one PHP filter string, which means that you don't have to send additional GET or POST parameters. You just need your PHP filter string, and you get RCE. So every file reading primitive now that you have on PHP, you have RCE instead, which is pretty nice. I'm going to show you a demo that actually involves Cosmic Sting, which is a Magento X6E, which is pre-authentication. And it came out after I published my bug, so it was in June. And the original impact was being able to read files. And using these files that you've read, you would be able to craft API keys, and so you would get an access which is similar to an administrator level on Magento. But you wouldn't be able to get RCE. But with the bug that we have now, we get RCE easily because we have an X6E, so we can force it into reading any file, and therefore we can read a PHP filter string and get RCE. So, quick demo, which is not on the right screen. There we go. So, I cannot see it, but it's quite easy to understand. You have the Magento website on the left, and then you have an exploit on the right, and in a few moments, you will have a shell on the bottom. There you go. There we go. Thank you, man. So, oh, I lost my... On the other screen, I lost it. Wait. Okay, there we go. Okay, does that work? Yeah. Okay, so now that we have exploited PHP filters, we want to do a completely different exploitation, because PHP filters are not the only way in which you can reach ICONF using PHP. There's another way that is way simpler. It is when PHP calls ICONF directly. And so, there's a PHP function that does this. It's called ICONF. So, how do we exploit such a call to ICONF? Well, it's very, very different to the attack that we've seen using PHP filters. So, here we don't have a five-read primitive, so we cannot just read proxmaps or read the libc or anything. We need to go, I would say, old-school exploitation, where we need an infoleak to get some pointers, and then we can start going with the exploitation. And in PHP, generally, when you want to have an infoleak, what you do is that you will try and alter the length field of a ZenString. So, a ZenString, it's the representation of PHP of your PHP string. And the length field, it will store the size of the string. So, if you are able to change the length of a string, and then it gets displayed, well, you are able to make PHP display more bytes than it should, and probably display lots of useful information from the heap, such as addresses. Sadly for us, the bug that we have, as I've said, really, really bad. We only have one to three bytes overflow. So, if we try to overflow into a ZenString, we will just overwrite the ref count, with values that we don't even control, so it's pretty useless. So, what we need to do is kind of the same as before, where we alter some free lists, and if we manage to alter some free lists, we are able to make two chunks overlap. And if we have two chunks that overlap, we can use the first one to store a string that is bound to be displayed, and then use the second one on top of it to overwrite the length field. And when the string gets displayed, we actually are able to see what comes afterwards in memory. The problem is that here, we completely rely on the code. Beforehand, we could implement an algorithm using PHP filters, as I've shown, but here we only have a single call to iconf, and that's it. Nothing else. So, getting it to work would make us reliant on the code that comes after the call to iconf. And to explain this, a very simple example. Say that you have this piece of code. We control the output charset, we control the input text, so it's clear that we can trigger the bug. But right after the bug has been triggered, the script will end. So, there's absolutely no way for us to use the bug after it's been triggered, because the heap will be destroyed. If you're lucky, however, you might find a line such as this one after your call to iconf. This line is the same as split in Python, so it will take a string and split it along a token, so here the token is newline. If you have a line such as this one, you can create as many chunks as you want, because it will take your string and split it along a known separator. And that will give you a way to use the bug right after it's been triggered, and then probably exploit the bug. So, this is what I call a code gadget, actually. That's a way to get to using your bug, starting from the position where iconf has been called. And to give you an idea of how it can be implemented in the real world, I will show you a demo, well, and explain to you the demo on Roundcube. Roundcube, for those who don't know, it's a webmail that is very much used. It's probably the most well-known in PHP. It's used by hosters generally, or private companies even, I've seen it a lot. And, well, yeah, it's used a lot. And so, when you're logged into Roundcube and you want to send an email, you have to specify email addresses. And so, you specify the two fields, the cc field and the bcc field. You can guess what they are, you've already sent an email. In addition to this, you can send another parameter, which is charset. And every parameter that you send, so the underscore 2, underscore cc, and underscore bcc parameter, they are all going to be cast to the charset that you've set. And it's going to be done using iconf. So, in this single script here, you have three ways of triggering your bug. You can trigger it using underscore 2, or with underscore cc, or with underscore bcc. And right after this, there's something even better. If one of the emails is not valid, you will get an error message that says, well, this is an invalid email, colon, your email. So, what can we do with this? Well, this is textbook, the strategy that I was telling you about before. The idea is that you set underscore 2 to an invalid email, so that invalid email gets set. It's ready to be displayed in the error message. So, now what we want to do is modify its length before it's included in the error message. So, then we use cc to trigger the bug, and we have a free list that is altered. And then we use bcc to allocate a few strings, so that we have a string that gets allocated on top of invalid email, and this will alter its size. And therefore, the error, when it gets displayed, will display more bytes than it should, and we will be able to get a memory leak, which is nice. So, I implemented this, and it was really fast. It took me a few hours, so I was really happy with it, and I started it, and it didn't work. And the reason for this is that when Roundcube sends an error message, it's converted to JSON. And when PHP converts to JSON, every byte that is not valid UTF-8 is removed. So, you have a memory leak, but you don't really have any bytes of interest, because generally addresses are not going to be valid UTF-8, so they're just going to be removed. Any raw data in memory is not going to be valid UTF-8, it's going to be removed. So, what you get is a memory leak, which consists of only ASCII characters and new bytes, which is completely useless. But, the idea is pretty good still. We still want to do the same thing, but we just need to find a string that will not get modified too much before it's displayed. And to do that, we just have to look at the framework and go a little bit deeper, look at many, many functions, up until we find a variable that gets displayed without being modified. Sadly for us, when it gets displayed without being modified, it will not have a lot of codes in between the creation of the variable and the display of the variable. So, it limits the number of gadgets that we can use. And, well, it's honestly pretty much hell to make this work, but you have to think that every line that you can use, like every line in the code, you can use it to go closer to your goal. Like, every line can be an allocation or deallocation that would shape the heap better for you. And I actually managed to pull that off in, I think, five days. It was really, really long. And I actually managed to get the leak. So, it was nice, because afterwards, it's pretty easy to get ASCII. Once you have an address of some value in the PHP heap, you can just reproduce the same exploit, but this time, use your freelist corruption to allocate at an arbitrary position. And that means that you can do data-only attacks, where you overwrite some value that is in your session, for instance. Maybe you want to overwrite your roles and set them to admin, or maybe you want to overwrite serialized data before it's deserialized, so that you have an arbitrary and serialized in PHP. Or, you can also go the standard way, where you go for a binary attack, where you want to control MIP. You started with binary, and you want to go full binary. But I think the data-only attack is more elegant, and it fits more, because you don't have to dump the binary. So, it's easier. But, like all of this that I'm saying, it's actually only the visible part of the iceberg. It's really, really hard to pull off, because first, you need a proper heap setup. I haven't covered this part, so it's really hard to do, because the only thing that you can use to do your heap setup is HTTP parameters, but then the script gets compiled, and you will use other scripts. They all get compiled in the same heap, so you will completely mess up the heap. It's really annoying to pull off. In addition to this, variable scope is here. If you have a method that is called, and then it exits the method, every variable that is in the method is going to be freed. So, it will completely change the heap as well. And also, obviously, it's very specific. Your attack to the server that you're targeting, the application that you're targeting, and also the settings. I think the original exploit that I built, it was for Roundcube in French. If I changed the language to English, it wouldn't work, because the strings that get allocated with error messages, they wouldn't be the same, and that would completely change the shape of the heap. So again, it's a huge pain to pull off, so don't do it unless it's really necessary. But it works! And I will show you an exploit, hopefully, if I can make it appear again. Oh, I'm paused. There we go. Now I need to find... Okay, same layout. You get a shell on the very bottom, an exploit on top of this, and the application on the left. And now I need to remove it again. Which one of these? This one? Nope. Nope. Yeah. Okay. A quick conclusion, and maybe a few more words afterwards. So the bug was really bad, honestly. It had lots of preconditions, and even the bug was not that good. A really bad overflow. But luckily for us, PHP exists, and we actually are able to do decent things with it. We have a new attack vector, where we convert a favorite primitive into an RCE on any PHP version, against any target. If you have a favorite primitive, you have RCE now. It's pretty nice. And also, you add application-specific attacks, such as the one I've demonstrated on Runcube. However, the bug is not PHP-specific, so there could be a lot of other targets. I couldn't find any, but maybe you will. And they might be discovered as time goes by, if people try to find a way to exploit the bug. The timeline goes fast. I found the bug last year, and I started exploiting it in February. After a month and a half, I could report it to the GDBC security team, and they were really amazing. They were really fast. After a week, I got a patch, and they were really nice. They knew what they were doing, which is not always the case, to say the least. So the bug got patched in a week, and two weeks after the embargo, it was released as CVE-2024-2961. That's probably the end of it for me. I have published lengthy blog posts about the bug, because there's so much to say about the bugs. And also, the impact on the PHP ecosystem, which I couldn't cover here, because we only have 45 minutes. And also, there are exploits that are available on our GitHub. And also, there's my Twitter, if you want to ask questions. You can also ask some questions right after the talk. And just to flex a little bit, a few what-ifs. What if we have a Fargate primitive, but we cannot see the output? We have Fargate contents, but no echo in front of it. So we cannot read FoxFMaps. We cannot read any binary. So the exploitation that I've shown you, it doesn't work. And also, in some very, very rare cases, zlibin-fake will not be present. You will not be able to decompress your stream, so you will have to exploit with one single pocket. And that looks impossible. But I was able to do both at the same time. That was actually my very first exploit. And I will try and show you how. It's just a demo, really sped up, because it's really slow. But, well, at the end you get a shell. The important part is on the left, the source code. You can see at the very bottom, you have a Fargate contents without an echo or anything. So I don't have the output. And also, on top of this, I have arbitrary allocation, uh, random, sorry, allocations and deallocations. Just to show that the script is not very, that it's not tailored to attack one PHP script. Like, it could work against any PHP instance. And, yeah, the exploit is not done yet. It's sped up like eight times, I think. It's really, really slow. But you get one byte per one byte, and at the end you have another shell. So, yeah, that's it. Okay, I'm getting close. No. Yeah. There we go. Questions? Okay, I guess we're good. Ah, there's one. Yeah, thank you. This is amazing. Uh, so, how did you get to the Roundcube target and establish that those conditions were present that you were looking for? Um, so, I thought that, like, emails to me... When you send an email, you can kind of send the charset with it. So I kind of felt like webmails would be a good target to look at. And I looked at Roundcube. And I saw that, like, it was a good target. So, yeah, that's why. Oh, cool. Pure intuition. That's amazing. Thanks. Well, thank you for listening to my talk.