0
votes

I am trying to execute the following command through PHP using shell_exec() function:

sudo -u USERNAME -pPASSWORD echo "SOME-STRING" > /dev/tcp/127.0.0.1/64444

but nothing happens (if I copy/paste it manually to the terminal it works). There is also nothing in the $output of the shell_exec() function.

So with that command I am trying to send a string over TCP through a different user with sudo privileges.

EDIT #1: The full PHP command looks like this:

shell_exec('sudo -u USERNAME -pPASSWORD echo "RLSET|79-192.168.1.33-0-1" > /dev/tcp/127.0.0.1/64444');

EDIT #2: I've also checked the phpinfo() function and safe_mode is off also the shell_exec() function is not on the disallowed functions list.

EDIT #4: My PHP PATH variable contains the following locations:

/usr/local/bin:/usr/bin:/bin

I'm lost here, any and all help would be appreciated.

3
No this is being executed locally to a local server that is always listening for TCP connections. - erikvimz

3 Answers

1
votes

Scape your quotes put your full command path:

 shell_exec("sudo -u USERNAME -pPASSWORD echo \"FULL-PATH-COMMAND\" > /dev/tcp/127.0.0.1/64444")
0
votes

maybe your binary (sudo, echo, ...) is not in the PATH env variable :

putenv('PATH', '/bin:/sbin:/usr/bin:/usr/sbin:') // etc...
0
votes

Have you tried putting a space after -p?

So that should be

shell_exec('sudo -u USERNAME -p PASSWORD echo "RLSET|79-192.168.1.33-0-1" > /dev/tcp/127.0.0.1/64444');

I just tried some commands here on my own machine.

I tried

sudo -u USERNAME -p PASSWORD ls

and it works but when I tried

sudo -u USERNAME -pPASSWORD ls

It give me the usage information.