5

我们如何防止 Java 应用程序中的帧注入?

就像在渗透测试中一样,发现如果黑客起草了一个演示 html 页面,并且在该页面中他使用了 iframe,其中包含工作应用程序的 URL,他/她可以通过该 URL/请求看到数据(在 iframe 中创建)。

假设这是黑客文件 test.html:

<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"   \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head><body>
<iframe id="inner" src="http://hostname:8080/Application_Name/ABC/DEF/SomePage.jsp?ABC=QWERTYL&XYZ=1&CDE=24" width="600" height="400" scrolling="yes">

</iframe>
</body>
</html>

现在黑客能够在应用程序中检索数据。如何阻止这种情况?

4

1 回答 1

7

这是点击劫持攻击:https ://www.owasp.org/index.php/Clickjacking 防止它的最简单方法是添加带有值“DENY”的标题“X-Frame-Options”。这可以使用filter来完成。在您的 web.xml 中注册它并使用如下代码:

@Override
public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws IOException,
            ServletException {
    HttpServletResponse response = (HttpServletResponse) resp;
    response.addHeader("X-Frame-Options", "DENY");    
    chain.doFilter(req, resp);
} 

所有现代浏览器都支持此标头,但为了保护使用旧版浏览器的用户,您还需要在 UI 中使用防御性 JavaScript。更多细节:https ://www.owasp.org/index.php/Clickjacking_Defense_Cheat_Sheet

于 2015-04-24T11:35:34.803 回答