PHP代码审计之代码执行(三)
call_user_func()
用法:
call_user_func ( callable $callback [, mixed $parameter [, mixed $... ]] ) : mixed
第一个参数 callback 是被调用的回调函数,其余参数是回调函数的参数。
示例:
<?php
function barber($type)
{
echo "You wanted a $type haircut, no problem\n";
}
call_user_func('barber', "mushroom");
call_user_func('barber', "shave");
?>
输出结果:
You wanted a mushroom haircut, no problem
You wanted a shave haircut, no problem
利用方法:
<?php
function shell($a){
return system($a);
}
$cmd = 'whoami';
call_user_func('shell',$cmd);
?>
call_user_func_array()
call_user_func_array ( callable $callback , array $param_arr ) : mixed
把第一个参数作为回调函数(callback)调用,把参数数组作(param_arr)为回调函数的的参数传入。
示例:
<?php
$func = function($arg1, $arg2) {
return $arg1 * $arg2;};
var_dump(call_user_func_array($func, array(2, 4)));
?>
输出结果:
int 8
利用代码:
<?php
function shell($a){
return system($a);
}
$cmd = array('whoami');
call_user_func_array('shell',$cmd);
?>