Trustwave SpiderLabs Uncovers Ov3r_Stealer Malware Spread via Phishing and Facebook Advertising. Learn More

Trustwave SpiderLabs Uncovers Ov3r_Stealer Malware Spread via Phishing and Facebook Advertising. Learn More

Services
Capture
Managed Detection & Response

Eliminate active threats with 24/7 threat detection, investigation, and response.

twi-managed-portal-color
Co-Managed SOC (SIEM)

Maximize your SIEM investment, stop alert fatigue, and enhance your team with hybrid security operations support.

twi-briefcase-color-svg
Advisory & Diagnostics

Advance your cybersecurity program and get expert guidance where you need it most.

tw-laptop-data
Penetration Testing

Test your physical locations and IT infrastructure to shore up weaknesses before exploitation.

twi-database-color-svg
Database Security

Prevent unauthorized access and exceed compliance requirements.

twi-email-color-svg
Email Security

Stop email threats others miss and secure your organization against the #1 ransomware attack vector.

tw-officer
Digital Forensics & Incident Response

Prepare for the inevitable with 24/7 global breach response in-region and available on-site.

tw-network
Firewall & Technology Management

Mitigate risk of a cyberattack with 24/7 incident and health monitoring and the latest threat intelligence.

Solutions
BY TOPIC
Microsoft Exchange Server Attacks
Stay protected against emerging threats
Rapidly Secure New Environments
Security for rapid response situations
Securing the Cloud
Safely navigate and stay protected
Securing the IoT Landscape
Test, monitor and secure network objects
Why Trustwave
About Us
Awards and Accolades
Trustwave SpiderLabs Team
Trustwave Fusion Security Operations Platform
Trustwave Security Colony
Partners
Technology Alliance Partners
Key alliances who align and support our ecosystem of security offerings
Trustwave PartnerOne Program
Join forces with Trustwave to protect against the most advance cybersecurity threats
SpiderLabs Blog

Attacking Ruby Gem Security with CVE-2015-3900

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. Developers push Ruby gems to a distribution server (aka: a gem server) where 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 ecosystem. The original goal of the research was 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 allowing an attacker to force the user to install malicious/trojaned gems.
  • We wrote a fully functional "Gem Trojan-ing" service that demonstrates how an attacker could simply send 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 not common in the Ruby gem ecosystem (not one 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: attackercontrolledrubygems.org.
  • These issues affect the RubyGems client and any environment that embeds the RubyGems client. Ruby, JRuby, and Rubinius all 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 secure.


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 per day for the DNS SRV record in question (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.

We've also deployed signatures to detect this vulnerability with our managed IDS/IPS service and have monitored for exploitation attempts 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 recommend that everyone deploy detections now. 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 later. The most common way to do so is by running the "gem update –system" command. You can verify the update 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, consider signing your gems to provide your users the option 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.


Slides, Advisories, and Demonstration Material

Here are the slides that we delivered at THOTCON 0x6 for your viewing pleasure:

Here are the three demonstration videos we covered during the presentation:

  • Gem Install Request Hijacking



  • Trojaning a Gem in Transit



  • Bypassing Signed Gems (on MediumSecurity)


Credits

We'd like to thank following for their contributions to this research effort:

Latest SpiderLabs Blogs

Trustwave SpiderLabs: Insights and Solutions to Defend Educational Institutions Against Cyber Threats

Security teams responsible for defending educational institutions at higher education and primary school levels often find themselves facing harsh lessons from threat actors who exploit the numerous...

Read More

Breakdown of Tycoon Phishing-as-a-Service System

Just weeks after Trustwave SpiderLabs reported on the Greatness phishing-as-a-service (PaaS) framework, SpiderLabs’ Email Security team is tracking another PaaS called Tycoon Group.

Read More

Trustwave SpiderLabs Uncovers Ov3r_Stealer Malware Spread via Phishing and Facebook Advertising

During an Advanced Continual Threat Hunt (ACTH) investigation that took place in early December 2023, Trustwave SpiderLabs discovered Ov3r_Stealer, an infostealer distributed using Facebook...

Read More