인젝션 대비 Injection 데이터베이스 조회 구조
출처2 : http://unabated.tistory.com/entry/Web-Hacking-1%ED%83%84-SQL-Injection
1. MSSQL 기준 해당 데이터베이스 조회
-- db 검색
select name
from master..sysdatabases;
-- table 검색
SELECT name FROM sysobjects WHERE xtype = 'U';
-- 해당 db의 table의 column 검색
select c.name, TYPE_NAME(c.xtype) as type, length
from syscolumns as c,sysobjects as t
where c.id = t.id
and t.name = 'dreamcis_pretable' -- list colum names and types for master..sometable
2. 대응 방안
- Request 로 받은 인자는 항상 값의 validate 입증 후 사용(특히 code behind 단에서)
- Request 로 받은 인자 값 중 해당 특수문자에 대해서 Replace 해야 함
str = replace(str, "<", "<")
str = replace(str, ">", ">")
str = replace(str, """, """)
str = replace(str, "|", "|")
str = replace(str, "$", "$")
str = replace(str, "%", "%")
str = replace(str, "'", "'")
str = replace(str, "/", "/")
str = replace(str, "(", "(")
str = replace(str, ")", ")")
str = replace(str, ",", ",")
- Request 인자를 받아 처리하는 ad-hoc 쿼리 사용금지
- Request 인자를 받아 처리하는 쿼리는 Proc 또는 Prepared 쿼리로 변경
- 특히 매니지사이트의 경우 IIS 셋팅에서 회사 IP만 허용으로 하고, 나머진 블록 시킨다.
- IIS 에러 페이지의 내용을 따로 추가하여 만드는 방식으로 IIS 오류 메시지가 외부에 공개되지 않도록 한다.