ASP网页防SQL注入的代码(二)
来源:互联网 发布:ff14男性捏脸数据 编辑:程序博客网 时间:2024/05/21 07:24
Dim Fy_Url,Fy_a,Fy_x,Fy_Cs(),Fy_Cl,Fy_Ts,Fy_Zx
'---定义部份 头------
Fy_Cl = 1 '处理方式:1=提示信息,2=转向页面,3=先提示再转向
Fy_Zx = "index.Asp" '出错时转向的页面
'---定义部份 尾------
On Error Resume Next
Fy_Url=Request.ServerVariables("QUERY_STRING")
Fy_a=split(Fy_Url,"&")
redim Fy_Cs(ubound(Fy_a))
On Error Resume Next
for Fy_x=0 to ubound(Fy_a)
Fy_Cs(Fy_x) = left(Fy_a(Fy_x),instr(Fy_a(Fy_x),"=")-1)
Next
For Fy_x=0 to ubound(Fy_Cs)
If Fy_Cs(Fy_x)<>"" Then
If Instr(LCase(Request(Fy_Cs(Fy_x))),"'")<>0 or Instr(LCase(Request(Fy_Cs(Fy_x))),"select")<>0 or Instr(LCase(Request(Fy_Cs(Fy_x))),"update")<>0 or Instr(LCase(Request(Fy_Cs(Fy_x))),"chr")<>0 or Instr(LCase(Request(Fy_Cs(Fy_x))),"delete%20from")<>0 or Instr(LCase(Request(Fy_Cs(Fy_x))),";")<>0 or Instr(LCase(Request(Fy_Cs(Fy_x))),"insert")<>0 or Instr(LCase(Request(Fy_Cs(Fy_x))),"mid")<>0 Or Instr(LCase(Request(Fy_Cs(Fy_x))),"master.")<>0 Then
Select Case Fy_Cl
Case "1"
Response.Write "<Script Language=JavaScript>alert(' 出现错误!参数 "&Fy_Cs(Fy_x)&" 的值中包含非法字符串!\n\n 请不要在参数中出现:and,select,update,insert,delete,chr 等非法字符!\n\n我已经设置了不能SQL注入,请不要对我进行非法手段!');window.close();</Script>"
Case "2"
Response.Write "<Script Language=JavaScript>location.href='"&Fy_Zx&"'</Script>"
Case "3"
Response.Write "<Script Language=JavaScript>alert(' 出现错误!参数 "&Fy_Cs(Fy_x)&"的值中包含非法字符串!\n\n 请不要在参数中出现:,and,select,update,insert,delete,chr 等非法字符!\n\n设计了门,非法侵入请离开,谢谢!');location.href='"&Fy_Zx&"';</Script>"
End Select
Response.End
End If
End If
Next
%>
以上代码为较多网友所用,从使用的感言来看,效果显著。
以下为引用的内容:
Dim Query_Badword,Form_Badword,Err_Message,Err_Web,form_name
'------定义部份 头----------------------------------------------------------------------
Err_Message = 1 '处理方式:1=提示信息,2=转向页面,3=先提示再转向
Err_Web = "Err.Asp" '出错时转向的页面
Query_Badword="'‖and‖select‖update‖chr‖delete‖%20from‖;‖insert‖mid‖master.‖set‖chr(37)‖="
'在这部份定义get非法参数,使用"‖"号间隔
Form_Badword="'‖%‖&‖*‖#‖@‖=‖select‖and‖set‖delete" '在这部份定义post非法参数,使用"‖"号间隔
'------定义部份 尾-----------------------------------------------------------------------
'
On Error Resume Next
'----- 对 get query 值 的过滤.
if request.QueryString<>"" then
Chk_badword=split(Query_Badword,"‖")
FOR EACH Query_form_name IN Request.QueryString
for i=0 to ubound(Chk_badword)
If Instr(LCase(request.QueryString(Query_form_name)),Chk_badword(i))<>0 Then
Select Case Err_Message
Case "1"
Response.Write "<Script Language=JavaScript>alert('传参错误!参数 "&form_name&" 的值中包含非法字符串!\n\n请不要在参数中出现:and update delete ; insert mid master 等非法字符!');window.close();</Script>"
Case "2"
Response.Write "<Script Language=JavaScript>location.href='"&Err_Web&"'</Script>"
Case "3"
Response.Write "<Script Language=JavaScript>alert('传参错误!参数 "&form_name&"的值中包含非法字符串!\n\n请不要在参数中出现:and update delete ; insert mid master 等非法字符!');location.href='"&Err_Web&"';</Script>"
End Select
Response.End
End If
NEXT
NEXT
End if
'-----对 post 表 单值的过滤.
if request.form<>"" then
Chk_badword=split(Form_Badword,"‖")
FOR EACH form_name IN Request.Form
for i=0 to ubound(Chk_badword)
If Instr(LCase(request.form(form_name)),Chk_badword(i))<>0 Then
Select Case Err_Message
Case "1"
Response.Write "<Script Language=JavaScript>alert('出错了!表单 "&form_name&" 的值中包含非法字符串!\n\n请不要在表单中出现: % & * # ( ) 等非法字符!');window.close();</Script>"
Case "2"
Response.Write "<Script Language=JavaScript>location.href='"&Err_Web&"'</Script>"
Case "3"
Response.Write "<Script Language=JavaScript>alert('出错了!参数 "&form_name&"的值中包含非法字符串!\n\n请不要在表单中出现: % & * # ( ) 等非法字符!');location.href='"&Err_Web&"';</Script>"
End Select
Response.End
End If
NEXT
NEXT
end if
以上是另一种版本。
以下为引用的内容:
<%
Dim GetFlag Rem(提交方式)
Dim ErrorSql Rem(非法字符)
Dim RequestKey Rem(提交数据)
Dim ForI Rem(循环标记)
ErrorSql = "'~;~and~(~)~exec~update~count~*~%~chr~mid~master~truncate~char~declare" Rem(每个敏感字符或者词语请使用半角 "~" 格开)
ErrorSql = split(ErrorSql,"~")
If Request.ServerVariables("REQUEST_METHOD")="GET" Then
GetFlag=True
Else
GetFlag=False
End If
If GetFlag Then
For Each RequestKey In Request.QueryString
For ForI=0 To Ubound(ErrorSql)
If Instr(LCase(Request.QueryString(RequestKey)),ErrorSql(ForI))<>0 Then
response.write "<script>alert(""警告:\n请不要做任何尝试"");location.href=""index.asp"";</script>"
Response.End
End If
Next
Next
Else
For Each RequestKey In Request.Form
For ForI=0 To Ubound(ErrorSql)
If Instr(LCase(Request.Form(RequestKey)),ErrorSql(ForI))<>0 Then
response.write "<script>alert(""警告:\n请不要做任何尝试"");location.href=""index.asp"";</script>"
Response.End
End If
Next
Next
End If
%>
将上述代码放入conn文件中即可,功能较全面……
ASP防止SQL注入方法,有效杜绝SQL注入的代码
通用防SQL注入代码ASP版
代码
dim sql_injdata
SQL_injdata = "'|and|exec|insert|select|delete|update|count|*|%|chr|mid|master|truncate|char|declare"
SQL_inj = split(SQL_Injdata,"|")
If Request.QueryString<>"" Then
For Each SQL_Get In Request.QueryString
For SQL_Data=0 To Ubound(SQL_inj)
if instr(Request.QueryString(SQL_Get),Sql_Inj(Sql_DATA))>0 Then
'Response.Write(Request.QueryString)
Response.Write "<Script>alert('@SQL通用防注入系统提示↓nn请不要在参数中包含非法字符尝试注入!');history.back(-1)</Script>"
Response.end
end if
next
Next
End If
If Request.Form<>"" Then 'liehuo.net
For Each Sql_Post In Request.Form
For SQL_Data=0 To Ubound(SQL_inj)
if instr(Request.Form(Sql_Post),Sql_Inj(Sql_DATA))>0 Then
'Response.Write(Request.Form)
Response.Write "<Script>alert('@SQL通用防注入系统提示↓nn请不要在参数中包含非法字符尝试注入!');history.back(-1)</Script>"
Response.end
end if
next
Next
End If
sss=LCase(request.servervariables("QUERY_STRING"))
if instr(sss,"select")<>0 or instr(sss,"inster")<>0 or instr(sss,"delete")<>0 or instr(sss,"(")<>0 or instr(sss,"'or")<>0 then
response.write "<BR><BR><center>你的网址不合法"
response.end
end if
StrTemp=request.servervariables("server_name")&request.servervariables("url")&"?"&Request.QueryString
StrTemp = LCase(StrTemp)
If Instr(StrTemp,"select%20") or Instr(StrTemp,"insert%20") or Instr(StrTemp,"delete%20from") or Instr(StrTemp,"count(") or Instr(StrTemp,"drop%20table") or Instr(StrTemp,"update%20") or Instr(StrTemp,"truncate%20") or Instr(StrTemp,"asc(") or Instr(StrTemp,"mid(") or Instr(StrTemp,"char(") or Instr(StrTemp,"xp_cmdshell") or Instr(StrTemp,"exec%20master") or Instr(StrTemp,"net%20localgroup%20administrators") or Instr(StrTemp,"net%20user") or Instr(StrTemp,"%20or%20") or Instr(StrTemp,"'") or Instr(StrTemp,"%20") or Instr(StrTemp,"""") or Instr(StrTemp,"“") or Instr(StrTemp,"”") or Instr(StrTemp,":") or Instr(StrTemp,":") or Instr(StrTemp,";") or Instr(StrTemp,";") or Instr(StrTemp,",") or Instr(StrTemp,",") or Instr(StrTemp,"%27") then
Response.Write "<script language='javascript'>alert('非法操作!立即返回!');history.back();</script>"
Response.end
End If- ASP网页防SQL注入的代码(二)
- ASP网页防SQL注入的代码
- sql防注入代码(asp)
- asp防sql注入代码
- ASP.net简单的防SQL注入代码
- ASP.net简单的防SQL注入代码
- ASP.net简单的防SQL注入代码
- asp.net(C#)防sql注入组件的实现代码
- 好用的asp防SQL注入代码
- 好用的asp防SQL注入代码
- asp sql 防注入
- asp防sql注入
- asp 防注入代码
- 防sql注入代码
- sql防注入代码
- asp.net防SQL注入的安全措施
- 通用ASP的sql防注入程序
- 简单的ASP.net防SQL注入
- 解决eclipse中出现Resource is out of sync with the file system问题
- Swift完成fizz buzz test
- HDU 1573 X问题 (中国剩余定理 模线性方程组)
- Android动态加载黑科技 动态创建Activity模式
- (数组练习)冒泡--从小到大--从大到小排列
- ASP网页防SQL注入的代码(二)
- [BZOJ4547]小奇的集合(矩乘)
- Nginx静态资源POST请求返回405状态
- Contest - 多校训练(三)
- js中this的指向
- 一个关于ABAP中AUTHORITY-CHECK的Demo
- header.phtml如何加载购物车的sidebar.phtml
- [二] rehl 6.4 更换 yum源为163的源
- C#判断字符串是否为数字字符串