1

I know there are other posts about this, but I have tried out all the solutions and fixes that were marked as solution and none of them works for me.

As the title says, I am trying to make a php script execute a bash script when being loaded in a web server (apache).

I am using a wrapper as I saw in another post, so here is the 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;
}

This is the testversion.sh script:

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

And this is the php code that I am using:

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

When I do ./php_root (which is the compiled wrapper.c) everything works fine, but when I try to load it from a web server the script doesn't work at all.

It's probably something to do with the permissions, but I used every permission exactly like in this post's solution: Execute root commands via PHP

The wrapper is supposed to make the script be executed as root no matter what user executes it, but it doesn't work.

Thanks guys.

Community
  • 1
  • 1
JR1
  • 23
  • 7

2 Answers2

0

Try check access to script. May be user of web-server can not run your bash script.

I IL
  • 13
  • 4
  • [It's not hard to earn enough rep to make comments.](http://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead) – Jay Blanchard Aug 07 '15 at 20:16
0

I recently published a project that allows PHP to obtain and interact with a real Bash shell (as user: apache/www-data or root if needed). Get it here: https://github.com/merlinthemagic/MTS

After downloading you would simply use the following code:

//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');

there is no need for the wrapper.

MerlinTheMagic
  • 575
  • 5
  • 16