PHP system()函数-是否使用shell来执行命令


PHP system() function - does it use shell to execute command?

我读了一篇相关的文章,我得到的印象是php中的system()函数不使用shell。但后来看到下面的例子张贴在owasp -示例6的页面:

下面的PHP代码片段容易受到命令注入攻击:

<?php
print("Please specify the name of the file to delete");
print("<p>");
$file=$_GET['filename'];
system("rm $file");
?>

下面的请求和响应是一个成功攻击的例子:请求

http://127.0.0.1/delete.php?filename=bob.txt;id
反应

Please specify the name of the file to delete
uid=33(www-data) gid=33(www-data) groups=33(www-data) 

如果没有shell,为什么系统会识别分号?或者system()函数在php中的实现以这种方式识别分号吗?

它确实使用了shell。在你链接的问题中,我没有看到任何答案说它没有。

文档说:

system()就像该函数的C版本,它执行给定的命令并输出结果。

由于C函数使用shell,所以PHP函数也使用shell。

文档有点误导,因为C函数不返回命令的任何输出,而PHP函数返回输出的最后一行。

是的,这个例子将告诉你:

echo system("echo $0");