从 PHP 调用 Perl 程序并打印输出
Calling a Perl program from PHP and printing the output
对于一个学校项目,我想尝试扫描网站的漏洞,并在页面上显示响应。
为此,我正在尝试使用 Uniscan。
我尝试了很多方法来获得任何回复,但没有成功。
这是我现在拥有的:
<?php
echo '<pre>';
// Outputs all the result of shellcommand "ls", and returns
// the last output line into $last_line. Stores the return value
// of the shell command in $retval.
$last_line = system('perl uniscan.pl -u https://domain.nl/ -qweds;ls', $ret$
// Printing additional info
echo '</pre>
<hr />Last line of the output: ' . $last_line . '
<hr />Return value: ' . $retval;
?>
这是响应,您唯一看到的是'ls'命令的响应。
希望有人能帮助我。
我认为您从 http://php.net/manual/en/function.system.php.
复制的代码很糟糕
除此之外,您的代码还有语法错误。您将 $ret
传递给系统,但试图打印 $retval
。右括号也不见了。
试试这个:
$last_line = system('/usr/bin/perl uniscan.pl -u https://domain.nl/ -qweds', $retval);
请注意,我提供了 perl 解释器的绝对路径。
问题在于 www-data 用户没有 运行 该脚本的权限。
所以当我像这样在 sudoers 文件中给他权限时:
www-data ALL = NOPASSWD: /var/www/html/Uniscan/uniscan.pl
一切正常!
对于一个学校项目,我想尝试扫描网站的漏洞,并在页面上显示响应。
为此,我正在尝试使用 Uniscan。
我尝试了很多方法来获得任何回复,但没有成功。
这是我现在拥有的:
<?php
echo '<pre>';
// Outputs all the result of shellcommand "ls", and returns
// the last output line into $last_line. Stores the return value
// of the shell command in $retval.
$last_line = system('perl uniscan.pl -u https://domain.nl/ -qweds;ls', $ret$
// Printing additional info
echo '</pre>
<hr />Last line of the output: ' . $last_line . '
<hr />Return value: ' . $retval;
?>
这是响应,您唯一看到的是'ls'命令的响应。
希望有人能帮助我。
我认为您从 http://php.net/manual/en/function.system.php.
复制的代码很糟糕除此之外,您的代码还有语法错误。您将 $ret
传递给系统,但试图打印 $retval
。右括号也不见了。
试试这个:
$last_line = system('/usr/bin/perl uniscan.pl -u https://domain.nl/ -qweds', $retval);
请注意,我提供了 perl 解释器的绝对路径。
问题在于 www-data 用户没有 运行 该脚本的权限。
所以当我像这样在 sudoers 文件中给他权限时:
www-data ALL = NOPASSWD: /var/www/html/Uniscan/uniscan.pl
一切正常!