该文件可以包含在任何需要调用数据库的ASP文件头部,直接过虑掉非法注入
2008-10-08 14:17
561 查看
<%
'该文件可以包含在任何需要调用数据库的ASP文件头部,直接过虑掉非法注入
'调用方法为:
<!-- #include file="safe.asp" -->
Function Safe(str)'该函数用来判断传递过来的变量是否包含特殊字符,没有返回TRUE
Dim s_BadStr, n, i
s_BadStr = "' &<>?%,;:()`~!@#$^*{}[]|//+-="&Chr(34)&Chr(9)&Chr(32)
n = Len(s_BadStr)
Safe = True
For i = 1 To n
If Instr(str, Mid(s_BadStr, i, 1)) > 0 Then
Safe = False
Exit Function
End If
Next
End Function
'以下代码直接判断发生请求的URL是否包含非法字符
On Error Resume Next
Dim strTemp
If LCase(Request.ServerVariables("HTTPS")) = "off" Then
strTemp = "http://"
Else
strTemp = "https://"
End If
strTemp = strTemp & Request.ServerVariables("SERVER_NAME")
If Request.ServerVariables("SERVER_PORT") <> 80 Then strTemp = strTemp & ":" & Request.ServerVariables("SERVER_PORT")
strTemp = strTemp & Request.ServerVariables("URL")
If Trim(Request.QueryString) <> "" Then strTemp = strTemp & "?" & Trim(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,"db_name(") or Instr(strTemp,"net%20user") or Instr(strTemp,"'") or Instr(strTemp,"%20or") or Instr(strTemp,"backup%20") then
Response.Write "<script language='javascript'>"
Response.Write "alert('非法地址!!');"
Response.Write "location.href='http://www.myzone.cn';"
Response.Write "</script>"
End If
For Each name In Request.Form
Dim s_BadStr, s_Sz, i
s_BadStr = "'|and|select|update|chr|delete|from|;|insert|mid|master.|truncate|db_name|xp_cmdshell|exec%20master|net%20localgroup%20administrators|drop|table|db_name(|exec"
s_Sz = split(s_BadStr,"|")
For i = 0 To ubound(s_Sz)
If Instr(Request.Form(name), s_Sz(i)) > 0 Then
Response.Write "<script language='javascript'>"
Response.Write "alert('非法地址!!');"
Response.Write "location.href='http://www.myzone.cn';"
Response.Write "</script>"
End If
Next
Next
%>
'该文件可以包含在任何需要调用数据库的ASP文件头部,直接过虑掉非法注入
'调用方法为:
<!-- #include file="safe.asp" -->
Function Safe(str)'该函数用来判断传递过来的变量是否包含特殊字符,没有返回TRUE
Dim s_BadStr, n, i
s_BadStr = "' &<>?%,;:()`~!@#$^*{}[]|//+-="&Chr(34)&Chr(9)&Chr(32)
n = Len(s_BadStr)
Safe = True
For i = 1 To n
If Instr(str, Mid(s_BadStr, i, 1)) > 0 Then
Safe = False
Exit Function
End If
Next
End Function
'以下代码直接判断发生请求的URL是否包含非法字符
On Error Resume Next
Dim strTemp
If LCase(Request.ServerVariables("HTTPS")) = "off" Then
strTemp = "http://"
Else
strTemp = "https://"
End If
strTemp = strTemp & Request.ServerVariables("SERVER_NAME")
If Request.ServerVariables("SERVER_PORT") <> 80 Then strTemp = strTemp & ":" & Request.ServerVariables("SERVER_PORT")
strTemp = strTemp & Request.ServerVariables("URL")
If Trim(Request.QueryString) <> "" Then strTemp = strTemp & "?" & Trim(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,"db_name(") or Instr(strTemp,"net%20user") or Instr(strTemp,"'") or Instr(strTemp,"%20or") or Instr(strTemp,"backup%20") then
Response.Write "<script language='javascript'>"
Response.Write "alert('非法地址!!');"
Response.Write "location.href='http://www.myzone.cn';"
Response.Write "</script>"
End If
For Each name In Request.Form
Dim s_BadStr, s_Sz, i
s_BadStr = "'|and|select|update|chr|delete|from|;|insert|mid|master.|truncate|db_name|xp_cmdshell|exec%20master|net%20localgroup%20administrators|drop|table|db_name(|exec"
s_Sz = split(s_BadStr,"|")
For i = 0 To ubound(s_Sz)
If Instr(Request.Form(name), s_Sz(i)) > 0 Then
Response.Write "<script language='javascript'>"
Response.Write "alert('非法地址!!');"
Response.Write "location.href='http://www.myzone.cn';"
Response.Write "</script>"
End If
Next
Next
%>
相关文章推荐
- 该文件可以包含在任何需要调用数据库的ASP文件头部,直接过虑掉非法注入
- ASP.NET文件下载简单实现(也可以通过直接读取数据库 大字段文件,如oracle 中的bolg,long raw 等大字段文件)
- 可以以单个mdf文件直接注册数据库
- 用程序(asp,asp.net等任何可以访问数据库的语言)来自动建立FTP帐号(serv-u的odbc设置)
- ASP开发中数据库文件调用的捷径
- android 文件上传类(可以直接被调用的)
- asp.net当文件在不同目录下,需要获取数据库连接字符串
- android 文件上传类(可以直接被调用的)
- ASP过虑非法字符,SQL防注入函数,禁止非法提交
- asp.net 2.0 页面中直接输出数据库中的txt、html文件格式流
- ASP 包含文件中的路径问题和使用单一数据库连接文件的解决方案
- 不附加数据库 ASP.NET调用.“.NET研究”sql文件
- 好象很多人要JB2006的注册文件,我把注册文件提交上来了,需要的人可以直接去下载。
- C#编译器优化那点事 c# 如果一个对象的值为null,那么它调用扩展方法时为甚么不报错 webAPI 控制器(Controller)太多怎么办? .NET MVC项目设置包含Areas中的页面为默认启动页 (五)Net Core使用静态文件 学习ASP.NET Core Razor 编程系列八——并发处理
- 在 Android 系统中直接调用 SO文件(包含System.loadLibrary加载so的路径解释)
- mysql 备份(直接拷贝数据文件)仅限myisam数据库可以
- >+ ASP模板类[实现一维循环和二维循环,可以从文件、数据库、变量取摸板]
- asp.net当文件在不同目录下,需要获取数据库连接字符串收藏
- 在 Android 系统中直接调用 SO文件(包含System.loadLibrary加载so的路径解释)
- 在任何一个java工程下(即便是j2ee工程)都可以直接对某一个java文件run as Java Application,但是为什么有的java文件右击,没有“Java Application”