网络营销电子商务研究中心  
How to buy the best prescription safety glasses in Canada? Let's study!
Go Back   网络营销电子商务研究中心 > 网站建设 > 代码交流
User Name
Password
 
FAQ Members List Calendar Cheap Glasses

代码交流 ASP,PHP,JSP等网站源代码下载与交流。

Reply
 
Thread Tools Display Modes
  #1   IP: 117.95.53.180
Old 2010-08-06, 09:29 AM
topvip topvip is offline
超级版主
 
Join Date: 2006-01-04
Posts: 1206
topvip 正向着好的方向发展
Default 用的asp防sql注入攻击程序

SQL注入被那些菜鸟级别的所谓黑客高手玩出了滋味,发现现在大部分黑客入侵都是基于SQL注入实现的。SQL注入被那些菜鸟级别的所谓黑客高手玩出了滋味,发现现在大部分黑客入侵都是基于SQL注入实现的,哎,谁让这个入门容易呢,好了,不说废话了,现在我开始说如果编写通用的SQL防注入程序一般的http请求不外乎get 和 post,所以只要我们在文件中过滤所有post或者get请求中的参数信息中非法字符即可,所以我们实现http 请求信息过滤就可以判断是是否受到SQL注入攻击。
  IIS传递给asp.dll的get 请求是是以字符串的形式,,当 传递给Request.QueryString数据后,asp解析器会分析Request.QueryString的信息,,然后根据"&",分出各个数组内的数据所以get的拦截如下:
  首先我们定义请求中不能包含如下字符:
  引用:
  |and|exec|insert|select|delete|update|count|*|%|chr|mid|master|truncate|char|declare
  
  各个字符用"|"隔开,,然后我们判断的得到的Request.QueryString,具体代码如下 :
  引用:
  dim sql_injdata
  SQL_injdata = "'|and|exec|insert|select|delete|update|count|*|%|chr|mid|master|truncate|char|declare"
  SQL_inj = split(SQL_Injdata,"|")
  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.Write "<Script Language=****>alert('天下电影联盟SQL通用防注入系统提示↓nn请不要在参数中包含非法字符尝试注入!');history.back(-1)</Script>"
  Response.end
  end if
  next
  Next
  End If
  
  这样我们就实现了get请求的注入的拦截,但是我们还要过滤post请求,所以我们还得继续考虑request.form,这个也是以数组形式存在的,我们只需要再进一次循环判断即可。代码如下:
  引用:
  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.Write "<Script Language=****>alert('天下电影联盟SQL通用防注入系统提示↓nn请不要在参数中包含非法字符尝试注入!nnHTTP://www.521movie.com ');history.back(-1)</Script>"
  Response.end
  end if
  next
  next
  end if
  
  好了大功告成,我们已经实现了get和post请求的信息拦截,你只需要在conn.asp之类的打开数据库文件之前引用这个页面即可。放心的继续开发你的程序,不用再考虑是否还会受到SQL注入攻击。难道不是么?
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is On
HTML code is Off

Forum Jump

Prescription-glasses.com offers prescription glasses online at discount prices.
All times are GMT +8. The time now is 10:44 AM.


Powered by vBulletin Version 3.8.7
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.