[NT] Microsoft Windows LoadImage API Integer Buffer Overflow

From: SecuriTeam (support_at_securiteam.com)
Date: 12/27/04

  • Next message: SecuriTeam: "[UNIX] Linux 2.6 Kernel Capability LSM Module Local Privilege Elevation"
    To: list@securiteam.com
    Date: 27 Dec 2004 16:05:14 +0200
    
    

    The following security advisory is sent to the securiteam mailing list, and can be found at the SecuriTeam web site: http://www.securiteam.com
    - - promotion

    The SecuriTeam alerts list - Free, Accurate, Independent.

    Get your security news from a reliable source.
    http://www.securiteam.com/mailinglist.html

    - - - - - - - - -

      Microsoft Windows LoadImage API Integer Buffer Overflow
    ------------------------------------------------------------------------

    SUMMARY

    An exploitable integer buffer overflow exists in the LoadImage API of the
    USER32 Lib. This function loads an icon, a cursor or a bitmap and then try
    to proceed the image. If an attacker sends a specially crafter bmp, cur,
    ico or ani file within an HTML page or in an Email, it is then possible to
    run arbitrary code on the affected system.

    DETAILS

    When the LoadImage API try to procees an image, it directly uses the size
    field in the image file and then add 4. So if we set the size of image
    between 0xfffffffc-0xffffffff, an integer buffer overflow occurs.

    The function defines:
    HANDLE LoadImage(
      HINSTANCE hinst, // handle of the instance containing the image
      LPCTSTR lpszName, // name or identifier of the image
      UINT uType, // type of image
      int cxDesired, // desired width
      int cyDesired, // desired height
      UINT fuLoad // load flags
    );

    lpszName is the handle to the image to load, uType specifies the type of
    image to be loaded. This parameter can be one of the following values:
     IMAGE_BITMAP Loads a bitmap.
     IMAGE_CURSOR Loads a cursor.
     IMAGE_ICON Loads an icon.

    When LoadImage API try to parse the bmp, cur, ico, ani file format, it
    doesn't implement any check on the size field and add 4. Look at the code
    below:

    When ANI or CUR is in question:
     .text:77D56178 mov eax, [ebx+8] //Direct read our size here:P
     .text:77D5617B mov [ebp+dwResSize], eax
     .text:77D5617E jnz short loc_77D56184
     .text:77D56180 add [ebp+dwResSize], 4 //add 4 int overflow...
     .text:77D56184
     .text:77D56184 loc_77D56184: ; CODE XREF: sub_77D5608F+EF#j
     .text:77D56184 push [ebp+dwResSize] //allocate a wrong size
     .text:77D56187 push 0
     .text:77D56189 push dword_77D5F1A0
     .text:77D5618F call ds:RtlAllocateHeap

    Then use the fake size for memmov leads to the heap overflow:
     .text:77D561A9 mov ecx, [ebx+8]
     .text:77D561AC mov esi, [ebx+0Ch]
     .text:77D561AF add esi, [ebp+arg_0]
     .text:77D561B2 mov edx, ecx
     .text:77D561B4 shr ecx, 2
     .text:77D561B7 mov edi, eax
     .text:77D561B9 rep movsd
     .text:77D561BB mov ecx, edx
     .text:77D561BD and ecx, 3
     .text:77D561C0 rep movsb

    More details and POC at
    <http://www.xfocus.net/flashsky/icoExp/index.html>
    http://www.xfocus.net/flashsky/icoExp/index.html

    ADDITIONAL INFORMATION

    The information has been provided by <mailto:fangxing@venustech.com.cn>
    Flashsky.

    ========================================

    This bulletin is sent to members of the SecuriTeam mailing list.
    To unsubscribe from the list, send mail with an empty subject line and body to: list-unsubscribe@securiteam.com
    In order to subscribe to the mailing list, simply forward this email to: list-subscribe@securiteam.com

    ====================
    ====================

    DISCLAIMER:
    The information in this bulletin is provided "AS IS" without warranty of any kind.
    In no event shall we be liable for any damages whatsoever including direct, indirect, incidental, consequential, loss of business profits or special damages.


  • Next message: SecuriTeam: "[UNIX] Linux 2.6 Kernel Capability LSM Module Local Privilege Elevation"

    Relevant Pages