News for hackers. Stuff that matters.
Re:Detecting the use of “curl – bash” server side (2016) by jjgreen on Wednesday December 09, 2020 @04:29AM (#25356825)
Anyone dare to incur the wrath of the Rust contingent by linking to the elephant in the room? OK then, I will

https://www.rust-lang.org/tools/install

Re:Detecting the use of “curl – bash” server side (2016) by est31 on Wednesday December 09, 2020 @04:56AM (#25356979)
The suggestion of the website is certainly not great, but note that:

* It has been improved a little by the https and tls 1.2 parameters compared to earlier versions that didn't have these params

* You are not required to install rustup that way. There are many rustup packages available in distros today. Arch has one, nix OS has one. Debian is dragging their feet [0] but they aren't entirely opposed to the idea, so maybe something will change about this in the future.

* Even if the download process is secured, rustup doesn't really verify any signatures, it just downloads what's inside the manifest. So you can download potentially malicious code if the S3 bucket is hacked that rustup downloads the compiler from.

* Even if the entire process of obtaining rustc is secured, the standard way of using rust + cargo basically gives maintainers access to your local computer through build.rs and other methods. You can sandbox the cargo invocation, but who does that?

[0]: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=955208

Re:Detecting the use of “curl – bash” server side (2016) by kzrdude on Wednesday December 09, 2020 @04:41AM (#25356879)
What, specifically is wrong with it?

The article writes this is obviously bad, but I think it needs to be expanded upon, it's not obvious.

Re:Detecting the use of “curl – bash” server side (2016) by beojan on Wednesday December 09, 2020 @04:44AM (#25356897)
`curl | bash` downloads an installation script and runs it as it's being downloaded, with no opportunity to read the script and ensure it does nothing malicious, and has no inadvertent bugs that could cause damage.
Re:Detecting the use of “curl – bash” server side (2016) by willeh on Wednesday December 09, 2020 @04:47AM (#25356917)
As opposed to downloading a binary and running it? We don't verify what the binaries we download contain, why do it for a bash script?
Re:Detecting the use of “curl – bash” server side (2016) by OskarS on Wednesday December 09, 2020 @04:56AM (#25356983)
Binaries we download and run (as well as packages from package managers) are generally cryptographically signed by people you trust. Shell scripts you curl into bash are not. It is generally MUCH easier to compromise a website and insert your own malicious script than it is to compromise a developer's secret key, which is usually stored much more securely.

Put it like this: if an attacker compromised Rust's website and put in their own malicious Rust installer, macOS and Windows would both show a very scary warning that's like "This is unsigned! Don't run this!" (macOS would even refuse to run it unless you did the right-click to open trick). A Linux package manager would refuse to install such a package outright, unless you --forced it. Not so with curl-to-bash, it would just silently compromise your computer.

Basically, if you believe that code signing is a good thing for security (and I think we all do), curl-to-bash is awful security practice, and you should manually review the script.

Re:Detecting the use of “curl – bash” server side (2016) by skissane on Wednesday December 09, 2020 @05:46AM (#25357295)
> Binaries we download and run (as well as packages from package managers) are generally cryptographically signed by people you trust. Shell scripts you curl into bash are not.

There is no reason in principle why a shell could not implement digital signatures. bash could have a "--require-signature" option where it looks for a GPG signature appended to the end of the script, and refuses to run the script if the signature is missing or the signer is untrusted.

(No idea if the Bash maintainers would be willing to accept a patch adding such a feature if someone were to write one; but, signed scripts is something supported by PowerShell, although most people's experience with it is limited to turning off the default setting which requires all scripts to be signed.)

A related question – what's the difference between downloading an unsigned script over HTTPS versus downloading a signed script (whether over HTTPS or just plain HTTP)? Ideally, the code signing is done offline, so an attacker that compromises the HTTPS server gets the HTTPS private key but not the code signing private key. However, I suspect that ideal often isn't actually obtained; offline code signing can be a pain for CI. If someone has a CI pipeline which signs the code and then deploys it to the HTTPS server, then all an attacker has to do is compromise access to that CI pipeline and neither HTTPS nor code signing will stop them.

Re:Detecting the use of “curl – bash” server side (2016) by OskarS on Wednesday December 09, 2020 @06:00AM (#25357368)
> There is no reason in principle why a shell could not implement digital signatures.

They currently don't, though, which is the point :)

The reason in principle this might not work is that different distros and os's trust different keys. Fedora trusts different keys than Ubuntu, than Arch, than macOS, etc.

> Ideally, the code signing is done offline, so an attacker that compromises the HTTPS server gets the HTTPS private key but not the code signing private key.

I don't think this is necessarily the case. Even if you gain access to the server, HTTPS keys are usually stored in such a way that only root can read them, right? So if you only compromised a non-root account, you wouldn't necessarily be able to read them (I might be wrong about this, I don't do this kind of thing professionally).

Also, you could imagine that the script is not stored as a file, but in a database or something, and then you could compromise it with SQL injection or a similar technique. That would allow you to change the script without any access to HTTPS keys.

> However, I suspect that ideal often isn't actually obtained; offline code signing can be a pain for CI.

You're probably right about this, but this is a great example of why you shouldn't use the same key for both code signing and HTTPS.

Re:Detecting the use of “curl – bash” server side (2016) by skissane on Wednesday December 09, 2020 @06:16AM (#25357455)
> The reason in principle this might not work is that different distros and os's trust different keys. Fedora trusts different keys than Ubuntu, than Arch, than macOS, etc.

Every distro has a keystore / certificate store to which root can add whatever keys/certificates they like. The only difference is in which keys/certificates are present OOTB.

> I don't think this is necessarily the case. Even if you gain access to the server, HTTPS keys are usually stored in such a way that only root can read them, right? So if you only compromised a non-root account, you wouldn't necessarily be able to read them (I might be wrong about this, I don't do this kind of thing professionally).

The purpose of the key is to vouch for the integrity of the data. If I can change the data the key vouches at will, I've effectively compromised the key, even if I never gain access to the bytes of the key itself.

> You're probably right about this, but this is a great example of why you shouldn't use the same key for both code signing and HTTPS.

If the CI pipeline has privilege both to (1) sign stuff with the code signing key (2) upload stuff to the HTTPS server, then even if the code signing key and the HTTPS key are different keys (which is the norm), compromising the CI pipeline is enough to effectively compromise both of them.

Re:Detecting the use of “curl – bash” server side (2016) by aesyondu on Wednesday December 09, 2020 @05:10AM (#25357080)
Pardon my ignorance, but couldn't we just cryptographically sign bash scripts as well?

Perhaps modify the installation script, something like `curl | some-verification-tool | bash`

Re:Detecting the use of “curl – bash” server side (2016) by Arnavion on Wednesday December 09, 2020 @05:54AM (#25357345)
You can. PowerShell already has a 15-year precedent of signed scripts - you generate a signature and embed it in the script in a specific way, and the shell can be configured to only run scripts if their signature is valid.

(PowerShell script signing is based on standard Windows codesigning certificates, but of course this hypothetical bash script signature verifier can use GPG keys instead.)

Re:Detecting the use of “curl – bash” server side (2016) by iso1631 on Wednesday December 09, 2020 @06:31AM (#25357556)
Those who do not understand package managers are doomed to rewrite them. Badly.
Re:Detecting the use of “curl – bash” server side (2016) by OskarS on Wednesday December 09, 2020 @05:44AM (#25357284)
Not easily, and probably not in a way that would work on all different systems (different distros/os's trust different keys).
Re:Detecting the use of “curl – bash” server side (2016) by leokennis on Wednesday December 09, 2020 @05:13AM (#25357097)
Not that it would fix anything, but wouldn't it be possible to:

- Store the install script on www.xyz.com/install.sh

- Store the hash of the install script on www.abc.com/hash.dat

Then in the installation command:

- curl the install script from www.xyz.com/install.sh

- hash it

- curl the hash from www.abc.com/hash.dat

- compare the computed hash with the "curl'd hash"

- only if they match, pipe www.xyz.com/install.sh to bash

In that case, a malicious actor would need to hack at least two locations to be successful.

Re:Detecting the use of “curl – bash” server side (2016) by jorangreef on Wednesday December 09, 2020 @05:21AM (#25357152)
The malicious actor would simply edit the install script to comment out the checksum verification step, since they already own the script.
Re:Detecting the use of “curl – bash” server side (2016) by leokennis on Wednesday December 09, 2020 @07:20AM (#25357797)
Ah yes...good thing I don’t work in IT security...
Re:Detecting the use of “curl – bash” server side (2016) by jorangreef on Wednesday December 09, 2020 @11:29AM (#25360365)
No worries, I've made the same mistake and everyone in software security probably makes that mistake at some point.
Re:Detecting the use of “curl – bash” server side (2016) by willeh on Wednesday December 09, 2020 @05:23AM (#25357160)
Except if you're using Homebrew where nothing is signed, so signing is not as ubiquitous as you seem to think.

But signing is largely a moot point as people will follow the instructions on the website where a clever attacker would simply create their own cryptographic keys sign it and provide instructions for adding it to your keychain to the compromised website. Public key crypto does not solve establishing trust for an actor. It can only do so through delegation which as we have seen with the deprecation of EV certificates (CAs no longer being trusted to establish the identity of legal persons) is not something that is easy to get right.

Certainly it is better to trust the maintainers of your operating system/package manager than a random website. However they only sign things where they have done due-diligence on the project, which is a slow process, too slow for projects with faster release cycle such as Docker or Rust.

Re:Detecting the use of “curl – bash” server side (2016) by megous on Wednesday December 09, 2020 @05:34AM (#25357226)
> Public key crypto does not solve establishing trust for an actor. It can only do so through delegation which as we have seen with the deprecation of EV certificates (CAs no longer being trusted to establish the identity of legal persons) is not something that is easy to get right.

Public crypto can help carry the established trust. Say you track some developer's work and the dev behaves consistently in a trustworthy manner, his signing key can be used to help carry this trust forward, so that after a while you don't need to keep checking and just rely on the assumption that dev is probably honest going forward + crypto to verify you're really using this developer's output.

No need for delegation. Delegation doesn't solve trust anyway, only identity verification.

Re:Detecting the use of “curl – bash” server side (2016) by tzs on Wednesday December 09, 2020 @08:31AM (#25358232)
The biggest issue is not bash script vs. binary. It is that “curl | bash” does not save the script locally.

If something goes wrong, you can’t examine the script afterwards to help figure out what happened and how to recover.

Re:Detecting the use of “curl – bash” server side (2016) by dastx on Wednesday December 09, 2020 @04:51AM (#25356956)
I suppose the difference is iff people do very script before they run, this could bypass it. But I think, those people would definitely download it, inspect it, then run the downloaded script.
Re:Detecting the use of “curl – bash” server side (2016) by VBprogrammer on Wednesday December 09, 2020 @05:07AM (#25357056)
I think it would take next to no effort to hide something in a bash script in such a way that it passed casual inspection even by an expert. See code obfuscation competitions for examples.
Re:Detecting the use of “curl – bash” server side (2016) by hvdijk on Wednesday December 09, 2020 @04:50AM (#25356941)
The whole point of the installation script is that it downloads and installs binaries obtained from a remote server though. You already need to trust the server if you're going to do that, don't you?
Re:Detecting the use of “curl – bash” server side (2016) by taejo on Wednesday December 09, 2020 @04:47AM (#25356916)
Just like if I'd done `curl > install.sh; bash install.sh` without reading install.sh or installed a binary package, both of which are done every day by people with work to do and without the time, skill and inclination to audit millions of lines of source code.
Re:Detecting the use of “curl – bash” server side (2016) by ciceryadam on Wednesday December 09, 2020 @05:04AM (#25357034)
or curl --output instead of using stdout
Re:Detecting the use of “curl – bash” server side (2016) by RMPR on Wednesday December 09, 2020 @04:52AM (#25356963)
In the meantime all the distributions (at least the major one) have Rust in their official repositories.
Re:Detecting the use of “curl – bash” server side (2016) by est31 on Wednesday December 09, 2020 @05:02AM (#25357018)
Unless you are on a rolling release distro, you can run into problems with the rust compiler package being out of date, as the rust ecosystem quickly starts requiring newer versions. 500 crates for a medium sized project are not unheard of, and if one of the maintainers decides to adopt a new feature, you run into issues.

That's why in order to write Rust, you'll likely need rustup, which is packaged on way less distros than the rust compiler is. Debian for example doesn't have an official rustup package.

Re:Detecting the use of “curl – bash” server side (2016) by jjgreen on Wednesday December 09, 2020 @05:57AM (#25357358)
> That's why in order to write Rust, you'll likely need rustup

It seems that way, which is a big disincentive to use Rust at all.

Re:Detecting the use of “curl – bash” server side (2016) by lock-free on Wednesday December 09, 2020 @10:14AM (#25359289)
The same issues exist for other languages and runtimes so I'm not sure why Rust having a standard solution is a disincentive. How many ways are there to ruin a python environment?
Re:Detecting the use of “curl – bash” server side (2016) by avhon1 on Wednesday December 09, 2020 @04:23PM (#25365269)
The issue is worse with Rust, which is still a young and rapidly-changing language. Debian stable currently packages rustc 1.41.1 (February 2020), which is 11 releases behind the most recent 1.48.0 release. The older compiler's differences after 10 months include:

* doesn't have subslice patterns * has `Error::description`, which has since been deprecated * doesn't have x86 CPU feature detection * lacks fix for unsound typecasts between integers and floats * lacks fix for incomplete constant propagation * doesn't let you use conditionals, loops, match, $$, or || in constant fns, or cast arrays to slices in constant fns * has less-helpful error messages and backtraces * doesn't let you implement traits on arrays with lengths >32 * has worse type inference, this (valid since 1.43.0) code doesn't compile because 0.0 and &0.0 are f64s: let n: f32 = 0.0 + &0.0; * requires you to import standard libraries to use predefined numeric constants (like MAXINT or NaN) * doesn't support Control Flow Guard on Windows * doesn't generate documentation links from classpaths (you have to write relative file paths instead)

and numerous libraries being pre-stable.

For code that you're writing yourself, not having these features is mostly just a quality-of-life issue: you'll have to do things that you wouldn't have to do if you had the latest compiler. For code that you're collaborating on, having an 10-months-older compiler can be a showstopper: the code might just not compile at all, and very likely the only fix will be to uninstall your system-packaged rustc and install the version from rustup.

Contrast this with C/C++ development, where your system's pre-packaged compilers are much more likely to be sufficiently up-to-date. These languages are more mature than Rust: they change slower, and new features are adopted by programmers more gradually. For example, the Linux kernel only requires GCC 4.9 [1], which was released in 2013. Debian stable supplies GCC 8.3, which will probably be able to compile unmodified kernel source code for many years without being updated.

[1] https://www.kernel.org/doc/html/latest/process/changes.html

Re:Detecting the use of “curl – bash” server side (2016) by lock-free on Wednesday December 09, 2020 @05:32PM (#25366234)
I can contrast with C/C++ development, where C++17/20 are not available by default on many distros because package managers lag so far behind the curve and new projects get tied to outdated versions.

I just don't really see this as a problem - Rust really isn't that much of a moving target, and the benefit is there is one solution to the problem: use Rustup to manage your Rust installation.

That is significantly more robust than "use your package manager."

Re:Detecting the use of “curl – bash” server side (2016) by richardwhiuk on Wednesday December 09, 2020 @12:28PM (#25361096)
Or avoid distributions like the former CentOS.
Re:Detecting the use of “curl – bash” server side (2016) by gspr on Wednesday December 09, 2020 @04:32AM (#25356842)
Yikes.