Summary
A path traversal flaw in HUSTOF's problem_import_qduoj.php and problem_import_hoj.php modules allows crafted ZIP archives to write files outside the intended extraction directory.
By embedding traversal sequences in filenames (for example, ../../shell.php), an attacker can place executable files into the web root and potentially achieve remote code execution on the server.
Affected context
This vulnerability appears in HUSTOF deployments that use the ZIP-based problem import functionality in the problem_import_qduoj.php and problem_import_hoj.php modules.
It becomes relevant when:
- Users are allowed to upload ZIP archives containing problem statements or related assets.
- The server automatically extracts these archives on the filesystem.
- Extracted files are placed somewhere within or near the web-accessible directory tree.
In such setups, insufficient checks on the internal filenames of ZIP entries can allow files to be written outside the intended import directory.
Exploit preconditions
- Attack surface: HTTP endpoints or admin panels that handle ZIP uploads for problem import (problem_import_qduoj.php and problem_import_hoj.php).
- Required access: Ability to submit a ZIP file through the problem import feature (this may require authenticated access depending on deployment configuration).
- Trigger point: Server-side extraction of the uploaded ZIP archive without normalizing and validating entry paths.
- Why exploitation is possible: The extraction logic trusts the paths stored inside the ZIP archive and does not robustly prevent directory traversal sequences (such as ../) from escaping the intended destination directory, enabling overwrite or creation of files in arbitrary locations, including the web root.
Why this happens
The root cause is insufficient validation and normalization of file paths contained within uploaded ZIP archives before extraction.
When the application extracts each ZIP entry, it uses the filename supplied by the archive without:
- Removing or rejecting traversal tokens (../, ..\).
- Ensuring the resolved path remains within a designated, constrained directory.
This behavior maps to CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal'), where user-controlled paths are allowed to escape a safe base directory.
Because the target environment is a web server, writing attacker-controlled PHP files into a web-accessible directory effectively converts the path traversal into remote code execution.
Potential impact
- Creation of arbitrary PHP files in the web root that can be executed remotely.
- Remote Code Execution under the web server or PHP-FPM process user.
- Overwriting of existing application files, potentially introducing backdoors or altering logic.
- Planting of web shells to maintain long-term unauthorized access.
- Modification or destruction of problem data, configuration files, or user-uploaded content.
- Lateral movement within the server environment if combined with other weaknesses (e.g., weak OS permissions).
General mitigation guidance
Effective mitigation centers on constraining file paths and treating archive contents as untrusted input:
- Normalize and validate all archive entry paths before extraction, rejecting entries containing traversal tokens (../, absolute paths, or drive prefixes).
- Resolve each entry path against a known, fixed base directory and explicitly verify that the final, canonical path remains inside that directory.
- Strip directory components and only allow a controlled subset of filenames or directories (e.g., whitelist allowed subdirectories and file extensions).
- Extract archives into non-web-accessible directories and separately copy or process only the specific, validated files needed by the application.
- Run the web server and extraction routines with least-privilege filesystem permissions, ensuring they cannot write outside designated application directories.
- Introduce secure-by-default helper utilities or libraries for archive handling that enforce these constraints centrally rather than ad hoc.
How teams detect issues like this
Detection typically involves a mix of code analysis and operational monitoring:
- Static analysis: Search the codebase for ZIP extraction routines that concatenate or directly use archive entry names as filesystem paths without canonicalization and boundary checks.
- Code review cues: Look for functions that:
- Use ZIP libraries to extract all files blindly from user-supplied archives.
- Write to paths derived from $_FILES, archive entries, or other user input without validating against a base directory.
- Policy and tooling: Enforce secure file-handling guidelines (e.g., must use centralized path-normalization helpers) through code review checklists and automated linters where possible.
- Runtime monitoring: Log file creation and modification events under web-accessible directories, especially around the time of ZIP uploads, and alert on suspicious locations (e.g., new .php files in upload directories).
- Security testing: Incorporate path traversal test cases in ZIP archives during routine penetration tests or CI-based DAST to identify unsafe extraction behaviors.

