Phabricator Phame Blog Skins Local File Inclusion
Phabricator's Phame blog skin setting accepted a path traversal value, so the application loaded skin template files from outside its own directory. An attacker who could already write files to a known server path could point the skin at those files and get code execution inside Phabricator.
- Fixed in 3 hours
- Paid in 3 hours
- Disclosed after 30 days
Phabricator's Phame blog allows users to set a skin.
An attacker with the ability to upload files to the server can exploit this LFI vulnerability to gain remote code execution through Phabricator and thus, gain access to Phabricator's data. Common scenarios may include:
- A box serving Phabricator and other web application that would allow uploading files to controlled paths.
- A box where the attacker can log in through ssh as a restricted user (not having access to Phabricator's files, but having access to write in /tmp, for instance)
- etc ...
While testing, I used the following request to create a blog:
POST /phame/blog/new/ HTTP/1.1
Host: phabricator
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:33.0) Gecko/20100101 Firefox/33.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-GB,en;q=0.5
Accept-Encoding: gzip, deflate
Referer: http://phabricator.48bits.com/phame/blog/new/
Cookie: phsid=o36kfovszv6sqpbjheacicu2ykx25lqoh5iepeit; phusr=guest
Connection: keep-alive
Content-Type: application/x-www-form-urlencoded
Content-Length: 254
__csrf__=B%40acbxwmgk39152b45fd9eff2e&__form__=1&name=xxxx&description=bla&can_view=users&can_edit=users&can_join=users&custom_domain=&skin=%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2f%74%6d%70%2f%74%65%73%74
That makes phabricator try to load the skin template php files from:
/var/www/phabricator/phabricator/externals/skins/../../../../../../../../../../tmp/test/
In order to exploit the vulnerability a valid skin structure must exist at the specified location, I have simply copied the oblivious skin and modified it to output a phpinfo() within the header.php script with the expected results.
Proposed fix:
Phabricator should verify that the skin's path is not outside its own root.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The skin parameter was used to build a filesystem path without checking that the resolved path stayed inside the skins directory.
Impact
An attacker who can already write files to a known path could achieve remote code execution and reach Phabricator's data; the report notes this depends on such a file-write scenario existing.
What the attacker needed
Ability to write files to a known server path
How it was found
- Send a request to create a new Phame blog.
- Set the skin field to a traversal path pointing at a directory the attacker controls.
- Place a valid skin structure, including a modified header template, at that location.
- Phabricator loads the skin template files from the attacker-specified location, running embedded code.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
A blog skin is a set of template files the site loads to decide how the blog looks. The skin name was used directly as a folder path, so typing a path with '..' segments made the server read files from somewhere else on the disk. If an attacker can place their own file there, the server runs it as code.
What is Path traversal?
Input that builds a file path escapes the intended folder, reading or writing files the application should never touch.