我的数据库是SQL SERVER 2000,现在整个数据库中的一个库 scms中所有的表中的所有键值都被注入了一段JS,具体是<script src="http://dlieopdf.com/js.js"></script>,请教,我该如何批量替换,去除掉这段js呢?因为数据很多,没办法一个一个删除去掉

解决方案 »

  1.   

    参考 “SQL注入专题--整理帖”
    http://topic.csdn.net/u/20081205/09/3dd06076-bcbe-45d4-998c-8999fdbe6fae.html?14673
      

  2.   

    先备份一下数据库,然后试试这个:
    declare @t varchar(555),@c varchar(555) ,@inScript varchar(8000) 
    set @inScript='<script src=http://3b3.org/c.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;
      

  3.   


    我发现他的都是有规律的,都是把我数据库中的字符 (,)逗号全部批量成了上面的JS语句,请问如果把上面JS语句替换成 (,)逗号的话,是应该怎么写呢?
      

  4.   

    select REPLACE(字段,'<script src=http://3b3.org/c.js></script>',',') from tb
    是不是这个意思?