来源:自学PHP网 时间:2015-04-17 11:59 作者: 阅读:次
[导读] 朋友服务器sql server 被注入。找到我帮忙,把用到脚本记录在下查找全表进行替换注:数据库为sql 2000---查找所有表并替换某值declare @t varchar(255),@c varchar(255)declare table_cursor cursor fo......
朋友服务器sql server 被注入。找到我帮忙,把用到脚本记录在下
查找全表进行替换
注:数据库为sql 2000
---查找所有表并替换某值
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='<style>.ava8{position:absolute;clip:rect(396px,auto,auto,396px);}</style><div class=ava8><a href=http://3mincashadvance.com >installment loans</a></div>'/*要替换的内容*/
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;
---------------------------------------------------------------------------------------------------------------------
上面那脚本有些记录会报错,没有清理干净 。现分两步解决此问题
1 查找到恶意代码所在的表和字段
2 用语句replace
先来查找某值在某表某字段的代码
-----查找某一值
declare @str varchar(100)
set @str='ava8'
www.2cto.com
declare @s varchar(8000)
declare tb cursor local for
select s='if exists(select 1 from ['+b.name+'] where ['+a.name+'] like ''%'+@str+'%'')
print ''所在的表及字段: ['+b.name+'].['+a.name+']'''
from syscolumns a join sysobjects b on a.id=b.id
where b.xtype='U' and a.status>=0
and a.xusertype in(175,239,231,167)
open tb
fetch next from tb into @s
while @@fetch_status=0
begin
exec(@s)
fetch next from tb into @s
end
close tb
deallocate tb
下面是清除找到所在表和字段后手动替换的脚本
declare @t varchar(5000) --表名
declare @c varchar(5000) ---字段名
declare @str varchar(5000) --恶意代码
declare @str2 varchar(5000) -- 替换后的值,这里通常是替换为''
set @t='收藏'
set @c='标题图片'
--set @str='<style>.ava8{position:absolute;clip:rect(396px,auto,auto,396px);}</style>'
set @str='<style>.ava8{position:absolute;clip:rect(396px,auto,auto,396px);}</style><div class=ava8><a '
set @str2=''
exec('update [' + @t + '] set [' + @c + ']=replace(cast([' + @c + '] as varchar(8000)),'''+@str+''','''+ @str2 +''')')
|
自学PHP网专注网站建设学习,PHP程序学习,平面设计学习,以及操作系统学习
京ICP备14009008号-1@版权所有www.zixuephp.com
网站声明:本站所有视频,教程都由网友上传,站长收集和分享给大家学习使用,如由牵扯版权问题请联系站长邮箱904561283@qq.com