WinDbg

Notes on using WinDbg for reverse engineering compiled in October 2021.

When using WinDbg to perform Dynamic Reverse Engineering start with configuring the symbol path

# Following guidance from https://docs.microsoft.com/en-us/windows-hardware/drivers/debugger/symbol-path


srv*c:\MyServerSymbols*https://msdl.microsoft.com/download/symbols
Selecting notepad.exe

After WinDbg attaches to a process the application execution flow is paused. If this is your first time using WinDbg it may take a minute to finish installing the symbol files.

notepad.exe loaded into WinDbg

In order to have the process continue enter the "g" command

Because the process was attached after execution has already begun it's useful to reload the process in order to load all relevant symbol files. This can be done with the command ".reload /f". This may take several minutes.

The "u" command can be used to specify which location to start disassembling from. In this instance the addresses following the instruction pointer are all 3's this is becasue of how WinDbg injects into the process and controls it's execution. (I'm not sure of why this works, will need to look into it closer).

Reading process memory with dW

Dumping structures from memory using dt. This requires the symbol files.

It is also possible to add -r in order to recursively dump nested structures.

Due to some APIs taking structures as arguments it is important to be able to determine the size of structures. This can be done using the sizeof command.

It is possible to modify registry values using the edit command ed in order to change execution flow or results from arithmetic operations.

Changing where EIP points

searching through memory space can be done with the s command. For instance the following pattern will look for four As.

Using r to modify and view registry values

WinDbg can be used to set both software and hardware breakpoints. Software breakpoints for instance can be used to stop at API calls including functions not yet loaded into the memory space. Hardware breakpoints can be used to determine when data is accessed.

By setting a breakpoint on the WriteFile API call it was possible to trigger the process to break when attempting to save the file. When you first click the save as button it will attempt to load a handful of symbol files and you may also need to hit g in order to go forward. After the first execution whenever you save the file the breakpoint will hit.

Breakpoints can be cleared using the bc command and specifying the breakpoint number

Unresolved functions can have breakpoints set with the bu command. Unresolved functions are functions contained within modules that have not yet been loaded.

It is possible using the ba command to set hardware breakpoints which trigger when a register is read, modified or executed.

----------------------------------------------------------------------------------------------------

Useful Hooks

  1. bp wsock32!recv This will hook the Windows recv API.

Useful Tips:

  • When searching for a string don't only use ascii, for instance strings in notepad.exe are stored as unicode and wouldn't show up in an ascii search.

Last updated