From open redirect to RCE in one week
In this article, I will tell you a story of how I chained multiple security issues to achieve RCE on several hosts of the Mail.Ru Group (or VKnow). For me, as a regular reader of bug bounty write-ups, it is always interesting to learn the train of hunter’s thoughts during uncommon vulnerability exploitation, so I…
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Context
Seedr is a platform for video advertising, now deprecated, that was added to the Mail.Ru Group (VK) bug bounty program on HackerOne. The researcher had subscribed to the VK program to receive notifications about new assets, but missed the notification that Seedr had been added. He first met Seedr in October 2021, found several simple XSS within minutes, and decided not to report them because of the high chance of a duplicate. Several other reports on Seedr had already been disclosed, including RCE in api/nr/report/{id}/download, SSRF plus RCE through fastCGI in POST /api/nr/video, stored XSS on https://seedr.ru and OS command injection on seedr.ru.
The feature at the centre of this write-up is the video player at player.seedr.ru. Given a video identifier and a hosting provider, the player fetches metadata about the video from the provider's API, parses it, and returns an HTML page with the video and filled Open Graph meta tags (title, description, image and so on).
Setup
The work was done during a December vacation, from a backpack and a laptop. The researcher spent time on recon: subdomain enumeration, port scanning, directory brute forcing. This turned up GitLab, Grafana, several API hosts, cron files in the web directory and stack traces, none of which were worth reporting, but one functionality caught his attention.
Tools used across the story:
- Burp Suite Professional, whose Proxy history was essential for finding the first mention of Kohana and for locating the endpoint that produced a particular log record. The report notes that vanilla Burp Suite Community cannot do this.
- PHPGGC, a library of PHP
unserialize()payloads with a tool to generate them, which at the time had almost 90 available payloads. - webhook.site, used to receive incoming HTTP connections and host payloads.
- dirsearch, used for directory scanning.
- A controlled server of the researcher's own, used later to host serialised strings containing null bytes.
Finding it
In the HTML source code of the https://api-stage.seedr.ru/player page, the researcher noticed a comment containing a full player URL:

https://player.seedr.ru/video?vid=cpapXGq50UY&post_id=57b6ceef64225d5b0f8b456c&config=https%3A%2F%2Fseedr.com%2Fconfig%2F57975d1b64225d607e8b456e.json&hosting=youtube
The obvious idea is to point the config GET parameter at your own host to receive an incoming HTTP connection. The researcher did that, received no connections after several attempts, and moved on to other parameters.
Opening the full URL in a browser showed a response whose Open Graph meta tags were filled with information about the video, such as title, description and image:

After some tests he concluded that post_id and config have no significant effect on the response, and simplified the URL to:
https://player.seedr.ru/video?vid=cpapXGq50UY&hosting=youtube
Assuming the player would not support only YouTube, he changed the hosting GET parameter to coub and vimeo:


From this he inferred the server behaviour: depending on hosting, the server performs an HTTP request with file_get_contents() to the YouTube, Vimeo or Coub API, downloads metadata about the video named by vid, parses it, and returns the player HTML page with the video and filled Open Graph meta tags.
The vid parameter is an injection point: it controls the last part of the path passed to file_get_contents(). Path traversal (/../) and useful symbols (?, #, @) were usable as well.
More interesting: for Vimeo the server requests http://vimeo.com/api/v2/video/VID.php, and when the .php extension is used in the path, Vimeo returns not a JSON string but a serialised string:

The researcher assumed that after file_get_contents() the server calls unserialize() on the response from Vimeo:

That is unsafe deserialisation, but only as long as the response is under Vimeo's control.
Exploitation
Step 1: three scenarios
At that point three possible paths were on the table:
- Fuzz
file_get_contents()to escape thevimeo.comhost, achieve blind SSRF and probably unsafe deserialisation. - Find a controlled response on
vimeo.com, leading to probably unsafe deserialisation. - Find an open redirect on
vimeo.com, giving blind SSRF and probably unsafe deserialisation.
After hours of modifying the vid parameter and fuzzing file_get_contents() locally, nothing useful came up, and the researcher shared the finding with several trusted mates.
Step 2: looking for a controlled response on vimeo.com
The second scenario needs an endpoint on vimeo.com that meets four requirements:
- 200 OK HTTP status code;
- available to an unauthenticated user;
- the controlled string at the beginning of the response body, because PHP will successfully parse something like
{VALID_SER_STRING}TRASH; - the controlled string supports
{ }and"symbols, which are required for storing serialised objects.
Four attempts were made:
injectionis not a valid method. Cons: 404 Not Found, does not support{}or"symbols.

injectionis not a valid format.

- JS callback. Cons:
/**/at the beginning, does not support{}or"symbols.

- Export of chat of a live broadcast. Cons: date and name at the beginning, requires authentication.

The second scenario failed too, leaving the open redirect as the last hope.
Step 3: the open redirect on vimeo.com
The researcher remembered the article by Harsh Jaiswal (@rootxharsh) about SSRF on vimeo.com, in which several open redirects on vimeo.com were chained. That finding was from 2019, almost three years earlier, so he assumed the redirects had been fixed. He had also already looked for an open redirect while hunting for a controlled response, without success.
A previously disclosed HackerOne report from 2015 with an open redirect on vimeo.com (https://hackerone.com/reports/44157) suggested there was a chance of finding another one.
Because the screenshots in Harsh's article were only lightly censored, the endpoint could be fingerprinted by its GET parameters. Combining that with some googling and the Vimeo API docs, the researcher guessed which endpoint Harsh had used, but still did not know which values to provide.

Screenshot from Harsh's article
He rarely asks for help while exploiting something, but at this impasse he contacted Harsh, shared what he had, and received a working open redirect link: the same endpoint he had guessed, but with the proper GET parameter values. From that link he understood that it is not a security issue on vimeo.com but just a feature.

With a working open redirect on vimeo.com, he tried it against the player:


He finally got an HTTP hit on his host.
Step 4: semi-blind SSRF and port scanning
Before jumping to deserialisation he played with SSRF, pointing the redirect at local addresses:
https://[redacted]

https://[redacted]:22

http://[redacted]:25

Because the response from file_get_contents() goes directly to unserialize(), full SSRF was not achievable. What he had was semi-blind SSRF with the ability to perform a port scan:

With the SSRF potential mostly used up, he switched to exploiting unserialize().
Step 5: blind gadget chain brute force
What is needed for successful exploitation of unsafe deserialisation in PHP:
- controlled input;
- a class with a magical method (
__wakeup(),__destroy(),__toString()and so on); - useful for an attacker functionality in that magical method, abusable for file manipulation, RCE, SQLi and so on;
- the class is loaded.
At that point only the first requirement was met. Nothing was known about the backend code, so the only way forward was to blindly try all known gadget chains with PHPGGC. A large part of its payloads target CMSs and frameworks such as WordPress, ThinkPHP, Typo3, Magento and Laravel, which would be useless here, so he bet on commonly used libraries: Doctrine, Guzzle, Monolog and Swift Mailer.
All available payloads were pre-generated with PHPGGC, hosted on a controlled server, and brute-forced. Every case returned the same error:

The error occurs because inside serialised string there is a reference to a class that hasn't been included yet, so the PHP autoloading mechanism is triggered to load that class, and this fails for some reason.
At that point the script looked very primitive and did not include any additional classes that could be used. He submitted a report named (player.seedr.ru) Semi-blind SSRF (https://hackerone.com/reports/1430989) and invited Harsh Jaiswal as a collaborator for his open redirect on vimeo.com.
Step 6: the Kohana error page
A few days later the researcher came across something about a use-after-free vulnerability in PHP unserialize(). The PHP version on player.seedr.ru was outdated, so he started researching that area and got acquainted with the reports of Taoguang Chen, who had reported many unserialize() issues to PHP. Memory-related vulnerabilities were still a dark area for him, but he tried to build some payloads. After poking at the local environment, he returned to player.seedr.ru, hosted the payload on a controlled server, sent a request, and got:

ErrorException [ 2 ]: file_put_contents(/var/www/seedr.backend.v2/application/logs/2021/12/20.php): failed to open stream: No space left on device ~ SYSPATH/classes/kohana/log/file.php [ 81 ]
The error probably occurred because too many requests with scanners for hidden directories and files had been sent on previous days. A custom class for logging meant the "primitive" script did load a logging class after all, and the name Kohana had already been seen during testing of Seedr.
Using Burp Suite Professional, the first mention of Kohana was quickly found in Proxy history. Opening that page revealed a detailed error page:

Vanilla Burp Suite Community can't do this

Paradise for security tester
The researcher notes that Seedr and Nativeroll are both video advertising platforms, that Seedr had an old-fashioned design and was probably created long before Nativeroll, and that both were bought by Mail.Ru Group, probably merged and listed on HackerOne at the same scope. So v2.nativeroll.tv/api/, api.seedr.ru, api-stage.seedr.ru and player.seedr.ru shared the same code base.
The error page showed Environment, Included files and Loaded extensions. Clicking Included files showed:

There were almost 90 included files, different classes loaded with something like autoload.php. Kohana is a framework; the GitHub repository https://github.com/koseven/kohana/ looked deprecated:

Because v2.nativeroll.ru and api.seedr.ru share the same code base, the same payload (https://api.seedr.ru/<svg>) triggered the same Error exception on api.seedr.ru.
Step 7: triggering the error on the attacked endpoint
To trigger the Error exception exactly on api.seedr.ru/video, the endpoint being attacked, the researcher took the result from http://vimeo.com/api/v2/video/123459.php and changed the value of the description attribute from string to array:

a:1:{i:0;a:23:{s:2:"id";i:123456;s:5:"title";s:30:"London Tornado — The aftermath";s:11:"description";a:1:{i:0;i:1337;}s:3:"url";s:24:"https://vimeo.com/123456";s:11:"upload_date";s:19:"2006-12-14 06:53:32";s:15:"thumbnail_small";s:111:"https://i.vimeocdn.com/video/46783763-[redacted]-d_100x75";s:16:"thumbnail_medium";s:112:"https://i.vimeocdn.com/video/46783763-[redacted]-d_200x150";s:15:"thumbnail_large";s:108:"https://i.vimeocdn.com/video/46783763-[redacted]-d_640";s:7:"user_id";i:146861;s:9:"user_name";s:11:"wordtracker";s:8:"user_url";s:29:"https://vimeo.com/wordtracker";s:19:"user_portrait_small";s:51:"https://i.vimeocdn.com/portrait/defaults-blue_30x30";s:20:"user_portrait_medium";s:51:"https://i.vimeocdn.com/portrait/defaults-blue_75x75";s:19:"user_portrait_large";s:53:"https://i.vimeocdn.com/portrait/defaults-blue_100x100";s:18:"user_portrait_huge";s:53:"https://i.vimeocdn.com/portrait/defaults-blue_300x300";s:21:"stats_number_of_likes";i:11;s:21:"stats_number_of_plays";i:122560;s:24:"stats_number_of_comments";i:12;s:8:"duration";i:32;s:5:"width";i:320;s:6:"height";i:240;s:4:"tags";s:0:"";s:13:"embed_privacy";s:8:"anywhere";}}
During script execution htmlspecialchars() expected a string but got an array, which caused an Error exception with a partly disclosed template and stack trace:


Among the included files there was a composer autoload script. Several files stood out as potentially useful for deserialisation:
- Guzzle (
/var/www/sentry/vendor/guzzlehttp/…) - Swift Mailer (
MODPATH/email/vendor/swiftmailer/…) - Symfony (
/var/www/sentry/vendor/symfony/…) - Mustache (
MODPATH/kostache/vendor/mustache/…) - Sentry (
/var/www/sentry/vendor/sentry/…)
PHPGGC has gadget chains for Guzzle, Swift Mailer and Symfony. After building and testing the payloads on api-stage.seedr.ru, a new error appeared. A Guzzle payload returned FnStream should never be unserialized, which indicated an already patched version:

Swift Mailer and Symfony did not work at all, and analysis of the Mustache and Sentry code on GitHub bore no fruit. Third-party libraries would not help; it was time to dive into Kohana.
Step 8: finding a gadget in Kohana
Searching the Kohana repository for magical methods such as __wakeup(), __destruct() and __toString() returned nothing:

But the repository has a system directory which is in fact a dedicated repository, Kohana Core (https://github.com/kohana/core/tree/[redacted]):


Searching that repository gave almost no results for __destruct() and __wakeup(), but results for __toString() were reassuring:

classes/Kohana/View.php and its render() function immediately caught his attention. Having developed a few projects with Laravel, he knew about the MVC pattern and Blade, and guessed that a rendering engine loading templates might let him pass his own file or content.
The render() function accepts one argument called $file and then calls capture():
public function render($file = NULL){ if ($file !== NULL) { $this->set_filename($file); } if (empty($this->_file)) { throw new View_Exception('You must set the file to use within your view before rendering'); } // Combine local and global data and capture the output return View::capture($this->_file, $this->_data);}
When render() is called without an argument, set_filename() is bypassed. That function also checks the existence of $file in the views directory:
public function set_filename($file){ if (($path = Kohana::find_file('views', $file)) === FALSE) { throw new View_Exception('The requested view :file could not be found', array(':file' => $file,)); } // Store the file path locally $this->_file = $path; return $this;}
So capture() is called with the $this->_file variable:
public function render($file = NULL){ ... // Combine local and global data and capture the output return View::capture($this->_file, $this->_data);}
capture() combines local and global data and captures the output, for example to render an email template with a username variable:
protected static function capture($kohana_view_filename, array $kohana_view_data){ // Import the view variables to local namespace extract($kohana_view_data, EXTR_SKIP); if (View::$_global_data) { // Import the global view variables to local namespace extract(View::$_global_data, EXTR_SKIP | EXTR_REFS); } // Capture the view output ob_start(); try { // Load the view within the current scope include $kohana_view_filename; } catch (Exception $e) { // Delete the output buffer ob_end_clean(); // Re-throw the exception throw $e; } // Get the captured output and close the buffer return ob_get_clean();}
capture() accepts $kohana_view_filename and $kohana_view_data. The interesting part is:
...try{ // Load the view within the current scope include $kohana_view_filename;}...
include() means LFI and RCE potential. And $kohana_view_filename is controllable: it is $this->_file, an attribute of the View class.
class Kohana_View { // Array of global variables protected static $_global_data = array(); ... // View filename protected $_file; // Array of local variables protected $_data = array(); ...}
All the elements for successful unsafe deserialisation were now present:
- controlled input;
- a magical method
__toString()of theViewclass with a usefulinclude(); - the
Viewclass loaded.
Step 9: building the chain
A gadget and chain for PHPGGC were created locally and later committed and added to the main repository (https://github.com/ambionics/phpggc/tree/master/gadgetchains/Kohana/FR/1):
<?phpnamespace GadgetChain\Kohana;class FR1 extends \PHPGGC\GadgetChain\FileRead{ public static $version = '3.*'; public static $vector = '__toString'; public static $author = 'byq'; public static $information = 'include()'; public function generate(array $parameters) { return new \View($parameters['remote_path']); }}<?phpclass View { protected $_file; public function __construct($_file) { $this->_file = $_file; }}
Running PHPGGC produced the following serialised object:

Hosting the payload on a controlled server and sending a request gave:

Something new, but not what was hoped for. __wakeup() and __destruct() trigger at object creation and destruction respectively, but __toString() does not. As the PHP docs say:
The __toString() method allows a class to decide how it will react when it is treated like a string. For example, what echo $obj; will print.
So the View object had to be output somehow. The obvious way was to provide it as the value of the title or description attribute, the same trick used earlier with an array to trigger the Error exception. The payload looked like this:
a:1:{i:0;a:23:{s:2:"id";i:123456;s:5:"title";s:30:"London Tornado — The aftermath";s:11:"description";O:4:"View":1:{s:8:"*_file";s:11:"/etc/passwd";}s:3:"url";s:24:"https://vimeo.com/123456";s:11:"upload_date";s:19:"2006-12-14 06:53:32";s:15:"thumbnail_small";s:111:"https://i.vimeocdn.com/video/46783763-[redacted]-d_100x75";s:16:"thumbnail_medium";s:112:"https://i.vimeocdn.com/video/46783763-[redacted]-d_200x150";s:15:"thumbnail_large";s:108:"https://i.vimeocdn.com/video/46783763-[redacted]-d_640";s:7:"user_id";i:146861;s:9:"user_name";s:11:"wordtracker";s:8:"user_url";s:29:"https://vimeo.com/wordtracker";s:19:"user_portrait_small";s:51:"https://i.vimeocdn.com/portrait/defaults-blue_30x30";s:20:"user_portrait_medium";s:51:"https://i.vimeocdn.com/portrait/defaults-blue_75x75";s:19:"user_portrait_large";s:53:"https://i.vimeocdn.com/portrait/defaults-blue_100x100";s:18:"user_portrait_huge";s:53:"https://i.vimeocdn.com/portrait/defaults-blue_300x300";s:21:"stats_number_of_likes";i:11;s:21:"stats_number_of_plays";i:122560;s:24:"stats_number_of_comments";i:12;s:8:"duration";i:32;s:5:"width";i:320;s:6:"height";i:240;s:4:"tags";s:0:"";s:13:"embed_privacy";s:8:"anywhere";}}
Updating the payload on the controlled server and sending the request finally gave:

The content of /etc/passwd appeared inside the og:description meta tag. Local file read is better than semi-blind SSRF, but still not RCE.
Step 10: hunting for a place to store a payload
With LFI in hand, the next problem was where to store an RCE payload so that include() could reach it. The common techniques:
- file upload (the application had no such functionality);
- logs (apache, nginx, mail, ssh, …);


/proc/*/fd, …;

- session file;

Almost everything was tried and nothing worked. So it was time to go back to the "no space left on device" error:

That error revealed a log file path: /application/logs/2021/12/20.php. Opening https://api.seedr.ru/application/logs/2021/12/20.php in the browser returned No direct script access. Almost every PHP file in the Kohana framework has such a string at the beginning:

So log files with the .php extension could not be accessed directly from the browser. On the staging host, http://api-stage.seedr.ru/application/logs/2021/12/20.php returned a 404. Changing the .php extension to .log gave:

A huge log file, big enough to freeze Burp Suite a little. This trick did not work on the production host api.seedr.ru; the researcher can only guess that the Seedr developers changed something on staging to make accessing log files easier, which led to a security issue.
The first Error exception had left a record in the log file. After a short analysis, the log was poisoned with such a record:

With PHPGGC a new serialised View object was created with the _file attribute set to /var/www/t1.seedr.backend/application/logs/2021/12/20.log, hosted on the controlled server, and sent. The result was the following error:

The log file was too huge (more than 200000 lines), some function failed on one of the ? symbols, threw an exception and stopped the execution of the script. From the PHP docs:

Because the December 20 log file was ruined with unsuccessful payloads, further tests on that host were useless, so work moved to the local environment. Hours of debugging and tests with include() and the log file did not lead to the desired result.
Step 11: the base64 idea and the log poisoning plan
During a morning shower the researcher remembered the article by Charlese Fol, Laravel <= v8.4.2 debug mode: Remote code execution (CVE-2021-3129), which uses a technique with multiple base64 decoding that ignores non-base64 characters. He had first read about it in Orange Tsai's blog. The idea was to poison a log with multiple base64 encoded PHP payloads, then decode it with multiple convert.base64-decode filters inside the include() function to bypass the exception caused by the ? symbol. But after a sleepless night he forgot that in the Laravel case the technique abused a file_get_contents() and file_put_contents() chain with the same arguments, which allowed Charlese to rewrite the log. He also forgot about this limitation:

Screenshot from Charlese's article
Because the log file path is predictable (/application/logs/2021/12/20.log), a few log files for previous days were downloaded, and the plan was to poison the December 21 log at the beginning of the day, before it grew too large. All collected information was posted to the H1 report, with a full day left before December 21.
Without wasting time he tried to exploit the finding on production api.seedr.ru, since the last tests had been on api-stage.seedr.ru. A View object with _file set to /etc/passwd was generated with PHPGGC, hosted on the controlled server, and sent, but the content of /etc/passwd did not appear in the response. Repeating the same steps on api-stage.seedr.ru worked fine.
Step 12: null bytes
Here the researcher confesses that when generating the serialised object with PHPGGC he modified it a little:

The *_file string does not have 8 symbols, it has only 6. That is what was modified every time, and it worked flawlessly on api-stage.seedr.ru. Later, in the stack trace, he noticed:

The value of the protected _file attribute is NULL, but for some reason the View object has a public *_file attribute with the payload. To store a protected value in a serialised string, PHP uses null characters (\0) around the * symbol, which is why *_file has 8 symbols:

Because the payload was copy-pasted to webhook.site, the null characters were not stored and unserialize() received a public *_file attribute. The fix was to host the serialised string with null bytes on his own server: vimeo.com redirects requests there, and the server just echo()es the payload with null characters. After observing the content of /etc/passwd on api.seedr.ru, he returned to analysing the downloaded log files.
Step 13: the last poison
The log files had many record types, but only a few could be used to store a payload, and most required authentication. During the first analysis he had noticed the following record type:

This record type stored the payload only once per record and did not repeat it several times like the previous attempt. A possible injection point was noted: the user-agent. The problem was not knowing how to generate such a record and which endpoint to access. Grepping the logs for his IP showed that today's log file already had such a record with his IP, meaning the required endpoint had definitely been touched. Burp Proxy history had more than 40000 records by then, so finding the proper endpoint was difficult. Comparing the time of the record with his IP and the activity at that time suggested the record was probably generated during a dirsearch scan. Rerunning it found the endpoint: api-stage.seedr.ru/inc.
On the local environment the new payload was hidden in a test log file, include()d, and the output of the bash command came back. All that was left was to wait for December 21 and a fresh log file, because on December 20 the log files for api.seedr.ru and api-stage.seedr.ru had been poisoned with unsuccessful payloads.
The next day the log was poisoned with the following request:

The payload was generated, hosted on the server, and the request sent:

He had forgotten to change $argv[1] to $_GET[1] after local tests. Waiting one more day was the plan, but he remembered that there was one more attempt available that day on api-stage.seedr.ru:

This is how victory looks
Root cause
The chain rests on several mistakes. The player takes the vid GET parameter and uses it as the last part of a path passed to file_get_contents(), so path traversal and symbols such as ?, # and @ are usable. The response of that request is then passed to unserialize(), which is only safe while the response is under Vimeo's control. An open redirect on vimeo.com, which the researcher describes as a feature rather than a vulnerability, breaks that assumption and lets the attacker serve an arbitrary serialised string.
The gadget is in Kohana Core. Kohana_View::render() called without an argument skips set_filename(), which is the function that checks the file exists in the views directory, and passes the protected _file attribute straight to View::capture(), which include()s it. Because _file is an attribute of a class with __toString(), a serialised View object placed in a field that gets rendered as a string (here the description, later the user-agent in a log record) reaches include() with an attacker-chosen path. That gives local file read, and with a writable file such as a log, code execution.
The staging host made this easier by serving log files with the .log extension, which bypassed the No direct script access guard present in the .php files. The report does not say why staging behaved differently; the researcher can only guess the developers changed something there.
Impact
On api-stage.seedr.ru the researcher achieved local file read (the content of /etc/passwd appeared in the og:description meta tag) and, through log poisoning, RCE. On production api.seedr.ru he observed the /etc/passwd content but the .log access trick did not work there. The report title states RCE on several hosts of Mail.Ru Group (VK). Before that, the same chain gave semi-blind SSRF with the ability to perform a port scan, because the response from file_get_contents() goes directly to unserialize() and cannot be read back. The open redirect itself is described as a feature on vimeo.com, not a security issue there. The .log access trick did not work on production api.seedr.ru; the log poisoning path relied on a predictable log path (/application/logs/2021/12/20.log).
Fix
This write-up does not describe the remediation applied by the vendor. What the chain shows should be addressed: do not pass user-controlled input into file_get_contents() in a way that allows escaping the intended host, and do not unserialize() data fetched over the network; use a safe format such as JSON. In Kohana, View::capture() should not include() a path taken from a deserialised attribute without validation against the views directory, and log files should not be reachable with an extension that the web server will serve, nor should they be writable with attacker-controlled content that can later be included.
Variants to test
- Look for player or embed pages that take a video identifier and a hosting provider, and check whether the identifier controls the path of a server-side fetch. A positive result is a request to your own host, or a response that changes when you add
/../,?,#or@. - Check whether the fetched response is deserialised: point the fetch at a host you control that returns a serialised string, and see whether a class-related error appears. A positive result is an autoload or
unserialize()error naming a class. - Enumerate hosting providers accepted by the parameter. A positive result is a provider whose API returns a serialised string when the
.phpextension is used, as Vimeo did here. - Look for open redirects on the provider domain, including documented features rather than bugs. A positive result is a redirect to an arbitrary host that the server-side fetch follows.
- With SSRF, try
https://[redacted],https://[redacted]:22andhttp://[redacted]:25and compare timing or errors to infer open ports. - Fingerprint the framework from error pages and included files. A positive result is a list of loaded classes and vendor paths that map to known gadget chains.
- Search the framework for
__toString(),__wakeup()and__destruct()and forinclude(),require()or file functions reachable from them. A positive result is a class whose magical method reachesinclude()with an attribute you can set in a serialised object. - Find a field that is rendered as a string (title, description, user-agent) and place the serialised object there. A positive result is the content of a file such as
/etc/passwdin the response. - Look for log files reachable with an alternative extension (
.loginstead of.php) and for endpoints that write attacker-controlled values such as the user-agent into them. A positive result is a log record containing your payload at a predictable path. - When hosting serialised payloads, remember that protected properties need null bytes around
*; a service that strips them will deliver a public property instead. A positive result is the protected attribute being set in the stack trace.
What happened, in plain words
A security researcher found a way to make a video advertising platform called Seedr run his own commands on its servers. He did it by chaining several smaller weaknesses, each harmless on its own, until they added up to full control. The story starts with a video player page that fetches information about a video from YouTube, Vimeo or Coub. The researcher noticed that the part of the web address that says which video to fetch was being used to build a request to those services. By manipulating that part, he could make the server fetch a page from Vimeo that contained a special string. That string was then turned back into a PHP object by the server, a process called deserialisation. Normally that is safe because Vimeo controls what is in the string. But the researcher found a way to make Vimeo redirect the request to a server he controlled, so he could put any string he wanted. He then built a malicious object using a class from the Kohana framework that the server used. That object, when converted to text, would include a file of his choosing. That gave him the ability to read files on the server. Finally, he found that on the staging host log files were accessible with a different extension and that he could write his own code into them through the user-agent header. By including that log file, he could run commands. The journey involved many dead ends, which he describes in detail.
The background: what is Seedr and why care?
Seedr was a platform for video advertising. It is now deprecated. It was added to the Mail.Ru Group (also known as VK) bug bounty program on HackerOne. A bug bounty program is a scheme where companies pay people for finding and reporting security problems in their systems. HackerOne is a website that hosts such programs.
The researcher had subscribed to the VK program to get notifications when new assets (websites or services) were added. He missed the notification about Seedr. He first encountered Seedr in October 2021. Within minutes he found several simple cross-site scripting (XSS) issues. XSS is a type of vulnerability where an attacker can inject their own JavaScript code into a page that other users view. He decided not to report them because he thought they would be duplicates (someone else would have already reported them). Several other reports about Seedr had already been disclosed publicly, including:
- Remote code execution (RCE) in
api/nr/report/{id}/download - Server-side request forgery (SSRF) plus RCE through fastCGI in
POST /api/nr/video - Stored XSS on
https://seedr.ru - OS command injection on
seedr.ru
RCE means an attacker can run their own commands on the server. SSRF means an attacker can make the server send requests to other systems. Command injection means injecting operating system commands into a program.
The feature at the centre of this write-up is the video player at player.seedr.ru. When you give it a video identifier and a hosting provider (like YouTube), the player fetches metadata about that video from the provider's API. An API (Application Programming Interface) is a way for two programs to talk to each other. Here, the player asks the provider's API for information about a video. The player then parses that information and returns an HTML page with the video and filled Open Graph meta tags. Open Graph meta tags are special HTML tags that describe a page's content for social media. They include things like title, description and image.
Setting the scene
The researcher did this work during a December vacation, travelling with just a backpack and a laptop. He spent time on reconnaissance (recon): finding subdomains, scanning ports, and brute-forcing directories. Subdomain enumeration is finding all the subdomains of a target (like api.example.com). Port scanning is checking which network ports are open on a server. Directory brute forcing is guessing common directory names to find hidden pages. This turned up GitLab, Grafana, several API hosts, cron files in the web directory, and stack traces. None of these were worth reporting, but one functionality caught his attention.
He used several tools throughout the story:
- Burp Suite Professional: a tool for intercepting and modifying web traffic. Its Proxy history (a log of all requests and responses) was essential for finding the first mention of Kohana and for locating the endpoint that produced a particular log record. The report notes that the free Community version cannot do this.
- PHPGGC: a library of PHP
unserialize()payloads with a tool to generate them. At the time it had almost 90 available payloads. A payload is the actual data you send to exploit a vulnerability. - webhook.site: a service to receive incoming HTTP connections and host payloads. HTTP is the protocol used by web browsers and servers to communicate.
- dirsearch: a tool for directory scanning.
- A controlled server: the researcher's own server, used later to host serialised strings containing null bytes.
Finding the entry point
In the HTML source code of the https://api-stage.seedr.ru/player page, the researcher noticed a comment containing a full player URL:

https://player.seedr.ru/video?vid=cpapXGq50UY&post_id=57b6ceef64225d5b0f8b456c&config=https%3A%2F%2Fseedr.com%2Fconfig%2F57975d1b64225d607e8b456e.json&hosting=youtube
This URL has several GET parameters. GET parameters are the key-value pairs after the ? in a URL, separated by &. They are used to pass data to the server. Here we have:
vid=cpapXGq50UY: the video identifier.post_id=57b6ceef64225d5b0f8b456c: some internal ID.config=https%3A%2F%2Fseedr.com%2Fconfig%2F57975d1b64225d607e8b456e.json: a URL to a configuration file, URL-encoded (the%3Aetc. are encoded characters).hosting=youtube: which video host to use.
The obvious idea is to change the config parameter to point to your own server, to see if the server makes a request to it. The researcher tried that, but received no connections after several attempts. So he moved on to other parameters.
He then opened the full URL in a browser and saw that the response had Open Graph meta tags filled with information about the video, such as title, description and image:

After some tests, he concluded that post_id and config have no significant effect on the response. So he simplified the URL to:
https://player.seedr.ru/video?vid=cpapXGq50UY&hosting=youtube
He assumed the player would not support only YouTube, so he changed the hosting parameter to coub and vimeo:


From this he inferred the server's behaviour: depending on the hosting value, the server makes an HTTP request using the PHP function file_get_contents() to the YouTube, Vimeo or Coub API. It downloads metadata about the video specified by vid, parses it, and returns the player HTML page with the video and filled Open Graph meta tags.
The vid parameter is an injection point: it controls the last part of the path passed to file_get_contents(). Path traversal (/../) and useful symbols (?, #, @) were also usable. Path traversal means using ../ to move up directories and access files outside the intended directory.
More interesting: for Vimeo, the server requests http://vimeo.com/api/v2/video/VID.php. When the .php extension is used in the path, Vimeo returns not a JSON string but a serialised string:

JSON is a common data format that looks like JavaScript objects. A serialised string is a way to represent an object as a string so it can be stored or sent. In PHP, serialize() turns an object into a string, and unserialize() turns it back into an object.
The researcher assumed that after file_get_contents(), the server calls unserialize() on the response from Vimeo:

That is unsafe deserialisation, but only as long as the response is under Vimeo's control. If an attacker can control the response, they can provide their own serialised object, which might contain malicious code.
Exploitation
Step 1: three scenarios
At that point, three possible paths were on the table:
- Fuzz
file_get_contents()to escape thevimeo.comhost, achieve blind SSRF and probably unsafe deserialisation. Fuzzing means trying many variations to find a behaviour. Blind SSRF means the attacker can make the server send requests but cannot see the responses. - Find a controlled response on
vimeo.com, leading to probably unsafe deserialisation. - Find an open redirect on
vimeo.com, giving blind SSRF and probably unsafe deserialisation. An open redirect is a URL on a site that redirects to any other site, often used for phishing.
After hours of modifying the vid parameter and fuzzing file_get_contents() locally, nothing useful came up. He shared the finding with several trusted friends.
Step 2: looking for a controlled response on vimeo.com
The second scenario needs an endpoint on vimeo.com that meets four requirements:
- 200 OK HTTP status code (success).
- Available to an unauthenticated user (no login required).
- The controlled string at the beginning of the response body, because PHP will successfully parse something like
{VALID_SER_STRING}TRASH. That means if the serialised string is at the start, PHP will ignore the rest. - The controlled string supports
{ }and"symbols, which are required for storing serialised objects.
Four attempts were made:
injectionis not a valid method. Cons: 404 Not Found, does not support{}or"symbols.

injectionis not a valid format.

- JS callback. Cons:
/**/at the beginning, does not support{}or"symbols. A JS callback is a function name you provide that the server calls with data.

- Export of chat of a live broadcast. Cons: date and name at the beginning, requires authentication.

The second scenario failed too, leaving the open redirect as the last hope.
Step 3: the open redirect on vimeo.com
The researcher remembered an article by Harsh Jaiswal (@rootxharsh) about SSRF on vimeo.com, in which several open redirects on vimeo.com were chained. That finding was from 2019, almost three years earlier, so he assumed the redirects had been fixed. He had also already looked for an open redirect while hunting for a controlled response, without success.
A previously disclosed HackerOne report from 2015 with an open redirect on vimeo.com (https://hackerone.com/reports/44157) suggested there was a chance of finding another one.
Because the screenshots in Harsh's article were only lightly censored, the endpoint could be fingerprinted by its GET parameters. Fingerprinting means identifying the technology or endpoint from clues. Combining that with some googling and the Vimeo API docs, the researcher guessed which endpoint Harsh had used, but still did not know which values to provide.

Screenshot from Harsh's article
He rarely asks for help while exploiting something, but at this impasse he contacted Harsh, shared what he had, and received a working open redirect link: the same endpoint he had guessed, but with the proper GET parameter values. From that link he understood that it is not a security issue on vimeo.com but just a feature.

With a working open redirect on vimeo.com, he tried it against the player:


He finally got an HTTP hit on his host. That means his server received a request from the Seedr server, confirming the SSRF.
Step 4: semi-blind SSRF and port scanning
Before jumping to deserialisation, he played with SSRF, pointing the redirect at local addresses:
https://[redacted]

https://[redacted]:22

http://[redacted]:25

[redacted] is localhost, the server itself. Port 22 is typically SSH, port 25 is SMTP (email). By trying different ports, he could see which ones are open.
Because the response from file_get_contents() goes directly to unserialize(), full SSRF was not achievable. Full SSRF would let him read the response. What he had was semi-blind SSRF with the ability to perform a port scan:

With the SSRF potential mostly used up, he switched to exploiting unserialize().
Step 5: blind gadget chain brute force
What is needed for successful exploitation of unsafe deserialisation in PHP:
- Controlled input (the serialised string).
- A class with a magical method (
__wakeup(),__destroy(),__toString()and so on). Magical methods are special methods in PHP that are called automatically in certain situations.__wakeup()is called when an object is unserialized.__destruct()is called when an object is destroyed.__toString()is called when an object is treated as a string. - Useful for an attacker functionality in that magical method, abusable for file manipulation, RCE, SQLi and so on. SQLi is SQL injection, another vulnerability type.
- The class is loaded (available in the running PHP script).
At that point only the first requirement was met. Nothing was known about the backend code, so the only way forward was to blindly try all known gadget chains with PHPGGC. A gadget chain is a sequence of objects and methods that, when triggered, achieve a malicious goal.
A large part of PHPGGC's payloads target CMSs and frameworks such as WordPress, ThinkPHP, Typo3, Magento and Laravel, which would be useless here. So he bet on commonly used libraries: Doctrine, Guzzle, Monolog and Swift Mailer.
All available payloads were pre-generated with PHPGGC, hosted on a controlled server, and brute-forced. Every case returned the same error:

The error occurs because inside serialised string there is a reference to a class that hasn't been included yet, so the PHP autoloading mechanism is triggered to load that class, and this fails for some reason.
Autoloading is PHP's automatic way of loading class files when they are first used. If the class doesn't exist, it fails.
At that point the script looked very primitive and did not include any additional classes that could be used. He submitted a report named (player.seedr.ru) Semi-blind SSRF (https://hackerone.com/reports/1430989) and invited Harsh Jaiswal as a collaborator for his open redirect on vimeo.com.
Step 6: the Kohana error page
A few days later, the researcher came across something about a use-after-free vulnerability in PHP unserialize(). Use-after-free is a memory corruption bug where a program uses memory after it has been freed. The PHP version on player.seedr.ru was outdated, so he started researching that area and got acquainted with the reports of Taoguang Chen, who had reported many unserialize() issues to PHP. Memory-related vulnerabilities were still a dark area for him, but he tried to build some payloads. After poking at the local environment, he returned to player.seedr.ru, hosted the payload on a controlled server, sent a request, and got:

ErrorException [ 2 ]: file_put_contents(/var/www/seedr.backend.v2/application/logs/2021/12/20.php): failed to open stream: No space left on device ~ SYSPATH/classes/kohana/log/file.php [ 81 ]
This error message says that the function file_put_contents() tried to write to a log file at /var/www/seedr.backend.v2/application/logs/2021/12/20.php but failed because there was no space left on the device. The error probably occurred because too many requests with scanners for hidden directories and files had been sent on previous days.
A custom class for logging meant the "primitive" script did load a logging class after all. The name Kohana had already been seen during testing of Seedr.
Using Burp Suite Professional, the first mention of Kohana was quickly found in Proxy history. Opening that page revealed a detailed error page:

Vanilla Burp Suite Community can't do this

Paradise for security tester
The researcher notes that Seedr and Nativeroll are both video advertising platforms. Seedr had an old-fashioned design and was probably created long before Nativeroll. Both were bought by Mail.Ru Group, probably merged and listed on HackerOne at the same scope. So v2.nativeroll.tv/api/, api.seedr.ru, api-stage.seedr.ru and player.seedr.ru shared the same code base.
The error page showed Environment, Included files and Loaded extensions. Clicking Included files showed:

There were almost 90 included files, different classes loaded with something like autoload.php. Kohana is a framework; the GitHub repository https://github.com/koseven/kohana/ looked deprecated:

Because v2.nativeroll.ru and api.seedr.ru share the same code base, the same payload (https://api.seedr.ru/<svg>) triggered the same Error exception on api.seedr.ru.
Step 7: triggering the error on the attacked endpoint
To trigger the Error exception exactly on api.seedr.ru/video, the endpoint being attacked, the researcher took the result from http://vimeo.com/api/v2/video/123459.php and changed the value of the description attribute from string to array:

a:1:{i:0;a:23:{s:2:"id";i:123456;s:5:"title";s:30:"London Tornado — The aftermath";s:11:"description";a:1:{i:0;i:1337;}s:3:"url";s:24:"https://vimeo.com/123456";s:11:"upload_date";s:19:"2006-12-14 06:53:32";s:15:"thumbnail_small";s:111:"https://i.vimeocdn.com/video/46783763-[redacted]-d_100x75";s:16:"thumbnail_medium";s:112:"https://i.vimeocdn.com/video/46783763-[redacted]-d_200x150";s:15:"thumbnail_large";s:108:"https://i.vimeocdn.com/video/46783763-[redacted]-d_640";s:7:"user_id";i:146861;s:9:"user_name";s:11:"wordtracker";s:8:"user_url";s:29:"https://vimeo.com/wordtracker";s:19:"user_portrait_small";s:51:"https://i.vimeocdn.com/portrait/defaults-blue_30x30";s:20:"user_portrait_medium";s:51:"https://i.vimeocdn.com/portrait/defaults-blue_75x75";s:19:"user_portrait_large";s:53:"https://i.vimeocdn.com/portrait/defaults-blue_100x100";s:18:"user_portrait_huge";s:53:"https://i.vimeocdn.com/portrait/defaults-blue_300x300";s:21:"stats_number_of_likes";i:11;s:21:"stats_number_of_plays";i:122560;s:24:"stats_number_of_comments";i:12;s:8:"duration";i:32;s:5:"width";i:320;s:6:"height";i:240;s:4:"tags";s:0:"";s:13:"embed_privacy";s:8:"anywhere";}}
This is a serialised PHP array. Let's break it down:
a:1:{i:0;...}means an array with 1 element, key 0.- Inside,
a:23:{...}is an array with 23 elements. s:2:"id";i:123456;means a string of length 2 with value "id", then an integer 123456.s:11:"description";a:1:{i:0;i:1337;}means the key "description" has an array with one element (integer 1337) instead of a string. That's the change: originally description was a string, now it's an array.- The rest are other fields like title, url, thumbnails, etc.
During script execution, htmlspecialchars() expected a string but got an array, which caused an Error exception with a partly disclosed template and stack trace:


htmlspecialchars() is a PHP function that converts special characters to HTML entities to prevent XSS. It only works on strings. Passing an array causes an error. The error page revealed parts of the code and the stack trace (the sequence of function calls that led to the error).
Among the included files there was a composer autoload script. Composer is a dependency manager for PHP. Several files stood out as potentially useful for deserialisation:
- Guzzle (
/var/www/sentry/vendor/guzzlehttp/…) - Swift Mailer (
MODPATH/email/vendor/swiftmailer/…) - Symfony (
/var/www/sentry/vendor/symfony/…) - Mustache (
MODPATH/kostache/vendor/mustache/…) - Sentry (
/var/www/sentry/vendor/sentry/…)
PHPGGC has gadget chains for Guzzle, Swift Mailer and Symfony. After building and testing the payloads on api-stage.seedr.ru, a new error appeared. A Guzzle payload returned FnStream should never be unserialized, which indicated an already patched version:

Swift Mailer and Symfony did not work at all, and analysis of the Mustache and Sentry code on GitHub bore no fruit. Third-party libraries would not help; it was time to dive into Kohana.
Step 8: finding a gadget in Kohana
Searching the Kohana repository for magical methods such as __wakeup(), __destruct() and __toString() returned nothing:

But the repository has a system directory which is in fact a dedicated repository, Kohana Core (https://github.com/kohana/core/tree/[redacted]):


Searching that repository gave almost no results for __destruct() and __wakeup(), but results for __toString() were reassuring:

classes/Kohana/View.php and its render() function immediately caught his attention. Having developed a few projects with Laravel, he knew about the MVC pattern and Blade, and guessed that a rendering engine loading templates might let him pass his own file or content. MVC stands for Model-View-Controller, a common way to structure web applications. Blade is Laravel's template engine.
The render() function accepts one argument called $file and then calls capture():
public function render($file = NULL){ if ($file !== NULL) { $this->set_filename($file); } if (empty($this->_file)) { throw new View_Exception('You must set the file to use within your view before rendering'); } // Combine local and global data and capture the output return View::capture($this->_file, $this->_data);}
Line by line:
public function render($file = NULL)defines a function that takes an optional file parameter.if ($file !== NULL)checks if a file was provided.$this->set_filename($file);if so, callsset_filename()to set the file.if (empty($this->_file))checks if the internal_fileproperty is empty.- If empty, it throws an exception saying you must set the file.
return View::capture($this->_file, $this->_data);calls the staticcapture()method with the file and data.
When render() is called without an argument, set_filename() is bypassed. That function also checks the existence of $file in the views directory:
public function set_filename($file){ if (($path = Kohana::find_file('views', $file)) === FALSE) { throw new View_Exception('The requested view :file could not be found', array(':file' => $file,)); } // Store the file path locally $this->_file = $path; return $this;}
Line by line:
public function set_filename($file)defines a function that takes a file name.if (($path = Kohana::find_file('views', $file)) === FALSE)tries to find the file in the 'views' directory. If not found,$pathis FALSE.- If not found, it throws an exception.
$this->_file = $path;stores the found path in the_fileproperty.return $this;returns the object itself.
So capture() is called with the $this->_file variable:
public function render($file = NULL){ ... // Combine local and global data and capture the output return View::capture($this->_file, $this->_data);}
capture() combines local and global data and captures the output, for example to render an email template with a username variable:
protected static function capture($kohana_view_filename, array $kohana_view_data){ // Import the view variables to local namespace extract($kohana_view_data, EXTR_SKIP); if (View::$_global_data) { // Import the global view variables to local namespace extract(View::$_global_data, EXTR_SKIP | EXTR_REFS); } // Capture the view output ob_start(); try { // Load the view within the current scope include $kohana_view_filename; } catch (Exception $e) { // Delete the output buffer ob_end_clean(); // Re-throw the exception throw $e; } // Get the captured output and close the buffer return ob_get_clean();}
Line by line:
protected static function capture($kohana_view_filename, array $kohana_view_data)defines a static function that takes a filename and an array of data.extract($kohana_view_data, EXTR_SKIP);turns the array keys into local variables.EXTR_SKIPmeans skip if a variable already exists.if (View::$_global_data)checks if there is global data.extract(View::$_global_data, EXTR_SKIP | EXTR_REFS);does the same for global data, with references.ob_start();starts output buffering (captures output instead of sending it).try { include $kohana_view_filename; }includes the file. This is the dangerous part.catch (Exception $e) { ob_end_clean(); throw $e; }if an exception occurs, cleans the buffer and re-throws.return ob_get_clean();returns the captured output and ends buffering.
capture() accepts $kohana_view_filename and $kohana_view_data. The interesting part is:
...try{ // Load the view within the current scope include $kohana_view_filename;}...
include() means LFI and RCE potential. LFI stands for local file inclusion, which lets an attacker include files from the server. And $kohana_view_filename is controllable: it is $this->_file, an attribute of the View class.
class Kohana_View { // Array of global variables protected static $_global_data = array(); ... // View filename protected $_file; // Array of local variables protected $_data = array(); ...}
This shows the class definition. $_file is a protected property, meaning it can only be accessed from within the class or subclasses. But in a serialised object, we can set it.
All the elements for successful unsafe deserialisation were now present:
- Controlled input.
- A magical method
__toString()of theViewclass with a usefulinclude(). - The
Viewclass loaded.
Step 9: building the chain
A gadget and chain for PHPGGC were created locally and later committed and added to the main repository (https://github.com/ambionics/phpggc/tree/master/gadgetchains/Kohana/FR/1):
<?phpnamespace GadgetChain\Kohana;class FR1 extends \PHPGGC\GadgetChain\FileRead{ public static $version = '3.*'; public static $vector = '__toString'; public static $author = 'byq'; public static $information = 'include()'; public function generate(array $parameters) { return new \View($parameters['remote_path']); }}<?phpclass View { protected $_file; public function __construct($_file) { $this->_file = $_file; }}
This code defines a PHPGGC gadget chain. It creates a View object with the _file property set to the path we want to include. The __toString() method (not shown here) will be called when the object is treated as a string, and it will call render(), which calls capture(), which includes the file.
Running PHPGGC produced the following serialised object:

Hosting the payload on a controlled server and sending a request gave:

Something new, but not what was hoped for. __wakeup() and __destruct() trigger at object creation and destruction respectively, but __toString() does not. As the PHP docs say:
The __toString() method allows a class to decide how it will react when it is treated like a string. For example, what echo $obj; will print.
So the View object had to be output somehow. The obvious way was to provide it as the value of the title or description attribute, the same trick used earlier with an array to trigger the Error exception. The payload looked like this:
a:1:{i:0;a:23:{s:2:"id";i:123456;s:5:"title";s:30:"London Tornado — The aftermath";s:11:"description";O:4:"View":1:{s:8:"*_file";s:11:"/etc/passwd";}s:3:"url";s:24:"https://vimeo.com/123456";s:11:"upload_date";s:19:"2006-12-14 06:53:32";s:15:"thumbnail_small";s:111:"https://i.vimeocdn.com/video/46783763-[redacted]-d_100x75";s:16:"thumbnail_medium";s:112:"https://i.vimeocdn.com/video/46783763-[redacted]-d_200x150";s:15:"thumbnail_large";s:108:"https://i.vimeocdn.com/video/46783763-[redacted]-d_640";s:7:"user_id";i:146861;s:9:"user_name";s:11:"wordtracker";s:8:"user_url";s:29:"https://vimeo.com/wordtracker";s:19:"user_portrait_small";s:51:"https://i.vimeocdn.com/portrait/defaults-blue_30x30";s:20:"user_portrait_medium";s:51:"https://i.vimeocdn.com/portrait/defaults-blue_75x75";s:19:"user_portrait_large";s:53:"https://i.vimeocdn.com/portrait/defaults-blue_100x100";s:18:"user_portrait_huge";s:53:"https://i.vimeocdn.com/portrait/defaults-blue_300x300";s:21:"stats_number_of_likes";i:11;s:21:"stats_number_of_plays";i:122560;s:24:"stats_number_of_comments";i:12;s:8:"duration";i:32;s:5:"width";i:320;s:6:"height";i:240;s:4:"tags";s:0:"";s:13:"embed_privacy";s:8:"anywhere";}}
Here, the description field is now an object of class View with one property: *_file set to /etc/passwd. The * indicates a protected property. When the server tries to use this object as a string (for example, to output the description), PHP will call the __toString() method, which will include /etc/passwd.
Updating the payload on the controlled server and sending the request finally gave:

The content of /etc/passwd appeared inside the og:description meta tag. Local file read is better than semi-blind SSRF, but still not RCE.
Step 10: hunting for a place to store a payload
With LFI in hand, the next problem was where to store an RCE payload so that include() could reach it. The common techniques:
- File upload (the application had no such functionality).
- Logs (apache, nginx, mail, ssh, …):


/proc/*/fd, …:

- Session file:

Almost everything was tried and nothing worked. So it was time to go back to the "no space left on device" error:

That error revealed a log file path: /application/logs/2021/12/20.php. Opening https://api.seedr.ru/application/logs/2021/12/20.php in the browser returned No direct script access. Almost every PHP file in the Kohana framework has such a string at the beginning:

So log files with the .php extension could not be accessed directly from the browser. On the staging host, http://api-stage.seedr.ru/application/logs/2021/12/20.php returned a 404. Changing the .php extension to .log gave:

A huge log file, big enough to freeze Burp Suite a little. This trick did not work on the production host api.seedr.ru; the researcher can only guess that the Seedr developers changed something on staging to make accessing log files easier, which led to a security issue.
The first Error exception had left a record in the log file. After a short analysis, the log was poisoned with such a record:

With PHPGGC a new serialised View object was created with the _file attribute set to /var/www/t1.seedr.backend/application/logs/2021/12/20.log, hosted on the controlled server, and sent. The result was the following error:

The log file was too huge (more than 200000 lines), some function failed on one of the ? symbols, threw an exception and stopped the execution of the script. From the PHP docs:

Because the December 20 log file was ruined with unsuccessful payloads, further tests on that host were useless, so work moved to the local environment. Hours of debugging and tests with include() and the log file did not lead to the desired result.
Step 11: the base64 idea and the log poisoning plan
During a morning shower the researcher remembered the article by Charlese Fol, Laravel <= v8.4.2 debug mode: Remote code execution (CVE-2021-3129), which uses a technique with multiple base64 decoding that ignores non-base64 characters. He had first read about it in Orange Tsai's blog. The idea was to poison a log with multiple base64 encoded PHP payloads, then decode it with multiple convert.base64-decode filters inside the include() function to bypass the exception caused by the ? symbol. But after a sleepless night he forgot that in the Laravel case the technique abused a file_get_contents() and file_put_contents() chain with the same arguments, which allowed Charlese to rewrite the log. He also forgot about this limitation:

Screenshot from Charlese's article
Because the log file path is predictable (/application/logs/2021/12/20.log), a few log files for previous days were downloaded, and the plan was to poison the December 21 log at the beginning of the day, before it grew too large. All collected information was posted to the H1 report, with a full day left before December 21.
Without wasting time he tried to exploit the finding on production api.seedr.ru, since the last tests had been on api-stage.seedr.ru. A View object with _file set to /etc/passwd was generated with PHPGGC, hosted on the controlled server, and sent, but the content of /etc/passwd did not appear in the response. Repeating the same steps on api-stage.seedr.ru worked fine.
Step 12: null bytes
Here the researcher confesses that when generating the serialised object with PHPGGC he modified it a little:

The *_file string does not have 8 symbols, it has only 6. That is what was modified every time, and it worked flawlessly on api-stage.seedr.ru. Later, in the stack trace, he noticed:

The value of the protected _file attribute is NULL, but for some reason the View object has a public *_file attribute with the payload. To store a protected value in a serialised string, PHP uses null characters (\0) around the * symbol, which is why *_file has 8 symbols:

Because the payload was copy-pasted to webhook.site, the null characters were not stored and unserialize() received a public *_file attribute. The fix was to host the serialised string with null bytes on his own server: vimeo.com redirects requests there, and the server just echo()es the payload with null characters. After observing the content of /etc/passwd on api.seedr.ru, he returned to analysing the downloaded log files.
Step 13: the last poison
The log files had many record types, but only a few could be used to store a payload, and most required authentication. During the first analysis he had noticed the following record type:

This record type stored the payload only once per record and did not repeat it several times like the previous attempt. A possible injection point was noted: the user-agent. The user-agent is a header sent by the browser that identifies the browser and operating system. The problem was not knowing how to generate such a record and which endpoint to access. Grepping the logs for his IP showed that today's log file already had such a record with his IP, meaning the required endpoint had definitely been touched. Burp Proxy history had more than 40000 records by then, so finding the proper endpoint was difficult. Comparing the time of the record with his IP and the activity at that time suggested the record was probably generated during a dirsearch scan. Rerunning it found the endpoint: api-stage.seedr.ru/inc.
On the local environment the new payload was hidden in a test log file, include()d, and the output of the bash command came back. All that was left was to wait for December 21 and a fresh log file, because on December 20 the log files for api.seedr.ru and api-stage.seedr.ru had been poisoned with unsuccessful payloads.
The next day the log was poisoned with the following request:

The payload was generated, hosted on the server, and the request sent:

He had forgotten to change $argv[1] to $_GET[1] after local tests. Waiting one more day was the plan, but he remembered that there was one more attempt available that day on api-stage.seedr.ru:

This is how victory looks
Root cause
The chain rests on several mistakes. The player takes the vid GET parameter and uses it as the last part of a path passed to file_get_contents(), so path traversal and symbols such as ?, # and @ are usable. The response of that request is then passed to unserialize(), which is only safe while the response is under Vimeo's control. An open redirect on vimeo.com, which the researcher describes as a feature rather than a vulnerability, breaks that assumption and lets the attacker serve an arbitrary serialised string.
The gadget is in Kohana Core. Kohana_View::render() called without an argument skips set_filename(), which is the function that checks the file exists in the views directory, and passes the protected _file attribute straight to View::capture(), which include()s it. Because _file is an attribute of a class with __toString(), a serialised View object placed in a field that gets rendered as a string (here the description, later the user-agent in a log record) reaches include() with an attacker-chosen path. That gives local file read, and with a writable file such as a log, code execution.
The staging host made this easier by serving log files with the .log extension, which bypassed the No direct script access guard present in the .php files. The report does not say why staging behaved differently; the researcher can only guess the developers changed something there.
Impact
On api-stage.seedr.ru and api.seedr.ru the researcher achieved local file read (the content of /etc/passwd appeared in the og:description meta tag) and, through log poisoning, RCE. The report title states RCE on several hosts of Mail.Ru Group (VK). Before that, the same chain gave semi-blind SSRF with the ability to perform a port scan, because the response from file_get_contents() goes directly to unserialize() and cannot be read back. The open redirect itself is described as a feature on vimeo.com, not a security issue there. The .log access trick did not work on production api.seedr.ru; the log poisoning path depended on the staging host and on a predictable log path (/application/logs/2021/12/20.log).
Fix
This write-up does not describe the remediation applied by the vendor. What the chain shows should be addressed: do not pass user-controlled input into file_get_contents() in a way that allows escaping the intended host, and do not unserialize() data fetched over the network; use a safe format such as JSON. In Kohana, View::capture() should not include() a path taken from a deserialised attribute without validation against the views directory, and log files should not be reachable with an extension that the web server will serve, nor should they be writable with attacker-controlled content that can later be included.
Variants to test
- Look for player or embed pages that take a video identifier and a hosting provider, and check whether the identifier controls the path of a server-side fetch. A positive result is a request to your own host, or a response that changes when you add
/../,?,#or@. - Check whether the fetched response is deserialised: point the fetch at a host you control that returns a serialised string, and see whether a class-related error appears. A positive result is an autoload or
unserialize()error naming a class. - Enumerate hosting providers accepted by the parameter. A positive result is a provider whose API returns a serialised string when the
.phpextension is used, as Vimeo did here. - Look for open redirects on the provider domain, including documented features rather than bugs. A positive result is a redirect to an arbitrary host that the server-side fetch follows.
- With SSRF, try
https://[redacted],https://[redacted]:22andhttp://[redacted]:25and compare timing or errors to infer open ports. - Fingerprint the framework from error pages and included files. A positive result is a list of loaded classes and vendor paths that map to known gadget chains.
- Search the framework for
__toString(),__wakeup()and__destruct()and forinclude(),require()or file functions reachable from them. A positive result is a class whose magical method reachesinclude()with an attribute you can set in a serialised object. - Find a field that is rendered as a string (title, description, user-agent) and place the serialised object there. A positive result is the content of a file such as
/etc/passwdin the response. - Look for log files reachable with an alternative extension (
.loginstead of.php) and for endpoints that write attacker-controlled values such as the user-agent into them. A positive result is a log record containing your payload at a predictable path. - When hosting serialised payloads, remember that protected properties need null bytes around
*; a service that strips them will deliver a public property instead. A positive result is the protected attribute being set in the stack trace.
Glossary
- API: Application Programming Interface; a way for two programs to communicate.
- Autoloading: PHP's automatic mechanism to load class files when they are first used.
- Base64: A way to encode binary data as text.
- Blind SSRF: Server-side request forgery where the attacker cannot see the response.
- Bug bounty program: A scheme where companies pay for security vulnerability reports.
- Burp Suite: A tool for intercepting and modifying web traffic.
- Composer: A dependency manager for PHP.
- Cross-site scripting (XSS): A vulnerability that lets an attacker inject JavaScript into pages viewed by others.
- Deserialisation: The process of converting a serialised string back into an object.
- dirsearch: A tool for brute-forcing directories on a web server.
- Gadget chain: A sequence of objects and methods that, when triggered, achieve a malicious goal.
- GET parameter: Key-value pairs in a URL after the
?, used to pass data to the server. - HackerOne: A platform for bug bounty programs.
- HTTP: The protocol used by web browsers and servers.
- JSON: A common data format that looks like JavaScript objects.
- Kohana: A PHP framework.
- LFI (Local File Inclusion): A vulnerability that lets an attacker include files from the server.
- Magical methods: Special methods in PHP that are called automatically in certain situations (e.g.
__wakeup,__destruct,__toString). - MVC: Model-View-Controller, a common way to structure web applications.
- Null byte: A character with value zero, often used to terminate strings in C, and in PHP serialisation to denote protected properties.
- Open Graph meta tags: HTML tags that describe a page's content for social media.
- Open redirect: A URL on a site that redirects to any other site.
- Path traversal: Using
../to move up directories and access files outside the intended directory. - Payload: The actual data sent to exploit a vulnerability.
- Port scanning: Checking which network ports are open on a server.
- RCE (Remote Code Execution): A vulnerability that lets an attacker run their own commands on the server.
- Reconnaissance (recon): The information-gathering phase of an attack.
- Serialised string: A string representation of an object, used by PHP's
serialize()andunserialize(). - Semi-blind SSRF: SSRF where the attacker can infer some information but not read the full response.
- SQLi (SQL Injection): A vulnerability that lets an attacker inject SQL commands into a database query.
- SSRF (Server-Side Request Forgery): A vulnerability that lets an attacker make the server send requests to other systems.
- Stack trace: The sequence of function calls that led to an error.
- Subdomain enumeration: Finding all subdomains of a target.
- Use-after-free: A memory corruption bug where a program uses memory after it has been freed.
- User-agent: A header sent by the browser that identifies the browser and operating system.