News for hackers. Stuff that matters.
Re:Don't Pipe to your Shell by cbhl on Thursday October 31, 2013 @11:23PM (#6651608)
Would it make sense to mitigate this by creating a (even smaller) bootstrap script that itself downloads the "real" script and checks e.g. the SHA256 hash of the downloaded file before executing?
Re:Don't Pipe to your Shell by hrjet on Friday November 01, 2013 @03:43AM (#6652383)
Even simpler would be:

  function install_my_software() {
    ...
  }

  install_my_software()
If the script is partially downloaded, it won't have any effect.
Re:Don't Pipe to your Shell by mercurial on Friday November 01, 2013 @03:57AM (#6652416)
I realize that I tend to do that by default in my shell scripts. After a few years of Python, I always make a main() function which gets the command line parameters. Is this weird?
Re:Don't Pipe to your Shell by pdpi on Friday November 01, 2013 @07:37AM (#6653007)
If you're weird, I'm weird too.

It just seems to me that the main should worry about interfacing with the outside world, and the rest of your code should really just be written as a library.

Re:Don't Pipe to your Shell by mercurial on Saturday November 02, 2013 @02:48AM (#6658411)
Yes, my main usually does little more than argument handling.
Re:Don't Pipe to your Shell by eropple on Friday November 01, 2013 @04:51AM (#6652538)
Not really weird - it allows for more composability if you ever need to go that way.
Re:Don't Pipe to your Shell by mercurial on Friday November 01, 2013 @06:08AM (#6652781)
I think I do that to avoid global variables as much as possible, as well. Declaring things as "local" tends to keep me honest, as opposed to having a bunch of junk cluttering the global namespace.
Re:Don't Pipe to your Shell by shawabawa3 on Friday November 01, 2013 @08:43AM (#6653283)
I had an idea for solving this problem and MITMs..

I made a utility "shacat", which takes a sha1 checksum as an argument and then pipes input to output iff the sum of input matches the sum

e.g.

    $ curl http://site.com/script | shacat 7ef39183 | sh
You don't even need https! You copy the command from the site including the sha sum, so it can't have been tampered with

Of course, getting people to use shacat is the hard part

Re:Don't Pipe to your Shell by gbog on Friday November 01, 2013 @09:03AM (#6653347)
"so it can't have been tampered with"

Why that? Have we never heard of defaced web pages?

Granted, using shacat is much better than piping into sh. But basic learning from security breaches is that nothing is safe, you only can find ways to do thing in a less catastrophic manner than others.

Re:Don't Pipe to your Shell by shawabawa3 on Friday November 01, 2013 @09:22AM (#6653466)
> Why that? Have we never heard of defaced web pages?

Well if you can't trust the website you're screwed anyway. If the website is compromised then absolutely any way they have of installing software is broken

Re:Don't Pipe to your Shell by tokenrove on Friday November 01, 2013 @02:04PM (#6655276)
Unless you verify against a PGP signature with trusted keys.
Re:Don't Pipe to your Shell by kolev on Friday November 01, 2013 @01:15PM (#6654994)
Good, but in some cases this won't work with latest versions (content will change), plus, you need to add instructions for installing shacat first, which defeats the point of having a single line install. It's always been convenience over security.
Re:Don't Pipe to your Shell by mikegirouard on Friday November 01, 2013 @01:16AM (#6651916)
Yes, but I understand the problem to be that we simply have gotten too comfortable with this behavior.
Re:Don't Pipe to your Shell by djjaxe on Friday November 01, 2013 @12:21AM (#6651750)
or possibly a self checking script that only executed if it was complete... ie: the script is escaped and must run unescape(escaped_script) to be lethal but by then you can confirm that the script is infact whole and as the creator intended to be...