解决并清除SQL被注入<script>恶意病毒代码的语句

简介:

declare @t varchar(255),@c varchar(255)  
declare table_cursor cursor for select a.name,b.name   
from sysobjects a,syscolumns b ,systypes c   
where a.id=b.id and a.xtype='u' and c.name   
in ('char''nchar''nvarchar''varchar','text','ntext')  
declare @str varchar(500),@str2 varchar(500)  
set @str='<script src=http://r01.3322.org/c.js></script>'/*要替换的内容*/  
set @str2=''   
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)),'''+@str+''','''+ @str2 +''')')  
fetch next from table_cursor  
into @t,@c end close table_cursor deallocate table_cursor; 

 

 

-- sql 去掉字段html代码 dbo.StripAllTags(ProductDetails)
CREATE  FUNCTION  [ dbo ]. [ StripAllTags ]
(
     @input  VARCHAR( 8000--   NVARCHAR(MAX)--2000内改为VARCHAR(8000)
)
RETURNS  NVARCHAR( MAX)
AS
BEGIN
     declare 
     @Result  nvarchar( MAX),
     @start  int,
     @end  int,
     @len  int

     set  @input  =  @input + ' <> '
     set  @Result  =  ''
     set  @len = len( @input)
     set  @start  =  charindex( ' < ', @input, 1)
     set  @end  =  charindex( ' > ', @input, @start)
     while( @start < @end)
         begin        
             if( @start <> 1
             set  @Result  =  @Result  +  substring( @input, 1, @start - 1)
             set  @len  =  @len  -  @end
             set  @input  =  substring( @input, @end + 1, @len)
             set  @start  =  charindex( ' < ', @input, 1)
             set  @end  =  charindex( ' > ', @input, @start)
         end

     RETURN  replace( @Result, ' &nbsp; ', '')    

END  

 


    本文转自曾祥展博客园博客,原文链接:http://www.cnblogs.com/zengxiangzhan/archive/2010/02/08/1665660.html,如需转载请自行联系原作者


相关文章
|
SQL Oracle 关系型数据库
|
SQL 关系型数据库 PostgreSQL
sql: postgreSQL sql script
--pg_catalog SELECT * from pg_class c,pg_attribute a,pg_type t where c.relname='BookKindList' and a.attnum&gt;0 and a.attrelid=c.oid and a.atttypid=t.oid SELECT a.attname from pg_class c,pg_attri
1101 0
|
14天前
|
SQL 人工智能 算法
【SQL server】玩转SQL server数据库:第二章 关系数据库
【SQL server】玩转SQL server数据库:第二章 关系数据库
52 10
|
1月前
|
SQL 数据库 数据安全/隐私保护
Sql Server数据库Sa密码如何修改
Sql Server数据库Sa密码如何修改
|
24天前
|
SQL
启动mysq异常The server quit without updating PID file [FAILED]sql/data/***.pi根本解决方案
启动mysq异常The server quit without updating PID file [FAILED]sql/data/***.pi根本解决方案
17 0