/

CVE-2021-48016

Severity:

CRITICAL RISK

(9.8)

PHP Code Injection (CWE-94) in DedeCMS ShowMsg() Path

CVE-2021-48016

Deferred

Vulnerability type

Category:

Code Injection

CWE:

CWE-94

Impact:

Remote Code Execution

Severity:

CRITICAL RISK

(9.8)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

Summary

A critical PHP code injection vulnerability in DedeCMS allows unauthenticated attackers to influence template content through the HTTP Referer header. Under affected configurations, crafted requests may cause the application to interpret attacker-controlled content as PHP and execute arbitrary PHP or system commands.

A critical PHP code injection vulnerability in DedeCMS allows unauthenticated attackers to influence template content through the HTTP Referer header. Under affected configurations, crafted requests may cause the application to interpret attacker-controlled content as PHP and execute arbitrary PHP or system commands.

Affected context

The vulnerability occurs in DedeCMS deployments through 5.8.1-beta where the ShowMsg() function processes a Referer value through a DedeTemplate string and includes the resulting content. The relevant request flow involves the link-management endpoint at /plus/flink.php?dopost=save, with exploitation depending on the application accepting the request without a valid verification code.

The vulnerability occurs in DedeCMS deployments through 5.8.1-beta where the ShowMsg() function processes a Referer value through a DedeTemplate string and includes the resulting content. The relevant request flow involves the link-management endpoint at /plus/flink.php?dopost=save, with exploitation depending on the application accepting the request without a valid verification code.

Exploit preconditions

  • Attack surface: Publicly reachable DedeCMS HTTP request handling
  • Required access: No authenticated account is generally required
  • Trigger point: Processing of the link-saving request and subsequent ShowMsg() template handling
  • Relevant input: The HTTP Referer header and request validation state
  • Why exploitation is possible: Attacker-controlled header data can reach a template inclusion path where it may be interpreted as PHP code rather than treated solely as data
  • Attack surface: Publicly reachable DedeCMS HTTP request handling
  • Required access: No authenticated account is generally required
  • Trigger point: Processing of the link-saving request and subsequent ShowMsg() template handling
  • Relevant input: The HTTP Referer header and request validation state
  • Why exploitation is possible: Attacker-controlled header data can reach a template inclusion path where it may be interpreted as PHP code rather than treated solely as data

Why this happens

The underlying bug is an unsafe code-generation and template-inclusion pattern. Data derived from an HTTP header is inserted into a DedeTemplate string and included without reliably separating untrusted content from executable PHP logic. This behavior maps to CWE-94: Improper Control of Generation of Code, because externally influenced data can affect dynamically generated or evaluated code.

The underlying bug is an unsafe code-generation and template-inclusion pattern. Data derived from an HTTP header is inserted into a DedeTemplate string and included without reliably separating untrusted content from executable PHP logic. This behavior maps to CWE-94: Improper Control of Generation of Code, because externally influenced data can affect dynamically generated or evaluated code.

Potential impact

  • Attackers may execute arbitrary PHP code in the web application process.
  • Attackers could execute operating-system commands with the permissions of the hosting service.
  • Website content, credentials, and application data may be exposed or modified.
  • The server could be used for persistence, malware deployment, or further network access.
  • Availability may be affected through destructive commands or resource consumption.
  • Attackers may execute arbitrary PHP code in the web application process.
  • Attackers could execute operating-system commands with the permissions of the hosting service.
  • Website content, credentials, and application data may be exposed or modified.
  • The server could be used for persistence, malware deployment, or further network access.
  • Availability may be affected through destructive commands or resource consumption.

General mitigation guidance

Mitigation generally focuses on preventing request-derived data from reaching executable template or inclusion paths.

Defensive patterns include:

  • Treating HTTP headers and other request values as untrusted data at every processing layer.
  • Using context-safe output encoding and non-executable template rendering.
  • Removing dynamic PHP generation or inclusion where static templates and explicit data binding are sufficient.
  • Enforcing verification and authorization checks before any state-changing processing or response-template generation.
  • Running the application with least-privilege service accounts and restricting filesystem and process permissions.
  • Applying centralized web-application policies that limit suspicious requests and unexpected template-related input.

Mitigation generally focuses on preventing request-derived data from reaching executable template or inclusion paths.

Defensive patterns include:

  • Treating HTTP headers and other request values as untrusted data at every processing layer.
  • Using context-safe output encoding and non-executable template rendering.
  • Removing dynamic PHP generation or inclusion where static templates and explicit data binding are sufficient.
  • Enforcing verification and authorization checks before any state-changing processing or response-template generation.
  • Running the application with least-privilege service accounts and restricting filesystem and process permissions.
  • Applying centralized web-application policies that limit suspicious requests and unexpected template-related input.

How teams detect issues like this

High-level detection approaches include:

  • Static analysis for request parameters or headers flowing into include, require, dynamic evaluation, template compilation, or generated PHP.
  • Code review checks for response helpers that concatenate untrusted values into template source.
  • Runtime monitoring for unusual PHP process behavior, child-process creation, command execution, or modifications to web-accessible files.
  • Web-application logs focused on unexpected Referer values, repeated requests to link-management endpoints, and validation failures preceding successful state changes.
  • CI and policy checks that prohibit dynamic code construction from externally controlled input.
  • Neutral automated security-review tools may help identify tainted data flows, but findings should be validated against the application's actual rendering behavior.

High-level detection approaches include:

  • Static analysis for request parameters or headers flowing into include, require, dynamic evaluation, template compilation, or generated PHP.
  • Code review checks for response helpers that concatenate untrusted values into template source.
  • Runtime monitoring for unusual PHP process behavior, child-process creation, command execution, or modifications to web-accessible files.
  • Web-application logs focused on unexpected Referer values, repeated requests to link-management endpoints, and validation failures preceding successful state changes.
  • CI and policy checks that prohibit dynamic code construction from externally controlled input.
  • Neutral automated security-review tools may help identify tainted data flows, but findings should be validated against the application's actual rendering behavior.

Sources

SourceLink
github.comgithub.com/dedecms/DedeCMS/blob/v5.8.1/include/common.func.php
github.comgithub.com/projectdiscovery/nuclei-templates/blob/main/http/vulnerabilities/dedecms/dedecms-rce.yaml
srcincite.iosrcincite.io/blog/2021/09/30/chasing-a-dream-pwning-the-biggest-cms-in-china.html
vulncheck.comvulncheck.com/advisories/dedecms-5.8.1-beta-unauthenticated-rce-via-plus-flink-php

Frequently asked

questions

Yes. The vulnerable request path may be reachable over HTTP, and exploitation does not generally require an authenticated account. The exact exposure depends on whether the affected endpoint is publicly accessible and whether request validation controls are effective.

An attacker typically needs network access to the DedeCMS endpoint but not a privileged application account. The request's validation behavior and deployment-specific access controls can change the practical attack surface.

Prevent untrusted request data from entering executable PHP or dynamic template-inclusion paths. Use non-executable templates, strict data binding, and validation before processing state-changing requests.

Apply taint-aware code review and static analysis, prohibit dynamic code generation from request data, enforce least privilege for the web process, and monitor for anomalous command execution or web-file changes.

Yes. The vulnerable request path may be reachable over HTTP, and exploitation does not generally require an authenticated account. The exact exposure depends on whether the affected endpoint is publicly accessible and whether request validation controls are effective.

An attacker typically needs network access to the DedeCMS endpoint but not a privileged application account. The request's validation behavior and deployment-specific access controls can change the practical attack surface.

Prevent untrusted request data from entering executable PHP or dynamic template-inclusion paths. Use non-executable templates, strict data binding, and validation before processing state-changing requests.

Apply taint-aware code review and static analysis, prohibit dynamic code generation from request data, enforce least privilege for the web process, and monitor for anomalous command execution or web-file changes.

Find out what's already
exploitable in your codebase.