技術(shù)細(xì)節(jié)
wordpress的權(quán)限處理機(jī)制主要是通過給不同角色提供不同的功能來實(shí)現(xiàn)的,當(dāng)商鋪管理員角色被定義之后,它便會(huì)給這個(gè)角色分配edit_users功能,這樣他們就可以直接管理商鋪的客戶賬號(hào)了。整個(gè)權(quán)限分配過程發(fā)生在插件插件餓的安裝過程當(dāng)中。woocommerce/includes/class-wc-install.php:
//Shop manager role.add_role( 'shop_manager', // Internal name of the new role 'Shop manager', // The label for displaying array( // Capabilities ? 'read_private_posts' => true, 'edit_users' => true, 'edit_posts' => true, ? ));
角色權(quán)限信息會(huì)以WordPress核心設(shè)置存儲(chǔ)在數(shù)據(jù)庫(kù)中,這也就意味著用戶角色現(xiàn)在已經(jīng)獨(dú)立于插件了,即使插件不啟用,也不會(huì)影響到相關(guān)的角色權(quán)限。
當(dāng)一名通過身份驗(yàn)證的用戶嘗試修改其他用戶信息時(shí),便會(huì)調(diào)用current_user_can()函數(shù),然后確保只有特權(quán)用戶可以執(zhí)行這種操作。current_user_can()函數(shù)調(diào)用樣例:
$target_user_id= $_GET['target_user_id'];if(current_user_can('edit_user',$target_user_id)) { edit_user($target_user_id);}
調(diào)用的驗(yàn)證邏輯如下:這個(gè)用戶想使用$target_user_id這個(gè)ID來修改特定的用戶,他是否有權(quán)限執(zhí)行?
默認(rèn)配置下,edit_users功能允許有權(quán)限的用戶(例如商鋪管理員)來編輯其他用戶,甚至是管理員用戶,然后執(zhí)行類似密碼更新這樣的操作。出于安全因素考慮,WooCommerce需要指定商鋪管理員是否能夠編輯用戶,因此,插件需要增加meta權(quán)限功能。Meta功能可以被current_user_can()調(diào)用。默認(rèn)行為下函數(shù)返回的值為true,但meta權(quán)限函數(shù)返回的值可以決定當(dāng)前用戶是否可以執(zhí)行這樣的操作。下面給出的是WooCommerce meta權(quán)限過濾器的抽象函數(shù)代碼:
function disallow_editing_of_admins( $capability, $target_user_id ) { // If the user is an admin return false anddisallow the action if($capability == "edit_user"&& user_is_admin($target_user_id)) { return false; } else { return true; }}add_filter('map_meta_cap', 'disallow_editing_of_admins');
比如說,當(dāng)current_user_can(‘edit_user’, 1)被調(diào)用時(shí),過濾器將會(huì)判斷ID為1 ($target_user_id)的用戶是否是管理員,并根據(jù)結(jié)果來決定是否允許用戶操作。
商鋪管理員禁用插件
默認(rèn)情況下,只有管理員可以禁用插件。但是這個(gè)漏洞允許商鋪管理員刪除服務(wù)器上的任意可寫文件,所以我們我們額可以通過刪除WooCommerce的主文件-woocommerce.php來禁止WordPress加載該插件。
這個(gè)文件刪除漏洞存在于WooCommerce的日志記錄功能中,日志會(huì)以.log文件的形式存儲(chǔ)在wp-content目錄中。當(dāng)商鋪管理員想要?jiǎng)h除日志文件時(shí),他需要以GET參數(shù)來提交文件名。下面顯示的代碼段就是存在漏洞的部分:
woocommerce/includes/admin/class-wc-admin-status.php
class WC_Admin_Status{ public static function remove_log() { ? $log_handler = newWC_Log_Handler_File(); $log_handler->remove(wp_unslash($_REQUEST['handle']));}
woocommerce/includes/log-handlers/class-wc-log-handler-file.php
class WC_Log_Handler_File extends WC_Log_Handler{ public function remove($handle) { ? $file = trailingslashit(WC_LOG_DIR) .$handle; ?unlink($file);
這里的問題就在于,文件名($handle)會(huì)被添加到日志目錄(wp-content/wc-logs/)后,然后傳遞給unlink()函數(shù)。在設(shè)置“$handle../../plugins/woocommerce-3.4.5/woocommerce.php”時(shí),文件wp-content/wc-logs/../../plugins/woocommerce-3.4.5/woocommerce.php將會(huì)被刪除,并導(dǎo)致WooCommerce被禁用。