php function pcntl_exec("/bin/sh", "/bin/sh")

686 views Asked by At

According to the php manual, the function pcntl_exec is equal to the syscall execve.

So I think

pcntl_exec("/bin/sh", ["/bin/sh"]);

should do the same thing like:

#!/bin/sh
/bin/sh

However I got the result: # /bin/sh: 1: Syntax error: ")" unexpected

Why?

php version 7.4.3(cli) Zend Engine v3.4.0

1

There are 1 answers

0
Sammitch On BEST ANSWER

This is incorrect:

should do the same thing like:

#!/bin/sh
/bin/sh

It is equivalent to running the command /bin/sh /bin/sh which will attempt to interpret /bin/sh as a shell script.

The actual equivalent of what you want would be:

pcntl_exec("/bin/sh", ["-c", "/bin/sh"]);