On an isolated test machine, I took an old site running PHP 7.4 from an avatar upload all the way to server-side code execution, then made the same attack fail, unchanged, against five layers of hardening. The attack stays at the level of concepts; the hardening is laid out layer by layer.
It was a Saturday evening. On an old computer kept apart from the office network, I uploaded a PHP file one line long. There was nothing in it except an instruction to print PROBE-OK. Then I opened it in the browser, and the page answered with one word: PROBE-OK.
For two seconds I just stared at the screen. Not because it surprised me (it was exactly the result I wanted) but because it was far too easy. Something I had uploaded, the server ran as code. From that moment, the machine no longer entirely belonged to itself.
This article is the full record of how I broke into an old PHP site with my own hands, then sealed it, layer by layer, with my own hands. I won't talk about abstract principles. I'll tell you what I saw, how I judged it at the time, and how I see it now.
Why I wanted to do it myself
I work in IT in Tokyo, and I've looked after the websites of quite a few small and mid-sized Japanese companies. They share one profile: running on very old PHP, untouched for years, and nobody thought anything was wrong until something happened.
I didn't want another "PHP security best practices" list; there are ten thousand of those online. I wanted to walk the road myself: "broken into → contain → upgrade → migrate", on a test machine I fully control and fully isolate, leaving a real picture of every step. Only after you have really seen it broken into does the "why fix it this way" that follows hold up.
So I built two identical sites: one deliberately broken vulnerable version, and one version I had hardened. The same attack hits the vulnerable version first, then the hardened version, unchanged. The difference between the two is the whole value of this article.
Act one · The server introduces itself
The first thing I did doesn't even count as an attack. I simply asked it, "Who are you?":
Server: nginx/1.27.5
X-Powered-By: PHP/7.4.33
Figure 1: The test machine's response headers, read with curl. The server announces nginx/1.27.5 and PHP/7.4.33 (an isolated test machine, listening only on 127.0.0.1)
It gave away its version number by itself. And PHP 7.4.33 is a version that should have retired long ago. The official record: the last release of PHP 7.4 is 7.4.33; the 7.4 branch first shipped on November 28, 2019, and its security support ended on November 28, 2022 (sources: php.net supported-versions, php.watch, as of 2026-11-28).
Only while writing this did I notice a coincidence: the day I ran this exercise, November 28, 2026, was exactly the fourth anniversary of the end of PHP 7.4's security support. In other words, any site still running on 7.4 has gone four years without an official security patch.
This is my judgment, not a statement of fact: a site that volunteers its version number and sits on a version four years without patches as good as says "come in" to an attacker.
Act two · Broken into (the step I won't spell out)
Next I went after one of the most common features: avatar upload.
First I tested whether it would take files at all. It took anything. I uploaded the PHP file that only prints PROBE-OK; it accepted it without complaint and put it in the website's directory. When I then requested that file, it ran.
Figure 2: A PHP file that only prints PROBE-OK is uploaded, then requested, and the page returns PROBE-OK: the uploaded file was run as code
Here is a misconception many people fall into. I noticed that requesting the upload directory /uploads/ directly returned 403. Three years ago, I might have relaxed at that point: "Look, it's blocked." But a 403 only means the server won't show you the directory listing; it does not protect the files inside. The files in the directory can still be requested, and still run. I ran my probe, and PROBE-OK was the proof.
At this point the conclusion was clear: this site lets anyone upload any PHP file, and runs it. In security terms, it is a complete path from "file upload" straight to "server-side code execution (RCE)".
And after that? Swap my harmless line of echo for one line that runs system commands, and you have a complete "webshell" that lets an attacker do whatever they like on the server.
This is where the article stops. I won't write out that line of code, and I won't write out the full exploitation steps. The reason is simple: my test machine is mine and isolated, but this article is public. Publishing an attack recipe that can be copied straight onto a real website isn't sharing technology; it's handing someone a knife. Explaining it far enough that "you understand how dangerous this is" is enough. The remaining details stay in my own isolated environment.
My judgment: what proves expertise has never been "I can break in"; it is "I can fix it, and explain why each layer is fixed this way". What follows is what this article really wants to give you.
Act three · Upgrade: five layers, each one a safety net
I didn't just plug one hole. I hardened the site in five layers, because any single layer of defense will be bypassed one day; with five stacked, an attacker has to break through all five at once.
Figure 3: Five layers of defense: application code, PHP runtime, Nginx, least privilege, detection; the same upload attack is stopped once at each layer
Layer one · Application code. This is the root. The vulnerable version trusts the file name and extension the client sends, which is the most fatal mistake. In the hardened version I changed it: extensions go through an allowlist (jpg/png/pdf only), and, without trusting the extension, finfo decides the MIME type from the file's actual content; images should also be re-encoded, stripping any code that may be smuggled inside them (this time it was not turned on in the test machine; the allowlist, storage outside the web root and Nginx's ban on execution already stopped the attack); the server generates the file name at random; and most important of all, uploaded files are stored outside the website's root directory, so they never land anywhere they could be run as a web page.
Figure 4: The key differences in upload.php. The vulnerable version trusts the client's file name and saves into the website directory; the hardened version decides the MIME type from content, uses an extension allowlist, returns 415 for non-images, uses a random file name and stores outside the website root
Layer two · PHP runtime. If the code layer is still bypassed, this layer turns "the shell you got" into an empty one: disable_functions blocks functions that run system commands, such as system, exec and shell_exec; open_basedir locks down the directories PHP may touch; allow_url_fopen / allow_url_include are switched off; cgi.fix_pathinfo=0 closes the classic image.jpg/x.php spoofing flaw. Even with execution rights, it can't call commands or get out of the cage.
Layer three · Nginx. This is defense in depth: the upload directory is simply forbidden from running PHP, and try_files $uri =404 sends any path that doesn't exist straight to 404, which stops path spoofing. Even if both the code layer and the runtime fail and a file lands in the website directory, this Nginx layer will not hand it to PHP to run.
Layer four · Least privilege. php-fpm runs under a low-privilege account, the container gets no --privileged and no mounted docker.sock, and in production outbound connections should also be blocked at the network level, so the impact "even if it runs" is shut in the smallest box possible, unable to get out or move sideways.
Layer five · Detection. The first four layers are "don't let it succeed"; this layer is "if it succeeds, I want to know at once": Nginx access logs, auditd watching writes to the website directory, a file integrity baseline, webshell scanning. On the test machine I wired up only part of this layer; in production it must be wired up in full. This layer answers one question: when the attack came, what did the defenders see? That is exactly what most sites that get breached lack the most.
Act four · Attack again, and this time it doesn't get through
With the hardening done, I took the attack from act two, without changing a single character, and ran it again against the hardened version. This time:
I uploaded the same probe file, and the server refused it outright:
HTTP/1.1 415 Unsupported Media Type
type not allowed: text/x-php
Figure 5: The same probe file: the vulnerable version (port 8080) accepts it, the hardened version (port 8081) returns 415 Unsupported Media Type
finfo saw through it ("this isn't an image, it's PHP code") and refused it at the first layer. I also tried disguising it and changing the path; those attempts were stopped by the first layer and by Nginx respectively. The same attack failed once at each of the different layers.
The vulnerable version silently accepts and runs it; the hardened version sees through it at a glance and throws back a 415. Put the two figures side by side, and they are more convincing than any sentence about "doing input validation properly".
Act five · Migration
After containing and upgrading, the last step is migration: moving the foundation from PHP 7.4 to PHP 8.3. This isn't icing on the cake: a site stuck on a version four years without patches, however well hardened, is still being patched on a foundation that keeps growing new holes. Only an upgrade to a version still under official support actually replaces the foundation.
Current status: this exercise used PHP 8.3. Active support for PHP 8.3 ended on December 31, 2025, and security patches are provided until December 31, 2027 (source: php.net supported-versions, as of 2026-11-28); the migration target for production is PHP 8.4 or 8.5.
My view
Having done this, I'm more convinced of one thing: for the PHP sites at small and mid-sized Japanese companies that "haven't been touched in years and were fine until something happened", the biggest risk isn't any one hole; it's that "nobody knows it should have been dealt with long ago".
- The facts: the upload → RCE path is real and reproducible; PHP 7.4 has had no official security patch since 2022-11-28.
- The judgment (this is my opinion): for sites like these, the right order is contain (first close the wound that is bleeding) → upgrade (five layers of hardening) → migrate (replace the expired foundation), not tearing everything down and rebuilding from day one.
If you happen to have a site like this, or you are a fellow professional who maintains sites like this for clients: this is exactly what SolanaLink does. For legacy PHP websites at small and mid-sized Japanese companies, we offer security assessment and remediation along the lines of "contain → upgrade → migrate". You can start with PHP2Shell Emergency Response, Upgrades & Migration.

Comments (0)