RFI attacks through file upload functionality
This lab demonstrates RFI vulnerabilities that can be exploited through file upload functionality. Attackers can upload files containing malicious code or reference remote files that get processed and executed on the server.
Objective: Use file upload functionality to achieve remote file inclusion and code execution.
// Vulnerable: Direct inclusion without validation
function include_uploaded_file($filename) {
if (empty($filename)) {
return "No file specified.";
}
// Check if it's a remote URL
if (filter_var($filename, FILTER_VALIDATE_URL)) {
// Vulnerable: Direct inclusion of remote files
$content = @file_get_contents($filename);
if ($content !== false) {
return $content;
}
}
// Local file inclusion
$local_path = "uploads/" . basename($filename);
if (file_exists($local_path)) {
return file_get_contents($local_path);
}
}
No files uploaded yet.
malicious.php - Upload PHP shellhttp://attacker.com/shell.php - Remote fileconfig.txt - Upload config filetemplate.html - Upload templateUpload these files to test RFI vulnerabilities: