首页
社区
课程
招聘
[求助]如何在patching过程中添加需要的API[已解决]
2008-6-17 22:12 4477

[求助]如何在patching过程中添加需要的API[已解决]

2008-6-17 22:12
4477
对于未加壳的程序,一般都有LoadLibraryA和GetAddress等API,可以方便的加入。但今天在patching一个加了TMD壳的程序时,当我想用MessageBox弹出个窗口时,却发现,程序本身的输入表中,只有ExitProcess,CreateFileA和 InitCommonControls三个API,在现在这种情况下,如何来添加自己需要的API呢?而且还得能跨平台。原来我试着直接用 call MessageBoxA,在本机上是可以。但当拿到其他机器上,如2003/2000等系统上,这个 call MesssageBoxA就变成了call 077xxyy,也就是不同平台上的user32.MessageBoxA的地址应该是不一样的。使补丁不能正常使用了

首先谢谢楼下两兄弟的指点。最后说一下我的解决方法:
1,用dup做好相应的loader,在内存补丁时调用没有的API时以call dword ptr ds:[aabbccdd]
2,diy一下loader,把需要的API的地址写到目标程序的[aabbccdd]中,当然,这里写的位置,和之前在lodaer调用时一一对应就可以了。

(可以跨平台,且碰到loader本身也没有的API时也可以方便添加进来)

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

收藏
点赞0
打赏
分享
最新回复 (3)
雪    币: 256
活跃值: (463)
能力值: ( LV4,RANK:50 )
在线值:
发帖
回帖
粉丝
wyqzm 1 2008-6-17 22:30
2
0
首先,可以用LordPE加一个MessageBoxA,
再在定位时使用相对地址,不要直接用绝对的


mov eax,[esp]
add eax,0x1234
call [eax]
雪    币: 299
活跃值: (300)
能力值: ( LV9,RANK:290 )
在线值:
发帖
回帖
粉丝
clide2000 7 2008-6-17 22:52
3
0
[QUOTE=wyqzm;468143]首先,可以用LordPE加一个MessageBoxA,
再在定位时使用相对地址,不要直接用绝对的


mov eax,[esp]
add eax,0x1234
call [eax][/QUOTE]

最好是有像内存补丁的方式,因为那样就不用修改程序了(一般自检验N多,包括壳和程序的,不太方便)
雪    币: 204
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
anykey 2008-6-17 23:54
4
0
给你一段我以前写过的代码看看
#include "windows.h"

#pragma comment(linker, "/entry:main")

typedef HANDLE (WINAPI *MYOpenProcess)(DWORD, BOOL, DWORD);

//get kernel base image address
unsigned int GetBaseImage()
{
        __asm {
                mov eax,fs:[30h]
                mov eax,[eax+0ch]
                mov esi,[eax+1ch]
                lodsd
                mov eax,[eax+08h] //return
        }
}

unsigned int GetAPIFuncAdress(unsigned int nImageBase,const char *pFuncName, int iLen)
{
        __asm {
                mov eax,nImageBase
                        mov eax,[eax+0x3c]   
                add eax,nImageBase //PE header
                        mov eax,[eax+0x78]
                add eax,nImageBase //Data_Directory   
                        mov esi,eax //IMAGE_EXPORT_DIRECTORY
                        mov ecx,[eax+0x18] //NumberOfName  
                mov eax,[eax+0x20] //AddressOfName
                add eax,nImageBase
                        mov ebx,eax  
                        xor edx,edx
FindLoop:
                push ecx
                        push esi
                        mov eax,[eax]
                add eax,nImageBase
                        mov esi,pFuncName
                        mov edi,eax
                        mov ecx,iLen
                        cld
                        rep cmpsb //compare function
                        pop esi //pop esi => IMAGE_EXPORT_DIRECTORY
                        je  Found  
                        inc edx  
                        add ebx,4
                        mov eax,ebx
                        pop ecx
                        loop FindLoop   
Found:
                add esp,4
                        mov eax,esi
                        mov eax,[eax+0x1c] //AddressOfFunction
                add eax,nImageBase   
                        shl edx,2
                        add eax,edx
                        mov eax,[eax]      
                add eax,nImageBase //eax return
        }
}

int main()
{
        char *szTitle = "title";
        char *szMsg = "message";

        char *szUserDLL = "User32.dll";
        char *szMessagebox = "MessageBoxA";

        unsigned int nBaseImage = 0;
        unsigned int nLoadLibraryAdress = 0;
        unsigned int nGetProcAddress = 0;

        nBaseImage = GetBaseImage();
        nLoadLibraryAdress = GetAPIFuncAdress(nBaseImage, "LoadLibraryA", 12);
        nGetProcAddress = GetAPIFuncAdress(nBaseImage, "GetProcAddress", 14);

        __asm {
                push szUserDLL
                call dword ptr nLoadLibraryAdress
                push szMessagebox
                push eax
                call dword ptr nGetProcAddress
                push MB_OK
                push szTitle
                push szMsg
                push NULL
                call eax
        }

        ExitProcess(0);
        return 0;
}
游客
登录 | 注册 方可回帖
返回