Welcome to your second lesson! In our previous session, we deconstructed the theoretical architecture of Portable Executable (PE) files. You learned about the sequence of headers and sections that act as a blueprint for the Windows loader, and we even practiced finding our way through a binary with a hex editor. While that's a crucial foundational skill, it's also clear that manual parsing is slow and error-prone for routine analysis.
Today, we'll build on that foundation by embracing the hands-on, tool-driven approach you prefer. We will explore specialized PE analysis tools that automate the parsing process, presenting the complex structure of a PE file in a clear, navigable format. By the end of this lesson, you will be proficient in using a tool like PE-bear to rapidly examine the headers and sections of any Windows executable, which is a core skill for any reverse engineer.
The Analyst's Toolkit: Why Use a PE Parser?
Before diving into a specific tool, it's helpful to understand what information an analyst typically seeks when first examining a binary, especially in a malware analysis context. Tools like PE-bear, PE-studio, and CFF Explorer are designed to surface this critical information quickly.
The following video from HackerSploit provides an excellent overview of the key data points an analyst looks for. While the presenter uses PE-studio, the concepts are universal across all PE parsers.
Malware Analysis Bootcamp - Analyzing The PE Header
This video sets the stage by explaining the purpose of PE header analysis from a practical, cybersecurity perspective.
Watch the first few minutes to understand the main goals: What to Look For: Pay attention to the list of key items: compiler stamp, subsystem, sections, and libraries/imports. This is the "what" and "why" of our analysis. PE-studio Intro: Observe how the tool organizes information into a tree structure, separating the different headers and directories. This is a common UI pattern you'll see in PE-bear as well.
As you saw, these tools are designed to take the raw bytes of a file and present them as the structured data we discussed in the last lesson—headers, sections, imports, and more. Now, let's get our hands on our main tool for this lesson, PE-bear, and see it in action.
A Guided Tour of PE-bear
PE-bear is a powerful, freeware PE viewer that provides an intuitive interface for navigating an executable's structure. It visually maps the file's components, which is invaluable for understanding the relationship between the on-disk format and its in-memory representation.
Let's open a common executable, like C:\Windows\System32\calc.exe, and see how PE-bear presents the information we previously had to hunt for manually.
The general workflow in PE-bear involves selecting a component in the left-hand tree (like "DOS Header" or a specific section) and then examining the parsed details in the main window. This immediately saves us from the tedious process of calculating offsets and interpreting raw hex values.
The following video provides a detailed, step-by-step walkthrough of parsing an executable with PE-bear. The presenter methodically connects the fields shown in the tool to their corresponding C structures in the winnt.h header file, an approach that should resonate well with your background.
Manually parsing PE files with PE-bear
This video from the SEKTOR7 Malware Development Essentials course is a masterclass in using PE-bear. It's the core practical exercise for this lesson.
Follow along with the presenter as they dissect notepad.exe. It's recommended to have PE-bear open with notepad.exe loaded to replicate the steps. Conceptual Intro: This segment recaps the key concepts of File Pointer (Raw Address) vs. RVA, and provides a great "road signs" analogy for navigating the PE headers. This reinforces our previous lesson. Header Walkthrough: This is the most critical part. The presenter navigates from the DOS Header (finding e_lfanew) to the NT Headers. They then break down the File Header and the all-important Optional Header, explaining key fields like AddressOfEntryPoint, ImageBase, and DllCharacteristics. Data Directories: Focus on how the tool parses the DataDirectory array. The presenter shows how to find the RVA for the Import Table and demonstrates how to translate that RVA to a virtual address in a debugger, a crucial skill connecting static analysis to dynamic analysis. Section Headers: Finally, see how PE-bear displays the Section Headers in a clean table. The presenter explains the key fields like VirtualAddress, PointerToRawData, and Characteristics (permissions), and relates them to the memory permissions seen in a debugger.
Reinforcing with a Textual Guide
The video provided a dynamic walkthrough. For review and reference, a textual guide can be invaluable. The following article, "PE Format Illustrated," covers the same ground using PE-bear, providing clear screenshots and interpretations for each part of the PE file.
PE Format Illustrated – Part 1 - Mark Pelf - Blog
This blog post by Mark Pelf serves as an excellent written companion to the video walkthrough. It uses PE-bear to illustrate the PE file structure.
Review the following sections to solidify your understanding: Skim the introduction and the short description of PE-bear. Read through Section 7, DOS Header, and see how it mirrors the video's explanation of the "MZ" magic number and the e_lfanew offset. Study Section 9, NT Headers. Pay close attention to how PE-bear parses the File Header and Optional Header, highlighting the Entry Point and Data Directories. Examine Section 10, Section Headers, to see the tabular representation of the section table. Finally, look at Section 11, Multiple sections, which shows how PE-bear can be used to inspect the content of individual sections like .text and .rsrc.
Applying Your Knowledge: The Analyst's Perspective
Now that you're comfortable navigating the PE structure with a parser, let's return to the malware analyst's perspective. The true power of these tools lies not just in viewing data, but in interpreting it to understand a program's potential behavior.
A common technique used by malware authors to hinder analysis is "packing." A packer is a program that compresses or encrypts an executable, wrapping it in a small "stub" of code that unpacks the original program into memory at runtime. This can significantly alter the PE structure that a static analysis tool sees.
Let's see how packing impacts the sections and imports, and how a tool like PE-studio (or PE-bear) can help us quickly identify it.
Malware Analysis Bootcamp - Analyzing The PE Header
This part of the HackerSploit video demonstrates the practical application of PE analysis: identifying functionality and spotting obfuscation.
Watch the following segments, focusing on the interpretation of the data: Analyzing Sections: The presenter checks the permissions (Read, Write, Execute) for standard sections, looking for anything unusual. This is a critical step in security analysis. Libraries and Imports: This is key. See how the list of imported DLLs (like kernel32.dll, advapi32.dll, ws2_32.dll) and functions (CreateFile, RegOpenKey, socket) provides powerful clues about the malware's capabilities: file manipulation, registry access, and networking. The Impact of Packers: Here, a packed version of the same sample is analyzed. Notice how the section names are changed (e.g., to UPX0, UPX1) and, more importantly, how the list of imports shrinks dramatically. This is a classic indicator that the true functionality is hidden.
Conclusion
In this lesson, you've transitioned from theoretical knowledge to practical application. You've learned how to wield a powerful PE parser to dissect Windows executables efficiently, a skill that is fundamental to all reverse engineering disciplines.
Here are the key takeaways from today's session:
- PE analysis tools like PE-bear automate the parsing of headers and sections, saving you from tedious manual work in a hex editor.
- The user interface of these tools directly maps to the PE structures (
DOS_HEADER,NT_HEADERS, etc.) we've learned about. - By examining the
Optional Header, you can quickly find critical information like theAddressOfEntryPoint,ImageBase, and requiredSubsystem. - The Section Table view provides a clear summary of each section's on-disk and in-memory properties, including its permissions (Read/Write/Execute).
- From an analyst's perspective, the most valuable information often comes from the Import Table, which reveals the program's intended capabilities by listing the external functions it relies on.
- Anomalies in the PE structure, such as non-standard section names and a suspiciously small import table, are strong indicators that a binary may be packed or obfuscated.
In our next lesson, we will shift our focus from the Windows world to Linux. You will learn about the ELF (Executable and Linkable Format), the standard binary format on Linux and other Unix-like systems, and use powerful command-line tools like readelf and objdump to perform a similar structural analysis.