Vampire

Bypass "str_replace"

Code

<?php 
  include "./config.php"; 
  login_chk(); 
  $db = dbconnect(); 
  if(preg_match('/\'/i', $_GET[id])) exit("No Hack ~_~");
  $_GET[id] = strtolower($_GET[id]);
  $_GET[id] = str_replace("admin","",$_GET[id]); 
  $query = "select id from prob_vampire where id='{$_GET[id]}'"; 
  echo "<hr>query : <strong>{$query}</strong><hr><br>"; 
  $result = @mysqli_fetch_array(mysqli_query($db,$query)); 
  if($result['id'] == 'admin') solve("vampire"); 
  highlight_file(__FILE__); 
?>

Line 6: Uses strtolower to convert to lower-case

Line 7: Uses str_replace to replace the string "admin" with an empty value.

Line 8: Query is set to obtain user-supplied input and assign it to the "id" parameter.

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

Query

SELECT id FROM prob_vampire WHERE id=''

Testing

Vulnerable parameter is "id".

str_replace as it's used on line 6 strips the string "admin" from whatever value is supplied to $_GET[id].

If the supplied value were "administrator" the resulting value after str_replace would be "istrator".

By supplying a value of "admiadminn" the result will become "admin" and solve the challenge.

Effective Query

SELECT id FROM prob_vampire WHERE id='admin'

Last updated