View My Albums
Category: Web
Description
My RateYourMusic competitor will take off any day now. I just need to add rating... and CSS... and images... and a bunch of other things
Attachments: view-my-albums-dist.zip
Write-up
- Upon accessing the provided URL, we encountered a straightforward web application that allows users to view album details.
- Our attention was drawn to the
prefs
cookie, which contained serialized user preferences. - Upon analyzing the codebase, our initial approach involved attempting to exploit a Local File Inclusion (LFI) vulnerability. The line
<h1><?php include("greetings/$prefs->language"); ?></h1>
inindex.php
piqued our interest. - This could be achieved by manipulating the
language
attribute within the serialized userprefs
. - However, our attempts were thwarted by the following check right after
prefs
deserialization: - This check could be bypassed using type juggling, but we were only able to fix the language value as
true
, not an arbitrary value. - After investing a considerable amount of time in exploring this potential vulnerability, we decided to explore other attack vectors.
- In the
Albums.php
file, we discovered that theAlbums
class implemented the__debugInfo()
magic method. This meant that when we usedvar_dump()
on anAlbums
object, we could access all the records in itsstore
. - Within the codebase, three types of stores were implemented:
MysqlRecordStore
,JsonRecordStore
, andCsvRecordStore
. TheMysqlRecordStore
can retrieve all records from the specified database, while theJsonRecordStore
andCsvRecordStore
can retrieve records from the specified file. - Therefore, we crafted a serialized cookie that contained an instance of the
Albums
class initialized with aCsvRecordStore
that read the contents ofdb_creds.php
. - Since
prefs
was an instance ofAlbums
and notUserPrefs
, the following code block would execute when accessingindex.php
: - This logic would result in a
var_dump()
of our maliciousAlbums(CsvRecordStore)
object, leaking the contents ofdb_creds.php
.
- With the leaked
db_creds.php
, we could then provide a maliciousAlbum(MysqlRecordStore)
object, whereMysqlRecordStore
was initialized with the leaked database credentials and theflag
table. - The subsequent
var_dump()
would reveal the entire contents of theflag
table, exposing the flag.
- The PHP script to generate both payloads can be found here.
Flag: grey{l4_mu5iCA_DE_haIry_FroG}