352 points · by ingve · 10y ago · 120 comments
It's funny how so many obvious things are all but obvious when you think a little bit more about it. Interesting read on the subject: https://sandstorm.io/news/2015-09-24-is-curl-bash-insecure-p...
(I don't want to enter the `curl | bash` good or bad rabbit hole; just that the topic cannot be just dismissed as "obvious")
Each time I'm about to run `curl https://install.newhotness.io|sudo sh` I'm left with the following questions:
* Will it work? I'm on Arch Linux. This installer was probably tested on OSX and Ubuntu and deemed "portable". I've seen curl|sudo sh installers trying to apt-get installing dependencies.
* Where does it place files? I've got a ~/.meteor folder that's 784MB. Why would you install software libraries and binaries to $HOME? I now have to tell my backup tool to ignore it when backing up my home partition, great. The FHS was established for a reason, people.
* Correlary to the previous question: How do I uninstall it? Maybe all files were installed to a hidden folder in ~/, maybe there's some stuff in /opt, or /usr/local, or who knows where else. If the installer doesn't implement uninstall functionality itself, I now have to go hunt for the stuff it placed in my filesystem.
I understand the need to be able to distribute your software without having to implement native packaging for OSX/Debian/Ubuntu/Red Hat/Fedora/Arch/...
Docker solved this problem. If you're feeling lazy when it comes to distributing your app, just ship a Docker container and be done with it.
How does one uninstall stuff on Linux anyway? My Linux boxes are always like thrash cans - I add and add new stuff until it's time to upgrade either the system or the machine, so it gets wiped and replaced. Never figured out how to delete stuff in a way that will not leave a ton of things behind...
sudo apt-get purge --auto-remove packagename
with a package manager suited for your system, or with the knowledge of what files the software in question touches.
The closest to cruft is hidden directories in my homedir from software I don't use anymore. That isn't a problem either: they don't take up much space, and it's easy to manually delete them if I ever feel like it. If not, they are compressed and deduplicated by backup software, and they're hidden by default, so who cares?
That is called sedimentary data storage, ie. piling new files on top of the old ones.
Every time I've seen it used, curl | bash is simply a way to deal with the fact that the users all have different package managers (often with outdated software) and quite complicated workflows to get stuff set up with them because there were problems that the package manager didn't solve.
>Docker solved this problem.
Ironic. Docker is one of those applications. And they used to ask for it to be installed with a curl pipe.
They seem to have replaced it with what is effectively a script executed with human hands. Not really an improvement.
There's a section on their website[0] there are installation instructions for various distributions using repositories and package managers. In other words, the right(tm) way of doing software distribution on Linux.
But then on a different part of their website I found the curl | sh instructions you allude to[1]. Bizarre that they still support that installation method.
To make matters worse, the big orange "Get Started" call to action button actually leads to the curl|sh installation instructions. In light of that I certainly can't blame you for not knowing about the proper distribution packages.
# This is the script that we install somewhere in your $PATH (as "meteor")
# when you run
# $ curl https://install.meteor.com/ | sh
# It's the only file that we install globally on your system; each user of
# Meteor gets their own personal package and tools repository, called the
# warehouse (or, for 0.9.0 and newer, the "tropohouse"), in ~/.meteor/. This
# means that a user can share packages among multiple apps and automatically
# update to new releases without having to have permissions to write them to
# anywhere global.A few points of the shortcomings of curl|bash vs RPM and others:
* curl|bash is not transactional. If you have an install/upgrade process in a different tab, and you close your terminal accidentally, how do you know if the install/upgrade completed?
* There's no obvious uninstall method, and you need to read the docs to see what, if anything, you should remove outside the main directory.
* There's no way of verifying if files have been tampered with post installation. This has negative security and operational consequences.
* It's much more vulnerable to MiTM attacks - a proxy with a successfully faked certificate can trivially modify a bash script on the wire and add a malicious command to it. This is hard for a user to detect. Packages are (on most distros) installed via package managers that verify GPG signing keys, making in-flight modification very very greatly more difficult.
* Packages are much more auditable - I can download a package and inspect it, and know that it will run the same actions on every machine it's deployed to. curl|bash can trivially serve different instructions to different requests, based on whatever secret criteria the server operator decides.
If you're going to try and argue that instead of doing what the generally accepted $good_thing is, and instead use $quick_and_easy solution that's widely perceived to be insecure, when you argue in defence of your position, you need to make very sure that you're not just trying to justify laziness. I don't think sandstorm have really thought about this hard enough.
1. "curl|bash" vs "curl >install.sh; sh install.sh" 2. install scripts vs package managers
The OP talks about how to detect a streaming execution of a script and exploit it. This proof of concept exploit aims at discouraging the the use of curl|bash as a means to installing code, and instead promotes that at least you should save the script (and review it) (i.e. the "curl >install.sh; sh install.sh").
All of the points you mentioned are valid and important pain points that affect any arbitrary executable install script (not verified cryptographically using a side channel). Deciding whether to use an install script or a packaging system is really a tradeoff.
The "obvious" problem the OP was talking about was that smell you feel when you see piping code to bash. I think OP made an excellent job showing how you can make it harder for people to spot and audit malicious code and how this is pretty serious downside for piping code into bash; It's more like: "I have a gut feeling this is horrible, so let's think about a way to prove that gut feeling", and the proof is insightful and non obvious.
Perhaps they should have said: "however, the following non-security arguments are valid, and there are more we didn't list." Agreed.
But, at the end of the day, they're right: it's not _less secure_ than, e.g., npm.
PS: In your list; "It's much more vulnerable to MiTM attacks" --- that's essentially the PGP vs HTTPS argument in disguise. Which they also cover, and acknowledge to be true; the argument is essentially "curl https:.. | bash is not less secure than any HTTPS based method, including npm, .isos, etc."
EDIT: and because this is such a hot topic, I just want to emphasize: I'm not arguing in favor of curl | bash. This is only a counter-argument to "curl | bash is less secure than other https- based install methods".
My point with the PGP argument is that you can indeed go through all those steps to verify their install script with GPG (although note that on top of the steps they run, you should ideally also verify the script against a known hash that you verified elsewhere to make sure that the contents of the script is what you expect, as well as the authors).
But the manual GPG verification process will be ignored by almost all users, who will decide they can't be bothered. My point about package managers is that they do this automatically, without requiring the user to jump through extra hoops. Which is much better than the 8 additional steps that almost no-one will bother with, in practice.
Also saying that it's not less secure than npm isn't a great benchmark - npm is really bad too. See the recent left-pad issues, for example. So yeah - it's not really much worse than other things which are also bad. But it's a lot worse than doing it properly, with a signed RPM repository.
I suspect we've spent far more time thinking about this than most people. We've heard every argument many times. The referenced blog post specifically addresses the security argument (hence the title) because that's the one we feel is most misleading.
I absolutely agree that curl|bash is ugly compared to package managers, but there are some serious shortcomings of package managers too, and it's a trade-off. With deb or rpm, we are tied to the release schedules of the distros, which is unreasonably slow -- Sandstorm does a release every week whereas most distros don't release any more often than twice a year.
We can perhaps convince people to add our own servers as an apt source or whatever, but now the MITM attack possibility is back. Yes, packages are signed, but you'd have to get the signing key from us, probably over HTTPS. No one wants to do the web of trust thing in our experience (I know because we actually offer this option, as described in the blog post, and sadly, almost no one takes it).
The Sandstorm installer actually goes to great lengths to be portable and avoid creating a mess. It self-containerizes under /opt/sandstorm and doesn't touch anything else on your system. This actually means that Sandstorm is likely to work on every distro (given a new enough kernel, which the installer checks for). If we instead tried to fit into package managers, we'd need to maintain half a dozen different package formats and actually test that they install and work on a dozen distros -- it would get pretty hard to do that for every weekly release. (Incidentally, Sandstorm auto-updates, and it does check signatures when downloading updates.)
So, yeah, it's pretty complicated, and we're constantly re-evaluating whether our current solution is really the best answer, but for now it seems like what we have is the best trade-off.
$ ./configure
$ make
without a second thought. sudo make installEither way I'm not saying `curl | bash` is good, I'm just trying to point out that people have a very knee jerk reaction to it and pay no mind to things which are similarly as dangerous.
https://www.gnu.org/prep/standards/html_node/Standard-Target...
It's not about where it will install it if it works fine.
Install software from verified sources.
Whether you use curl or not is irrelevant.
This is what the Debian guys standing in a circle holding their passwords are doing at your Linux event. It's also why when you visit github it says 'GitHub, Inc [US]' in your browser's address bar. Heads up: I work on the latter.
If something is from e.g. Red Hat or a large project repository like Apache, it's more trusted than a random website with some unknown tarball...
If many people in websites and forums say "don't trust this program", well, don't trust it.
Etc.
It's like being emailed a .bat file in 1999. Would you blindly run it on your Windows box?! I hope not!
Taking RVM for example. Their instructions are to run this: `curl -sSL https://get.rvm.io | bash -s stable`. The script that is executed is 887 lines long. The installation is "complex", requiring a lot of different stages. Now, the solution to this is "Use a package manager". Sure, that works in a lot of cases. However, when you have something like RVM which is used across several major operating systems, and hundreds of different flavours, each with their own quirks and package managers it suddenly gets difficult to manage each of these.
The problem we face is, how can we make it easy to install something, while still being safe and maintainable?
Breaking this down further, there are 2 issues to solve. The first is "How do we ensure what we download is what the maintainer says that we should download?". I.e. How do we make sure there are no malicious injections. That one is simple. Use SSL.
The second issue is, "I want to install this thing but I don't know if I can trust the installer". Are you crazy!? This isn't an issue. If you don't trust the installer, you sure as hell can't trust the product. If you don't trust either of them, then you automatically don't trust the other and shouldn't be installing it.
The result is that, yes, people can maliciously serve up code when you pipe the output of curl through bash without you realising. However, this is no different than blindly trusting and installing a script.
I can't think of ten pieces of software with excellent installers.
Software distributors generally pay very little attention to the installer. That is because installers are written by people who want to try and make it easy to install something, and don't really care about anything else. If they can get you to install something, helping you remove it isn't their problem.
If they can get you to install something, protecting you from really unlikely things like someone hacking their CDN and delivering malware is a high quality problem: Either they have enough users so that they will be forgiven, or they won't have enough users and the project is abandoned anyway.
I don't trust installers.
I don't trust installers to document what they're doing, or tell me where files go, because they don't.
I don't trust installers to deliver a secure transparent experience, because they don't.
I don't trust installers to consider conflicts, like what else do I have installed because they don't.
I don't trust installers to create security boundaries, protecting me and my files from bugs in the software, because they don't.
For things that are open source, I try to use the software in-tree without installing it. For other things, I evaluate using a virtual machine. Seriously, I don't trust installers because all of you are bad at them.
> The problem we face is, how can we make it easy to install something, while still being safe and maintainable?
Google, Apple, Microsoft, et al have recommended publishing platforms (aka "app stores") that are designed to specifically solve this problem.
For Debian and the derived, we can approach a Debian Maintainer and ask them for help getting it into Debian. For other distributions, we can take similar steps.
If we insist on publishing things ourselves, we can make our software really portable: Let it live in any directory, and not touch any files. Make it easy for the user to verify this.
If we can't do that, we can document the details: Explain all the files we touch and why, and recommend users create separate user accounts (or containers/virtual machines) to really protect themselves. Try to get people used to this level of care because having a positive experience with good software with excellent documentation[1] will give you pause when faced with anything else.
Honestly, the number of programs that want to run as root or as my user account is terrifying, and the amount of work necessary to sandbox unknown apps really makes me not want to bother. I know most people don't worry about this, so purely from a "hurr hurr move fast" point of view, this isn't anything anyone needs to worry about: `curl | bash` is good enough, and will likely be good enough for a long time.
Its why I stick everything in a container now, as then I don't care what software does to its filesystem, and I only push what directories I want it to have into it. This also lets me run multiple versions of software when the software does not normally support that.
I'm not sure that really changes with an install script. You've got several major operating systems, hundreds of flavours with all kinds of quirks. And you don't even know what shell you're really running on. How do you know your install script will work in any reasonable way?
For example, all reasonable package managers will make sure existing files aren't overwritten, existing configs are not modified, all ownership/modes are reasonable by default. Sure, you can override that in post-install script, but it will stand out that you're doing something non-standard, because there's a post-install script.
> how can we make it easy to install something, while still being safe and maintainable?
Have you seen FPM? (https://github.com/jordansissel/fpm) It provides a nice, simple(ish) abstraction over all the packaging craziness.
> Are you crazy!? This isn't an issue. If you don't trust the installer, you sure as hell can't trust the product.
I do not trust either the installer or the app. If I have a simple package to deploy, I can: 1) check that there are no post/pre-install scripts 2) install the files on the system 3) contain/sandbox them using selinux / grsec / apparmor / chroot / separate user. I cannot easily do the same thing with an installer script, which by definition wants to merge foreign files into my running system.
Even better, it's in the interest of app creator to care about this and provide sandboxing by default, even if they trust the app.
Please enlighten me :)
Are we dealing with a smarter-than-average user that is downloading the script and then running it (who knows, he might actually read it too!)? Let's serve a legit one. Are we dealing with somebody who's just mindlessly piping curl output into sh? We found our victim!
It's fundamentally not much worse than curl > file.sh && sh ./file.sh, but even if the victim notices something odd, all the oddity is invisible.
While this is true, how is this any different from installing using apt-get/dpkg/rpm ? I have never looked into any package I install. In fact, those things are worse because they require root unlike curl | bash.
At the end of the day it's about trust. If you trust the author(s), you would install it. I trust my distribution/browser/OS and I install things they want me to install it. So, if a project suggests "curl | bash", I would do it when I trust the project.
Developers can screw up even with the best of intentions.
I trust distributions more because interactions between components is pretty much all they deal with. That's their specialty.
I'm a distribution developer. I know first hand how often upstream projects screw up due to naivety, because it's my day job to fix their bugs.
I think it can be prevented by `tee`ing bash :
$ curl -s https://localhost:5555/setup.bash | tee bash sleep 3 echo "Hello there :)"
> bash -c 'S="3bceab0bdc63b2dd7980161ae7d952ea821a23e693cb74961b0d41f61f557489";T="/tmp/gut.sh";set -e;wget -qO- "https://www.tillberg.us/c/$S/gut-1.0.3.sh">$T; echo "$S $T"|shasum -a256 -c-;bash $T;rm $T'
This downloads the file to /tmp/gut.sh (which hopefully works on your system), then checks whatever file was downloaded against the hash specified (which hopefully works on your system), then executes it, then deletes it.
I think that `shasum` is a pretty widely-available utility among Linuxes and OSX, though not universal, but it occurred to me that it would be really awesome to have a program that was more purpose-built to only execute shell scripts that matched a particular hash, a la:
> curl https://www.tillberg.us/c/blah/gut-1.0.3.sh | shverify --sha256 3bceab0bdc63b2dd7980161ae7d952ea821a23e693cb74961b0d41f61f557489
Obviously, many other systems are more "secure" than curl-bashing, but curl-bashing is very convenient, and adding some sort of common utility to support it could mitigate the most obvious security issues.
If `tillberg.us` is malicious you assume that both the gut-1.0.3.sh file and also the hash in the curl command will be changed.
So I think your idea only works when you reference files hosted with a third party but decide to trust the guy who gives you the hash. Basically all occurences of curl to bash piping I have seen in the wild are of the former type, so I really don't think this helps much.
> adding some sort of common utility to support it could mitigate the most obvious security issues.
Package managers are awesome!
but curl -o 'file_#1.htm' http://example.com/[1-10].html
downloads 10 files and renames them
We detached this subthread from https://news.ycombinator.com/item?id=11535742 and marked it off-topic.
He called me a jackass I merely stated that he should improve his understanding.
It's hard to tell someone kindly that they are incorrect.
It's really not that hard, and it's a skill we all need to learn in order to comment here.
I work as a linux admin professionally and work with four different distros on a daily basis. Simply, I don't have enough time to fix every fucking issue that happens on my operating system that prevents something from being installed. And this happens constantly. Is it incompetence when the shitty apt/yum/aur repos are broken by default where an uninstall of $ASININEPACKAGE that needs to be reinstalled later for $DUMBSHITPACKAGE? If someone has a solution that works for many, I will try that, then bitch when it doesn't work, then use the competency you think I don't have to fix it.
Jackass.
It's easy to understand why someone would lash out in response to having their competence snidely negated, but it still damages the community if you do that, so please don't.
Edit: can't edit that post :(
I'm the user and I'm feeling these effects hard and I'm speaking loudly so that some devs may hopefully listen and respect their product, not just their code.
-Why would you deal with 4 different distros wouldn't it be a lot easier to learn the quirks of one or two?
-Expecting every single package on something like the aur which allows anyone to contribute to all be of optimum quality seems a bit optimistic. Why would you use arch and the aur if you want low maintenance?
-If you have constant issues you are either in the wrong profession, picked the wrong employer, or the wrong software.
-aur is just an example, but there are many, many "live" packages on there that aren't close to production ready like they think they are. A better example might be something like skype, whose repos last time I checked fail during install without a LOT of work. There's an enormous lack of QAing in packaging out there.
-That's incredibly dismissive of you again. Mind you, linux admin work is only my job. I do data science, low latency freelance work, security and networking as a hobby, so the extent of the software I use is comparatively large compared to most.