File Inclusion
http://localhost/DVWA/vulnerabilities/fi
Low
We've a div containing three distinct hyperlinks, each triggering the display of various files within the web application upon activation. The exhibition of a specific file is accomplished through the utilization of the subsequent GET request.




This is php code of this level:

The concept involves manipulating the filename within the page parameter to any desired file on the target, enabling us to retrieve its contents. By employing the following GET request, we can read the contents of the etc password file.
1st Payload
Replacing this path: ../../../../../../etc/passwd at file1.php, we obtain result of command in html output:

If the goal is to disclose certain PHP code, one approach is to utilize PHP filters to encode the PHP code into base64.
2nd Payload
but the request is to see fi.php file, then we use this URL:
which gives us the following base64 payload
Decoding it, we obtain this php code:
The input is not sanitized, so I can execute any (potentially malicious) command.
Medium

In this case, code includes a little validation checks:
$file = str_replace( array( "http://", "https://" ), "", $file );
$file = str_replace( array( "../", "..\\" ), "", $file );
it tries to remove all sorts of http and https protocol usage, trying to remove the possibility for a Remote File Inclusion (RFI), and it also replaces ../ with the empty string: "".
The handling of the '../' character sequence is insufficient, as the validation is not performed recursively.
1st Payload
After input validation (not recursive), changing ../ to "", we obtain this result:
Then full URL will be this:
How the low level, adding the php filters we can also leak the server’s php code:
and we get the following base64
To get an RFI instead we can use php streams.
The input is not sanitized sufficiently , so I can execute any (potentially malicious) command.
High

In this code the're two validation checks:
The
fnmatch()function in PHP, which matches strings against patterns using shell-style wildcards. In our scenario, it matches any file that begins with 'file.'The condition
$file != 'include.php'introduces a specific case where the 'if' statement fails only when the file doesn't start with 'file' and is precisely 'include.php'.
1st Payload
Regarding LFI exploitation, the code solely verifies whether the parameter begins with 'file' and does not examine its ending. Consequently, we can employ the following GET request to expose the 'passwd' file.
however we cannot seem to able to use the php filters to leak php code by using the base64 converter.
2nd Payload
An alternative approach involves leveraging the file protocol to access and read any file in the system based on its given path.
The input is not sanitized sufficiently , so I can execute any (potentially malicious) command.
Impossible

References
For the making of this solution the following resource were used: