首页>
技术资讯>
详情

全面防御asp网站防黑客攻击

2016-06-17 来源:CloudBest 阅读量: 811
关键词: 应用技术


  asp最脆弱的不是技术,而是防范黑客攻击。而无论怎样攻击,通过QueryString和form,只要这两处防范好了,问题就解决了
  下面是我自家独创的一些代码,供大家参考
  
  一.防通过querystring的sql攻击
  一般sql能够攻击的页面通常是在参数为数字的页面
  1.首先我们做一个警告子过程
  '''''子过程功能:错误信息提示''''''''''''''''''
  '''''参数说明:errmsg 错误信息说明 var 处理方式 1返回不刷新 2返回上页 3关闭页面''''''''''''''''''
  Public sub alarm(errmsg,var)
  response.Write("<table width=514 height=293 border=0 align=center cellpadding=0 cellspacing=0>")
  response.Write("<tr><td height=43><img src=images/error_bg.gif width=514 height=43></td></tr><tr>")
  response.Write("<td height=239 valign=top> ")
  response.Write("<table width='100%' height='100%' cellpadding=0 cellspacing=1 bgcolor='#cccccc' style='border-left:1px solid #DDDDDD;border-right:1px solid #DDDDDD'>")
  response.Write("<tr bgcolor='#FFFFFF'><td width='57%' align='center'><img src='images/error_show.gif' width='272' height='92'></td>")
  response.Write("<td width='43%' align='center'><div align='center' style='line-height:150%'><font color='#0099FF' style='font-size:9pt'>对于操作失败我们表示抱歉!<br>如果仍有问题,请给我们发送错误报告 </font></div></td></tr>")
  response.Write("<tr bgcolor='#FFFFFF'><td height=25 colspan=2>  <strong><font color=#0099FF style='font-size:9pt'>操作失败的可能原因:</font></strong></td></tr>")
  response.Write("<tr bgcolor='#FFFFFF'><td height=86 colspan=2>")
  response.Write("<table width='100%' border=0 cellspacing=0 cellpadding=0>")
  response.Write("<tr><td width='2%'> </td>")
  response.Write("<td width='98%'><font style='font-size:9pt' color='#FF0000'>"&errmsg&"</font></td>")
  response.Write("</tr></table></td></tr><tr align=center bgcolor='#FFFFFF'><td height=49 colspan=2>")
  if var=1 then
  response.Write("<a href='javascript:history.go(-1)'><img src='images/error_enterenter.gif' width='61' height='21' style='cursor:hand' border='0'></a>")
  elseif var=2 then
  response.Write("<a href='javascript:location.href='"&request.ServerVariables("HTTP_REFERER")&"'><img src='images/error_enterenter.gif' width='61' height='21' style='cursor:hand' border='0'></a>")
  elseif var=3 then
  response.Write("<a href='javascript:window.close()'><img src='images/error_enterenter.gif' width='61' height='21' style='cursor:hand' border='0'></a>")
  end if
  response.Write("</td></tr></table></td></tr><tr>")
  response.Write("<td height=9><img src='images/error_down.gif' width='514' height='9'></td></tr></table>")
  End Sub
  
  2.写一个验证数字的函数
  '''''函数功能:检测是否为数字并且数字是否有效''''''''''''''''''
  '''''返 回 值:boolean'''''''''''''''''''''''''''''''''''''''''
  Public function isInteger(para)
  if isnumeric(para)=false then isinteger=false
  dim str
  dim l,i
  if isNUll(para) then
  isInteger=false
  exit function
  end if
  str=cstr(para)
  if trim(str)="" then
  isInteger=false
  exit function
  end if
  l=len(str)
  for i=1 to l
  if mid(str,i,1)>"9" or mid(str,i,1)<"0" then
  isInteger=false
  exit function
  end if
  next
  isInteger=true
  end function
  
  3.写一个对querysting参数是否为数字的验证过程
  '''''''''''子过程功能,验证参数是否为数字
  '''''''''''参数说明:manage 处理方式:1=提示信息并关闭页面,2=转向页面,3=先提示再转向 redi 出错时转向的页面,str:接受检测的变量
  public sub integerok(manage,redi,str)
  if isinteger(str)=false then
  select case manage
  case 1
  response.Write("<script language=javascript>alert('地址栏中的参数错误,本页面将自动关闭');window.close();</script>")
  case 2
  Response.Write "<Script Language=javascript>location.href='"&redi&"'</Script>"
  case 3
  Response.Write "<Script Language=javascript>alert('地址栏中的参数错误,本页将自动导向其他页面');location.href='"&redi&"';</Script>"
  end select
  end if
  end sub
  
  4.写一个对qureystring整体验证的子过程
  '''''''''''参数说明:manage 处理方式:1=提示信息并关闭页面,2=转向页面,3=先提示再转向 redi 出错时转向的页面
  public sub saferush(manage,redi)
  Dim my_Url,my_a,my_x,my_Cs(),my_Ts 'my_url:转接过来的url地址 my_a:获取url地址中用&隔开的字符串数组
  my_Url=Request.ServerVariables("QUERY_STRING") 'my_x:interger my_cs()动态数组
  my_a=split(my_Url,"&")
  redim my_Cs(ubound(my_a))
  On Error Resume Next
  for my_x=0 to ubound(my_a)
  my_Cs(my_x) = left(my_a(my_x),instr(my_a(my_x),"=")-1)
  Next

热门推荐 查看更多