---
title: "4. PHP Filters"
date: 2024-10-18
draft: false
---

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. 
- Very useful for developers 
- Even more useful for webapp pentesters

Vectors:
- Read php sourcecode
- XXE
- Exec sys commands

## 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` 
- Resource: 
	- Required for filter wrapper
	- Specify stream to apply filter on (like a local file)
- Read:
	- Apply diff filters on input resource 

Four kinds of filters available for use
- String
- Conversion
- Compression
- Encryption 

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`
- Not restricted to 200 responses
- Scan for all codes, 301, 302, 403 and we can read their source code too 

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. 
- potentially useful (accessing local php pages we dont have access over)
	- think SSRF (serverside request forgery)
- in most cases - we're more interested in reading the php code via lfi
	- source code tends to reveal important information 
	- this is where our above `base64` php filter is useful 

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 
- same applies to webapp langs other than php - as long as vulnerable funtion can execute files 

**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. 

```bash
php://filter/read=convert.base64-encode/resource=config
```
- **NOTE:** intentionally left `resource=config` as just `config` because `.php` is appended automatically 

---
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)

