Skip to content
RCE Write-up Intermediate

How I Discovered a Dependency Confusion Vulnerability in a Ruby Application Leading to RCE

An internal Ruby gem name was not reserved on the public RubyGems registry, so an attacker could publish a malicious gem with the same name and a very high version number. A developer who manually installed the gem with the gem command received the attacker's package, which ran code during installation and sent a callback.

bakkar0x Follow

Published on medium.com

Today, I want to share a fascinating dependency confusion vulnerability I discovered, one that led to remote code execution (RCE).

Ahmed Tarek, on medium.com

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

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

How it worked

Root cause

The internal gem name was not reserved on the public RubyGems registry, and the gem command selects the highest version across all configured sources, so a public package with a higher version was installed instead of the private one.

Impact

The attack affected only individual developer workstations, not production or CI/CD, but those machines may hold source code, environment variables, SSH keys and cloud access, so the issue was rated high severity.

What the attacker needed

Internal gem name not reserved publicly; developer runs gem install manually; attacker can publish to RubyGems.org

How it was found

  1. Clone the target organisation's public repositories and search Gemfile files for gem names.
  2. Check each gem name against RubyGems and note names that return 404, meaning they are not public.
  3. Create a gem with the same name and a very high version number, containing code that runs at install time and sends a callback.
  4. Publish the gem to RubyGems.org and monitor the callback server.
  5. Observe callbacks from developer workstations with human usernames, indicating manual gem installs.

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 write-up has not been written yet. The Original tab links to the source.

Package managers download code libraries from online registries. If a company uses a private library name that is not also claimed on the public registry, an attacker can publish a package with that same name and a huge version number. When someone installs it, the attacker's code runs automatically, which is why this is called dependency confusion.

What is RCE?

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

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.