我正在追逐我网站上报告的漏洞,该漏洞主要是使用VBscript编写的经典ASP。我认为我所做的修复应该已经足够,但“重新扫描”仍然显示端口80 / tcp上的“中等风险”项目:
51972 - CGI Generic Cross-Site Scripting (Parameters Names)
以下是此报告项目的摘录:
-------- request --------
GET /stagedmds/marketshare/ParmsV2.asp?<<<<<<<<<<foo"bar'314>>>>>=1 HTTP/1.1
Host: www.mortgagedataweb.com
Accept-Charset: iso-8859-1,utf-8;q=0.9,*;q=0.1
Accept-Language: en
Connection: Close
Cookie: ASPSESSIONIDSQQQBDTB=MCJAMHCACGEHCNCCGDDPOEAI; ASPSESSIONIDQSSQDCTB=JAFAABIAONBOMMAMJILMMLGL; ASPSESSIONIDQSQQBDTB=IBJAMHCAIGIGCEKMBNPOMCPN
User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0)
Pragma: no-cache
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, image/png, */*
------------------------
-------- output --------
<button type="button" onclick=
"location.href='/stagedmds/marketshare/ParmsV2.asp?<<<<<<<<<<foo"bar'314
>>>>>=1&Doc=Y';"
ONMOUSEOVER="this.className = 'over';"
ONMOUSEOUT="this.className = '';"
------------------------
/stagedmds/marketshare/ParmsV2.ASP?<<<<<<<<<<foo"bar'314>>>>>=1
当我查看服务器端脚本的这一页时,我注意到我的参数检索没有按照以下方式“清理”输入:
implied_Menu = UCase(Request.QueryString("Menu"))
所以,我改变了如下:
implied_Menu = getUserInput(UCase(Request.QueryString("Menu")))
其中新添加的函数应该“清理”parm值,如下所示:
Function getUserInput(input)
dim newString
newString=input
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的变量永远不会以任何方式输出到页面。它仅使用某些案例逻辑进行评估,以设置其他变量,如下例所示:
Select Case implied_Menu
Case "C_ST"
implied_PromptType = ByCounty
implied_DataSubset = iConventional
implied_ReportName = Conventional
我看不出还有什么要做的。我已阅读Protect from cross-site scripting attacks?,其中一些漏洞扫描程序无法识别我所采取的措施。
当扫描程序看到从查询字符串中检索时,是否有可能始终报告XSS违规?
答案 0 :(得分:1)
在我看来,当您的代码生成此按钮时,问题是如何为location.href生成值:
<button type="button" onclick=
"location.href='/stagedmds/marketshare/ParmsV2.asp?<<<<<<<<<<foo"bar'314
>>>>>=1&Doc=Y';"
ONMOUSEOVER="this.className = 'over';"
ONMOUSEOUT="this.className = '';"
我猜您使用ServerVariable或Request.QueryString生成URL。您需要更改它,以便它只包含您允许的参数。
如果你发布这段代码,可能会有所帮助。
答案 1 :(得分:0)
@John's answer现场点亮 - 这是由于按钮onclick
中使用的文字造成的。
查看OWASP XSS (Cross Site Scripting) Prevention Cheat Sheet以获取有关如何防止XSS的提示。
RULE #3 - JavaScript Escape Before Inserting Untrusted Data into JavaScript Data Values适用于此处: -
除了字母数字字符外,使用\ xHH格式转义所有小于256的字符,以防止将数据值切换到脚本上下文或其他属性中。
所以在这种情况下你的价值
/stagedmds/marketshare/ParmsV2.asp?<<<<<<<<<<foo"bar'314>>>>>=1&Doc=Y
应编码为
\x2fstagedmds\x2fmarketshare\x2fParmsV2\x2easp\x3f\x3c\x3c\x3c\x3c\x3c\x3c\x3c\x3c\x3c\x3cfoo\x22bar\x27314\x3e\x3e\x3e\x3e\x3e\x3d1\x26Doc\x3dY