问答
发起
提问
文章
攻防
活动
Toggle navigation
首页
(current)
问答
商城
实战攻防技术
漏洞分析与复现
NEW
活动
摸鱼办
搜索
登录
注册
记一次小程序cms安全事件应急响应
漏洞分析
2021年11月16日,上级发来不良检测记录,内容包含为某站点存在涉赌违规内容,该站点为基于ThinkPHP 5.0.10框架的小程序管理系统。
**记一次小程序cms安全事件应急响应** 1、安全事件发生 2021年11月16日,上级发来不良检测记录,内容包含为某站点存在涉赌违规内容,该站点为基于ThinkPHP 5.0.10框架的小程序管理系统,下面以xcx.test.cn作为代替  经过对比原始版本的源码,以及命令ls -alh确认,index.php于11月15日23:16分出现文件修改,确认该web服务器遭到非法攻击。  后果:修改内容为在head内添加了meta标签和修改了title标签,标签内容为非法内容,搜索引擎的爬虫在爬取该站点时会爬取meta标签的内容,那么用户在百度搜索关键词时,会检索出不良内容。  2、安全事件溯源 2.1 暂停服务 首先进入宝塔关闭Apache与MySQL服务,其他途径告知用户系统正在维护  2.2 保存现场环境 进入到宝塔的网站管理界面,点击被入侵站点,点击备份站点(数据库同理备份)。 因为备份文件过大,则把全部备份通过宝塔的“腾讯云COSFS 2.0”插件,转储到cos里,在通过访问cos下载备份文件。   2.3 提取WEB日志 ssh连接进入服务器,提取宝塔的web日志,路径/www/wwwlogs/xcx.test.cn/ ,提取xcx.test.cn-access\_log与xcx.test.cn-error\_log到本地  2.4 find命令检索被文件修改 使用find . -mtime -300 -name "\*.php"检索/www/wwwroot/xcx.test.cn/网站目录下被修改过的PHP文件,以快速确认webshell落地路径  从图中可以发现,在十一月份分别不同天数,有三个文件被添加或修改过,对比原始源码发现,除了index.php原本不存在图中另外两个文件。 2.5 分析webshell文件1 路径:/public/plugin/PHPExcel/PHPExcel/CalcEngine/index.php  分析该文件,总共分为两个部分 s函数:对$dapeng的字符串进行rot13解码 m函数与get1\_str函数:该函数作用是eval执行PHP代码,通过组合变量$dp和$dapeng1成新的系统函数,把rot13解码的字符串,从十六进制转换为字符串文本(既为PHP代码)。 PS:该图为十六进制转码后的PHP代码  从图中可以得知,这里的变量file\_path是上一层的index.php的$file\_path,此处先备份网站首页index.php另存为index.bk.html,并把index.php的权限修改为0666,既所有用户可读可写权限,猜测此处目的防止因为权限原因无法修改首页。 2.6 分析webshell文件2 路径./public/webuploader/server/preview/dd887179e09b2326595305d8dd475763.php  分析该文件,可以得知是一个PHP远程文件包含+eval执行 Ps:该文件在后面日志分析得出,该文件为黑客第一个上传的木马。 从该路径/public/webuploader/server/preview/可猜测,黑客应该是使用webuploader下的fileupload.php或fileupload2.php或presiew.php里其中的一个php文件的上传漏洞,把webshell上传到服务器  2.7 分析access日志之攻击手法 从access日志来看,该web站点一直由来自不同地区,不同国家的IP地址用web漏洞扫描器一直进行扫描   由于刚刚提到webshell文件2的路径在webuploader/server下,而该文件夹下恰好有三个相关的上传文件,我们分别在access\_log中搜寻fileupload.php或fileupload2.php或presiew.php 结果均为无结果:    我们猜测,黑客在使用presiew.php的原文件名应该为preview.php,通过对比1月份的备份包与本月的备份包,其中得出1月份的preview.php与presiew.php的文件内容完全一致,可以确认是被黑客修改了名称,preview.php内是有关文件上传的PHP代码。  那么回到vscode继续检索preview.php得到结果  结果还是比较多,在精确搜索一下,只显示有200回响的  成功筛选出4条记录,分别是     其中第1与第2条IP地址均为浙江省金华市婺城区 电信  第3条与第4条IP地址均为深圳市腾讯云  然后对比user-agent,第1、2条为  第3、4条为  请注意上述两条USER-AGENT都是非常旧的系统和浏览器版本,理应不符合该系统的对象用户,可初步判别均为异常流量。 通过相同UA头检索,发现UA为”Mac OS X 10\_15\_7”的主机,正在不断的从2021年6月21号到2021年11月16日,一直使用爬虫/web扫描工具进行扫描测试。  可以看出图中的相关日志,该UA都在同一天访问有关sql数据库的管理页,通过检索可知,有关“Mac OS X 10”的UA有6838条,可以判断是爬虫工具。 继续检索UA头为"Mozilla/5.0 (Windows NT 6.1; rv:25.0) Gecko/20100101 Firefox/2X.0"的相关行日志共两条,请注意下面两条日志的时间与webshell木马的dd887179e09b2326595305d8dd475763.php时间。    从上图中可以看出,第二条日志的时间与webshell的修改时间完全重合,且同时说明在11月1日该站点已经被渗透, 跟随这个UA继续检索日志,又发现访问了另外一个木马CalcEngine/index.php  故判断UA为“Mozilla/5.0 (Windows NT 6.1; rv:25.0) Gecko/20100101 Firefox/2X.0”就是黑客攻击我企站点的UA。 在这一些不同行的日志里,除了IP归属地为浙江省金华市婺城区 电信外,其他的IP归属地均为国外,所以金华市的这个IP很有可能是黑客的真实IP地址。 总结:黑客使用preview.php分时段上传了木马dd475763.php与CalcEngine/index.php,然后在11月15日23点16分通过dd475763.php修改了public/index.php 2.8 分析access日志之留种后门分析 根据来源地址为dd88719e.php,查找referer: <https://xcx.test.cn/webuploader/server/preview/dd887179e09b2326595305d8dd475763.php> 查找出以下几个后门  (1)111.php  (2)banner3.php(经典大马)   (3)picture3\_6.php(此处与preview.php文件内容一致)   (4)config.php(WebShell)   通过$\_REQUEST\[admin\]传参到eval函数,实现命令执行。  使用D\_SAFE补充验证  2.9 分析preview.php  1)首先该文件的首行应该是if判断session是否为管理员,但在该文件内并没有写校验,故存在越权漏洞。只要知道路径,任何人都可使用该php来上传文件。 2)存在上传文件后缀无限制  从图中可以看出,通过正则表达式,变量$base64是文件内容,变量$type是文件后缀,从红色框住的if语句里,完全没有任何的过滤,故payload为data:image/php;base64,PD9waHAgcGhwaW5mbygpOz8+ 3)不校验上传文件内容  从截图得知,上传后的文件名是文件内容的md5值,而代码中也不做文件内容检查,即可直接写<?php phpinfo();?> 2.10 preview.php攻击手法复现    复现完成 三、修复建议 1. 过滤presiew.php文件内上传的文件后缀名传参,并加入session校验。 2. 对webuploader/下所有文件进行审计后发现,fileupload.php和fileupload2.php都有文件上传漏洞,故建议对上传文件进行过滤 3. 对上传目录./preview/和./upload/禁止执行php。 4. 禁止非大陆地区的IP地址访问。
发表于 2021-11-25 09:41:25
阅读 ( 8121 )
分类:
应急响应
4 推荐
收藏
0 条评论
请先
登录
后评论
寺鹓
1 篇文章
×
发送私信
请先
登录
后发送私信
×
举报此文章
垃圾广告信息:
广告、推广、测试等内容
违规内容:
色情、暴力、血腥、敏感信息等内容
不友善内容:
人身攻击、挑衅辱骂、恶意行为
其他原因:
请补充说明
举报原因:
×
如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!