PHP filter_var shenanigans
pwning.systems
pwning.systems
I'm thinking PHP's built in request size limit config items (e.g. post_max_size) will prevent this from being an issue too. Might not stop this bug if the URL is in a header though.
A 4GB request is a very large amount of data indeed.
A beefy server should be able to process 4GB of data within 30 seconds though I suppose.
If I recall correctly, max_input_time includes time taken to copy the file to the tmp directory and to parse the file for metadata, but not the upload time either (it does start prior to max_execution_time though). This value is set to -1 by default meaning it uses the value from max_execution_time instead.
You're more likely to run into Apache, Nginx, or PHP FPM timeouts. I can't remember exactly which timeout, but I remember there is one in Apache or FPM that is affected by upload time.
I'll call it exceptional when it can encode any real-drive-size repeated-character file into the size of a tweet.
$ getconf ARG_MAX
2097152
It's driven by some formula related to max stack size (ulimit -Ss), but capped at 6 MiB.It's not so much a vulnerability, but certainly a bug and I agree, it needs fixing. But it doesn't feel particularly urgent.
It would likely be classed as a vulnerability if the out of bounds access _itself_ exposed some kind of internal issue beyond accessing the user input data in an unusual manner.
It only becomes a vulnerability in userland code where it's in the hands of a naive implementation, such as the one posited here.
The other factor is that, as noted by others, there are likely a number of other layers that a sysadmin can put into place using readily-available PHP config options that would essentially prevent this from being possible and by default are pre-configured in such a way to prevent this.
Would be interesting to see if there is code in the wild that is as naive as the example given, but my gut says 'probably not' so again likelihood of this being an issue is very very low.
From that perspective I can understand core PHP devs opting not to pursue this immediately.
What you should be using is quoting and escaping for the specific context.
Here in PHP and in the shell command argument position, you'd use `escapeshellarg()`. This will produce a correctly quoted and escaped string that can be safely used at argument position in a shell command.
It also doesn't rely on knowledge of the specific domain of the argument and it doesn't parse the argument at all. It's stateless and works everywhere.
Of course, if the input isn't a valid hostname, to come back to this article, `ping` will still fail, but there will be no possibility for arbitrary code execution (of course, neither their would be if `filter` worked right, but that's a) accidental (because ; and ' are not valid host name characters) and b) obviously not a given because filtering and sanitisation is much harder than dumb quoting.
Always quote. Only validate if you need to produce a readable error message. But never rely on validation or sanitisation.
That is if you actually use raw php. Very few (good) people do. (Kinda like ruby). And symfony / laravel have functions for both these use cases. Symfonys process takes care of this for example
But the author kind of made it seem like a big deal, while realistically nobody would write code this way. Taking user input, running the domain with host flag through filter var and then system call it?
Most libraries tend to implement validation themselves and not rely on filter_var.
But even if this was fixed, most people should know taking user input and running it via system is a bad idea and needs more than a simple filter_var filter.
Even without any proxies/WAF, PHP is always run (except in development environments with `php -S localhost:4124`) behind a web server, usually apache or nginx. Not sure about apache, but nginx defaults to a limit of 1MB for the request size (via `client_max_body_size` https://nginx.org/en/docs/http/ngx_http_core_module.html#cli...) and I can imagine apache have a similar default as well. Even if you allow requests to carry 1GB of data, this is still not exploitable, and if you have that large requests anyways, you usually find another way of doing the transfer than using plain HTTP requests.
I don't believe this is what's happening at all... e and t are pointers, and they're not being written to, just reassigned.
Some systems will have that a bit higher to allow uploads of larger files, but the largest one I've ever seen is somewhere around 50mb, with 4gb you'd either have to have a super large php-fpm setup where each process could receive 4gb requests and deal with them, plus you'd have to have the config adjusted to receive these large posts.
The number of instances out there might not be exactly zero, but I'm pretty sure it's somewhere very close if not.
Regardless, php should fix the issue.