shell_exec not working with nmap command

爱⌒轻易说出口 提交于 2020-01-11 04:04:08

问题


I got a problem with the shell_exec php function, here is a example code:

$output = shell_exec('nmap -PS80 -n -oG - --send-ip 11.11.11.11');

if ( $output )
{
     echo "Output found...";
}
else
{
     var_dump( $output );
}

It does return: NULL, but when I change the shell_exec command to the following:

$output = shell_exec('echo 1');

then the output is: Output found... so its working properly, and there is no problems with permissions or safe mode (which is off , by the way).

It is having a problems with execute the nmap command. I've check that command in the shell command line in putty and its working properly:

# nmap -PS80 -n -oG - --send-ip 11.11.11.11
# Nmap 5.61TEST2 scan initiated Tue Feb 28 13:55:41 2012 as: nmap -PS80 -n -oG - --send-ip 11.11.11.11
# Nmap done at Tue Feb 28 13:55:43 2012 -- 1 IP address (0 hosts up) scanned in 0.04 seconds

So where is the problem?


回答1:


Try to specify full path to nmap like /usr/local/bin/nmap. PHP might not know about nmap location. Enjoy!




回答2:


You might want to resort to exec() instead, which gives you greater error diagnostics:

// Capture outout from STDERR as well
$command = "nmap ... 2>&1";

exec($command, $output, $return_var);

// If return code is not zero, the command failed
if ($return_var != 0) 
{
    // dump all output, including error messages
    var_dump($output);
}


来源:https://stackoverflow.com/questions/9483227/shell-exec-not-working-with-nmap-command

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!