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.
- 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:
- 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
- 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
- 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 :-)
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
- Run the provided WEBrick server with BasicAuth on a local port.
- From another terminal, send a request with a username containing an escape sequence.
- 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.