Arbitrary code Execution Vulnerability

Source: Internet
Author: User
Tags assert phpinfo reflection
Background Introduction :When applied to a function that calls some strings into code, no consideration is given to whether the user can control the string, resulting in a code injection vulnerability.
Correlation function:PHP eval (), assert () python exec () Java does not have a function similar to the previous two, but there are reflection mechanisms, and there are expression engines based on the reflection mechanism, such as 0GNL, Spel, Mvel, etc.

The main function that can cause code injection in--php--

①eval ()


<span style= "FONT-SIZE:14PX;" ><?php
$data = $_get[' data '];
Eval ($ret = $data);
echo $ret
?></span>
$data=phpinfo (), you can display the contents of the phpinfo.php file
②assert (), like the former, executes a string as code.
③preg_replace () +/e mode

<?php
$data = $_get[' data '];
Preg_replace ('/<data> (. *) <\/data>/e ', ' $ret = ' \\1 '; ', $data);
? >
Echo $reat
Make a data=<data>${phpinfo ()}</data>
Instance:
④unserialize () (deserialization function)
Repair plan:For the Eval () function, it is important to ensure that the user is not easily exposed to eval parameters, if the contact must use single quotes wrapped controllable code, and before inserting the addslashes
<?php
$data = addslashes ($data);
Eval ("$data = Deal (' $data ')");
? >
For the Preg_replace () function, you can discard the use of the/e modifier or use the Preg_replace_callback () function instead. If you must use this function, make sure that the second argument is wrapped in single quotes for the object that matches the regular match.

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.