PHP或Apache? EXEC,popen这,制度和proc_open命令不执行任何命令甚至没有LS [英] php or apache? exec, popen, system and proc_open commands do not execute any command not even ls

查看:1134
本文介绍了PHP或Apache? EXEC,popen这,制度和proc_open命令不执行任何命令甚至没有LS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是从我的PHP网页执行任意命令。

解决了一半,我得到了我的pythonscript运行,但在进一步的pythonscript没有权限来执行它的模块

但i'm开始认为这个问题是与Apache和PHP的不是?我试图运行pythonscript,实际上是什么i'm要在结束时运行,那么它似乎运行,但是当脚本试图访问一个txt文件看起来像这样停止

  [标准输出] =>
[标准错误] =>回溯(最近通话最后一个):
 文件pythontest.py,4号线,在? F =打开((路径)/temp.txt,W)
 IO错误:[错误13]权限被拒绝:'(路径)/temp.txt

我已经尝试了所有不同类型的执行方法,我能找到的exec,系统的popen,proc_open几乎没有跑,我可以从系统中的字符串(PWD),但系统(LS)返回一个数字127或者126.我也试着运行编译的C程序(code以下)Exec将返回一个对象阵列,但系统将只返回127或126 LS一样。

此外,我试图让价值观出了阵列的对象?从EXEC但它没有返回值,如果我PHP的print_r的阵列的页面加载不需额外

PHP的输出(code以下) - >答:OUT1:126,T [0]:,strlen的出:5,出:数组,T:
不管有多少争论其实我放!

要LS的完整路径给出了126,只是LS给出数127

我已经测试chmod命令完全权限的所有文件,从page.php测试程序,但它仍然提供同样的输出

PHP安全模式关闭

 回声'< pre>';
的print_r(执行(LS))
呼应'< / pre>';

返回

 阵列

    [标准输出] =>
    [标准错误] => SH:在/ var / www / html等/ grndb / upscgenesearch /测试1:权限被拒绝    [返回] => 126

为什么它给我的权限被拒绝时,test1的程序有充分的权限?

 < PHP
美元=系统(/斌/ LS,$ OUT1);
回声一个;回声$一个;
回声,OUT1:回声$ OUT1;
$ T = EXEC('PWD / test1的AA HH 11',$出);的foreach($ T为&放大器; $值){
    回波($值);
}回声,T [0]:回声$ T [0];
回声,strlen的一声:;回声的strlen($出);
回声,指出:;回声$出;
回声,T:回声$吨;
?>

C源$ C ​​$ C

  INT主(INT ARGC,CHAR *的argv [])
{
INT I;对于(i = 0; I< ARGC,我++)
的printf(ARG%D:%S \\ n,我的argv [I]);
返回0;
}


解决方案

下面是另一个功能添加到列表中的:)

  / **
 *执行的程序,并等待其完成,同时管考虑。
 * @参数字符串$ cmd命令行来执行,包括任何参数。
 *标准输入字符串@param $输入数据。
 *标准输出,标准错误和回归的@返回数组。
 * @copyright 2011 K2F框架/ COVAC软件
 * /
函数执行(CMD $,$标准输入= NULL){
    $proc=proc_open($cmd,array(0=>array('pipe','r'),1=>array('pipe','w'),2=>array('pipe','w')),$pipes);
    FWRITE($管[0],$标准输入); FCLOSE($管[0]);
    $标准输出= stream_get_contents($管[1]); FCLOSE($管[1]);
    $标准错误= stream_get_contents($管[2]); FCLOSE($管[2]);
    $收益率= proc_close($ PROC);
    返回阵列(标准输出= GT; $标准输出,'标准错误'=> $标准错误,回归= GT; $回报);
}

使用您的情况举例:

 回声'< pre>';
的print_r(执行('LS'));
呼应'< / pre>';

功能上面提供了比直接使用PHP的人更多的功能。它可以帮助你在调试,但它更适合于产品code。

在一般情况下,这是你应该知道是什么了:


  • 您不是在安全模式

  • 您的可执行文件确实存在

  • 您的可执行文件的的可运行 - 知道FTP客户端通常使用ASCII /文本模式,改变上传文件CRLFs从而破坏它们

  • 请务必于chmod可执行至少755

My problem is with executing any command from my php homepage

Half solved, I got my pythonscript running but futher on the pythonscript does not have permission to execute its modules

but i´m starting to think that the problem is with apache and not php? i tried to run a pythonscript that is actually what i´m going to run in the end, then it seems to run but stops when the script tries to access a txt file looking like this

[stdout] =>
[stderr] => Traceback (most recent call last): 
 File "pythontest.py", line 4, in ? f = open("(path)/temp.txt", "w") 
 IOError: [Errno 13] Permission denied: '(path)/temp.txt'

I have tried all different kind of execution methods that i could find exec, system, popen, proc_open almost nothing runs, i can get a string from system("pwd") but system("ls") returns a number 127 or 126. I also tried to run a compiled c program (code below) exec will return an object "Array" but system will only return 127 or 126 as ls does.

Also I tried to get the values out of the "Array" object? from exec but it returns nothing, if I php print_R Array the page won´t load.

the php output is (code below)-> a: , out1: 126, t[[0]: , strlen out: 5, out: Array, t: no matter how many arguments i actually put in!

the full path to ls gives 126 and just "ls" gives the number 127

i have tested to chmod all files to full permission, from the page.php to test program but it still gives the same output

php safe mode is off

echo '<pre>';
print_r(execute('ls'))
echo '</pre>';

returns

array
(
    [stdout] => 
    [stderr] => sh: /var/www/html/grndb/upscgenesearch/test1: Permission denied

    [return] => 126
)

why does it give me Permission denied when the test1 program has full permission?

<?php
$a = system("/bin/ls",$out1);
echo "a: "; echo $a;
echo ", out1: "; echo $out1;
$t = exec('pwd/test1 aa hh 11',$out);

foreach ($t as &$value) {
    echo ($value);
}

echo ", t[[0]: "; echo $t[0]; 
echo ", strlen out: "; echo strlen($out);
echo ", out: "; echo $out; 
echo ", t: "; echo $t;
?>

C source code

int main(int argc, char *argv[])
{
int i;

for(i = 0; i < argc; i++)
printf("arg %d: %s\n", i, argv[i]);
return 0;
}

解决方案

Here's another functions to add to the list :)

/**
 * Executes a program and waits for it to finish, taking pipes into account.
 * @param string $cmd Command line to execute, including any arguments.
 * @param string $input Data for standard input.
 * @return array Array of "stdout", "stderr" and "return".
 * @copyright 2011 K2F Framework / Covac Software
 */
function execute($cmd,$stdin=null){
    $proc=proc_open($cmd,array(0=>array('pipe','r'),1=>array('pipe','w'),2=>array('pipe','w')),$pipes);
    fwrite($pipes[0],$stdin);                      fclose($pipes[0]);
    $stdout=stream_get_contents($pipes[1]);        fclose($pipes[1]);
    $stderr=stream_get_contents($pipes[2]);        fclose($pipes[2]);
    $return=proc_close($proc);
    return array( 'stdout'=>$stdout, 'stderr'=>$stderr, 'return'=>$return );
}

Example of use for your case:

echo '<pre>';
print_r(execute('ls'));
echo '</pre>';

The function above is offers more features than using the PHP ones directly. It could help you at debugging, though it's more intended for production code.

In general, this is what you should be aware off:

  • You're not under safe mode
  • Your executable does exist
  • Your executable is runnable - know that FTP clients often use ASCII/Text mode, changing CRLFs in uploaded files thus corrupting them
  • Be sure to chmod your executable at least 755

这篇关于PHP或Apache? EXEC,popen这,制度和proc_open命令不执行任何命令甚至没有LS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆