UNION SQL Injection
: 2개 이상의 쿼리를 요청해 결과를 얻는 SQL연산자, 공격자는 이를 악용해 원래의 요청에 한 개의 추가 쿼리를 삽입해 정보를 얻어내는 방식
- 실제 사이트의 경우 null방법을 이용해 필드의 개수 확인
select문 union select null; //오류 -> 앞쪽 select문 필드 1개 아님
select문 union select null, null; //오류 -> 필드 2개 아님
:
select문 union select null, null, null, null, null, null; //실행 -> 필드 6개이다.
==================================================
*Union을 이용한 SQL Injection (MySQL)
1. 주석 : #
2. user() : db사용자를 반환하는 함수 (ex : sa)
3. database() : db명을 반환하는 함수
4. group_concat(expression) : null이 아닌 값들을 연결하여 결과문자열을 varchar타입으로 반환, 각 값들을 쉼표로 구분
idx | bid | bname
select idx, bid, bname, group_concat(idx, bid, bname) from 테이블명
select group_concat(idx, bid, bname) from 테이블명
5. information_schema : 정보데이터베이스 mysql에서
운영하는 모든 데이터베이스 정보가 들어있는 뷰
information_schema.tables : 테이블 정보가 들어있는 테이블
information_schema.columns : 컬럼에 대한 정보가 들어있는 테이블
※exec sp_tables, exec sp_columns (저장프로시저 사용), 결과는 같지만 select문에서는 사용 불가능
table_schema : db명
table_name : 테이블명
ex) A라는 DB에 저장된 테이블 명을 모두 알고 싶다면.
Select table_name from information_schema.tables
where table_schema =’A’#
column_name : 컬럼명
ex) userinfo 테이블에 저장된 컬럼명을 모두 알고 싶다명
select column_name from information_schema.columns where
table_name =’userinfo’