8 ms·
Detecting the use of “curl – bash” server side
- deleted 11y ago[deleted]
- ithkuil 11y ago> Installing software by piping from curl to bash is obviously a bad idea and a knowledgable user will most likely check the content first 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-pgp-verified-install 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")
- kenny_r 11y agoFor me personally, the security aspect isn't even the reason I dislike curl | bash installers. There's no standard behaviour for curl|sh, and it re-introduces many problems that were solved by package managers decades ago. Each time I'm about to run `curl https://install.newhotness.io|sudo 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.
- TeMPOraL 11y ago> 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. 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...
- dsp1234 11y agoThe following generally works for me. It removes the installed files, including configuration files. Additionally it will remove any dependencies that were only used by packagename sudo apt-get purge --auto-remove packagename
- HappyTypist 11y agoYour package manager should have a remove operation.
- serf 11y ago>How does one uninstall stuff on Linux anyway? with a package manager suited for your system, or with the knowledge of what files the software in question touches.
- RijilV 11y agoIt's a best effort though, you're relying on the package maintainer to have tracked all the installed files and clean up anything they might have modified, which hopefully you or something else hasn't modified after the package was installed. The packages authored by distributions tend to be pretty good, but I've seen RPMs with nothing more than tar zxf in them and no tracking of the files installed. The major package managers expect the package to manage the artifacts installed, this works if everyone plays nice and does their job...
- 11y ago
- Sean1708 11y agoWhat amuses me is that the people who are vehemently against using a bash script are often the same people who will run $ ./configure $ make without a second thought.
- merb 11y agoActually 99% of the Time this will install it to /usr/local
- fjarlq 11y agoI disagree. Many (probably most) makefiles conform to the GNU Coding Standards, which recommend declaring "all" to be the default make target. `make all` does not install; that's what `make install` is for. https://www.gnu.org/prep/standards/html_node/Standard-Targets.html https://www.gnu.org/prep/standards/html_node/Standard-Target...
- coldtea 11y agoThe idea of the original parent comment on Make is not about well conforming makefiles. The idea is that if one doesn't trust a random curl-ed install file, they shouldn't trust a downloaded makefile either -- and for the same reasons, yet tons of people complaint about the first, but have been using the latter for decades without complain...
- coldtea 11y agoThe idea is that the Makefile (and maybe configure?) could just as well as a "curled" install script contain ANY command, even "sudo rm -rf /". It's not about where it will install it if it works fine.
- koolba 11y agoDon't forget the most important part: sudo make install
- pif 11y agoYes, but not as root!
- nailer 11y agoAgreed 100%. Things installed on your machine have privileges regardless of how you install them. Install software from verified sources. Whether you use curl or not is irrelevant.
- raesene6 11y agoI'd be interested in knowing, how do you assess whether something is a "trusted source" or not?
- coldtea 11y agoThe same way we trust people. By reputation and familiarity. 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.
- raesene6 11y agoAhh but that's one of the hardest pieces of the trust puzzle. On the internet, how do you know who's who. you download a package from npm. Who wrote it, what's their background, where do they work? What are their security practices like, what are the security practices of the hosting company? so we say Redhat/Apache are more trusted sure, that's one of the reasons that I dislike curl|bash from random sites, there's no way of assessing trust in that software or its origin...
- coldtea 11y ago>On the internet, how do you know who's who. you download a package from npm. Who wrote it, what's their background, where do they work? What are their security practices like, what are the security practices of the hosting company? Check the npm package's ratings, and the github repository watchers and stars. Try to find and read a few posts (and their comments) on the package. The more respected the source (e.g. HN comments vs comments on Digg), the better.
- jfindley 11y agoI don't think that's nearly as clever a counter-argument against curl|bash as they appear to. 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.
- ithkuil 11y agoI think the many discussions about this conflates two things: 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.
- donquichotte 11y agoRecently I stumbled across hashpipe: "hashpipe helps you venture into the unknown. It reads from stdin, checks the hash of the content, and outputs it IF AND ONLY IF it matches the provided hash checksum." [https://github.com/jbenet/hashpipe https://github.com/jbenet/hashpipe]
- NDizzle 11y agoEvery time I see that I just wget the script and inspect it. If it does anything too clever, I don't install it that way. If I can't reason about the shell script something is wrong. It's like being emailed a .bat file in 1999. Would you blindly run it on your Windows box?! I hope not!
- tamana 11y agoThe script downloads a binary onto your system. How would you inspect that?
- goldbrick 11y agoThat article is good, but keybase.io is a non-starter until they open registration. I have been on the pending queue for over a year now.
- kentonv 11y agoYou don't need a Keybase account to follow the Sandstorm PGP-verified installation instructions.
- Velox 11y agoThe unfortunate problem with this is that while piping directly into bash can be exploited, it remains as one of the easiest ways to install programs. Taking RVM for example. Their instructions are to run this: `curl -sSL https://get.rvm.io 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.
- viraptor 11y ago> 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. 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 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.
- rollulus 11y ago"a knowledgable user will most likely check the content first.". Really? I'm knowledgeable in that I understand that the script may contain evil, but I'm lazy as hell so I don't bother to check 99% of the time. Like I clone, build and run repos without checking every SLoC.
- dantillberg 11y agoI wrote up a little utility I wanted to distribute last year, and I came up with this little script block to do it while also verifying the scripts hash: > bash -c 'S="3bceab0bdc63b2dd7980161ae7d952ea821a23e693cb74961b0d41f61f557489";T="/tmp/gut.sh";set -e;wget -qO- "https://www.tillberg.us/c/$S/gut-1.0.3.sh">$T; 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 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.
- NeutronBoy 11y agoIt sounds good, but if you're distributing the hash through the same channel as the script, then it's open to the same vulnerability (MITM, website breach, whatever) > adding some sort of common utility to support it could mitigate the most obvious security issues. Package managers are awesome!
- bflesch 11y agoYour approach tackles the scenario that the actual shell script `https://www.tillberg.us/c/blah/gut-1.0.3.sh` https://www.tillberg.us/c/blah/gut-1.0.3.sh` might be untrustworthy, but the whole command including the verification hash will most likely also be downloaded from `tillberg.us`. 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.
- some1else 11y agoTake-away: Always download the script and execute it locally. An attacker may change the underlying script once you pipe it to shell.
- paco3346 11y agoI appreciate the value you find in this. I too was thinking this but everyone else seems to be find fault in what the article was pointing out.
- amelius 11y agoSorry, but I fail to see the difference with downloading and installing without verifying the code. And since verifying the code is usually hard, I don't see the significance of this article. Please enlighten me :)
- Xylakant 11y agoThis allows a malicious server to send you different content when you pipe to bash than it sends your browser (or even to a script), hiding the attack from people that give the script at least a cursory look. 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.
- Morgawr 11y agoThe difference is in the article itself. Regardless or not of the fact that most people don't verify the scripts that they run (we should! But we don't), the curl | bash paradigm, as explained in the article, actually makes it possible for the attacker to provide two different types of scripts depending on the situation. 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!
- nerdponx 11y agoMaybe this is a dumb question, but is there a difference in behavior between "curl > tmp.sh" and "curl -o tmp.sh"?
- SixSigma 11y agonot in that case but curl -o 'file_#1.htm' http://example.com/[1-10].html http://example.com/[1-10].html downloads 10 files and renames them
- klue07 11y agoReminds me of why I also don't copy paste text from websites directly into my terminal. https://thejh.net/misc/website-terminal-copy-paste https://thejh.net/misc/website-terminal-copy-paste
- educar 11y ago> Installing software by piping from curl to bash is obviously a bad idea and a knowledgable user will most likely check the content first 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.
- rlpb 11y agoIt's not just about trusting that project. It's about trusting that project to understand relevant interactions with the rest of your system, which may include components or configurations that project's authors have never heard of. 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.
- educar 11y agoDon't get me wrong, I definitely don't think that curl|bash can replace package managers. curl|bash can be used for getting software which doesn't need the sophisticatedness (and effort) of creating packages.
- michaelmrose 11y agoI don't want to be rude but it's not luck its competency. You would derive a lot of benefit from learning how to manage your system properly.
- bpchaps 11y agoWow. Assuming much? 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.
- michaelmrose 11y agoIf it were entirely easy it would have already been automated and you wouldn't have a job. -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.
- bpchaps 11y ago-Way to be dismissive. I work with two professionally and two at home. Not that simple. -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.
- jchiu1106 11y agoNice exploit. I think it can be prevented by `tee`ing bash : $ curl -s https://localhost:5555/setup.bash https://localhost:5555/setup.bash | tee bash sleep 3 echo "Hello there :)"
- cyphar 11y agoI think you'll still hit the buffer of tee in that case, which may still cause the problem. I'd recommend just saving the file and executing it afterwards.
- kevrone 11y agoWhat's funny is that they suggest adding a sleep in the script so that it can be detected as a delay in byte stream delivery, but if you really want to know if the script is being executed and by what, you could literally just have the first line of the script make an http request with whatever meta data you want.