SqlServer中批量替換被插入的木馬記錄
更新時(shí)間:2011年08月09日 19:50:22 作者:
最近公司做的一個(gè)事業(yè)性質(zhì)網(wǎng)站被黑客攻擊了,通過(guò)sql注入方式,把木馬注入了數(shù)據(jù)庫(kù),整個(gè)MSSQL SERVER 的數(shù)據(jù)都被附加上惡意腳本了
最近找了找 批量替換被插入的木馬記錄,找到了一條好的語(yǔ)句,用處很大,僅僅使用十幾行游標(biāo)語(yǔ)句,把整個(gè)數(shù)據(jù)庫(kù)的所有表的惡 意木馬清除掉了,而且在Google搜索到此記錄幾率很小,在此專門(mén)轉(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ù)庫(kù)
2、新建一個(gè)public權(quán)限數(shù)據(jù)庫(kù)用戶,并用這個(gè)用戶訪問(wèn)數(shù)據(jù)庫(kù)
3、[角色]去掉角色public對(duì)sysobjects與syscolumns對(duì)象的select訪問(wèn)權(quán)限
4、[用戶]用戶名稱-> 右鍵-屬性-權(quán)限-在sysobjects與syscolumns上面打“×”
5、通過(guò)以下代碼檢測(cè)(失敗表示權(quán)限正確,如能顯示出來(lái)則表明權(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ù)庫(kù)
2、新建一個(gè)public權(quán)限數(shù)據(jù)庫(kù)用戶,并用這個(gè)用戶訪問(wèn)數(shù)據(jù)庫(kù)
3、[角色]去掉角色public對(duì)sysobjects與syscolumns對(duì)象的select訪問(wèn)權(quán)限
4、[用戶]用戶名稱-> 右鍵-屬性-權(quán)限-在sysobjects與syscolumns上面打“×”
5、通過(guò)以下代碼檢測(cè)(失敗表示權(quán)限正確,如能顯示出來(lái)則表明權(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)文章
清除SQL?Server數(shù)據(jù)庫(kù)日志(ldf文件)的方法匯總
隨著系統(tǒng)運(yùn)行時(shí)間的推移,數(shù)據(jù)庫(kù)日志文件會(huì)變得越來(lái)越大,這時(shí)我們需要對(duì)日志文件進(jìn)行備份或清理,這篇文章主要介紹了清除SQL?Server數(shù)據(jù)庫(kù)日志(ldf文件)的幾種方法,需要的朋友可以參考下2022-10-10
SQL Server 總結(jié)復(fù)習(xí)(一)
寫(xiě)這篇文章,主要是總結(jié)最近學(xué)到的一些新知識(shí),這些特性不一定是SQLSERVER最新版才有,大多數(shù)是2008新特性,有些甚至是更早。如果有不懂的地方,建議大家去百度谷歌搜搜,本文不做詳細(xì)闡述,有錯(cuò)誤的地方,歡迎大家批評(píng)指正2012-08-08
SQL?Server數(shù)據(jù)庫(kù)命令整理大全
剛開(kāi)始學(xué)數(shù)據(jù)庫(kù),可能一下子記不住那么多的命令,或者命令太多,容易混淆,不知道如何選擇最合適的那一條,所以我在這里整理好了一份經(jīng)常會(huì)用到的一些,這篇文章主要給大家介紹了關(guān)于SQL?Server數(shù)據(jù)庫(kù)命令整理大全的相關(guān)資料,需要的朋友可以參考下2024-05-05
sql2000 卸載后重新安裝時(shí)不能安裝的解決辦法
sql2000卸載了后重新安裝時(shí)不能安裝的解決辦法,大家可以看下,下面的步驟。2009-07-07

