/

CVE-2022-50898

Severity:

HIGH RISK

(8.8)

Code Injection in NanoCMS 0.4

CVE-2022-50898

Modified

Vulnerability type

Category:

Code Injection

CWE:

CWE-434

Impact:

Remote Code Execution

Severity:

HIGH RISK

(8.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

NanoCMS 0.4 contains an authenticated file upload flaw in its page creation mechanism that allows attackers to upload PHP files with arbitrary code into the pages directory.

When an authenticated user can create or modify page content without proper validation, this can lead to remote code execution on the server whenever the uploaded PHP file is requested.

Affected context

This vulnerability arises in NanoCMS 0.4 deployments where authenticated users are allowed to create or manage pages and the application stores page content as executable PHP files or allows PHP code within uploaded content.

The risk is present when:

  • Page creation or editing accepts input that can be saved as a PHP file (or within a PHP context),
  • The resulting files are written into a web-accessible directory (e.g., a pages directory),
  • The web server is configured to execute PHP in that directory.

In such setups, user-supplied content effectively becomes server-side executable code if not sanitized.

Exploit preconditions

  • Attack surface: Web application interface for page creation and content management.
  • Required access: Valid authenticated account with permissions to create or modify pages.
  • Trigger point: Submitting crafted page content or file data that is saved as a PHP file in the pages directory.
  • Why exploitation is possible: The application does not sufficiently sanitize or restrict the content or file type during the page creation process, allowing user-controlled data to be stored as executable PHP, which the server then interprets as code when accessed via HTTP.

Why this happens

The underlying issue is improper control over dynamically generated code, aligning with CWE-94: Improper Control of Generation of Code ('Code Injection').

The page creation functionality accepts user input that can end up in a PHP file or within a PHP execution context without robust validation, encoding, or restriction of executable constructs.

As a result, user-controlled data can become server-side code that is executed when the file is requested, effectively granting the attacker the ability to run arbitrary commands within the web server's execution environment.

This is a design and validation flaw where content intended to be treated as data is instead handled as executable code by the platform.

Potential impact

  • Remote code execution with the privileges of the web server process.
  • Installation of web shells for persistent access and further attacks.
  • Reading or modification of application configuration and data.
  • Pivoting to other internal systems or services reachable from the server.
  • Defacement or manipulation of website content served from the CMS.
  • Potential escalation to full server compromise depending on environment hardening.

General mitigation guidance

Effective mitigation focuses on preventing user-supplied content from becoming executable code and constraining the effects of any uploaded content.

Recommended patterns include:

  • Treating user-supplied page content strictly as data: store content in a database or non-executable templates rather than as raw PHP files.
  • Enforcing strict content validation and sanitization for page bodies, disallowing PHP tags and other executable constructs.
  • Restricting upload destinations to directories that are not configured for code execution (e.g., serve uploads from a static file host or non-PHP-enabled path).
  • Applying server-side configuration controls (such as disabling PHP execution in upload or pages directories via web server configuration).
  • Applying least-privilege principles to the web server user and file system permissions so that it cannot create or modify executable code paths unnecessarily.
  • Using templating engines or rendering layers that separate presentation logic from user-provided content and do not directly evaluate user input as code.

How teams detect issues like this

Detection efforts can combine code-focused analysis with runtime monitoring:

  • Static analysis: Search for code paths where user input from page creation forms is written directly to disk as .php or other executable files without content filtering or file-type checks.
  • Code review: During manual review, flag any functionality that:
  • Writes user input into PHP files,
  • Uses include, require, or dynamic file execution on user-controllable paths,
  • Lacks checks on MIME type, file extension, and content for uploaded or generated files.
  • Configuration review: Inspect web server and PHP-FPM configuration to identify directories where uploads or generated pages are stored and verify whether those paths allow code execution.
  • Runtime monitoring: Look for unusual file creation events in web-accessible directories, requests to unexpected new PHP files, or outbound network activity originating from the web server process.
  • Automated tools: Employ SAST/DAST tools or CMS-specific security scanners configured to detect code injection and unsafe file upload patterns.

Sources

SourceLink
github.comgithub.com/ishell/Exploits-Archives/blob/master/2009-exploits/0904-exploits/nanocms-multi.txt
github.comgithub.com/kalyan02/NanoCMS
exploit-db.comexploit-db.com/exploits/50997
vulncheck.comvulncheck.com/advisories/nanocms-remote-code-execution-rce-authenticated

Frequently asked

questions

Exploitation is straightforward once an attacker has valid credentials with page creation rights. They only need to craft content or a file that is saved as executable PHP and then access it via the browser to trigger code execution.

Not necessarily. Any role that can create or modify pages in a way that results in files being written to the pages directory can potentially be abused. The exact requirement depends on how roles and permissions are configured in the NanoCMS instance.

The most robust pattern is to ensure that user-provided content is never stored or interpreted as executable code. Store page data as plain text or markup in non-executable storage (e.g., database or static templates), and disable PHP execution in directories used for user content.

Future development should follow a clear separation of code and content: avoid designs where user input can alter server-side code paths, enforce strict validation of uploads and page content, configure the web server to treat user-controlled paths as non-executable, and integrate security-focused code review and static analysis into the development lifecycle.

Find out what's already
exploitable in your codebase.