SqlServer中批量替換被插入的木馬記錄
更新時間:2011年08月09日 19:50:22 作者:
最近公司做的一個事業(yè)性質(zhì)網(wǎng)站被黑客攻擊了,通過sql注入方式,把木馬注入了數(shù)據(jù)庫,整個MSSQL SERVER 的數(shù)據(jù)都被附加上惡意腳本了
最近找了找 批量替換被插入的木馬記錄,找到了一條好的語句,用處很大,僅僅使用十幾行游標(biāo)語句,把整個數(shù)據(jù)庫的所有表的惡 意木馬清除掉了,而且在Google搜索到此記錄幾率很小,在此專門轉(zhuǎn)載一下!為了以后自己能找得到,也希望后人能得到幫助。
原文如下:
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)限太高):
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ù)制代碼 代碼如下:
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
相關(guān)文章
SQLServer實現(xiàn)Ungroup操作的示例代碼
本文主要介紹了SQLServer實現(xiàn)Ungroup操作的示例代碼,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2023-07-07SQL SERVER數(shù)據(jù)庫表記錄只保留N天圖文教程
本篇向大家介紹SQL Server 2008 R2數(shù)據(jù)庫中數(shù)據(jù)表保留10天記錄,需要的朋友可以參考下2015-09-09SQL Server 開窗函數(shù) Over()代替游標(biāo)的使用詳解
這篇文章主要介紹了SQL Server 開窗函數(shù) Over()代替游標(biāo)的使用,本文給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-10-10Sql Server 如何去掉內(nèi)容里面的Html標(biāo)簽
這篇文章主要介紹了Sql Server 去掉內(nèi)容里邊的Html標(biāo)簽的實現(xiàn)方法,代碼超簡單,具有一定的參考借鑒價值,需要的朋友可以參考下2018-05-05