Web security

Remote code execution (RCE)

Definition

Remote code execution (RCE) is a vulnerability that lets an attacker make a server run their own instructions over the network, without any legitimate access to it. It is one of the most severe types of vulnerability, because it often leads to a complete takeover of the site.

Remote code execution (RCE), Web security

RCE is rarely a vulnerability family on its own: it is the most serious outcome that several kinds of mistakes can lead to. Once an attacker gets PHP to run their code, they act with the site's privileges: they read wp-config.php and therefore the database credentials, create accounts, plant a backdoor or use the server to send spam. That is why unauthenticated RCE vulnerabilities almost always receive the highest severity scores.

The paths that lead to RCE

  • Code injection (CWE-94): the program builds code from external data, for example with eval(). According to OWASP, the attacker is then limited only by what the language can do.
  • Command injection: data is passed to a system shell through exec(), system() or an equivalent. The attacker hijacks existing commands rather than writing PHP.
  • File upload: a form accepts a .php file and stores it in a folder reachable from the web.
  • File inclusion and deserialization: two mechanisms covered in the definitions of file inclusion and insecure deserialization.
  • Flaws in the language or the server: PHP itself, or a system library it uses.
Five-step RCE scenario through file upload: the attacker sends a .php file through a form that checks neither the type nor permissions, the plugin saves it in wp-content/uploads, the attacker requests its URL, PHP runs the code with the site's privileges, then the attacker installs a backdoor and an administrator account

Real-world examples

  • WP File Manager, CVE-2020-25213: before version 6.9, the plugin renamed an example file from the elFinder library with a .php extension, which allowed remote attackers to upload and run PHP code. CVSS 3.1 score: 10.
  • PHP-CGI on Windows, CVE-2024-4577: an argument injection caused by Windows character conversion, in PHP before 8.1.29, 8.2.20 and 8.3.8 running in CGI mode. Our explanation of this PHP-CGI flaw specifies which servers were affected.
  • glibc iconv, CVE-2024-2961: a flaw in a system library, made exploitable through PHP, covered in our article on the iconv vulnerability.

For WordPress: reducing the risk and the impact

  • Update plugins that handle files quickly (file managers, forms with attachments, import and export, backups).
  • Block PHP execution in wp-content/uploads at the web server level: that folder should only contain media.
  • Add define( 'DISALLOW_FILE_EDIT', true ); to wp-config.php to disable the admin file editor.
  • Run a supported PHP version and ask your host how they handle disable_functions and open_basedir: hardening PHP limits what injected code can do.
  • A web application firewall blocks some known attempts, without replacing the update.

WP Feint doesn't block RCE exploitation: it is neither a firewall nor an antivirus. After an intrusion, however, its integrity check flags modified, missing or unknown WordPress core files, one of the places where attackers hide their code. Plugin and theme files need to be checked by other means.

Further reading

  • Article CVE-2024-4577: the PHP-CGI flaw on Windows explained
  • Article CVE-2024-2961: the glibc iconv flaw that targets PHP
  • Page WordPress file integrity check

Sources

  1. MITRE CWE-94: Improper Control of Generation of Code (Code Injection) (external link, opens in a new tab)
  2. OWASP: Code Injection (external link, opens in a new tab)
  3. CVE Record: CVE-2020-25213 (external link, opens in a new tab)
  4. CVE Record: CVE-2024-4577 (external link, opens in a new tab)

All definitions

Start free, go Pro when you’re ready

The free version already hides WordPress and moves the login page. Pro adds aliases, two-factor authentication and monitoring.