text
stringlengths
0
1.99k
[...]
Content-Security-Policy: default-src 'none';
<svg/onload=alert(1)>
|-------------------------------- [ next ] -------------------------------|
=> [2] We're free from CSP now!
$ curl -i "http://orange.local/?xss=<svg/onload=alert(1)> \
&A=1&A=2&A=3&A=4&...&A=999&A=1000"
HTTP/1.1 200 OK
[...]
<b>Warning</b>: PHP Request Startup: Input variables exceeded 1000 [...]
<br />
<b>Warning</b>: Cannot modify header information - headers already sent
<svg/onload=alert(1)>
+-------------------------------------------------------------------------+
Honestly, I really love this kind of story - where security features end
up making you less secure! And... Speaking of fixes for complexity attacks
- there was one time when a patch accidentally upgraded the simple DoS
issue into full-blown remote code execution. But that's a whole other fun
story [21]!
----[ 2. One `unserialize()` to Rule Them All
The entire Infosec community realized early on: once attackers control the
`unserialize()` input, they can prefill an object and reuse dangerous
Magic Methods to launch various attacks. However, as people gradually
became aware of the danger of deserialization, developers no longer
trusted user-supplied inputs. This shift pushed security researchers to
start digging deeper into the underlying behavior of applications.
WordPress, for example, stores strings, arrays, and even objects in the
database without caring about their data types - which turns out to be a
particularly interesting feature.
In WordPress, whenever a string fetched from the database "looks
serialized," WordPress attempts to restore it automatically. So whether
you're leveraging an asymmetric serialization interface [22], or bringing
back the classic Column Truncation Attack [23] with a Pile of Poo Emoji
(U+1F4A9) [24], you can easily trigger a deserialization bug in WordPress!
-----------------[ WordPress Unserialize ALL the Things! ]-----------------
function maybe_unserialize( $original ) {
if ( is_serialized( $original ) ) // Looks serialized? Let's wake it up!
return @unserialize( $original );
return $original;
}
function is_serialized( $data, $strict = true ) {
// [...] validate serialized string formats
$token = $data[0];
switch ( $token ) {
// [...] `O` stands for `Object`
case 'O' :
return (bool) preg_match( "/^{$token}:[0-9]+:/s", $data );
case 'b' :
case 'i' :
case 'd' :
$end = $strict ? '$' : '';
return (bool) preg_match( "/^{$token}:[0-9.E-]+;$end/", $data );
}
return false;
}
---------------------------------------------------------------------------
------[ 2.1 - The "Serialize-Then-Replace" Pattern
As far as I remember, the first time I saw this pattern was back in 0CTF
2016 [25]. The challenge cleverly leveraged an extra step that
applications perform on serialized strings - breaking the serialization
format, causing the embedded string to escape from its intended context,
and ultimately get interpreted as an entirely new - and malicious -
object!
And if we're talking about classic examples of this concept, Joomla!
definitely comes to mind - it manages all SESSION operations by itself,
storing serialized user states directly in the database. However, since
the PHP serialization can produce strings containing NULL bytes, Joomla!
also replaces these NULLs with special placeholders to maintain backward
compatibility, giving attackers a perfect opportunity to break the
deserialization format by flooding the username field with lots of
placeholders [26]. I guess this is exactly the original inspiration behind
that 0CTF challenge!
+--------------------[ Serialize, Replace, Then Pwn! ]--------------------+
=> [1] crafting the payload...