[Level 21]Lord of SQL injection – iron_golem

Lord of SQL injection – iron_golem

Level 21


Source Code

<?php
  include "../config.php"; 
  login_chk(); 
  dbconnect(); 
  if(preg_match('/prob|_|\.|\(\)/i', $_GET[pw])) exit("No Hack ~_~");
  if(preg_match('/sleep|benchmark/i', $_GET[pw])) exit("HeHe");
  $query = "select id from prob_iron_golem where id='admin' and pw='{$_GET[pw]}'";
  $result = @mysql_fetch_array(mysql_query($query));
  if(mysql_error()) exit(mysql_error());
  echo "<hr>query : <strong>{$query}</strong><hr><br>";
  
  $_GET[pw] = addslashes($_GET[pw]);
  $query = "select pw from prob_iron_golem where id='admin' and pw='{$_GET[pw]}'";
  $result = @mysql_fetch_array(mysql_query($query));
  if(($result['pw']) && ($result['pw'] == $_GET['pw'])) solve("iron_golem");
  highlight_file(__FILE__);
?>

Analyse

http://los.sandbox.cash/iron_golem-~~.php?pw=123 이라고 입력하게 되면
select id from prob_iron_golem where id='admin' pw='123'과 같이 MySQL 쿼리문이 입력된다.
6번째 줄에서 sleep과 benchmark를 필터링 하고 있다. 
다만 10번째 줄을 보면 SQL문장이 오류가 일어날 경우  그 오류를 출력 하는 함수가 존재한다.
이를 이용해 &result['pw']가 입력한 pw와 일치시켜야  iron_golem문제가 풀린다.

Frist Hint is next page

카테고리LOS

글의 문제가 있다면 댓글을 달아 주세요.

이 사이트는 스팸을 줄이는 아키스밋을 사용합니다. 댓글이 어떻게 처리되는지 알아보십시오.