问答
发起
提问
文章
攻防
活动
Toggle navigation
首页
(current)
问答
商城
实战攻防技术
漏洞分析与复现
NEW
活动
摸鱼办
搜索
登录
注册
小白第一次审计
渗透测试
## 前言 刚开始学审计 也是看了社区们师傅的文章https://forum.butian.net/share/387 可能是自己太菜了 感觉不太详细 就自己审了一下 ## 漏洞分析 先打开cms 简单浏览一下 [](https://shs3.b.qianxin.com/attack_forum/2021/08/attach-c6224c5fab0bc48515dbd42cb9d0f12a626521cc.png) > 看起来视乎是个商城一样的网站 不管随便点点 然后来到代码 ### 第一处 然后看到index.php文件,发现里面用include\_once 包含了3个文件 > include\_once() 语句是指在脚本执行期间包含并运行指定文件。 > 此行为和 include() 语句类似,唯一区别是如果该文件中的代码已经被包含了,则不会再次包含。如同此语句名字暗示的那样,只会包含一次 [](https://shs3.b.qianxin.com/attack_forum/2021/08/attach-e61edfa7b86a496c6aa40fbd84a4dd7214f5ffa7.png) **然后打开web\_inc.php 看看这个文件里面有什么** [](https://shs3.b.qianxin.com/attack_forum/2021/08/attach-6c5488de3fac6644d0e14cf2f269f4968171f399.png) 这个文件开始是一个ob\_start() 函数 因为第一次审 所以不懂什么意思 百度了一下发现是打开缓冲区 但这里暂时不管它 这个文件里面也用到了include\_once 函数包含了2个文件 但暂时都不管 继续往下看 在53行的时候发现了一串代码 [](https://shs3.b.qianxin.com/attack_forum/2021/08/attach-3af3395a852963c25b612cea271375bd1ae82f53.png) > $web\_urls接收了$\_SERVER\["REQUEST\_URI"\]值然后通过explode函数分割后传入web\_language\_ml函数中 > $\_SERVER\["REQUEST\_URI"\]函数是返回当前的url路径 我们通过 > var\_dump来查看返回值 [](https://shs3.b.qianxin.com/attack_forum/2021/08/attach-4928eb031a60b3ba084b5f61820074e80f003f38.png) 保存之后来到index.php文件下查看 [](https://shs3.b.qianxin.com/attack_forum/2021/08/attach-5912ab932a3e3e94c02e7c0c42834fb8455a9f47.png) explode(separator,string,limit)函数是把获取到的url路径通过 / 分割为数组,第一个参数是根据什么进行分割,第二个参数是需要分割的字符串 [](https://shs3.b.qianxin.com/attack_forum/2021/08/attach-2a9c65a945f56c5afd5c57aab0a2fdcc8b353720.png) 然后看下面的web\_language\_ml函数 通过将$web\_urls中的\[1\][2](%E5%9B%A0%E4%B8%BA%E8%BF%99%E4%B8%AA%E6%97%B6%E5%80%99web_urls%E4%BB%A5%E5%8F%8A%E8%A2%AB%E5%88%86%E5%89%B2%E4%B8%BA%E6%95%B0%E7%BB%84%E4%BA%86) 传到了函数中 以及$db-conn $db-conn则是最开是include\_once 包含进来的数据库连接对象 [](https://shs3.b.qianxin.com/attack_forum/2021/08/attach-aaab8e1ec730ac402941c766db7a003a450037ee.png) [](https://shs3.b.qianxin.com/attack_forum/2021/08/attach-3af0a8722b2c5146ef43f046228d6218497a470a.png) 继续跟进web\_language\_ml函数 [](https://shs3.b.qianxin.com/attack_forum/2021/08/attach-79395d5a476d27265b8590ecef67f54f6638018f.png) 发现该函数没有任何的过滤操作 直接就把传过来的值 进行了数据库查询操作 很明显存在sql注入 根据代码发现是单引号闭合 直接注就行了 [](https://shs3.b.qianxin.com/attack_forum/2021/08/attach-cdb2e4e822f0ad5e85c9bc7fcbd446ca98f92eb6.png) 这个洞有个前提 就是文件必须解压在根目录下才行 如果套了一层目录的话 就不能成功 [](https://shs3.b.qianxin.com/attack_forum/2021/08/attach-8a6a4fb8d1b687fa0e19427662795374f7fc8c7b.png) 因为分割后的数组内容就变了 添加其他的内容就没用了 ### 第二处 后面发现在后台登录的时候会经过SEMCMS\_Top\_include.php 判断 然后跟进文件 [](https://shs3.b.qianxin.com/attack_forum/2021/08/attach-a7ddb3e8b7125d4e3c8a1f4c1f5cac635a9dc99e.png) [](https://shs3.b.qianxin.com/attack_forum/2021/08/attach-36d442c4c09b6291e02006645ff08541a6c2aa60.png) 发现有一个checkuser函数 从函数的命名上就可以看出 肯定和登录相关 然后跟进checkuser()函数 [](https://shs3.b.qianxin.com/attack_forum/2021/08/attach-7014bce099971fed82f5eb1b08d20edd75e243d4.png) 发现是通过cookie传值的方法 然后进行数据库查询 判断用户是否登录 这里还有两个函数test\_input(),和verify\_str()函数 不知道这两函数的作用 大概猜测是过滤 然后跟进函数 [](https://shs3.b.qianxin.com/attack_forum/2021/08/attach-47b9698466544caf4f386f2e81cc23587292506a.png) Test\_input函数接收数据,然后通过str\_replace函数将结束数据中的% 替换为percent 然后通过trim函数去掉首位的空格,stripslashes函数删去数据中的反斜杠(只去掉一个反斜杠),htmlspecialchars() 函数把双引号和单引号转为 HTML 实体。 然后返回过滤之后的数据 跟进verify\_str函数 [](https://shs3.b.qianxin.com/attack_forum/2021/08/attach-e7212287172c905ff5d96f898551ac3e42dbc6e0.png) verify\_str()函数接受参数然后利用if判断 将参数传给inject\_check\_sql函数 继续跟进inject\_check\_sql函数 [](https://shs3.b.qianxin.com/attack_forum/2021/08/attach-9d76ea5dd6ad66af9b99c7ddf0f0f4f2abdc7d1a.png) inject\_check\_sql函数接受参数 然后通过 正则匹配 ,返回 pattern 的匹配次数。 它的值将是 0 次(不匹配)或 1 次, 如果匹配到了就会返回1就会进去前面的if判断 执行报错 所以还是过滤了很多相关的关键词 这里没有规定大小写 所以可以用大小写绕过 然后尝试绕过payload: > scuseradmin:aaa\\ > scuserpass:or 1# 然后放到sql执行的语句就是 [](https://shs3.b.qianxin.com/attack_forum/2021/08/attach-3fc59e36a98618eea2f5515d7b2c8038f60715c7.png) [](https://shs3.b.qianxin.com/attack_forum/2021/08/attach-bd27cb3403e73d1ca2fec02ffa5d34383770d872.png) 能查出数据 所以函数执行返回的行数是大于0的,所以就会进去if判断 [](https://shs3.b.qianxin.com/attack_forum/2021/08/attach-3bcfd17d72fdfc2b8ecd0c84234ae9cd3ce39608.png) 然后利用mysqli\_fetch\_assoc函数接收结果 并把user\_qx返回 然后验证 但是发现了bug 不知道是本地环境还是怎么回事 就是进不去页面 但是没报错 [](https://shs3.b.qianxin.com/attack_forum/2021/08/attach-4995cb40b93a9665578c99d7f3cca5ce5265b102.png) 然后我换成延时试试 [](https://shs3.b.qianxin.com/attack_forum/2021/08/attach-483701640a0997cba7d51b1d700b02843ee51b90.png) 延时sql是成功执行的 上面第一次没进去 就很奇怪 讲道理这里应该是能绕过登录直接进去才对 我就是进不去 ### 第三处: 在web\_inc.php的91行发现了一个sql查询语句 发现了一个language参数 是传过来的 跟进看看 怎么来的 [](https://shs3.b.qianxin.com/attack_forum/2021/08/attach-5cec8ad13ae04e30668c7b32099ff0686f2e4300.png) [](https://shs3.b.qianxin.com/attack_forum/2021/08/attach-067a192656521ce028fa52921c59ff5e26fb6aee.png) 前面太多花里胡哨的 就先不看 直接看if if里面的意思是 如果存在post的传参languageID的话 就进去if判断 然后进行过滤返回 过滤函数和前面一样 那就看前面就好了 然后写上echo 进行调试看看 因为很多页面都引用了web\_inc.php这个文件 就不一一查找了 直接先访问首页看看 好家伙 直接打印了 [](https://shs3.b.qianxin.com/attack_forum/2021/08/attach-d0ec481c56ef5415699698578b3365b85269a033.png) 好 接下来试试post 用bp抓包 这里有个小问题 因为搭建在本地的 如果url是127.0.0.1会抓不到包 我的解决方式是把127.0.0.1 换成ipv4的值 然后就可以抓包了 然后来到主页 刷新抓包 然后用bp改包 [](https://shs3.b.qianxin.com/attack_forum/2021/08/attach-e0f10bed6fd2a1fe6d2bb0e5b068d75cd0ffc36a.png) 点击就改成post包,然后在下面加上languageID 然后放包 [](https://shs3.b.qianxin.com/attack_forum/2021/08/attach-f24fa3c3ba3c1f22af8dd58f8f1131a2973a8b7b.png) 开始注入 [](https://shs3.b.qianxin.com/attack_forum/2021/08/attach-ce3c282d701c9b29a30954cb8eccf0282a0fe53f.png) 成功延时 继续看其他的 ### 第四处 在SEMCMS\_Banner.php发现了sql语句 在SEMCMS\_Banner.php的74行 这行sql语句没用任何参数过滤 [](https://shs3.b.qianxin.com/attack_forum/2021/08/attach-3756fdbb1766272f96e782e22dd5235ae56abe8b.png) 然后上面的代码逻辑是判断type [](https://shs3.b.qianxin.com/attack_forum/2021/08/attach-2a1dfbd7ce21619f1f29a7774ba0a75b31395481.png) 先判断add和edit 然后才else进到下面 [](https://shs3.b.qianxin.com/attack_forum/2021/08/attach-2627cadd6c94d7abb66d592672e7c56e96d23b42.png) 因为这里没看见上面过滤 就直接构造payload: > /SEMCMS\_PHP\_3.9/vyT4nP\_Admin/SEMCMS\_Banner.php?lgid=1+and+sleep(5)# [](https://shs3.b.qianxin.com/attack_forum/2021/08/attach-9859f5601be2926cb0d2242ff366bb3ad0691e17.png) 延时成功 但是在尝试select的时候却出现了问题 [](https://shs3.b.qianxin.com/attack_forum/2021/08/attach-b453bbb41e326b9e994925944babe6278427e819.png) 直接报错了 这个报错信息是前面解释过的过滤函数中的一个 但是这里没有看见使用该函数进行过滤呀 这里有点懵 这个文件虽然包含了 [](https://shs3.b.qianxin.com/attack_forum/2021/08/attach-898b07b82d82cb9b3c97fa54125aee553cc4f6f9.png) 这个php文件是用来判断是否登录的 因为前面发现可以通过sql 绕过登录 使用banner.php也是直接进来了 但是过滤我真没找到 应该是我太菜了 毕竟都报错了 那就只能通过大小写登方式来绕过过滤 但是当我尝试的时候 发现不行 windows不区分大小写 难道是因为这样嘛 有点小懵 看来还是只能通过其他的方式注入 用其他的替换过滤掉的关键词 这处注入是简历在第二处注入绕过登录的前提下 因为这个页面相当于是后台的页面 ### 第五处: 其实这处也不算啥 登录出可以爆破 因为没有验证码的限制 可以直接跑字典 直接来到后台页面 [](https://shs3.b.qianxin.com/attack_forum/2021/08/attach-440b2a75948cca507630a1d0dd61bdbe2772ea4b.png) 然后抓到包直接丢爆破模块里面 [](https://shs3.b.qianxin.com/attack_forum/2021/08/attach-8e5de8635df2ee0e9e27ce2c13cd87f2306321e7.png) 就可以开始爆破了 [](https://shs3.b.qianxin.com/attack_forum/2021/08/attach-f1b52ac06218658a252a17c6a4075b417e19f0af.png) ### 最后 小白第一次审计 还有很多不会 也看了很多文章 查了很多函数 师傅们轻点喷 有什么不足的地方提个建议 我学习学习 这cms还在看 感觉应该还有洞 虽然没能找到直接拿shell的洞 通过这些 也学到了不少审计的思路
发表于 2021-08-31 16:40:48
阅读 ( 6481 )
分类:
代码审计
1 推荐
收藏
1 条评论
uyhacked
2021-08-31 16:59
师傅太强了
请先
登录
后评论
请先
登录
后评论
永安寺
8 篇文章
×
发送私信
请先
登录
后发送私信
×
举报此文章
垃圾广告信息:
广告、推广、测试等内容
违规内容:
色情、暴力、血腥、敏感信息等内容
不友善内容:
人身攻击、挑衅辱骂、恶意行为
其他原因:
请补充说明
举报原因:
×
如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!