Skip to content
Path traversal Write-up Advanced

WordPress: Unauthenticated path traversal leading to conditional RCE

An unauthenticated attacker can make WordPress page-template resolution include a chosen readable local .php file outside the active theme directories. If the server environment and active theme meet certain pre-conditions, this can lead to remote code execution.

github.com

Published on github.com

An unauthenticated attacker can make getpagetemplate() page-template resolution include a chosen readable local .php file outside the active theme directories. If relevant pre-conditions for both the server environment and the active theme are met, this can lead to RCE.

The author, on github.com

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the page-template resolution logic does not properly restrict the path to the active theme directories, allowing directory traversal to include arbitrary local PHP files.

Impact

If the pre-conditions are met, an attacker could achieve remote code execution; otherwise the impact is limited to including a readable local PHP file.

What the attacker needed

Theme has a top-level dir starting with 'page-'; a readable local .php file exists on server; register_argc_argv On for pearcmd.php route

The fix

WordPress 7.1.2 was released containing a fix, backported to all branches back to 4.7.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

WordPress picks a template file to show a page, and it can be tricked into loading a PHP file from anywhere on the server. PHP files are code, so loading an unexpected one can let an attacker run their own code. This only works if the theme has a folder starting with 'page-' and a suitable file exists on the server.

What is Path traversal?

Input that builds a file path escapes the intended folder, reading or writing files the application should never touch.

Similar reports

View all

Same bug class and techniques, clearest first.

Path traversal and file inclusion

The lesson behind this report.

Input that builds a file path escapes the intended folder, reading or writing files the application should never touch.