<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>PhpMyFAQ — CraftedSignal Threat Feed</title><link>https://feed.craftedsignal.io/products/phpmyfaq/</link><description>Trending threats, MITRE ATT&amp;CK coverage, and detection metadata — refreshed continuously.</description><generator>Hugo</generator><language>en</language><managingEditor>hello@craftedsignal.io</managingEditor><webMaster>hello@craftedsignal.io</webMaster><lastBuildDate>Tue, 09 Jan 2024 12:00:00 +0000</lastBuildDate><atom:link href="https://feed.craftedsignal.io/products/phpmyfaq/feed.xml" rel="self" type="application/rss+xml"/><item><title>phpMyFAQ Unauthenticated SQL Injection via User-Agent Header</title><link>https://feed.craftedsignal.io/briefs/2024-01-phpmyfaq-sql-injection/</link><pubDate>Tue, 09 Jan 2024 12:00:00 +0000</pubDate><author>hello@craftedsignal.io</author><guid isPermaLink="true">https://feed.craftedsignal.io/briefs/2024-01-phpmyfaq-sql-injection/</guid><description>Unauthenticated SQL injection vulnerability exists in phpMyFAQ &lt;= 4.1.1 due to improper handling of the User-Agent header in BuiltinCaptcha, allowing attackers to inject malicious SQL payloads and potentially gain complete control of the datastore.</description><content:encoded><![CDATA[<p>phpMyFAQ versions 4.1.1 and earlier are vulnerable to unauthenticated SQL injection in the BuiltinCaptcha component. The vulnerability stems from the improper handling of the User-Agent header and client IP address in the <code>garbageCollector()</code> and <code>saveCaptcha()</code> methods within <code>phpmyfaq/src/phpMyFAQ/Captcha/BuiltinCaptcha.php</code>. These methods fail to sanitize user-supplied data before incorporating it into SQL queries, specifically a DELETE and an INSERT statement, respectively. An attacker can inject arbitrary SQL commands by crafting a malicious User-Agent header and sending a GET request to the <code>/api/captcha</code> endpoint. The vulnerability was verified against phpMyFAQ 4.2.0-alpha, demonstrating a significant time difference in response times between clean and injected requests. This issue allows attackers to potentially read sensitive data, manipulate database records, and gain complete control of the phpMyFAQ datastore.</p>
<h2 id="attack-chain">Attack Chain</h2>
<ol>
<li>An unauthenticated attacker crafts a malicious SQL payload.</li>
<li>The attacker injects the payload into the User-Agent header of an HTTP GET request.</li>
<li>The attacker sends the crafted GET request to the <code>/api/captcha</code> endpoint of the phpMyFAQ instance.</li>
<li>The <code>CaptchaController.php</code> processes the request, instantiating the <code>BuiltinCaptcha</code> class.</li>
<li>The <code>BuiltinCaptcha</code> class retrieves the unsanitized User-Agent header.</li>
<li>The <code>getCaptchaImage()</code> method calls both the <code>saveCaptcha()</code> and <code>garbageCollector()</code> methods.</li>
<li>These methods execute the SQL queries with the injected payload, due to the lack of sanitization.</li>
<li>The attacker leverages time-based blind SQL injection to extract sensitive data or manipulate database records.</li>
</ol>
<h2 id="impact">Impact</h2>
<p>Successful exploitation of this vulnerability allows an attacker to perform unauthenticated remote SQL injection against the phpMyFAQ database. In a default installation, this includes the ability to read user credential hashes, the admin token, SMTP credentials, and the content of FAQ entries, including those marked as private or restricted. Attackers can also tamper with or wipe arbitrary rows within the database due to the ability to modify DELETE queries. The absence of authentication, CSRF protection, or rate limiting on the <code>/api/captcha</code> endpoint makes exploitation straightforward.</p>
<h2 id="recommendation">Recommendation</h2>
<ul>
<li>Apply the recommended fix provided in the advisory by implementing input sanitization using <code>Database::escape()</code> before interpolating values into SQL queries. Specifically, modify <code>phpmyfaq/src/phpMyFAQ/Captcha/BuiltinCaptcha.php:298-325</code> and <code>phpmyfaq/src/phpMyFAQ/Captcha/BuiltinCaptcha.php:330</code> as described in the advisory.</li>
<li>Audit the entire codebase for instances of <code>sprintf</code> used in conjunction with SQL queries, as suggested by the advisory, to identify and remediate any other potential SQL injection vulnerabilities.</li>
<li>Deploy the provided Sigma rule &ldquo;phpMyFAQ Captcha API SQL Injection Attempt&rdquo; to detect attempts to exploit this vulnerability by monitoring for suspicious User-Agent headers in requests to <code>/api/captcha</code>.</li>
<li>Upgrade to a patched version of phpMyFAQ that addresses this vulnerability, if available.</li>
</ul>
]]></content:encoded><category domain="severity">critical</category><category domain="type">advisory</category><category>sql-injection</category><category>unauthenticated</category><category>web-application</category></item></channel></rss>