SQL Server数据库被注入,可以通过执行以下任一个方法中的命令来快速恢复 SQL Server数据库被注入,可以通过执行以下任一个方法中的命令来快速恢复

2016-06-11



方法一:

declare @sql nvarchar(4000);
set @sql = '';
select @sql = @sql + 'update ' + o.[name] + ' set ' + c.[name] + '=replace(convert(varchar(8000),' + c.[name] + '),''被注入的代码'', '''');' from syscolumns as c, sysobjects as o where c.[id]=o.[id] and o.[xtype]='U' and c.[xtype] in (35,99,167,231)
exec(@sql);





方法二:


Declare @T Varchar(255),@C Varchar(255)
Declare Table_Cursor Cursor For Select A.Name,B.Name 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)

Open Table_Cursor
Fetch Next From Table_Cursor Into @T,@C

While(@@Fetch_Status=0)
Begin
Exec('update ['+@T+'] Set ['+@C+']=Replace(Convert(Varchar(8000),['+@C+']), ''<script src=http://z%3360.net/c.js></script>'', '''')')
Fetch Next From Table_Cursor Into @T,@C
End

Close Table_Cursor
Deallocate Table_Cursor



个人推荐方法二,也就是用游标的方法,虽然执行速度稍慢,
但不像方法一,@sql变量有长度的限制。