Skip to content
Smuggling / CRLF Disclosed report Intermediate

Ruby:HTTP Header injection in 'net/http'

The Ruby net/http library did not reject a request path containing carriage-return and line-feed characters, so a crafted path could inject extra HTTP headers into the outgoing request. An attacker who controls the path passed to net/http could add arbitrary headers or even smuggle a second request to the target server.

rootredrain Follow

Originally disclosed on HackerOne

  • Disclosed after 8 months

Hi,

I would like to report a HTTP Header injection vulnerability in 'net/http' that allows attackers to inject arbitrary headers in request even create a new evil request.

###PoC

require 'net/http'
http = Net::HTTP.new('192.168.30.214','80')
res = http.get("/r.php HTTP/1.1\r\nx-injection: memeda")

222333.png
222333.png From the original on HackerOne

###Example Server Code:

#!/usr/bin/env ruby
require 'sinatra'
require 'uri'
require 'net/http'

get '/' do
  'hello world'
end

post '/' do
  ip = params[:ip]
  port = params[:port]
  path = params[:path]

  # do what you want
  http = Net::HTTP.new ip, port.to_i
  res = http.get path

  res.body

end

post data:

ip=192.168.30.214&port=80&path=/r.php%20HTTP/1.1%0d%0ax-injection: memeda

print_r all HTTP Headers:

123123.png
123123.png From the original on HackerOne

###Create an evil request

post data:

4444.png
4444.png From the original on HackerOne

server log:

5555.png
5555.png From the original on HackerOne

###Suggestion:

Should validate URI legality before send request

btw,

Cloud I have a CVEID with this vulnerability? reported by @redrain([email protected]) and @ztz([email protected])

The original report as published on HackerOne, by rootredrain. 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 library did not validate the request path for CR/LF characters before writing it into the raw HTTP request line.

Impact

An attacker who can influence the path passed to net/http could inject arbitrary headers into the request, and the report claims a second request could be smuggled to the target server.

What the attacker needed

Attacker controls the path given to net/http

How it was found

  1. Create a Net::HTTP object pointing at a target host and port.
  2. Call get with a path that contains CRLF characters followed by an extra header.
  3. Observe that the target server receives the injected header.

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 program builds an HTTP request, it puts the path on one line and the headers on the following lines. If the path contains special line-break characters, the server reads the rest of the path as if it were a new header. Here the Ruby library passed the path through without checking, so an attacker could slip in their own headers.

What is Smuggling / CRLF?

A front end and a back end split one connection's bytes into requests differently, letting an attacker hide a request inside another user's.

More from Ruby

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Request smuggling and header injection

The lesson behind this report.

A front end and a back end split one connection's bytes into requests differently, letting an attacker hide a request inside another user's.