Subversion — 1 vulnerability check

noctis ships 1 vulnerability check for Subversion, covering 1 CVE; each one has to observe the bug on the live service before it reports a finding.

← All products · Feeds on GitHub

Subversion svnserve < 1.0.5 svn:// protocol parser integer overflow

CVECVE-2004-0413
Severitycritical · CVSS 10.0
Categoryrce — Remote code execution
Servicessvn, subversion, svnserve
Detectiontcp_open, script, tcp_send, tcp_close, set_var, match · highest QoD 75
Feedtests/vulnerabilities/subversion/CVE-2004-0413.yaml

libsvn_ra_svn in Subversion before 1.0.5 trusts the length prefix of every string in the svn:// protocol: read_item() allocates `length + 1` bytes and then reads `length` bytes into it, so a huge length wraps the allocation size and overflows the heap of svnserve. A remote unauthenticated client can crash svnserve and possibly run code. Fixed in 1.0.5.

How the detection works (both checked against the 1.0.4 / 1.0.5 sources): - Parser behaviour (the decisive signal). After the greeting the feed sends `( 2 ( edit-pipeline ) 24:svn://host/svn/VT-Testr0x )`, a 25-byte URL behind a 24-byte length. The fix commit rewrote read_item(): before 1.0.5 the string branch returns right after reading the string, so the byte that follows is consumed and never checked; from 1.0.5 on it must be whitespace, otherwise "Malformed network data" and svnserve closes the connection without writing anything. So this off-by-one request is answered (`( failure ( ( 210005 ...'svn://host/svn/VT-Testr0' ...`) only by the vulnerable parser. Read-only, nothing is allocated beyond the 24 bytes; the overflow itself (a huge length) is never sent. - Source path (supporting evidence). svnserve 1.0.x writes the svn_error_t's __FILE__ in every failure tuple and Subversion compiles sources as `$(abs_srcdir)/subversion/...`, so a tarball build leaks e.g. `/usr/src/subversion-1.0.4/subversion/svnserve/serve.c`. A second, well-formed request (correct length 25) collects it for the evidence; it is not required.

Because the decision rests on the fixed parser's behaviour, not on a version string, builds from a checkout or a renamed directory are found, and a distro 1.0.x package with the fix backported is not flagged. The greeting must be an svn:// greeting (`( success (`) and the answer must be an svn `failure`/`success` tuple; the feed runs on every port the service scan reports as svn, not only 3690. Limit: only protocol-2 servers (0.37 / 1.0.x) answer the probe; early 0.x pre-releases that speak protocol 1 only are not reported.

How noctis detects it

  1. Opens a persistent TCP/TLS socket
  2. Parses / computes the next value with a Rhai script
  3. Sends ( 2 ( edit-pipeline ) 24:svn://host/svn/VT-Testr0x ) on the open socket
  4. Opens a persistent TCP/TLS socket
  5. Sends ( 2 ( edit-pipeline ) 25:svn://host/svn/VT-Testr0x ) on the open socket
  6. Parses / computes the next value with a Rhai script
  7. Checks res.lenient for ^true$ → finding QoD 75: Subversion svnserve < 1.0.5 svn:// protocol parser integer overflow (CVE-2004-0413)

References:

Feed source — tests/vulnerabilities/subversion/CVE-2004-0413.yaml
uid: d741ae40-6829-4824-8b8f-6979b4cce993
name: "Subversion svnserve < 1.0.5 svn:// protocol parser integer overflow (CVE-2004-0413)"
description: |
  libsvn_ra_svn in Subversion before 1.0.5 trusts the length prefix of every
  string in the svn:// protocol: read_item() allocates `length + 1` bytes and
  then reads `length` bytes into it, so a huge length wraps the allocation size
  and overflows the heap of svnserve. A remote unauthenticated client can crash
  svnserve and possibly run code. Fixed in 1.0.5.

  How the detection works (both checked against the 1.0.4 / 1.0.5 sources):
  - Parser behaviour (the decisive signal). After the greeting the feed sends
    `( 2 ( edit-pipeline ) 24:svn://host/svn/VT-Testr0x )`, a 25-byte URL behind a
    24-byte length. The fix commit rewrote read_item(): before 1.0.5 the string
    branch returns right after reading the string, so the byte that follows is
    consumed and never checked; from 1.0.5 on it must be whitespace, otherwise
    "Malformed network data" and svnserve closes the connection without writing
    anything. So this off-by-one request is answered (`( failure ( ( 210005
    ...'svn://host/svn/VT-Testr0' ...`) only by the vulnerable parser. Read-only,
    nothing is allocated beyond the 24 bytes; the overflow itself (a huge length)
    is never sent.
  - Source path (supporting evidence). svnserve 1.0.x writes the svn_error_t's
    __FILE__ in every failure tuple and Subversion compiles sources as
    `$(abs_srcdir)/subversion/...`, so a tarball build leaks e.g.
    `/usr/src/subversion-1.0.4/subversion/svnserve/serve.c`. A second, well-formed
    request (correct length 25) collects it for the evidence; it is not required.

  Because the decision rests on the fixed parser's behaviour, not on a version
  string, builds from a checkout or a renamed directory are found, and a distro
  1.0.x package with the fix backported is not flagged. The greeting must be an
  svn:// greeting (`( success (`) and the answer must be an svn `failure`/`success`
  tuple; the feed runs on every port the service scan reports as svn, not only 3690.
  Limit: only protocol-2 servers (0.37 / 1.0.x) answer the probe; early 0.x
  pre-releases that speak protocol 1 only are not reported.
cves: [CVE-2004-0413]
cvss: 10.0
severity: critical
category: rce
confidence_base: 0.30
tags: [subversion, svnserve, svn, integer-overflow, heap-overflow, unauthenticated, openvas]
services: [svn, subversion, svnserve]
author: noctis
version: "1.0.0"
references:
  - "https://nvd.nist.gov/vuln/detail/CVE-2004-0413"
  - "https://subversion.apache.org/security/CAN-2004-0413-advisory.txt"
  - "https://security-tracker.debian.org/tracker/CVE-2004-0413"

steps:
  # ── 1. Off-by-one request (the NASL's own bytes) on a fresh connection ────
  - id: connect
    action: tcp_open
    handle: svn
    port: "{{port}}"
    read_banner: true
    timeout_secs: 10
    store_as: conn

  - id: is-svn
    action: script
    store_as: gate
    code: |
      conn.connected == true && type_of(conn.banner) == "string"
        && ereg("^\\(\\s*success\\s+\\(\\s*[0-9]+\\s+[0-9]+\\s+\\(", conn.banner)

  - id: off-by-one
    action: tcp_send
    handle: svn
    condition: "gate == true"
    send: "( 2 ( edit-pipeline ) 24:svn://host/svn/VT-Testr0x ) "
    timeout_secs: 10
    store_as: probe

  - id: close
    action: tcp_close
    handle: svn

  # ── 2. Well-formed request (correct length) — evidence only: source path ──
  - id: init-ctl
    action: set_var
    var_name: ctl_reply
    var_value: ""

  - id: connect-ctl
    action: tcp_open
    handle: ctl
    condition: "gate == true"
    port: "{{port}}"
    read_banner: true
    timeout_secs: 10
    store_as: conn2

  - id: well-formed
    action: tcp_send
    handle: ctl
    condition: "gate == true && conn2.connected == true"
    send: "( 2 ( edit-pipeline ) 25:svn://host/svn/VT-Testr0x ) "
    timeout_secs: 10
    store_as: ctl_reply

  - id: close-ctl
    action: tcp_close
    handle: ctl

  - id: evaluate
    action: script
    condition: "gate == true"
    store_as: res
    code: |
      fn text(r) {
        if type_of(r) == "map" && r.responded == true && type_of(r.response) == "string" { r.response } else { "" }
      }
      let p = text(probe);
      let c = text(ctl_reply);
      let lenient = ereg("^\\(\\s*(failure|success)\\s+\\(", p);
      let m = eregmatch("subversion-([0-9]+\\.[0-9]+\\.[0-9]+)/", p + " " + c);
      let ver = if type_of(m) == "array" && m.len() > 1 { m[1] } else { "unknown (no source path in the reply)" };
      #{ lenient: lenient, reply: p, version: ver }

  - id: confirm
    action: match
    condition: "gate == true"
    source: res.lenient
    pattern: "^true$"
    on_match:
      finding:
        title: "Subversion svnserve < 1.0.5 svn:// protocol parser integer overflow (CVE-2004-0413)"
        description: "svnserve answered an svn:// request whose string is one byte longer than its declared length. Only the libsvn_ra_svn parser of Subversion before 1.0.5 accepts this (1.0.5 rewrote read_item() together with the length-overflow fix and rejects it); that parser trusts string lengths, letting a remote unauthenticated client overflow the heap of svnserve (denial of service, possibly code execution)."
        remediation: "Upgrade Subversion to 1.0.5 or later (any supported release today), and restrict access to svnserve (TCP/3690) to trusted clients."
        confidence_delta: 0.50
        qod: 75
        evidence: "Off-by-one request `24:svn://host/svn/VT-Testr0x` answered (fixed parsers close silently): {{res.reply}} — source version: {{res.version}}"

View these feeds on GitHub