简体   繁体   中英

when using shell_exec() function in PHP nothing happens

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.

忽略引号,可以使用完整的命令路径:

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

也许您的二进制文件( sudoecho ,...)不在PATH env变量中:

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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