This challenge required us to find a flag in a sql table using a time-based blind sql injection over a POST parameter. This writeup will be a little sparse because the server was taken offline before I could do this writeup, but I’ll provide server-side concept code where I can as well as my hastily written and hacked-together scripts.

Here was the challenge description:

Well, I found this shop and their offers are quite awesome, but something here smells… fishy.

## Finding the Injection

The site was a basic free website template. search.php was the only php script that I saw being called anywhere. Fuzzing the search box didn’t prove fruitful, however the source was something along the lines of <form action="search.php" method="post" class="search"> (Again, I no longer have the page source).

So we can try sending an injection over the POST parameter. Doing this in python:

Running it spat back the page but this time with a lovely MySQL error included.

## Extracting the Database Information

Now that I could inject into the search parameter I tweaked my script for future injections and starting getting to work extracting database information

We can imagine that the server is doing something along the lines of:

In order to make our statement valid we will need to end the previous statement ' and comment out the rest of our line -- . An order-by clause gives the number of colums: ' order by 3-- . I extracted some information about table and column names using FROM ... style statements and their corresponding error output. Trying to get output from any of the columns (' union select 1,2,3-- , MySQL allows implicit numeric conversion) was a dead end because the results of our search aren’t displayed on the page. This throws a wrench into the equation by making us work blind.

Even if we can’t see the output of our statement, we can use if-style commands coupled with a heavy operation to get information from the database. This is called a time-based sql injection.

Testing this out:

made the database hang a short while so the first character of our flag should be h. This makes sense with our flag format hxp{…}. All that’s left is to automate this and extract our flag.

## Extracting the Flag

Running this slowly extracts our flag character by character: