我可以在屏幕上显示的 url 部分注入 php 代码吗?

Can I inject php code in the url in part thats displayed on screen?

嘿,这是我非常简单的代码:

<?php
$test= $_GET['test'];
echo $test;

?>

在 url 我写了这个:

test.php?test=system('dir')  

为什么不执行命令,为什么不显示?

您通过 URL 传递字符串,回显不会执行字符串。你需要写:

eval($test)

执行它。所以你现在的代码不能执行PHP代码,但是可以用来执行JS代码。你应该过滤它。

查看有关过滤器的文档以了解有关过滤的更多信息:http://php.net/manual/en/intro.filter.php. You could also use such a library: https://github.com/ircmaxell/filterus。如果您正在使用某些框架,请检查集成的过滤功能/方法。

您在 URL 中将命令作为字符串传递。此外,您只是 "echo-ing" 屏幕上的字符串。虽然回显可能包含转义的 php 代码,即 运行,但您可能想要评估和 运行 命令。

要实际 运行 命令,您可以使用以下任一命令:

确保阅读 safe-mode-exec 的文档。 特别是以下位:

safe_mode_exec_dir string If PHP is used in safe mode, system() and the other functions executing system programs refuse to start programs that are not in this directory. You have to use / as directory separator on all environments including Windows.