PHP代码审计之代码执行(三)

本文深入探讨PHP中call_user_func()和call_user_func_array()函数的使用方法与潜在的安全风险,通过实例展示如何利用这些函数执行系统命令,揭示代码审计中的关键点。

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);
?>
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值