Source Code Examples
Last updated
Last updated
In the DVWA the LFI vulnerability page URL is /dvwa/vulnerabilities/fi/page=<page>. The page URL parameter is vulnerable. Using directory traversal you can retrieve the /etc/passwd file.
The code that handles this does not validate the user input from the page URL parameter. It merely sets the URL parameter to the file variable.
The Index.php handles this file variable:
Seen above, the low.php uses the URL parameter and sets the $file variable based on it. The code in Index.php then retrieves the file if it exists. There is no sanitization of the user input or checks to validate the accessibility of the file. Thus allowing LFI.
The source code is modified in the Medium security level to validate the user input, remove http and https and strip dot-dot-slash characters.
These attempted checks can be bypassed by merely entering /etc/passwd in the page URL parameter without using "../".
The high security level only allows inputs starting with word "file" or if the file is "include.php".
This can be bypassed using the "File" URI scheme since it starts with the word "File". The File URI scheme is used to access files on the localhost. Changing the parameter to file:///etc/passwd will successfully return the file.
The code for the impossible security level only allows the "include.php" file or files 1-3 which are hard coded into the if statement. There is no way to exploit this to retrieve arbitrary files.
The source code that retrieves files for the LFI example is in xvwa/vulnerabilities/fi/home.php file.
The URL to exploit is http://localhost:8012/xvwa/vulnerabilities/fi/?file=/Windows/system.ini
The "file" URL parameter is used in line 13 and if the parameter is not null it retrieves the files with no input checks or validation and returns the file to the user.