Skip to content
Path traversal Disclosed report Intermediate CVE-2017-0901

Installing a crafted gem package may create or overwrite files

The gem installer did not validate the name field in a gem's metadata, so a crafted gem could write files outside its own install directory. An attacker could create arbitrary files or overwrite an existing file such as another gem's executable, which would then run malicious code when invoked.

mame Follow

Originally disclosed on HackerOne

Bounty$1,000 High View original
  • Fixed in 2 months
  • Paid in 2 months
  • Disclosed after 2 months

There is no check for name field in metadata.gz. By assigning a maliciously crafted string like ../../../../../any/where to the field, an attacker can create an arbitrary file out of the directory of the gem, or even replace an existing file with a malicious file.

Proof of Concept 1: Create a file anywhere

This PoC attempts to create a file /tmp/malicious-0/BOOOOM.

  1. Download the attached file malicious.gem.
  2. Run gem install malicious.gem --no-doc.
  3. /tmp/malicious-0/BOOOOM should be created.

malicious.gem assigns ../../../../../../../../../../tmp/malicious as name field. This attack is relatively weak since the path must include a directory named <name>-<version>, such as malicious-0. Still, there are many chances that cause a catastrophe. For example, think of replacing a file in /etc/dbus-1/.

Proof of Concept 2: Replace rackup command

This PoC attempts to replace gems/rack-2.0.3/bin/rackup with a malicious file.

  1. Download the attached file replace-rackup.gem.
  2. Run gem install rack -v 2.0.3.
  3. Run gem install replace-rackup.gem --no-doc.
  4. Run rackup. It will emit just BOOOOM!.

replace-rackup.gem assigns ../gems/rack as name field, and contains a malicious file bin/rackup. This is really exploitable for attackers.

Note

For how to create the malicious gems, see the attached file src.tar.gz.

In my opinion, this attack is much more dangerous than the issues I reported recently. I hope you could fix this issue ASAP.

The original report as published on HackerOne, by mame. 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 installer used the untrusted name field from the gem metadata directly when building file paths, without checking for path traversal sequences.

Impact

An attacker could create files anywhere the installer can write, or overwrite an existing file such as another gem's command, which then runs the attacker's code; the first proof of concept is limited because the path must include a directory named after the gem and version.

What the attacker needed

Ability to supply a crafted gem; victim installs the gem

How it was found

  1. Download the crafted gem file.
  2. Install it with the gem install command and the no-doc option.
  3. Observe that the file was created at the path outside the gem directory.

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 you install a software package, the installer unpacks its files into a folder. This report shows the installer trusted a name written inside the package to decide where files go, so a package could use a name like a path going up and out of that folder. That let it drop or replace files elsewhere on the machine, including a program another package runs.

What is Path traversal?

Input that builds a file path escapes the intended folder, reading or writing files the application should never touch.

More by mame

View all

3 more disclosed reports, best first.

More from RubyGems

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Path traversal and file inclusion

The lesson behind this report.

Input that builds a file path escapes the intended folder, reading or writing files the application should never touch.