ASP中两个防止SQL注入的Function

web前端504213年前 (2011-03-29)
ASP中两个防止SQL注入的Function
 
代码如下:
  1. '==========================  
  2. '过滤提交表单中的SQL语言规则   
  3. '==========================  
  4. funCtion ForSqlForm()  
  5. dim fqys,errC,i,items  
  6. dim nothis(18)   
  7. nothis(0)="net user"   
  8. nothis(1)="xp_Cmdshell"   
  9. nothis(2)="/add"   
  10. nothis(3)="exeC%20master.dbo.xp_Cmdshell"   
  11. nothis(4)="net loCalgroup administrators"   
  12. nothis(5)="seleCt"   
  13. nothis(6)="Count"   
  14. nothis(7)="asC"   
  15. nothis(8)="Char"   
  16. nothis(9)="mid"   
  17. nothis(10)="'"    
  18. nothis(11)=":"    
  19. nothis(12)=""""    
  20. nothis(13)="insert"    
  21. nothis(14)="delete"    
  22. nothis(15)="drop"    
  23. nothis(16)="trunCate"    
  24. nothis(17)="from"    
  25. nothis(18)="%"  
  26.   
  27. 'nothis(19)="@"    
  28. errC=false   
  29. for i= 0 to ubound(nothis)   
  30.   for eaCh items in request.Form  
  31.   if instr(request.Form(items),nothis(i))<>0 then   
  32.    response.write("<div>")  
  33.    response.write("你所填写的信息:" & server.HTMLEnCode(request.Form(items)) & "<br>含非法char:" & nothis(i))  
  34.    response.write("</div>")  
  35.    response.write("对不起,你所填写的信息含非法char!<a href=""#"" onCliCk=""history.baCk()"">返回</a>")  
  36.    response.End()  
  37.   end if   
  38.   next  
  39. next   
  40. end funCtion  
  41. '==========================   
  42. '过滤查询中的SQL语言规则  
  43. '==========================   
  44. funCtion ForSqlInjeCtion()   
  45. dim fqys,errC,i   
  46. dim nothis(19)    
  47. fqys = request.ServerVariables("QUERY_STRING")   
  48. nothis(0)="net user"    
  49. nothis(1)="xp_Cmdshell"    
  50. nothis(2)="/add"    
  51. nothis(3)="exeC%20master.dbo.xp_Cmdshell"    
  52. nothis(4)="net loCalgroup administrators"    
  53. nothis(5)="seleCt"    
  54. nothis(6)="Count"    
  55. nothis(7)="asC"    
  56. nothis(8)="Char"    
  57. nothis(9)="mid"    
  58. nothis(10)="'"    
  59. nothis(11)=":"    
  60. nothis(12)=""""    
  61. nothis(13)="insert"    
  62. nothis(14)="delete"    
  63. nothis(15)="drop"    
  64. nothis(16)="trunCate"    
  65. nothis(17)="from"    
  66. nothis(18)="%"  
  67.   
  68. nothis(19)="@"     
  69. errC=false    
  70. for i= 0 to ubound(nothis)    
  71. if instr(FQYs,nothis(i))<>0 then    
  72. errC=true    
  73. end if    
  74. next    
  75. if errC then    
  76. response.write "查询信息含非法char!<a href=""#"" onCliCk=""history.baCk()"">返回</a>"    
  77. response.end    
  78. end if    
  79. end funCtion