DOS Header, DOS Stub, & Rich Header
Introduction
TLDR: The DOS Header is the most important part in this page, and within that the key takeaway is the use of e_lfanew
to access the next header: NT Headers
.
DOS Header
Overview
The DOS Header (also known as MS-DOS header) is a 64 byte long structure that exists at the start of a PE file. It contains the DOS magic bytes 4D 5A
"MZ" in ascii. It is not important for the functionality of modern windows. It is however important on MS-DOS. But we don't need to worry about that.
Structure
The most important members are:
e_lfanew - Holds the offset to the start of NT headers. It tells the loader where to look for the NT header as well as allows us to access the NT header.
e_magic - This is the magic bytes
4D 5A
"MZ" in ascii. It is the DOS family signature.
Here is the view of DOS Header in PE Bear
NOTE: The offset to e_lfanew
is 0x3C from the start of the DOS Header.
DOS Stub
Overview
The DOS Stub is an error message that says “This program cannot be run in DOS mode. That's all.
Rich Header
The Rich Header is an undocumented structure that lies between the DOS Stub and the start of NT Headers. It is included in executables compiled with Visual Studio Toolset.
It technically is not part of the PE structure, and can be zeroed out. However, there have been numerous threat actors and malware writers that have utilized this Rich Header
Last updated