curl https://some-url/ | sh

I see this all over the place nowadays, even in communities that, I would think, should be security conscious. How is that safe? What’s stopping the downloaded script from wiping my home directory? If you use this, how can you feel comfortable?

I understand that we have the same problems with the installed application, even if it was downloaded and installed manually. But I feel the bar for making a mistake in a shell script is much lower than in whatever language the main application is written. Don’t we have something better than “sh” for this? Something with less power to do harm?

  • Undaunted@feddit.org
    link
    fedilink
    arrow-up
    20
    arrow-down
    1
    ·
    1 day ago

    You shouldn’t install software from someone you don’t trust anyway because even if the installation process is save, the software itself can do whatever it has permission to.

    “So if you trust their software, why not their install script?” you might ask. Well, it is detectable on server side, if you download the script or pipe it into a shell. So even if the vendor it trustworthy, there could be a malicious middle man, that gives you the original and harmless script, when you download it, and serves you a malicious one when you pipe it into your shell.

    And I think this is not obvious and very scary.

    • August27th@lemmy.ca
      link
      fedilink
      arrow-up
      7
      ·
      1 day ago

      it is detectable […] server side, if you download the script [vs] pipe it into a shell

      I presume you mean if you download the script in a browser, vs using curl to retrieve it, where presumably you are piping it to a shell. Because yeah, the user agent is going to reveal which tool downloaded it, of course. You can use curl to simply retrieve the file without executing it though.

      Or are you suggesting that curl makes something different in its request to the server for the file, depending on whether it is saving the file to disk vs streaming it to a pipe?

    • FizzyOrange@programming.dev
      link
      fedilink
      arrow-up
      5
      arrow-down
      4
      ·
      edit-2
      17 hours ago

      it is detectable on server side, if you download the script or pipe it into a shell

      Irrelevant. This is just an excuse people use to try and win the argument after it is pointed out to them that there’s actually no security issue with curl | bash.

      It’s waaaay easier to hide malicious code in a binary than it is in a Bash script.

      You can still see the “hidden” shell script that is served for Bash - just pipe it through tee and then into Bash.

      Can anyone even find one single instance of that trick ever actually being used in the wild (not as a demo)?

      • Undaunted@feddit.org
        link
        fedilink
        arrow-up
        4
        ·
        17 hours ago

        I never tried to win any argument. Hell I was not even aware that I’m participating in one. I just wanted to share the info, that even if the vendor is absolutely trustworthy and even if you validated the script by downloading and looking at it, there’s still another hole that’s not obvious to see.

        Yes it’s unlikely, but again, I never said it were. There are also arguments you can run curl with, to tell it to do the download first and then push it through the pipe afterwards, though I don’t know them by heart now.

        It won’t cost you anything to set those parameters, when you insist to use curl | bash, just in the off chance that someone’s trying to do what I mentioned.

        But I’m also someone who usually validates their downloads with a checksum so maybe I’m just weird. Who knows.