TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Protect yourself from the hidden dangers of `curl – sh`

52 pointsby stevejalimover 10 years ago

14 comments

snuxollover 10 years ago
I&#x27;ve seen this same argument time and time again and it&#x27;s just silly. We preach that curl | sh is evil because of a potential lack of &quot;transparency&quot; but rarely does anyone denounce the evils of binary packages.<p>When you run third-party code on your system there is ALWAYS a risk of it doing nasty things, it doesn&#x27;t matter if it&#x27;s an easily readable bash script or a .deb you downloaded. The biggest argument I see about curl | sh that I can agree with is the issues that happens when your connection dies in the middle of the download. Just download the file, then run it.
评论 #8385993 未加载
评论 #8385645 未加载
评论 #8386716 未加载
评论 #8386111 未加载
0x0over 10 years ago
There are other risks besides malicious webservers. Even an accidental network glitch can be fatal, for example if the connection is dropped after the first &quot;&#x2F;&quot; here:<p>rm -rf &#x2F;tmp&#x2F;myawesomeinstaller
评论 #8385452 未加载
评论 #8385946 未加载
carlsverreover 10 years ago
I don&#x27;t understand why you would go through all of this effort...<p>Just dump the data into a file:<p>curl &gt; foobar<p>Read the file using any number of normal utilities<p>vim foobar<p>cat foobar<p>nano foobar<p>less foobar<p>Then if you like what you see execute the file<p>sh foobar<p>Linux&#x2F;Unix utilities are meant to be used. Don&#x27;t limit yourself to only knowing how to check the contents of a curl install if you have a curlsh function.
评论 #8385823 未加载
评论 #8386515 未加载
e12eover 10 years ago
I&#x27;d say apply the same level of scrutiny as you would other code, such as the code that your distribution allows you to install. That means:<p><pre><code> 1) Find a source you trust (nominally) 2) Get a gpg-key that you trust belong to that user 3) Get the install.sh script 4) Get the matching gpg signature (install.sh.asc) 5) Verify that 4) is a valid signature of 3) under 2) 6) Have a look at the script 7) Run the script </code></pre> If you can&#x27;t establish 2), you&#x27;ll just have to stick to 3) 6) and 7).<p>Seeing that something is on a https site, just means someone had the access to put it there. If someone got access to the private key behind 2) -- 1) is probably so compromised that there isn&#x27;t anything other than 6) that might protect you -- and if the script is truly malicious (as opposed to just your average botched bash script) -- it&#x27;s not guaranteed that it&#x27;s obviously malicious.<p>Anyway, a gpg signature links some distributable the author has verified all the way back to wherever that file was authored -- while https only anchors trust on the web server. Web servers get compromised all the time. Prefer a proper signature as a means to anchor trust (&quot;yes, this is probably what X <i>wanted</i> to distribute. If you trust X, this is probably OK&quot;).<p>A https signature just means: &quot;This is something someone&#x2F;anyone managed to upload to this web server&quot;.
meowfaceover 10 years ago
If you don&#x27;t want to bother with all this you can also just do a simple `wget <a href="http://site.com/file.sh" rel="nofollow">http:&#x2F;&#x2F;site.com&#x2F;file.sh</a> -O &#x2F;tmp&#x2F;script`, look through it in your editor, then run it.
peterwallerover 10 years ago
Another method to protect against malformed output due to the connection being cut short - &quot;shell armour&quot;:<p><a href="http://drj11.wordpress.com/2014/03/19/piping-into-shell-may-be-harmful/" rel="nofollow">http:&#x2F;&#x2F;drj11.wordpress.com&#x2F;2014&#x2F;03&#x2F;19&#x2F;piping-into-shell-may-...</a><p><pre><code> { echo { &amp;&amp; curl https:&#x2F;&#x2F;thing &amp;&amp; echo } ; } | sh</code></pre>
jiggy2011over 10 years ago
Is this any different from downloading and running software without reading the source code?
Igglybooover 10 years ago
Is this really a &quot;hidden&quot; danger? It&#x27;s pretty obvious that you shouldn&#x27;t execute a script without reading it unless it&#x27;s from a trusted source over https.
silvestreover 10 years ago
Protect yourself by only using apt-get and packaging open source software yourself if isn&#x27;t already packaged.
retr0hover 10 years ago
I don&#x27;t see much reason for ever needing to do this. Should build packages to install software, and use config management for anything needed outside the package.
Dylan16807over 10 years ago
Don&#x27;t forget that you can&#x27;t even copy and paste a url safely, because there might be hidden text halfway through.
评论 #8386701 未加载
iancarrollover 10 years ago
If you can&#x27;t install software to your box for whatever reason, just replace sh with cat or nano and read it.
_hnwoover 10 years ago
Protect yourself from the hidden dangers of `curl &lt;url&gt; | sh`<p>... by running this script i&#x27;m hosting on the internet.
评论 #8387785 未加载
jamiesonbeckerover 10 years ago
Any &quot;risk&quot; is canceled by simply using HTTPS.