ASA-2019-00051 – rdesktop: Integer overflow that leads to a heap-based buffer overflow in function process_bitmap_updates()


Allele Security Alert

ASA-2019-00051

Identifier(s)

ASA-2019-00051, CVE-2018-8795

Title

Integer overflow that leads to a heap-based buffer overflow in function process_bitmap_updates()

Vendor(s)

rdesktop team

Product(s)

rdesktop

Affected version(s)

rdesktop versions up to and including v1.8.3

Fixed version(s)

rdesktop v1.8.4

Proof of concept

Unknown

Description

rdesktop versions up to and including v1.8.3 contain an integer overflow that leads to a heap-based buffer overflow in function process_bitmap_updates() and results in a memory corruption and probably even a remote code execution.

Technical details

Another classic vulnerability is an integer overflow when processing the received bitmap (screen content) updates, as can be seen below:

/* Process bitmap updates*/
void 
process_bitmap_updates(STREAM s){
    uint16 num_updates;
    uint16 left, top, right, bottom, width, height;
    uint16 cx, cy, bpp, Bpp, compress, bufsize, size;
    uint8 *data, *bmpdata;
    int i;

    in_uint16_le(s,num_updates)

    for(i=0 i<num_updates; i++){
         in_uint16_le(s,left);
         in_uint16_le(s,top);
         in_uint16_le(s,right);
         in_uint16_le(s,bottom);
         // EI-DBG: Here we control width (16bit), height (16bit), and bpp (13bit)
         in_uint16_le(s,width);
         in_uint16_le(s,height);
         in_uint16_le(s,bpp);
         Bpp = (bpp + 7) / 8;
         ...
         in_uint8p(s,data,size);
         // EI-DBG: A nice Integer-Overflow: width * height * Bpp > 4Gb
         // EI-DBG: Since the compression methods stop on illegal opcode, 
         // EI-DBG: this is a controllable heap-based Buffer-Overflow
         bmpdata = (uint8 *)xmalloc(width * height * Bpp);
         if(bitmap_decompress(bmpdata, width, height, data, size, Bpp))
         {
             ui_paint_bitmap(left, top, cx, cy, width, height, bmpdata)
         }
         else
         {
             DEBUG_RDPS(("Failed to decompress data\n"));
         }
    }
}

Although “width” and “height” are only 16 bits each, by multiplying them together with “Bpp” (bits-per-pixel), we can trigger an integer overflow. Later on, the bitmap decompression will process our input and break on any decompression error, giving us a controllable heap-based buffer-overflow.

Credits

Eyal Itkin (Checkpoint Research)

Reference(s)

Reverse RDP Attack: Code Execution on RDP Clients
https://research.checkpoint.com/reverse-rdp-attack-code-execution-on-rdp-clients/

Updated ChangeLog and bumped version to 1.8.4
https://github.com/rdesktop/rdesktop/commit/34b8a18fe5d4de795851defe34b3ad3e1f43532b

CVE-2018-8795
https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2018-8795

CVE-2018-8795
https://nvd.nist.gov/vuln/detail/CVE-2018-8795

If there is any error in this alert or you wish a comprehensive analysis, let us know.

Last modified: February 11, 2019

We are not responsible for any data loss, device corruption or any other type of issue due to the use of any information mentioned in our security alerts.