Enjoying this issue?
Get tomorrow's AI & engineering digest in your inbox — hand-picked, summarized, and always spam-free.
TLDR
PHP has a memory-handling flaw that can be exploited to run arbitrary commands on servers, and PHP powers roughly 70% of websites. The bug was reported about 10 weeks before the public patch, and three leaks made it public even earlier. The episode shows AI-accelerated vulnerability discovery outpacing AI-assisted patching.
Key points
A PHP memory allocation bug lets attackers execute arbitrary commands on vulnerable servers.
The exploit hides malicious data in memory using an empty key that PHP does not count.
The vulnerability was reported almost 10 weeks before the public patch was available.
A working exploit demo and a patch image leaked before the official patch, forcing PHP to publish a day early.
Amazon saw signs of AWS exploitation on October 17, possibly before the first report.
Techniques
- Using an empty key to leave arbitrary data in PHP-allocated memory without bookkeeping
- Forcing an out-of-memory condition during PHP array handling
- Redirecting the array destructor pointer to a different function
Stop scrolling. Start reading smarter.
Receive the day's most important AI & engineering updates in one concise email. No spam.
Transcript (captions)
When I send a request to the server running PHP, it'll often store some of its data into memory. And that data is eventually freed up so that it can be reused for future requests. Now, because
other people also compete for the memory in the server all at the same time, the memory is often claimed first before it can actually be written into the spot. So, what you actually see in production
in real server running PHP is constantly allocating memory, initializing value in them, and then freeing them up to be reused later on. And it's in this very operation right here where a bug was
found which if it was exploited the right way, anyone can essentially trick PHP into running arbitrary command on the server. So how could something like this happen? Now just because you
allocate the memory doesn't necessarily mean that what's actually contained in that very space is clear and sanitary. In fact, you're often dealing with data that's sort of been left behind from
previous operations until you actually initializing by overwriting them with a new value directly on it. So that begs the question, what if after you allocate the memory in this block right here, but
the data that you inherited that already is contained in that spot contains something malicious? What if this very spot right here was filled with data that was planted on purpose to do
something different? Now, there's a way to format your request where if you leave the key blank, as you can see, the value will then be written in memory. But because the key is empty, PHP won't
actually count that towards its own bookkeeping because it thinks that an empty key must mean that it's not being used. So, we now found a way to essentially leave any random data left
in memory to just sit there without PHP treating it as a valid entry. And within the very same request, if we follow up with the valid data to be written because the previously written data is
no longer allocated, PHP will actually reuse that same block of memory to overwrite with our new data. And this is exactly where the vulnerability with PHP starts. Now, the goal is to manually
allocate memory beyond what PHP setting allows, which would then force PHP to trigger an out of memory response because it ran out of memory. Now, being out of memory is not anything uncommon
that we see and how PHP actually deals with it is pretty standard practice since stuff like this happens all the time when servers are overloaded. But how PHP handles when it specifically
gets out of memory as it's handling an array is where things go wrong real fast. Because my request here caused the memory to run out of space, PHP needs to abandon the job that I submitted halfway
through. And because it needs to free up the space that I try to allocate, it'll go through what I already initialized into memory to clean those out. The problem is how PHP actually handles its
bookkeeping and treats this very large array that I was going to write which counts it as a valid entry first before it actually gets written after. So even though I was in the middle of allocating
enough space so that I can write data later on, it ran out of memory trying to allocate the space beyond what it can offer. So what you have here is an allocated space right here that PHP
thinks that it contains an array of values when it actually just contains the initial value that was left behind from the previous ride that had the missing key. And there's a specific way
in how PHP actually destructs an array. Except in this case, the array doesn't actually exist, but it's really the data that was left behind carefully crafted to manipulate the pointer for the
destructor to instead point to a completely different function in the server and PHP would inadvertently call a function that allows command to be written directly on the server and this
is where the vulnerabilities originated from. Now, as much as the technical theory that we just went through behind it is really interesting, what's even more worth looking at is what the future
holds with how AI and LLM play a factor into all of this. But first, thanks to Bluehost for sponsoring this video. Open source projects like PyTorch, VLM, and Lama.cpp are really important
repositories for understanding how the AI industry is moving. But there's no way I can constantly go through all of them and decide which updates actually matter. With decision models like Jev, I
can use Jev alongside with a clot code agent to go through issues and determine what's actually relevant. And if you want an agent like this to operate autonomously, it needs somewhere to
actually run without relying on my laptop. That's where Blue Host agent hosting comes in. I can deploy this entire workflow in the cloud and give the agent an always on environment to
run it in with full root access, dedicated CPU and RAM, custom runtimes and software, persistent services, background processes, scalable compute and storage. Now, Jeff can help
determine which updates actually matter while the agent executes the workflow in the environment that can keep running. The more capable AI agents become, the more important the infrastructure
underneath them becomes. Check out Blue Host to start deploying your own AI applications. When we look at this chart that shows you the progression of critical vulnerability and exposures
over time, we see just how with the rise of generative AI and agents have identified critical issues like this more and more. And arguably, we should really be celebrating this because we
want our software to be more bulletproof with these vulnerabilities identified. But the problem is a gap between how we've always used to do things versus how fast AI is advancing is not
something that we have nailed down just yet. And things are extremely turbulent right now when things like this happen all the time. The two security vulnerabilities with PHP that was
initially reported by OpenAI and CLI.io IO were, believe it or not, actually almost 10 weeks before it was leaked to the public. Which means even with the help of AI, it took us nearly 10 weeks
to get the patch to be made available to the public, showing you how much faster we're using AI to find bugs than using AIs to fix the bugs at the moment. And this specific situation with PHP is a
bit unique in that it should have been business as usual, but it had three different leaks before it was supposed to be announced publicly with the patch, which forced PHP to pull their go live
date a day earlier than expected. Even back in October 17, Amazon found indications of people exploiting AWS using this very vulnerability, PHP to shell, which suggests that maybe some
people had access to information that was leaked even before the first report. And as we went through the technical details earlier in our walkthrough, having a bug in PHP is very different
from knowing how the exploitation with the bug works in theory, which is also very different from actually being demonstrated how the exploitation works. And the companies that were supposed to
be on top of this and knew that this was an issue for 10 weeks fumbled on all three of these fronts. First, there was an information leak that there was a security vulnerability back in October
20th. And just hours later, Califf, which was literally the company that was involved in finding the exploit, accidentally published the demo of a working exploitation. And to put a
cherry on top, a company called Chain Guard released a working patch image that fixes this in PHP. All of this before the official patch was released, which gave people the ability to
actually reverse engineer how the vulnerability could have worked by looking at the fix itself. Now, as much as we can look at the situation and say that wow, we really dropped the ball
pretty badly, but it's really pointing us to the future of how much AI is lowering the barrier when it comes to finding vulnerabilities and also at the same time how much we really need to act
fast by leveraging AI to continue working on the other side to try and keep up with the fixes. In this case, the magnitude just happens to be pretty big given that PHP runs about 70% of the
websites. What's worse is that a simple demo of this only takes about 3 seconds to run remote code in the server. And the server's response to this is HTTP200,
which means it's technically a successful HTTP request, and the server recognizes it as a legitimate request.