PHP Code Audit Code Execution injection

Source: Internet
Author: User

PHP Code Audit Code Execution injection

The so-called code execution injection is that the string parameters entered in some functions in PHP are executed as PHP code.

In this article, great article can be explored.

A common code execution function

Eval,assert,preg_replace

The eval function in the PHP manual means that the input string is programmed into PHP code

Test the code as follows, and then assign the value of the variable Moon to Phpinfo () in the URL

Execution succeeded in drawing the current PHP version,

Preg_replace perform regular expression search and replace

Allow code execution when the/E pattern modifier is present in pattern

ASSERT () checks the given assertion and, if the result is false, takes the appropriate action.

First Test the Eval function, this is the test code.

Here are the test results

Preg_replace ()

1 first parameter injection

/* Roughly the regular expression filter is phpinfo ()

Must have parameter/E URL test plus reg=/e

*/

The general meaning is to remove the style of the string containing Reg

First of all there is the parameter/E, this mode for code execution

Then enter the characters to be filtered, enter <\/PHP>, Mode/E, <php>phpinfo () </php> filter to

Phpinfo (), successful execution

2 The second way is simpler and better understood, direct injection

Preg_replace ("/moon/e", $_get[' moon '], "I love Moon");

3 parameter three injection success

The entire test code is appended

<?PHP//PHP Code Audit Code Execution injection/*if (isset ($_get[' moon ')) {$moon =$_get[' moon '];         1.eval ("\ $moon = $moon;"); 2.assert ("\ $moon = $moon;");} */ //Regular Code Execution/*parameter one injects echo $regexp = $_get[' reg ']; $String = ' <php>phpinfo () </php> ';//preg_replace ("/<php> (. *?) $regexp "," \\1 ", $String); Var_dump (Preg_replace ("/<php> (. *?) " $regexp "," \\1 ", $String)); */ //parameter two injects//preg_replace ("/moon/e", $_get[' moon '], "I love Moon");//Parameter three-injectionPreg_replace("/\s*\[php\" (. +?) \[\/php\]\s*/ies "," \\1 ",$_get[' Moon ']); ?>

PHP Code Audit Code Execution injection

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.