Level 25 - Level 26
Last updated
Last updated
This time we got page with four inputs and a link to the source code.
Let's take a look at the source code.
There is class Logger
, which basically logs the message to the defined logFile
.
I checked the entire source code, but there is no object is created with the class Logger, its not used anywhere.
Next, the showImage()
function, simply shows the image file. The drawImage()
function, creates an image witht the data from the drawFromUserdata()
function.
The drawFromUserdata()
function, first checks for the URL parameters x1, x2, y1, y2 and if it exists it generates the image. Next it checks out whether the cookie drawing
exists, and if so, it base64 decodes the cookie drawing
and unserialize
the contents and generate the image using the contents that is decoded. Usage of PHP unserialize
function on a cookie value is vulnerable, since the cookie can be modified by the user, and if the cookie contains php code snippets, it will be executed. To know more check the following resource:
The storeData()
function also utilizes the PHP unserialize
function, to read the cookie if present and set's the cookie.
We can leverage the above mentioned vulnerability to get the password for the next level. But for that we need a valid php serialized object, which reads the password file and display the output. For this purpose, we can make use of the Logger()
function that we saw earlier, since we can generate a valid PHP object as it is a class and it writes the output to a file.
If we are gonna get and store the password in a file, we have to make sure that its publicly accessible. So we have to store the output file in a location that we could access.
From the source code we can see that the image files are located at img
directory, which is publicly accessible. So we can make use of this directory. I copied the Logger()
class and created a php script which will create a object with the Logger()
class, serialize
it and encode it using base64.
The following PHP script will perform the above mentioned action. I have made a few changes to the __construct()
function, adding php code snippets that read the contents of the natas27 file and store it in the file that is located at img/password.php
, which is publicly accessible. From the output of the below script, we will get a valid cookie [ Ignore the errors generated by the script ].
Valid cookie generated by the above script:
I captured the request to the web page using burpsuite and modified the value of the cookie drawing
with the cookie that we generated, which responded with an error, indicating successfull execution of code.
Now, to get the password, check the img/password.php
file, you can see the credential for the next level.