Hi everyone. Greg Magarshak here again. A few years ago I wrote about my
three proposals for PHP 9. One was to allow all legacy code to run much
faster in an "evented" style using Swoole / FrankenPHP. Since then I
released a webserver written in pure-PHP that already does it – any legacy
code can spin up 100x more workers and work 100x faster... and besides
handling HTTP requests, it also supports 100K websockets at once, on one
machine:
https://github.com/Qbix/webserver
https://l.gourl.es/l/f836d2a2f999bdcb110919420aeb983ecc6d53ae?u=1056127
By the way, that server doesn't suffer from php2shell, because it doesn't
even require nginx.
Anyway I am writing another post today with an idea for PHP 9, that would
close a ton of possibilities for arbitrary RCE. I am tired of seeing PHP
have such gaping holes that are easy to plug. Here is one that I would
absolutely recommend for PHP 9:
Make it so that include() and require() can only load specific extensions
like ".php" and ".phar". At the same time, all file functions that write to
a file (e.g. fwrite and file_put_contents) must refuse to write to exactly
these extensions. If a sysadmin wants to change this for a specific app,
they can edit the .ini file, but set_ini() should not be able to affect
these settings.
THIS ONE THING ALONE WOULD CLOSE A TON OF GAPING LOOPHOLES THAT ATTACKERS
CAN USE ANYTIME, BUT ACTUAL PHP DEVELOPERS DON'T NEED 99.9% OF THE TIME.
And it's easy to add.
My PHP webserver already rewrites PHP files when including them in PHP
userland using stream wrappers, to do exactly things like this. Being able
to rewrite PHP being loaded let me achieve a lot of the speed and security
innovations on the Qbix webserver. That's why it doesn't have nearly the
attack surface that regular PHP-FPM has. Please look at the GitHub and feel
free to lift the ideas from it (it's MIT licensed).
Sincerely,
Greg Magarshak
[image: http://qbix.com] <http://qbix.com