text
stringlengths
0
1.99k
`php://filter` wrapper.
- [ CODEGATE 2015: Owlur Challenge ] - [53]
=> the challenge leveraged the `zip://` wrapper to circumvent the
fixed `.php` requirement.
=================================
| Level 0 - The LFI Arms Race |
=================================
When it comes to the LFI arms race, I guess we can start with my "One Line
PHP Challenge" [54]. While preparing for HITCON CTF 2018, I wanted to
bring the competition back to its basics - focusing purely on cool tricks
rather than stacking tedious tasks just to annoy participants. And that's
how "One Line PHP" was born:
------------------------[ One Line PHP Challenge ]-------------------------
<?php
($_=@$_GET['orange']) && @substr(file($_)[0],0,6) === '@<?php' ?
include($_) : highlight_file(__FILE__);
---------------------------------------------------------------------------
The whole idea behind the challenge came from a small upload-progress
feature that @Ryat mentioned in the comment of his SESSION Data Injection
report [55]. Inspired by that trick, I decided to blend it to LFI -
merging the two entirely different approaches we discussed earlier into
one single challenge!
I'd say "One Line PHP" turned out to be a successful CTF challenge. HITCON
CTF served as a qualifier for the "Hacker World Cup" DEFCON CTF that year,
drawing over 1800 teams worldwide, yet only three teams managed to crack
it. The challenge then also sparked a whole new trend to find more generic
ways to leave temporary files behind, and inspired numerous later CTF
challenges, including:
- 2018/12 - The Return of One Line PHP Challenge (RealWorld CTF Final)
=> [ By the way, I was sitting right there as a finalist, [56]
watching (the return of) my challenge go live on stage! ]
- 2019/12 - Includer (36C3 CTF) [57]
- 2021/07 - 1linephp (0CTF/TCTF) [58]
- 2021/10 - 2linephp (Balsn CTF) [59]
- 2021/12 - Includer's Revenge (hxp CTF) [60]
If you're interested in the technical details behind them, I highly
recommend checking out the article "One Line PHP: From Genesis to
Ragnarok" [61], by @Ginoah and @Bookgin!
==============================
| Level 1 - The End of LFI |
==============================
As we've seen, up until a few years ago, the entire LFI scene was still
largely focused on finding more generic ways to plant temporary files. But
everything changed thanks to one wild idea from @loknop [62]. While he was
tackling the "includer's revenge," he started thinking: since we can
already manipulate file contents by `php://filter`, why not just chain
filters together to turn any file into a PHP backdoor?
In fact, his inspiration came from an unintended solution [63] discovered
by @gynvael. During Insomni'hack CTF 2018, @gynvael managed to find a way
to transform the `/flag` file into a viewable image by chaining multiple
PHP filters. Although the challenge at that time had nothing to do with
LFI - and the trick itself wasn't complicated at all - it unexpectedly
inspired @loknop several years later, becoming yet another unintended
solution in an LFI scene!
His idea mainly built around two PHP filters:
- [ Removing ]: The `convert.base64-decode` filter is tolerant of its
input, and "skips invalid characters."
- [ Prepending ]: The `convert.iconv.CSISO2022KR` encoding "adds a
fixed string" to the beginning.
By applying these two filters along with various encoding combinations, he
was ultimately able to insert arbitrary content at the very beginning of a
file - such as, prepending a letter `C`:
+-------------------------------------------+
| [Stage 1] Original File Content |
+-------------------------------------------+
| root:x:0:0:root:/root:/bin/bash [...] |
+---------------------+---------------------+
| Prepend Charset Header
v
+-------------------------------------------+
| [Stage 2] convert.iconv.UTF8.CSISO2022KR |
+-------------------------------------------+
| \x1B$)Croot:x:0:0:root:/root:/bin/bash |