SQL Injection - DB 에 일괄적으로 내용 삭제하기 및 예방 > MSSQL Tip

본문 바로가기
 

SQL Injection - DB 에 일괄적으로 내용 삭제하기 및 예방

작성일 09-01-17 16:09

페이지 정보

작성자 no_profile 휴먼 쪽지보내기 메일보내기 홈페이지 자기소개 아이디로 검색 전체게시물 조회 16,611회 댓글 0건

본문




DB 의 내용에 일부 필드에 무차별적으로
<script src=http://s.shunxing.com.cn/s.js></script>  가 추가된것을 발견


일괄적으로 삭제 하는 방법 및 예방
출처 : http://www.phpschool.com/gnuboard4/bbs/board.php?bo_table=tipntech&wr_id=62284

-- 6번째줄의 일괄 삭제하고픈 문구 입력후 이 프로시저를 실행해서 생성
CREATE PROCEDURE  [MP_DELSTR]
AS

DECLARE @TP  int;
DECLARE @TBL varchar(255), @CLN varchar(255),  @DEL_STR varchar(255);
SET @DEL_STR='<script src=http://s.shunxing.com.cn/s.js></script>

DECLARE Table_Cursor CURSOR FOR
SELECT a.name, b.name ,b.xtype
FROM sysobjects a, syscolumns b
WHERE a.id = b.id AND a.xtype = 'u' AND
(b.xtype = 99 OR b.xtype = 35 OR b.xtype = 231 OR b.xtype = 167  OR b.xtype=175  OR b.xtype=239 );

OPEN Table_Cursor;

FETCH NEXT FROM Table_Cursor INTO @TBL, @CLN, @TP;
WHILE (@@FETCH_STATUS = 0) BEGIN
    IF  @TP  > 100
    BEGIN
          EXEC('UPDATE ['+ @TBL +'] set [' + @CLN + '] = REPLACE('+ @CLN+' , '''+@DEL_STR +''','''' )');
    END
    ELSE
    BEGIN
                    EXEC('UPDATE ['+ @TBL +'] set [' + @CLN + '] = REPLACE(CONVERT(varchar(8000),'+ @CLN+') , '''+@DEL_STR +''','''' )');
    END
FETCH NEXT FROM Table_Cursor INTO @TBL, @CLN,@TP;
END;

CLOSE Table_Cursor;
DEALLOCATE Table_Cursor;
GO



-- 해당 관련 DB 에 들어가서 아래의 프로시저 실행
EXEC MP_DELSTR 





예방방법

DB 에 Insert 할때 스크립트나 악성 관련 문구를 없애거나 무마하도록 설정

출처 : http://zeshai.tistory.com/entry/SQL-injection-bjs

DBConn.asp (DB 연결 부분 파일) 에 아래의 내용 입력

<%
' Code for preventing SQL Injection
' Injection Keyword
array_split_item = Array("-", ";", "/*", "*/", "@@", "@", "char", "nchar", "varchar", "nvarchar", "alter", "begin", "cast", "create", "cursor", "declare", "delete", "drop", "end", "exec","execute", "fetch", "insert", "kill", "open","select", "sys", "sysobjects", "syscolumns","table", "update", "<script", "</script>", "'")
for each item in Request.QueryString

for array_counter = lbound(array_split_item) to ubound(array_split_item)

item_position1 = InStr(lcase(Request(item)), array_split_item(array_counter))

'Response.Write(array_split_item(array_counter) & "<BR>")

if item_position1 > 0 then
Response.Write("Command cannot be executed.")
Response.End()
end if

next
next
%>





WebKnight 로 완벽하게 막는 방법 : http://cdmanii.tistory.com/entry/IIS-MSSQL-sql-injection-attack

댓글목록

등록된 댓글이 없습니다.

전체 12건 1 페이지
게시물 검색