几种过滤URL和FORM中非法字符的方法
ASP
过滤URL和FORM中非法字符
第一种:
' 检查URL输入 限制非法字符
url = LCase (request.querystring())
ip = request.ServerVariables( " REMOTE_ADDR " )
pos1 = instr (url, " % " )
pos2 = instr (url, " ' " )
pos3 = instr (url, " ; " )
pos4 = instr (url, " where " )
pos5 = instr (url, " select " )
pos6 = instr (url, " chr " )
pos7 = instr (url, " / " )
pos8 = Instr (url, " and " )
if pos1 <> 0 or pos2 <> 0 or pos3 <> 0 or pos4 <> 0 or pos5 <> 0 or pos6 <> 0 or pos7 <> 0 or pos8 <> 0 then
response.Write " 你尝试使用危险字符,系统已经对此做了记录如下<Br>您的IP: " & ip & " <br>操作时间: " & date () & ""
response.End()
end if
' 检查表单输入,限制非法字符
' 使用request.QueryString来索引request的所有资料,作为SQL检查之用
' 如出现非法字符则自动停止输出
for i_request = 1 to request.form.Count
if instr (request.form(i_request), " ' " ) <> 0 or instr (request.form(i_request), " ; " ) <> 0 then
Response.Write " <script language='javascript'>history.back(); alert('你尝试使用危险字符,系统已经对此做了记录如下您的IP: " & ip & " 操作时间: " & date () & " ');</script> "
response.End()
end if
next
% >
第二种:
On Error Resume Next
dim sql_injdata,sql_inj,sql_get,sql_data
SQL_injdata = " '|ox "
SQL_inj = split (SQL_Injdata, " | " )
' 定义过滤字符,可以自己添加,以|分隔
' "'|;|and|exec|insert|select|delete|update|count|*|%|chr|mid|master|truncate|char|declare"
' 对post方式过滤
If Request.Form <> "" Then
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.redirect " ss " ' 出错时转向页面
Response.end
end if
next
next
end if
' 对GET方式过滤
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.redirect " ss " ' 出错时转向页面
Response.end
end if
next
Next
End If
% >
第三种:
dim tempstr
if str = "" then exit function
tempstr = replace (str, chr ( 34 ), "" ) ' "
tempstr = replace (tempstr, chr ( 39 ), "" ) ' '
tempstr = replace (tempstr, chr ( 60 ), "" ) ' <
tempstr = replace (tempstr, chr ( 62 ), "" ) ' >
tempstr = replace (tempstr, chr ( 37 ), "" ) ' %
tempstr = replace (tempstr, chr ( 38 ), "" ) ' &
tempstr = replace (tempstr, chr ( 40 ), "" ) ' (
tempstr = replace (tempstr, chr ( 41 ), "" ) ' )
tempstr = replace (tempstr, chr ( 59 ), "" ) ' ;
tempstr = replace (tempstr, chr ( 43 ), "" ) ' +
tempstr = replace (tempstr, chr ( 45 ), "" ) ' -
tempstr = replace (tempstr, chr ( 91 ), "" ) ' [
tempstr = replace (tempstr, chr ( 93 ), "" ) ' ]
tempstr = replace (tempstr, chr ( 123 ), "" ) ' {
tempstr = replace (tempstr, chr ( 125 ), "" ) ' }
checkstr = tempstr
end function
第四种:
' 函数名:IsValidStr
' 作 用:判断字符串中是否含有非法字符
' 参 数:str ----原字符串
' 返回值:False‚True -----布尔值
' ================================================
Public Function IsValidStr(ByVal str)
IsValidStr = False
On Error Resume Next
If IsNull (str) Then Exit Function
If Trim (str) = Empty Then Exit Function
Dim ForbidStr‚ i
ForbidStr = " and|chr|:|=|%|&|$|#|@|+|-|*|/|/|<|>|;|‚|^| " & Chr ( 32 ) & " | " & Chr ( 34 ) & " | " & Chr ( 39 ) & " | " & Chr ( 9 )
ForbidStr = Split (ForbidStr‚ " | " )
For i = 0 To UBound (ForbidStr)
If InStr ( 1 ‚str‚ ForbidStr(i)‚ 1 ) > 0 Then
IsValidStr = False
Exit Function
End If
Next
IsValidStr = True
End Function
ASP.NET
... {
int flag = 0;
flag += para.indexOf("'") + 1;
flag += para.indexOf(";") + 1;
flag += para.indexOf("1=1") + 1;
flag += para.indexOf("|") + 1;
flag += para.indexOf("<") + 1;
flag += para.indexOf(">") + 1;
if (flag != 0)
...{
System.out.println("提交了非法字符!!!");
return false;
}
return true;
}
几种过滤URL和FORM中非法字符的方法相关推荐
- mysql 过滤微信昵称表情_PHP正则过滤处理微信昵称中emoji字符的方法
本文实例讲述了PHP正则过滤处理微信昵称中emoji字符的方法.分享给大家供大家参考,具体如下: 今天刚做了一个微信应用,在获取微信昵称的过程中报错了,经查原因是微信昵称中包含emoji字符,在写入数 ...
- PHP正则过滤处理微信昵称中emoji字符的方法(导出excel)
今天做了excel导出数据,发现微信昵称含有emoji字符,导致导出信息不全,所以选择过滤掉emoji字符 function removeEmoji($nickname) {$clean_text = ...
- xml 中转意字符\/使用方法
xml 中转意字符&\/使用方法 所有 XML 元素都须有关闭标签 在 HTML,经常会看到没有关闭标签的元素: <p>This is a paragraph <p>T ...
- python处理xml中非法字符的一种思路
非法字符在xml中的存储一直比较讨厌,其实这个非法字符并不仅仅是非可见字符,还包括xml中规定的某些特殊字符,比如<&>等. 一种比较方便的处理方式是将那些非法字符采用HEX方式存 ...
- json非法字符有哪些_JSON文件中非法字符的处理
JSON是一种很好的数据格式,但是简单之处也有麻烦的地方,比如如果JSON的字符串里面出现了双引号的话,那真是搞死人了. 之前我很傻,每次抛出异常,我就根据异常显示的位置,去慢慢一个一个找错误的地方, ...
- python如何增加字符串_在python中增加字符的方法
在本教程中,我们将看到在Python中增加字符的不同方法. 类型转换 首先让我们看看如果在不进行类型转换的情况下向char添加int会发生什么. 示例## str initialization cha ...
- Java删除字符串中指定字符的方法分享
转自: Java如何删除字符串中指定字符呢? 字符串: 字符串主要用于编程,概念说明.函数解释.用法详述见正文,这里补充一点:字符串在存储上类似字符数组,所以它每一位的单个元素都是可以提取的,如s=& ...
- java replaceall lt,JAVA中替换字符的方法replace和replaceAll 区别
replace和replaceAll是JAVA中常用的替换字符的方法,它们的区别是: 1.replace的参数是char和CharSequence,即可以支持字符的替换,也支持字符串的替换(CharS ...
- 一种解析SAS程序文件中的变量的方法
笔者使用的SAS数据库查询平台,对接了一个以JSON格式的分级授权引擎,需将用户提交给数据库查询的SQL语句拼接在JSON入参里,但大量用户使用的数据库查询语句SQL超长(超过32767字节),这里, ...
最新文章
- java 中 bean 的生命周期
- python下载大文件mp4_python合并大量ts文件成mp4格式(ps:上限是450,亲测)
- Gartner:缺乏技术人才将影响企业数字化转型
- Android如何分析native代码,使用android-ndk-profiler对native代码进行性能分析
- hdu 1300(dp)
- 面试题:请介绍⼀下 JMM(Java 内存模型)
- vue-socket.io 对IE浏览器(IE10+)的兼容性修复
- 第三方短信验证码服务
- stream().sorted 排序
- matlab海底地形数据,海底地形建模器
- 小程序发布成功后搜索不到怎么办?
- 简述linux的系统组成,【简答题】Linux操作系统有哪几个部分组成?请简述每个组成部分的作用。...
- 网络攻防 横向移动_网络安全101的数据分析:检测横向移动
- LR关联知识点详解(精品总结)一定要看
- xp桌面计算机在哪个文件夹,windows桌面文件路径 windows xp 桌面文件默认存放路径...
- 球半篮球比分,NBA总决赛第三场:顿凯尔特人VS勇士
- 2845 ACM 豆子 beans
- UnityShader Reversed-Z的理解
- 网络编程 —— 了解
- 使用live555 直播来自v4l2的摄像头数据