【问题标题】:how to prevent null byte injection from querystring如何防止从查询字符串注入空字节
【发布时间】:2016-11-02 20:07:47
【问题描述】:

Nessus 漏洞扫描程序是针对旧代码网站运行的。关于如何使用 PHP 防止 空字节注入 攻击有很多建议,但我找不到任何关于在经典 ASP 中使用 VBScript 解决此问题的任何信息。

这是扫描仪对我们公共网站的攻击:

http://www.mortgagedataweb.com/mds/marketshare/ParmsV2.asp?Menu=%00<"kzwezl%20>

我尝试向QueryString 输入添加有效性检查,但我的努力没有奏效。关于%00 的某些事情会掩盖我检查正确值的尝试。下面是一些相关的代码sn-ps:

Function getUserInput(input)    
    Dim newString
    If Len(input) = 0 Then
        getUserInput = ""
        Exit Function
    End If
    newString = input        'this was omitted in original post but was in fact in the code
    newString = Replace(newString, Chr(0), "")  'I thought this would fix it !  
    newString = Replace(newString, "--", "")
    newString = Replace(newString, ";", "")          
    newString = Replace(newString, Chr(34),"'") 
    newString = Replace(newString, "'", "") 
    newString = Replace(newString, "=", "=") 
    newString = Replace(newString, "(", "[") 
    newString = Replace(newString, ")", "]")
    newString = Replace(newString, "'", "''")
    newString = Replace(newString, "<", "[")
    newString = Replace(newString, ">", "]")  
    newString = Replace(newString, "/*", "/") 
    newString = Replace(newString, "*/", "/")
    getUserInput = newString
End Function

implied_Menu = UCase(getUserInput(Request.QueryString("Menu")))  'store Menu value for Fast-Path link
Select Case implied_Menu
    Case "FHA_ZP", "C_ZP", "J_ZP", "F_ZP"
        implied_SQLName = MARKETSHAREZip
    Case "P_ALL", "P_MA", "P_ST", "P_ZP", "P_CT", "P_NATION"
        implied_SQLName = PMIMARKETSHARE
    Case "FHA_ALL_D", "FHA_MA_D", "FHA_ST_D", "FHA_CT_D", "FHA_ZP_D", "FHA_NATION_D"
        implied_SQLName = FHAMARKETSHAREDETAILS
    Case ""
        implied_SQLName = MARKETSHARE
    Case Else
        Response.Write("<h2>Invalid Menu parameter</h2>")
        Response.End
End Select

正确的菜单值是:

  • 完全缺失(即Menu=不在QueryString中)
  • 上述Select Case 逻辑中勾勒的一系列有效值的一部分

在我的开发机器上,我可以将%00 更改为%0 并用Response.Write 消息然后Response.End 标记错误,但是关于%00 的某些内容通过了我的检查尝试。

【问题讨论】:

  • 在替换之前您没有为newString 赋值。
  • 就像@Kul-Tigin 说的那样,在您开始在newString 上调用Replace() 之前,您需要将input 分配给newString,否则您什么都不会被替换。
  • 我在将代码粘贴到原始帖子时出错了。将输入值分配给 newString 实际上是在代码中,但未能将其正确放入原始帖子中。问题依然存在。

标签: security vbscript asp-classic code-injection nessus


【解决方案1】:

我建议用正则表达式来处理这个问题:

function getUserInput(sInput)
    Dim obj_regex
    Set obj_regex = New RegExp

    obj_regex.IgnoreCase = true
    obj_regex.Global = true
    obj_regex.Pattern = "\W"

    getUserInput = obj_regex.Replace(sInput, "")
    set obj_regex = Nothing
end function

由于您的所有菜单条目都只有字母数字字符和下划线,因此您可以替换所有其他字符。

【讨论】:

  • 感谢代码解决方案和清晰的解释!
猜你喜欢
  • 2012-04-28
  • 2011-09-26
  • 2015-04-02
  • 1970-01-01
  • 2011-12-24
  • 2011-06-02
  • 2010-12-21
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多