简单的动态寻址

这篇博客通过PEB(Process Environment Block)结构动态查找并调用Windows API,如FreeLibrary、LoadLibraryA和MessageBoxA,展示了如何在内存中搜索特定模块和函数地址。

mov eax,fs:[30h]        ; PEB 必须是开头哦
mov eax,[eax+0ch]        ; LDR table
mov esi,[eax+1ch]        ; InInitOrder.flink
lodsd
mov edi,[eax+8h]        ;  Krnl32  的基址
mov eax,[edi+3ch]        ;加上偏移 到Krnl32 PE头
mov edx,[edi+eax+78h]
        add edx,edi                        ; 函数到处表地址
        mov ecx,[edx+18h]        ; count
        mov ebx,[edx+20h]
        add ebx,edi                      
search:     ;做个标记
           dec ecx
       mov esi,[ebx+ecx*4]
        add esi,edi
        cmp [esi],50746547h        ; 'PteG'
        jne search
        cmp [esi+4],41636f72h
        jne search                        ; 'Acor'
        
        mov ebx,[edx+24h]
        add ebx,edi                        ; AddressOfNameOrdinals
        mov cx,[ebx+ecx*2]
        mov ebx,[edx+1ch]
        add ebx,edi                        ; AddressOfFunction
        mov eax,[ebx+ecx*4]
        add eax,edi
        mov esi,eax                        ; addr GetProcAddress

        push 0
        push 0
        push 00797261h
        push 7262694ch
        push 65657246h                ; FreeLibrary
        push esp
        push edi
        call esi
        
        mov [esp+16],eax
        
        pop ecx
        push 64616f4ch                ; LoadLibraryA
        mov byte ptr [esp+11],41h
        push esp
        push edi
        call esi
        
        push 00003233h
        push 72657375h                ; user32
        push esp
        call eax
        mov edi,eax                        ; addr user32
        
        push 0041786fh
        push 42656761h
        push 7373654dh                ; MessageBoxA  
        push esp
        push edi
        call esi
        
        push 0h
        push ced3bbd2h
        push cbb4bdb5h
        push acb3acb3h                ;超超到此一游
        mov ecx,esp
        push 40h
        push ecx
        push ecx
        push 0
        call eax
        
        add esp,34h
        pop eax
        push edi
        call eax
        retn

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值