Skip to content

Multiple Arbitrary File Write vulnerabilities #14

Closed
@catfag

Description

@catfag

A specially crafted malicious .unitypackage can save or overwrite arbitrary files on the system when extracted with unitypackage_extractor due to several vulnerabilities. This could be used to install malware or overwrite important files.

tarfile.extractAll

with tarfile.open(name=packagePath, encoding=encoding) as upkg:
upkg.extractall(tmpDir)

Please note the warning in TarFile.extractall's docs: It doesn't ensure that files aren't created outside of the specified path. Here's a proof of concept:

touch /tmp/badfile
# Make a tarfile with an absolute path
tar -cf bad.tar -PC / /tmp/badfile
rm /tmp/badfile
python -c "import tarfile; tarfile.open('bad.tar').extractall('.')"
ls /tmp/badfile # It exists again!

When fixing this please keep in mind that tarfiles can also contain symlinks and other weird things. So maybe this approach might help to mitigate this issue.

No validation of "pathname" in .unitypackage

with open(f"{assetEntryDir}/pathname", encoding=encoding) as f:
pathname = f.readline()
pathname = pathname[:-1] if pathname[-1] == '\n' else pathname #Remove newline
#Extract to the pathname
print(f"Extracting '{dirEntry.name}' as '{pathname}'")
assetOutPath = os.path.join(outputPath, pathname)
os.makedirs(os.path.dirname(assetOutPath), exist_ok=True) #Make the dirs up to the given folder
shutil.move(f"{assetEntryDir}/asset", assetOutPath)

This very similar to the above. If a specially crafted .unitypackage has a modified pathname file in it that contains an absolute path, then the asset file will be moved to that location. This issue exists regardless of whether the user specifies an extraction output path or not, as os.path.join() will ignore its first argument when the second argument is an absolute path (tested on Windows and Linux).

As above the path should be validated. I don't think any valid .unitypackage will have absolute paths in it (in the tar itself, or in the pathfiles) so it would make sense to abort extraction if this is the case and inform the user.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions