zoukankan      html  css  js  c++  java
  • 也谈 SQL 注入攻击。

    做好几点可以避免被注入:

    1. 尽可能不要再页面中或存储过程中使用拼接的方式来生成 SQL 语句
    2. 连接数据库应当使用专用的数据库用户(而不是sa)
    3. 尽可能的使用 command 的方式来查询数据库。如果给 command 增加一个参数,那么,无论参数中包含什么字符都不会截断 SQL 语句的,也就不存在注入攻击的可能了。

    但是,毕竟使用拼接方式查询数据库的使用率还是比较高的,贴一段代码:


    ''--------定义部份------------------
    Dim Fy_Post,Fy_Get,Fy_In,Fy_Inf,Fy_Xh,Fy_db,Fy_dbstr
    ''自定义需要过滤的字串,用 "|" 分隔
    Fy_In = "#|exec|insert|select|delete|update|%|chr|char|mid|master|truncate|declare|(|)|*|or|and|=|-|net user|xp_cmdshell|/add|exec%20master.dbo.xp_cmdshell|net localgroup administrators|asc|nchar|substring|abc|between|sysobjects|administrators|db_name|backup|object_id|xtype|%25|%2B|and%20|or%20|%27|net|'"
    Fy_Inf 
    = split(Fy_In,"|")



    If Request.Form<>"" Then
    For Each Fy_Post In Request.Form

        
    For Fy_Xh=0 To Ubound(Fy_Inf)

        
    If Instr(LCase(Request.Form(Fy_Post)),Fy_Inf(Fy_Xh))<>0 Then
            Response.Write 
    "非法操作!本站已经给大侠您做了如下记录↓<br>"
            Response.Write 
    "操作IP:"&Request.ServerVariables("REMOTE_ADDR")&"<br>"
            Response.Write 
    "操作时间:"&Now&"<br>"
            Response.Write 
    "操作页面:"&Request.ServerVariables("URL")&"<br>"
            Response.Write 
    "提交方式:POST<br>"
            Response.Write 
    "提交参数:"&Fy_Post&"<br>"
            Response.Write 
    "提交数据:"&Request.Form(Fy_Post)
            Response.End
    '        Response.Redirect("/")
        End If

        
    Next

    Next

    End If






    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 
    Instr(LCase(Request.QueryString(Fy_Get)),Fy_Inf(Fy_Xh)) & "<br>  " & Fy_Inf(1& " / " & LCase(Request.QueryString(Fy_Get)) & "<br><br>"
            Response.Write 
    "非法操作!本站已经给大侠您做了如下记录↓<br>"
            Response.Write 
    "操作IP:"&Request.ServerVariables("REMOTE_ADDR")&"<br>"
            Response.Write 
    "操作时间:"&Now&"<br>"
            Response.Write 
    "操作页面:"&Request.ServerVariables("URL")&"<br>"
            Response.Write 
    "提交方式:GET<br>"
            Response.Write 
    "提交参数:"&Fy_Get&"<br>"
            Response.Write 
    "提交数据:"&Request.QueryString(Fy_Get)
            Response.End
    '        Response.Redirect("/")
        End If
        
    Next
    Next

    End If

    这段代码保存成一个单独的ASP文件,在可能存在注入的页面中包含即可。

    可以起到过滤 Request.Form 和 Request.QueryString 集合的作用

  • 相关阅读:
    linux中fork()函数详解
    并发和并行有什么区别?
    利用bochs调试Linux 0.11内核
    [调整] Firemonkey iOS 原生 Edit 透明框, 改变框色
    [修正] Firemonkey Windows 控件有虚线残影问题
    [示例] Firemonkey 图片按钮(3态)
    [示例] Firemonkey 不规则按钮实做
    [函数] Delphi FMX Windows 取得下载 Downloads 目录
    [工具] Firemonkey Style 调色工具(可另存 Style 文件)
    [教学] Delphi Berlin 10.1 开发 Windows 10 平板 App 远程调试
  • 原文地址:https://www.cnblogs.com/jarod99/p/1355487.html
Copyright © 2011-2022 走看看