clock menu more-arrow no yes mobile

Filed under:

The Bash Bug: What you need to know about the latest security flaw

Torkild Retvedt

Right now, security professionals are scrambling to fix a security flaw some are calling Shellshock. It's a major vulnerability related to Bash, a computer program that's installed on millions of computers around the world. There's been a lot of confusion in mainstream media accounts about how the bug works, who's vulnerable, and what users can do about it.

In this explainer, I'll first give a high-level explanation of who is vulnerable and what they can do about it. Then, for those who are interested, I'll give a more technical explanation of exactly how the Bash bug works.

Who is vulnerable?

Bash (which we'll discuss more below) is installed on many computers running operating systems derived from an ancient operating system called Unix. That includes Macs, as well as a lot of web servers running operating systems such as Linux.

Whether these computers are actually vulnerable depends on whether they invoke Bash in an unsafe way. We already know that this is true of many web servers, and it's believed that other types of network services could also be vulnerable. But it'll take a while for security experts to audit various pieces of software to check for vulnerabilities.

(Bwana McCall)

Apple PCs such as MacBooks don't seem to be running services that use Bash in an unsafe way. That means they are probably not vulnerable to hacks from across the internet. But we won't know that for sure until security experts have had time for a careful audit.

Most Microsoft software doesn't use Bash, so users running Windows PCs, people with Windows phones, as well as websites built using Microsoft software, are probably safe from these attacks. Also, it looks like most Android phones are not vulnerable because they use a Bash alternative.

What should I do to protect myself?

Unfortunately, there isn't a ton you can do in the short run. Presumably, Apple will release updated versions of their software soon. So keep an eye out for that on your platform's software update service, and install it as soon as it's available.

There has also been some speculation that a service called DHCP might be vulnerable, though this is looking increasingly doubtful. This is a service that allows laptops, tablets, and smartphones to automatically configure themselves when they log into a wifi network. A malicious wifi router could use the bug to hack into users' laptops and mobile devices. So if you're a Mac user, it might be prudent to avoid logging into untrusted wifi networks — for example, at coffee shops — until Apple has released a security update.

But for the most part, the vulnerability affects servers more than users' own computers. So most of the heavy lifting needs to be done by security professionals, not the rest of us.

What could attackers do with this vulnerability?

The bug can be used to hack into vulnerable servers. Once inside, attackers could deface websites, steal user data, and engage in other forms of mischief.

There's a good chance that hackers will use the vulnerability to create a worm that automatically spreads from vulnerable machine to vulnerable machine. The result would be a botnet, a network of thousands of compromised machines that operate under the control of a single hacker. These botnets — which are often created in the wake of major vulnerabilities — can be used to send spam, participate in denial-of-service attacks on websites or to steal confidential data.

As I write this, security professionals are racing to update their server software before the bad guys have time to attack it.

How hard will it be to fix the problem?

From a technical perspective, the fix shouldn't be too difficult. A partial fix has already been made available, and a full fix should be released soon.

The tricky thing will be that, as with the Heartbleed vulnerability earlier this year, Bash is embedded in a huge number of different devices, and it will take a long time to find and fix them all.

For example, many home wifi routers run web servers to enable users to configure them using a web browser. Some of these devices may be vulnerable to a Bash-related attack. And unfortunately, these devices may not have an automatic or straightforward mechanism for upgrading their software. So old IT devices might have lingering vulnerabilities for many years.

OK, let's get technical. What's Bash?

Bash stands for Bourne-Again SHell. It's a computer program that allows users to type commands and executes them. If you're a Mac OS X user, you can check it out out yourself. Go to the Finder, open the Applications folder (from the "Go" menu), then the Utilities folder, and then open "Terminal." It looks like this:

You can see in the menu bar that it says "bash," indicating that the program running inside this terminal window is the Bash shell. The Bash shell understands a wide variety of commands. For example, "cd" stands for "change directory," and tells the Bash shell to navigate to a new folder on your hard drive. Typing "ls" lists the contents of the current directory, while "echo" prints out text to the screen.

Bash has been around since the 1980s, and it has become an industry standard. To this day, it's one of the most popular ways for systems administrators, computer programmers, and other tech-savvy users to execute complex commands on computers.

Because the Bash shell is entirely text-based, it's particularly useful for administering a computer remotely. Running a Bash shell on a server halfway across the world feels exactly the same as running the Bash shell on your local computer. IT professionals use remote shells like Bash extensively to configure, diagnose, repair, and upgrade servers without having to physically travel to their location. As a result, Bash is a standard feature on almost all servers that run an operating system not made by Microsoft.

What's the bug in Bash that people discovered this week?

Bash has a feature where users can set "environment variables" and retrieve them later. It works like this:

That's a trivial example, but environment variables turn out to be an extremely useful feature when executing complex commands.

So what's the bug? Here's a slight variation on the previous example:

The "env" command sets an environment variable (in this case COLOR=red), and then executes a command based on that environment. Here, it's executing a second Bash shell which in turn echoes the string "My favorite color is $COLOR." Because the shell was running in an environment where COLOR=red, it prints out "My favorite color is red."

The exploit works like this:

Notice that the command "echo I hate colors" doesn't use the $COLOR variable at all. So if Bash were working correctly, the command "echo vulnerable" should be ignored — it's just random text in a variable that never gets used. So the word "vulnerable" shouldn't be in the output.

But the malicious string '() { :;}; echo vulnerable" takes advantage of a bug in the way Bash handles environment variables to trick it into treating the string "echo vulnerable" as a command rather than just a string of letters. Even worse, it does this automatically, even if it's evaluating a command (like "echo I hate colors") that doesn't use the $COLOR variable at all!

Of course, in a real attack, the bad guys would do something a lot scarier than printing out the word "vulnerable." They'd use this same mechanism to tell your computer to run spyware, send your private files to a remote server, send out spam, or do other bad stuff.

Wait, doesn't an attacker need to have physical access to my computer to pull this off? That doesn't sound very scary.

If Bash were only a mechanism for accepting commands from human users, this wouldn't be such a big problem. The problem is that Bash has also become a popular way for computer programs to invoke other computer programs.

For example, when you load a website with dynamic content on it, the server handling the request may be using Bash commands to access the information you requested. So while most people never use Bash directly, we're all using it constantly — indirectly — as we're browsing the web.

Even worse, when a computer program uses Bash to invoke another computer program, it often uses environment variables to pass along user inputs. For example, when you visit a website, your browser sends the server a variable known as the "User Agent," which tells the server something about which browser you're running. (In my case, I'm running Chrome.)

Web servers often set this user-agent string as an environment variable before using Bash to execute code that generates the web page the user asked for. That allows the server to generate a different website for mobile and desktop browsers, for example.

But malicious parties can manually change their user-agent variable to contain, not a textual description of their browser, but a snippet of malicious code. And if they then visit a server that invokes a vulnerable version of Bash, the server will automatically execute this code, allowing the attacker to hack into the server.

Is anyone actually taking advantage of this bug?

Yes. Malicious software exploiting the vulnerability has already begun to appear online.

Correction: I originally stated that mobile devices running Android and iOS run Bash, but that appears to have been incorrect. Most Android phones ship with a competitor that, so far, does not appear to be vulnerable. I've updated the article accordingly. Also, I stated that a software patch to Bash would fix the problem, but it has since been discovered that the fix is incomplete.

Sign up for the newsletter Today, Explained

Understand the world with a daily explainer plus the most compelling stories of the day.