File Inclusion Vulnerability Analysis for DVWA Series 14
Program developers usually write reusable functions into a single file. When using some functions, they call this file directly without writing it again, this process of calling a file is generally called inclusion. Developers all want code to be more flexible, so they usually set the contained files as variables for dynamic calls. However, this flexibility is precisely because of this, as a result, the client can call a malicious file, resulting in a File Inclusion Vulnerability.
PHP provides four file-contained functions, including include (), include_once (), require (), and require_once (). Their differences are as follows:
When require cannot find the contained file, a fatal error occurs and the script is stopped.
When the include file cannot be found, only warnings are generated and the script continues to run.
Include_once is similar to include. The only difference is that if the code in the file has been included, it will not be included again.
Require_once is similar to require. The only difference is that if the code in the file has been included, it will not be included again.
For example, in this example, 01.txt is a normal text file, but the file content is a code that conforms to the PHP syntax:
The 01.txt file is included in the 02.php file. The Code is as follows:
Put the two files in the D: \ AppServ \ wwwdirectory, and then upload 02.php in the browser. You can see that the code in 01.txt is correctly executed. The extension of the 02.txt file is changed to jpg, rar, doc, and xxx for testing. The phpinfo information can be correctly displayed. As long as the file content complies with PHP syntax specifications, any extension name can be parsed by PHP.
Create another test file 03.txt with the content "Hello, world !", It does not conform to the PHP syntax specification and can be found that such a file can directly display its content.