网页脚本攻击防范全攻略 2
程序体(1)另外,值得我们注意的是,很多站点在用户注册,或者是用户资料修改的页面上也缺少脚本的过滤,或者是只在其中之一进行过滤,注册进入后修改资料仍然可以进行脚本攻击。对用户提交的数据进行检测和过滤,程序体(2) 如下:
‘以下是过滤函数
If Instr(request("username"),"=")>0 or Instr(request("username"),"%")>0 or Instr(request("username"),chr(32))>0 or Instr(request("username"),"?")>0 or Instr(request("username"),"&")>0 or Instr(request("username"),";")>0 or Instr(request("username"),",")>0 or Instr(request("username"),"'")>0 or Instr(request("username"),"?")>0 or Instr(request("username"),chr(34))>0 or Instr(request("username"),chr(9))>0 or Instr(request("username"),"")>0 or Instr(request("username"),"$")>0 or Instr(request("username"),">")>0 or Instr(request("username"),"<")>0 or Instr(request("username"),"""")>0 then response.write "朋友,你的提交用户名含有非法字符,请更改,谢谢合作 <a href='****:window.history.go(-1);'>返回</a>" response.end end if
程序体(2)
为了提供工作效率我们再将过滤内容程序化,这样对多个参数的过滤效率将有很大程度上的提高:如
程序体(3)
‘以下为程序主体
dim Bword(18) Bword(0)="?" Bword(1)=";" Bword(2)=">" Bword(3)="<" Bword(4)="-" Bword(5)="’" Bword(6)="””" Bword(7)="&" Bword(8)="%" Bword(9)="$" Bword(10)="'" Bword(11)=":" Bword(12)=" " Bword(13)="(" Bword(14)=")" Bword(15)="--" Bword(16)=" chr(9)" Bword(17)=" chr(34)" Bword(18)=" chr(32)" errc=false
‘以下是应用实例部分
for i= 0 to ubound(Bword) if instr(FQYs,Bword(i))<>0 then errc=true end if next if errc then response.write "<script language=""****"">" response.write "parent.alert('很抱歉!您的操作违法了);" response.write "history,back();" response.write "</script>" response.end end if
程序体(3)
有了上面的过滤函数您可以在任何需要过滤的地方应用过滤函数直接使用就可以了。这就使我们的修复工作大大的简化了。
另外,我想在这里再次多提醒一下,一些站点的UBB在进行小的表情图标转化时也会出现过滤问题,由于很隐蔽所以不容易发现:
如:
我们标签内的文字进行修改,
不知道各位看懂没,前一个单引号用来中和程序提供的左引号,第二个单引号用来中和闭合的右引号,这样程序输出就为:
<img src=’img/0001.gif’ onerror=****:alert(); alt=’’>
如果图片不存在,那么将激活onerror标签执行脚本程序。对于已经过滤了单引号的站点在这里用双引号一样可以完成。对于过滤了****字段的,只用alert()也完全可以。所以说要过滤就要过滤完全,别给攻击者留下一丝机会。
- 联系我们: QQ:82526114(技术) 411523648(客服) 237057746(财务)
- 电话:+86-762-4372098 邮箱:webmaster@814e.net,support@814e.net
- 粤ICP备05002242号 网监局备案:4403701910502
