1 00:00:01,780 --> 00:00:02,580 Hi. 2 00:00:03,980 --> 00:00:04,740 Yeah. 3 00:00:05,240 --> 00:00:06,240 Thank you. 4 00:00:08,040 --> 00:00:16,540 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. 5 00:00:17,100 --> 00:00:21,900 So, the bug is a bug that I found by auditing PHP, but it's not on PHP. 6 00:00:21,900 --> 00:00:29,160 It's a bug in the glibc, and it targets iconf, which is the character set conversion library of the glibc. 7 00:00:29,740 --> 00:00:38,920 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. 8 00:00:40,040 --> 00:00:43,580 So, first I will describe how I found the bug. 9 00:00:43,580 --> 00:00:54,800 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. 10 00:00:54,800 --> 00:00:58,480 If you don't know what a PHP filter is, don't worry, I will explain what it is. 11 00:00:58,480 --> 00:01:02,220 And also, afterwards, I will attack a different way. 12 00:01:02,220 --> 00:01:05,860 I will attack PHP by targeting direct calls to iconf. 13 00:01:06,120 --> 00:01:12,160 And, well, after this, hopefully we'll have time for a conclusion and maybe a little bit of a bonus. 14 00:01:13,200 --> 00:01:22,480 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. 15 00:01:22,480 --> 00:01:33,140 So, code such as this one, an fopen followed by an fread, like any valid primitive in PHP, what can you do with it? 16 00:01:33,200 --> 00:01:44,420 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. 17 00:01:44,600 --> 00:01:52,800 And there are also other protocols that you can use, which are PHP-specific, such as far-colon-slash-slash. 18 00:01:52,800 --> 00:01:58,320 It will let you read the contents of a file archive. 19 00:01:58,320 --> 00:02:08,540 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. 20 00:02:08,560 --> 00:02:14,560 And when you access such a file using far-colon-slash-slash, the metadata will be deserialized. 21 00:02:14,740 --> 00:02:32,160 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. 22 00:02:33,320 --> 00:02:41,660 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. 23 00:02:41,820 --> 00:02:53,460 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. 24 00:02:53,660 --> 00:02:58,660 Magento got completely demolished with the far-colon-slash-slash bug. 25 00:02:59,000 --> 00:03:03,340 There were hundreds of bugs reported to them using far-colon-slash-slash. 26 00:03:03,340 --> 00:03:05,160 So, they just removed it entirely. 27 00:03:05,800 --> 00:03:17,760 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. 28 00:03:17,760 --> 00:03:20,020 But that's probably a subject for another talk. 29 00:03:21,480 --> 00:03:26,580 So, people are taking the interest into another PHP-specific protocol, which is called PHP... 30 00:03:26,580 --> 00:03:29,240 well, you can guess it's PHP-specific. 31 00:03:29,360 --> 00:03:32,360 And there's a sub-part of this which is called PHP filter. 32 00:03:32,380 --> 00:03:38,660 And what it does is that it will read a resource and apply some filters that you have chosen onto it. 33 00:03:39,620 --> 00:03:44,680 It will then return the resource as if it was the original file, but with filters applied onto it. 34 00:03:44,680 --> 00:03:48,960 So, a good example of this, and probably the simplest one that you can get, is this string. 35 00:03:48,960 --> 00:03:52,980 So, you have PHP filter, then one filter which is convert.base64encodes. 36 00:03:52,980 --> 00:03:54,400 You can probably guess what it does. 37 00:03:54,400 --> 00:03:55,540 It converts to base64. 38 00:03:55,540 --> 00:03:57,960 And then the resource is etcpassword. 39 00:03:58,220 --> 00:04:02,900 So, what you get when you do a file get contents of this is file get... 40 00:04:02,900 --> 00:04:06,200 is etcpassword, sorry, but base64encoded. 41 00:04:06,480 --> 00:04:10,180 And the good thing about these filters is that you can stack as many as you want. 42 00:04:10,180 --> 00:04:16,360 So, instead of base64encoding once, I can do it twice, but I could also do it like a thousand times. 43 00:04:16,360 --> 00:04:17,280 It will work. 44 00:04:18,860 --> 00:04:21,940 Well, obviously, you can do other things than base64encodes. 45 00:04:21,940 --> 00:04:32,800 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. 46 00:04:32,800 --> 00:04:35,300 I don't know why it's there, but it actually works. 47 00:04:35,520 --> 00:04:41,780 And you can also use filters that are not documented, but very useful as an attacker, such as dchunk. 48 00:04:41,780 --> 00:04:43,020 I will talk about it later. 49 00:04:43,020 --> 00:04:48,520 And, well, you can also use the stuff for today, which is convert.iconv.x.y. 50 00:04:48,520 --> 00:04:57,000 And what it will do is that it will use the iconv library of the gdpc to convert your stream from charsetX to charsetY. 51 00:04:57,040 --> 00:05:11,800 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. 52 00:05:13,800 --> 00:05:18,780 So, well, these filters have been attacked a lot. 53 00:05:18,780 --> 00:05:20,700 There's been a lot of research on them. 54 00:05:20,700 --> 00:05:28,500 And the consensus in 2023 was that you could add, using filters, an arbitrary prefix to any file. 55 00:05:28,500 --> 00:05:35,260 So you could dump etcpassword with an arbitrary prefix just by picking the right filters to apply onto it. 56 00:05:35,520 --> 00:05:40,920 And myself, what I wanted to see was whether or not I could get an arbitrary suffix as well. 57 00:05:40,920 --> 00:05:45,660 So, an arbitrary prefix on some text, and then some suffix as well. 58 00:05:45,660 --> 00:05:47,140 And the idea is very simple. 59 00:05:47,140 --> 00:05:48,780 Say that you have this piece of code. 60 00:05:48,860 --> 00:05:52,720 Of course you have a far-read primitive, but then right afterwards you have a JSON decode. 61 00:05:52,720 --> 00:05:56,760 So if the file is not valid JSON, your far-read primitive is useless. 62 00:05:56,760 --> 00:05:58,420 You cannot read etcpassword. 63 00:05:58,420 --> 00:06:13,000 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. 64 00:06:13,020 --> 00:06:15,200 And this research, it actually works. 65 00:06:15,200 --> 00:06:18,560 It has a few preconditions, but you can actually pull it off. 66 00:06:18,560 --> 00:06:23,180 And I call the tool VrapVrap, and I've made a blog post about it. 67 00:06:23,180 --> 00:06:27,880 It's on our company's blog, so I'mbertenix.io, as you can see on the bottom. 68 00:06:28,220 --> 00:06:36,640 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. 69 00:06:36,680 --> 00:06:40,680 So I built a few scripts just to try and do some conversions. 70 00:06:40,680 --> 00:06:45,720 So maybe from charset A to B, then apply a basic C4D code, then from C to D. 71 00:06:45,720 --> 00:06:49,860 Like, lots of conversions just to see what I could get as a result. 72 00:06:49,860 --> 00:06:53,440 And I actually got a crash while doing this, so I was pretty surprised. 73 00:06:53,640 --> 00:07:01,120 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. 74 00:07:01,140 --> 00:07:02,800 But this time it wasn't PHP. 75 00:07:02,940 --> 00:07:08,420 It was actually due to the glibc, so the base library for most Linux programs. 76 00:07:08,480 --> 00:07:15,140 Because when PHP does the character set conversion using convert.iconv, it will use the iconv library of the glibc. 77 00:07:15,260 --> 00:07:26,440 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. 78 00:07:27,340 --> 00:07:34,200 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. 79 00:07:34,200 --> 00:07:43,840 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. 80 00:07:43,840 --> 00:07:47,200 And generally, it does so pretty well, like, there's no overflow. 81 00:07:47,400 --> 00:08:06,540 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. 82 00:08:06,920 --> 00:08:18,940 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. 83 00:08:18,940 --> 00:08:26,540 So your overflow could be with $H, or $I, or $J, any of these six values, but only these six values. 84 00:08:28,000 --> 00:08:34,900 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. 85 00:08:35,120 --> 00:08:39,580 So those are Chinese characters, I have no idea what they mean, but they give you a buffer overflow. 86 00:08:41,720 --> 00:08:50,540 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. 87 00:08:50,600 --> 00:09:00,340 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. 88 00:09:00,340 --> 00:09:04,420 So, yeah, you need to find an application that will let you pick your output charset. 89 00:09:04,420 --> 00:09:07,200 Otherwise, you will not find an application that does it willingly. 90 00:09:07,500 --> 00:09:13,200 In addition to this, you need to control part of the input buffer so that you can put in the Chinese characters. 91 00:09:13,580 --> 00:09:18,240 And again, a third condition is that you need to have a suitable output buffer. 92 00:09:18,360 --> 00:09:33,800 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. 93 00:09:33,900 --> 00:09:49,620 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, 94 00:09:49,620 --> 00:09:50,780 and therefore I couldn't exploit. 95 00:09:50,780 --> 00:09:53,000 And that's only one of many. 96 00:09:53,000 --> 00:10:08,500 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, 97 00:10:08,500 --> 00:10:15,000 so I was like, okay, that's probably my best bet to exploit this bug, and I focused onto it. 98 00:10:15,020 --> 00:10:24,020 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. 99 00:10:24,760 --> 00:10:32,040 So to explain to you how we might be able to do this, we need to think about how PHP does allocations and deallocations. 100 00:10:32,740 --> 00:10:38,380 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. 101 00:10:38,520 --> 00:10:50,000 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... 102 00:10:50,000 --> 00:10:56,260 In page 10, you may have chunks of size 0x100, in page 11, you may have chunks of size 0x30, et cetera, et cetera. 103 00:10:56,940 --> 00:11:01,520 Then when you free a chunk, it will go into the free list for this chunk size. 104 00:11:01,700 --> 00:11:06,180 So if I free a chunk of size 0x100, it will go into the free list for size 0x100. 105 00:11:06,180 --> 00:11:12,120 If I free a chunk of size 0x10, it will go into the free list for chunks of this size as well. 106 00:11:12,340 --> 00:11:22,940 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. 107 00:11:23,140 --> 00:11:33,160 And it's very similar for those who do PTMalloc exploitation to the libctcache, but completely unlimited and without any protections. 108 00:11:34,360 --> 00:11:41,600 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. 109 00:11:41,600 --> 00:11:50,540 So , on the left you have the heap, with 512 pages, and in page 5, in this example, I have chunks of size 0x400. 110 00:11:50,700 --> 00:11:53,020 So, in page 5, I have 4 chunks. 111 00:11:53,340 --> 00:11:59,180 In my example, I have chunk 1 that is allocated, chunk 3 that is allocated, chunk 2 and 4 that are not. 112 00:11:59,340 --> 00:12:07,880 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. 113 00:12:08,260 --> 00:12:19,220 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. 114 00:12:19,420 --> 00:12:27,680 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. 115 00:12:29,720 --> 00:12:33,900 So, the PHP heap, it looks very, very easy to exploit, right? 116 00:12:33,900 --> 00:12:39,300 There's no metadata, it's page-based, there's absolutely no protections, it's really easy to understand. 117 00:12:39,300 --> 00:12:43,240 So, why is it that there are not that many remote binary exploits? 118 00:12:43,240 --> 00:12:49,640 Well, to me, the main problem is that the PHP has the one heap for one request policy. 119 00:12:49,800 --> 00:13:03,440 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. 120 00:13:03,680 --> 00:13:08,260 So, now imagine that you have a use-after-free on some VPN instance, for instance. 121 00:13:08,840 --> 00:13:20,660 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. 122 00:13:20,960 --> 00:13:23,160 But here, you cannot do this. 123 00:13:23,160 --> 00:13:35,460 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. 124 00:13:35,460 --> 00:13:43,900 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. 125 00:13:43,900 --> 00:13:47,000 Like, you've sent every HTTP parameter, and it's done. 126 00:13:47,000 --> 00:13:48,340 Like, it's a black box now. 127 00:13:48,720 --> 00:13:54,240 And this is, to me, why it's really, really hard to exploit on PHP remotely. 128 00:13:59,640 --> 00:14:00,480 Okay. 129 00:14:00,500 --> 00:14:06,440 So, in addition to this, there's one thing that we need to understand, is how PHP processes PHP filter strings. 130 00:14:06,620 --> 00:14:28,200 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. 131 00:14:28,200 --> 00:14:40,520 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, 132 00:14:40,520 --> 00:14:41,820 et cetera, et cetera, et cetera. 133 00:14:41,860 --> 00:14:45,080 So that's a way to be able to represent any stream. 134 00:14:45,080 --> 00:14:48,960 A list of buffers that are linked together, and that may have different sizes. 135 00:14:51,560 --> 00:14:55,320 Once you have your stream, you can start applying filters onto them. 136 00:14:55,320 --> 00:14:59,820 So you take the first filter, and you take the first bucket, and you apply the filter onto it. 137 00:15:00,240 --> 00:15:07,040 So, for instance, if it's base64 decode, PHP will take the first bucket, and decode the data that is into it. 138 00:15:07,040 --> 00:15:11,280 Then it will be able to process bucket two, which it will do, and then bucket three. 139 00:15:11,360 --> 00:15:15,900 And at the end, you get a new bucket brigade, on which the first filter has been applied. 140 00:15:16,040 --> 00:15:22,620 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. 141 00:15:22,660 --> 00:15:31,060 And now you have a stream that has been completely processed with filters, and your PHP filter string has been completely, perfectly handled. 142 00:15:32,500 --> 00:15:43,320 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. 143 00:15:43,320 --> 00:15:50,620 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. 144 00:15:50,640 --> 00:15:55,960 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? 145 00:15:56,400 --> 00:15:59,180 So that means that you can find gadgets easily. 146 00:15:59,220 --> 00:16:03,880 In addition to this, ASLR and Pi are not a problem, because I can just read Proxet Maps. 147 00:16:04,180 --> 00:16:11,320 So, any address that I want is going to be probably in Proxet Maps, so ASLR and Pi, it's gone. 148 00:16:11,700 --> 00:16:20,780 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. 149 00:16:21,020 --> 00:16:31,420 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. 150 00:16:31,420 --> 00:16:37,840 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. 151 00:16:39,420 --> 00:16:54,160 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. 152 00:16:54,180 --> 00:16:59,040 I want an exploit that just straight up works, like basically a web exploit, even though it's binary. 153 00:16:59,100 --> 00:17:01,440 And also bonus points if it doesn't match. 154 00:17:02,640 --> 00:17:04,620 So, how can we do this? 155 00:17:04,620 --> 00:17:12,180 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. 156 00:17:12,180 --> 00:17:16,280 So , if PHP reads the ETC password, it will give you one bucket with the whole file. 157 00:17:16,280 --> 00:17:22,620 If it reads an HTTP resource, it will give you one bucket with the whole HTTP response into it. 158 00:17:22,620 --> 00:17:24,180 Same for FTP, same for everything. 159 00:17:24,180 --> 00:17:25,580 You always get one bucket. 160 00:17:25,680 --> 00:17:33,720 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. 161 00:17:33,720 --> 00:17:45,820 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. 162 00:17:47,180 --> 00:17:53,700 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. 163 00:17:53,700 --> 00:18:00,500 What it does is that it will read your stream and decompress it, as with the zlib algorithm. 164 00:18:00,580 --> 00:18:06,980 And the way it works is that it will allocate eight pages, a buffer of eight pages, and then decompress into it. 165 00:18:07,000 --> 00:18:11,420 If it's not big enough, it will create eight more pages and decompress the rest into it. 166 00:18:11,420 --> 00:18:15,780 If it's still not big enough, it will create a third bucket, et cetera, et cetera, et cetera. 167 00:18:15,920 --> 00:18:21,140 So this filter, it gives us a way to go from one bucket to as many as we want. 168 00:18:21,140 --> 00:18:36,440 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. 169 00:18:36,800 --> 00:18:40,800 So we need a way to change the size of each of these buckets. 170 00:18:41,100 --> 00:18:45,280 And a way to do this is to use another filter, which is called dchunk. 171 00:18:45,300 --> 00:18:50,320 It's undocumented, but it's been used by many hackers before, so it's pretty well known. 172 00:18:50,320 --> 00:18:57,780 And the idea is that it will take an HTTP chunked encoded string and simply decode it. 173 00:18:57,780 --> 00:19:01,500 So for those who don't know, the HTTP chunked encoding is very simple. 174 00:19:01,500 --> 00:19:10,120 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. 175 00:19:10,160 --> 00:19:18,840 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. 176 00:19:18,840 --> 00:19:22,760 So for instance, if it reads 8, as in the example, it will read 8 bytes. 177 00:19:22,760 --> 00:19:27,880 Then it will read 11, and since it's ASCII X, it's 17, so it will read 17 bytes. 178 00:19:27,880 --> 00:19:32,140 And then it will read D, read the D bytes, and then it will read 0. 179 00:19:32,140 --> 00:19:37,340 And 0, it doesn't indicate an empty chunk, it indicates the end of the dchunking. 180 00:19:37,340 --> 00:19:40,400 So when it receives 0, it stops processing the data. 181 00:19:41,720 --> 00:19:46,820 So, now you probably have an idea of how we can resize our chunks. 182 00:19:47,280 --> 00:19:54,240 We take bucket 1, if we want it to have a size of 148, we write 148, then 148 bytes, and then 0. 183 00:19:54,320 --> 00:19:57,600 If we want bucket 2 to have a size of 100, we do the same. 184 00:19:57,600 --> 00:20:00,700 We write 100, then all bytes, and then 0. 185 00:20:00,700 --> 00:20:02,240 And we do the same with every chunk. 186 00:20:02,240 --> 00:20:07,340 And then when we apply dchunk onto this, we expect it to resize every single bucket. 187 00:20:07,440 --> 00:20:16,480 But you may notice that this won't work, because even though each bucket is different, they are all processed as one stream. 188 00:20:16,480 --> 00:20:28,100 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. 189 00:20:28,100 --> 00:20:33,140 So you go back to a single bucket with an arbitrary size, which is completely useless. 190 00:20:33,660 --> 00:20:36,740 So luckily for us, there's a way to improve this. 191 00:20:36,960 --> 00:20:44,000 And the way to improve this is to pad the size with thousands of 0s, such as what we can see here. 192 00:20:44,000 --> 00:20:48,280 The idea is that in each bucket, we will have one chunk size and one chunk data. 193 00:20:48,280 --> 00:20:49,000 And that's it. 194 00:20:49,000 --> 00:20:49,860 Nothing else. 195 00:20:49,860 --> 00:21:02,400 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. 196 00:21:02,400 --> 00:21:06,440 It will read the size, read the data, then bucket 3, read the size, read the data. 197 00:21:06,460 --> 00:21:13,180 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. 198 00:21:13,180 --> 00:21:17,620 And now we have a way to create as many buckets as we want, and change the size. 199 00:21:17,620 --> 00:21:21,020 And this is only with two filters, so it's pretty promising. 200 00:21:23,060 --> 00:21:33,380 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. 201 00:21:33,380 --> 00:21:34,180 So how do we do this? 202 00:21:34,180 --> 00:21:42,760 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. 203 00:21:42,760 --> 00:21:47,240 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. 204 00:21:47,260 --> 00:21:49,440 And at this point we are not able to do this. 205 00:21:49,540 --> 00:21:52,660 But to do this, what we can do is think about the PHP heap. 206 00:21:52,660 --> 00:21:53,740 It's page-based. 207 00:21:53,740 --> 00:22:02,660 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. 208 00:22:02,660 --> 00:22:05,500 I will not have to think about them in my exploit algorithm. 209 00:22:05,500 --> 00:22:13,020 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. 210 00:22:13,240 --> 00:22:20,740 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. 211 00:22:20,740 --> 00:22:22,320 It's as if they weren't there. 212 00:22:22,320 --> 00:22:27,800 So the only thing that I need to be able to do is to be able to resize buckets as the exploitation goes on. 213 00:22:27,800 --> 00:22:34,140 And to be able to do this, I built buckets that are Russian dolls of dchunk algorithm. 214 00:22:34,220 --> 00:22:40,140 So the idea is that every time I call dchunk on some buckets, its size will change. 215 00:22:40,140 --> 00:22:47,740 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. 216 00:22:47,860 --> 00:22:51,980 And that basically means that I can allocate and deallocate at will. 217 00:22:51,980 --> 00:22:55,260 And at this point, I'm really, really close to getting an exploit working. 218 00:22:56,720 --> 00:23:01,760 And the final idea here is that we have a one-byte overflow, using the icon bug. 219 00:23:01,860 --> 00:23:09,360 And we want to use it to alter some freelist and get complete control over it. 220 00:23:09,400 --> 00:23:14,600 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. 221 00:23:16,260 --> 00:23:18,420 First, we will start in step one. 222 00:23:18,420 --> 00:23:21,460 And we're going to have three chunks, A, B, C. 223 00:23:21,460 --> 00:23:23,280 And each chunk is freed. 224 00:23:23,280 --> 00:23:26,320 We have A that points to B, and B that points to C. 225 00:23:26,320 --> 00:23:28,720 Then we allocate these three chunks, and we free them. 226 00:23:28,720 --> 00:23:33,940 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. 227 00:23:33,940 --> 00:23:35,500 So we have reversed the freelist. 228 00:23:35,840 --> 00:23:45,360 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. 229 00:23:46,100 --> 00:23:49,060 Then we allocate B and A, and then we free everything. 230 00:23:49,060 --> 00:23:50,500 And we get into step five. 231 00:23:50,500 --> 00:24:00,280 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. 232 00:24:00,280 --> 00:24:02,340 So now you can probably see where this is going. 233 00:24:02,340 --> 00:24:06,280 We overflow using chunk A into chunk B. 234 00:24:06,280 --> 00:24:11,100 So the freelist that was B to C is now B to C plus 48. 235 00:24:11,120 --> 00:24:14,880 And what we have in C plus 48 is another pointer that we added ourselves. 236 00:24:14,920 --> 00:24:21,320 So with three more allocations, we will allocate B, C plus 48, and then we will allocate our arbitrary pointer. 237 00:24:21,640 --> 00:24:28,520 And now we are able to have a write-what-where, which is really, really close to getting code execution. 238 00:24:30,400 --> 00:24:33,120 But now we have to think about how we can do this. 239 00:24:33,120 --> 00:24:39,200 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. 240 00:24:39,300 --> 00:24:50,840 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. 241 00:24:50,920 --> 00:24:56,740 So for those, again, we do heap exploitation on ptMalloc, it would be the same as free-hook, malloc-hook, and realloc-hook. 242 00:24:56,760 --> 00:25:03,500 Those are pointers that, if you set them to something else that null, they're going to be called inside of the original function. 243 00:25:03,700 --> 00:25:10,000 And so, since it's basically the same as the glibc, I can use the glibc technique, and I can override free with system. 244 00:25:10,000 --> 00:25:14,480 So now, when PHP wants to free a chunk, it will call free, but it will instead call system. 245 00:25:14,480 --> 00:25:20,380 And this gives me a way to call an arbitrary comment. 246 00:25:21,220 --> 00:25:25,480 And so, with everything put together, what do we have? 247 00:25:25,480 --> 00:25:35,720 We have an exploit that works against any target, from PHP 7 to the current version, which is H3-something. 248 00:25:35,720 --> 00:25:39,600 So that's 10 years of PHP covered with a single binary exploit. 249 00:25:39,600 --> 00:25:48,240 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. 250 00:25:48,240 --> 00:25:49,160 It doesn't matter. 251 00:25:49,280 --> 00:25:56,540 In addition to this, the exploit is completely deterministic, so it's 100% reliable, so you will never get a crash. 252 00:25:56,660 --> 00:25:57,700 So it's pretty cool. 253 00:25:57,860 --> 00:26:08,220 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. 254 00:26:08,220 --> 00:26:10,480 So originally, it's compressed, so it's very small. 255 00:26:10,480 --> 00:26:16,560 And the last good thing that we can say about the exploit is that it's completely self-contained. 256 00:26:16,680 --> 00:26:23,760 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. 257 00:26:23,760 --> 00:26:26,560 You just need your PHP filter string, and you get RCE. 258 00:26:26,780 --> 00:26:32,700 So every file reading primitive now that you have on PHP, you have RCE instead, which is pretty nice. 259 00:26:33,400 --> 00:26:39,940 I'm going to show you a demo that actually involves Cosmic Sting, which is a Magento X6E, which is pre-authentication. 260 00:26:39,940 --> 00:26:43,100 And it came out after I published my bug, so it was in June. 261 00:26:43,160 --> 00:26:46,840 And the original impact was being able to read files. 262 00:26:46,880 --> 00:26:57,300 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. 263 00:26:57,300 --> 00:26:59,600 But you wouldn't be able to get RCE. 264 00:26:59,700 --> 00:27:10,380 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. 265 00:27:12,560 --> 00:27:17,320 So, quick demo, which is not on the right screen. 266 00:27:18,460 --> 00:27:19,380 There we go. 267 00:27:23,640 --> 00:27:28,420 So, I cannot see it, but it's quite easy to understand. 268 00:27:28,420 --> 00:27:36,220 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. 269 00:27:36,820 --> 00:27:38,140 There you go. 270 00:28:07,360 --> 00:28:09,120 There we go. 271 00:28:09,120 --> 00:28:10,160 Thank you, man. 272 00:28:11,340 --> 00:28:14,580 So, oh, I lost my... 273 00:28:14,580 --> 00:28:16,400 On the other screen, I lost it. 274 00:28:20,440 --> 00:28:21,480 Wait. 275 00:28:24,000 --> 00:28:25,580 Okay, there we go. 276 00:28:26,020 --> 00:28:27,960 Okay, does that work? 277 00:28:28,320 --> 00:28:29,320 Yeah. 278 00:28:29,760 --> 00:28:41,980 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. 279 00:28:41,980 --> 00:28:44,520 There's another way that is way simpler. 280 00:28:44,560 --> 00:28:46,940 It is when PHP calls ICONF directly. 281 00:28:47,540 --> 00:28:51,220 And so, there's a PHP function that does this. 282 00:28:51,220 --> 00:28:52,660 It's called ICONF. 283 00:28:55,840 --> 00:28:59,860 So, how do we exploit such a call to ICONF? 284 00:28:59,860 --> 00:29:05,680 Well, it's very, very different to the attack that we've seen using PHP filters. 285 00:29:06,980 --> 00:29:13,640 So, here we don't have a five-read primitive, so we cannot just read proxmaps or read the libc or anything. 286 00:29:13,640 --> 00:29:22,640 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. 287 00:29:22,920 --> 00:29:33,760 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. 288 00:29:33,760 --> 00:29:38,540 So, a ZenString, it's the representation of PHP of your PHP string. 289 00:29:38,720 --> 00:29:41,480 And the length field, it will store the size of the string. 290 00:29:41,480 --> 00:29:56,280 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. 291 00:29:57,140 --> 00:30:00,880 Sadly for us, the bug that we have, as I've said, really, really bad. 292 00:30:00,880 --> 00:30:03,040 We only have one to three bytes overflow. 293 00:30:03,040 --> 00:30:10,840 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. 294 00:30:11,940 --> 00:30:21,980 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. 295 00:30:22,040 --> 00:30:31,060 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. 296 00:30:31,060 --> 00:30:36,920 And when the string gets displayed, we actually are able to see what comes afterwards in memory. 297 00:30:38,440 --> 00:30:42,260 The problem is that here, we completely rely on the code. 298 00:30:42,340 --> 00:30:49,920 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. 299 00:30:49,920 --> 00:30:50,780 Nothing else. 300 00:30:50,780 --> 00:30:59,440 So, getting it to work would make us reliant on the code that comes after the call to iconf. 301 00:30:59,440 --> 00:31:02,000 And to explain this, a very simple example. 302 00:31:02,040 --> 00:31:04,080 Say that you have this piece of code. 303 00:31:05,020 --> 00:31:12,200 We control the output charset, we control the input text, so it's clear that we can trigger the bug. 304 00:31:12,860 --> 00:31:16,820 But right after the bug has been triggered, the script will end. 305 00:31:16,920 --> 00:31:22,200 So, there's absolutely no way for us to use the bug after it's been triggered, because the heap will be destroyed. 306 00:31:23,040 --> 00:31:28,760 If you're lucky, however, you might find a line such as this one after your call to iconf. 307 00:31:28,960 --> 00:31:38,360 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. 308 00:31:39,500 --> 00:31:47,580 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. 309 00:31:47,840 --> 00:31:54,080 And that will give you a way to use the bug right after it's been triggered, and then probably exploit the bug. 310 00:31:54,120 --> 00:31:56,420 So, this is what I call a code gadget, actually. 311 00:31:56,540 --> 00:32:04,540 That's a way to get to using your bug, starting from the position where iconf has been called. 312 00:32:05,440 --> 00:32:15,720 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. 313 00:32:15,720 --> 00:32:20,840 Roundcube, for those who don't know, it's a webmail that is very much used. 314 00:32:21,220 --> 00:32:23,420 It's probably the most well-known in PHP. 315 00:32:23,560 --> 00:32:27,760 It's used by hosters generally, or private companies even, I've seen it a lot. 316 00:32:28,520 --> 00:32:31,520 And , well, yeah, it's used a lot. 317 00:32:32,280 --> 00:32:37,880 And so, when you're logged into Roundcube and you want to send an email, you have to specify email addresses. 318 00:32:37,880 --> 00:32:42,460 And so, you specify the two fields, the cc field and the bcc field. 319 00:32:42,460 --> 00:32:45,580 You can guess what they are, you've already sent an email. 320 00:32:45,820 --> 00:32:51,180 In addition to this, you can send another parameter, which is charset. 321 00:32:51,180 --> 00:32:59,020 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. 322 00:32:59,020 --> 00:33:00,780 And it's going to be done using iconf. 323 00:33:00,780 --> 00:33:05,760 So, in this single script here, you have three ways of triggering your bug. 324 00:33:05,760 --> 00:33:10,960 You can trigger it using underscore 2, or with underscore cc, or with underscore bcc. 325 00:33:10,960 --> 00:33:13,780 And right after this, there's something even better. 326 00:33:13,780 --> 00:33:21,000 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. 327 00:33:21,540 --> 00:33:22,740 So, what can we do with this? 328 00:33:22,740 --> 00:33:27,780 Well, this is textbook, the strategy that I was telling you about before. 329 00:33:27,780 --> 00:33:33,160 The idea is that you set underscore 2 to an invalid email, so that invalid email gets set. 330 00:33:33,160 --> 00:33:35,340 It's ready to be displayed in the error message. 331 00:33:35,340 --> 00:33:41,120 So, now what we want to do is modify its length before it's included in the error message. 332 00:33:41,360 --> 00:33:44,980 So, then we use cc to trigger the bug, and we have a free list that is altered. 333 00:33:45,060 --> 00:33:54,100 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. 334 00:33:54,160 --> 00:34:01,800 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. 335 00:34:02,380 --> 00:34:04,320 So, I implemented this, and it was really fast. 336 00:34:04,320 --> 00:34:08,420 It took me a few hours, so I was really happy with it, and I started it, and it didn't work. 337 00:34:08,540 --> 00:34:14,780 And the reason for this is that when Roundcube sends an error message, it's converted to JSON. 338 00:34:14,780 --> 00:34:19,320 And when PHP converts to JSON, every byte that is not valid UTF-8 is removed. 339 00:34:19,380 --> 00:34:28,780 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. 340 00:34:28,860 --> 00:34:32,700 Any raw data in memory is not going to be valid UTF-8, it's going to be removed. 341 00:34:32,700 --> 00:34:39,420 So, what you get is a memory leak, which consists of only ASCII characters and new bytes, which is completely useless. 342 00:34:39,820 --> 00:34:42,060 But, the idea is pretty good still. 343 00:34:42,060 --> 00:34:49,200 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. 344 00:34:49,200 --> 00:34:58,560 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. 345 00:34:58,560 --> 00:35:11,300 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. 346 00:35:11,300 --> 00:35:15,300 So, it limits the number of gadgets that we can use. 347 00:35:15,680 --> 00:35:28,380 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. 348 00:35:28,380 --> 00:35:32,660 Like, every line can be an allocation or deallocation that would shape the heap better for you. 349 00:35:32,740 --> 00:35:36,300 And I actually managed to pull that off in, I think, five days. 350 00:35:36,300 --> 00:35:38,120 It was really, really long. 351 00:35:38,120 --> 00:35:40,360 And I actually managed to get the leak. 352 00:35:40,360 --> 00:35:44,180 So, it was nice, because afterwards, it's pretty easy to get ASCII. 353 00:35:44,180 --> 00:35:55,840 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. 354 00:35:55,960 --> 00:36:01,600 And that means that you can do data-only attacks, where you overwrite some value that is in your session, for instance. 355 00:36:01,600 --> 00:36:10,400 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. 356 00:36:10,580 --> 00:36:17,020 Or, you can also go the standard way, where you go for a binary attack, where you want to control MIP. 357 00:36:17,020 --> 00:36:20,180 You started with binary, and you want to go full binary. 358 00:36:20,300 --> 00:36:25,440 But I think the data-only attack is more elegant, and it fits more, because you don't have to dump the binary. 359 00:36:25,540 --> 00:36:27,220 So, it's easier. 360 00:36:27,880 --> 00:36:32,160 But, like all of this that I'm saying, it's actually only the visible part of the iceberg. 361 00:36:32,160 --> 00:36:36,500 It's really, really hard to pull off, because first, you need a proper heap setup. 362 00:36:36,500 --> 00:36:46,120 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. 363 00:36:46,120 --> 00:36:49,600 They all get compiled in the same heap, so you will completely mess up the heap. 364 00:36:49,600 --> 00:36:51,120 It's really annoying to pull off. 365 00:36:51,280 --> 00:36:54,300 In addition to this, variable scope is here. 366 00:36:54,300 --> 00:37:00,600 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. 367 00:37:00,940 --> 00:37:03,900 So, it will completely change the heap as well. 368 00:37:04,100 --> 00:37:06,520 And also, obviously, it's very specific. 369 00:37:06,520 --> 00:37:11,660 Your attack to the server that you're targeting, the application that you're targeting, and also the settings. 370 00:37:11,660 --> 00:37:15,740 I think the original exploit that I built, it was for Roundcube in French. 371 00:37:15,740 --> 00:37:24,580 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. 372 00:37:24,580 --> 00:37:30,420 So again, it's a huge pain to pull off, so don't do it unless it's really necessary. 373 00:37:31,000 --> 00:37:31,960 But it works! 374 00:37:32,340 --> 00:37:40,580 And I will show you an exploit, hopefully, if I can make it appear again. 375 00:37:46,050 --> 00:37:47,850 Oh, I'm paused. 376 00:37:48,670 --> 00:37:49,750 There we go. 377 00:37:50,350 --> 00:37:53,910 Now I need to find... 378 00:38:00,840 --> 00:38:03,280 Okay, same layout. 379 00:38:03,740 --> 00:38:10,360 You get a shell on the very bottom, an exploit on top of this, and the application on the left. 380 00:38:17,780 --> 00:38:20,800 And now I need to remove it again. 381 00:38:21,500 --> 00:38:22,880 Which one of these? 382 00:38:23,000 --> 00:38:23,860 This one? 383 00:38:23,920 --> 00:38:24,580 Nope. 384 00:38:25,820 --> 00:38:26,780 Nope. 385 00:38:27,980 --> 00:38:28,940 Yeah. 386 00:38:29,300 --> 00:38:30,000 Okay. 387 00:38:30,780 --> 00:38:33,940 A quick conclusion, and maybe a few more words afterwards. 388 00:38:35,960 --> 00:38:38,400 So the bug was really bad, honestly. 389 00:38:38,500 --> 00:38:42,400 It had lots of preconditions, and even the bug was not that good. 390 00:38:42,400 --> 00:38:44,140 A really bad overflow. 391 00:38:44,240 --> 00:38:52,480 But luckily for us, PHP exists, and we actually are able to do decent things with it. 392 00:38:52,480 --> 00:38:59,940 We have a new attack vector, where we convert a favorite primitive into an RCE on any PHP version, against any target. 393 00:38:59,940 --> 00:39:02,240 If you have a favorite primitive, you have RCE now. 394 00:39:02,240 --> 00:39:03,440 It's pretty nice. 395 00:39:03,500 --> 00:39:09,720 And also, you add application-specific attacks, such as the one I've demonstrated on Runcube. 396 00:39:09,720 --> 00:39:16,020 However, the bug is not PHP-specific, so there could be a lot of other targets. 397 00:39:16,100 --> 00:39:18,720 I couldn't find any, but maybe you will. 398 00:39:18,940 --> 00:39:29,020 And they might be discovered as time goes by, if people try to find a way to exploit the bug. 399 00:39:30,440 --> 00:39:32,340 The timeline goes fast. 400 00:39:32,340 --> 00:39:36,400 I found the bug last year, and I started exploiting it in February. 401 00:39:36,400 --> 00:39:41,740 After a month and a half, I could report it to the GDBC security team, and they were really amazing. 402 00:39:41,740 --> 00:39:42,780 They were really fast. 403 00:39:42,780 --> 00:39:45,380 After a week, I got a patch, and they were really nice. 404 00:39:45,420 --> 00:39:51,640 They knew what they were doing, which is not always the case, to say the least. 405 00:39:52,040 --> 00:40:00,620 So the bug got patched in a week, and two weeks after the embargo, it was released as CVE-2024-2961. 406 00:40:02,300 --> 00:40:04,920 That's probably the end of it for me. 407 00:40:04,920 --> 00:40:10,920 I have published lengthy blog posts about the bug, because there's so much to say about the bugs. 408 00:40:10,980 --> 00:40:16,180 And also, the impact on the PHP ecosystem, which I couldn't cover here, because we only have 45 minutes. 409 00:40:16,380 --> 00:40:19,540 And also, there are exploits that are available on our GitHub. 410 00:40:19,640 --> 00:40:21,820 And also, there's my Twitter, if you want to ask questions. 411 00:40:21,820 --> 00:40:25,300 You can also ask some questions right after the talk. 412 00:40:25,520 --> 00:40:29,520 And just to flex a little bit, a few what-ifs. 413 00:40:29,520 --> 00:40:34,640 What if we have a Fargate primitive, but we cannot see the output? 414 00:40:34,720 --> 00:40:37,340 We have Fargate contents, but no echo in front of it. 415 00:40:37,340 --> 00:40:39,100 So we cannot read FoxFMaps. 416 00:40:39,100 --> 00:40:41,120 We cannot read any binary. 417 00:40:41,180 --> 00:40:43,980 So the exploitation that I've shown you, it doesn't work. 418 00:40:44,280 --> 00:40:48,820 And also, in some very, very rare cases, zlibin-fake will not be present. 419 00:40:48,820 --> 00:40:53,460 You will not be able to decompress your stream, so you will have to exploit with one single pocket. 420 00:40:53,760 --> 00:40:55,840 And that looks impossible. 421 00:40:56,100 --> 00:40:59,240 But I was able to do both at the same time. 422 00:40:59,240 --> 00:41:00,980 That was actually my very first exploit. 423 00:41:01,640 --> 00:41:04,040 And I will try and show you how. 424 00:41:06,900 --> 00:41:10,620 It's just a demo, really sped up, because it's really slow. 425 00:41:10,620 --> 00:41:12,780 But, well, at the end you get a shell. 426 00:41:12,780 --> 00:41:15,920 The important part is on the left, the source code. 427 00:41:15,920 --> 00:41:19,320 You can see at the very bottom, you have a Fargate contents without an echo or anything. 428 00:41:19,320 --> 00:41:20,660 So I don't have the output. 429 00:41:20,680 --> 00:41:26,260 And also, on top of this, I have arbitrary allocation, uh, random, sorry, allocations and deallocations. 430 00:41:26,260 --> 00:41:30,780 Just to show that the script is not very, that it's not tailored to attack one PHP script. 431 00:41:30,780 --> 00:41:33,280 Like, it could work against any PHP instance. 432 00:41:33,540 --> 00:41:35,800 And, yeah, the exploit is not done yet. 433 00:41:35,800 --> 00:41:37,520 It's sped up like eight times, I think. 434 00:41:37,520 --> 00:41:38,540 It's really, really slow. 435 00:41:38,540 --> 00:41:42,320 But you get one byte per one byte, and at the end you have another shell. 436 00:41:42,360 --> 00:41:43,580 So, yeah, that's it. 437 00:41:50,200 --> 00:41:51,840 Okay, I'm getting close. 438 00:41:52,000 --> 00:41:52,640 No. 439 00:41:57,600 --> 00:41:58,400 Yeah. 440 00:41:58,620 --> 00:41:59,600 There we go. 441 00:42:00,420 --> 00:42:01,220 Questions? 442 00:42:09,890 --> 00:42:11,090 Okay, I guess we're good. 443 00:42:11,090 --> 00:42:12,290 Ah, there's one. 444 00:42:15,770 --> 00:42:16,550 Yeah, thank you. 445 00:42:16,550 --> 00:42:17,630 This is amazing. 446 00:42:17,790 --> 00:42:24,590 Uh , so, how did you get to the Roundcube target and establish that those conditions were present that you were looking for? 447 00:42:24,590 --> 00:42:29,430 Um, so, I thought that, like, emails to me... 448 00:42:30,010 --> 00:42:32,750 When you send an email, you can kind of send the charset with it. 449 00:42:32,750 --> 00:42:37,150 So I kind of felt like webmails would be a good target to look at. 450 00:42:37,230 --> 00:42:38,970 And I looked at Roundcube. 451 00:42:38,970 --> 00:42:42,130 And I saw that, like, it was a good target. 452 00:42:42,130 --> 00:42:43,310 So , yeah, that's why. 453 00:42:43,310 --> 00:42:43,810 Oh, cool. 454 00:42:43,810 --> 00:42:44,590 Pure intuition. 455 00:42:44,590 --> 00:42:45,170 That's amazing. 456 00:42:45,170 --> 00:42:45,650 Thanks. 457 00:42:52,930 --> 00:42:55,050 Well, thank you for listening to my talk.