【问题标题】:How do I upgrade Bash in Mac OSX Snow Leopard [and set it the correct path]?如何在 Mac OSX Snow Leopard 中升级 Bash [并设置正确的路径]?
【发布时间】:2014-11-22 16:30:10
【问题描述】:

鉴于最近出现的 bash - Shellshock 错误,我想在我的 Mac OS X Snow Leopard (10.6.8) 中更新我的 Bash(和 Sh)程序。我故意使用 10.6.8,所以我现在不想更新到更新版本的 OS X。

我已阅读此问答 - How do I upgrade Bash in Mac OSX Mountain Lion and set it the correct path? 但它对我不起作用,因为我没有安装 [home?]brew(或 Xcode,或任何编译器等)。我刚刚开始在 Max OS X 平台上进行编程。

顺便说一句,当我在终端输入 brew update 时,我会得到以下输出:

[489]$ brew update
-bash: brew: command not found

那么,我需要执行哪些步骤(从头开始)才能为 OS X 10.6.8 安装 bash固定 版本?
是吗:

  1. 安装 XCode 3.2.6(我现在正在下载 4.1 GB 的安装文件)
  2. 安装 Homebrew(如何安装?)
  3. 按照How do I upgrade Bash in Mac OSX Mountain Lion and set it the correct path? 中的步骤操作?

或者,由于我使用的是 OS X 10.6.8,我是否需要从某处下载 Bash 代码并使用 XCode 3.2.6(或 4.2,如果我付费)并手动替换 /bin/bash 和/bin/sh 文件?

就像我说的,我是 Mac 上所有这些方面的新手,但我确实有 [有点过时的] 编程经验。

谢谢。

【问题讨论】:

    标签: xcode bash homebrew osx-snow-leopard shellshock-bash-bug


    【解决方案1】:

    Homebrew 是一个适用于 Mac 的包管理系统。很多人用它来管理 mysql、python 和(你可能已经猜到了)bash。 Homebrew 所做的只是简单地安装这些包并让它们对用户可用。虽然有些人确实将它用于 bash,但使用 Homebrew 更新 bash 并不能保护他们的整个系统免受 shellshock(我的团队今天测试并确定)。

    我建议您为您的 OS X 版本下载 XCode,下载 xcode 命令行实用程序(通过转到首选项 -> 下载 -> 命令行实用程序),然后运行我编写的这个脚本。需要明确的是,这个脚本只是跟随the same steps outlined here,我只是让开发团队更容易更新。

    您可以将此代码复制到可执行的 bash 脚本中并使用 ./bash-fixer.sh 运行它

    #!/bin/bash
    # In all good conscience, I can not guarantee anything in this script. 
    # I've tested it to the best of my ability, but please use at your own risk
    
        if [ "$EUID" -eq 0 ]; then
          echo "DO NOT RUN AS SUDO! Running as sudo will break the world and will make your computer very unhappy."
          echo "There are commands later that are appropriately sudo'd."
          exit 1
        fi
    
        xcode-select --version
    
        if [[ $? != 0 ]] ; then
          echo "You need to install the xcode stuff that makes magic. Let's try that together"
          xcode-select --install || echo "Something broke. Try running \"xcode-select --install\" manually" && exit 1
        fi
    
        cd ~/
        test=$( env x='() { :;}; echo vulnerable' bash -c 'echo hello' | wc -l )
    
        if [[ ${test} -lt 2 ]]; then
          echo "Your version of bash is up to date"
        else
          mkdir -p bash-fix
          cd bash-fix
          curl https://opensource.apple.com/tarballs/bash/bash-92.tar.gz | tar zxf -
          cd bash-92/bash-3.2
          for i in $(seq -f "%03g" 52 54); do
            curl https://ftp.gnu.org/pub/gnu/bash/bash-3.2-patches/bash32-$i | patch -p0
          done
          cd ..
    
          xcodebuild
          sudo cp /bin/bash /bin/bash.old
          sudo cp /bin/sh /bin/sh.old
    
          echo
          echo
          echo "Current version of bash is $(build/Release/bash --version | head -1 | awk -F "version " '{ print $2 }')"
          echo "Current version of sh is $(build/Release/sh --version | head -1 | awk -F "version " '{ print $2 }' )"
    
          if [[ $(build/Release/bash --version) =~ "3.2.54(1)-release" && $(build/Release/sh --version) =~ "3.2.54(1)-release" ]]; then
            echo "So far so good. Let's do some more checks, because we like dilligence"
          else
            echo "The bash and shell versions are not showing up as being the most recent. Something is afoot!"
            exit 1
          fi
    
          if [[ "${test}" < 2 ]]; then
            echo "Your version of bash is up to date"
            exit 0
          else
            echo "Something went horribly wrong!"
            exit 1
          fi
    
          echo "Awesome. All checks have passed. Cleaning up, and removing executable privaleges from the old bash and sh, just in case"
          sudo cp build/Release/bash /bin
          sudo cp build/Release/sh /bin
          sudo chmod a-x /bin/bash.old /bin/sh.old
    
        fi
    

    告诉我你是怎么做的,祝你好运!

    【讨论】:

    【解决方案2】:

    请注意,Apple 于 2014 年 9 月 29 日发布了一组 Bash 官方补丁版本。但是,支持只能追溯到 Lion,而不是 Snow Leopard。因此,您仍然无法在 Snow Leopard 上构建和安装您自己的补丁版本。

    -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA1
    
    APPLE-SA-2014-09-29-1 OS X bash Update 1.0
    
    OS X bash Update 1.0 is now available and addresses the following:
    
    Bash
    Available for: OS X Lion v10.7.5, OS X Lion Server v10.7.5, OS X Mountain Lion v10.8.5,
    OS X Mavericks v10.9.5
    Impact: In certain configurations, a remote attacker may be able to execute arbitrary
    shell commands
    Description: An issue existed in Bash's parsing of environment variables. This issue was
    addressed through improved environment variable parsing by better detecting the end of
    the function statement.
    This update also incorporated the suggested CVE-2014-7169 change, which resets the
    parser state.
    In addition, this update added a new namespace for exported functions by creating a
    function decorator to prevent unintended header passthrough to Bash. The names of all
    environment variables that introduce function definitions are required to have a
    prefix "__BASH_FUNC<" and suffix ">()" to prevent unintended function passing via
    HTTP headers.
    CVE-ID
    CVE-2014-6271 : Stephane Chazelas
    CVE-2014-7169 : Tavis Ormandy
    
    
    OS X bash Update 1.0 may be obtained from the following webpages:
    http://support.apple.com/kb/DL1767 – OS X Lion
    http://support.apple.com/kb/DL1768 – OS X Mountain Lion
    http://support.apple.com/kb/DL1769 – OS X Mavericks
    
    To check that bash has been updated:
    
    * Open Terminal
    * Execute this command:
    bash --version
    * The version after applying this update will be:
    OS X Mavericks:  GNU bash, version 3.2.53(1)-release (x86_64-apple-darwin13)
    OS X Mountain Lion:  GNU bash, version 3.2.53(1)-release (x86_64-apple-darwin12)
    OS X Lion:  GNU bash, version 3.2.53(1)-release (x86_64-apple-darwin11)
    
    Information will also be posted to the Apple Security Updates
    web site: http://support.apple.com/kb/HT1222
    
    This message is signed with Apple's Product Security PGP key,
    and details are available at:
    https://www.apple.com/support/security/pgp/
    
    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG/MacGPG2 v2.0.22 (Darwin)
    
    iQIcBAEBAgAGBQJUKdToAAoJEBcWfLTuOo7t4QEP/jrigiLB9GYO5JIdVHSFPUtx
    MBr4hAe90LnyAIuhxny1PgAC8BZCPv4otm6DQBQSlX1PxLv8TWm8yp5IKCKJP6ZN
    Smm+OqJLLWwcTOVv345bi5W9dp2nyZVLjWxx9MUfn4YLxKrBJ3fKyHWIycD0WpbD
    4kfXW1G1JGTtyUX6Ge2lnhbOiYBPxJN2TSX4qEmix3KLmEwCwsZVgbjzW2ijNO0O
    3AaUkFIICAECMCE+VZj/fGFQaEmYaPzpt3Tjy+X2NdXL8E0hnui4ymfU0DyR39Oz
    8DQpP499hISeXucdAEH6b2mMO2pOmuDs6FWTSS6talT8ftLUpTmWqv2Rghto5ZXN
    b8RZpOp9RUwurZPMq66BjbHfidEaLjMPCVcfAnjO6HwBaKGQ5kM5+ThPA5/DLSL6
    gGPa4t3qM/JdQAzm8da9m62vjWZ1BXzIlLSmxpIq/5bDMpBNiA783f+uuDUjpQ/N
    3SkKNn2U47VsCLYaoSSmL6FUBLsInnNvwkVyNsnMiEjMVn/BtV5ogAYAc8SSvGM7
    Mlx9OBKYork0bNuViPK09j/8te74tt6t38B+0lb4mG5m1r2CyI96f2uVBpKkqDlj
    K6INwsDZKqtg1Y+6xtnJb9F3ZNZarzSxZa2C8qKaVCH11vLaXVPJJCrYspWnV8yI
    DrlKtF9VhcfUGTKJiRNX
    =ZVVk
    -----END PGP SIGNATURE——
    

    【讨论】:

      【解决方案3】:

      http://hacksagogo.wordpress.com/2014/10/02/shell-shock-os-x-bash-update-installer-for-snow-leopard/

      这是为那些疯狂的人、不合时宜的人、麻烦制造者、方孔中的圆钉准备的。那些以不同方式看待事物的人......并且仍在运行 Snow Leopard。

      1.- 在 PackageMaker 中打开 bashUpdateLion.pkg

      2.- 进入项目/原始编辑模式,修改“Distribution”文件中的“InstallationCheck”和“VolumeCheck”功能,如下所示:

      function InstallationCheck(prefix) {
          return true; }
      
      function VolumeCheck(prefix) {
          return true; }
      

      3.- 点击“构建”并为安装程序包选择一个名称。

      这就是所有人。

      【讨论】:

      • 我的操作系统:Mac OSX 10.6.8。一些进一步的解释: 1)去你下载的地方bashUpdateLion.dmg,然后双击它。然后,右键单击 bashUpdateLion.pkg 并选择 Open With&gt;Other 并导航到 Macintosh HD>Developer>Applications>Utilities>PackageMaker,选择它,然后单击 Open 按钮。 3)构建并选择名称后,您可以立即打开安装程序(错误地(?)列出了原始名称)....
      • ...或者,您可以关闭 PackageMaker(并且不要保存更改),弹出卷(您会在 Finder 中看到它打开),导航到新命名的 .pkg 文件,然后单击它(它也错误地(?)列出了原始名称),然后继续安装。
      • 应用该更新后,我的 bash 版本 $ bash --versionGNU bash, version 3.2.48(1)-release (x86_64-apple-darwin10.0) Copyright (C) 2007 Free Software Foundation, Inc. 更改为 GNU bash, version 3.2.53(1)-release (x86_64-apple-darwin11) Copyright (C) 2007 Free Software Foundation, Inc.。而且运行shellshock测试:$ curl https://shellshocker.net/shellshock_test.sh | bash后,我还有一个漏洞:CVE-2014-7186 (redir_stack bug): VULNERABLE,可以像这样单独测试...
      • $ bash -c 'true &lt;&lt;EOF &lt;&lt;EOF &lt;&lt;EOF &lt;&lt;EOF &lt;&lt;EOF &lt;&lt;EOF &lt;&lt;EOF &lt;&lt;EOF &lt;&lt;EOF &lt;&lt;EOF &lt;&lt;EOF &lt;&lt;EOF &lt;&lt;EOF &lt;&lt;EOF' || echo "vulnerable",对我来说产生:Segmentation fault vulnerable
      【解决方案4】:

      您也可以在全终端样式中执行此操作(已提供 Lion 更新包):

      # pkgutil --expand ~/BashUpdateLion.pkg ~/BashUpdate
      # vi ~/BashUpdate/Distribution
      

      编辑 InstallationCheckVolumeCheck 函数,如下所示:

      function InstallationCheck(prefix) {
           return true;
      }
      function VolumeCheck(prefix) {
           return true;
      }
      

      最后再次将其扁平化为可安装的包

      # pkgutil --flatten ~/BashUpdate ~/Desktop/BashUpdateModified.pkg
      

      【讨论】:

        猜你喜欢
        • 2013-05-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多