国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 數(shù)據(jù)庫 > SQL Server > 正文

SqlServer中批量替換被插入的木馬記錄

2024-08-31 00:58:13
字體:
供稿:網(wǎng)友
最近找了找 批量替換被插入的木馬記錄,找到了一條好的語句,用處很大,僅僅使用十幾行游標(biāo)語句,把整個數(shù)據(jù)庫的所有表的惡 意木馬清除掉了,而且在Google搜索到此記錄幾率很小,在此專門轉(zhuǎn)載一下!為了以后自己能找得到,也希望后人能得到幫助。
原文如下:

復(fù)制代碼 代碼如下:


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用戶連接數(shù)據(jù)庫
2、新建一個public權(quán)限數(shù)據(jù)庫用戶,并用這個用戶訪問數(shù)據(jù)庫
3、[角色]去掉角色public對sysobjects與syscolumns對象的select訪問權(quán)限
4、[用戶]用戶名稱-> 右鍵-屬性-權(quán)限-在sysobjects與syscolumns上面打“×”
5、通過以下代碼檢測(失敗表示權(quán)限正確,如能顯示出來則表明權(quán)限太高):

復(fù)制代碼 代碼如下:


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

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 北海市| 夹江县| 莎车县| 纳雍县| 米林县| 赣榆县| 章丘市| 永清县| 江陵县| 手机| 平顺县| 霍城县| 曲水县| 寻甸| 聂荣县| 桐乡市| 浪卡子县| 永福县| 柘荣县| 临洮县| 莲花县| 开封县| 通州区| 金乡县| 富川| 广灵县| 辽源市| 阜宁县| 西和县| 长沙县| 鱼台县| 西青区| 龙泉市| 新民市| 芜湖县| 岳普湖县| 邹平县| 紫云| 金溪县| 三原县| 平山县|