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

Unix domain socket and a path containing a null character

Several Ruby socket methods for UNIX domain sockets did not reject path strings containing a null byte, so the operating system truncated the path at the null and the call silently used a different socket path than the one given. An attacker who can influence a socket path could therefore cause a program to connect to or create an unintended socket.

ooooooo_q Follow

Originally disclosed on HackerOne

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

Some methods on UNIX domain socket are not checked for null characters.

[vagrant@localhost ~]$ ls /tmp
[vagrant@localhost ~]$ irb
irb(main):001:0> require 'socket'
=> true

irb(main):002:0> UNIXServer.open("/tmp/socket\0ruby") {|serv|
irb(main):003:1*   c = UNIXSocket.open("/tmp/socket\0sapphire")
irb(main):004:1>   s = serv.accept
irb(main):005:1>   s.write "from server"
irb(main):006:1>   c.write "from client"
irb(main):007:1>   p c.recv(20)
irb(main):008:1>   p s.recv(20)
irb(main):009:1> }
"from server"
"from client"
=> "from client"

irb(main):010:0> UNIXServer.open("/tmp/socket2") {|serv|
irb(main):011:1*   c = Socket.unix("/tmp/socket2\0emerald")
irb(main):012:1>   s = serv.accept
irb(main):013:1>   s.write "from server"
irb(main):014:1>   p c.recv(20)
irb(main):015:1> }
"from server"
=> "from server"

# safe
irb(main):016:0> Socket.unix_server_loop("/tmp/socket3\0yellow")
Traceback (most recent call last):
        5: from /home/vagrant/.rbenv/versions/2.5.0/bin/irb:11:in `<main>'
        4: from (irb):16
        3: from /home/vagrant/.rbenv/versions/2.5.0/lib/ruby/2.5.0/socket.rb:1163:in `unix_server_loop'
        2: from /home/vagrant/.rbenv/versions/2.5.0/lib/ruby/2.5.0/socket.rb:1108:in `unix_server_socket'
        1: from /home/vagrant/.rbenv/versions/2.5.0/lib/ruby/2.5.0/socket.rb:1108:in `lstat'
ArgumentError (path name contains null byte)
irb(main):017:0> Socket.unix_server_socket("/tmp/socket3\0yellow")
Traceback (most recent call last):
        4: from /home/vagrant/.rbenv/versions/2.5.0/bin/irb:11:in `<main>'
        3: from (irb):17
        2: from /home/vagrant/.rbenv/versions/2.5.0/lib/ruby/2.5.0/socket.rb:1108:in `unix_server_socket'
        1: from /home/vagrant/.rbenv/versions/2.5.0/lib/ruby/2.5.0/socket.rb:1108:in `lstat'
ArgumentError (path name contains null byte)

Impact

It may be connected to an unintended socket.

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

It may be connected to an unintended socket.

What the attacker needed

Ability to supply a socket path; Ruby socket library in use

How it was found

  1. Open a UNIX server socket using a path that contains a null byte followed by extra text.
  2. Connect a client socket using the same path prefix but a different suffix after the null.
  3. Observe that the connection succeeds and data is exchanged, showing both sides used the truncated path.
  4. Try the server-loop and server-socket helpers with a null-byte path and note they correctly raise an error.

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 UNIX domain socket is a way for programs on the same machine to talk to each other, identified by a file path. Some Ruby functions accepted a path with a hidden null character in the middle, and the system only looked at the part before it, so the program used a different socket than intended. That mismatch could let someone redirect a connection to a socket they control.

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.