Summary
Grav's Direct Install feature allows an authenticated administrator to upload a specially crafted ZIP archive that bypasses file extension checks and deploys a malicious plugin.
Once extracted, the plugin can execute arbitrary PHP code or install a persistent web shell, leading to full remote code execution on the server under administrative misuse or account compromise.
Affected context
This vulnerability occurs in Grav installations where:
- The Direct Install tool is enabled for installing themes/plugins from ZIP archives
- Administrative users can upload ZIP files directly to the server
- Server-side validation focuses on top-level file extensions but does not recursively inspect archive contents
The issue becomes relevant when an attacker gains or abuses administrative access and can introduce untrusted ZIP packages into the environment.
Exploit preconditions
- Attack surface: Web administration interface (Direct Install / ZIP upload endpoint)
- Required access: Authenticated administrative account or equivalent privilege that can upload and install plugins/themes
- Trigger point: Uploading and installing a malicious ZIP package via Direct Install, which is then extracted and loaded by the Grav runtime
- Why exploitation is possible: The upload protection checks for disallowed extensions (such as
.php) only on direct file uploads and does not analyze or enforce constraints on files inside ZIP archives. Malicious PHP code bundled as a plugin is therefore extracted into executable paths without adequate validation.
Why this happens
The underlying bug stems from incomplete server-side validation of uploaded content, specifically in the handling of compressed archives used for plugin installation.
While the platform attempts to prevent direct upload of dangerous file types (e.g., .php), it does not apply equivalent checks to files contained within ZIP archives. This allows an attacker to smuggle executable PHP code into the application as part of a plugin directory structure.
From a weakness taxonomy perspective, this maps to CWE-94: Improper Control of Generation of Code ('Code Injection') because the system loads and executes attacker-supplied PHP code as part of the application's plugin mechanism without adequately constraining what can be installed.
Potential impact
- Remote execution of arbitrary PHP code in the context of the web server process
- Installation of persistent web shells enabling long-term server compromise
- Reading, modifying, or deleting application and user data stored on the server
- Lateral movement within the hosting environment, depending on server configuration
- Abuse of the compromised server to launch further attacks (spam, phishing, malware hosting)
General mitigation guidance
Effective mitigation generally focuses on hardening the plugin installation pipeline and reducing trust in uploaded packages:
- Enforce strict validation of archive contents, including recursive checks for disallowed file types and executable code inside ZIP files.
- Restrict plugin execution to a well-defined, minimal subset of files and forbid arbitrary PHP entry points or dynamic code loading where possible.
- Permit installation only from trusted, signed, or otherwise verified sources instead of arbitrary ZIP uploads.
- Apply least-privilege principles to the web server and application runtime, limiting filesystem write access and execution permissions in plugin directories.
- Consider disabling direct ZIP-based installation in high-security environments and using controlled deployment processes (e.g., manual review and controlled file distribution).
How teams detect issues like this
Organizations can detect and monitor this class of issue using:
- Static analysis or security review of the code paths responsible for file upload, archive extraction, and plugin loading, looking for missing validation on archive contents and executable file types.
- Configuration and policy checks that flag or block plugin directories containing unexpected PHP files, writable executable paths, or non-standard entry points.
- Runtime monitoring and intrusion detection focused on:
- Creation of new PHP files in plugin or web-accessible directories
- Unusual outbound connections or command execution originating from plugin code
- Periodic file integrity monitoring (FIM) on plugin and webroot directories to detect unauthorized additions or modifications.
- Use of automated application security testing tools (e.g., SAST/DAST) to identify unvalidated file upload and archive handling flows in custom extensions or integrations.

