Skip to content
RCE Disclosed report Intermediate

Insecure Bundler configuration fetching internal Gems (okra) from Rubygems.org

An internal Ruby gem named okra was not registered on the public Rubygems repository, allowing an attacker to publish a malicious gem under that name. The attacker's gem was installed on a developer machine when the developer manually ran 'gem install' instead of using the internal source, though production builds were protected.

James Sanderson Follow

Originally disclosed on HackerOne

Bounty$5,000 High View original
  • Triaged in 24 hours
  • Fixed in 6 months
  • Paid in 25 hours
  • Disclosed after 6 months

Summary by the researcher

I found an internal gem (Ruby library) in use by Basecamp that was not registered on Rubygems (the public Ruby package repository). I registered a gem of my own under the name that would call back when installed, in an attempted "dependency confusion" attack.

Although this attack was not successful against any production machines or automated builds, as Basecamp had successfully mitigated against the attack in those places, my library was installed on a developer machine when a member of Basecamp attempted to install the gem by hand using "gem install" rather than running a "bundle install".

This vulnerability was resolved by using configuration management software to set the default package repository on developer machines to one controlled by Basecamp, where they can control which packages come from which repositories and can prevent internal packages being pulled from Rubygems.

The report

I believe (most likely) that one of your projects is not set up correctly to only pull internal gems from your internal gem server, and instead will pull gems from Rubygems.org if the version number there is higher.

Specifically, the "okra" gem.

At around 15:21 today (UTC) the okra gem that I wrote – https://rubygems.org/gems/okra – was installed on the machine with hostname "oscillatinghost" under the username "fernando" on your network.

This would be possible if the Gemfile either installs gems from global sources (thus allowing the version on Rubygems to 'trump' the internal version) or if the okra gem is depended on by another internal gem, and your version of Bundler is less than 2.2.10 – see here for details on that: https://bundler.io/blog/2021/02/15/a-more-secure-bundler-we-fixed-our-source-priorities.html

It is possible this is not correct, and instead, someone typed "gem install okra" without specifying where to fetch the Gem from. This would potentially also have fetched it from Rubygems.

Please note that the Gem I wrote does not do anything malicious, and only fetches the minimum information I need to filter out false positives and correctly identify organisations. You can verify this yourself by looking at the code for the gem "okra-90002.0" in your gems folder. I will delete all information relating to your organisation as soon as it is no longer needed.

Impact

The impact is that an attacker could achieve arbitrary Remote Code Execution on any machines that will fetch the gem from the Rubygems repository.

Note that to achieve code execution, merely installing the Gem is enough, it does not have to be require'd or run.

The original report as published on HackerOne, by zofrex. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the developer machine's default gem source was not restricted to the internal repository, so a manual 'gem install' fetched the attacker's public gem instead of the internal one.

Impact

An attacker could achieve arbitrary remote code execution on any machine that fetches the gem from Rubygems, though production machines and automated builds were mitigated and only a developer machine was affected.

What the attacker needed

Internal gem name not reserved on public repo; developer manually installs gem from public source

The fix

The issue was fixed by using configuration management to set the default package repository on developer machines to one controlled by Basecamp.

How it was found

  1. The attacker noticed an internal gem name (okra) was not registered on Rubygems.
  2. The attacker published a gem with that name to Rubygems that would call back when installed.
  3. A Basecamp developer manually ran 'gem install okra' without specifying the internal source.
  4. The attacker's gem was installed on the developer's machine and called back to the attacker.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

When software is built, it often downloads extra pieces called packages from the internet. If a company uses a private package name that is not reserved on the public package store, anyone can upload a package with that same name. If a developer accidentally installs from the public store, they get the attacker's package, which can run code on their computer.

What is RCE?

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.

More from Basecamp

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Remote code execution

The lesson behind this report.

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.