Описание
fontTools is Vulnerable to Arbitrary File Write and XML injection in fontTools.varLib
Summary
The fonttools varLib (or python3 -m fontTools.varLib) script has an arbitrary file write vulnerability that leads to remote code execution when a malicious .designspace file is processed. The vulnerability affects the main() code path of fontTools.varLib, used by the fonttools varLib CLI and any code that invokes fontTools.varLib.main().
The vulnerability exists due to unsanitised filename handling combined with content injection. Attackers can write files to arbitrary filesystem locations via path traversal sequences, and inject malicious code (like PHP) into the output files through XML injection in labelname elements. When these files are placed in web-accessible locations and executed, this achieves remote code execution without requiring any elevated privileges. Once RCE is obtained, attackers can further escalate privileges to compromise system files (like overwriting /etc/passwd).
Overall this allows attackers to:
- Write font files to arbitrary locations on the filesystem
- Overwrite configuration files
- Corrupt application files and dependencies
- Obtain remote code execution
The attacker controls the file location, extension and contents which could lead to remote code execution as well as enabling a denial of service through file corruption means.
Affected Lines
fontTools/varLib/__init__.py
PoC
- Set up
malicious.designspaceand respectivesource-*.ttffiles in a directory like/Users/<username>/testing/demo/(will impact relative file location within malicious.designspace)
setup.py
malicious.designspace
Optional: You can put a file with any material within ../../tmp/newarbitraryfile.json in advance, the contents in the file will be overwritten after running the setup script in the following step.
- Run the setup.py script to generate
source-*.tfffiles required for the malicious.designspace file.
- Execute the given payload using the vulnerable varLib saving the file into the arbitrary file location of filename
- Validate arbitrary file write was performed by looking at path assigned within malicious designspace
- After validating that we can provide arbitrary write to any location, we can also validate that we can control sections of content as well demonstrated with the below payload.
malicious2.designspace
- When the program is run, we can show we control the contents in the new file
Here being outputted to a localised area ignoring filename presented in variable-font
- We can look inside file123 to validate user controlled injection
to show <?php echo shell_exec("/usr/bin/touch /tmp/MEOW123");?>]]>
- Executing the file and reading looking at the newly generated file
we can see that the file was just created showing RCE.
Recommendations
- Ensure output file paths configured within designspace files are restricted to the local directory or consider further security measures to prevent arbitrary file write/overwrite within any directory on the system
Пакеты
fonttools
>= 4.33.0, < 4.60.2
4.60.2
Связанные уязвимости
fontTools is a library for manipulating fonts, written in Python. In versions from 4.33.0 to before 4.60.2, the fonttools varLib (or python3 -m fontTools.varLib) script has an arbitrary file write vulnerability that leads to remote code execution when a malicious .designspace file is processed. The vulnerability affects the main() code path of fontTools.varLib, used by the fonttools varLib CLI and any code that invokes fontTools.varLib.main(). This issue has been patched in version 4.60.2.
fontTools is a library for manipulating fonts, written in Python. In versions from 4.33.0 to before 4.60.2, the fonttools varLib (or python3 -m fontTools.varLib) script has an arbitrary file write vulnerability that leads to remote code execution when a malicious .designspace file is processed. The vulnerability affects the main() code path of fontTools.varLib, used by the fonttools varLib CLI and any code that invokes fontTools.varLib.main(). This issue has been patched in version 4.60.2.
fontTools is a library for manipulating fonts, written in Python. In v ...