2

渗透测试团队告诉我,以下 URL 导致 XSS 攻击 -

https://some-site.com/test/jsp/download_msg.jsp?&report_id=0&id=1369413198709cUjxb8IRCtTJcbYBHb0Qiph&id=1369413198709cUj

这是我的 download_msg.jsp 代码

        <% String download_msg = null;
           if (session == null || session.getAttribute("user") == null) {
               download_msg = "Error message";
           } else {
               download_msg =
              (OLSUser)session.getAttribute("user")).getReportInfo().getDownloadMsg();
           } 
        %>

       <html>
        <head>
         <SCRIPT LANGUAGE='JavaScript' SRC='/Test/test.js'></SCRIPT>
           <SCRIPT LANGUAGE='JavaScript'>init('StmsReps');</SCRIPT>
             <script language="JavaScript">
            function redirect() {
             if (window.focus)
            self.focus();
         this.location = "/test/DownloadReport?<%=request.getQueryString()%>";
    }
        </script>
     <title>XSS</title>
     </head>
      <body marginwidth='0' marginheight='0' onload='javascript:redirect()'>
         <table width='90%' height='100%' align='center' border='0' cellspacing='0'
            cellpadding='0'>               
      <tr>
    <td align='center' class='header2'> <%= download_msg %></td>
   </tr>
   </table>
   </body>
   </html>

我发现jstl可以处理XSS攻击。您能否建议如果执行以下操作会很好还是我需要做其他事情?

         <c:out value="<%= download_msg %>" escapeXml="true"/>
4

1 回答 1

1

不,这还不够

this.location = "/test/DownloadReport?<%=request.getQueryString()%>";

攻击者可能能够发送带有查询字符串的链接,例如

?</script><script>alert(1337)//

或者

?%22/alert('Pwned')

对于可能会单击链接并执行嵌入代码的天真的用户。

您必须在将不受信任的输入插入到模板中的任何地方应用适当的转义策略。


我显然无法针对您的设置测试这些字符串,如果您使用它们进行测试,它们可能无法正常工作,因为浏览器经常对查询字符串进行一些规范化,但您不应该依赖它来保护您免受查询中的 HTML 元字符的影响字符串。

于 2013-05-24T21:11:41.043 回答