<?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>Phpspreadsheet — CraftedSignal Threat Feed</title><link>https://feed.craftedsignal.io/tags/phpspreadsheet/</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, 30 Jan 2024 12:00:00 +0000</lastBuildDate><atom:link href="https://feed.craftedsignal.io/tags/phpspreadsheet/feed.xml" rel="self" type="application/rss+xml"/><item><title>PhpSpreadsheet SSRF and RCE Vulnerability via IOFactory::load</title><link>https://feed.craftedsignal.io/briefs/2024-01-30-phpspreadsheet-rce-ssrf/</link><pubDate>Tue, 30 Jan 2024 12:00:00 +0000</pubDate><author>hello@craftedsignal.io</author><guid isPermaLink="true">https://feed.craftedsignal.io/briefs/2024-01-30-phpspreadsheet-rce-ssrf/</guid><description>PhpSpreadsheet is vulnerable to Server-Side Request Forgery (SSRF) and Remote Code Execution (RCE) due to improper validation of filenames in the IOFactory::load function, exploitable via PHP wrappers like `phar://` and `ftp://`.</description><content:encoded><![CDATA[<p>PhpSpreadsheet, a widely used PHP library for reading and writing spreadsheet files, is susceptible to a critical vulnerability that can lead to both Server-Side Request Forgery (SSRF) and Remote Code Execution (RCE). The vulnerability stems from insufficient validation of the <code>$filename</code> parameter passed to the <code>IOFactory::load</code> function. When this parameter is user-controlled, attackers can leverage PHP wrappers such as <code>ftp://</code>, <code>phar://</code>, and <code>ssh2.sftp://</code> to bypass the <code>is_file</code> check, leading to malicious file inclusion or arbitrary code execution. This flaw affects versions up to and including 1.30.2, as well as versions 2.0.0 through 5.5.0. Exploitation can occur even if the specified file inside the phar archive does not exist or is not a supported file type, potentially masking the attack. Due to PhpSpreadsheet&rsquo;s widespread use in other popular libraries like <code>maatwebsite/excel</code> and <code>sonata-project/exporter</code>, the impact of this vulnerability is significant.</p>
<h2 id="attack-chain">Attack Chain</h2>
<ol>
<li>An attacker crafts a malicious phar archive (<code>exploit.xlsx</code>) containing a PHP object with a <code>__destruct</code> method that executes arbitrary code via <code>shell_exec</code>.</li>
<li>The attacker hosts the malicious phar archive on a web server or makes it accessible through other means.</li>
<li>The attacker crafts a request to a vulnerable web application using PhpSpreadsheet, providing a <code>phar://</code> URL (e.g., <code>phar://exploit.xlsx/whatever</code>) as the <code>$filename</code> parameter to <code>IOFactory::load</code>.</li>
<li><code>IOFactory::load</code> attempts to load the file specified in the <code>$filename</code> parameter, which passes through the vulnerable <code>is_file</code> check.</li>
<li>The <code>phar://</code> wrapper triggers PHP&rsquo;s phar extension, which deserializes the metadata within the <code>exploit.xlsx</code> archive.</li>
<li>Deserialization of the malicious PHP object triggers the <code>__destruct</code> method, executing the attacker&rsquo;s arbitrary code via <code>shell_exec</code>, achieving RCE. The code creates <code>/tmp/poc.txt</code> in the example.</li>
<li>Alternatively, the attacker provides an <code>ftp://</code> URL to <code>IOFactory::load</code>, pointing to an attacker-controlled FTP server.</li>
<li>The vulnerable <code>is_file</code> check allows the <code>ftp://</code> connection, leading to an SSRF vulnerability where the server running PhpSpreadsheet connects to the attacker&rsquo;s specified FTP server.</li>
</ol>
<h2 id="impact">Impact</h2>
<p>Successful exploitation of this vulnerability can lead to a range of severe consequences. Remote Code Execution (RCE) allows an attacker to execute arbitrary commands on the server, potentially leading to complete system compromise. The SSRF vulnerability enables an attacker to probe internal network resources, potentially exposing sensitive information or allowing further attacks on internal systems. Given PhpSpreadsheet&rsquo;s use in numerous web applications and frameworks, a successful attack could impact a large number of users and organizations. Example impact includes attackers gaining initial access to internal applications.</p>
<h2 id="recommendation">Recommendation</h2>
<ul>
<li>Apply the suggested mitigations by either checking for PHP wrappers in the filename before calling <code>is_file</code> or by using <code>realpath</code> to ensure a clean absolute path (see code snippets in the advisory).</li>
<li>Deploy the Sigma rule <code>Detect_PhpSpreadsheet_Phar_Wrapper</code> to detect attempts to exploit the RCE vulnerability by monitoring process creation events with command lines containing &ldquo;phar://&rdquo; and <code>php</code>.</li>
<li>Deploy the Sigma rule <code>Detect_PhpSpreadsheet_Ftp_Wrapper</code> to detect attempts to exploit the SSRF vulnerability by monitoring network connections with destination ports on FTP protocol (21) and file paths contain ftp.</li>
<li>Monitor web server logs for requests containing the <code>phar://</code> or <code>ftp://</code> schemes in the filename parameter to <code>IOFactory::load</code>.</li>
</ul>
]]></content:encoded><category domain="severity">critical</category><category domain="type">advisory</category><category>phpspreadsheet</category><category>ssrf</category><category>rce</category><category>php</category><category>deserialization</category></item><item><title>PhpSpreadsheet XML Reader Denial of Service via Unbounded Row Index</title><link>https://feed.craftedsignal.io/briefs/2024-01-09-phpspreadsheet-dos/</link><pubDate>Tue, 09 Jan 2024 18:45:00 +0000</pubDate><author>hello@craftedsignal.io</author><guid isPermaLink="true">https://feed.craftedsignal.io/briefs/2024-01-09-phpspreadsheet-dos/</guid><description>PhpSpreadsheet is vulnerable to a denial-of-service attack by crafting a SpreadsheetML XML file with an excessively large row index, which exhausts server CPU resources due to unbounded iteration.</description><content:encoded><![CDATA[<p>The PhpSpreadsheet library is susceptible to a denial-of-service (DoS) vulnerability within its SpreadsheetML XML reader (<code>Reader\Xml</code>). This flaw arises because the reader fails to validate the <code>ss:Index</code> row attribute against the maximum allowed row count (<code>AddressRange::MAX_ROW = 1,048,576</code>). By crafting a malicious SpreadsheetML XML file containing an extremely large <code>ss:Index</code> value (e.g., &ldquo;999999999&rdquo;) on a <code>&lt;Row&gt;</code> element, an attacker can inflate the internal <code>cachedHighestRow</code> property to approximately 1 billion. Subsequently, any call to <code>getRowIterator()</code> without a specified end row will attempt to iterate over this inflated range, leading to CPU exhaustion and ultimately a DoS condition. This issue affects versions of PhpSpreadsheet from 2.0.0 to 5.6.0 and poses a risk to PHP applications that process user-uploaded SpreadsheetML XML files.</p>
<h2 id="attack-chain">Attack Chain</h2>
<ol>
<li>An attacker crafts a malicious SpreadsheetML XML file (e.g., <code>poc.xml</code>).</li>
<li>The crafted XML file contains a <code>&lt;Row&gt;</code> element with an <code>ss:Index</code> attribute set to a very large integer (e.g., <code>ss:Index=&quot;999999999&quot;</code>).</li>
<li>A PHP application using PhpSpreadsheet loads the malicious XML file using <code>IOFactory::createReader('Xml')-&gt;load('poc.xml')</code>.</li>
<li>The <code>loadSpreadsheetFromFile</code> method in <code>src/PhpSpreadsheet/Reader/Xml.php</code> processes the <code>&lt;Row&gt;</code> element, reads the <code>ss:Index</code> value, and casts it to an integer without validation.</li>
<li>The <code>getRowDimension()</code> method in <code>src/PhpSpreadsheet/Worksheet.php</code> is called with the attacker-controlled <code>$rowID</code>, inflating the <code>cachedHighestRow</code> property.</li>
<li>A subsequent call to <code>$sheet-&gt;getRowIterator()</code> attempts to iterate from the beginning to the inflated <code>cachedHighestRow</code>, triggering excessive CPU consumption.</li>
<li>The server&rsquo;s CPU resources are exhausted, leading to a denial-of-service condition.</li>
</ol>
<h2 id="impact">Impact</h2>
<p>The vulnerability allows attackers to cause a denial-of-service condition on servers running PHP applications that utilize PhpSpreadsheet to process SpreadsheetML XML files. The impact includes:</p>
<ul>
<li>CPU exhaustion with a small malicious file (~300 bytes).</li>
<li>Blocking PHP worker processes, affecting concurrent users.</li>
<li>Triggering PHP <code>max_execution_time</code> limits while still consuming resources.</li>
<li>Applications are vulnerable without authentication if they allow the processing of uploaded SpreadsheetML files.</li>
</ul>
<h2 id="recommendation">Recommendation</h2>
<ul>
<li>Implement validation for the <code>ss:Index</code> attribute in <code>src/PhpSpreadsheet/Reader/Xml.php</code> to ensure it does not exceed <code>AddressRange::MAX_ROW</code>. Apply this validation to both <code>&lt;Row&gt;</code> and <code>&lt;Cell&gt;</code> elements. Use the fix from the advisory (<a href="https://github.com/advisories/GHSA-84wq-86v6-x5j6">https://github.com/advisories/GHSA-84wq-86v6-x5j6</a>) as a reference.</li>
<li>Deploy the Sigma rule <code>DetectSuspiciousPhpSpreadsheetXML</code> to detect the use of extremely large row indexes in SpreadsheetML files.</li>
<li>Monitor web server logs for requests uploading XML files and triggering high CPU usage, correlating with the execution of PhpSpreadsheet.</li>
</ul>
]]></content:encoded><category domain="severity">medium</category><category domain="type">advisory</category><category>denial-of-service</category><category>xml</category><category>phpspreadsheet</category></item><item><title>PhpSpreadsheet CPU Denial of Service via Unbounded Row Number</title><link>https://feed.craftedsignal.io/briefs/2024-01-03-phpspreadsheet-dos/</link><pubDate>Wed, 03 Jan 2024 12:00:00 +0000</pubDate><author>hello@craftedsignal.io</author><guid isPermaLink="true">https://feed.craftedsignal.io/briefs/2024-01-03-phpspreadsheet-dos/</guid><description>A vulnerability in PhpSpreadsheet exists where a crafted XLSX file containing a large row number can cause excessive CPU consumption due to unbounded loop iterations, leading to a denial of service.</description><content:encoded><![CDATA[<p>A vulnerability exists in PhpSpreadsheet versions 1.x through 5.6.0 where the XLSX reader does not properly validate row numbers read from XML attributes within a spreadsheet file. Specifically, the <code>ColumnAndRowAttributes::readRowAttributes()</code> method lacks a check against the maximum allowed row number (<code>AddressRange::MAX_ROW = 1,048,576</code>). An attacker can exploit this by crafting a minimal XLSX file (approximately 1.6KB) containing a <code>&lt;row r=&quot;999999999&quot;/&gt;</code> element. When processed, this inflates the <code>cachedHighestRow</code> property, causing subsequent row iteration operations to attempt nearly one billion loop cycles, thereby exhausting CPU resources and leading to a denial-of-service condition. This vulnerability can be exploited in web applications that accept user-uploaded spreadsheet files, making it a significant risk for systems using vulnerable versions of PhpSpreadsheet. The vulnerability was reported in GHSA-7c6m-4442-2x6m.</p>
<h2 id="attack-chain">Attack Chain</h2>
<ol>
<li>An attacker crafts a malicious XLSX file containing an XML <code>&lt;row&gt;</code> element with a large <code>r</code> attribute (e.g., <code>&lt;row r=&quot;999999999&quot;/&gt;</code>).</li>
<li>The attacker uploads the malicious XLSX file to a web application or system that uses PhpSpreadsheet to process spreadsheet files.</li>
<li>The PhpSpreadsheet library, specifically the <code>IOFactory::createReader('Xlsx')</code> component, is used to read the uploaded file.</li>
<li>During the parsing process, the <code>ColumnAndRowAttributes::readRowAttributes()</code> method reads the large row number from the XML attribute.</li>
<li>The large row number is then used to update the <code>cachedHighestRow</code> property in the <code>Worksheet</code> object, effectively setting it to a very high value.</li>
<li>A subsequent operation that iterates over rows using <code>getRowIterator()</code> or retrieves the highest row using <code>getHighestRow()</code> triggers a loop that iterates up to the inflated <code>cachedHighestRow</code> value.</li>
<li>The excessive number of loop iterations consumes a significant amount of CPU resources, leading to a denial-of-service condition.</li>
<li>The application becomes unresponsive or crashes due to the CPU exhaustion.</li>
</ol>
<h2 id="impact">Impact</h2>
<p>Successful exploitation of this vulnerability leads to a CPU denial of service. A small, 1.6KB crafted XLSX file can trigger almost one billion iterations, causing the system to become unresponsive for an extended period (estimated at ~144 seconds per file). This impacts any application using <code>getRowIterator()</code> or <code>getHighestRow()</code> methods, making the system unavailable. Applications processing the spreadsheet may also exhaust memory if they attempt to accumulate data during the iteration process. The high amplification factor (small input leading to massive CPU consumption) makes this vulnerability particularly dangerous, especially in web applications that process user-supplied spreadsheets.</p>
<h2 id="recommendation">Recommendation</h2>
<ul>
<li>Apply the recommended fix by adding row bounds validation in <code>readRowAttributes()</code> to check if <code>$rowIndex</code> is within the acceptable range (1 to <code>AddressRange::MAX_ROW</code>). This is the primary recommendation from the source advisory.</li>
<li>Deploy the Sigma rule <code>Detect PhpSpreadsheet Excessive Row Iteration</code> to detect processes that may be attempting to process XLSX files with extremely high row numbers, indicating a potential exploitation attempt.</li>
<li>Monitor web server logs for suspicious file uploads, specifically XLSX files with unusually small sizes, which might indicate an attempt to upload a malicious file exploiting this vulnerability.</li>
</ul>
]]></content:encoded><category domain="severity">medium</category><category domain="type">advisory</category><category>denial-of-service</category><category>phpspreadsheet</category><category>xlsx</category><category>php</category></item></channel></rss>