SQL清除被注入的內容

來源:互聯網
上載者:User

進入SQL查詢分析器
選擇你的資料庫
第一步:先sql表修改所有者為dbo
EXEC   sp_MSforeachtable   'exec   sp_changeobjectowner   ''?'',''dbo''   '  
第二步:統一刪除欄位被掛的js

declare @t varchar(555),@c varchar(555) ,@inScript varchar(8000) 
set @inScript='<script src=http://okm4.org/z.js></script>' 
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  
---------------------------------------------------------------

本文來自CSDN部落格,轉載請標明出處:http://blog.csdn.net/htl258/archive/2009/04/03/4026169.aspx

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.