Java代码审计-OFCMS
source link: https://timeshu.github.io/2022/02/23/Java%E4%BB%A3%E7%A0%81%E5%AE%A1%E8%AE%A1-OFCMS/#0x06-CSRF
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Java代码审计-OFCMS
0X01 环境搭建
Gitee 下载: https://gitee.com/oufu/ofcms
导入 IEDA ,Maven 根据 pox.xml 自动下载依赖组件
创建 ofcms 空数据库
ofcms-master/ofcms-admin/src/main/resources/dev/conf/db-config.properties
改为
ofcms-master/ofcms-admin/src/main/resources/dev/conf/db.properties
Tomcat 配置
启动,安装CMS
安装成功!
0X02 SQL注入
漏洞点:ofcms-admin/src/main/java/com/ofsoft/cms/admin/controller/system/SystemGenerateController.java
47 行处,语句直接获取,未经过任何过滤
跟进 update
此处获取数据库资源连接,然后传送sql语句
pst.executeUpdate 执行了 sql 语句
而这个对象方法只允许执行 insert、update、delete及DLL。
功能点:系统设置-代码生成-增加
payload
update of_cms_ad set ad_id=(updatexml(1,concat(0x7e,(select user())),0))
0X03 目录遍历
漏洞点:ofcms-master/ofcms-admin/src/main/java/com/ofsoft/cms/admin/controller/cms/TemplateController.java
getPara 无过滤,且整段代码中也没有对 / ../ ./
做限制
46 行 获取模板路径和当前传入的路径,new 一个 File 对象, pathFile.listFiles 列出当前目录、文件
此处表明,只显示 html、xml、css、js 文件中的内容。
功能点:模板设置-模板文件=模板资源
payload
localhost:8080/ofcms_admin_war/admin/cms/template/getTemplates.html?dir=../../../../../../../../../
0X04 文件上传
漏洞原理同上,由于未对文件后缀名进行过滤及校验目录,导致可通过写入文件方式上传 jsp 目录文件,并保存至网站任意目录下。
漏洞点:ofcms-master/ofcms-admin/src/main/java/com/ofsoft/cms/admin/controller/cms/TemplateController.java
SystemUtile.getSiteTemplatePath() 获取当前目录
dirName 目录名,此处因未做过滤,可以穿越到其他目录
fileName 文件名,也是没有做过滤,所以可直接修改文件名为 jsp 或 jspx
fileContent 将内容中的<>实体化。。。
此处写入文件内容,并保存到我们指定的位置。
漏洞原理,就是没有经过过滤。
功能点:模板设置-模板资源
0X05 SSTI 模板注入
挖坑先,具体原理没咋研究过,但是可插入特殊的语句,模板解析可执行命令
payload
<#assign ex="freemarker.template.utility.Execute"?new()>
${ ex("ifconfig") }
0x06 CSRF
前端 ofcms-admin/src/main/webapp/WEB-INF/page/admin/cms/template/index.html 代码中,未发现 CSRF-Token,存在漏洞
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK