程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> 其他數據庫知識 >> 更多數據庫知識 >> SqlServer中批量替換被插入的木馬記錄

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

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved