Homebrew 是一个适用于 Mac 的包管理系统。很多人用它来管理 mysql、python 和(你可能已经猜到了)bash。Homebrew 所做的只是简单地安装这些包并让它们对用户可用。虽然有些人确实将它用于 bash,但使用 Homebrew 更新 bash 并不能保护他们的整个系统免受 shellshock(我的团队今天测试并确定)。
我建议您为您的 OS X 版本下载 XCode,下载 xcode 命令行实用程序(通过转到首选项 -> 下载 -> 命令行实用程序),然后运行我编写的这个脚本。需要明确的是,此脚本只是遵循此处概述的相同步骤,我只是让开发团队更容易更新。
您可以将此代码复制到可执行的 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
让我知道你是怎么做到的,祝你好运!