Skip to content
Path traversal Write-up Intermediate

Partial File Read in phpList <= 3.6.12 (CVE-2023-35834)

The gchart.php script in phpList accepts a user-controlled URL parameter and passes it to file_get_contents without proper validation, allowing an attacker with admin access to read partial contents of arbitrary files on the server. The vulnerability is limited to the administration panel and the amount of data exfiltrated is constrained by the GET parameter length.

Vincent Herbulot Follow

Published on synacktiv.com

phpList is software for sending email newsletters, marketing campaigns and announcements: you can send to millions of subscribers or just to a few hundred. phpList is used via a web browser and installed on your server. 2.

Vincent Herbulot, Rémi Matasse (@_remsio_), on synacktiv.com

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 5 min read.

Context

phpList is software for sending email newsletters, marketing campaigns and announcements. It can send to millions of subscribers or just to a few hundred, is used through a web browser, and is installed on your own server. This write-up covers a partial file read that Synacktiv discovered in the project, tracked as CVE-2023-35834. The issue is a lack of control on user-provided input, and it is only exploitable from the administration panel of the phpList application. By exploiting it, an attacker can exfiltrate a partial content of any file readable by the system user running the server.

The affected file is gchart.php. The vulnerable code path takes a URL from a GET parameter, checks that it contains a particular Google Charts host string, and then fetches it with file_get_contents. The report says file_get_contents, along with other functions, allows an attack to blindly extract arbitrary file content by submitting a specially crafted PHP filter chain.

Setup

  • Target: phpList, tested against version 3.6.6 using the phplist-docker project for the proof of concept. The exploited file, gchart.php, is identical in the latest version of the project at the time, 3.6.12.
  • Affected versions: phpList 3.6.12 is affected, and anterior versions are likely to be vulnerable as well.
  • Precondition: an authenticated session on the administration panel. The vulnerability is only exploitable from the admin panel.
  • Tooling: the filters_chain_oracle_exploit tool was used to leak the content of the file.

Finding it

The url GET parameter in gchart.php is controlled by the user and reaches file_get_contents after an &amp; replacement and a substring check. The file_get_contents function, along with other functions, has been discovered to allow an attack to blindly extract arbitrary file content on the system by submitting a specially crafted PHP filter chain. That is the basis of the finding: user input reaches a file-reading function with insufficient restriction.

Exploitation

Step 1: Authenticate to the admin panel

Log in as an administrator on phpList. The exploit only works from the administration panel, so a valid admin session is required.

Step 2: Run the oracle tool against gchart.php

Once authenticated as admin, the following command exfiltrates a file content by exploiting gchart.php. Because the exploited variable is a GET parameter, the amount of data that can be exfiltrated is limited.

Bash
$ python3 filters_chain_oracle_exploit.py --target 'http://localhost:8000/lists/admin/?page=gchart' --file /etc/passwd --parameter url --headers='{"Cookie": "preferredLanguage=fr; browsetrail=%3Fpage%3Dupdatetranslation %26tk%[redacted]; browsetrail=; phpListSession=o86km1ie0uvk3m60b9c3l1cpj1"}' --verb GET --in_chain 'chart.apis.google.com/chart' [*] The following URL is targeted : http://localhost:8000/lists/admin/?page=gchart [*] The following local file is leaked : /etc/passwd [...] [*] You passed your payload on a GET parameter, the leak might be partial! (~135 chars max by default) b'[redacted] [redacted] czovZG' b'root:x:0:0:root:/root:/bin/bash\ndaemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin\ nbin:x:2:2:bin:/bin:/usr/sbin/nologin\nsys:x:3:3:sys:/d'

Key parts of the command:

  • --target points at the admin page with page=gchart, which is the endpoint that processes the url parameter.
  • --file /etc/passwd is the local file to leak.
  • --parameter url is the GET parameter carrying the filter chain.
  • --headers supplies the admin session cookie so the request is authorised.
  • --verb GET sends the payload as a GET request.
  • --in_chain 'chart.apis.google.com/chart' keeps the required substring in the generated chain so the application's check passes.

The tool warns that a GET parameter limits the leak to roughly 135 characters by default, so the output is partial.

Root cause

The vulnerable code is in gchart.php, in the url GET parameter:

PHP
<?php
[...]
$url = $_GET['url'];
$url = str_replace('&amp;', '&', $url);
if (strpos($url, 'chart.apis.google.com/chart') === false) {
    echo 'Error';
    exit;
}
[...]
$cache = Sql_Fetch_Row_Query(sprintf('select content from %s where url = "%s"', $GLOBALS['tables']['gchartcache'], $url), 1);
if (empty($cache[0])) {
    $content = file_get_contents($url);
    Sql_Query(sprintf('insert into %s (url,content,added) values("%s","%s",now())', $GLOBALS['tables']['gchartcache'], $url, base64_encode($content)), 1);
} else {
    $content = base64_decode($cache[0]);

The url GET parameter is controlled by the user. A transformation replaces all & characters with &amp;. The parameter is then checked to ensure that the string chart.apis.google.com/chart is present in the user-provided value. Finally, if the URL submitted by the user is not present in the database cache, it is opened and its content is read using file_get_contents.

The only validation is a substring check for chart.apis.google.com/chart, so a PHP filter chain that includes the required substring passes the check and is handed to file_get_contents. The report points to a separate publication for the full explanation of the technique. The report notes that PHP developers have been notified about this issue affecting multiple file read functions, and that a patch is not yet available at the time of writing, because it is a complex issue.

Impact

An attacker with access to the administration panel can exfiltrate a partial content of any file readable by the system user running the server. The leak is partial: because the exploited variable is a GET parameter, the amount of data that can be exfiltrated is limited (roughly 135 characters by default with the tool used). The vulnerability is only exploitable from the administration panel, so it requires an authenticated admin session.

Fix

phpList 3.6.13, released on 2023.05.26, contains the patch. The report does not describe the code change itself. The timeline records that the advisory was sent to the phpList developers on 2023.03.23, acknowledged on 2023.03.24 with a patch scheduled for the next release, followed up on 2023.04.25, patched in 3.6.13 on 2023.05.26, assigned CVE-2023-35834 on 2023.06.19, and publicly released on 2023.07.04.

Variants to test

  • Substring checks on URLs that can be satisfied by a filter chain: a positive result is a chain that still contains the required substring and reaches the file-reading function.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 14 min read.

What happened, in plain words

phpList is a piece of software that organisations install on their own web server to send email newsletters, marketing campaigns and announcements. It can handle a list of millions of subscribers or just a few hundred. People use it through a normal web browser, and the software runs on the server the organisation controls.

Synacktiv, a security research company, found a flaw in phpList. The flaw lets someone who is already logged in as an administrator make the server hand over part of the contents of a file stored on that server. The problem was given the identifier CVE-2023-35834. A CVE is a public catalogue number that security teams use to refer to one specific vulnerability, so that everyone is talking about the same thing.

The technical name for this kind of flaw is a "partial file read". "File read" means the server is tricked into reading a file and showing it to the attacker. "Partial" means the attacker does not get the whole file, only a piece of it, because of a size limit explained later.

The cause is a lack of control on input provided by the user. In plain terms: the application takes something a person types or sends, and uses it without checking it properly. The report says the flaw can only be exploited from the administration panel, so the attacker must already have an admin login. With that access, the attacker can pull out part of any file that the server's own system user is allowed to read.

The affected versions

phpList version 3.6.12 is affected. The report adds that earlier versions are likely to be vulnerable as well. "Earlier versions" means older releases of the same software; if a flaw exists in the current release, it often exists in the ones before it too, because the same code was carried forward.

The timeline

The report gives a table of dates. Here it is in the same order:

Date What happened
2023.03.23 The advisory was sent to the phpList developers at [redacted]
2023.03.24 phpList acknowledged the vulnerability and said a patch was planned for the next release
2023.04.25 Follow-up on the progress of phpList
2023.05.26 phpList 3.6.13 was released, containing the patch
2023.06.19 CVE-2023-35834 was assigned
2023.07.04 Public release of the advisory

An "advisory" is the formal write-up a security company sends to the makers of a product to describe a flaw, so they can fix it. A "patch" is the change to the software that closes the hole. The sequence matters: the researchers told the developers first, gave them time to fix it, and only published the details afterwards. This is the usual responsible way of handling a security finding.

The technical description

The exploit

The proof of concept was built using the phplist-docker project. "Docker" is a tool that packages software and everything it needs into a ready-to-run box, so a researcher can start a test copy of phpList quickly without configuring a real server. The proof of concept was tested against version 3.6.6, but the file that gets exploited, gchart.php, is identical in the latest version at the time, 3.6.12. That is why the finding applies to 3.6.12 even though the test ran on 3.6.6.

The tool filters_chain_oracle_exploit was used to leak the content of the file. "Leak" here simply means getting the data out of the server and into the attacker's hands.

Before any of this, the attacker logs in as an administrator on phpList. The report shows this state as Figure 1, "Logged as admin on phpList".

Once authenticated as admin, the following command can be used to exfiltrate a file's content by exploiting gchart.php. Because the exploited variable is a GET parameter, the amount of data that can be exfiltrated is limited.

Bash
$ python3 filters_chain_oracle_exploit.py --target 'http://localhost:8000/lists/admin/?page=gchart' --file /etc/passwd --parameter url --headers='{"Cookie": "preferredLanguage=fr; browsetrail=%3Fpage%3Dupdatetranslation %26tk%[redacted]; browsetrail=; phpListSession=o86km1ie0uvk3m60b9c3l1cpj1"}' --verb GET --in_chain 'chart.apis.google.com/chart' [*] The following URL is targeted : http://localhost:8000/lists/admin/?page=gchart [*] The following local file is leaked : /etc/passwd [...] [*] You passed your payload on a GET parameter, the leak might be partial! (~135 chars max by default) b'[redacted] [redacted] czovZG' b'root:x:0:0:root:/root:/bin/bash\ndaemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin\ nbin:x:2:2:bin:/bin:/usr/sbin/nologin\nsys:x:3:3:sys:/d'

Let us go through this command piece by piece, because every part has a purpose.

  1. python3 filters_chain_oracle_exploit.py runs a Python script. Python is a programming language; a script is a text file containing instructions. This particular script is the tool written by the researchers to automate the attack. You run it from a terminal, which is a text window where you type commands instead of clicking buttons.
  2. --target 'http://localhost:8000/lists/admin/?page=gchart' tells the tool which web address to send its requests to. A URL is the address of a page on the web, the same kind of address you type into a browser's address bar. localhost means "this same computer", and 8000 is a port number, a numbered door on the computer where the web server listens. The part ?page=gchart is a parameter: a piece of information appended to the address that tells the application which page or feature to load. Here it selects the gchart feature, which is the code that contains the flaw.
  3. --file /etc/passwd names the file on the server that the attacker wants to read. /etc/passwd is a standard file on Linux systems that lists the user accounts of the machine. It is a common target in demonstrations because it is readable by everyone on the system and its contents are easy to recognise.
  4. --parameter url says which input field carries the attack. The application reads a value named url from the request, and that is the value the tool will fill with its malicious content.
  5. --headers='{"Cookie": "..."}' adds extra information to each request. A header is a small labelled line that travels with every web request and response, carrying metadata such as what browser you use or what language you prefer. A cookie is a small piece of data that a website asks your browser to store and send back on every later request, so the site can remember who you are. The Cookie header here carries the admin's session: the proof that this browser is already logged in. Without it, the application would refuse the request.
  6. --verb GET chooses the HTTP method. HTTP is the language browsers and servers use to talk. A GET request is the ordinary kind your browser sends when you open a page: it asks the server to give you something. The alternative, POST, is used when you submit a form and send data in the body of the request. The tool is told to use GET because the vulnerable value is read from the address itself.
  7. --in_chain 'chart.apis.google.com/chart' is the string the application insists on finding inside the url value. The tool must build its malicious value so that this exact text still appears somewhere in it, otherwise the application's check fails and the request is rejected. This is the key trick: the check looks for a substring, and a substring can be hidden inside a much larger, harmful value.

After the command, the tool prints progress lines. [*] The following URL is targeted repeats the address being attacked. [*] The following local file is leaked repeats the file being read. The line [*] You passed your payload on a GET parameter, the leak might be partial! (~135 chars max by default) is a warning: because the attack value has to fit in a URL, and URLs have practical length limits, only about 135 characters of the file can come back by default. That is the reason the read is called partial.

The output then shows two lines beginning with b'...'. The b prefix means "bytes": raw data, not text. It shows the first few entries of /etc/passwd: root, daemon, bin and sys.

The details: where the flaw lives

The vulnerability arises in the gchart.php file, and more specifically in the url GET parameter. Here is the relevant code:

PHP
<?php
[...]
$url = $_GET['url'];
$url = str_replace('&amp;', '&', $url);
if (strpos($url, 'chart.apis.google.com/chart') === false) {
    echo 'Error';
    exit;
}
[...]
$cache = Sql_Fetch_Row_Query(sprintf('select content from %s where url = "%s"', $GLOBALS['tables']['gchartcache'], $url), 1);
if (empty($cache[0])) {
    $content = file_get_contents($url);
    Sql_Query(sprintf('insert into %s (url,content,added) values("%s","%s",now())', $GLOBALS['tables']['gchartcache'], $url, base64_encode($content)), 1);
} else {
    $content = base64_decode($cache[0]);

Line by line, in plain words:

  1. <?php marks the start of a block of PHP code. PHP is the programming language phpList is written in, and it runs on the server, not in your browser.
  2. [...] stands for code the report left out because it is not relevant to the flaw.
  3. $url = $_GET['url']; takes the value named url from the incoming request and stores it in a variable called $url. A variable is a named box that holds a value. $_GET is PHP's built-in way of exposing values that arrived in the address of a GET request. This is the moment user input enters the program.
  4. $url = str_replace('&amp;', '&', $url); replaces every occurrence of the text &amp; with a single & character. &amp; is how the ampersand is written in HTML, the language web pages are made of. This line is a small clean-up step.
  5. if (strpos($url, 'chart.apis.google.com/chart') === false) { asks a question: does the text chart.apis.google.com/chart appear anywhere inside $url? strpos finds the position of one piece of text inside another. If it returns false, the text was not found.
  6. echo 'Error'; and exit; are what happens when the answer is no: the program prints the word Error and stops immediately. So the only requirement to get past this gate is that the required text appears somewhere in the value.
  7. $cache = Sql_Fetch_Row_Query(sprintf('select content from %s where url = "%s"', ...), 1); looks in a database table for a previous entry matching this URL. A database is an organised store of data; a table is like a spreadsheet inside it. Sql_Fetch_Row_Query runs a database query and returns one row. The %s placeholders are filled in by sprintf with the table name and the URL. This is a cache: a store of results already fetched, so the same thing is not downloaded twice.
  8. if (empty($cache[0])) { checks whether nothing was found in the cache. If the cache is empty, the code goes on to fetch the URL.
  9. $content = file_get_contents($url); is the dangerous line. file_get_contents is a PHP function that opens whatever it is given and returns its contents as a string. It is meant to fetch a web page, but PHP is flexible about what it will open, and that flexibility is what the attack abuses.
  10. Sql_Query(sprintf('insert into %s (url,content,added) values("%s","%s",now())', ...), 1); saves the fetched content into the cache table, encoded with base64_encode, together with the URL and the current time (now()).
  11. } else { is the branch taken when the URL was already in the cache.
  12. $content = base64_decode($cache[0]); takes the stored, encoded content and turns it back into the original data.

The report summarises the flow: the url GET parameter is controlled by the user; a transformation replaces all & characters with &amp;; the parameter is then checked to ensure the string chart.apis.google.com/chart is present; and finally, if the URL is not in the database cache, it is opened and its content is read with file_get_contents.

The mistake is that the only validation is a substring check. The only validation is a substring check for chart.apis.google.com/chart, so a specially crafted PHP filter chain that includes the required substring passes the check and is handed to file_get_contents. A specially crafted PHP filter chain that includes the required substring passes the check and is handed straight to file_get_contents.

A "PHP filter chain" is a sequence of PHP's built-in data filters joined together. Filters are small transformations, such as converting text to base64 or to upper case. When you chain them, the output of one becomes the input of the next. The report points to a separate publication on the Synacktiv website for the full explanation of this technique. That is what the report calls an error-based oracle. An "oracle" in security means any behaviour that answers a yes or no question. Here, the server's error or success response tells the attacker something about the file, one small piece at a time, without ever showing the file directly. The report points to a separate publication on the Synacktiv website for the full explanation of this technique, and to a tool one of their experts built to make it practical.

The report adds that PHP developers have been notified about this issue affecting multiple file read functions. In other words, file_get_contents is not the only PHP function with this behaviour. The report says a patch is not yet available at the time of writing, because it is a complex issue.

Impact

An attacker with access to the administration panel can exfiltrate a partial content of any file readable by the system user running the server. "The system user running the server" is the account on the operating system under which the web server process runs; every file on the machine has permissions saying which users may read it, and the attacker can reach exactly those the server account can reach, no more.

The leak is partial. Because the exploited variable is a GET parameter, the amount of data that can be exfiltrated is limited, roughly 135 characters by default with the tool used. And the vulnerability is only exploitable from the administration panel, so it requires an authenticated admin session. Someone without an admin login cannot use it.

The fix

phpList 3.6.13, released on 2023.05.26, contains the patch. The report does not describe the code change itself. What it does record is the timeline: the advisory was sent to the phpList developers on 2023.03.23, acknowledged on 2023.03.24 with a patch scheduled for the next release, followed up on 2023.04.25, patched in 3.6.13 on 2023.05.26, assigned CVE-2023-35834 on 2023.06.19, and publicly released on 2023.07.04.

Variants to test

If you were reviewing similar software, the report's reasoning suggests places to look. These are the kinds of tests a reviewer would run:

  • Substring checks on URLs that can be satisfied by a filter chain. A positive result is a chain that still contains the required substring and still reaches the file-reading function, exactly as happened here.

Glossary

  • Advisory: a formal write-up of a security flaw, sent to the people who maintain the software so they can fix it.
  • Base64: a way of encoding data using only ordinary letters, digits and a couple of symbols, so it can travel through systems that expect text.
  • Cache: a store of results that were already fetched, kept so the same thing does not have to be fetched again.
  • Cookie: a small piece of data a website asks your browser to keep and send back on later requests, often used to remember that you are logged in.
  • CVE: a public catalogue number assigned to one specific vulnerability so everyone can refer to it unambiguously.
  • Docker: a tool that packages software with everything it needs into a ready-to-run box.
  • Endpoint: one specific address or feature of an application that accepts requests.
  • Error-based oracle: a technique where the presence or absence of an error, or a change in the response, answers a yes or no question about data the attacker cannot see directly.
  • Exfiltrate: to get data out of a system and into the attacker's hands.
  • File read: a flaw that lets an attacker make a server read a file and reveal its contents.
  • Filter chain: a series of PHP data transformations joined so the output of one feeds the next, used here to make PHP produce chosen text.
  • GET request: the ordinary kind of HTTP request a browser sends when you open a page, with data carried in the address.
  • Header: a small labelled line travelling with a web request or response, carrying metadata such as cookies or preferred language.
  • HTTP: the language browsers and servers use to exchange requests and responses.
  • Parameter: a named piece of information attached to a request, such as url or page.
  • Patch: a change to software that fixes a flaw.
  • PHP: the programming language phpList is written in, which runs on the server.
  • POST request: an HTTP request that sends data in the body rather than the address, typically used when submitting a form.
  • Proof of concept: a working demonstration that a flaw can actually be exploited.
  • Scheme: the first part of an address, such as http://, that says how to reach the resource.
  • Session: the state of being logged in, represented by values the browser sends back with each request.
  • Substring: a piece of text that appears inside a longer piece of text.
  • System user: the account on the operating system under which the web server process runs, which determines which files it may read.
  • URL: the address of a resource on the web, as typed into a browser's address bar.
  • Variable: a named box in a program that holds a value.
  • Vulnerability: a weakness in software that an attacker can use to make it behave in a way its makers did not intend.

Similar reports

View all

Same bug class and techniques, clearest first.

Path traversal and file inclusion

The lesson behind this report.

Input that builds a file path escapes the intended folder, reading or writing files the application should never touch.