4. PHP Filters

Many popular webapps dev'd in php. There's php frameworks for php like Laravel and Symfony If we identify LFI in php webapp we can use different PHP Wrappers to extend our LFI exploitation or even get remote code execution

https://www.php.net/manual/en/wrappers.php.php

PHP wrappers allow access to different I/O streams at the application level, like stdin/stdout, file descriptors and memory streams.

Vectors:

PHP Filters - Input Filter vulns

PHP Filters are types of PHP wrappers. https://www.php.net/manual/en/filters.php We can pass diff types of input, and have it filtered by the php filter. To use php wrapper streams we use php:// scheme in string and access php filter wrapper with php://filter/

Filter wrapper has several parameters Most important for attack is resource and read

Four kinds of filters available for use

Filter that is most useful for LFI is convert.base64-encode under Conversion Filters

First step, fuzz for php page ffuf -w /opt/useful/SecLists/Discovery/Web-Content/directory-list-2.3-small.txt:FUZZ -u http://<SERVER_IP>:<PORT>/FUZZ.php

After reading source of any files we can scan them for other referenced PHP files and read those as well

Standard PHP Inclusion

In previous examples if you tried to include php files via LFI - included php file gets executed and eventually rendered as a normal HTML page.

Module example includes index.php?language=config to try and load config.php - empty result - but this is likely because execution of config.php only sets the app up; doesn't render html output.

we will b64 encode the php file and exfiltrate it. esp useful when dealing with LFI that appends php extensions because we may be restricted to php files only

Source code disclosure

Once we have a list of php files we may want to read we can check them out with the base64 php filter. Example using b64 filter with convert.base64-encode for read parameter and config for the resource parameter.

php://filter/read=convert.base64-encode/resource=config

example from module:

![](/img/Pasted image 20241018183736.png) fuzz for php files with ffuf

![](/img/Pasted image 20241018183849.png)

plugging in php:// wrapper in language parameter

![](/img/Pasted image 20241018183920.png)

![](/img/Pasted image 20241018183953.png)