text stringlengths 0 1.99k |
|---|
I think this bypass also echoes what we mentioned earlier about |
"cross-application" - security is never confined to just one dimension. |
Sometimes, shifting your perspective a bit can magically turn those |
seemingly rock-solid protections into just a piece of cake! ;) |
------[ 5.2 - From CTF to Real World! |
For a long time, CTFs have carried a kind of *original sin* - being |
criticized for putting too much emphasis on tricky techniques. As the |
technical bar kept rising, some challenges grew a bit overly contrived, |
giving people the impression that CTFs were becoming "disconnected from |
reality." That's exactly what gave birth to competitions like Real World |
CTF - aiming to ground every challenge in real-world applications and |
bring focus back to practical, realistic hacking scenarios! |
At Real World CTF 2019, the organizers set up a challenge using Nginx + |
PHP, expecting players to bypass the built-in XSS Auditor in the latest |
Chrome to steal the admin's cookie. Obviously, this was a challenge |
focusing on frontend security - but while messing around with the server, |
@d90pwn noticed something unusual happening on the backend. Specifically, |
he found that if the URL contained a newline, the server would |
unexpectedly respond with additional internal information. |
--------------------------[ PHP-FPM is Bleeding? ]------------------------- |
$ curl http://orange.local/test.php/AAAAAAAAA |
string(10) "/AAAAAAAAA" |
$ curl http://orange.local/test.php/AAAAA%0AB |
string(7) "TH_INFO" <= WTF!? |
--------------------------------------------------------------------------- |
Although @d90pwn didn't manage to crack this challenge during the |
competition, his post-event analysis (along with @neex and @beched) |
unexpectedly exposed a serious vulnerability in PHP-FPM. The entire issue |
started from an unintended behavior in Nginx - while processing URLs |
containing newlines, Nginx mistakenly passed an empty `PATH_INFO` to the |
backend PHP-FPM. Meanwhile, PHP-FPM always assumed that variable could |
never be empty, causing its internal logic to miscalculate the offset. |
This mistake eventually made the `path_info` point just before its |
intended buffer - giving attackers a chance to zero out that location! |
=> CVE-2019-11043: A Buffer Underflow leads to a single NULL-byte write! |
--------------------------------------------------------------------------- |
char *env_path_info = FCGI_GETENV(request, "PATH_INFO"); |
int pilen = env_path_info ? strlen(env_path_info) : 0; |
if (apache_was_here) { |
path_info = script_path_translated + ptlen; |
} else { |
// [1] `path_info` *UNDERFLOWS*, pointing before its intended buffer |
path_info = env_path_info ? env_path_info + pilen - slen : NULL; |
} |
old = path_info[0]; |
path_info[0] = 0; // <--- [2] single NULL-byte write! |
--------------------------------------------------------------------------- |
But how could a single NULL-byte write lead to an RCE? Here's the |
ingenious part: @neex skillfully abused PHP-FPM's inetrnal memory |
allocation for CGI variables. By overwriting the LSB (least significant |
bit) of the `pos` field in the structure to `0`, he was able to overwrite |
existing variable contents on the subsequent write. Combined with some |
Hash Table magic, he successfully crafted a pure data-only attack - |
performing full RCE without any memory read/write primitives at all [83]! |
Honestly, the entire exploit was incredibly neat and packed with details. |
Looking back through PHP's history, it's extremely rare to see |
vulnerabilities that can directly cause RCE without any dangerous |
functions or scripts at all. On top of that, this bug was also hard to |
uncover through traditional fuzzing. To trigger it, you had to not only |
leverage a specific edge case in Nginx, but also deal with PHP's internal |
contiguous memory allocations, making it way harder for tools like ASAN to |
catch - all of these truly make it a remarkable vulnerability in PHP |
history! |
So, without something like the CTF scene - where groups of hackers |
intensively focus on seemingly minor details through trial and error - who |
knows how long this bug would've stayed hidden? |
+---------------------[ Exploit PHP-FPM Like a Boss! ]--------------------+ |
=> [1] a minified payload to trigger the NULL-byte write! |
$ curl http://orange.local/index.php/%0A$(printf %032d)?$(printf %01759d) |
[...Switching to GDB] |
Breakpoint 1, init_request_info () at ./sapi/fpm/fpm/fpm_main.c:1222 |
1222 path_info[0] = 0; |
1: /x path_info = 0x55a371abfd60 |
2: /x request.env.data = 0x55a371abfd60 |
|-------------------------------- [ next ] -------------------------------| |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.