繁体   English   中英

Bash脚本在php脚本中执行

[英]Bash script being executed in a php script

我知道还有与此相关的其他帖子,但是我已经尝试了所有被标记为解决方案的解决方案和修补程序,但是它们都不适合我。

如标题所述,我正在尝试使php脚本在加载到Web服务器(Apache)中时执行bash脚本。

正如我在另一篇文章中所看到的,我正在使用包装器,因此这是wrapper.c:

#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>

int main (int argc, char *argv[]) {
    setuid (0);
    system ("/bin/sh /var/www/html/scrip/debugport/testversion.sh");
    return 0;
}

这是testversion.sh脚本:

#!/bin/bash
screen -S skywars -X stuff "stop
"
cd /tmp
pid=$(fuser -n tcp 12321 | awk '{print $1}')
kill -9 $pid

这是我正在使用的php代码:

<?php
    $message=shell_exec("./var/www/html/scrip/php_root");
    print_r($message);
?>  

当我执行./php_root(已编译的wrapper.c)时,一切正常,但是当我尝试从Web服务器加载该脚本时,它根本无法工作。

这可能与权限有关,但是我使用每个权限的方式与本帖子的解决方案完全相同: 通过PHP执行root命令

无论用户执行什么操作,包装程序都应使脚本以root用户身份执行,但是它不起作用。

多谢你们。

尝试检查对脚本的访问。 可能是Web服务器的用户无法运行您的bash脚本。

我最近发布了一个项目,该项目使PHP可以获取真实的Bash shell并与之交互(作为用户:apache / www-data或root(如果需要))。 在这里获取它: https : //github.com/merlinthemagic/MTS

下载后,您只需使用以下代码:

//Setting the second argument in getShell():
//true will return a shell with root
//false will return a shell with the php execution user
$shell    = \MTS\Factories::getDevices()->getLocalHost()->getShell('bash', true);
$return1  = $shell->exeCmd('/full/path/to/script.sh');

不需要包装器。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM