问答
发起
提问
文章
攻防
活动
Toggle navigation
首页
(current)
问答
商城
实战攻防技术
漏洞分析与复现
NEW
活动
摸鱼办
搜索
登录
注册
代码审计-从0到1通读源码
漏洞分析
## 0x00前言: 本文使用wodecms 代码下载链接:http://zjdx.down.chinaz.com/201709/wodecms_v1.1.zip 我们在审计之前,要摸清楚整套源码的结构,例如mvc的走势,函数等,而且还要对漏洞熟悉,...
0x00前言: ------- 本文使用wodecms 代码下载链接:[http://zjdx.down.chinaz.com/201709/wodecms\_v1.1.zip](http://zjdx.down.chinaz.com/201709/wodecms_v1.1.zip) 我们在审计之前,要摸清楚整套源码的结构,例如mvc的走势,函数等,而且还要对漏洞熟悉,这样才可以快速定位到敏感点。 0x01 通读MVC: ----------- 先从index.php入手 [](https://shs3.b.qianxin.com/attack_forum/2021/07/attach-9e63c988275e4af72edecd1e67a88803b3c38e21.png) 在通读MVC时,先了解一部分define定义的常量,这些常量对我们后面审计能否读通有一定影响。 在33,34行里,require包含了2个文件,而通过上面的单行注释说明知道,下面2条是该cms的MVC入口文件 而ROOT\_PATH常量通过上面16行define定义可知道为根目录 [](https://shs3.b.qianxin.com/attack_forum/2021/07/attach-3cf2a7752e00fe84351b6fbf7f4b17cd330b7384.png) 而APP\_PATH常量通过上面25-28行得知传参g不为空时,APP\_PATH常量为app。 [](https://shs3.b.qianxin.com/attack_forum/2021/07/attach-396212bb82d70bcc6718fa9b3dd38d1680727cc0.png) 所以require包含了2个文件的目录分别是 根目录/WODECMS/Init.php和app/setup.php 进入到Init.php文件 [](https://shs3.b.qianxin.com/attack_forum/2021/07/attach-d1f8fea6b32c3575df00c741ac860a2cf08e8907.png) 看见通过require的方式包含了5个文件,但是,通过注释说明,我们先去摸清mvc的走势,先进入到下面2个文件 进入到model.class.php文件,发现只是定义了一些方法而已 [](https://shs3.b.qianxin.com/attack_forum/2021/07/attach-b9ae6d61e5f0aec061d798d176c2b490e161874c.png) 接着进入controller.class.php文件 拉到122-149行, Run定义方法中,可以看到136行有一个通过include的包含的变量 [](https://shs3.b.qianxin.com/attack_forum/2021/07/attach-b5c39ced27844db0f5ea099d89f0fd4d068bf0c7.png) 而$controlFile变量实际构造的内容是根目录/app/controller/$this->control(可控制变量).class.php#GROUP\_DIR常量定义在index.php文件31行 [](https://shs3.b.qianxin.com/attack_forum/2021/07/attach-2652a11a47a074e41c356462a77aa6397e26e771.png) 然后在145-147行中, $instance=new $this->control()的意思是实例化上面包含文件的那个类 $methodName = $this->action;的意思是$this->action的内容赋值给$methodName变量 $instance->$methodName ();的意思是引用该类中的方法 [](https://shs3.b.qianxin.com/attack_forum/2021/07/attach-44cfb770b2301e674382e6f618efe0c2a34205f6.png) 回到123-125行中,$this->control和$this->action分别由传参a和c赋值,而$this指向了Analysis方法 [](https://shs3.b.qianxin.com/attack_forum/2021/07/attach-e35c296559f58199ccd2f5da58fa3da3be3a5a9b.png) 来到定义Analysis方法中,看到$acStr有GET传参ac赋值,然后$acStr通过explode函数分解成数组赋值给$acAry变量,$acAry进行判断数目为2时,变量里的数组1赋值给$modelClass,0则赋值给$controlClass 最后,在174和175行中,分别赋值给$this->control和$this->action [](https://shs3.b.qianxin.com/attack_forum/2021/07/attach-f37176bff3f5db172d03e65cac7f4fd4ab58b763.png) 所以,通过上面的审计,我们脑袋里面应该有个框架整体思维 1. 网址/?ac=控制器\_方法名 2. 网址/?a=方法名&c=控制器 0x02全局的过滤和防护 ------------ 继续读取controller.class.php文件,在checkHaveRight定义方法中,对用户权限进行了鉴权,当控制器指向admin的时候,就会进行鉴权 [](https://shs3.b.qianxin.com/attack_forum/2021/07/attach-fadc6ce4335368b25d0d7b79ee6615fdcd7918c0.png) 而checkHaveRight在Analysis方法中被调用 [](https://shs3.b.qianxin.com/attack_forum/2021/07/attach-ca13dadda888730d0ec72c597976a1121bf4a4c6.png) 回到Inte.php文件中,审计配置文件,33行那个没啥好看的,就31和32有用 [](https://shs3.b.qianxin.com/attack_forum/2021/07/attach-a8e4ff222a2912f5b26a38267e3a13716720d9a3.png) 其中b ase.inc.php文件中,对全局变量进行了一个防止宽字节注入的过滤 [](https://shs3.b.qianxin.com/attack_forum/2021/07/attach-cdc742135b2713b65417d594ae4a8c19d19d2a50.png) 而stripslashes\_array函数在core.func.php文件中197-205行被定义 [](https://shs3.b.qianxin.com/attack_forum/2021/07/attach-f57f743cd6a337a0d1d531203bf247bdf13436c4.png) 大概内容就是检测到传参有\\号时,通过stripslashes函数进行去除。 继续读取core.func.php文件,在370-372行中,又对全局变量进行了过滤 [](https://shs3.b.qianxin.com/attack_forum/2021/07/attach-eb1f7ee7acb2dbddf797f5b1f662a818af5753ba.png) SafeFilterPost和SafeFilterGet函数定义的内容是一样的 所以直接看SafeFilterGet函数的内容,从中可以得知'号会被转为%27 [](https://shs3.b.qianxin.com/attack_forum/2021/07/attach-1dc73787c908f83757603a325b1f4a6f680fa389.png) 0x03通过seay审计工具,对控制器进行漏洞审计 ------------------------- 通对上面mvc的审计,知道了控制器的位置在/app/controller/中,直接丢进seay审计系统进行审计 #### 1.前台任意文件删除漏洞(可重装整站) 在控制器文件中,发现了一个editor的文件,而seay又扫到他有一个变量在unl ink()函数中 [](https://shs3.b.qianxin.com/attack_forum/2021/07/attach-beca5b06cbb1932029e920b1b861db7e2195a83a.png) 点进去 [](https://shs3.b.qianxin.com/attack_forum/2021/07/attach-6152613128554c36e3bf0fc05e8280b986eb943e.png) 可以看到无任何过滤 所以payload:/index.php?ac=kindeditor\_delete&pic=要删除的文件 #### 2.前台sql注入漏洞 通过seay扫描,扫描到该文件存在数字型注入 [](https://shs3.b.qianxin.com/attack_forum/2021/07/attach-689e46a9f606f7bfac25a0049a10e15e5422f489.png) 传参aid没有单引号括住,所以不需要插入单引号,就可以注入,而且通过上面对mvc的防护进行审计知道,输入单引号会被转为%27 Payload:/index.php?ac=picture\_collect&uid\[\]&aid=sql注入语句
发表于 2021-07-24 14:25:22
阅读 ( 8826 )
分类:
代码审计
3 推荐
收藏
0 条评论
请先
登录
后评论
修仙者
2 篇文章
×
发送私信
请先
登录
后发送私信
×
举报此文章
垃圾广告信息:
广告、推广、测试等内容
违规内容:
色情、暴力、血腥、敏感信息等内容
不友善内容:
人身攻击、挑衅辱骂、恶意行为
其他原因:
请补充说明
举报原因:
×
如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!