WEB开发网
开发学院网络安全安全技术 SQL注入攻击及其防范检测技术研究 阅读

SQL注入攻击及其防范检测技术研究

 2008-11-01 13:29:27 来源:WEB开发网   
核心提示: 本模型的最大特点是自动将攻击信息及时的传递给管理员,方便管理员及时做出响应,SQL注入攻击及其防范检测技术研究(6),图1 SQL注入攻击自动防范模型核心代码如下:sub stopit()response.write "存在禁止访问ip地址:"&rs("ip&

本模型的最大特点是自动将攻击信息及时的传递给管理员,方便管理员及时做出响应。

SQL注入攻击及其防范检测技术研究

图1 SQL注入攻击自动防范模型

核心代码如下:

sub stopit()
response.write "存在禁止访问ip地址:"&rs("ip")
response.end
response.redirect "noright.asp"
end sub
dim attack_browser,attack_ip,attack_host
attack_browser=Request.ServerVariables("Http_User_Agent")
attack_ip=Request.ServerVariables("ReMote_Addr")
attack_host=Request.ServerVariables("Remote_Host")
set rs1=server.createobject("adodb.recordset")
'从访问禁止ip中查询是否存在访问者的IP地址,如果存在则禁止其访问
sql1="select ip from prohibit_ip where ip='"&attack_ip&"'"
rs1.open sql1,conn,1,3
if not rs1.eof then
call stopit()
end if
rs1.close
set rs1=nothing
'从系统防范设置中查出email地址和运行的访问次数
set rs2=server.createobject("adodb.recordset")
sql2="select * from D_setup"
rs2.open sql2,conn,1,3
if not rs2.eof then
session("email")=rs2("email")
session("ok_count")=rs2("ok_count")
end if
rs2.close
set rs2=nothing
url=Request.ServerVariables("Query_String")
call chk(url)
'从Attack_count表中获取A_count的次数,如果A_count次数不小于默认的访问次数则禁止
if chk(url) then
set rs3=server.createobject("adodb.recordset")
sql3="select A_count from attack_count "
rs3.open sql3,conn,1,3
if not rs3.eof then
if rs3("A_count")>=session("ok_count") then
 '插入攻击记录信息到attack_record表中
  t1_sql1="insert into Attack_record(ip,Attacktime,Host,Browser) value('"&attack_ip&"',now
(),'"&attack_host&"','"&attack_browser&"')"
set rsdel=conn.execute(t1_sql1)
call stopit()
ok=Jmail(session("email"),"SQL注入攻击告警!","攻击者IP地址:"& attack_ip )
else
temp_a_count=rs3("a_count")+1
'插入攻击Ip和a_count信息到Attack_count表中
t1_sql2="insert into Attack_count(ip,A_count) value('"&attack_ip&"','"&temp_a_count&"')"
set rsdel=conn.execute(t1_sql2)
end if
end if

4.2使用方法

所有代码均存入一个文件sqlinject.asp,只需要将该文件包含在需要防范的页面中即可;其中需要包含email.asp和conn.asp二个文件,前者主要通过Jmail组件来发送email邮件,后者是调用数据库连接,本模型的所采用的数据库是SQL Server 2000。

4.3实际应用效果分析

通过实际测试,当入侵者在网页提交一些非法字符达到指定次数后,系统会自动屏蔽掉该IP地址对网站的访问并将攻击IP地址、攻击时间、攻击者浏览器版本等信息写入到数据库中。当本模型存在一个缺陷:当攻击者在一个局域网时,一旦系统自动记录该地址后,其它使用该IP地址的非入侵用户也无法访问网站。本文采取的折衷办法是,在禁止的网页时留有email地址,如果发现是因为SQL入侵导致某个局域网(企业)不能访问网站,则可以通过删除数据库中禁止访问的IP地址,即可恢复正常访问。

5 .结束语

本文对SQL注入攻击的方法、原理以及攻击实施过程进行了阐述和总结,并给出了常见的一些SQL注入攻击防范方法。最后给出了一种SQL注入攻击自动防范模型,通过在实际项目中的使用,能够很好的进行主动防范,具有较高的实用价值。

上一页  1 2 3 4 5 6 

Tags:SQL 注入 攻击

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接