SqlServer中批量替换被插入的木马记录
2019/6/30 17:18:22
本文主要是介绍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
原文如下:
复制代码 代码如下:
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
这篇关于SqlServer中批量替换被插入的木马记录的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-01-08Docker下的SqlServer发布订阅启用
- 2023-06-05Docker安装MS SQL Server并使用Navicat远程连接
- 2023-05-25深入浅出 SQL Server CDC 数据同步
- 2023-05-12通过空间占用和执行计划了解SQL Server的行存储索引
- 2023-04-24以SQLserver为例的Dapper详细讲解
- 2022-11-30SQL server高级函数查询
- 2022-11-26SQL SERVER数据库服务器CPU不能全部利用原因分析
- 2022-11-21SQL Server 时间算差值/常用函数
- 2022-11-20调试Archery连接SQL Server提示驱动错误
- 2022-10-22SQL Server 完整、差异备份+完整、差异还原(详细讲解,规避错误)