如何批量查找替换所有字段内容

bjhuzi 2009-04-13 12:27:32
现在数据库每个表都被插入了恶意代码
由于表和字段都比较多
通过update 表名 set 字段名=replace(convert(varchar(8000),字段名),'要替换的','替换为的') 效率太低
哪位高手告知一下
怎样能够批量查找替换 谢谢了!
...全文
198 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
htl258_Tony 2009-04-13
  • 打赏
  • 举报
回复
数据库被注入攻击  所有文本型字下段数据都被加了    <script_src=http://ucmal.com/0.js> </script> 
怎么删掉?



--sql 2000解决方法
DECLARE @fieldtype sysname
SET @fieldtype='varchar'

--删除处理
DECLARE hCForEach CURSOR GLOBAL
FOR
SELECT N'update '+QUOTENAME(o.name)+N' set '+ QUOTENAME(c.name) + N' = replace(' + QUOTENAME(c.name) + ',''<script_src=http://ucmal.com/0.js> </script>'','''')'
FROM sysobjects o,syscolumns c,systypes t
WHERE o.id=c.id
AND OBJECTPROPERTY(o.id,N'IsUserTable')=1
AND c.xusertype=t.xusertype
AND t.name=@fieldtype
EXEC sp_MSforeach_Worker @command1=N'?'






--sql 2005 解决方法
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)
declare @str varchar(500)
--这里是你要替换的字符
set @str='<script_src=http://ucmal.com/0.js> </script>'
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+''','''')')
fetch next from table_cursor into @t,@c
end
close table_cursor deallocate table_cursor;



SQL注入专题
http://topic.csdn.net/u/20081205/09/3dd06076-bcbe-45d4-998c-8999fdbe6fae.html
claro 2009-04-13
  • 打赏
  • 举报
回复
处理前切记数据库备份。
jinjazz 2009-04-13
  • 打赏
  • 举报
回复
参考
http://blog.csdn.net/jinjazz/archive/2008/12/05/3454824.aspx
claro 2009-04-13
  • 打赏
  • 举报
回复
--批量处理网站数据库被注入恶意代码
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)
declare @str varchar(500)
--这里是你要替换的字符
set @str='<script src=http://3b3.org/c.js></script><script src=http://3b3.org/c.js></script>'
open table_cursor fetch next from table_cursor
into @t,@c while(@@fetch_status=0)
begin
exec('update cmspa.[' + @t + '] set [' + @c + ']=replace(cast([' + @c + '] as varchar(8000)),'''+@str+''','''')')
fetch next from table_cursor into @t,@c
end
close table_cursor deallocate table_cursor;
百年树人 2009-04-13
  • 打赏
  • 举报
回复
有很多关于注入的帖子可以参考一下

http://topic.csdn.net/u/20081205/09/3dd06076-bcbe-45d4-998c-8999fdbe6fae.html

http://topic.csdn.net/u/20090326/11/5e584897-2dd7-4e10-af1b-9b48b146af8e.html

jinjazz 2009-04-13
  • 打赏
  • 举报
回复
通过系统表批量生成语句,来执行,参考
http://topic.csdn.net/u/20090326/11/5e584897-2dd7-4e10-af1b-9b48b146af8e.html
  • 打赏
  • 举报
回复
没办法。这基本上时最简单的语句了
Zoezs 2009-04-13
  • 打赏
  • 举报
回复
只能这样。
ks_reny 2009-04-13
  • 打赏
  • 举报
回复
在論壇里找關於SQL注入的帖子看看.
百年树人 2009-04-13
  • 打赏
  • 举报
回复
貌似只能这样了
bjhuzi 2009-04-13
  • 打赏
  • 举报
回复
--sql 2005 解决方法
declare @t varchar(255),@c varchar(255)

消息 208,级别 16,状态 1,第 1 行 执行报错啊。。
conan304 2009-04-13
  • 打赏
  • 举报
回复
8000也太大了,影响效率啊

22,211

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧