A researcher, Daniel Le Gall, has uncovered a serious vulnerability in one of Facebook’s servers. The researcher found a Sentry service hosted on 18.104.22.168 with the hostname sentryagreements.thefacebook.com, while scanning an IP range that belongs to Facebook -22.214.171.124/24.
Remote Code Execution on a Facebook Server: Technical Details
What is Sentry? It is a log collection web application which is written in Python with the Django framework.
The researcher also explained that, while he was looking at the Sentry app, some stracktraces regularly popped on the page for no particular reason.
The application seemed to be unstable regarding the user password reset feature, which occasionally crashed, he added, noting that Django debug mode was not turned off, which consequently prints the whole environment when a stacktrace occurs.
However, Django snips critical information (passwords, secrets, key…) in those stacktraces, therefore avoiding a massive information leakage.
The researcher decided to look closer, and realized he could spot session cookie names, various options, as well as serializer known as Pickle. Simply put, Pickle is a binary protocol for (un)serializing Python object structures, such as classes and methods in them.
If we were able to forge our own session that contains arbitrary pickle content, we could execute commands on the system,” Daniel noted.
Nonetheless, the SECRET_KEY used by Django for signing session cookies is not available in the stacktrace. Furthermore, the SENTRY_OPTIONS list contains a key named system.secret-key, that is not snipped. According to the Sentry documentation, system.secret-key is “a secret key used for session signing. If this becomes compromised it’s important to regenerate it as otherwise its much easier to hijack user sessions.“
As the researcher pointed out, it looks like that the situation is “a sort of Django SECRET-KEY override”.
Using all of this information, Daniel was able to create a script which forges malicious cookies using arbitrary Pickle content. The latter contained a payload to override the Sentry cookie. This cookie was later overridden with an arbitrary object. To test this vulnerability, the researcher implemented a 30-second time delay avoiding the cause of any real damage. His attempt was successful.
An attacker could have exploited the security vulnerability to remotely hijack the system to steal data from the Facebook server or perform other malicious activities. It should be emphasized though, that no user data was located in the server, nether was it exposed due to this flaw.
Daniel reported his discovery to Facebook on July 30, 2018, with the company quickly acknowledging the bug by taking down the server. A patch was issued on August 9, and the researcher was awarded $5,000 for reporting the flaw.
Last year, a security researcher, Andrew Leonov, was awarded $40,000 on behalf of Facebook for breaching the social network and fixing a remote code execution vulnerability which was already discovered and fixed in 2016. Apparently, the vulnerability needed to be addressed once again. The flaw was still impacting the website.