error based sql injection 참과 거짓을 error로 구분하는 것인데 보통 if문으로 공격하는 기법.


일단 mysql에서의 if문을 보면

if(조건 , 참 , 거짓) 으로 나타냅니다.

이것으로 참일때 또는 거짓일 때 에러를 출력하게 하면 됩니다.

에러는 서브쿼리를 이용하면 됩니다


예시:

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

?>

출처 : lord of sqlinjection


위의 예시를 보면 if문에

mysql에서 (select 1 union select 2)를 넣게 되면 Subquery returns more than 1 row 라는 에러가 뜨게 됩니다.

따라서 url에 " ' or id = 'admin' and (if(length(pw)>숫자,(select 1 union select 2),1)#"를 넣으면

숫자에 해당되는 수에서만 error를 띄우지 않습니다.

물론 select 1 union select 2 와 1 의 자리를 바꾸어 준다면 error가 참일때만 발생할 것입니다.

이렇게 알게된 길이를 범위로 잡고

비밀번호를 계속해서 대입시켜준 다음 화면을 txt로 받아 Subquery가 있을 때의 값으로 비밀번호를 찾을수 있습니다. 




'Hacking' 카테고리의 다른 글

File Inclusion Attacks  (0) 2018.02.01
Oracle Padding Attack[실전편]  (0) 2018.01.31
XSS(Cross Site Scripting)  (0) 2018.01.15
Oracle Padding Attack[이론편]  (2) 2018.01.09

+ Recent posts