0-day analysis by a web Editor in South Korea

Source: Internet
Author: User
Tags ereg upload php

This editor is widely used in South Korea. It is used in www. hani. co. kr, www. kbs. co. kr, and www.joinsmsn.com. Because it involves many sites, the specific program name cannot be directly released. The following is a brief analysis of the problem code.
 
The main problem is that the upload class is not rigorous when verifying the file extension, which allows attackers to upload PHP files. By Ca3tie1
 
First look at the upload function:
If ($ file-> getFileSize ("Filedata")> 0 ){
$ Save_name = $ req-> get ("save_name ");
If ($ save_name = null | $ save_name = "")
$ Save_name = $ file-> nameUnique ('Ph _');
$ File_name = $ file-> getFileName ("Filedata ");
If ($ file-> isUploadable ($ file_name) // verify the extension. if the verification fails, the extension is set to tmp.
$ File_ext = $ file-> name2Ext ($ file_name); // retrieve the extension
Else
$ File_ext = 'tmp ';
$ Save_name = uniqid (date ('ymd _'));
$ File_server = $ file-> file_Copy ("Filedata", $ savearea. $ save_name. '.'. $ file_ext );
}
 
Follow up with the isUploadable function:
 
Function isUploadable ($ fileName ){
Return! (RainUtil: find ($ this-> forbidden_extension_patten, $ fileName ));
}
// Forbidden_extension_patten is involved here, which is defined as: var $ forbidden_extension_patten = '(html | htm | php | php3 | cgi | phtml | shtml | jsp | asp | exe | com | dll) $ ';
 
Continue to follow up the find function: www.2cto.com
 
Function find ($ patternStr, $ str, $ reg = Array ()){
Return (ereg ($ patternStr, $ str, $ reg ))? True: false; // the problem is here. The ereg function is case sensitive! Verification can be bypassed here as long as the file name extension we submit is pHp.
}
 
After the extension verification is bypassed, continue to view the code for retrieving the extension in the upload function:
 
$ File_ext = $ file-> name2Ext ($ file_name );
 
Follow up with the name2Ext function:
 
Function name2Ext ($ fileName ){
$ Tar_file_extension = "";
If ($ fileName! = ""){
If (ereg ("\. ([^ \.] +) $", $ fileName, $ tmp_reg ))
$ Tar_file_extension = substr (strtolower ($ tmp_reg [1]), 0, 4); // the file name extension is converted to lowercase !!
Else
$ Tar_file_extension = "tmp ";
} Else
$ Tar_file_extension = "";
Return $ tar_file_extension;
}
Perfect bypass. This is a program written by Korean experts. Of course, it cannot be compared with that in China. If the analysis is incorrect, we hope to point it out! Thank you!

From the space of Ca3tie1

Related Article

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.