Shellshock 错误会影响 ZSH 吗?

mar*_*lar 38 bash zsh shellshock

请问弹震击的错误影响ZSH?

升级 Bash 是唯一的解决方案吗?

men*_*nte 36

No, it doesn't affect ZSH.

You still MUST update bash as most of the system scripts are written for bash and vulnerable to the shellshock bug.

To test your ZSH do this:

env x='() { :;}; echo vulnerable' zsh -c 'echo hello'
Run Code Online (Sandbox Code Playgroud)

What exactly does this code do?

  1. env x='() { :;}; echo vulnerable' creates an environment variable with known bug using command in the end of variable
  2. zsh -c 'echo hello' launches ZSH shell with simple hello (and evaluating all env variables including x)

If you see output:

vulnerable
hello
Run Code Online (Sandbox Code Playgroud)

Then your ZSH is vulnerable. Mine (5.0.2) is not:

$ env x='() { :;}; echo vulnerable' zsh -c 'echo hello'
hello
Run Code Online (Sandbox Code Playgroud)

  • @Dineshkumar:是的,您仍然应该担心并修补。原因是即使*你*正在使用zsh,其他程序(提到dhcp,许多PHP应用程序可能会这样做,典型Linux机器上的许多其他程序和脚本)仍然会调用bash。(事实上​​,他们不应该,但这已经成为一个坏习惯。) (16认同)
  • @stephenmurdoch Ubuntu 10.10 已经很老了,并且已经超过 2 年没有得到支持了...... (2认同)
  • @Ghanima:调用`bash` 是系统实用程序的坏习惯,因为不能保证安装 bash;`/bin/sh` 是标准的 shell,需要是一个正确的 POSIX shell 解释器。 (2认同)
  • fwiw - 当 bash 作为 /bin/sh 运行时,它作为与 POSIX 兼容的 shell 运行。然而,在这种模式下,它也有错误。`env x='() { :;}; 回声脆弱' sh -c '回声你好'` (2认同)

小智 6

From this link:

You can determine if you are vulnerable to the original problem in CVE-2014-6271 by executing this test:

env x='() { :;}; echo vulnerable' bash -c 'echo hello'
Run Code Online (Sandbox Code Playgroud)

If you see the word vulnerable in the output of that command your bash is vulnerable and you should update. Below is a vulnerable version from OS X 10.8.5:

env x='() { :;}; echo vulnerable' bash -c 'echo hello'
vulnerable
hello
Run Code Online (Sandbox Code Playgroud)

The following output is an example of a non-vulnerable bash version.

$ env x='() { :;}; echo vulnerable' bash -c 'echo hello'
bash: warning: x: ignoring function definition attempt
bash: error importing function definition for `x'
hello
Run Code Online (Sandbox Code Playgroud)

  • 请注意,有一个 [followup](https://twitter.com/taviso/status/514887394294652929):``env X='() { (a)=>\' bash -c "echo date"``在打补丁的 bash 上,尽管抛出了很多错误,但会生成一个名为“echo”的文件,其中包含日期。我不想知道为什么。 (9认同)
  • @vectorsize `zsh` 在其核心 * 不* 使用 `bash`。`bash` 在您的示例中被显式调用。您使用哪个 shell 来运行这些行并不重要。此漏洞影响新启动的 bash shell,而不是运行它的 shell。 (5认同)
  • @Adaephon 所以有人想用“$SHELL”替换示例中的“bash”。 (2认同)

Vol*_*gel 6

二进制不受影响

它不会影响zshshell 可执行文件,因为它的源代码从未包含错误。和
之间有很多相似之处,但它们是相互独立地实现的。相同的功能以两种不同的方式实现,并且 - 在这种情况下更重要 - 通常有不同的错误。bashzsh

但交互式使用是

它确实间接地影响与zsh终端中 shell 的交互工作,几乎与使用bash.

的使用bash是如此普遍,以至于人们难以避免称之为它。

需要避免的太多用途

  • 您知道并希望使用的脚本zsh,但实际上包含bash.
  • 许多#!/bin/bash用于指定bash为解释器的 shell 脚本。
  • 您假设的许多命令是二进制文件,但它们是 shell 脚本,其中一些使用bash.

  • 在许多显式执行 shell 的地方,bash可能会使用,并且可能需要。

    • 像复杂的xargs命令,或git涉及参数的别名
    • 终端模拟器的默认 shell
    • 你 sudo 的用户 shell
    • 等等。