首页
社区
课程
招聘
[求助]关于动态定位API,书中讲的不太明白?
2011-7-11 14:21 5716

[求助]关于动态定位API,书中讲的不太明白?

2011-7-11 14:21
5716
int main()
{       
        _asm{
                        nop
                        nop
                       
               
                       
                        nop
                        nop
                        nop
                        CLD                                        ; clear flag DF
                        ;store hash
                        push 0x1e380a6a                ;hash of MessageBoxA
                        push 0x4fd18963                ;hash of ExitProcess
                        push 0x0c917432                ;hash of LoadLibraryA
                        mov esi,esp                        ; esi = addr of first function hash
                        lea edi,[esi-0xc]        ; edi = addr to start writing function

                       

                        ; make some stack space
                        xor ebx,ebx
                        mov bh, 0x04                          
                        sub esp, ebx
                       

                       
                        ; push a pointer to "user32" onto stack
                        mov bx, 0x3233                 ; rest of ebx is null
                        push ebx
                        push 0x72657375
                        push esp
                       
                        xor edx,edx

                ; find base addr of kernel32.dll
                        mov ebx, fs:[edx + 0x30]         ; ebx = address of PEB
                        mov ecx, [ebx + 0x0c]                 ; ecx = pointer to loader data
                        mov ecx, [ecx + 0x1c]                 ; ecx = first entry in initialisation order list
                        mov ecx, [ecx]                                 ; ecx = second entry in list (kernel32.dll)
                        mov ebp, [ecx + 0x08]                 ; ebp = base address of kernel32.dll
                       
                                               
                find_lib_functions:
               
                        lodsd                                         ; load next hash into al and increment esi
                        cmp eax, 0x1e380a6a                ; hash of MessageBoxA - trigger
                                                                        ; LoadLibrary("user32")
                        jne find_functions
                        xchg eax, ebp                         ; save current hash
                        call [edi - 0x8]                 ; LoadLibraryA
                        xchg eax, ebp                         ; restore current hash, and update ebp
                                                                        ; with base address of user32.dll
                       
                       
                find_functions:
                        pushad                                                 ; preserve registers
                        mov eax, [ebp + 0x3c]                ; eax = start of PE header
                        mov ecx, [ebp + eax + 0x78]        ; ecx = relative offset of export table
                        add ecx, ebp                                 ; ecx = absolute addr of export table
                        mov ebx, [ecx + 0x20]                 ; ebx = relative offset of names table
                        add ebx, ebp                                 ; ebx = absolute addr of names table
                        xor edi, edi                                 ; edi will count through the functions

                next_function_loop:
                        inc edi                                         ; increment function counter
                        mov esi, [ebx + edi * 4]         ; esi = relative offset of current function name
                        add esi, ebp                                 ; esi = absolute addr of current function name
                        cdq                                                 ; dl will hold hash (we know eax is small)
                       
                hash_loop:
                        movsx eax, byte ptr[esi]
                        cmp al,ah
                        jz compare_hash
                        ror edx,7
                        add edx,eax
                        inc esi
                        jmp hash_loop

                compare_hash:       
                        cmp edx, [esp + 0x1c]                 ; compare to the requested hash (saved on stack from pushad)
                        jnz next_function_loop
                       
                 
                        mov ebx, [ecx + 0x24]                 ; ebx = relative offset of ordinals table
                        add ebx, ebp                                 ; ebx = absolute addr of ordinals table
                        mov di, [ebx + 2 * edi]         ; di = ordinal number of matched function
                        mov ebx, [ecx + 0x1c]                 ; ebx = relative offset of address table
                        add ebx, ebp                                 ; ebx = absolute addr of address table
                        add ebp, [ebx + 4 * edi]         ; add to ebp (base addr of module) the
                                                                                ; relative offset of matched function
                        xchg eax, ebp                                 ; move func addr into eax
                        pop edi                                         ; edi is last onto stack in pushad
                        stosd                                                 ; write function addr to [edi] and increment edi
                        push edi
                        popad                                        ; restore registers
                                                                         ; loop until we reach end of last hash
                        cmp eax,0x1e380a6a
                        jne find_lib_functions

                function_call:
                        xor ebx,ebx
                        push ebx                        // cut string
                        push 0x74736577
                        push 0x6C696166                //push failwest
                        mov eax,esp                        //load address of failwest
                        push ebx       
                        push eax
                        push eax
                        push ebx
                        call [edi - 0x04] ; //call MessageboxA
                        push ebx
                        call [edi - 0x08] ; // call ExitProcess
                        nop
                        nop
                        nop
                        nop

以上是书中的例子,我就是不明白,请各位大大解释一下,行吗?

如果我想调用msvcrt.dll中的system以上代码怎么改呢?希望有完整的代码。

[培训]《安卓高级研修班(网课)》月薪三万计划,掌握调试、分析还原ollvm、vmp的方法,定制art虚拟机自动化脱壳的方法

收藏
点赞0
打赏
分享
最新回复 (3)
雪    币: 276
活跃值: (183)
能力值: ( LV3,RANK:20 )
在线值:
发帖
回帖
粉丝
fjrdwork 2011-9-5 14:33
2
0
这段内容我已经看过的第一版内容,第一步我记得是要先得到你需要修改的
msvcrt.dll中的system这个函数名的hash值。
怎么获取印象中有代码了,左移几位 与上 右移几位这样的算法。
第二版因为今天刚买到,所以也没看到到底有没有计算HASH值的示例代码了。
你拿到HASH指以后,把
;store hash
push 0x1e380a6a    ;hash of MessageBoxA

这个替换一下。这步是起码的。接下去。如果是我,我只能继续调试研究,
看看那儿还需要更换修改的了。我觉得应该还需要改其他地方。但是还没有具体操作。
所以想象不来。
雪    币: 90
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
慢慢学 2011-9-5 14:52
3
0
这段代码,我记得应该是Oday里面的见到过的。。。我觉得书上就已经很清楚了。。。
雪    币: 540
活跃值: (216)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
chuxuezhe 2012-1-15 20:36
4
0
阅读代码不是小说,不能囫囵吞枣,要一点疑问都没有才行。
最好还要自己亲手跑一跑才好。
这一段代码我也没有全看明白,继续啃
游客
登录 | 注册 方可回帖
返回