PHP code auditing tips: Analysis of PHP string offset Characteristics

Source: Internet
Author: User

0x01 Introduction
 
This is the [PCH-009] Security risk of php string offset I published in the 80 vul Journal, according to my understanding, for the PHP offset feature, from the actual point of view, write analysis. Address: http://www.bkjia.com/Article/201202/119105.html
 
0x02 Overview
 
PHP has such a feature in the string array. When we do not explicitly declare a string variable as an array, we directly assign a value to it, for example, $ test = 'tpc '. After the code, we want to use this string variable as a string array, for example, echo $ test ['hello']. What will we get? Let's take a look at the effect, such:
 
 
 


Through the experiment, we can know that when the corresponding key does not exist (hello), php will take the value (T) with the offset value of this string as the value of this key.
 
0x03 Exploitation
 
What does this feature help with our attacks?
 
Currently, the php Service generally enables magic quotation marks by default. If it is not enabled, it will also perform backslash processing in the key parameter section. Imagine if a controllable variable is transmitted through an array. Obscenity is too abstract. Let's take an example ?.
 
Assume that a source code contains the following code:
 
 
 
SQL variables are the SQL statements to be executed. By default, magic quotes are enabled for php. Let's take a look at the results of normal submission.
 
 
 
The single quotation mark is filtered out by the backslash. Next let's try another method of submission to see how it works.
 
 
 
Test is completely out of the hateful single quotes. Now it's just a matter of days. You can just insert SQL. Why is this happening? Let's dump some key variables to see how this situation is caused.
 
Code:
 
 


Run



These two images, in combination with the PHP offset feature we mentioned earlier, are easy to understand. Xigr [] = 'first. Due to the limitation of magic quotation marks, xigr [] = \'. When xigr [] [uid] is passed, due to the PHP offset feature, "\" is passed into the variable. In this way, "\", which protects SQL statements from being injected, becomes a helper and helps us escape normal "'" in SQL.
 

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.