emlog pro文件上传漏洞审计(CVE-2023-44974)(CVE-2023-44973)
<h1 style="color: black; text-align: left; margin-bottom: 10px;">【<span style="color: black;">制品</span>介绍】</h1>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">emlog 是 “Every Memory Log” 的简<span style="color: black;">叫作</span>,意即:点滴记忆。它是一款基于PHP语言和MySQL数据库的开源、免费、功能强大的个人或多人联合撰写的博客系统(blog)。基于PHP和MySQL的功能强大的博客及CMS建站系统。致力于<span style="color: black;">供给</span>快速、稳定,且在<span style="color: black;">运用</span>上又极其简单、舒适的博客服务。安装和<span style="color: black;">运用</span>都非常方便</span></p>
<h1 style="color: black; text-align: left; margin-bottom: 10px;">环境配置环境配置</h1>
<h1 style="color: black; text-align: left; margin-bottom: 10px;">影响版本:emlog emlog pro 2.2.0</h1>
<h1 style="color: black; text-align: left; margin-bottom: 10px;">emlog pro /admin/plugin.php任意文件上传漏洞 CVE-2023-44974</h1>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">Emlog官网下载存在漏洞版本的源码:</p><span style="color: black;">https://github.com/emlog/emlog/releases</span>
<div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-axegupay5k/aa154236a92c4a4fb8142fc6b9c79434~noop.image?_iz=58558&from=article.pc_detail&lk3s=953192f4&x-expires=1728083065&x-signature=glAod5zqw%2B0ppdFM8RLqyihL5Jc%3D" style="width: 50%; margin-bottom: 20px;"></div>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">运用</span>PhpStudy进行搭建,配置数据库信息</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">起始</span>代码审计,<span style="color: black;">按照</span>上面emlog pro提示 路径/admin/plugin.php存在任意文件上传漏洞,远程攻击者可利用该漏洞提交特殊的请求,可上传恶意文件,以应用程序上下文执行任意代码。</p>先<span style="color: black;">拜访</span>路径,<span style="color: black;">瞧瞧</span>页面是什么样的,这个是原生<span style="color: black;">研发</span>的可以<span style="color: black;">这般</span>,<span style="color: black;">倘若</span>是mvc的就不行
<div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-6w9my0ksvp/572ccde69ef64b3db8186168951c0441~noop.image?_iz=58558&from=article.pc_detail&lk3s=953192f4&x-expires=1728083065&x-signature=R4k0sACUmykIQnR5lHROUvf0IE8%3D" style="width: 50%; margin-bottom: 20px;"></div>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">挖掘文件上传这种漏洞就直接找功能点,这个页面的功能点<span style="color: black;">仅有</span>一个安装插件</span></p>
<div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-6w9my0ksvp/374865e3d4224aa6a62c59c28d924dd0~noop.image?_iz=58558&from=article.pc_detail&lk3s=953192f4&x-expires=1728083065&x-signature=rXoFGGj5W0%2FXQhdJ3LBveCsuOx4%3D" style="width: 50%; margin-bottom: 20px;"></div>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">先正常的安装个插件走一下流程</span></p>
<div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-6w9my0ksvp/1a63f7483feb49f9bcb86b9543b77dba~noop.image?_iz=58558&from=article.pc_detail&lk3s=953192f4&x-expires=1728083065&x-signature=Jqj2fw2aKp3sB8gbsEhly4xxYEU%3D" style="width: 50%; margin-bottom: 20px;"></div>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">运用</span>burp抓包</span></p>
<div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-6w9my0ksvp/e03f8cb23b9b46e785596d37ab32eb81~noop.image?_iz=58558&from=article.pc_detail&lk3s=953192f4&x-expires=1728083065&x-signature=uTU%2BO6ntQiwUyatjn%2FzwToeuLh8%3D" style="width: 50%; margin-bottom: 20px;"></div>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">晓得</span>了这个数据包是成功上传文件的</span></p>
<div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-6w9my0ksvp/bdabbc7201f0450a81578d74b6e13a66~noop.image?_iz=58558&from=article.pc_detail&lk3s=953192f4&x-expires=1728083065&x-signature=BLZp3ezSUyj4%2FwuQ%2B8i2krPGTMM%3D" style="width: 50%; margin-bottom: 20px;"></div>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">打开源码<span style="color: black;">经过</span>搜索全局upload_zip</span></p>
<div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-6w9my0ksvp/23a1d6a6dad94a3ea3e747fb4b14df54~noop.image?_iz=58558&from=article.pc_detail&lk3s=953192f4&x-expires=1728083065&x-signature=nsRKACZhlYxs5qApYu3yUlDQRgM%3D" style="width: 50%; margin-bottom: 20px;"></div>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">按照</span>上面的提示路径找到了这个文件</span></p>
<div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-6w9my0ksvp/95d245beccc64951a4ee3bedf928c879~noop.image?_iz=58558&from=article.pc_detail&lk3s=953192f4&x-expires=1728083065&x-signature=9ca0ZPV9LCLE%2B77UYdoPzB14M%2Fw%3D" style="width: 50%; margin-bottom: 20px;"></div><span style="color: black;">if</span> ($action == <span style="color: black;">upload_zip</span>) {
LoginAuth::checkToken();
$zipfile =<span style="color: black;">isset</span>($_FILES[<span style="color: black;">pluzip</span>]) ? $_FILES[<span style="color: black;">pluzip</span>] : ;
<span style="color: black;">if</span> ($zipfile[<span style="color: black;">error</span>] == <span style="color: black;">4</span>) {
emDirect(<span style="color: black;">"./plugin.php?error_d=1"</span>);
}<span style="color: black;">if</span> ($zipfile[<span style="color: black;">error</span>] == <span style="color: black;">1</span>) {
emDirect(<span style="color: black;">"./plugin.php?error_g=1"</span>);
}
<span style="color: black;">if</span> (!$zipfile || $zipfile[<span style="color: black;">error</span>] >= <span style="color: black;">1</span> || <span style="color: black;">empty</span>($zipfile[<span style="color: black;">tmp_name</span>])) {
emMsg(<span style="color: black;">插件上传失败, 错误码:</span> . $zipfile[<span style="color: black;">error</span>]);
}
<span style="color: black;">if</span> (getFileSuffix($zipfile[<span style="color: black;">name</span>]) != <span style="color: black;">zip</span>) {
emDirect(<span style="color: black;">"./plugin.php?error_f=1"</span>);
}
$ret = emUnZip($zipfile[<span style="color: black;">tmp_name</span>], <span style="color: black;">../content/plugins/</span>, <span style="color: black;">plugin</span>);
<span style="color: black;">switch</span> ($ret) {
<span style="color: black;">case</span> <span style="color: black;">0</span>:
emDirect(<span style="color: black;">"./plugin.php?activate_install=1"</span>);
<span style="color: black;">break</span>;
<span style="color: black;">case</span> <span style="color: black;">-1</span>:
emDirect(<span style="color: black;">"./plugin.php?error_e=1"</span>);
<span style="color: black;">break</span>;
<span style="color: black;">case</span> <span style="color: black;">1</span>:
<span style="color: black;">case</span> <span style="color: black;">2</span>:
emDirect(<span style="color: black;">"./plugin.php?error_b=1"</span>);
<span style="color: black;">break</span>;
<span style="color: black;">case</span> <span style="color: black;">3</span>:
emDirect(<span style="color: black;">"./plugin.php?error_c=1"</span>);
<span style="color: black;">break</span>;
}
}<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">这段是<span style="color: black;">能够</span>绕过的,没什么问题获取文件后缀名zip</span></p>
<div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-6w9my0ksvp/f53108659e4a4437b53e8d762a763459~noop.image?_iz=58558&from=article.pc_detail&lk3s=953192f4&x-expires=1728083065&x-signature=64qja4PXJgiV%2B6Ypf%2FyLL%2BVB%2Bos%3D" style="width: 50%; margin-bottom: 20px;"></div>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">继续跟踪一下emUnZip,解压文件<span style="color: black;">瞧瞧</span>解压过程中有<span style="color: black;">无</span>什么过滤</span></p>
<div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-6w9my0ksvp/273dde468fee45a5a7c9dda9a5e1951f~noop.image?_iz=58558&from=article.pc_detail&lk3s=953192f4&x-expires=1728083065&x-signature=Ez4A0PjEIPwPPOZi0SMvtxgY3Pc%3D" style="width: 50%; margin-bottom: 20px;"></div><span style="color: black;">function</span> emUnZip(<span style="color: black;">$zipfile</span>, <span style="color: black;">$path</span>, <span style="color: black;">$type</span> = <span style="color: black;">tpl</span>) {
<span style="color: black;">if</span> (!class_exists(<span style="color: black;">ZipArchive</span>, FALSE)) {
<span style="color: black;">return</span>3;//zip模块问题
}<span style="color: black;">$zip</span> = new ZipArchive();
<span style="color: black;">if</span> (<span class=<span style="color: black;">"label label-primary"</span>>@<span style="color: black;">$zip</span>-</span>>open(<span style="color: black;">$zipfile</span>) !== TRUE) {
<span style="color: black;">return</span> 2;//文件权限问题
}
<span style="color: black;">$r</span> = explode(<span style="color: black;">/</span>, <span style="color: black;">$zip</span>->getNameIndex(0), 2);<span style="color: black;">$dir</span> = isset(<span style="color: black;">$r</span>) ? <span style="color: black;">$r</span> . <span style="color: black;">/</span> : ;
switch (<span style="color: black;">$type</span>) {
<span style="color: black;">case</span> <span style="color: black;">tpl</span>:
<span style="color: black;">$re</span> = <span style="color: black;">$zip</span>->getFromName(<span style="color: black;">$dir</span> . <span style="color: black;">header.php</span>);
<span style="color: black;">if</span> (<span style="color: black;">false</span> === <span style="color: black;">$re</span>) {
<span style="color: black;">return</span> -2;
}
<span style="color: black;">break</span>;
<span style="color: black;">case</span> <span style="color: black;">plugin</span>:
<span style="color: black;">$plugin_name</span> = substr(<span style="color: black;">$dir</span>, 0, -1);
<span style="color: black;">$re</span> = <span style="color: black;">$zip</span>->getFromName(<span style="color: black;">$dir</span> . <span style="color: black;">$plugin_name</span> . <span style="color: black;">.php</span>);
<span style="color: black;">if</span> (<span style="color: black;">false</span> === <span style="color: black;">$re</span>) {
<span style="color: black;">return</span> -1;
}
<span style="color: black;">break</span>;
<span style="color: black;">case</span> <span style="color: black;">backup</span>:
<span style="color: black;">$sql_name</span> = substr(<span style="color: black;">$dir</span>, 0, -1);
<span style="color: black;">if</span> (getFileSuffix(<span style="color: black;">$sql_name</span>) != <span style="color: black;">sql</span>) {
<span style="color: black;">return</span> -3;
}
<span style="color: black;">break</span>;
<span style="color: black;">case</span> <span style="color: black;">update</span>:
<span style="color: black;">break</span>;
}
<span style="color: black;">if</span> (<span style="color: black;">true</span> === <span class=<span style="color: black;">"label label-primary"</span>>@<span style="color: black;">$zip</span>-</span>>extractTo(<span style="color: black;">$path</span>)) {
<span style="color: black;">$zip</span>->close();
<span style="color: black;">return</span> 0;
}
<span style="color: black;">return</span> 1; //文件权限问题
}<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">经过</span>跟踪并<span style="color: black;">无</span>什么过滤,emUnZip函数,<span style="color: black;">能够</span><span style="color: black;">发掘</span>他需要获取一个路径$dir,<span style="color: black;">然则</span>咱们的压缩包里面<span style="color: black;">便是</span>一个文件,安装正常的插件压缩包里面都有一个文件夹</span></p>
<div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-6w9my0ksvp/f1d2919fe29e45f39b6c342e196b3e94~noop.image?_iz=58558&from=article.pc_detail&lk3s=953192f4&x-expires=1728083065&x-signature=fNjgOpbh9%2FJUpnkI%2BesqiG%2BiCk4%3D" style="width: 50%; margin-bottom: 20px;"></div>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">去网上找了一个正常插件,上传,<span style="color: black;">能够</span>成功上传</span></p>
<div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-6w9my0ksvp/70d75f704df6474bb3b5df6d00233b04~noop.image?_iz=58558&from=article.pc_detail&lk3s=953192f4&x-expires=1728083065&x-signature=%2BSObyf34xsQKxeIOULDzWU1f%2BCc%3D" style="width: 50%; margin-bottom: 20px;"></div>
<div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-6w9my0ksvp/78f2984b9ac94123bd78ea61279b2e6a~noop.image?_iz=58558&from=article.pc_detail&lk3s=953192f4&x-expires=1728083065&x-signature=jotCE%2BgcD3uXI8j4VUyYB7fWOX0%3D" style="width: 50%; margin-bottom: 20px;"></div>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">而后</span>在本地修改插件,创建一个php文件</span></p>
<div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-6w9my0ksvp/780e78d59fb54ccab1c4b82a1794fad6~noop.image?_iz=58558&from=article.pc_detail&lk3s=953192f4&x-expires=1728083065&x-signature=zdLZoCZ%2FKcn2HJ9VSCopXYPuqno%3D" style="width: 50%; margin-bottom: 20px;"></div>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">写入内容</span></p>
<div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-6w9my0ksvp/4005516900db4f2e877940bcc3ee0d4b~noop.image?_iz=58558&from=article.pc_detail&lk3s=953192f4&x-expires=1728083065&x-signature=aimKhtN9J8QonRxIExXquMji6oY%3D" style="width: 50%; margin-bottom: 20px;"></div>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">而后</span>进行压缩上传,分析上面代码,<span style="color: black;">晓得</span>了上传解压<span style="color: black;">无</span>对文件内的内容进行过滤,成功上传</span></p>
<div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-6w9my0ksvp/346fcbee50ec45f798dcef0f9d91450d~noop.image?_iz=58558&from=article.pc_detail&lk3s=953192f4&x-expires=1728083065&x-signature=djrEWnq0HVM1jztRjGLbUOQpg3o%3D" style="width: 50%; margin-bottom: 20px;"></div>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">查看本地文件夹<span style="color: black;">是不是</span>存在phpinfo.php</span></p>
<div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-6w9my0ksvp/62a1ec6a201f4cae8cfdb8d59a8622b5~noop.image?_iz=58558&from=article.pc_detail&lk3s=953192f4&x-expires=1728083065&x-signature=uzap5QXcyprg68DTf89BrFWzI7U%3D" style="width: 50%; margin-bottom: 20px;"></div>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">网页<span style="color: black;">拜访</span>路径</span></p>
<div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-6w9my0ksvp/a027fff80d7a43ce9401c5e2b55ef5c1~noop.image?_iz=58558&from=article.pc_detail&lk3s=953192f4&x-expires=1728083065&x-signature=iQ5VHJ9n1yBK0KJNPA6tUG2qiGQ%3D" style="width: 50%; margin-bottom: 20px;"></div>
<h1 style="color: black; text-align: left; margin-bottom: 10px;">emlog pro /content/templates/任意文件上传漏洞 CVE-2023-44973</h1>
<div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-6w9my0ksvp/d437e24856c64dfea7ac26b5b8696f9a~noop.image?_iz=58558&from=article.pc_detail&lk3s=953192f4&x-expires=1728083065&x-signature=%2F29uc8k7hDE5Fs9G%2FityCIkVUjM%3D" style="width: 50%; margin-bottom: 20px;"></div>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">打开网站,还是先找功能点,<span style="color: black;">按照</span>上面的cnvd提示<span style="color: black;">亦</span><span style="color: black;">晓得</span>是模板那个位置有问题</span></p>
<div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-6w9my0ksvp/bed9ae53087f41d2b1c72a1da765227d~noop.image?_iz=58558&from=article.pc_detail&lk3s=953192f4&x-expires=1728083065&x-signature=nHL%2FB5JBMRcgcZUNNwBqAQFP2Pg%3D" style="width: 50%; margin-bottom: 20px;"></div>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">和上面<span style="color: black;">第1</span>则<span style="color: black;">同样</span>先上传个正常的文件上去,抓一下包</span></p>
<div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-6w9my0ksvp/4e35e369fa364305b60bd45c0a00cf34~noop.image?_iz=58558&from=article.pc_detail&lk3s=953192f4&x-expires=1728083065&x-signature=z9SQrxn1X86lxVTF3AFLzK4SO8g%3D" style="width: 50%; margin-bottom: 20px;"></div>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">定位到代码位置</span></p><span style="color: black;">if</span> ($action === <span style="color: black;">upload_zip</span>) {
LoginAuth::checkToken(); <span style="color: black;">// <span style="color: black;">检测</span>登录状态和令牌,<span style="color: black;">保证</span>安全性</span>
$zipfile = <span style="color: black;">isset</span>($_FILES[<span style="color: black;">tplzip</span>]) ? $_FILES[<span style="color: black;">tplzip</span>] : ; <span style="color: black;">// 获取上传的ZIP文件</span>
<span style="color: black;">if</span> ($zipfile[<span style="color: black;">error</span>] == <span style="color: black;">4</span>) {
emDirect(<span style="color: black;">"./template.php?error_d=1"</span>);<span style="color: black;">// <span style="color: black;">倘若</span>上传文件为空,重定向到错误页面</span>
}
<span style="color: black;">if</span> ($zipfile[<span style="color: black;">error</span>] == <span style="color: black;">1</span>) {
emDirect(<span style="color: black;">"./template.php?error_f=1"</span>); <span style="color: black;">// <span style="color: black;">倘若</span>上传文件超过了php.ini中的限制<span style="color: black;">体积</span>,重定向到错误页面</span>
}
<span style="color: black;">if</span> (!$zipfile || $zipfile[<span style="color: black;">error</span>] > <span style="color: black;">0</span> || <span style="color: black;">empty</span>($zipfile[<span style="color: black;">tmp_name</span>])) {
emMsg(<span style="color: black;">模板上传失败, 错误码:</span> . $zipfile[<span style="color: black;">error</span>]); <span style="color: black;">// <span style="color: black;">倘若</span>上传文件出错,<span style="color: black;">表示</span>错误信息并返回</span>
}
<span style="color: black;">if</span> (getFileSuffix($zipfile[<span style="color: black;">name</span>]) != <span style="color: black;">zip</span>) {
emDirect(<span style="color: black;">"./template.php?error_a=1"</span>); <span style="color: black;">// <span style="color: black;">倘若</span>上传文件不是ZIP文件,重定向到错误页面</span>
}
$ret = emUnZip($zipfile[<span style="color: black;">tmp_name</span>], <span style="color: black;">../content/templates/</span>, <span style="color: black;">tpl</span>); <span style="color: black;">// 调用解压缩函数解压上传的ZIP文件</span>
<span style="color: black;">switch</span> ($ret) {
<span style="color: black;">case</span> <span style="color: black;">0</span>:
emDirect(<span style="color: black;">"./template.php?activate_install=1"</span>); <span style="color: black;">// 解压缩成功,重定向到激活安装页面</span>
<span style="color: black;">break</span>;
<span style="color: black;">case</span> <span style="color: black;">-2</span>:
emDirect(<span style="color: black;">"./template.php?error_e=1"</span>); <span style="color: black;">// 找不到header.php文件,重定向到错误页面</span>
<span style="color: black;">break</span>;
<span style="color: black;">case</span> <span style="color: black;">1</span>:
<span style="color: black;">case</span> <span style="color: black;">2</span>:
emDirect(<span style="color: black;">"./template.php?error_b=1"</span>); <span style="color: black;">// 文件权限问题或解压缩失败,重定向到错误页面</span>
<span style="color: black;">break</span>;
<span style="color: black;">case</span> <span style="color: black;">3</span>:
emDirect(<span style="color: black;">"./template.php?error_c=1"</span>); <span style="color: black;">// 缺少ZIP模块,重定向到错误页面</span>
<span style="color: black;">break</span>;
}
}<div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-6w9my0ksvp/2ee5ee7d97144063a269546c09138dd0~noop.image?_iz=58558&from=article.pc_detail&lk3s=953192f4&x-expires=1728083065&x-signature=ox4Jg0y0AAcHT%2F2%2BRfpr%2F6PiQ3U%3D" style="width: 50%; margin-bottom: 20px;"></div>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">当action为upload_zip时,执行if后面的语句,LoginAuth::checkToken();是用来检测登录状态的。$zipfile用来接收tplzip上传上来的数据,<span style="color: black;">而后</span>对上传的数据进行<span style="color: black;">各样</span>错误判断,判断成功后,执行下面的emUnZip函数进行解压,并把解压后的文件放到/content/templates/目录下,<span style="color: black;">咱们</span>在<span style="color: black;">跟踪</span>一下emUnZip函数<span style="color: black;">瞧瞧</span><span style="color: black;">是不是</span>有过滤等<span style="color: black;">状况</span></p><span style="color: black;">经过</span>查看代码文件上传时会执行if后面的语句,$zipfile变量来接收上传的数据,对数据进行判断,符合<span style="color: black;">需求</span>执行解压函数emUnZip进行解压,<span style="color: black;">因此</span><span style="color: black;">咱们</span>继续跟踪emUnZip<span style="color: black;">瞧瞧</span>有<span style="color: black;">无</span>过滤<span style="color: black;">function</span> emUnZip(<span style="color: black;">$zipfile</span>, <span style="color: black;">$path</span>, <span style="color: black;">$type</span> = <span style="color: black;">tpl</span>) {
<span style="color: black;">if</span> (!class_exists(<span style="color: black;">ZipArchive</span>, FALSE)) {
<span style="color: black;">return</span>3; // <span style="color: black;">倘若</span>服务器上<span style="color: black;">无</span>安装Zip模块,返回错误码3,<span style="color: black;">暗示</span>zip模块问题
}<span style="color: black;">$zip</span> = new ZipArchive(); // 创建一个ZipArchive对象
<span style="color: black;">if</span> (<span class=<span style="color: black;">"label label-primary"</span>>@<span style="color: black;">$zip</span>-</span>>open(<span style="color: black;">$zipfile</span>) !== TRUE) {
<span style="color: black;">return</span>2; // <span style="color: black;">倘若</span><span style="color: black;">没法</span>打开指定的压缩文件,返回错误码2,<span style="color: black;">暗示</span>文件权限问题
}<span style="color: black;">$r</span> = explode(<span style="color: black;">/</span>, <span style="color: black;">$zip</span>->getNameIndex(0), 2); // 获取压缩文件中的<span style="color: black;">第1</span>个文件的路径
<span style="color: black;">$dir</span> = isset(<span style="color: black;">$r</span>) ? <span style="color: black;">$r</span> . <span style="color: black;">/</span> : ; // 获取文件的目录路径
switch (<span style="color: black;">$type</span>) {<span style="color: black;">case</span> <span style="color: black;">tpl</span>:
<span style="color: black;">$re</span> = <span style="color: black;">$zip</span>->getFromName(<span style="color: black;">$dir</span> . <span style="color: black;">header.php</span>); // 从压缩文件中获取名为header.php的文件内容
<span style="color: black;">if</span> (<span style="color: black;">false</span> === <span style="color: black;">$re</span>) {
<span style="color: black;">return</span> -2; // <span style="color: black;">倘若</span><span style="color: black;">没法</span>获取到header.php文件内容,返回错误码-2
}
<span style="color: black;">break</span>;
<span style="color: black;">case</span> <span style="color: black;">plugin</span>:
<span style="color: black;">$plugin_name</span> = substr(<span style="color: black;">$dir</span>, 0, -1); // 获取插件的名<span style="color: black;">叫作</span>
<span style="color: black;">$re</span> = <span style="color: black;">$zip</span>->getFromName(<span style="color: black;">$dir</span> . <span style="color: black;">$plugin_name</span> . <span style="color: black;">.php</span>); // 从压缩文件中获取与插件名<span style="color: black;">叫作</span>对应的php文件内容
<span style="color: black;">if</span> (<span style="color: black;">false</span> === <span style="color: black;">$re</span>) {
<span style="color: black;">return</span> -1; // <span style="color: black;">倘若</span><span style="color: black;">没法</span>获取到插件对应的php文件内容,返回错误码-1
}
<span style="color: black;">break</span>;
<span style="color: black;">case</span> <span style="color: black;">backup</span>:
<span style="color: black;">$sql_name</span> = substr(<span style="color: black;">$dir</span>, 0, -1); // 获取备份文件的名<span style="color: black;">叫作</span>
<span style="color: black;">if</span> (getFileSuffix(<span style="color: black;">$sql_name</span>) != <span style="color: black;">sql</span>) { // 判断备份文件的后缀名<span style="color: black;">是不是</span>为sql<span style="color: black;">return</span> -3; // <span style="color: black;">倘若</span>备份文件的后缀名不为sql,返回错误码-3
}
<span style="color: black;">break</span>;
<span style="color: black;">case</span> <span style="color: black;">update</span>:
<span style="color: black;">break</span>;
}
<span style="color: black;">if</span> (<span style="color: black;">true</span> === <span class=<span style="color: black;">"label label-primary"</span>>@<span style="color: black;">$zip</span>-</span>>extractTo(<span style="color: black;">$path</span>)) { // 将压缩文件内容解压到指定路径
<span style="color: black;">$zip</span>->close();
<span style="color: black;">return</span> 0; // 解压缩成功,返回0
}
<span style="color: black;">return</span> 1; // 解压缩失败,返回错误码1,<span style="color: black;">暗示</span>文件权限问题
}<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">能够</span>看出<span style="color: black;">无</span>过滤,<span style="color: black;">而后</span>对上传的文件添加恶意文件</span></p>
<div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-6w9my0ksvp/46c9dbb5288240008ca39ea1441f3366~noop.image?_iz=58558&from=article.pc_detail&lk3s=953192f4&x-expires=1728083065&x-signature=XcEeKGExqBRatehEUpRyWTgcBu4%3D" style="width: 50%; margin-bottom: 20px;"></div>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">还是和上面<span style="color: black;">同样</span>,在正常的模板里面添加一个php文件,文件内容不为空,压缩上传</span></p>
<div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-6w9my0ksvp/1757ee7d113f4e26bad5a9b82b2d90ca~noop.image?_iz=58558&from=article.pc_detail&lk3s=953192f4&x-expires=1728083065&x-signature=Zs17xAFk4E2%2FoHXTqIdN%2BovDV1E%3D" style="width: 50%; margin-bottom: 20px;"></div>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">上传成功<span style="color: black;">拜访</span></span></p>
<div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-6w9my0ksvp/d8746a84ec6c4eb5bcb68aebf219e3d5~noop.image?_iz=58558&from=article.pc_detail&lk3s=953192f4&x-expires=1728083065&x-signature=q0xvhmpIlHak66rGCO1wQvf1Gvw%3D" style="width: 50%; margin-bottom: 20px;"></div>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">这两个文件上传都是<span style="color: black;">同样</span>调用同一个文件</span></p>
<div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-6w9my0ksvp/92a7674f42214d219957d951d46cba77~noop.image?_iz=58558&from=article.pc_detail&lk3s=953192f4&x-expires=1728083065&x-signature=3y3GL8EwVCpYoYvuh5YcGjATZ0s%3D" style="width: 50%; margin-bottom: 20px;"></div>
楼主的文章深得我心,表示由衷的感谢! 楼主听话,多发外链好处多,快到碗里来!外链论坛 http://www.fok120.com/ 软文发布平台 http://www.fok120.com/ 论坛是一个舞台,让我们在这里尽情的释放自己。
页:
[1]