Common Vulnerabilities and attacks in PHP

Source: Internet
Author: User
[Global variables] variables in PHP do not need to be declared in advance. they are automatically created in the first application, and their types do not need to be specified. they are automatically determined based on the context of the high and low files. From the programmer's point of view, this is undoubtedly an extremely convenient[Global variables]
Variables in PHP do not need to be declared in advance. they are automatically created during the first application, and their types do not need to be specified. they are automatically determined based on the context. From the programmer's point of view, this is undoubtedly an extremely convenient processing method. Obviously, this is also a very useful feature of rapid language development. Once a variable is created, it can be applied anywhere in the program. The result of this feature is that programmers seldom initialize variables. after all, when they were first created, they were empty.

Obviously, the main functions of PHP-based exploitation programs generally receive user input (mainly form variables, upload files and cookies), and then process the input data, then return the result to the client browser. To make PHP code visit users as easy as possible, PHP regards the input data as a global variable for processing.

For example:



Obviously, a text box and a submit button are displayed. When a user clicks the submit button, "test. php" processes user input and output. when "test. php" is run, "$ hello" contains the data that the user enters in the text box. We can see from this that attackers can create arbitrary global variables as they wish. If the attacker does not call "test. php" through form input, but directly enters http: // server/test. php in the browser address bar? Hello = hi & set ...? Knock? Why? /A> $ hello was created, and $ setup was created.

Note: These two methods are the "POST" and "GET" methods we usually call.
The following user authentication code *** shows the security Title caused by the global variables of PHP:

If ($ pass = 'Hello ')
$ Auth = 1;
...
If ($ auth = 1)
Echo 'some impant Ant information ';
?>

The above code first checks whether the user's password is "hello". if the password matches, set "$ auth" to "1" to pass authentication. If "$ suth" is "1", some important information will be displayed.

On the surface, it seems to be accurate, and a considerable number of us do this, but this code makes a mistake of course, it assumes that "$ auth" is empty when no value is set, but does not expect attackers to create any global variables and assign values. php? Auth = 1 "and? Current region? Copy? /A>

Therefore, to improve the security of PHP programs, we cannot trust any variables without definition. If there are many variables in the program, this is a very difficult task.

A common protection method is to check the variables in the array HTTP_GET [] or POST_VARS [], which is attached to our commit method (GET or POST ). When PHP is configured to enable the "track_vars" option (this is the default value), the variables submitted by the user can be obtained in the global variables and the array mentioned above.

However, it is worth noting that PHP has four different array variables used to process user input. The HTTP_GET_VARS array is used to process the variables submitted by the GET method. the HTTP_POST_VARS array is used to process the variables submitted by the POST method. the HTTP_COOKIE_VARS array is used to process the variables submitted as cookie headers, for the HTTP_POST_FILES array (provided only by the new PHP), it is an optional method for users to submit variables. A user's pleading can easily store variables in these four arrays, so a safe PHP program should check these four arrays.

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.