CVE-2020-5902——關於;號繞過認證技巧總結


1、背景

BIG IPCVE-2020-5902 漏洞的payload說一下前端認證繞過,注意這裏用到的;分號,是否是在不少認證繞過的payload裏都見過。javascript

https://[F5Host]/tmui/login.jsp/..;/tmui/locallb/workspace/tmshCmd.jsp?command=list+auth+user+admin'


2、原理解析

 1HttpServletRequestURL解析函數

   首先要了解HTTPServletRequest中對URL路徑的幾種解析方法:php

request.getRequestURL():返回全路徑;request.getRequestURI():返回除去Host(域名或IP)部分的路徑;request.getContextPath():返回工程名部分,若是工程映射爲/,則返回爲空;request.getServletPath():返回除去Host和工程名部分的路徑;request.getPathInfo():僅返回傳遞到Servlet的路徑,若是沒有傳遞額外的路徑信息,則此返回Null;

   漏洞出在,當後臺程序使用getRequestURI()getRequestURL()函數來解析用戶請求的URL時,若URL中包含了一些特殊符號,則可能會形成訪問限制繞過的安全風險,其中分號;就是其一。css


 2TomcatURL特殊字符的處理

1)分號;html

  在URL中遇到;號會將;xxx/中的分號與斜槓之間的字符串以及分號自己都去掉:前端

2)斜杆/java

  判斷是否有連續的/,存在的話則循環刪除掉多餘的/web

3./../安全

 將/./刪除掉、將/../進行跨目錄拼接處理。ruby

  總結一下,分號可用在兩種場景:微信

/;xxx/實現分割目錄/..;/實現跨目錄,經常使用在../被禁用的場景下;.css或;.js等利用白名單繞過認證鑑權


3、案例

假設Tomcat上啓動的Web目錄下存在一個info目錄,其中有一個secret.jsp文件,其中包含敏感信息:

<%@ pagecontentType="text/html;charset=UTF-8" language="java" %><html><head> <title>Secret</title></head><body>username: mi1k7ea<br>password: 123456<br>address: china<br>phone: 13666666666<br></body></html>

新建一個filter包,其中新建一個testFilter類,實現Filter接口類,實現只要訪問/urltest/info目錄下的資源,都須要進行權限判斷,不然直接放行。

注意這裏調用getRequestURI()函數來獲取請求中的URL目錄路徑,而後調用startsWith()函數判斷是不是訪問的敏感目錄:

package filter;
import javax.servlet.*;import javax.servlet.http.*;import java.io.IOException;
public class testFilter implements Filter { @Override public void init(FilterConfig filterConfig) throws ServletException {
}
@Override public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse,FilterChain filterChain) throws IOException, ServletException { HttpServletRequest httpServletRequest =(HttpServletRequest)servletRequest; HttpServletResponse httpServletResponse =(HttpServletResponse)servletResponse;
String url =httpServletRequest.getRequestURI();
if (url.startsWith("/urltest/info")) { httpServletResponse.getWriter().write("No Permission."); return; }
filterChain.doFilter(servletRequest, servletResponse); }
@Override public void destroy() {
}}

  編輯web.xml,添加testFilter設置:

<?xml version="1.0"encoding="UTF-8"?><web-appxmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaeehttp://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd" version="4.0"> <filter> <filter-name>testFilter</filter-name> <filter-class>filter.testFilter</filter-class> </filter> <filter-mapping> <filter-name>testFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping></web-app>

  運行以後,訪問http://localhost:8080/urltest/info/secret.jsp,會顯示無權限,可用的繞過方法有下面幾種:


加/繞過:http://localhost:8080//urltest/info/secret.jsp跨目錄:http://localhost:8080/urltest/anything/../info/secret.jsp 或http://localhost:8080/urltest/anything/..;/info/secret.jsp./繞過:http://localhost:8080/urltest/./info/secret.jsp;繞過:http://localhost:8080/urltest/;anything/info/secret.jsp

 

參考:

http://www.mi1k7ea.com/2020/04/01/Tomcat-URL%E8%A7%A3%E6%9E%90%E5%B7%AE%E5%BC%82%E6%80%A7%E5%8F%8A%E5%88%A9%E7%94%A8/https://mp.weixin.qq.com/s/ujfGCP25lFVRtNQOJYBYDw

本文分享自微信公衆號 - 卓文見識(zhuowenjianshi)。
若有侵權,請聯繫 support@oschina.cn 刪除。
本文參與「OSC源創計劃」,歡迎正在閱讀的你也加入,一塊兒分享。

相關文章
相關標籤/搜索