【问题标题】:Safe executing shell scripts; escaping vars before execution安全执行 shell 脚本;在执行前转义变量
【发布时间】:2010-04-12 19:03:43
【问题描述】:

假设我们有一个简单的 php 脚本,它应该从 $_GET 数组中获取 ssh_hostssh_usernamessh_port,并尝试使用此参数连接到 SSH。

$port      = escapeshellcmd($_GET['ssh_port']);
$host      = escapeshellcmd($_GET['ssh_host']);
$username  = escapeshellcmd($_GET['ssh_username']);

$answer = shell_exec("ssh -p " . $port . " " . $user . "@" . $host);

escapeshellcmd() 够用还是我需要一些更棘手的东西? 或者我应该在这个例子中使用escapeshellarg()

谢谢。

【问题讨论】:

    标签: php security shell


    【解决方案1】:

    我想说这就是 escapeshellarg 函数的创建目的——所以,为了转义参数,你应该使用它。

    基本上:


    引用他们各自的文件:

    escapeshellcmd():
    此函数应用于确保来自用户输入的任何数据在传递给exec()system() 函数或反引号运算符之前被转义。

    escapeshellarg() :
    此函数应用于将单个参数转义为来自用户输入的 shell 函数。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-04-20
      • 2013-09-15
      • 2017-12-05
      • 2012-07-23
      • 1970-01-01
      • 2014-05-15
      • 2014-03-26
      相关资源
      最近更新 更多