{"id":2803,"date":"2023-03-28T13:37:03","date_gmt":"2023-03-28T11:37:03","guid":{"rendered":"https:\/\/www.dsecbypass.com\/?p=2803"},"modified":"2024-02-07T10:18:22","modified_gmt":"2024-02-07T09:18:22","slug":"admin-prestashop-rce-a-la-wordpress","status":"publish","type":"post","link":"https:\/\/www.dsecbypass.com\/en\/admin-prestashop-rce-a-la-wordpress\/","title":{"rendered":"Admin PrestaShop RCE &#8220;\u00e0 la WordPress&#8221;"},"content":{"rendered":"<p>[et_pb_section fb_built=&#8221;1&#8243; _builder_version=&#8221;4.17.3&#8243; _module_preset=&#8221;default&#8221; custom_padding=&#8221;0px||||false|false&#8221; global_colors_info=&#8221;{}&#8221;][et_pb_row _builder_version=&#8221;4.17.3&#8243; _module_preset=&#8221;default&#8221; custom_padding=&#8221;||88px|||&#8221; global_colors_info=&#8221;{}&#8221;][et_pb_column type=&#8221;4_4&#8243; _builder_version=&#8221;4.17.3&#8243; _module_preset=&#8221;default&#8221; global_colors_info=&#8221;{}&#8221;][et_pb_image src=&#8221;https:\/\/www.dsecbypass.com\/wp-content\/uploads\/2023\/03\/Prestashop-logo.png&#8221; alt=&#8221;Prestashop logo&#8221; title_text=&#8221;Prestashop logo&#8221; align=&#8221;center&#8221; _builder_version=&#8221;4.20.2&#8243; _module_preset=&#8221;default&#8221; background_color=&#8221;RGBA(255,255,255,0)&#8221; width=&#8221;50%&#8221; module_alignment=&#8221;center&#8221; global_colors_info=&#8221;{}&#8221;][\/et_pb_image][et_pb_text _builder_version=&#8221;4.20.2&#8243; _module_preset=&#8221;default&#8221; global_colors_info=&#8221;{}&#8221;]<\/p>\n<p style=\"text-align: justify;\">As pentesters, whenever we get admin rights on a WordPress website we know we are very close to the RCE. Indeed, whether by modifying the theme or adding a module, the execution of arbitrary PHP code is generally not complicated to obtain. In addition, consultants can find many articles on this subject on Google:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.dsecbypass.com\/wp-content\/uploads\/2023\/03\/google_wordpress_rce_module-300x295.png\" alt=\"Google results about WordPress admin RCE module\" class=\"wp-image-2745 aligncenter size-medium\" width=\"300\" height=\"295\"><\/p>\n<p style=\"text-align: justify;\">DSecBypass pentesters have managed to become PrestaShop website administrators several times and the lack of literature on the subject, compared to that available for WordPress, prompted them to write this article.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.dsecbypass.com\/wp-content\/uploads\/2023\/03\/google_prestashop_rce_module-1-223x300.png\" alt=\"Google results PrestaShop admin RCE module\" class=\"wp-image-2749 aligncenter size-medium\" width=\"223\" height=\"300\"><\/p>\n<p style=\"text-align: justify;\">Learn how to build a PrestaShop module modified to execute arbitrary PHP code during your penetration testing.<\/p>\n<p>[\/et_pb_text][et_pb_text module_id=&#8221;tamper&#8221; _builder_version=&#8221;4.23.2&#8243; _module_preset=&#8221;default&#8221; hover_enabled=&#8221;0&#8243; global_colors_info=&#8221;{}&#8221; sticky_enabled=&#8221;0&#8243;]<\/p>\n<h2 class=\"part\" data-startline=\"14\" data-endline=\"14\">Building the PrestaShop module<\/h2>\n<p style=\"text-align: justify;\">PrestaShop offers a convenient web interface to create a valid module skeleton: <a href=\"https:\/\/validator.prestashop.com\/generator\" target=\"_blank\" rel=\"noopener\">https:\/\/validator.prestashop.com\/generator<\/a>.<\/p>\n<p style=\"text-align: justify;\">Be careful, this step is important because bad options can make the administration interface or the shop inaccessible. This is why we prefer to generate a module which only interacts with the administration interface and which is not instantiated automatically. If in doubt, test on a locally replicated version of PrestaShop.<\/p>\n<p style=\"text-align: justify;\">For the exercise, we make sure that the module is not too visible in the list of modules by filling the fields with probable values. Note the &#8220;Module name&#8221; field that it is better to randomize because it is used to create the folder on the file system and is therefore found in the final URL. In order not to find the name of your pentest company indexed by search engines, it is best to insert a string of random characters here.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.dsecbypass.com\/wp-content\/uploads\/2023\/03\/presta_module_generator_1-1024x674.png\" alt=\"Building a PrestaShop module for pentest\" class=\"wp-image-2757 aligncenter size-large\" width=\"1024\" height=\"674\" srcset=\"https:\/\/www.dsecbypass.com\/wp-content\/uploads\/2023\/03\/presta_module_generator_1-1024x674.png 1024w, https:\/\/www.dsecbypass.com\/wp-content\/uploads\/2023\/03\/presta_module_generator_1-980x646.png 980w, https:\/\/www.dsecbypass.com\/wp-content\/uploads\/2023\/03\/presta_module_generator_1-480x316.png 480w\" sizes=\"(min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) and (max-width: 980px) 980px, (min-width: 981px) 1024px, 100vw\" \/><\/p>\n<p style=\"text-align: justify;\">It is best to set &#8220;Need instance&#8221; to &#8220;No&#8221; to avoid generating a 500 error on the back office. Concerning the &#8220;Compliancy&#8221;, adapt it according to the version of the PrestaShop you are targeting. The max value doesn&#8217;t really matter because the module code then uses the value of &#8220;_PS_VERSION_&#8221;.<\/p>\n<p style=\"text-align: justify;\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.dsecbypass.com\/wp-content\/uploads\/2023\/03\/presta_module_generator_2-1024x612.png\" alt=\"Building a PrestaShop module for pentest step 2\" class=\"wp-image-2759 aligncenter size-large\" width=\"1024\" height=\"612\" srcset=\"https:\/\/www.dsecbypass.com\/wp-content\/uploads\/2023\/03\/presta_module_generator_2-1024x612.png 1024w, https:\/\/www.dsecbypass.com\/wp-content\/uploads\/2023\/03\/presta_module_generator_2-980x586.png 980w, https:\/\/www.dsecbypass.com\/wp-content\/uploads\/2023\/03\/presta_module_generator_2-480x287.png 480w\" sizes=\"(min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) and (max-width: 980px) 980px, (min-width: 981px) 1024px, 100vw\" \/><\/p>\n<p> From experience, the module is more likely to work with the &#8220;Administration panel footer&#8221; hook:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.dsecbypass.com\/wp-content\/uploads\/2023\/03\/presta_module_generator_3-1024x499.png\" alt=\"Building a PrestaShop module for pentest step 3\" class=\"wp-image-2763 aligncenter size-large\" width=\"1024\" height=\"499\" srcset=\"https:\/\/www.dsecbypass.com\/wp-content\/uploads\/2023\/03\/presta_module_generator_3-1024x499.png 1024w, https:\/\/www.dsecbypass.com\/wp-content\/uploads\/2023\/03\/presta_module_generator_3-980x477.png 980w, https:\/\/www.dsecbypass.com\/wp-content\/uploads\/2023\/03\/presta_module_generator_3-480x234.png 480w\" sizes=\"(min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) and (max-width: 980px) 980px, (min-width: 981px) 1024px, 100vw\" \/><\/p>\n<p style=\"text-align: justify;\">By clicking on &#8220;Create&#8221; the ZIP archive of the module is downloaded.<\/p>\n<p style=\"text-align: justify;\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.dsecbypass.com\/wp-content\/uploads\/2023\/03\/presta_module_file_tree.png\" alt=\"Prestashop module filetree\" class=\"wp-image-2766 aligncenter size-full\" width=\"246\" height=\"212\"><\/p>\n<p>[\/et_pb_text][et_pb_text module_id=&#8221;postprocess&#8221; _builder_version=&#8221;4.20.2&#8243; _module_preset=&#8221;default&#8221; global_colors_info=&#8221;{}&#8221;]<\/p>\n<h2>Modifying the PrestaShop module with a WebShell<\/h2>\n<p style=\"text-align: justify;\">The goal is to include the PHP code of a WebShell in this newly created plugin.<\/p>\n<p style=\"text-align: justify;\">It is possible to simply add the PHP file of your favorite WebShell in the archive and upload it. But to stay in the perspective of having a module that is not too suspicious, we modify the &#8220;index.php&#8221; file accessible at the root of the archive. The only line added in the screenshot below is the underline one.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.dsecbypass.com\/wp-content\/uploads\/2023\/03\/presta_module_index.png\" alt=\"Modifying index.php with a simple WebShell\" class=\"wp-image-2769 aligncenter size-full\" width=\"722\" height=\"594\" srcset=\"https:\/\/www.dsecbypass.com\/wp-content\/uploads\/2023\/03\/presta_module_index.png 722w, https:\/\/www.dsecbypass.com\/wp-content\/uploads\/2023\/03\/presta_module_index-480x395.png 480w\" sizes=\"(min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) 722px, 100vw\" \/><\/p>\n<p style=\"text-align: justify;\"><span style=\"text-decoration: underline;\">Warning:<\/span> the webshell used here is for example. Its access is not authenticated which can endanger your client&#8217;s infrastructure. Prefer secure webshells or PHP reverse shells.<\/p>\n<p style=\"text-align: justify;\">Once the archive has been zipped again, we can upload the PrestaShop module containing our WebShell. Just go to the Modules menu in the administration interface. The latter can be complicated to discover since PrestaShop encourages administrators to modify the path to the administrator dashboard. We assume here that readers know this path and have an administrator account.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.dsecbypass.com\/wp-content\/uploads\/2023\/03\/presta_admin-1024x601.png\" alt=\"Modules tab in PrestaShop\" class=\"wp-image-2774 aligncenter size-large\" width=\"1024\" height=\"601\" srcset=\"https:\/\/www.dsecbypass.com\/wp-content\/uploads\/2023\/03\/presta_admin-1024x601.png 1024w, https:\/\/www.dsecbypass.com\/wp-content\/uploads\/2023\/03\/presta_admin-980x575.png 980w, https:\/\/www.dsecbypass.com\/wp-content\/uploads\/2023\/03\/presta_admin-480x282.png 480w\" sizes=\"(min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) and (max-width: 980px) 980px, (min-width: 981px) 1024px, 100vw\" \/><\/p>\n<p style=\"text-align: justify;\">If the module is badly formed (archive badly rebuilt, error in the PHP code) an error may be returned:<\/p>\n<p style=\"text-align: justify;\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.dsecbypass.com\/wp-content\/uploads\/2023\/03\/presta_admin_module_upload-300x189.png\" alt=\"Module PrestaShop upload 500 error\" class=\"wp-image-2776 aligncenter size-medium\" width=\"300\" height=\"189\"><\/p>\n<p style=\"text-align: justify;\">Depending on the type of error, the module may have been deployed successfully but there is a good chance that the &#8220;Modules&#8221; menu is now broken (error 500). Since it has been deployed, you can still go to your webshell to remove this new module and try to fix the problem.<\/p>\n<p style=\"text-align: justify;\">If the steps for creating the module have been followed correctly, the following message should instead appear:<\/p>\n<p style=\"text-align: justify;\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.dsecbypass.com\/wp-content\/uploads\/2023\/03\/presta_admin_module_upload_good-300x166.png\" alt=\"PrestaShop webshell module uploaded\" class=\"wp-image-2778 aligncenter size-medium\" width=\"300\" height=\"166\"><\/p>\n<p style=\"text-align: justify;\">[\/et_pb_text][\/et_pb_column][\/et_pb_row][et_pb_row _builder_version=&#8221;4.20.2&#8243; _module_preset=&#8221;default&#8221; global_colors_info=&#8221;{}&#8221;][et_pb_column type=&#8221;4_4&#8243; _builder_version=&#8221;4.20.2&#8243; _module_preset=&#8221;default&#8221; global_colors_info=&#8221;{}&#8221;][et_pb_text _builder_version=&#8221;4.20.2&#8243; _module_preset=&#8221;default&#8221; global_colors_info=&#8221;{}&#8221;]<\/p>\n<h2>WebShell usage<\/h2>\n<p>Once the PrestaShop module has been correctly uploaded, it should appear in the list of modules (here &#8220;Cache management&#8221;):<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.dsecbypass.com\/wp-content\/uploads\/2023\/03\/presta_malicious_module_in_list-1024x317.png\" alt=\"List of PrestaShop WebShell modules\" class=\"wp-image-2782 aligncenter size-large\" width=\"1024\" height=\"317\" srcset=\"https:\/\/www.dsecbypass.com\/wp-content\/uploads\/2023\/03\/presta_malicious_module_in_list-980x304.png 980w, https:\/\/www.dsecbypass.com\/wp-content\/uploads\/2023\/03\/presta_malicious_module_in_list-480x149.png 480w\" sizes=\"(min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) and (max-width: 980px) 980px, (min-width: 981px) 1024px, 100vw\" \/><\/p>\n<p>An icon could be added to make it even less visible.<\/p>\n<p>If an administrator tries to uninstall it, the message entered when creating the module will be displayed in order to dissuade him:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.dsecbypass.com\/wp-content\/uploads\/2023\/03\/presta_malicious_module_warning_uninstall.png\" alt=\"PrestaShop plugin uninstallation warning\" class=\"wp-image-2790 aligncenter size-full\" width=\"758\" height=\"355\" srcset=\"https:\/\/www.dsecbypass.com\/wp-content\/uploads\/2023\/03\/presta_malicious_module_warning_uninstall.png 758w, https:\/\/www.dsecbypass.com\/wp-content\/uploads\/2023\/03\/presta_malicious_module_warning_uninstall-480x225.png 480w\" sizes=\"(min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) 758px, 100vw\" \/><\/p>\n<p>We can confirm that the module is well deployed on the file system of our local environment:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.dsecbypass.com\/wp-content\/uploads\/2023\/03\/presta_admin_module_upload_filesystem.png\" alt=\"WebShell PrestaShop module on the file system\" class=\"wp-image-2784 aligncenter size-full\" width=\"853\" height=\"57\" srcset=\"https:\/\/www.dsecbypass.com\/wp-content\/uploads\/2023\/03\/presta_admin_module_upload_filesystem.png 853w, https:\/\/www.dsecbypass.com\/wp-content\/uploads\/2023\/03\/presta_admin_module_upload_filesystem-480x32.png 480w\" sizes=\"(min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) 853px, 100vw\" \/><\/p>\n<p>So all we have to do is use our WebShell and continue the pentest:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.dsecbypass.com\/wp-content\/uploads\/2023\/03\/presta_module_rce.png\" alt=\"PrestaShop RCE module as admin\" class=\"wp-image-2786 aligncenter size-full\" width=\"867\" height=\"59\" srcset=\"https:\/\/www.dsecbypass.com\/wp-content\/uploads\/2023\/03\/presta_module_rce.png 867w, https:\/\/www.dsecbypass.com\/wp-content\/uploads\/2023\/03\/presta_module_rce-480x33.png 480w\" sizes=\"(min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) 867px, 100vw\" \/><\/p>\n<p>[\/et_pb_text][\/et_pb_column][\/et_pb_row][et_pb_row _builder_version=&#8221;4.17.3&#8243; _module_preset=&#8221;default&#8221; global_colors_info=&#8221;{}&#8221;][et_pb_column type=&#8221;4_4&#8243; _builder_version=&#8221;4.17.3&#8243; _module_preset=&#8221;default&#8221; global_colors_info=&#8221;{}&#8221;][et_pb_text _builder_version=&#8221;4.23.2&#8243; _module_preset=&#8221;default&#8221; hover_enabled=&#8221;0&#8243; global_colors_info=&#8221;{}&#8221; sticky_enabled=&#8221;0&#8243;]<\/p>\n<p style=\"text-align: justify;\"><span>\ud83d\udee1\ufe0f DSecBypass accompanies you on the <a href=\"https:\/\/www.dsecbypass.com\/en\/website-pentest\/\" title=\"Website penetration test\">security audit of your Web applications<\/a>. Do not hesitate to <a href=\"https:\/\/www.dsecbypass.com\/en\/contact\/\">contact <\/a>us for additional information and\/or a personalized quote \ud83d\udcdd.<\/span><\/p>\n<p>[\/et_pb_text][\/et_pb_column][\/et_pb_row][et_pb_row _builder_version=&#8221;4.17.3&#8243; _module_preset=&#8221;default&#8221; global_colors_info=&#8221;{}&#8221;][et_pb_column type=&#8221;4_4&#8243; _builder_version=&#8221;4.17.3&#8243; _module_preset=&#8221;default&#8221; global_colors_info=&#8221;{}&#8221;][et_pb_button button_url=&#8221;https:\/\/www.dsecbypass.com\/en\/contact\/&#8221; button_text=&#8221;CONTACT US&#8221; button_alignment=&#8221;center&#8221; _builder_version=&#8221;4.17.4&#8243; _module_preset=&#8221;default&#8221; custom_button=&#8221;on&#8221; button_text_size=&#8221;13px&#8221; button_bg_color=&#8221;#4328b7&#8243; button_border_width=&#8221;10px&#8221; button_border_color=&#8221;#4328b7&#8243; button_border_radius=&#8221;0px&#8221; button_letter_spacing=&#8221;2px&#8221; button_font=&#8221;Titillium Web|700||on|||||&#8221; background_layout=&#8221;dark&#8221; global_colors_info=&#8221;{}&#8221;][\/et_pb_button][\/et_pb_column][\/et_pb_row][\/et_pb_section]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Build a PrestaShop module in order to have an RCE when obtaining administrator access during a pentest.<\/p>\n","protected":false},"author":4,"featured_media":2779,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"on","_et_pb_old_content":"","_et_gb_content_width":"","footnotes":""},"categories":[34],"tags":[],"class_list":["post-2803","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog-en"],"_links":{"self":[{"href":"https:\/\/www.dsecbypass.com\/en\/wp-json\/wp\/v2\/posts\/2803","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dsecbypass.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dsecbypass.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dsecbypass.com\/en\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dsecbypass.com\/en\/wp-json\/wp\/v2\/comments?post=2803"}],"version-history":[{"count":14,"href":"https:\/\/www.dsecbypass.com\/en\/wp-json\/wp\/v2\/posts\/2803\/revisions"}],"predecessor-version":[{"id":3233,"href":"https:\/\/www.dsecbypass.com\/en\/wp-json\/wp\/v2\/posts\/2803\/revisions\/3233"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.dsecbypass.com\/en\/wp-json\/wp\/v2\/media\/2779"}],"wp:attachment":[{"href":"https:\/\/www.dsecbypass.com\/en\/wp-json\/wp\/v2\/media?parent=2803"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dsecbypass.com\/en\/wp-json\/wp\/v2\/categories?post=2803"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dsecbypass.com\/en\/wp-json\/wp\/v2\/tags?post=2803"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}