Remote Code Execution by uploading a phar file using frontmatter
SummaryDue to insufficient permission verification, user who can write a page use frontmatter feature.Inadequate File Name ValidationDetailsInsufficient Permission VerificationIn Grav CMS, "[Frontmatter](https://learn.getgrav.org/17/content/headers)" refers to the metadata block located at the top of a Markdown file. Frontmatter serves the purpose of providing additional information about a specific page or post.
In this feature, only administrators are granted access, while regular users who can create pages are not. However, if a regular user adds the data[_json][header][form] parameter to the POST Body while creating a page, they can use Frontmatter. The demonstration of this vulnerability is provided in video format. [Video Link](https://www.youtube.com/watch?v=EU1QA0idoWE)Inadequate File Name ValidationTo create a Contact Form, Frontmatter and markdown can be written as follows:
[Contact Form Example](https://learn.getgrav.org/17/forms/forms/example-form)
[Form Action Save Option](https://learn.getgrav.org/17/forms/forms/reference-form-actions#save)
When an external user submits the Contact Form after filling it out, the data is stored in the user/data folder. The filename under which the data is stored corresponds to the value specified in the filename attribute of the process property. For instance, if the filename attribute has a value of "feedback.txt," a feedback.txt file is created in the user/data/contact folder. This file contains the value entered by the user in the "name" field. The problem with this functionality is the lack of validation for the filename attribute, potentially allowing the creation of files such as phar files on the server. An attacker could input arbitrary PHP code into the "name" field to be saved on the server. However, Grav filter the < and > characters, so to disable these options, an xss_check: false attribute should be added. [Disable XSS](https://learn.getgrav.org/17/forms/forms/form-options#xss-checks)Exploiting these two vulnerabilities allows the following scenario:A regular user account capable of creating pages is required.An attacker creates a Contact Form page containing malicious Frontmatter using the regular user's account.Accessing the Contact Form page, the attacker submits PHP code.The attacker attempts Remote Code Execution by accessing HOST/user/data/[form-name]/[filename].PoC[PoC Video Link](https://www.youtube.com/watch?v=Gh3ezpORbPc)ImpactRemote Code Execution