Problem :lock:

We arrive at a webpage that asks for a query again

Solution :key:

Let’s take a look at the source code.

Full PHP Code Snippet
<?

$encodedSecret = "3d3d516343746d4d6d6c315669563362";

function encodeSecret($secret) {
    return bin2hex(strrev(base64_encode($secret)));
}

if(array_key_exists("submit", $_POST)) {
    if(encodeSecret($_POST['secret']) == $encodedSecret) {
    print "Access granted. The password for natas9 is <censored>";
    } else {
    print "Wrong secret";
    }
}
?>

We can conclude that we need to input something that will then go through the encodeSecret() function and then match the string value of $encodedSecret.

So let’s try to find the “counter” to each of the functions called in the encodeSecret() function:

We also need to reverse the flow of these functions, let’s say we have a string, if we pass it into encodeSecret() it will:

  1. get encoded into base64,
  2. reversed, then
  3. converted into it’s hexadecimal representation.

Now it’s supposed to be some wierd string, if we want to change it back into our original string, we need to:

  1. convert it from it’s hexadecimal representation back into what it actually is,
  2. reverse it back, then
  3. decode it from base64.

Let’s try it out.

Full Terminal output
$ php --interactive
Interactive mode enabled

php > $encodedSecret = "3d3d516343746d4d6d6c315669563362";
php > echo base64_decode(strrev(hex2bin($encodedSecret)));
oubWYf2kBq
php > 

Now we just need to submit the string that we got from our “reverse” function.

Flag :checkered_flag:

W0mMhUcRRnG8dcghE4qvk3JA9lGt8nDl

Takeaway :books: