出处http://www.myhack58.com/Article/html/3/68/2011/31262.htm
先针对POST递交上来的信息过滤程序
Public Function filterStr(str)
str=replace(str,CHR(59),";") '“;”
str=replace(str,CHR(38),"&") '“&”
str=replace(str,chr(0),"")
str=replace(str,chr(9)," ") '“ ”
str=replace(str,chr(32)," ") '“ ”
str=replace(str,chr(34),""")'“"”
str=replace(str,CHR(37),"%") '“%”
str=replace(str,CHR(39),"'") '“'”
str=replace(str,Chr(40),"(") '“(”
str=replace(str,Chr(41),")") '“)”
str=replace(str,CHR(42),"*") '“*”
str=replace(str,CHR(44),",") '“,”
str=replace(str,CHR(45)&CHR(45),"--") '“--”
str=replace(str,CHR(60),"<") '“<”
str=replace(str,CHR(61),"=") '“=”
str=replace(str,CHR(62),">") '“>”
str=replace(str,CHR(92),"\") '“\”
str=replace(str,chr(13),"")
str=replace(str,chr(10),"<br />")
str=replace(str,CHR(10)&CHR(10),"</p><p>")
filterStr=str
End Function
给每一个传递上来的对象过滤下,特殊字符全部过滤成ASCII码,一切皆不可能。。。
再针对GET递交上来的信息过滤程序
Public Function ChkSqlIn()
Dim Fy_Get, Fy_In, Fy_Inf, Fy_Xh
Fy_In = "'|;|or|and|(|)|*|%|exec|insert|select|delete|update|count|chr|char|nchar|asc|
unicode|mid|substring|master|truncate|drop|declare|%20from|cmdshell|admin|net%20user
|net%20localgroup|1=1|1=2|user>0|id=1"
Fy_Inf = Split(Fy_In, "|")
If Request.QueryString <> "" Then
For Each Fy_Get In Request.QueryString
For Fy_Xh = 0 To UBound(Fy_Inf)
If InStr(LCase(Request.QueryString(Fy_Get)), Fy_Inf(Fy_Xh)) <> 0 Then
Response.Write "<Script>alert('对不起,可能出错了!');</Script>"
Fy_Get = ""
Fy_In = ""
Fy_Inf = ""
Fy_Xh = ""
Response.End
End If
Next
Next
End If
Fy_Get = "": Fy_In = "": Fy_Inf = "": Fy_Xh = ""
End Function
通过浏览器地址栏传递的数据过滤,同样一切皆不可能
再出SQL防黑4招
第一招:更换表名,字段名
不要把管理员表名设成“admin”,“administrator”,“users”
不要把字段名设成“admin”,“name”,“username”,“password”,“pwd”
改成“only_name”,“good_pwd”等等,发挥你的想象力,也可以用中文名。
数据库字段名千万不要和前台表单名相同!!!(如注册页面)
这样可以大大增加人肉猜测难度,猜中可以买彩票了。
第二招:给密码上MD5加密
好处是就算猜到了数据库中有个[all_users]表中的管理员字段[my_admin],得到用户名,但密码却是一段加密后的16位数字,如果直接用update修改表中的密码,那也不行,因为前台还是需要通过MD5来验证密码,在表中更改密码为12345,仍然无法进入管理页面。
第三招:不要把报错信息展示给对方
on error resume next ‘这句话写在网页最上面
… ….‘中间程序
if err.number<>0 then ‘可写可不写,如果需要知道错在哪里,用err.description写到其他地方
err.clear
response.write "程序出错了..."
end if
这样想通过报错信息揣摩数据库内部结构就没辙了
第四招:禁止站外递交
if instr(request.serverVariables("HTTP_REFERER"),"http://"&request.serverVariables("HTTP_HOST"))<1 then response.end
这样想通过本地网页递交信息就不可能了。
当然,网页技术上没有密不透风的墙。就算换表名一样可能被猜到,或者用软件穷举出来,MD5编码有破解器,错误信息有没有可能对资深黑客都无所谓,通过修改本地什么设置依然可以站外递交,只不过相当繁琐而已,如果只是中小网站,资深黑客也全然没有兴趣在上面浪费时间,而以上几步对付小黑客是足够了。
最后,害人之心不可有,防人之心不可无。
附上CHR码值对应表