Code Execution via Local File Inclusion and Remedy Explained
Netsparker detected code execution via local file inclusion, which occurs when a file from the target system is injected into the attacked page and interpreted as code.
At the beginning of the attacking phase, Netsparker made an HTTP request which contained custom payload and saw the output of execution of it at this page. This means this code has been executed, and this vulnerability generally happens with inclusion of log files by LFI-vulnerable PHP scripts.
An attacker can execute malicious code by abusing the Local File Inclusion vulnerability on the server.
Required Skills for Successful Exploitation
Significant attacking skills are required because there is no tool or automated way to exploit this vulnerability. The attack consists of three phases: detecting the vulnerability, finding malicious code (or if possible creating one, by uploading an image, etc.) on the targeted system, and including that code via the identified vulnerability to run it. Generally the attacker needs to find the physical path of server access logs or needs to upload an image to the server or abuse
/proc/self/ functionality in Linux systems where possible.
- If possible, do not permit file paths to be appended directly. Make them hard-coded or selectable from a limited hard-coded path list via an index variable.
- If you definitely need dynamic path concatenation, ensure you only accept required characters such as "a-Z0-9" and do not allow ".." or "/" or "%00" (null byte) or any other similar unexpected characters.
- It's important to limit the API to allow inclusion only from a directory and directories below it. This ensures that any potential attack cannot perform a directory traversal attack.