Skip to content
Path traversal Disclosed report Intermediate CVE-2018-8780

The possibility that unintended file operation may be performed because some methods of `Dir` do not check NULL characters.

Several methods of Ruby's Dir class (entries, new and empty?) did not reject path strings containing a NULL character, so the part after the NULL was silently ignored. An attacker who can influence a path passed to these methods could cause a directory other than the intended one to be opened or listed.

ooooooo_q Follow

Originally disclosed on HackerOne

  • Triaged in 56 days
  • Fixed in 3 months
  • Paid in 3 months
  • Disclosed after 3 months

It seems that entries,new, and empty? do not check NULL characters in methods of Dir.

LOG
[vagrant@localhost ~]$ ls
test
[vagrant@localhost ~]$ irb
irb(main):001:0> Dir.open("/home/vagrant\0xxx") do |d|
irb(main):002:1* p d.read   # => "."
irb(main):003:1> p d.read   # => ".."
irb(main):004:1> p d.read
irb(main):005:1> p d.read
irb(main):006:1> end
"."
".."
".bash_logout"
".bash_profile"
=> ".bash_profile"

irb(main):007:0> d = Dir.new("/home/vagrant\0xxx")
=> #<Dir:/home/vagrantxxx>
irb(main):008:0> p d.read   # => "."
"."
=> "."
irb(main):009:0> p d.read   # => ".."
".."
=> ".."
irb(main):010:0> p d.read
".bash_logout"
=> ".bash_logout"
irb(main):011:0> p d.read
".bash_profile"
=> ".bash_profile"

irb(main):012:0> Dir.entries("/home/vagrant\0yyy")
=> [".", "..", ".bash_logout", ".bash_profile", ".bashrc", ".ssh", ".rbenv", ".pki", ".bash_history", "test"]

irb(main):013:0> Dir.empty?("/home/vagrant\0zzz")
=> false

Impact

When using the corresponding method, unintended file operation may be performed.

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

Impact

When these methods are used, an unintended file operation may be performed, because the path is truncated at the NULL and a different directory than the one named is accessed.

What the attacker needed

Attacker controls a path passed to Dir; path may contain a NULL byte

How it was found

  1. Open an interactive Ruby session.
  2. Call Dir.open with a path that contains a NULL character followed by extra text and read entries from it.
  3. Call Dir.new with a similar NULL-containing path and read entries from it.
  4. Call Dir.entries with a NULL-containing path and observe the listing.
  5. Call Dir.empty? with a NULL-containing path and observe the result.

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 NULL character is a byte with value zero. Ruby strings can contain it. Here the Dir methods accepted a path containing a NULL character instead of raising an error.

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

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.