How to build a trustworthy curl pipe bash workflow
Tags: security, servers
Published: 2020-12-23 00:32:34

<p><strong>Installing and configuring third-party software for managing servers is usually painful. It comes with a handful of requirements that need to be met to accomplish the simple task of just getting it to work.</strong></p>

<p><strong>Operous will offer you a method to configure your server to be tested by us conveniently, which will not make you waste time not doing productive work. It is as simple as copying and pasting a concise command.</strong></p>

<p><img alt="Curl" src="https://1.bp.blogspot.com/-gjuprqeOlXU/X9JXGOzvscI/AAAAAAAAfRA/6g5IlT3x1A8_2WvqPZeolsJTf0vGuCwbgCLcBGAsYHQ/s0/curl.png"/></p>

<p>The method we are going to use is known as the “curl pipe bash” method. This particular method has had many discussions around it before, with very strong opinions both in favor and against it.</p>

<p>Many vendors offer such a method and also call it a “convenience script,” a name that indeed is a good fit and expresses its purpose.</p>

<p>Bellow, you can check out how simple and fast it is going to be to configure Operous on your server:</p>

<p><img alt="Installer" src="https://1.bp.blogspot.com/-FhVq6Bvsh2U/X9I-UZmy0NI/AAAAAAAAfQY/o0kTiASWto0iMN8U0agbtxXsEOzzsoLoQCLcBGAsYHQ/s0/installer3.gif"/></p>

<p>This post will discuss the concerns security specialists usually have with running the &quot;curl pipe bash&quot; method and what we did to address them.</p>

<h3>We believe convenience and security must work together</h3>

<p>People believed that convenience is a trait that lives at odds with security. The harder it is to access your service, the safer it is.</p>

<p>This belief changed recently. We’re moving towards a consensus that in order to build a secure system, <em>it needs to be convenient</em>.</p>

<p>A practical example of the statement above is NIST changes regarding passwords: asking people to create longer, but easier to remember, passwords and change them less frequently (only when compromised) increases security.</p>

<p>Other advances in this realm are: easier to use multi-factor authentication and password managers with a good user experience. When enough effort is put into building something safe and convenient for users, the result is an increase in overall security and productivity.</p>

<p>We know that pushing complexity to the user is a path that must be avoided at all costs. We do careful engineering to accommodate that complexity to achieve both a safer and user-friendly product.</p>

<p>Our convenience script is all about simplifying complexity for you. We worked hard to move complexity away from you and into our product to achieve a more secure, fast, and effortless experience, so you don&#39;t waste time with non-productive work.</p>

<h3>Considered issues</h3>

<p>Now let’s take a deep dive into some technical considerations about our implementation, so you don&#39;t have to worry about them.</p>

<h4>Man-in-the-middle Attack</h4>

<p><em>Concern: An attacker between our web server and your server could change the script’s content and inject code into the script, changing its behavior.</em></p>

<p>Solution: All of our content will be served with state of the art TLS (HTTP encryption). It won’t be possible to download the script nor access any of our pages through an insecure HTTP connection, significantly reducing the risk of content tampering.</p>

<h4>Hidden text attack</h4>

<p><em>Concern: Current JavaScript clipboard API allows a script to change a copied text’s content without any confirmation or warnings. This could be used to make you run something in your shell different from what you think you copied on our website.</em></p>

<p>Solution: We have absolutely no reason whatsoever to trick our users like that. JavaScript injection by a third party through content tampering is protected by TLS (HTTP encryption).</p>

<h4>Client detectiion attack</h4>

<p><em>Concern: Make a web server return distinct responses based on the request User-Agent or through other client detection methods. The script you’d see in your browser might not be the same downloaded on your server.</em></p>

<p>Solution: Again, we have no reason to do such a thing. Nevertheless, in addition to serving our content through TLS, a checksum will be available alongside the script so you can download and validate the script with the checksum before running it.</p>

<h4>Partial content and network issues</h4>

<p><em>Concern: A network error between the script source and the Curl agent could result in an incomplete download, which would result in partial execution of the script. That is indeed dangerous because any incomplete command could be executed.</em></p>

<p>Solution: We addressed this concern by wrapping the script “body” inside a function that is called at the very end. If something wrong really happens, the script will only define some functions but doesn’t do anything.</p>

<h4>Compromised web server</h4>

<p><em>Concern: Even using TLS to serve all content, there might still be room for tampering with the script content by exploiting a vulnerability on the web server and changing its configuration to serve a different script. A similar attack could be made with a supply-chain attack or exploiting some library vulnerability.</em></p>

<p>Solution: Our infrastructure is automated to ensure we’re always running up to date software. We’ll also constantly audit the libraries we use in our application to avoid known vulnerabilities.</p>

<p>We’ll also rely on a separate system that will continuously monitor the script by downloading it and checking the served content against the expected checksum. If this breach ever happens, we’ll be able to cross the monitoring data with our audit events to inform users that may have downloaded a rogue script.</p>

<h3>Conclusion</h3>

<p><strong>Achieving convenience and security at the same time is not an easy feat.</strong></p>

<p>Operous method for registering a server with a single and concise command is part of our strategy to make you get results from our tests on your servers as fast as possible.</p>

<p>Installing third-party software does not have to be a hassle. <a href="http://operous.dev/" target="_blank"> Operous will make it easy to configure the server to be tested</a>.</p>

<p>With our convenient script developed from scratch, you will test your servers quickly and effectively.</p>

<h3>References</h3>

<a class="reference" target="blank" href="https://auth0.com/blog/security-vs-convenience/">Security vs. Convenience</a> 
<a class="reference" target="blank" href="https://sandstorm.io/news/2015-09-24-is-curl-bash-insecure-pgp-verified-install">Is curl | bash insecure<a> 
<a class="reference" target="blank" href="https://sysdig.com/blog/friends-dont-let-friends-curl-bash/">Friends don't let friends Curl | Bash</a> 
<a class="reference" target="blank" href="https://www.seancassidy.me/dont-pipe-to-your-shell.html">Don't Pipe to your Shell</a> 
<a class="reference" target="blank" href="https://briantracy.xyz/writing/copy-paste-shell.html">copy-paste-shell</a> 
<a class="reference" target="blank" href="https://0x46.net/thoughts/2019/04/27/piping-curl-to-shell/">Piping curl to s(hell)</a> 
<a class="reference" target="blank" href="https://www.arp242.net/curl-to-sh.html">Curl to shell isn't so bad</a> 
<a class="reference" target="blank" href="https://www.idontplaydarts.com/2016/04/detecting-curl-pipe-bash-server-side/">Detecting the use of "curl | bash" server side</a> 
<a class="reference" target="_blank" href="https://gist.github.com/btm/6700524">Why curl | sudo bash is good</a>

<hr>

<a href="https://sshcheck.operous.dev/" target="_blank">Know more about Operous and how it can help hardening SSH servers with the vulnerability scanner</a>