Spring GoN Open Qual CTF 2022 Write Up
Summary⌗
This time I did participate in CTF because GoN team of Kaist hosted the CTF. I was hacking to dawn after long time and I solved two challenges:ColorfulMemo, NSS.
I gave up that i felt it’s so hard challenge while analysing this challenge called Trino: Albireo.
(Q) - NSS [897 pts]⌗
This is a challenge that leak a local file using Prototype Pollution. Personally, this challenge of Prototype Pollution is best I solved latest.
they provided the code of challenge, but it was a little than thought.
In docker file, there is no important setting but I could know the location of flag is /usr/src/app/flag
.
main.js call a total of three Apis:user.js, workspace.js, file.js.
user.js has a function to creating and deleting users and login. If it created user, it put user information into user object. And If login successful, it put user token into tokes object after creating the token using user id. In this point, important point is when it is creating user, it make os.tmpdir()+appPrefix
as base_dir
. So, default path of user is /tmp*
workspace.js too is similar with user.js: making, deleting workspace of user. here is no vulnerability too.
file.js
is important that solve this challenge. file.js
has a function to print the workspace of user and creat, delete a file and read the file it created. But when we see the function of reading the file, it take the value of f_name
from workspace
object and use it as the path of file. So If we modify the value of f_name
to flag path, we can read a flag.
the value of f_path
was defined in logic of creating a file. it put the path value into f_name value of workspace
. But in the if statement, if workspace of user is not defined, error occurs but we can create it that we request to /api/users/:userid
as POST. And even if we created, base_dir
is /tmp/*
and the value f_path
remove .
chars using replace() method so we can’t go to up. So we can’t escape from base_dir using this function.
But Prototype Pollution
occur when we make or read or delete a file. So I used it. it call several if statement after getting the value of several parameter. Here, important thing is way for calling object of users.
Call all object of users as above. But here, we can use prototype pollution because be not checking the value ws_name
If the value of ws_name
is __proto__
, in second part workspace will be prototype object because the result value is prototype object. then we can pollute internal property to f_path
using the f_name
.
So, Prototype Pollution
occur as above.
After creating a user, if we request as above, we can pollute the value what we want to base_dir
.
From now, we have to make the value of f_path to flag. But this f_path is in the object of workspace and also object workspace is in the object workspaces. Eventually we have to make the object of new user after we make the new token and object of workspace temporarily. So I got the flag after I pollutued the pass, owner, expire, base_dir, flag, workspace.
I wrote the exploit code as above.
(V) - ColorfulMemo [490 pts]⌗
This is a challenge that triggers RCE via LFI vulnerability after uploading using SQL Injection.
In the docker file, I could know that challenge use MySQL and Apache and location of flag is /flag_$(md5sum /flag | awk ‘{print $1}’).
Above code is back-end code. There is three vulnerabilities called CSS Injection to SSRF, SQL Injection to File upload, LFI to RCE.
CSS Injection occurred in read.php. this is important point.
LFI occurred because it don’t check $path parameter in index.php.
SQL Injection occurred because it don’t check $id parameter in check.php. But SQL Injection is occuring only locally.
it calls bot.py in submit.php. we can’t exploit because it don’t check $id parameter using ctype_digit() function. But we can exploit as SSRF using background: url() of CSS. So I just decided to insert an SSRF PoC as color value using post writing function.
I inserted an SSRF PoC as above. After this processing, When I go to connect, I could see that it request to check.php well. If we report this post, we can see that it sleep for 5 seconds. (delete photo)
Now we have to upload the webshell. So I tried to upload the webshell to /var/www/html/cmd.php but it failed. So I read a code that for finding a reason. The reason is that the value of secure-file-priv is /tmp.
So, as above, I inserted the SQL Injection payload that upload the webshell in the /tmp/cmd1.php path and uploaded the webshell through the report function.
I wrote the exploit code as above