【发布时间】:2021-04-29 18:20:05
【问题描述】:
我一直试图弄清楚为什么我不能让 NMap 给我任何类型的输出,甚至不能通过 PHP 解决这个问题。
到目前为止我尝试过的事情:
// this doesn't return anything because it's wrong
$output = passthru('nmap -V');
echo $output;
// this returns a negated integer value
passthru('nmap -V', $output);
echo $output;
// this doesn't return anything either
$stream = popen('C:\nmap -V', 'r');
while (!feof($stream))
{
$buffer = fread($stream, 1024);
echo $buffer;
}
pclose($stream);
// this doesn't do anything as well
$output = system('C:\nmap -V');
echo $output;
// this does nothing also...
ob_start(); // start output buffering
fpassthru('C:\nmap -V'); // flush COMPLETE output of nmap
$output = ob_get_contents(); // capture output buffer contents
ob_end_clean(); // shutdown output buffers
echo $output; // echo it
.
// okay, how about we try a 'proc_open()'?
// nope, this doesn't work either. I just get a value of "command returned -1073741515"
$descriptorspec = array(
0 => array("pipe", "r"), // stdin is a pipe that the child will read from
1 => array("pipe", "w"), // stdout is a pipe that the child will write to
2 => array("file", "errors/errors.txt", "a") // stderr is a file to write to
);
$cwd = 'errors';
$env = array('some_option' => 'aeiou');
$process = proc_open('C:/nmap -V', $descriptorspec, $pipes, $cwd, $env);
if (is_resource($process))
{
// $pipes now looks like this:
// 0 => writeable handle connected to child stdin
// 1 => readable handle connected to child stdout
// Any error output will be appended to /errors/errors.txt
fwrite($pipes[0], '<?php print_r($_ENV); ?>');
fclose($pipes[0]);
echo stream_get_contents($pipes[1]);
fclose($pipes[1]);
// It is important that you close any pipes before calling
// proc_close in order to avoid a deadlock
$return_value = proc_close($process);
echo "command returned $return_value\n";
}
还有许多其他人,但我从$output 得到绝对NOTHING。我也做了很多谷歌搜索,但我仍然无法弄清楚。许多示例似乎也适用于 Linux,但无济于事。
谢谢。
【问题讨论】:
-
我建议重新阅读docs for
passthru(),因为该函数在任何情况下都不会返回任何数据。 -
好的,所以我们可以删除
passthru。 -
这能回答你的问题吗? How to use Nmap in PHP exec
-
shell_exec()也不一定返回任何内容。 -
@esqew,不。这也不起作用,这是我已经在 Google 搜索中找到的。
标签: php shell-exec nmap