请遵守法律法规,合法冲浪
本文仅作知识分享用
一切直接或间接由于本文所造成的后果与本人无关
程序简介
前台一键发布图文,视频,音乐。发布内容支持定位或自定义位置信息。支持将发布内容设为广告模式消息站内通知或邮件通知。支持其他用户注册,支持其他用户发布文章,管理自己的文章。拥有丰富的后台管理功能,一键操作。
开发语言:PHP
源码信息:源码来自“刀客源码”
代码分析
山重水复疑无路
代码审计我个人喜欢从较为简单的SQL注入开始,但是看了下,程序请求参数全经过了处理,处理如下例所示:
$cid = addslashes(htmlspecialchars($_GET["cid"]));
遂决定从最直接的文件上传入手,用Seay快速扫了一下,存在多个上传点,但是都存在白名单校验,示例如下:
$file = $_FILES["file"];
$allowedExts = ["gif", "jpeg", "jpg", "png", "webp"];
$temp = explode(".", $_FILES["file"]["name"]);
$extension = end($temp);
if ($extension == "") {
exit("<script language="JavaScript">;alert("未选择图片!");location.href="../setup.php";</script>;");
}
if ($file["type"] == "image/jpeg" || $file["type"] == "image/png" || $file["type"] == "image/jpg" || $file["type"] == "image/gif" || $file["type"] == "image/webp" && in_array($extension, $allowedExts)) {
} else {
exit("<script language="JavaScript">;alert("文件类型错误,请上传图片!");location.href="../setup.php";</script>;");
}
柳暗花明又一村
挨个看了一下,终于在一处上传视频的功能点中,发现仅对“Content-Type”做了校验,这个可以在数据包中修改,漏洞代码如下:
$wzlx = "video";
if ($text == "") {
exit("<script language="JavaScript">;alert("请输入内容!");location.href="../edit.php";</script>;");
}
if ($spp == "") {
if ($_FILES["file"]["name"] == "") {
exit("<script language="JavaScript">;alert("请上传视频!");location.href="../edit.php";</script>;");
}
}
if ($spp != "") {
$spljd = $spp . "|" . $sppfm;
if (!preg_match("/^(http:\/\/|https:\/\/).*$/", $spljd)) {
exit("<script language="JavaScript">;alert("请输入正确的视频链接!");location.href="../edit.php";</script>;");
}
} else {
$fileEx = strtolower(substr(strrchr($_FILES["file"]["name"], "."), 1));
$allowedVideoTypes = ["video/mp4", "video/mpeg", "video/quicktime", "video/x-msvideo", "video/x-flv"];
$uploadedFileType = $_FILES["file"]["type"];
if (in_array($uploadedFileType, $allowedVideoTypes)) {
} else {
exit("<script language="JavaScript">alert("文件类型错误,请上传视频!");location.href="../edit.php";</script>");
}
$fileName = str_replace(".", "", microtime(true)) . mt_rand() . substr(md5($zjzhq), 0, 12) . "." . $fileEx;
move_uploaded_file($_FILES["file"]["tmp_name"], "../upload/" . $fileName);
$spljd = "/upload/" . $fileName . "|" . $sppfm;
}
文件上传后,需要返回首页查看上传的文件路径。
漏洞复现
一、利用条件
1.需要用户权限,或者管理员权限(管理员发布文章不需要审核)。
2.用户发布的文章需要通过审核,或者管理员在后台把审核功能关闭。
二、复现过程
1.登录用户后,进入发布文章。
2.之后点击“图片图标”,进入视频上传选项。
3.接下来就是常规的Burpsuit抓包修改数据包了,只需要将“filename”修改为“php”后缀,“Content-Type”修改为“video/mp4”发包即可。
4.上传成功后会跳转到主页,此时点击查看源代码即可看到文件路径。
5.访问路径,成功RCE。
http://xxx.xxx.xxx/upload/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.php
原文始发于微信公众号(不够安全):Miaoo朋友圈程序代码审计
免责声明:文章中涉及的程序(方法)可能带有攻击性,仅供安全研究与教学之用,读者将其信息做其他用途,由读者承担全部法律及连带责任,本站不承担任何法律及连带责任;如有问题可邮件联系(建议使用企业邮箱或有效邮箱,避免邮件被拦截,联系方式见首页),望知悉。
- 左青龙
- 微信扫一扫
-
- 右白虎
- 微信扫一扫
-
评论