SQL Server批量替换全部表中内容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 /*“u”为你要操作的数据类型。不改为所有数据类型,不想麻烦就不用改动了*/
in ('char', 'nchar', 'nvarchar', 'varchar','text','ntext' /* --这里假设你的text(ntext)类型没有超过8000(4000)长度,才干够使用*/)
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 Server的查询分析器运行上面的代码。不须要在查看哪个表,哪个字断被注入了,能够非常快删除被注入的字段,非常好用!



posted @ 2015-12-30 13:38  hrhguanli  阅读(1295)  评论(0编辑  收藏  举报