We have now found two use-after-free vulnerabilities in PHP’s rubbish assortment algorithm. Those vulnerabilities have been remotely exploitable over PHP’s unserialize function. We were also awarded with $2,000 by the Internet Bug Bounty committee (c.f. Many thanks go out to cutz for co-authoring this text. Pornhub’s bug bounty program and its relatively high rewards on Hackerone caught our attention. That’s why we’ve got taken the perspective of an advanced attacker with the full intent to get as deep as possible into the system, specializing in one principal goal: gaining remote code execution capabilities. Thus, we left no stone unturned and attacked what Pornhub is constructed upon: PHP. After analyzing the platform we quickly detected the utilization of unserialize on the web site. In all instances a parameter named « cookie » bought unserialized from Post information and afterwards mirrored by way of Set-Cookie headers. Standard exploitation techniques require so called Property-Oriented-Programming (POP) that contain abusing already current lessons with specifically outlined « magic methods » so as to trigger undesirable and malicious code paths.
Unfortunately, it was difficult for us to collect any details about Pornhub’s used frameworks and PHP objects usually. Multiple courses from widespread frameworks have been tested – all with out success. The core unserializer alone is relatively complicated as it involves more than 1200 strains of code in PHP 5.6. Further, many inside PHP classes have their very own unserialize methods. By supporting buildings like objects, arrays, integers, strings or even references it is not any surprise that PHP’s track record reveals a tendency for bugs and memory corruption vulnerabilities. Sadly, there were no identified vulnerabilities of such kind for newer PHP variations like PHP 5.6 or PHP 7, especially because unserialize already got quite a lot of attention in the past (e.g. phpcodz). Hence, auditing it may be in comparison with squeezing an already tightly squeezed lemon. Finally, after so much attention and so many security fixes its vulnerability potential should have been drained out and it ought to be secure, shouldn’t it? To find a solution Dario carried out a fuzzer crafted particularly for fuzzing serialized strings which have been passed to unserialize.
Running the fuzzer with PHP 7 immediately lead to unexpected behavior. This conduct was not reproducible when tested towards Pornhub’s server although. Thus, xhamster we assumed a PHP 5 model. However, working the fuzzer towards a newer version of PHP 5 just generated more than 1 TB of logs without any success. Eventually, after placing an increasing number of effort into fuzzing we’ve stumbled upon unexpected conduct again. Several questions needed to be answered: is the problem safety related? In that case can we only exploit it locally or also remotely? To additional complicate this situation the fuzzer did generate non-printable knowledge blobs with sizes of more than 200 KB. An incredible period of time was crucial to investigate potential issues. In spite of everything, we might extract a concise proof of idea of a working memory corruption bug – a so referred to as use-after-free vulnerability! Upon further investigation we discovered that the foundation cause could possibly be present in PHP’s rubbish collection algorithm, a part of PHP that is completely unrelated to unserialize.
However, the interaction of both elements occurred solely after unserialize had completed its job. Consequently, it was not well fitted to remote exploitation. After further analysis, gaining a deeper understanding for the problem’s root causes and a number of laborious work an identical use-after-free vulnerability was discovered that appeared to be promising for remote exploitation. The high sophistication of the found PHP bugs and their discovery made it mandatory to jot down separate articles. You’ll be able to read extra details in Dario’s fuzzing unserialize write-up. As well as, we’ve written an article about Breaking PHP’s Garbage Collection and Unserialize. Even this promising use-after-free vulnerability was significantly tough to take advantage of. Specifically, it concerned a number of exploitation levels. 1. The stack and heap (which also embody any potential person-enter) in addition to some other writable segments are flagged non-executable (c.f. 2. Even in case you are able to regulate the instruction pointer you have to know what you need to execute i.e. it’s essential have a sound deal with of an executable reminiscence phase.