SqlServer中批量替换被插入的木马记录

最近找了找 批量替换被插入的木马记录,找到了一条好的语句,用处很大,仅仅使用十几行游标语句,把整个数据库的所有表的恶 意木马清除掉了,而且在google搜索到此记录几率很小,在此专门转载一下!为了以后自己能找得到,也希望后人能得到帮助。

原文如下:


复制代码 代码如下:

declare @t varchar(555),@c varchar(555) ,@inscript varchar(8000)

set @inscript=’恶意代码’

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(cast([‘+@c+’] as varchar(8000)),”’+@inscript+”’,””)’ )

fetch next from table_cursor into @t,@c

end

close table_cursor

deallocate table_cursor;

彻底杜绝sql注入

1.不要使用sa用户连接数据库

2、新建一个public权限数据库用户,并用这个用户访问数据库

3、[角色]去掉角色public对sysobjects与syscolumns对象的select访问权限

4、[用户]用户名称-> 右键-属性-权限-在sysobjects与syscolumns上面打“×”

5、通过以下代码检测(失败表示权限正确,如能显示出来则表明权限太高):


复制代码 代码如下:

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 print @c

fetch next from table_cursor into @t,@c

end

close table_cursor

deallocate table_cursor

(0)
上一篇 2022年3月21日
下一篇 2022年3月21日

相关推荐