text stringlengths 0 1.99k |
|---|
=> Defender *emulates* the JavaScript inside |
+--------------------------------------------------------------+ |
| Crafted HTML File | |
|--------------------------------------------------------------| |
| [ Arbitrary Padding / Junk Data ] | |
| | |
| +----------------------------------------------------------+ | |
| | <script> | | |
| | var c = document.body.innerHTML[0] == 'A' ? '!' : 0; | | |
| | eval("EICAR-STANDARD-ANTIVIRUS-TEST-FILE" + c) | | |
| | </script> | | |
| +----------------------------------------------------------+ | |
| | |
| +----------------------------------------------------------+ | |
| | <body> | | |
| | [ Leaked Secret / Sensitive Data ] | | |
| | </body> | | |
| +----------------------------------------------------------+ | |
| | |
+--------------------------------------------------------------+ |
----[ 4. New Attacks and Techniques Born in CTFs |
We've already talked about tons of PHP-related tricks, but honestly, most |
of them didn't originally come from CTFs. On the other hand, we've |
introduced brand-new attacks born in CTFs - but again, they weren't |
exactly PHP-specific. So, are there any new attacks out there that are |
both totally PHP-specific and originated from CTFs? |
I think this chapter perfectly captures where these two worlds intersect. |
Let's see how the CTF community pushes technology forward in its unique |
way, breathing new life into the following attack surfaces! |
------[ 4.1 - Twenty Years of Evolving LFI to RCE |
"How can a simple LFI be turned into RCE?" This question has bothered the |
web security community for almost twenty years, and I think we'd all agree |
- solving this long-standing problem is probably one of CTF's greatest |
contributions to PHP security! |
--------------------------[ LFI Never Gets Old ]--------------------------- |
<?php |
include( $_GET['page'] ); |
--------------------------------------------------------------------------- |
Looking back at the twenty-year journey from LFI to RCE, I think we can |
generally divide it into two approaches: |
1. How to find more universal and attacker-controllable files on the |
server. |
2. How to bypass restrictions using built-in URL Protocols and |
Wrappers. |
Since the success of an attack directly depends on what files exist on the |
target system, early LFI hackers focused heavily on finding better ways to |
control file contents - like poisoning server logs through HTTP requests |
or leveraging environment variables exposed by `procfs`. Among all these |
tricks, the most classic one has to be abusing PHP's file upload |
mechanism. |
When PHP processes the upload requests, it would temporarily store the |
content on the filesystem. Even though this timing window is extremely |
short, figuring out how to exploit LFI within such a tiny window became |
quite a hot topic for early hackers. A bunch of classic tricks emerged |
from this challenge, such as: |
- [ PHP LFI to RCE via RFC1867 ] - [50] |
=> @gynvael combined the previously mentioned DOS wildcard tricks, |
showing how to turn "LFI on Windows" into RCE. |
- [ LFI with PHPINFO() Assistance ] - [51] |
=> Brett Moore leveraged the fact that `phpinfo()` prints temporary |
filenames. By significantly increasing the server's load, he |
managed to include the file before it got deleted, proving how |
"LFI with PHPINFO" can lead to RCE. |
As for the second approach, since exploiting LFI in real-world scenarios |
often comes with additional restrictions - such as a fixed `.php` file |
extension - though early hackers could still bypass these with overly long |
paths or NULL-byte truncation, PHP gradually patched these tricks, forcing |
hackers to start exploring built-in URL Protocols and Wrappers to bypass |
such constraints. Some classic examples include: |
- [ `php://filter` Base64 in Piwik ] - [52] |
=> In his bug, Stefan Esser pointed out that you could bypass |
content restrictions by abusing the loose Base64 decoding in the |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.