API
Logic error in user authentication
Description
Easy and simple API
https://api.chal.acsc.asia
Solution
Sample API request:
id=test&pw=test&c=iThe c parameter is used to decide the first command - signin, signup or signout.
function main($acc){
gen_user_db($acc);
gen_pass_db();
header("Content-Type: application/json");
$user = new User($acc);
$cmd = $_REQUEST['c'];
usleep(500000);
switch($cmd){
case 'i':
if (!$user->signin())
echo "Wrong Username or Password.\n\n";
break;
case 'u':
if ($user->signup())
echo "Register Success!\n\n";
else
echo "Failed to join\n\n";
break;
case 'o':
if ($user->signout())
echo "Logout Success!\n\n";
else
echo "Failed to sign out..\n\n";
break;
}
challenge($user);
}The user is checked for is_admin(), then the c2 parameter is used to decide a second admin command. If is_admin() is false, then redirect() is called.
However, redirect() does not actually terminate the PHP script. It simply prints some HTML output. The code execution continues, and the c2 parameter is always processed.
Now, we need the passcode in order to perform the admin functions. We can access /lib/db/user.db and /lib/db/passcode.db directly from the server.
The admin account is
The passcode is
The export_db function gets the contents of a file.
$file is user-controlled, so we can simply do a path traversal to get the flag:

The flag is ACSC{it_is_hard_to_name_a_flag...isn't_it?}.
Last updated
Was this helpful?