Attacking Ruby Gem Security with CVE-2015-3900

By   ISBuzz Team
Writer , Information Security Buzz | Jun 25, 2015 09:00 pm PST

A Ruby gem is a standard packaging format used for Ruby libraries and applications.  This packaging format allows Ruby software developers a clearly defined format in which they can reliably build and distribute software.  Developer’s push Ruby gems to a distribution server (aka: a gem server) where by users can then install the Ruby application using “gem install gem_name”.

In a recent presentation, “Trojaned Gems: You can’t tell you’re using one” at THOTCON 0x6, we (Brandon Myers and Jonathan Claudius) shared some of our research looking at the security of the Ruby gem eco system.   The original goal of the research was merely to act as a driving means to improve our own Ruby gem security, but we felt what we discovered was worth sharing to help better protect others.

Summary of our Ruby Gem research

  • The RubyGems client has a “Gem Server Discovery” functionality, which uses a DNS SRV request for finding a gem server.  This functionality does not require that DNS replies come from the same security domain as the original gem source, allowing arbitrary redirection to attacker controlled gem servers (aka: CVE-2015-3900).
  • CVE-2015-3900 allows an attacker to redirect a RubyGem client that is using HTTPS to an attacker controlled gem server; this effectively bypasses HTTPS verification on the original HTTPS gem source.  This means that the attacker can force the user to install malicious/trojaned gems.
  • We wrote a fully functional Gem Trojaning service that demonstrates how an attacker could simply Trojan Ruby gems transparently over the wire while the user was installing them.
  • Ruby gem signing is an obvious mitigation strategy for the above mentioned transport security issues.  However, gem signing is barely used in the Ruby gem eco-system (0 of the top 10 gems are signed).  See our blog post on how to sign gems here.
  • We demonstrated that even if you are using signed gems, by using CVE-2015-3900, you must be using the HighSecurity trust policy or gems can still be trojaned in transit due to a signing downgrade attack.
  • After getting CVE-2015-3900 fixed, we identified a bypass allowing attackers to redirect users to domains that end with the original security domain (aka: CVE-2015-4020).  For example: attackercontrolled
  • These issues affect the RubyGems client and any environment that embeds the RubyGems client.  Ruby, JRuby, and Rubinuius have all been confirmed to embed the RubyGems client and are affected by CVE-2015-3900.
  • The mechanism for updating to a fixed version of RubyGems also uses the same vulnerable functionality we’re trying to protect.

How many are affected by this vulnerability?

We recently collaborated with Anthony Kasza, a security researcher at OpenDNS, to help understand the number of Ruby gem installations that are potentially affected by this vulnerability.  Anthony was able to confirm that OpenDNS sees roughly 24,000 requests for the DNS SRV record in question per day, inferring 24,000 gem installations per day if we discount local system caches, gem dependencies, and gem installation typos.   Given that OpenDNS sees about two percent of the world’s Internet traffic—assuming each region of the world has the same likelihood of installing gem packages—that’s a possible 1.2 Million gem installations per day across the entire Internet (or 438 Million gem installs per year) that could be affected.

Trustwave has also deployed signatures to detect this vulnerability with our managed IDS/IPS service and have been monitoring for exploitation attempts on this vulnerability for some time.  Thankfully, at the time of this writing, we’ve yet to see any “in-the-wild” exploitation attempts outside of our research lab, which is great news.  However, we believe it to be only a matter of time before criminals get wise to this attack vector and make use of it, so we advise everyone to deploy detections now for when or if it sees exploitation in the wild.  For more information on Trustwave IDS/IPS solutions, see here.  For existing Trustwave IDS/IPS customers, the signature name is “RubyGems DNS hijack attempt detected (CVE-2015-3900)”.

What should you do?

  • Upgrade your RubyGem client in all of your Ruby environments to 2.4.8 or greater.  The most common way to do so is by running the “gem update –system” command.  You can verify after with “gem –-version”.  You can have more than one RubyGem client installed per system.
  • Verify that all your Ruby gem sources are using HTTPS.  This can be verified using the “gem sources” command, which will list all your gem sources.  Using the ‘—add’ or ‘—remove” switches will help you manage the list.
  • As a gem producer, start considering signing your gems.  This means that you can provide options to your users as to whether they want to verify the integrity of your gem.
  • As a gem consumer, start using gem installation trust policies and use the strongest policy supported by your gem provider.  Trust policies can be used with the “gem install” command by using the –P switch and will look something like this “gem install –P HighSecurity gem_name”.
  • Consider reading up on or contributing to TUF (The Update Framework) to better protect your update mechanisms to help protect against the attacks mentioned above.

[su_box title=”About Trustwave” style=”noise” box_color=”#336588″]

trustwaveTrustwave helps businesses fight cybercrime, protect data and reduce security risk. With cloud and managed security services, integrated technologies and a team of security experts, ethical hackers and researchers, Trustwave enables businesses to transform the way they manage their information security and compliance programs. More than 2.7 million businesses are enrolled in the Trustwave TrustKeeper® cloud platform, through which Trustwave delivers automated, efficient and cost-effective data protection, risk management and threat intelligence. Trustwave is a privately held company, headquartered in Chicago, with customers in 96 countries.[/su_box]

Notify of
0 Expert Comments
Inline Feedbacks
View all comments

Recent Posts

Would love your thoughts, please comment.x