All Projects → farisv → Prestashop Cve 2018 19126

farisv / Prestashop Cve 2018 19126

Licence: mit
PrestaShop (1.6.x <= 1.6.1.23 or 1.7.x <= 1.7.4.4) Back Office Remote Code Execution (CVE-2018-19126)

Projects that are alternatives of or similar to Prestashop Cve 2018 19126

sqlinjection-training-app
A simple PHP application to learn SQL Injection detection and exploitation techniques.
Stars: ✭ 56 (+51.35%)
Mutual labels:  exploit, web-security
Hackvault
A container repository for my public web hacks!
Stars: ✭ 1,364 (+3586.49%)
Mutual labels:  exploit, web-security
Joomscan
OWASP Joomla Vulnerability Scanner Project
Stars: ✭ 640 (+1629.73%)
Mutual labels:  exploit
Featherduster
An automated, modular cryptanalysis tool; i.e., a Weapon of Math Destruction
Stars: ✭ 876 (+2267.57%)
Mutual labels:  exploit
Wasabi Aeg
Yet another implementation of AEG (Automated Exploit Generation) using symbolic execution engine Triton.
Stars: ✭ 23 (-37.84%)
Mutual labels:  exploit
K8cscan
K8Cscan大型内网渗透自定义插件化扫描神器,包含信息收集、网络资产、漏洞扫描、密码爆破、漏洞利用,程序采用多线程批量扫描大型内网多个IP段C段主机,目前插件包含: C段旁注扫描、子域名扫描、Ftp密码爆破、Mysql密码爆破、Oracle密码爆破、MSSQL密码爆破、Windows/Linux系统密码爆破、存活主机扫描、端口扫描、Web信息探测、操作系统版本探测、Cisco思科设备扫描等,支持调用任意外部程序或脚本,支持Cobalt Strike联动
Stars: ✭ 693 (+1772.97%)
Mutual labels:  exploit
Pegaswitch
PegaSwitch is an exploit toolkit for the Nintendo Switch
Stars: ✭ 922 (+2391.89%)
Mutual labels:  exploit
Penetration Testing Tools
A collection of more than 140+ tools, scripts, cheatsheets and other loots that I have developed over years for Red Teaming/Pentesting/IT Security audits purposes. Most of them came handy on at least one of my real-world engagements.
Stars: ✭ 614 (+1559.46%)
Mutual labels:  exploit
H Encore
Fully chained kernel exploit for the PS Vita on firmwares 3.65-3.68
Stars: ✭ 968 (+2516.22%)
Mutual labels:  exploit
Xattacker
X Attacker Tool ☣ Website Vulnerability Scanner & Auto Exploiter
Stars: ✭ 897 (+2324.32%)
Mutual labels:  exploit
Phonesploit
Using open Adb ports we can exploit a Andriod Device
Stars: ✭ 854 (+2208.11%)
Mutual labels:  exploit
Shellen
🌸 Interactive shellcoding environment to easily craft shellcodes
Stars: ✭ 799 (+2059.46%)
Mutual labels:  exploit
Htshells
Self contained htaccess shells and attacks
Stars: ✭ 708 (+1813.51%)
Mutual labels:  exploit
Pwn jenkins
Notes about attacking Jenkins servers
Stars: ✭ 841 (+2172.97%)
Mutual labels:  exploit
Spectre Attack
Example of using revealed "Spectre" exploit (CVE-2017-5753 and CVE-2017-5715)
Stars: ✭ 690 (+1764.86%)
Mutual labels:  exploit
Cve 2017 0065
Exploiting Edge's read:// urlhandler
Stars: ✭ 15 (-59.46%)
Mutual labels:  exploit
Openftp4
A list of all FTP servers in IPv4 that allow anonymous logins.
Stars: ✭ 634 (+1613.51%)
Mutual labels:  web-security
Resources For Beginner Bug Bounty Hunters
A list of resources for those interested in getting started in bug bounties
Stars: ✭ 7,185 (+19318.92%)
Mutual labels:  web-security
Confiscate
Discover duplication glitches, abusive staff giving items, x-ray or simply poor server economy.
Stars: ✭ 23 (-37.84%)
Mutual labels:  exploit
Exploit Cve 2016 9920
Roundcube 1.0.0 <= 1.2.2 Remote Code Execution exploit and vulnerable container
Stars: ✭ 34 (-8.11%)
Mutual labels:  exploit

PrestaShop Back Office Remote Code Execution (CVE-2018-19126)

This is the PoC for CVE-2018-19126, chaining multiple vulnerabilities in PrestaShop Back Office to trigger deserialization via phar to achieve remote code execution.

Prerequisite:

  • PrestaShop 1.6.x before 1.6.1.23 or 1.7.x before 1.7.4.4.
  • Back Office account (logistician, translator, salesman, etc.).

PrestaShop release note: http://build.prestashop.com/news/prestashop-1-7-4-4-1-6-1-23-maintenance-releases/

Vulnerable package link: https://assets.prestashop2.com/en/system/files/ps_releases/prestashop_1.7.4.3.zip

WARNING

FOR EDUCATIONAL PURPOSES ONLY. DO NOT USE THIS SCRIPT FOR ILLEGAL ACTIVITIES. THE AUTHOR IS NOT RESPONSIBLE FOR ANY MISUSE OR DAMAGE.

Example

You need php with curl extension and set phar.readonly = Off in php.ini to run the exploit.

# Download repository
wget https://github.com/farisv/PrestaShop-CVE-2018-19126/archive/master.zip -O PrestaShop-CVE-2018-19126.zip
unzip PrestaShop-CVE-2018-19126.zip
cd PrestaShop-CVE-2018-19126-master

# Run the exploit
# Usage: php exploit.php back-office-url email password func param
php exploit.php http://127.0.0.1/admin-dev/ [email protected] 54l35m4n123 system 'cat /etc/passwd'

Note that the upload directory will be renamed and you can't upload the malicious phar file again if the folder name is not reverted. You might want to execute reverse shell to gain persistence RCE or include the command to rename the folder again in your payload (you need to know the path to the upload directory).

Explanation

We can achieve implicit deserialization with phar wrapper via getimagesize() function in [back-office-path]/filemanager/ajax_calls.php.

https://github.com/PrestaShop/PrestaShop/commit/4c6958f40cf7faa58207a203f3a5523cc8015148#diff-0f03d65f71cdd8eeb12913a97a6b8945

case 'image_size':
    if (realpath(dirname(_PS_ROOT_DIR_.$_POST['path'])) != realpath(_PS_ROOT_DIR_.$upload_dir)) {
        die();
    }
    $pos = strpos($_POST['path'], $upload_dir);
    if ($pos !== false) {
        $info = getimagesize(substr_replace($_POST['path'], $current_path, $pos, strlen($upload_dir)));
        echo json_encode($info);
    }

We need to find the way so getimagesize() is called with phar wrapper URL as parameter by bypassing certain checks.

First check with realpath() is quite strict.

if (realpath(dirname(_PS_ROOT_DIR_.$_POST['path'])) != realpath(_PS_ROOT_DIR_.$upload_dir)) {
    die();
}

The $upload_dir variable is come from config.php, which is set with $upload_dir = Context::getContext()->shop->getBaseURI().'img/cms/'; by default. We can't use phar://[string] in $_POST['path'] because realpath(dirname(_PS_ROOT_DIR_.$_POST['path'])) will return false because it's not exist.

There is exist another vulnerability (CVE-2018-19125) which allows user to delete or rename $upload_dir. If $upload_dir directory is not exist, realpath(_PS_ROOT_DIR_.$upload_dir) will return false and we can bypass this check because realpath(dirname(_PS_ROOT_DIR_.$_POST['path'])) is also false. This vulnerability is discovered during code review when trying to find the way to bypass :).

In short, CVE-2018-19125 allows the path parameter in call to delete_folder or rename_folder action in execute.php to be empty so the application will delete/rename the $upload_dir instead.

The second check is simple, the $_POST['path'] need to contains $upload_dir.

$pos = strpos($_POST['path'], $upload_dir);
if ($pos !== false) {

We can just append /img/cms/ in the phar URL after the file path to phar file because if the directory is not exist inside the phar archive, the deserialization is still occurs. The substr_replace($_POST['path'], $current_path, $pos, strlen($upload_dir)) will only replace /img/cms/ to the absolute path ($current_path) of that folder (e.g. /var/www/html/img/cms/ if the application is installed in /var/www/html/).

Because we can control the getimagesize() function to process a phar wrapper URL, we need to upload the malicious phar file to the server. By default, FileManager in PrestaShop only allows 'jpg', 'jpeg', 'png', 'gif', 'bmp', 'tiff', 'svg', 'pdf', 'mov', 'mpeg', 'mp4', 'avi', 'mpg', 'wma', 'flv', and 'webm' as extension. We can just craft the payload and save it with valid extension. We can use Monolog gadget chains from PHPGGC (https://github.com/ambionics/phpggc/blob/master/gadgetchains/Monolog/RCE/1/) as it is used by PrestaShop.

Final exploitation steps:

  1. Craft the malicious phar file and save with valid extension (e.g. phar.pdf).
  2. Upload the phar.pdf to FileManager.
  3. Trigger the vulnerability to rename the upload directory to another name (e.g. renamed).
  4. Call the image_size action with phar://../../img/renamed/phar.pdf/img/cms/ as path parameter.
  5. Deserialization payload in phar.pdf will be executed.

The exploit.php script will automatically do all steps.

Remember that the upload directory is renamed in step 3 and you can't upload the malicious phar file again if the folder name is not reverted. You might want to use reverse shell as payload or include the command to rename the folder again in the payload (you need to know the path to the upload directory).

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].