CVE-2024-27299: Phpmyfaq/phpmyfaq SQL Injection Vulnerability

HIGH
Advisory Identifier: GHSA-qgxx-4xv5-6hcw
CVSS 8.8
CWE-89
Published
Advisory Summary

CVE-2024-27299 is a HIGH (CVSS 8.8) sql injection vulnerability (CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')) affecting Phpmyfaq/phpmyfaq libraries in the Packagist ecosystem. The issue involves phpmyfaq sql injection at "save news". Remediation is available by upgrading affected packages to version 3.2.6.

CVE-2024-27299 at a Glance

CVE Identifier CVE-2024-27299
GHSA Identifier GHSA-qgxx-4xv5-6hcw
Severity HIGH
CVSS v3.1 Base Score 8.8
CWE Classification CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
Affected Product Phpmyfaq/phpmyfaq
Package Ecosystem Packagist
Published Date
Last Updated

Security Impact

CVSS: 8.8

The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H).

Attack Vector Network (AV:N)
Attack Complexity Low (AC:L)
Privileges Required Low (PR:L)
User Interaction None (UI:N)
Scope Unchanged (S:U)
Confidentiality High (C:H)
Integrity High (I:H)
Availability High (A:H)

How to Fix CVE-2024-27299

To remediate this vulnerability, upgrade all affected Phpmyfaq/phpmyfaq dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

phpmyfaq/phpmyfaq fixed: 3.2.6
Upgrade phpmyfaq/phpmyfaq to 3.2.6
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

inspect dependencies for phpmyfaq/phpmyfaq

How to Check if You Are Affected

To determine whether your application is affected by CVE-2024-27299, inspect your project dependencies for Phpmyfaq/phpmyfaq:

inspect dependencies for phpmyfaq/phpmyfaq

Analyze the terminal output to locate any version of Phpmyfaq/phpmyfaq in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 3.2.6), your application is affected.

Note: Verify declared build manifests and deployed runtime container environments.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection'), where the product constructs all or part of an sql command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended sql command when it is sent to a downstream component. without sufficient removal or quoting of sql syntax in user-controllable inputs, the generated sql query can cause those inputs to be interpreted as sql instead of ordinary user data. In Phpmyfaq/phpmyfaq, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

### Summary A SQL injection vulnerability has been discovered in the the "Add News" functionality due to improper escaping of the email address. This allows any authenticated user with the rights to add/edit FAQ news to exploit this vulnerability to exfiltrate data, take over accounts and in some cases, even achieve RCE. ### Details The vulnerable field lies in the `authorEmail` field which uses PHP's `FILTER_VALIDATE_EMAIL` filter. This filter is insufficient in protecting against SQL injection attacks and should still be properly escaped. However, in this version of phpMyFAQ (3.2.5), this field is not escaped properly can be used together with other fields to fully exploit the SQL injection vulnerability. ### PoCs 4 PoCs are demonstrated here to illustrate the potential impacts. #### PoC 1 - Postgres Time Based SQLi 1. Login as admin or any user with the rights to view and save news. 2. Navigate to "../phpmyfaq/admin/?action=news", click on "Add news", fill in some data, send and intercept the request. 3. Modify the intercepted "/admin/?action=save-news" request to look like the SS below: 3.1 - Set the "authorEmail" field in the body to "`test'/*@[email.com](http://email.com/)`". 3.2 - Set the "linkTitle" field in the body to "`*/,1,1,1,1,1,1,1);select+pg_sleep(5)--`". 3.3 - Set the rest of the fields as empty and send the request. 4. Notice the 5s delay in the response time, indicating that the sleep function was executed, verifying the existence of the SQLi vulnerability. ![image](https://github.com/thorsten/phpMyFAQ/assets/63487456/b19a3f88-0794-4919-a485-60f45cfc83a5) #### PoC 2 - SQLi to Read Data from PostgresDB 1. Steps 1 and 2 are the same as PoC 1. 2. Modify the intercepted "/admin/?action=save-news" request to look like the SS below and send the request: 2.1 - Set the "authorEmail" field in the body to "`test'/*@[email.com](http://email.com/)`". 2.2 - Set the "linkTitle" field in the body to "`*/,1,1,1,1,1,1,1);SELECT+remember_me+FROM+faquser+limit+1+offset+1%3b--`". ![image (1)](https://github.com/thorsten/phpMyFAQ/assets/63487456/131a6b5f-cfbf-4d94-9851-73f4d9e1605a) #### PoC 3 - SQLi to Read Files from PostgresDB 1. Steps 1 and 2 are the same as PoC 1. 2. Modify the intercepted "/admin/?action=save-news" request to look like the SS below and send the request: 2.1 - Set the "authorEmail" field in the body to "`test'/*@[email.com](http://email.com/)`". 2.2 - Set the "linkTitle" field in the body to "`*/,1,1,1,1,1,(select+pg_read_file(CONCAT(CHR(67),CHR(58),CHR(92),CHR(87),CHR(105),CHR(110),CHR(100),CHR(111),CHR(119),CHR(115),CHR(92),CHR(119),CHR(105),CHR(110),CHR(46),CHR(105),CHR(110),CHR(105)))),1)--`". (_the CONCAT() and CHR() functions are used to bypass the escaping of single quotes, these characters in its decoded form is "select pg_read_file('C:\Windows\win.ini')"_) ![image (2)](https://github.com/thorsten/phpMyFAQ/assets/63487456/61857d4c-4eab-43e3-87fa-20eefe6553e5) #### PoC 4 - SQLi to Shell It is also possible to obtain a shell if superuser is enabled on the postgres DB. These are the high level steps of the exploit chain: 1. Create a table called "cmd_exec" to store the payload. 2. Create a function in postgres to store the command to write a web shell to the "../htdocs" directory. (This step is required as CONCAT() function cannot be used to bypass the step where; "COPY cmd_exec FROM PROGRAM '<command>' " is run as it requires single quotes.) 3. Trigger the function to write the PHP web shell at "`http://<URL>/shell.php`" that takes in commands via the "?cmd=" parameter. 4. Send the Python reverse shell command via a GET request to launch the reverse shell. The video demo and the Python PoC script can be accessed from this link: https://drive.google.com/drive/folders/1BFL8GHIBxSUxu0TneYf66KjFA0A4RZga?usp=sharing ### Impact The SQL injection vulnerability discovered in the "Add News" functionality of the application allows authenticated users with appropriate privileges to execute malicious SQL queries, potentially leading to data exfiltration, account takeover, and even remote code execution. Attackers can exploit the vulnerability to read sensitive data from the database, such as user credentials and system files, compromising the confidentiality and integrity of the system. Moreover, successful exploitation may enable attackers to gain unauthorized access to user accounts or execute arbitrary commands on the server, impacting both system administrators and end users.

CVE-2024-27299 Affected Phpmyfaq/phpmyfaq Versions

1 component(s)
Fixed Versions:
3.2.6
Product / Package Ecosystem Affected Versions Fixed Version
phpmyfaq/phpmyfaq
Packagist
≥ 3.2.5
< 3.2.6
All 1 versions
3.2.5
3.2.6

References

Frequently Asked Questions

What is CVE-2024-27299?
CVE-2024-27299 is a security vulnerability in Phpmyfaq/phpmyfaq involving phpMyFAQ SQL Injection at "Save News" under CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection').
Which Phpmyfaq/phpmyfaq versions are affected?
Affected versions include releases prior to 3.2.6 across affected packages: phpmyfaq/phpmyfaq.
What version fixes CVE-2024-27299?
Upgrading to 3.2.6 (or the latest patched release for your respective branch) resolves the vulnerability.
Is phpmyfaq/phpmyfaq affected?
Yes, phpmyfaq/phpmyfaq is affected in releases prior to 3.2.6. Upgrade your dependency to 3.2.6 or later.
What is the CVSS score of CVE-2024-27299?
CVE-2024-27299 has a CVSS v3.1 base score of 8.8 (HIGH) with vector string CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H.
What CWE is associated with CVE-2024-27299?
CVE-2024-27299 is classified under CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') (The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. Without sufficient removal or quoting of SQL syntax in user-controllable inputs, the generated SQL query can cause those inputs to be interpreted as SQL instead of ordinary user data.).
How can I check Packagist dependencies for CVE-2024-27299?
Run the dependency tree command: 'inspect dependencies for phpmyfaq/phpmyfaq'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-qgxx-4xv5-6hcw",
  "modified" : "2024-03-25T22:28:25Z",
  "published" : "2024-03-25T19:44:05Z",
  "aliases" : [ "CVE-2024-27299" ],
  "summary" : "phpMyFAQ SQL Injection at \"Save News\"",
  "details" : "### Summary\nA SQL injection vulnerability has been discovered in the the \"Add News\" functionality due to improper escaping of the email address. This allows any authenticated user with the rights to add/edit FAQ news to exploit this vulnerability to exfiltrate data, take over accounts and in some cases, even achieve RCE.\n\n### Details\nThe vulnerable field lies in the  `authorEmail` field which uses PHP's `FILTER_VALIDATE_EMAIL` filter. This filter is insufficient in protecting against SQL injection attacks and should still be properly escaped. However, in this version of phpMyFAQ (3.2.5), this field is not escaped properly can be used together with other fields to fully exploit the SQL injection vulnerability.\n\n### PoCs\n4 PoCs are demonstrated here to illustrate the potential impacts.\n\n#### PoC 1 - Postgres Time Based SQLi\n1. Login as admin or any user with the rights to view and save news.\n2. Navigate to \"../phpmyfaq/admin/?action=news\", click on \"Add news\", fill in some data, send and intercept the request.\n3. Modify the intercepted \"/admin/?action=save-news\" request to look like the SS below:\n    3.1 - Set the \"authorEmail\" field in the body to \"`test'/*@[email.com](http://email.com/)`\".\n    3.2 - Set the \"linkTitle\" field in the body to \"`*/,1,1,1,1,1,1,1);select+pg_sleep(5)--`\".\n    3.3 - Set the rest of the fields as empty and send the request.\n4. Notice the 5s delay in the response time, indicating that the sleep function was executed, verifying the existence of the SQLi vulnerability.\n![image](https://github.com/thorsten/phpMyFAQ/assets/63487456/b19a3f88-0794-4919-a485-60f45cfc83a5)\n\n#### PoC 2 - SQLi to Read Data from PostgresDB \n1. Steps 1 and 2 are the same as PoC 1.\n2. Modify the intercepted \"/admin/?action=save-news\" request to look like the SS below and send the request:\n    2.1 - Set the \"authorEmail\" field in the body to \"`test'/*@[email.com](http://email.com/)`\".\n    2.2 - Set the \"linkTitle\" field in the body to \"`*/,1,1,1,1,1,1,1);SELECT+remember_me+FROM+faquser+limit+1+offset+1%3b--`\".\n![image (1)](https://github.com/thorsten/phpMyFAQ/assets/63487456/131a6b5f-cfbf-4d94-9851-73f4d9e1605a)\n\n#### PoC 3 - SQLi to Read Files from PostgresDB \n1. Steps 1 and 2 are the same as PoC 1.\n2. Modify the intercepted \"/admin/?action=save-news\" request to look like the SS below and send the request:\n    2.1 - Set the \"authorEmail\" field in the body to \"`test'/*@[email.com](http://email.com/)`\".\n    2.2 - Set the \"linkTitle\" field in the body to \"`*/,1,1,1,1,1,(select+pg_read_file(CONCAT(CHR(67),CHR(58),CHR(92),CHR(87),CHR(105),CHR(110),CHR(100),CHR(111),CHR(119),CHR(115),CHR(92),CHR(119),CHR(105),CHR(110),CHR(46),CHR(105),CHR(110),CHR(105)))),1)--`\". (_the CONCAT() and CHR() functions are used to bypass the escaping of single quotes, these characters in its decoded form is \"select pg_read_file('C:\\Windows\\win.ini')\"_)\n![image (2)](https://github.com/thorsten/phpMyFAQ/assets/63487456/61857d4c-4eab-43e3-87fa-20eefe6553e5)\n\n#### PoC 4 - SQLi to Shell\nIt is also possible to obtain a shell if superuser is enabled on the postgres DB. These are the high level steps of the exploit chain:\n\n1. Create a table called \"cmd_exec\" to store the payload.\n2. Create a function in postgres to store the command to write a web shell to the \"../htdocs\" directory. (This step is required as CONCAT() function cannot be used to bypass the step where; \"COPY cmd_exec FROM PROGRAM '<command>' \" is run as it requires single quotes.)\n3. Trigger the function to write the PHP web shell at \"`http://<URL>/shell.php`\" that takes in commands via the \"?cmd=\" parameter.\n4. Send the Python reverse shell command via a GET request to launch the reverse shell. \n\nThe video demo and the Python PoC script can be accessed from this link: https://drive.google.com/drive/folders/1BFL8GHIBxSUxu0TneYf66KjFA0A4RZga?usp=sharing\n\n### Impact\nThe SQL injection vulnerability discovered in the \"Add News\" functionality of the application allows authenticated users with appropriate privileges to execute malicious SQL queries, potentially leading to data exfiltration, account takeover, and even remote code execution. Attackers can exploit the vulnerability to read sensitive data from the database, such as user credentials and system files, compromising the confidentiality and integrity of the system. Moreover, successful exploitation may enable attackers to gain unauthorized access to user accounts or execute arbitrary commands on the server, impacting both system administrators and end users.\n",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "Packagist",
      "name" : "phpmyfaq/phpmyfaq"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "3.2.5"
      }, {
        "fixed" : "3.2.6"
      } ]
    } ],
    "versions" : [ "3.2.5" ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/thorsten/phpMyFAQ/security/advisories/GHSA-qgxx-4xv5-6hcw"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2024-27299"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/thorsten/phpMyFAQ/commit/1b68a5f89fb65996c56285fa636b818de8608011"
  }, {
    "type" : "WEB",
    "url" : "https://drive.google.com/drive/folders/1BFL8GHIBxSUxu0TneYf66KjFA0A4RZga?usp=sharing"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/thorsten/phpMyFAQ"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-89" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2024-03-25T19:44:05Z",
    "nvd_published_at" : "2024-03-25T19:15:57Z"
  }
}