Windows中很多重要结构都是undocumented或文档不完整的,因为主要提供给操作系统内部使用,且可能会随着Windows更新而发生变化,没有稳定性保证。
观察这些结构一般推荐的做法都是那WinDbg调试,主要的好处是提供了大量windows相关的指令,例如 !peb
!teb
等,且能自动地从微软官方服务器上下载对应的符号,打印结构具体信息。
但我个人更习惯IDA Pro一些,可以通过 Type Libraries (Shift+F11) 加载 Windows API dll 中用到的结构信息,例如 PEB 和 TEB 在微软文档里的结构名叫 _PEB
和 _TEB
,这两个结构的定义可以通过加载ntapi中的结构信息来添加到IDA Pro中。
shellcode - Structure Definitions for PEB in IDA - Reverse Engineering Stack Exchange
Thread Information Block (TIB) or Thread Environment Block (TEB),类型 _TEB
存储当前线程相关运行时信息
x86 32位下位于fs指示的段中,x86_64位于gs指示的段中,下方是一些重要字段的偏移
Size | Offset 32 | Offset 64 | Content | Documented |
---|---|---|---|---|
void* | FS:[0x00] | GS:[0x00] | Current SEH frame | |
void* | FS:[0x04] | GS:[0x08] | Stack Base (high) | |
void* | FS:[0x08] | GS:[0x10] | Stack Limit (low) | |
void* | FS:[0x18] | GS:[0x30] | Linear address of TEB | |
size_t | FS:[0x20] | GS:[0x40] | Process ID | |
size_t | FS:[0x24] | GS:[0x48] | Current thread ID | |
void* | FS:[0x2C] | GS:[0x58] | Linear address of the thread-local storage array | |
void* | FS:[0x30] | GS:[0x60] | Linear address of PEB | ✓ |
Win32 Thread Information Block - Wikipedia
TEB and PEB – RvsEc0n (wordpress.com)
Process Environment Block,类型 _PEB
PEB 包含了进程相关的数据结构,包括进程上下文、启动参数、程序映像加载器(动态链接)的数据结构、程序基地址等
Size | Offset 32 | Offset 64 | Content | Documented |
---|---|---|---|---|
BYTE | 0x2 | 0x02 | BeingDebugged | |
void* | 0x8 | ImageBaseAddress | ||
void* | 0xC | Ldr, contains information about the loaded modules for the process. | ✓ |
Process Environment Block - Wikipedia