解决并清除SQL被注入恶意病毒代码的语句

declare @t varchar(255),@c varchar(255) declare table_cursor cursor for select a.name,b.name from sysobjects a,syscolumns b ,systypes c where a.id=b.id and a.xtype='u' and c.name in ('char', 'nchar', 'nvarchar', 'varchar','text','ntext') declare @str varchar(500),@str2 varchar(500) set @str=''/*要替换的内容*/ set @str2='' open table_cursor fetch next from table_cursor into @t,@c while(@@fetch_status=0) begin exec('update [' + @t + '] set [' + @c + ']=replace(cast([' + @c + '] as varchar(8000)),'''+@str+''','''+ @str2 +''')') fetch next from table_cursor into @t,@c end close table_cursor deallocate table_cursor;

-- sql 去掉字段html代码 dbo.StripAllTags(ProductDetails) CREATE FUNCTION [ dbo ]. [ StripAllTags ]
(
@input VARCHAR( 8000) -- NVARCHAR(MAX)--2000内改为VARCHAR(8000) )
RETURNS NVARCHAR( MAX)
AS
BEGIN
declare
@Result nvarchar( MAX),
@start int,
@end int,
@len int

set @input = @input + ' <> '
set @Result = ''
set @len = len( @input)
set @start = charindex( ' < ', @input, 1)
set @end = charindex( ' > ', @input, @start)
while( @start < @end)
begin
if( @start <> 1)
set @Result = @Result + substring( @input, 1, @start - 1)
set @len = @len - @end
set @input = substring( @input, @end + 1, @len)
set @start = charindex( ' < ', @input, 1)
set @end = charindex( ' > ', @input, @start)
end

RETURN replace( @Result, '   ', '')

END

[@more@]

declare @t varchar(255),@c varchar(255) declare table_cursor cursor for select a.name,b.name from sysobjects a,syscolumns b ,systypes c where a.id=b.id and a.xtype='u' and c.name in ('char', 'nchar', 'nvarchar', 'varchar','text','ntext') declare @str varchar(500),@str2 varchar(500) set @str=''/*要替换的内容*/ set @str2='' open table_cursor fetch next from table_cursor into @t,@c while(@@fetch_status=0) begin exec('update [' + @t + '] set [' + @c + ']=replace(cast([' + @c + '] as varchar(8000)),'''+@str+''','''+ @str2 +''')') fetch next from table_cursor into @t,@c end close table_cursor deallocate table_cursor;

-- sql 去掉字段html代码 dbo.StripAllTags(ProductDetails) CREATE FUNCTION [ dbo ]. [ StripAllTags ]
(
@input VARCHAR( 8000) -- NVARCHAR(MAX)--2000内改为VARCHAR(8000) )
RETURNS NVARCHAR( MAX)
AS
BEGIN
declare
@Result nvarchar( MAX),
@start int,
@end int,
@len int

set @input = @input + ' <> '
set @Result = ''
set @len = len( @input)
set @start = charindex( ' < ', @input, 1)
set @end = charindex( ' > ', @input, @start)
while( @start < @end)
begin
if( @start <> 1)
set @Result = @Result + substring( @input, 1, @start - 1)
set @len = @len - @end
set @input = substring( @input, @end + 1, @len)
set @start = charindex( ' < ', @input, 1)
set @end = charindex( ' > ', @input, @start)
end

RETURN replace( @Result, '   ', '')

END

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/54654/viewspace-1059361/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/54654/viewspace-1059361/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值