ChatterBot Predictable Directory Symlink Vulnerability
Overview
ChatterBot, a Python library for creating conversational AI, contains a critical vulnerability in its `UbuntuCorpusTrainer.extract()` method. Versions prior to 1.2.14 are susceptible to a local arbitrary file write attack. The vulnerability stems from the use of a predictable, user-home-directory-rooted output path (`~/ubuntu_data/ubuntu_dialogs`) for extracted corpus data. The code first checks if the directory exists and then creates it, followed by calling `tar.extractall(path=self.data_path)`. An attacker with local access can exploit this by pre-creating a symbolic link at the expected `~/ubuntu_data/ubuntu_dialogs` location that points to an arbitrary, attacker-controlled directory. When `tar.extractall()` is invoked, it will follow this symlink, writing the contents of the tar archive (which the attacker could also control) to the attacker-specified location. This could lead to overwriting critical system files, sensitive data leakage, or the injection of malicious code into the system's filesystem, depending on the attacker's target directory and the contents of the tar archive.
Affected Systems
Testing Guide
1. Create a temporary directory for the symlink target: `mkdir /tmp/evil_output` 2. Create a harmless tar archive: `echo 'test' > dummy_file.txt; tar -czvf evil.tar.gz dummy_file.txt; rm dummy_file.txt` 3. Navigate to the ChatterBot project directory (or where `UbuntuCorpusTrainer` would be used). 4. Remove the existing `~/ubuntu_data` directory if it exists: `rm -rf ~/ubuntu_data` 5. Create the symlink: `ln -s /tmp/evil_output ~/ubuntu_data/ubuntu_dialogs` 6. Attempt to run the `UbuntuCorpusTrainer` with a dummy or minimal corpus extraction that would normally target `~/ubuntu_data/ubuntu_dialogs`. 7. Check if `evil.tar.gz` contents appear in `/tmp/evil_output` (they should not if vulnerable, they *will* appear if vulnerable). If the archive was extracted to `/tmp/evil_output`, the system is vulnerable. 8. Clean up: `rm -rf ~/ubuntu_data ~/ubuntu_data.tar.gz /tmp/evil_output`
Mitigation Steps
* Upgrade ChatterBot to version 1.2.14 or later. * Avoid running ChatterBot trainers with untrusted input archives if upgrading is not immediately possible. * Ensure that the `~/ubuntu_data/ubuntu_dialogs` directory and its parent directories are not writable by unprivileged users. * Regularly audit system directories for unexpected symbolic links, especially within user home directories.
Patch Details
1.2.14