首页
社区
课程
招聘
4
[原创]对照内核结构深入理解动态定位 API
发表于: 2015-8-14 19:45 3932

[原创]对照内核结构深入理解动态定位 API

2015-8-14 19:45
3932

图 / 文 N0viceLive <rectigu@gmail.com>

2015 年 8 月

tl, dr

我们先理清总体的方向。动态定位 API 有如下几个重要步骤。

1
2
1. 获取 kernel32.dll 的加载基址。
2. 获取 GetProcAddress 的地址。
1
2
3
4
5
6
7
8
lkd> dt nt!_TEB
   +0x000 NtTib            : _NT_TIB
   +0x01c EnvironmentPointer : Ptr32 Void
   +0x020 ClientId         : _CLIENT_ID
   +0x028 ActiveRpcHandle  : Ptr32 Void
   +0x02c ThreadLocalStoragePointer : Ptr32 Void
   +0x030 ProcessEnvironmentBlock : Ptr32 _PEB
   /* tl, dr */
1
2
3
4
5
6
7
8
9
lkd> dt nt!_PEB
   +0x000 InheritedAddressSpace : UChar
   +0x001 ReadImageFileExecOptions : UChar
   +0x002 BeingDebugged    : UChar
   +0x003 SpareBool        : UChar
   +0x004 Mutant           : Ptr32 Void
   +0x008 ImageBaseAddress : Ptr32 Void
   +0x00c Ldr              : Ptr32 _PEB_LDR_DATA
   /* tl, dr */
1
2
xor ecx, ecx
mov ecx, dword ptr fs:[ecx + 30h]
1
2
3
4
5
6
7
8
lkd> dt nt!_PEB_LDR_DATA
   +0x000 Length           : Uint4B
   +0x004 Initialized      : UChar
   +0x008 SsHandle         : Ptr32 Void
   +0x00c InLoadOrderModuleList : _LIST_ENTRY
   +0x014 InMemoryOrderModuleList : _LIST_ENTRY
   +0x01c InInitializationOrderModuleList : _LIST_ENTRY
   +0x024 EntryInProgress  : Ptr32 Void
1
2
3
lkd> dt nt!_LIST_ENTRY
   +0x000 Flink            : Ptr32 _LIST_ENTRY
   +0x004 Blink            : Ptr32 _LIST_ENTRY
1
2
mov ecx, dword ptr [ecx + 0ch]
mov ecx, dword ptr [ecx + 1ch]
1
2
3
4
5
6
7
8
9
10
lkd> dt nt!_LDR_DATA_TABLE_ENTRY
   +0x000 InLoadOrderLinks : _LIST_ENTRY
   +0x008 InMemoryOrderLinks : _LIST_ENTRY
   +0x010 InInitializationOrderLinks : _LIST_ENTRY
   +0x018 DllBase          : Ptr32 Void
   +0x01c EntryPoint       : Ptr32 Void
   +0x020 SizeOfImage      : Uint4B
   +0x024 FullDllName      : _UNICODE_STRING
   +0x02c BaseDllName      : _UNICODE_STRING
   /* tl, dr */
1
2
3
4
lkd> dt nt!_UNICODE_STRING
   +0x000 Length           : Uint2B
   +0x002 MaximumLength    : Uint2B
   +0x004 Buffer           : Ptr32 Uint2B
1
2
3
4
5
6
7
find_kernel32_dll_base:
    mov ebx, dword ptr [ecx + 8]
    mov eax, dword ptr [ecx + 20h]
    mov ecx, dword ptr [ecx]
 
    cmp byte ptr [eax + 0ch], 33h
    jne find_kernel32_dll_base
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
lkd> dt nt!_IMAGE_DOS_HEADER
   +0x000 e_magic          : Uint2B
   +0x002 e_cblp           : Uint2B
   +0x004 e_cp             : Uint2B
   +0x006 e_crlc           : Uint2B
   +0x008 e_cparhdr        : Uint2B
   +0x00a e_minalloc       : Uint2B
   +0x00c e_maxalloc       : Uint2B
   +0x00e e_ss             : Uint2B
   +0x010 e_sp             : Uint2B
   +0x012 e_csum           : Uint2B
   +0x014 e_ip             : Uint2B
   +0x016 e_cs             : Uint2B
   +0x018 e_lfarlc         : Uint2B
   +0x01a e_ovno           : Uint2B
   +0x01c e_res            : [4] Uint2B
   +0x024 e_oemid          : Uint2B
   +0x026 e_oeminfo        : Uint2B
   +0x028 e_res2           : [10] Uint2B
   +0x03c e_lfanew         : Int4B
1
2
mov ebp, ebx
add ebp, dword ptr [ebp + 3ch]

[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课

收藏
免费 4
支持
分享
赞赏记录
参与人
雪币
留言
时间
飘零丶
为你点赞~
2024-5-31 05:27
shinratensei
为你点赞~
2024-5-31 05:20
PLEBFE
为你点赞~
2023-2-26 00:48
xanderchen
为你点赞~
2018-12-12 13:22
最新回复 (0)
游客
登录 | 注册 方可回帖
返回

账号登录
验证码登录

忘记密码?
没有账号?立即免费注册